@@ -133,7 +133,6 @@ func (s *CreateOrderService) ClosePosition(closePosition bool) *CreateOrderServi
133
133
}
134
134
135
135
func (s * CreateOrderService ) createOrder (ctx context.Context , endpoint string , opts ... RequestOption ) (data []byte , header * http.Header , err error ) {
136
-
137
136
r := & request {
138
137
method : http .MethodPost ,
139
138
endpoint : endpoint ,
@@ -241,24 +240,13 @@ type CreateOrderResponse struct {
241
240
// ModifyOrderService create order
242
241
type ModifyOrderService struct {
243
242
c * Client
244
- symbol string
245
243
orderID * int64
246
244
origClientOrderID * string
245
+ symbol string
247
246
side SideType
248
- positionSide * PositionSideType
249
- orderType OrderType
250
- timeInForce * TimeInForceType
251
247
quantity string
252
- reduceOnly * string
253
248
price * string
254
- newClientOrderID * string
255
- stopPrice * string
256
- workingType * WorkingType
257
- activationPrice * string
258
- callbackRate * string
259
- priceProtect * string
260
- newOrderRespType NewOrderRespType
261
- closePosition * string
249
+ priceMatch * PriceMatchType
262
250
}
263
251
264
252
// Symbol set symbol
@@ -267,11 +255,13 @@ func (s *ModifyOrderService) Symbol(symbol string) *ModifyOrderService {
267
255
return s
268
256
}
269
257
258
+ // OrderID will prevail over OrigClientOrderID
270
259
func (s * ModifyOrderService ) OrderID (orderID int64 ) * ModifyOrderService {
271
260
s .orderID = & orderID
272
261
return s
273
262
}
274
263
264
+ // OrigClientOrderID is not necessary if OrderID is provided
275
265
func (s * ModifyOrderService ) OrigClientOrderID (origClientOrderID string ) * ModifyOrderService {
276
266
s .origClientOrderID = & origClientOrderID
277
267
return s
@@ -283,141 +273,46 @@ func (s *ModifyOrderService) Side(side SideType) *ModifyOrderService {
283
273
return s
284
274
}
285
275
286
- // PositionSide set side
287
- func (s * ModifyOrderService ) PositionSide (positionSide PositionSideType ) * ModifyOrderService {
288
- s .positionSide = & positionSide
289
- return s
290
- }
291
-
292
- // Type set type
293
- func (s * ModifyOrderService ) Type (orderType OrderType ) * ModifyOrderService {
294
- s .orderType = orderType
295
- return s
296
- }
297
-
298
- // TimeInForce set timeInForce
299
- func (s * ModifyOrderService ) TimeInForce (timeInForce TimeInForceType ) * ModifyOrderService {
300
- s .timeInForce = & timeInForce
301
- return s
302
- }
303
-
304
276
// Quantity set quantity
305
277
func (s * ModifyOrderService ) Quantity (quantity string ) * ModifyOrderService {
306
278
s .quantity = quantity
307
279
return s
308
280
}
309
281
310
- // ReduceOnly set reduceOnly
311
- func (s * ModifyOrderService ) ReduceOnly (reduceOnly bool ) * ModifyOrderService {
312
- reduceOnlyStr := strconv .FormatBool (reduceOnly )
313
- s .reduceOnly = & reduceOnlyStr
314
- return s
315
- }
316
-
317
282
// Price set price
318
283
func (s * ModifyOrderService ) Price (price string ) * ModifyOrderService {
319
284
s .price = & price
320
285
return s
321
286
}
322
287
323
- // NewClientOrderID set newClientOrderID
324
- func (s * ModifyOrderService ) NewClientOrderID (newClientOrderID string ) * ModifyOrderService {
325
- s .newClientOrderID = & newClientOrderID
326
- return s
327
- }
328
-
329
- // StopPrice set stopPrice
330
- func (s * ModifyOrderService ) StopPrice (stopPrice string ) * ModifyOrderService {
331
- s .stopPrice = & stopPrice
332
- return s
333
- }
334
-
335
- // WorkingType set workingType
336
- func (s * ModifyOrderService ) WorkingType (workingType WorkingType ) * ModifyOrderService {
337
- s .workingType = & workingType
338
- return s
339
- }
340
-
341
- // ActivationPrice set activationPrice
342
- func (s * ModifyOrderService ) ActivationPrice (activationPrice string ) * ModifyOrderService {
343
- s .activationPrice = & activationPrice
344
- return s
345
- }
346
-
347
- // CallbackRate set callbackRate
348
- func (s * ModifyOrderService ) CallbackRate (callbackRate string ) * ModifyOrderService {
349
- s .callbackRate = & callbackRate
350
- return s
351
- }
352
-
353
- // PriceProtect set priceProtect
354
- func (s * ModifyOrderService ) PriceProtect (priceProtect bool ) * ModifyOrderService {
355
- priceProtectStr := strconv .FormatBool (priceProtect )
356
- s .priceProtect = & priceProtectStr
357
- return s
358
- }
359
-
360
- // NewOrderResponseType set newOrderResponseType
361
- func (s * ModifyOrderService ) NewOrderResponseType (newOrderResponseType NewOrderRespType ) * ModifyOrderService {
362
- s .newOrderRespType = newOrderResponseType
363
- return s
364
- }
365
-
366
- // ClosePosition set closePosition
367
- func (s * ModifyOrderService ) ClosePosition (closePosition bool ) * ModifyOrderService {
368
- closePositionStr := strconv .FormatBool (closePosition )
369
- s .closePosition = & closePositionStr
288
+ // PriceMatch set priceMatch
289
+ func (s * ModifyOrderService ) PriceMatch (priceMatch PriceMatchType ) * ModifyOrderService {
290
+ s .priceMatch = & priceMatch
370
291
return s
371
292
}
372
293
373
294
func (s * ModifyOrderService ) modifyOrder (ctx context.Context , endpoint string , opts ... RequestOption ) (data []byte , header * http.Header , err error ) {
374
-
375
295
r := & request {
376
296
method : http .MethodPut ,
377
297
endpoint : endpoint ,
378
298
secType : secTypeSigned ,
379
299
}
380
300
m := params {
381
- "symbol" : s .symbol ,
382
- "side" : s .side ,
383
- "type" : s .orderType ,
384
- "newOrderRespType" : s .newOrderRespType ,
301
+ "symbol" : s .symbol ,
302
+ "side" : s .side ,
303
+ "quantity" : s .quantity ,
385
304
}
386
- if s .quantity != "" {
387
- m ["quantity" ] = s .quantity
388
- }
389
- if s .positionSide != nil {
390
- m ["positionSide" ] = * s .positionSide
391
- }
392
- if s .timeInForce != nil {
393
- m ["timeInForce" ] = * s .timeInForce
305
+ if s .orderID != nil {
306
+ m ["orderId" ] = * s .orderID
394
307
}
395
- if s .reduceOnly != nil {
396
- m ["reduceOnly " ] = * s .reduceOnly
308
+ if s .origClientOrderID != nil {
309
+ m ["origClientOrderId " ] = * s .origClientOrderID
397
310
}
398
311
if s .price != nil {
399
312
m ["price" ] = * s .price
400
313
}
401
- if s .newClientOrderID != nil {
402
- m ["newClientOrderId" ] = * s .newClientOrderID
403
- }
404
- if s .stopPrice != nil {
405
- m ["stopPrice" ] = * s .stopPrice
406
- }
407
- if s .workingType != nil {
408
- m ["workingType" ] = * s .workingType
409
- }
410
- if s .priceProtect != nil {
411
- m ["priceProtect" ] = * s .priceProtect
412
- }
413
- if s .activationPrice != nil {
414
- m ["activationPrice" ] = * s .activationPrice
415
- }
416
- if s .callbackRate != nil {
417
- m ["callbackRate" ] = * s .callbackRate
418
- }
419
- if s .closePosition != nil {
420
- m ["closePosition" ] = * s .closePosition
314
+ if s .priceMatch != nil {
315
+ m ["priceMatch" ] = * s .priceMatch
421
316
}
422
317
r .setFormParams (m )
423
318
data , header , err = s .c .callAPI (ctx , r , opts ... )
@@ -427,13 +322,22 @@ func (s *ModifyOrderService) modifyOrder(ctx context.Context, endpoint string, o
427
322
return data , header , nil
428
323
}
429
324
430
- // Do send request
431
- func (s * ModifyOrderService ) Do (ctx context.Context , opts ... RequestOption ) (res * Order , err error ) {
325
+ // Do send request:
326
+ // - Either orderId or origClientOrderId must be sent, and the orderId will prevail if both are sent
327
+ // - Either price or priceMatch must be sent. Sending both will fail the request
328
+ // - When the new quantity or price doesn't satisfy PriceFilter / PercentPriceFilter / LotSizeFilter,
329
+ // amendment will be rejected and the order will stay as it is
330
+ // - However the order will be cancelled by the amendment in the following situations:
331
+ // -- when the order is in partially filled status and the new quantity <= executedQty
332
+ // -- when the order is TimeInForceTypeGTX and the new price will cause it to be executed immediately
333
+ // - One order can only be modified for less than 10000 times
334
+ // - Will set ModifyOrderResponse.SelfTradePreventionMode to "NONE"
335
+ func (s * ModifyOrderService ) Do (ctx context.Context , opts ... RequestOption ) (res * ModifyOrderResponse , err error ) {
432
336
data , _ , err := s .modifyOrder (ctx , "/fapi/v1/order" , opts ... )
433
337
if err != nil {
434
338
return nil , err
435
339
}
436
- res = new (Order )
340
+ res = new (ModifyOrderResponse )
437
341
err = json .Unmarshal (data , res )
438
342
439
343
if err != nil {
@@ -442,6 +346,34 @@ func (s *ModifyOrderService) Do(ctx context.Context, opts ...RequestOption) (res
442
346
return res , nil
443
347
}
444
348
349
+ type ModifyOrderResponse struct {
350
+ OrderID int64 `json:"orderId"`
351
+ Symbol string `json:"symbol"`
352
+ Pair string `json:"pair"`
353
+ Status OrderStatusType `json:"status"`
354
+ ClientOrderID string `json:"clientOrderId"`
355
+ Price string `json:"price"`
356
+ AveragePrice string `json:"avgPrice"`
357
+ OriginalQuantity string `json:"origQty"`
358
+ ExecutedQuantity string `json:"executedQty"`
359
+ CumulativeQuantity string `json:"cumQty"`
360
+ CumulativeBase string `json:"cumBase"`
361
+ TimeInForce TimeInForceType `json:"timeInForce"`
362
+ Type OrderType `json:"type"`
363
+ ReduceOnly bool `json:"reduceOnly"`
364
+ ClosePosition bool `json:"closePosition"`
365
+ Side SideType `json:"side"`
366
+ PositionSide PositionSideType `json:"positionSide"`
367
+ StopPrice string `json:"stopPrice"`
368
+ WorkingType WorkingType `json:"workingType"`
369
+ PriceProtect bool `json:"priceProtect"` // if conditional order trigger is protected
370
+ OriginalType OrderType `json:"origType"`
371
+ PriceMatch PriceMatchType `json:"priceMatch"`
372
+ SelfTradePreventionMode string `json:"selfTradePreventionMode"`
373
+ GoodTillDate int64 `json:"goodTillDate"` // order pre-set auto cancel time for TIF GTD order
374
+ UpdateTime int64 `json:"updateTime"`
375
+ }
376
+
445
377
// ListOpenOrdersService list opened orders
446
378
type ListOpenOrdersService struct {
447
379
c * Client
@@ -588,7 +520,7 @@ type Order struct {
588
520
ReduceOnly bool `json:"reduceOnly"`
589
521
OrigQuantity string `json:"origQty"`
590
522
ExecutedQuantity string `json:"executedQty"`
591
- CumQuantity string `json:"cumQty"`
523
+ CumQuantity string `json:"cumQty"` // deprecated: use ExecutedQuantity instead
592
524
CumQuote string `json:"cumQuote"`
593
525
Status OrderStatusType `json:"status"`
594
526
TimeInForce TimeInForceType `json:"timeInForce"`
@@ -737,7 +669,7 @@ func (s *CancelOrderService) Do(ctx context.Context, opts ...RequestOption) (res
737
669
// CancelOrderResponse define response of canceling order
738
670
type CancelOrderResponse struct {
739
671
ClientOrderID string `json:"clientOrderId"`
740
- CumQuantity string `json:"cumQty"`
672
+ CumQuantity string `json:"cumQty"` // deprecated: use ExecutedQuantity instead
741
673
CumQuote string `json:"cumQuote"`
742
674
ExecutedQuantity string `json:"executedQty"`
743
675
OrderID int64 `json:"orderId"`
@@ -874,6 +806,7 @@ func (s *ListLiquidationOrdersService) Limit(limit int) *ListLiquidationOrdersSe
874
806
}
875
807
876
808
// Do send request
809
+ // Deprecated: use /fapi/v1/forceOrders instead
877
810
func (s * ListLiquidationOrdersService ) Do (ctx context.Context , opts ... RequestOption ) (res []* LiquidationOrder , err error ) {
878
811
r := & request {
879
812
method : http .MethodGet ,
0 commit comments