Skip to content

Commit

Permalink
Adding review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samuael committed Nov 1, 2024
1 parent e406221 commit 06300af
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 8 deletions.
48 changes: 42 additions & 6 deletions exchanges/okx/okx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -2386,8 +2414,12 @@ func TestGetOrderInfo(t *testing.T) {
if len(enabled) == 0 {
t.SkipNow()
}
sharedtestvalues.SkipTestIfCredentialsUnset(t, ok)
// sharedtestvalues.SkipTestIfCredentialsUnset(t, ok)

Check failure on line 2417 in exchanges/okx/okx_test.go

View workflow job for this annotation

GitHub Actions / lint

commentedOutCode: may want to remove commented-out code (gocritic)
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)
}
Expand Down Expand Up @@ -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)
}
Expand Down
15 changes: 13 additions & 2 deletions exchanges/okx/okx_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1292,14 +1292,21 @@ 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,
OrderID: resp.OrderID,
ClientOrderID: resp.ClientOrderID,
Side: oSide,
Type: oType,
Pair: pair,
Pair: cp,
Cost: resp.Price.Float64(),
AssetType: assetType,
Status: oStatus,
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 06300af

Please sign in to comment.