-
Notifications
You must be signed in to change notification settings - Fork 75
/
account.go
1893 lines (1734 loc) · 55.2 KB
/
account.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package binance_connector
import (
"context"
"encoding/json"
"net/http"
"strconv"
)
// Binance Test New Order endpoint (POST /api/v3/order/test)
type TestNewOrder struct {
c *Client
symbol string
side string
orderType string
timeInForce *string
quantity *float64
quoteOrderQty *float64
price *float64
newClientOrderId *string
strategyId *int
strategyType *int
stopPrice *float64
trailingDelta *int
icebergQty *float64
newOrderRespType *string
selfTradePrevention *string
}
// Symbol set symbol
func (s *TestNewOrder) Symbol(symbol string) *TestNewOrder {
s.symbol = symbol
return s
}
// Side set side
func (s *TestNewOrder) Side(side string) *TestNewOrder {
s.side = side
return s
}
// OrderType set orderType
func (s *TestNewOrder) OrderType(orderType string) *TestNewOrder {
s.orderType = orderType
return s
}
// TimeInForce set timeInForce
func (s *TestNewOrder) TimeInForce(timeInForce string) *TestNewOrder {
s.timeInForce = &timeInForce
return s
}
// Quantity set quantity
func (s *TestNewOrder) Quantity(quantity float64) *TestNewOrder {
s.quantity = &quantity
return s
}
// QuoteOrderQty set quoteOrderQty
func (s *TestNewOrder) QuoteOrderQty(quoteOrderQty float64) *TestNewOrder {
s.quoteOrderQty = "eOrderQty
return s
}
// Price set price
func (s *TestNewOrder) Price(price float64) *TestNewOrder {
s.price = &price
return s
}
// NewClientOrderId set newClientOrderId
func (s *TestNewOrder) NewClientOrderId(newClientOrderId string) *TestNewOrder {
s.newClientOrderId = &newClientOrderId
return s
}
// StrategyId set strategyId
func (s *TestNewOrder) StrategyId(strategyId int) *TestNewOrder {
s.strategyId = &strategyId
return s
}
// StrategyType set strategyType
func (s *TestNewOrder) StrategyType(strategyType int) *TestNewOrder {
s.strategyType = &strategyType
return s
}
// StopPrice set stopPrice
func (s *TestNewOrder) StopPrice(stopPrice float64) *TestNewOrder {
s.stopPrice = &stopPrice
return s
}
// TrailingDelta set trailingDelta
func (s *TestNewOrder) TrailingDelta(trailingDelta int) *TestNewOrder {
s.trailingDelta = &trailingDelta
return s
}
// IcebergQty set icebergQty
func (s *TestNewOrder) IcebergQty(icebergQty float64) *TestNewOrder {
s.icebergQty = &icebergQty
return s
}
// NewOrderRespType set newOrderRespType
func (s *TestNewOrder) NewOrderRespType(newOrderRespType string) *TestNewOrder {
s.newOrderRespType = &newOrderRespType
return s
}
// SelfTradePrevention set selfTradePrevention
func (s *TestNewOrder) SelfTradePrevention(selfTradePrevention string) *TestNewOrder {
s.selfTradePrevention = &selfTradePrevention
return s
}
// Send the request
func (s *TestNewOrder) Do(ctx context.Context, opts ...RequestOption) (res *AccountOrderBookResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/api/v3/order/test",
secType: secTypeSigned,
}
r.setParam("symbol", s.symbol)
r.setParam("side", s.side)
r.setParam("type", s.orderType)
if s.timeInForce != nil {
r.setParam("timeInForce", *s.timeInForce)
}
if s.quantity != nil {
r.setParam("quantity", strconv.FormatFloat(*s.quantity, 'f', -1, 64))
}
if s.quoteOrderQty != nil {
r.setParam("quoteOrderQty", *s.quoteOrderQty)
}
if s.price != nil {
r.setParam("price", *s.price)
}
if s.newClientOrderId != nil {
r.setParam("newClientOrderId", *s.newClientOrderId)
}
if s.strategyId != nil {
r.setParam("strategyId", *s.strategyId)
}
if s.strategyType != nil {
r.setParam("strategyType", *s.strategyType)
}
if s.stopPrice != nil {
r.setParam("stopPrice", *s.stopPrice)
}
if s.trailingDelta != nil {
r.setParam("trailingDelta", *s.trailingDelta)
}
if s.icebergQty != nil {
r.setParam("icebergQty", *s.icebergQty)
}
if s.newOrderRespType != nil {
r.setParam("newOrderRespType", *s.newOrderRespType)
}
if s.selfTradePrevention != nil {
r.setParam("selfTradePreventionMode", *s.selfTradePrevention)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(AccountOrderBookResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// Create AccountOrderBookResponse
type AccountOrderBookResponse struct {
}
// Binance New Order endpoint (POST /api/v3/order)
// CreateOrderService create order
type CreateOrderService struct {
c *Client
symbol string
side string
orderType string
timeInForce *string
quantity *float64
quoteOrderQty *float64
price *float64
newClientOrderId *string
strategyId *int
strategyType *int
stopPrice *float64
trailingDelta *int
icebergQty *float64
newOrderRespType *string
selfTradePreventionMode *string
}
// Symbol set symbol
func (s *CreateOrderService) Symbol(symbol string) *CreateOrderService {
s.symbol = symbol
return s
}
// Side set side
func (s *CreateOrderService) Side(side string) *CreateOrderService {
s.side = side
return s
}
// Type set type
func (s *CreateOrderService) Type(orderType string) *CreateOrderService {
s.orderType = orderType
return s
}
// TimeInForce set timeInForce
func (s *CreateOrderService) TimeInForce(timeInForce string) *CreateOrderService {
s.timeInForce = &timeInForce
return s
}
// Quantity set quantity
func (s *CreateOrderService) Quantity(quantity float64) *CreateOrderService {
s.quantity = &quantity
return s
}
// QuoteOrderQty set quoteOrderQty
func (s *CreateOrderService) QuoteOrderQty(quoteOrderQty float64) *CreateOrderService {
s.quoteOrderQty = "eOrderQty
return s
}
// Price set price
func (s *CreateOrderService) Price(price float64) *CreateOrderService {
s.price = &price
return s
}
// NewClientOrderId set newClientOrderId
func (s *CreateOrderService) NewClientOrderId(newClientOrderId string) *CreateOrderService {
s.newClientOrderId = &newClientOrderId
return s
}
// StrategyId set strategyId
func (s *CreateOrderService) StrategyId(strategyId int) *CreateOrderService {
s.strategyId = &strategyId
return s
}
// StrategyType set strategyType
func (s *CreateOrderService) StrategyType(strategyType int) *CreateOrderService {
s.strategyType = &strategyType
return s
}
// StopPrice set stopPrice
func (s *CreateOrderService) StopPrice(stopPrice float64) *CreateOrderService {
s.stopPrice = &stopPrice
return s
}
// TrailingDelta set trailingDelta
func (s *CreateOrderService) TrailingDelta(trailingDelta int) *CreateOrderService {
s.trailingDelta = &trailingDelta
return s
}
// IcebergQuantity set icebergQuantity
func (s *CreateOrderService) IcebergQuantity(icebergQty float64) *CreateOrderService {
s.icebergQty = &icebergQty
return s
}
// NewOrderRespType set newOrderRespType
func (s *CreateOrderService) NewOrderRespType(newOrderRespType string) *CreateOrderService {
s.newOrderRespType = &newOrderRespType
return s
}
// SelfTradePreventionMode set selfTradePreventionMode
func (s *CreateOrderService) SelfTradePreventionMode(selfTradePreventionMode string) *CreateOrderService {
s.selfTradePreventionMode = &selfTradePreventionMode
return s
}
const (
ACK = 1
RESULT = 2
FULL = 3
)
// Do send request
func (s *CreateOrderService) Do(ctx context.Context, opts ...RequestOption) (res interface{}, err error) {
respType := ACK
r := &request{
method: http.MethodPost,
endpoint: "/api/v3/order",
secType: secTypeSigned,
}
r.setParam("symbol", s.symbol)
r.setParam("side", s.side)
r.setParam("type", s.orderType)
switch s.orderType {
case "MARKET":
respType = FULL
case "LIMIT":
respType = FULL
}
if s.timeInForce != nil {
r.setParam("timeInForce", *s.timeInForce)
}
if s.quantity != nil {
r.setParam("quantity", strconv.FormatFloat(*s.quantity, 'f', -1, 64))
}
if s.quoteOrderQty != nil {
r.setParam("quoteOrderQty", *s.quoteOrderQty)
}
if s.price != nil {
r.setParam("price", *s.price)
}
if s.newClientOrderId != nil {
r.setParam("newClientOrderId", *s.newClientOrderId)
}
if s.strategyId != nil {
r.setParam("strategyId", *s.strategyId)
}
if s.strategyType != nil {
r.setParam("strategyType", *s.strategyType)
}
if s.stopPrice != nil {
r.setParam("stopPrice", *s.stopPrice)
}
if s.trailingDelta != nil {
r.setParam("trailingDelta", *s.trailingDelta)
}
if s.icebergQty != nil {
r.setParam("icebergQty", *s.icebergQty)
}
if s.newOrderRespType != nil {
r.setParam("newOrderRespType", *s.newOrderRespType)
switch *s.newOrderRespType {
case "ACK":
respType = ACK
case "RESULT":
respType = RESULT
case "FULL":
respType = FULL
}
}
if s.selfTradePreventionMode != nil {
r.setParam("selfTradePreventionMode", *s.selfTradePreventionMode)
}
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
switch respType {
case ACK:
res = new(CreateOrderResponseACK)
case RESULT:
res = new(CreateOrderResponseRESULT)
case FULL:
res = new(CreateOrderResponseFULL)
}
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// Create CreateOrderResponseACK
type CreateOrderResponseACK struct {
Symbol string `json:"symbol"`
OrderId int64 `json:"orderId"`
OrderListId int64 `json:"orderListId"`
ClientOrderId string `json:"clientOrderId"`
TransactTime uint64 `json:"transactTime"`
}
// Create CreateOrderResponseRESULT
type CreateOrderResponseRESULT struct {
Symbol string `json:"symbol"`
OrderId int64 `json:"orderId"`
OrderListId int64 `json:"orderListId"`
ClientOrderId string `json:"clientOrderId"`
TransactTime uint64 `json:"transactTime"`
Price string `json:"price"`
OrigQty string `json:"origQty"`
ExecutedQty string `json:"executedQty"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty"`
Status string `json:"status"`
TimeInForce string `json:"timeInForce"`
Type string `json:"type"`
Side string `json:"side"`
WorkingTime uint64 `json:"workingTime"`
SelfTradePreventionMode string `json:"selfTradePreventionMode"`
IcebergQty string `json:"icebergQty,omitempty"`
PreventedMatchId int64 `json:"preventedMatchId,omitempty"`
PreventedQuantity string `json:"preventedQuantity,omitempty"`
StopPrice string `json:"stopPrice,omitempty"`
StrategyId int64 `json:"strategyId,omitempty"`
StrategyType int64 `json:"strategyType,omitempty"`
TrailingDelta string `json:"trailingDelta,omitempty"`
TrailingTime int64 `json:"trailingTime,omitempty"`
}
// Create CreateOrderResponseFULL
type CreateOrderResponseFULL struct {
Symbol string `json:"symbol"`
OrderId int64 `json:"orderId"`
OrderListId int64 `json:"orderListId"`
ClientOrderId string `json:"clientOrderId"`
TransactTime uint64 `json:"transactTime"`
Price string `json:"price"`
OrigQty string `json:"origQty"`
ExecutedQty string `json:"executedQty"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty"`
Status string `json:"status"`
TimeInForce string `json:"timeInForce"`
Type string `json:"type"`
Side string `json:"side"`
WorkingTime uint64 `json:"workingTime"`
SelfTradePreventionMode string `json:"selfTradePreventionMode"`
IcebergQty string `json:"icebergQty,omitempty"`
PreventedMatchId int64 `json:"preventedMatchId,omitempty"`
PreventedQuantity string `json:"preventedQuantity,omitempty"`
StopPrice string `json:"stopPrice,omitempty"`
StrategyId int64 `json:"strategyId,omitempty"`
StrategyType int64 `json:"strategyType,omitempty"`
TrailingDelta string `json:"trailingDelta,omitempty"`
TrailingTime int64 `json:"trailingTime,omitempty"`
Fills []struct {
Price string `json:"price"`
Qty string `json:"qty"`
Commission string `json:"commission"`
CommissionAsset string `json:"commissionAsset"`
TradeId int64 `json:"tradeId"`
} `json:"fills"`
}
// Binance Cancel Order endpoint (DELETE /api/v3/order)
// CancelOrderService cancel order
type CancelOrderService struct {
c *Client
symbol string
orderId *int64
origClientOrderId *string
newClientOrderId *string
cancelRestrictions *string
}
// Symbol set symbol
func (s *CancelOrderService) Symbol(symbol string) *CancelOrderService {
s.symbol = symbol
return s
}
// OrderId set orderId
func (s *CancelOrderService) OrderId(orderId int64) *CancelOrderService {
s.orderId = &orderId
return s
}
// OrigClientOrderId set origClientOrderId
func (s *CancelOrderService) OrigClientOrderId(origClientOrderId string) *CancelOrderService {
s.origClientOrderId = &origClientOrderId
return s
}
// NewClientOrderId set newClientOrderId
func (s *CancelOrderService) NewClientOrderId(newClientOrderId string) *CancelOrderService {
s.newClientOrderId = &newClientOrderId
return s
}
// CancelRestrictions set cancelRestrictions
func (s *CancelOrderService) CancelRestrictions(cancelRestrictions string) *CancelOrderService {
s.cancelRestrictions = &cancelRestrictions
return s
}
// Do send request
func (s *CancelOrderService) Do(ctx context.Context, opts ...RequestOption) (res *CancelOrderResponse, err error) {
r := &request{
method: http.MethodDelete,
endpoint: "/api/v3/order",
secType: secTypeSigned,
}
m := params{
"symbol": s.symbol,
}
if s.orderId != nil {
m["orderId"] = *s.orderId
}
if s.origClientOrderId != nil {
m["origClientOrderId"] = *s.origClientOrderId
}
if s.newClientOrderId != nil {
m["newClientOrderId"] = *s.newClientOrderId
}
if s.cancelRestrictions != nil {
m["cancelRestrictions"] = *s.cancelRestrictions
}
r.setParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(CancelOrderResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, nil
}
// Binance Cancel all open orders on a symbol (DELETE /api/v3/openOrders)
// CancelOpenOrdersService cancel open orders
type CancelOpenOrdersService struct {
c *Client
symbol string
}
// Symbol set symbol
func (s *CancelOpenOrdersService) Symbol(symbol string) *CancelOpenOrdersService {
s.symbol = symbol
return s
}
// Do send request
func (s *CancelOpenOrdersService) Do(ctx context.Context, opts ...RequestOption) (res []*CancelOrderResponse, err error) {
r := &request{
method: http.MethodDelete,
endpoint: "/api/v3/openOrders",
secType: secTypeSigned,
}
m := params{
"symbol": s.symbol,
}
r.setParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = make([]*CancelOrderResponse, 0)
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
// Create CancelOrderResponse
type CancelOrderResponse struct {
Symbol string `json:"symbol"`
OrigClientOrderId string `json:"origClientOrderId"`
OrderId int64 `json:"orderId"`
OrderListId int64 `json:"orderListId"`
ClientOrderId string `json:"clientOrderId"`
Price string `json:"price"`
OrigQty string `json:"origQty"`
ExecutedQty string `json:"executedQty"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty"`
Status string `json:"status"`
TimeInForce string `json:"timeInForce"`
Type string `json:"type"`
Side string `json:"side"`
SelfTradePrevention string `json:"selfTradePrevention"`
IcebergQty string `json:"icebergQty,omitempty"`
PreventedMatchId int64 `json:"preventedMatchId,omitempty"`
PreventedQuantity string `json:"preventedQuantity,omitempty"`
StopPrice string `json:"stopPrice,omitempty"`
StrategyId int64 `json:"strategyId,omitempty"`
StrategyType int64 `json:"strategyType,omitempty"`
TrailingDelta string `json:"trailingDelta,omitempty"`
TrailingTime int64 `json:"trailingTime,omitempty"`
}
// Query Order (USER_DATA)
// Binance Query Order (USER_DATA) (GET /api/v3/order)
// GetOrderService get order
type GetOrderService struct {
c *Client
symbol string
orderId *int64
origClientOrderId *string
}
// Symbol set symbol
func (s *GetOrderService) Symbol(symbol string) *GetOrderService {
s.symbol = symbol
return s
}
// OrderId set orderId
func (s *GetOrderService) OrderId(orderId int64) *GetOrderService {
s.orderId = &orderId
return s
}
// OrigClientOrderId set origClientOrderId
func (s *GetOrderService) OrigClientOrderId(origClientOrderId string) *GetOrderService {
s.origClientOrderId = &origClientOrderId
return s
}
// Do send request
func (s *GetOrderService) Do(ctx context.Context, opts ...RequestOption) (res *GetOrderResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/order",
secType: secTypeSigned,
}
m := params{
"symbol": s.symbol,
}
if s.orderId != nil {
m["orderId"] = *s.orderId
}
if s.origClientOrderId != nil {
m["origClientOrderId"] = *s.origClientOrderId
}
r.setParams(m)
data, err := s.c.callAPI(ctx, r, opts...)
if err != nil {
return nil, err
}
res = new(GetOrderResponse)
err = json.Unmarshal(data, &res)
if err != nil {
return nil, err
}
return res, nil
}
// Create GetOrderResponse
type GetOrderResponse struct {
Symbol string `json:"symbol"`
OrderId int64 `json:"orderId"`
OrderListId int64 `json:"orderListId"`
ClientOrderId string `json:"clientOrderId"`
Price string `json:"price"`
OrigQty string `json:"origQty"`
ExecutedQty string `json:"executedQty"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty"`
Status string `json:"status"`
TimeInForce string `json:"timeInForce"`
Type string `json:"type"`
Side string `json:"side"`
StopPrice string `json:"stopPrice"`
IcebergQty string `json:"icebergQty,omitempty"`
Time uint64 `json:"time"`
UpdateTime uint64 `json:"updateTime"`
IsWorking bool `json:"isWorking"`
WorkingTime uint64 `json:"workingTime"`
OrigQuoteOrderQty string `json:"origQuoteOrderQty"`
SelfTradePreventionMode string `json:"selfTradePreventionMode"`
PreventedMatchId int64 `json:"preventedMatchId,omitempty"`
PreventedQuantity string `json:"preventedQuantity,omitempty"`
StrategyId int64 `json:"strategyId,omitempty"`
StrategyType int64 `json:"strategyType,omitempty"`
TrailingDelta string `json:"trailingDelta,omitempty"`
TrailingTime int64 `json:"trailingTime,omitempty"`
}
// Cancel an Existing Order and Send a New Order (TRADE)
type CancelReplaceService struct {
c *Client
symbol string
side string
orderType string
cancelReplaceMode string
timeInForce *string
quantity *float64
quoteOrderQty *float64
price *float64
cancelNewClientOrderId *string
cancelOrigClientOrderId *string
cancelOrderId *int64
newClientOrderId *string
strategyId *int32
strategyType *int32
stopPrice *float64
trailingDelta *int64
icebergQty *float64
newOrderRespType *string
selfTradePreventionMode *string
cancelRestrictions *string
}
// Symbol set symbol
func (s *CancelReplaceService) Symbol(symbol string) *CancelReplaceService {
s.symbol = symbol
return s
}
// Side set side
func (s *CancelReplaceService) Side(side string) *CancelReplaceService {
s.side = side
return s
}
// OrderType set orderType
func (s *CancelReplaceService) OrderType(orderType string) *CancelReplaceService {
s.orderType = orderType
return s
}
// CancelReplaceMode set cancelReplaceMode
func (s *CancelReplaceService) CancelReplaceMode(cancelReplaceMode string) *CancelReplaceService {
s.cancelReplaceMode = cancelReplaceMode
return s
}
// TimeInForce set timeInForce
func (s *CancelReplaceService) TimeInForce(timeInForce string) *CancelReplaceService {
s.timeInForce = &timeInForce
return s
}
// Quantity set quantity
func (s *CancelReplaceService) Quantity(quantity float64) *CancelReplaceService {
s.quantity = &quantity
return s
}
// QuoteOrderQty set quoteOrderQty
func (s *CancelReplaceService) QuoteOrderQty(quoteOrderQty float64) *CancelReplaceService {
s.quoteOrderQty = "eOrderQty
return s
}
// Price set price
func (s *CancelReplaceService) Price(price float64) *CancelReplaceService {
s.price = &price
return s
}
// CancelNewClientOrderId set cancelNewClientOrderId
func (s *CancelReplaceService) CancelNewClientOrderId(cancelNewClientOrderId string) *CancelReplaceService {
s.cancelNewClientOrderId = &cancelNewClientOrderId
return s
}
// CancelOrigClientOrderId set cancelOrigClientOrderId
func (s *CancelReplaceService) CancelOrigClientOrderId(cancelOrigClientOrderId string) *CancelReplaceService {
s.cancelOrigClientOrderId = &cancelOrigClientOrderId
return s
}
// CancelOrderId set cancelOrderId
func (s *CancelReplaceService) CancelOrderId(cancelOrderId int64) *CancelReplaceService {
s.cancelOrderId = &cancelOrderId
return s
}
// NewClientOrderId set newClientOrderId
func (s *CancelReplaceService) NewClientOrderId(newClientOrderId string) *CancelReplaceService {
s.newClientOrderId = &newClientOrderId
return s
}
// StrategyId set strategyId
func (s *CancelReplaceService) StrategyId(strategyId int32) *CancelReplaceService {
s.strategyId = &strategyId
return s
}
// StrategyType set strategyType
func (s *CancelReplaceService) StrategyType(strategyType int32) *CancelReplaceService {
s.strategyType = &strategyType
return s
}
// StopPrice set stopPrice
func (s *CancelReplaceService) StopPrice(stopPrice float64) *CancelReplaceService {
s.stopPrice = &stopPrice
return s
}
// TrailingDelta set trailingDelta
func (s *CancelReplaceService) TrailingDelta(trailingDelta int64) *CancelReplaceService {
s.trailingDelta = &trailingDelta
return s
}
// IcebergQty set icebergQty
func (s *CancelReplaceService) IcebergQty(icebergQty float64) *CancelReplaceService {
s.icebergQty = &icebergQty
return s
}
// NewOrderRespType set newOrderRespType
func (s *CancelReplaceService) NewOrderRespType(newOrderRespType string) *CancelReplaceService {
s.newOrderRespType = &newOrderRespType
return s
}
// SelfTradePreventionMode set selfTradePreventionMode
func (s *CancelReplaceService) SelfTradePreventionMode(selfTradePreventionMode string) *CancelReplaceService {
s.selfTradePreventionMode = &selfTradePreventionMode
return s
}
// CancelRestrictions set cancelRestrictions
func (s *CancelReplaceService) CancelRestrictions(cancelRestrictions string) *CancelReplaceService {
s.cancelRestrictions = &cancelRestrictions
return s
}
// Do send request
func (s *CancelReplaceService) Do(ctx context.Context, opts ...RequestOption) (res *CancelReplaceResponse, err error) {
r := &request{
method: http.MethodPost,
endpoint: "/api/v3/order/cancelReplace",
secType: secTypeSigned,
}
m := params{
"symbol": s.symbol,
"side": s.side,
"type": s.orderType,
"cancelReplaceMode": s.cancelReplaceMode,
}
if s.timeInForce != nil {
m["timeInForce"] = *s.timeInForce
}
if s.quantity != nil {
m["quantity"] = strconv.FormatFloat(*s.quantity, 'f', -1, 64)
}
if s.quoteOrderQty != nil {
m["quoteOrderQty"] = *s.quoteOrderQty
}
if s.price != nil {
m["price"] = *s.price
}
if s.cancelNewClientOrderId != nil {
m["cancelNewClientOrderId"] = *s.cancelNewClientOrderId
}
if s.cancelOrigClientOrderId != nil {
m["cancelOrigClientOrderId"] = *s.cancelOrigClientOrderId
}
if s.cancelOrderId != nil {
m["cancelOrderId"] = *s.cancelOrderId
}
if s.newClientOrderId != nil {
m["newClientOrderId"] = *s.newClientOrderId
}
if s.strategyId != nil {
m["strategyId"] = *s.strategyId
}
if s.strategyType != nil {
m["strategyType"] = *s.strategyType
}
if s.stopPrice != nil {
m["stopPrice"] = *s.stopPrice
}
if s.trailingDelta != nil {
m["trailingDelta"] = *s.trailingDelta
}
if s.icebergQty != nil {
m["icebergQty"] = *s.icebergQty
}
if s.newOrderRespType != nil {
m["newOrderRespType"] = *s.newOrderRespType
}
if s.selfTradePreventionMode != nil {
m["selfTradePreventionMode"] = *s.selfTradePreventionMode
}
if s.cancelRestrictions != nil {
m["cancelRestrictions"] = *s.cancelRestrictions
}
r.setParams(m)
data, _ := s.c.callAPI(ctx, r, opts...)
res = new(CancelReplaceResponse)
err = json.Unmarshal(data, res)
if err != nil {
return nil, err
}
return res, err
}
type CancelReplaceResponse struct {
Code int64 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
CancelResult string `json:"cancelResult,omitempty"`
NewOrderResult string `json:"newOrderResult,omitempty"`
CancelResponse *struct {
Code int `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
Symbol string `json:"symbol,omitempty"`
OrigClientOrderId string `json:"origClientOrderId,omitempty"`
OrderId int64 `json:"orderId,omitempty"`
OrderListId int64 `json:"orderListId,omitempty"`
ClientOrderId string `json:"clientOrderId,omitempty"`
Price string `json:"price,omitempty"`
OrigQty string `json:"origQty,omitempty"`
ExecutedQty string `json:"executedQty,omitempty"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty,omitempty"`
Status string `json:"status,omitempty"`
TimeInForce string `json:"timeInForce,omitempty"`
Type string `json:"type,omitempty"`
Side string `json:"side,omitempty"`
SelfTradePreventionMode string `json:"selfTradePreventionMode,omitempty"`
} `json:"cancelResponse,omitempty"`
NewOrderResponse *struct {
Code int64 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
Symbol string `json:"symbol,omitempty"`
OrderId int64 `json:"orderId,omitempty"`
OrderListId int64 `json:"orderListId,omitempty"`
ClientOrderId string `json:"clientOrderId,omitempty"`
TransactTime uint64 `json:"transactTime,omitempty"`
Price string `json:"price,omitempty"`
OrigQty string `json:"origQty,omitempty"`
ExecutedQty string `json:"executedQty,omitempty"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty,omitempty"`
Status string `json:"status,omitempty"`
TimeInForce string `json:"timeInForce,omitempty"`
Type string `json:"type,omitempty"`
Side string `json:"side,omitempty"`
Fills []struct {
Price string `json:"price"`
Qty string `json:"qty"`
Commission string `json:"commission"`
CommissionAsset string `json:"commissionAsset"`
TradeId int64 `json:"tradeId"`
} `json:"fills,omitempty"`
SelfTradePreventionMode string `json:"selfTradePreventionMode,omitempty"`
} `json:"newOrderResponse,omitempty"`
Data *struct {
CancelResult string `json:"cancelResult,omitempty"`
NewOrderResult string `json:"newOrderResult,omitempty"`
CancelResponse *struct {
Code int64 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
Symbol string `json:"symbol,omitempty"`
OrigClientOrderId string `json:"origClientOrderId,omitempty"`
OrderId int64 `json:"orderId,omitempty"`
OrderListId int64 `json:"orderListId,omitempty"`
ClientOrderId string `json:"clientOrderId,omitempty"`
Price string `json:"price,omitempty"`
OrigQty string `json:"origQty,omitempty"`
ExecutedQty string `json:"executedQty,omitempty"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty,omitempty"`
Status string `json:"status,omitempty"`
TimeInForce string `json:"timeInForce,omitempty"`
Type string `json:"type,omitempty"`
Side string `json:"side,omitempty"`
SelfTradePreventionMode string `json:"selfTradePreventionMode,omitempty"`
} `json:"cancelResponse,omitempty"`
NewOrderResponse struct {
Code int64 `json:"code,omitempty"`
Msg string `json:"msg,omitempty"`
Symbol string `json:"symbol,omitempty"`
OrderId int64 `json:"orderId,omitempty"`
OrderListId int64 `json:"orderListId,omitempty"`
ClientOrderId string `json:"clientOrderId,omitempty"`
TransactTime uint64 `json:"transactTime,omitempty"`
Price string `json:"price,omitempty"`
OrigQty string `json:"origQty,omitempty"`
ExecutedQty string `json:"executedQty,omitempty"`
CummulativeQuoteQty string `json:"cummulativeQuoteQty,omitempty"`
Status string `json:"status,omitempty"`
TimeInForce string `json:"timeInForce,omitempty"`
Type string `json:"type,omitempty"`
Side string `json:"side,omitempty"`
Fills []string `json:"fills,omitempty"`
SelfTradePreventionMode string `json:"selfTradePreventionMode,omitempty"`
} `json:"newOrderResponse"`
} `json:"data,omitempty"`
}
// Binance Get current open orders (GET /api/v3/openOrders)
// GetOpenOrdersService get open orders
type GetOpenOrdersService struct {
c *Client
symbol *string
}
// Symbol set symbol
func (s *GetOpenOrdersService) Symbol(symbol string) *GetOpenOrdersService {
s.symbol = &symbol
return s
}
// Do send request
func (s *GetOpenOrdersService) Do(ctx context.Context, opts ...RequestOption) (res []*NewOpenOrdersResponse, err error) {
r := &request{
method: http.MethodGet,
endpoint: "/api/v3/openOrders",
secType: secTypeSigned,