@@ -186,10 +186,7 @@ func (e *Exchange) QueryTicker(ctx context.Context, symbol string) (*types.Ticke
186
186
return nil , fmt .Errorf ("ticker rate limiter wait error: %w" , err )
187
187
}
188
188
189
- symbol = toLocalSymbol (symbol )
190
- if e .IsFutures {
191
- symbol = toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
192
- }
189
+ symbol = e .getInstrumentId (symbol )
193
190
marketTicker , err := e .client .NewGetTickerRequest ().InstId (symbol ).Do (ctx )
194
191
if err != nil {
195
192
return nil , err
@@ -316,7 +313,7 @@ func (e *Exchange) queryAccountBalance(ctx context.Context) ([]okexapi.Account,
316
313
func (e * Exchange ) SubmitOrder (ctx context.Context , order types.SubmitOrder ) (* types.Order , error ) {
317
314
orderReq := e .client .NewPlaceOrderRequest ()
318
315
319
- orderReq .InstrumentID (toLocalSymbol (order .Symbol ))
316
+ orderReq .InstrumentID (e . getInstrumentId (order .Symbol ))
320
317
orderReq .Side (toLocalSideType (order .Side ))
321
318
orderReq .Size (order .Market .FormatQuantity (order .Quantity ))
322
319
@@ -331,10 +328,6 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
331
328
orderReq .TradeMode (okexapi .TradeModeCross )
332
329
}
333
330
} else if e .IsFutures {
334
- quantity := order .Market .AdjustQuantityToContractSize (order .Quantity )
335
- orderReq .Size (order .Market .FormatQuantity (quantity ))
336
- orderReq .InstrumentID (toLocalSymbol (order .Symbol , okexapi .InstrumentTypeSwap ))
337
-
338
331
if e .FuturesSettings .IsIsolatedFutures {
339
332
orderReq .TradeMode (okexapi .TradeModeIsolated )
340
333
} else {
@@ -355,12 +348,8 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
355
348
case types .OrderTypeMarket :
356
349
// target currency = Default is quote_ccy for buy, base_ccy for sell
357
350
// Because our order.Quantity unit is base coin, so we indicate the target currency to Base.
358
- switch order .Side {
359
- case types .SideTypeSell :
360
- orderReq .Size (order .Market .FormatQuantity (order .Quantity ))
361
- orderReq .TargetCurrency (okexapi .TargetCurrencyBase )
362
- case types .SideTypeBuy :
363
- orderReq .Size (order .Market .FormatQuantity (order .Quantity ))
351
+ // Only applicable to SPOT Market Orders
352
+ if ! e .IsFutures {
364
353
orderReq .TargetCurrency (okexapi .TargetCurrencyBase )
365
354
}
366
355
}
@@ -424,7 +413,7 @@ func (e *Exchange) SubmitOrder(ctx context.Context, order types.SubmitOrder) (*t
424
413
// QueryOpenOrders retrieves the pending orders. The data returned is ordered by createdTime, and we utilized the
425
414
// `After` parameter to acquire all orders.
426
415
func (e * Exchange ) QueryOpenOrders (ctx context.Context , symbol string ) (orders []types.Order , err error ) {
427
- instrumentID := toLocalSymbol (symbol )
416
+ instrumentID := e . getInstrumentId (symbol )
428
417
429
418
nextCursor := int64 (0 )
430
419
for {
@@ -439,7 +428,6 @@ func (e *Exchange) QueryOpenOrders(ctx context.Context, symbol string) (orders [
439
428
if e .MarginSettings .IsMargin {
440
429
req .InstrumentType (okexapi .InstrumentTypeMargin )
441
430
} else if e .IsFutures {
442
- req .InstrumentID (toLocalSymbol (symbol , okexapi .InstrumentTypeSwap ))
443
431
req .InstrumentType (okexapi .InstrumentTypeSwap )
444
432
}
445
433
@@ -484,10 +472,8 @@ func (e *Exchange) CancelOrders(ctx context.Context, orders ...types.Order) erro
484
472
}
485
473
486
474
req := e .client .NewCancelOrderRequest ()
487
- req .InstrumentID (toLocalSymbol (order .Symbol ))
488
- if e .IsFutures {
489
- req .InstrumentID (toLocalSymbol (order .Symbol , okexapi .InstrumentTypeSwap ))
490
- }
475
+ req .InstrumentID (e .getInstrumentId (order .Symbol ))
476
+
491
477
req .OrderID (strconv .FormatUint (order .OrderID , 10 ))
492
478
if len (order .ClientOrderID ) > 0 {
493
479
if ok := clientOrderIdRegex .MatchString (order .ClientOrderID ); ! ok {
@@ -528,10 +514,7 @@ func (e *Exchange) QueryKLines(
528
514
return nil , fmt .Errorf ("failed to get interval: %w" , err )
529
515
}
530
516
531
- instrumentID := toLocalSymbol (symbol )
532
- if e .IsFutures {
533
- instrumentID = toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
534
- }
517
+ instrumentID := e .getInstrumentId (symbol )
535
518
536
519
req := e .client .NewGetCandlesRequest ().InstrumentID (instrumentID )
537
520
req .Bar (intervalParam )
@@ -566,10 +549,8 @@ func (e *Exchange) QueryOrder(ctx context.Context, q types.OrderQuery) (*types.O
566
549
return nil , errors .New ("okex.QueryOrder: OrderId or ClientOrderId is required parameter" )
567
550
}
568
551
req := e .client .NewGetOrderDetailsRequest ()
569
- instrumentID := toLocalSymbol (q .Symbol )
570
- if e .IsFutures {
571
- instrumentID = toLocalSymbol (q .Symbol , okexapi .InstrumentTypeSwap )
572
- }
552
+ instrumentID := e .getInstrumentId (q .Symbol )
553
+
573
554
req .InstrumentID (instrumentID )
574
555
// Either ordId or clOrdId is required, if both are passed, ordId will be used
575
556
// ref: https://www.okx.com/docs-v5/en/#order-book-trading-trade-get-order-details
@@ -599,10 +580,7 @@ func (e *Exchange) QueryOrderTrades(ctx context.Context, q types.OrderQuery) (tr
599
580
600
581
req := e .client .NewGetThreeDaysTransactionHistoryRequest ()
601
582
if len (q .Symbol ) != 0 {
602
- instrumentID := toLocalSymbol (q .Symbol )
603
- if e .IsFutures {
604
- instrumentID = toLocalSymbol (q .Symbol , okexapi .InstrumentTypeSwap )
605
- }
583
+ instrumentID := e .getInstrumentId (q .Symbol )
606
584
req .InstrumentID (instrumentID )
607
585
}
608
586
@@ -662,11 +640,7 @@ func (e *Exchange) QueryClosedOrders(
662
640
}
663
641
664
642
req := e .client .NewGetOrderHistoryRequest ()
665
- instrumentID := toLocalSymbol (symbol )
666
- if e .IsFutures {
667
- instrumentID = toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
668
- req .InstrumentType (okexapi .InstrumentTypeSwap )
669
- }
643
+ instrumentID := e .getInstrumentId (symbol )
670
644
671
645
req .InstrumentID (instrumentID ).
672
646
StartTime (since ).
@@ -822,6 +796,14 @@ func (e *Exchange) getInstrumentType() okexapi.InstrumentType {
822
796
return okexapi .InstrumentTypeSpot
823
797
}
824
798
799
+ func (e * Exchange ) getInstrumentId (symbol string ) string {
800
+ if e .IsFutures {
801
+ return toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
802
+ }
803
+
804
+ return toLocalSymbol (symbol )
805
+ }
806
+
825
807
func (e * Exchange ) QueryDepositHistory (
826
808
ctx context.Context , asset string , startTime , endTime * time.Time ,
827
809
) ([]types.Deposit , error ) {
@@ -912,11 +894,7 @@ func (e *Exchange) QueryTrades(
912
894
"req_id" : uuid .New ().String (),
913
895
})
914
896
915
- instrumentID := toLocalSymbol (symbol )
916
- if e .IsFutures {
917
- instrumentID = toLocalSymbol (symbol , okexapi .InstrumentTypeSwap )
918
- }
919
-
897
+ instrumentID := e .getInstrumentId (symbol )
920
898
instrType := e .getInstrumentType ()
921
899
922
900
if lessThan3Day {
0 commit comments