@@ -170,6 +170,8 @@ func (e *Exchange) QueryMarkets(ctx context.Context) (types.MarketMap, error) {
170
170
// OKEx does not offer minimal notional, use 1 USD here.
171
171
MinNotional : fixedpoint .One ,
172
172
MinAmount : fixedpoint .One ,
173
+
174
+ ContractValue : instrument .ContractValue ,
173
175
}
174
176
markets [symbol ] = market
175
177
}
@@ -184,10 +186,7 @@ func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticke
184
186
return nil , fmt .Errorf ("ticker rate limiter wait error: %w" , err )
185
187
}
186
188
187
- symbol = toLocalSymbol (symbol )
188
- if e .IsFutures {
189
- symbol = toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
190
- }
189
+ symbol = e .getInstrumentId (symbol )
191
190
marketTicker , err := e .client .NewGetTickerRequest ().InstId (symbol ).Do (ctx )
192
191
if err != nil {
193
192
return nil , err
@@ -314,7 +313,7 @@ func (e *Exchange) queryAccountBalance(ctx context.Context) ([]okexapi.Account,
314
313
func (e * Exchange ) SubmitOrder (ctx context.Context , order types.SubmitOrder ) (* types.Order , error ) {
315
314
orderReq := e .client .NewPlaceOrderRequest ()
316
315
317
- orderReq .InstrumentID (toLocalSymbol (order .Symbol ))
316
+ orderReq .InstrumentID (e . getInstrumentId (order .Symbol ))
318
317
orderReq .Side (toLocalSideType (order .Side ))
319
318
orderReq .Size (order .Market .FormatQuantity (order .Quantity ))
320
319
@@ -329,7 +328,6 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
329
328
orderReq .TradeMode (okexapi .TradeModeCross )
330
329
}
331
330
} else if e .IsFutures {
332
- orderReq .InstrumentID (toLocalSymbol (order .Symbol , okexapi .InstrumentTypeSwap ))
333
331
if e .FuturesSettings .IsIsolatedFutures {
334
332
orderReq .TradeMode (okexapi .TradeModeIsolated )
335
333
} else {
@@ -350,12 +348,8 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
350
348
case types .OrderTypeMarket :
351
349
// target currency = Default is quote_ccy for buy, base_ccy for sell
352
350
// Because our order.Quantity unit is base coin, so we indicate the target currency to Base.
353
- switch order .Side {
354
- case types .SideTypeSell :
355
- orderReq .Size (order .Market .FormatQuantity (order .Quantity ))
356
- orderReq .TargetCurrency (okexapi .TargetCurrencyBase )
357
- case types .SideTypeBuy :
358
- orderReq .Size (order .Market .FormatQuantity (order .Quantity ))
351
+ // Only applicable to SPOT Market Orders
352
+ if ! e .IsFutures {
359
353
orderReq .TargetCurrency (okexapi .TargetCurrencyBase )
360
354
}
361
355
}
@@ -419,7 +413,7 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
419
413
// QueryOpenOrders retrieves the pending orders. The data returned is ordered by createdTime, and we utilized the
420
414
// `After` parameter to acquire all orders.
421
415
func (e * Exchange ) QueryOpenOrders (ctx context.Context , symbol string ) (orders []types.Order , err error ) {
422
- instrumentID := toLocalSymbol (symbol )
416
+ instrumentID := e . getInstrumentId (symbol )
423
417
424
418
nextCursor := int64 (0 )
425
419
for {
@@ -434,7 +428,6 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [
434
428
if e .MarginSettings .IsMargin {
435
429
req .InstrumentType (okexapi .InstrumentTypeMargin )
436
430
} else if e .IsFutures {
437
- req .InstrumentID (toLocalSymbol (symbol , okexapi .InstrumentTypeSwap ))
438
431
req .InstrumentType (okexapi .InstrumentTypeSwap )
439
432
}
440
433
@@ -479,10 +472,8 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) erro
479
472
}
480
473
481
474
req := e .client .NewCancelOrderRequest ()
482
- req .InstrumentID (toLocalSymbol (order .Symbol ))
483
- if e .IsFutures {
484
- req .InstrumentID (toLocalSymbol (order .Symbol , okexapi .InstrumentTypeSwap ))
485
- }
475
+ req .InstrumentID (e .getInstrumentId (order .Symbol ))
476
+
486
477
req .OrderID (strconv .FormatUint (order .OrderID , 10 ))
487
478
if len (order .ClientOrderID ) > 0 {
488
479
if ok := clientOrderIdRegex .MatchString (order .ClientOrderID ); ! ok {
@@ -520,10 +511,7 @@ func (e *Exchange) QueryKLines(
520
511
return nil , fmt .Errorf ("failed to get interval: %w" , err )
521
512
}
522
513
523
- instrumentID := toLocalSymbol (symbol )
524
- if e .IsFutures {
525
- instrumentID = toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
526
- }
514
+ instrumentID := e .getInstrumentId (symbol )
527
515
528
516
req := e .client .NewGetCandlesRequest ().InstrumentID (instrumentID )
529
517
req .Bar (intervalParam )
@@ -558,10 +546,8 @@ func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.O
558
546
return nil , errors .New ("okex.QueryOrder: OrderId or ClientOrderId is required parameter" )
559
547
}
560
548
req := e .client .NewGetOrderDetailsRequest ()
561
- instrumentID := toLocalSymbol (q .Symbol )
562
- if e .IsFutures {
563
- instrumentID = toLocalSymbol (q .Symbol , okexapi .InstrumentTypeSwap )
564
- }
549
+ instrumentID := e .getInstrumentId (q .Symbol )
550
+
565
551
req .InstrumentID (instrumentID )
566
552
// Either ordId or clOrdId is required, if both are passed, ordId will be used
567
553
// ref: https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-details
@@ -591,10 +577,7 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) (tr
591
577
592
578
req := e .client .NewGetThreeDaysTransactionHistoryRequest ()
593
579
if len (q .Symbol ) != 0 {
594
- instrumentID := toLocalSymbol (q .Symbol )
595
- if e .IsFutures {
596
- instrumentID = toLocalSymbol (q .Symbol , okexapi .InstrumentTypeSwap )
597
- }
580
+ instrumentID := e .getInstrumentId (q .Symbol )
598
581
req .InstrumentID (instrumentID )
599
582
}
600
583
@@ -654,11 +637,7 @@ func (e *Exchange) QueryClosedOrders(
654
637
}
655
638
656
639
req := e .client .NewGetOrderHistoryRequest ()
657
- instrumentID := toLocalSymbol (symbol )
658
- if e .IsFutures {
659
- instrumentID = toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
660
- req .InstrumentType (okexapi .InstrumentTypeSwap )
661
- }
640
+ instrumentID := e .getInstrumentId (symbol )
662
641
663
642
req .InstrumentID (instrumentID ).
664
643
StartTime (since ).
@@ -814,6 +793,14 @@ func (e *Exchange) getInstrumentType() okexapi.InstrumentType {
814
793
return okexapi .InstrumentTypeSpot
815
794
}
816
795
796
+ func (e * Exchange ) getInstrumentId (symbol string ) string {
797
+ if e .IsFutures {
798
+ return toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
799
+ }
800
+
801
+ return toLocalSymbol (symbol )
802
+ }
803
+
817
804
func (e * Exchange ) QueryDepositHistory (
818
805
ctx context.Context , asset string , startTime , endTime * time.Time ,
819
806
) ([]types.Deposit , error ) {
@@ -904,11 +891,7 @@ func (e *Exchange) QueryTrades(
904
891
"req_id" : uuid .New ().String (),
905
892
})
906
893
907
- instrumentID := toLocalSymbol (symbol )
908
- if e .IsFutures {
909
- instrumentID = toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
910
- }
911
-
894
+ instrumentID := e .getInstrumentId (symbol )
912
895
instrType := e .getInstrumentType ()
913
896
914
897
if lessThan3Day {
0 commit comments