From 06300afc7ba4d423024b491e21c22c5bee2fbca3 Mon Sep 17 00:00:00 2001 From: Samuael A <39623015+samuael@users.noreply.github.com> Date: Fri, 1 Nov 2024 22:58:49 +0300 Subject: [PATCH] Adding review fixes --- exchanges/okx/okx_test.go | 48 +++++++++++++++++++++++++++++++----- exchanges/okx/okx_wrapper.go | 15 +++++++++-- 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/exchanges/okx/okx_test.go b/exchanges/okx/okx_test.go index 3eaff6902b0..3517e45942a 100644 --- a/exchanges/okx/okx_test.go +++ b/exchanges/okx/okx_test.go @@ -2297,8 +2297,8 @@ func TestSubmitOrder(t *testing.T) { sharedtestvalues.SkipTestIfCredentialsUnset(t, ok, canManipulateRealOrders) result, err := ok.SubmitOrder(contextGenerate(), orderSubmission) - require.NoError(t, err) - require.NotNil(t, result) + assert.NoError(t, err) + assert.NotNil(t, result) cp, err := currency.NewPairFromString("BTC-USDT-230630") require.NoError(t, err) @@ -2314,6 +2314,23 @@ func TestSubmitOrder(t *testing.T) { MarginType: margin.Multi, } result, err = ok.SubmitOrder(contextGenerate(), orderSubmission) + assert.NoError(t, err) + assert.NotNil(t, result) + + pair, err := currency.NewPairFromString("BTC-USDT-SWAP_BTC-USDT-250328") + require.NoError(t, err) + + result, err = ok.SubmitOrder(contextGenerate(), &order.Submit{ + Pair: pair, + Exchange: ok.Name, + Side: order.Buy, + Type: order.Limit, + Price: 1234, + Amount: 1, + ClientID: "hellomoto", + AssetType: asset.Spread, + MarginType: margin.Multi, + }) require.NoError(t, err) assert.NotNil(t, result) } @@ -2375,6 +2392,17 @@ func TestModifyOrder(t *testing.T) { Price: 123456.44, Amount: 123, }) + assert.NoError(t, err) + assert.NotNil(t, result) + + result, err = ok.ModifyOrder(contextGenerate(), + &order.Modify{ + AssetType: asset.Spread, + Pair: currency.NewPair(currency.LTC, currency.BTC), + OrderID: "1234", + Price: 123456.44, + Amount: 123, + }) require.NoError(t, err) assert.NotNil(t, result) } @@ -2386,8 +2414,12 @@ func TestGetOrderInfo(t *testing.T) { if len(enabled) == 0 { t.SkipNow() } - sharedtestvalues.SkipTestIfCredentialsUnset(t, ok) + // sharedtestvalues.SkipTestIfCredentialsUnset(t, ok) result, err := ok.GetOrderInfo(contextGenerate(), "123", enabled[0], asset.Futures) + assert.NoError(t, err) + assert.NotNil(t, result) + + result, err = ok.GetOrderInfo(contextGenerate(), "123", enabled[0], asset.Spread) require.NoError(t, err) assert.NotNil(t, result) } @@ -2464,11 +2496,15 @@ func TestGetOrderHistory(t *testing.T) { _, err := ok.GetOrderHistory(contextGenerate(), &getOrdersRequest) require.ErrorIs(t, err, currency.ErrCurrencyPairsEmpty) - getOrdersRequest.Pairs = []currency.Pair{ - currency.NewPair(currency.LTC, - currency.BTC)} + getOrdersRequest.Pairs = []currency.Pair{currency.NewPair(currency.LTC, currency.BTC)} sharedtestvalues.SkipTestIfCredentialsUnset(t, ok) result, err := ok.GetOrderHistory(contextGenerate(), &getOrdersRequest) + assert.NoError(t, err) + assert.NotNil(t, result) + + getOrdersRequest.AssetType = asset.Spread + getOrdersRequest.Type = order.Market + result, err = ok.GetOrderHistory(contextGenerate(), &getOrdersRequest) require.NoError(t, err) assert.NotNil(t, result) } diff --git a/exchanges/okx/okx_wrapper.go b/exchanges/okx/okx_wrapper.go index a5eee396c06..b47b3d47114 100644 --- a/exchanges/okx/okx_wrapper.go +++ b/exchanges/okx/okx_wrapper.go @@ -1292,6 +1292,13 @@ func (ok *Okx) GetOrderInfo(ctx context.Context, orderID string, pair currency.P if err != nil { return nil, err } + cp, err := currency.NewPairFromString(resp.InstrumentID) + if err != nil { + return nil, err + } + if !pair.IsEmpty() && !cp.Equal(pair) { + return nil, fmt.Errorf("%w, unexpected instrument ID %v for order ID %s", order.ErrOrderNotFound, pair, orderID) + } return &order.Detail{ Amount: resp.Size.Float64(), Exchange: ok.Name, @@ -1299,7 +1306,7 @@ func (ok *Okx) GetOrderInfo(ctx context.Context, orderID string, pair currency.P ClientOrderID: resp.ClientOrderID, Side: oSide, Type: oType, - Pair: pair, + Pair: cp, Cost: resp.Price.Float64(), AssetType: assetType, Status: oStatus, @@ -1602,7 +1609,11 @@ func (ok *Okx) GetOrderHistory(ctx context.Context, req *order.MultiOrderRequest var resp []order.Detail // For Spread orders. if req.AssetType == asset.Spread { - spreadOrders, err := ok.GetCompletedSpreadOrdersLast7Days(ctx, "", req.Type.Lower(), "", req.FromOrderID, "", req.StartTime, req.EndTime, 0) + oType, err := ok.OrderTypeString(req.Type) + if err != nil { + return nil, err + } + spreadOrders, err := ok.GetCompletedSpreadOrdersLast7Days(ctx, "", oType, "", req.FromOrderID, "", req.StartTime, req.EndTime, 0) if err != nil { return nil, err }