-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
future_inverse_perpetual.go
856 lines (732 loc) · 29.7 KB
/
future_inverse_perpetual.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
package bybit
import (
"encoding/json"
"fmt"
"net/url"
"github.com/google/go-querystring/query"
)
// FutureInversePerpetualServiceI :
type FutureInversePerpetualServiceI interface {
// Market Data Endpoints
OrderBook(SymbolFuture) (*OrderBookResponse, error)
ListKline(ListKlineParam) (*ListKlineResponse, error)
Tickers(SymbolFuture) (*TickersResponse, error)
TradingRecords(TradingRecordsParam) (*TradingRecordsResponse, error)
Symbols() (*SymbolsResponse, error)
MarkPriceKline(MarkPriceKlineParam) (*MarkPriceKlineResponse, error)
IndexPriceKline(IndexPriceKlineParam) (*IndexPriceKlineResponse, error)
PremiumIndexKline(PremiumIndexKlineParam) (*PremiumIndexKlineResponse, error)
OpenInterest(OpenInterestParam) (*OpenInterestResponse, error)
BigDeal(BigDealParam) (*BigDealResponse, error)
AccountRatio(AccountRatioParam) (*AccountRatioResponse, error)
// Account Data Endpoints
CreateOrder(CreateOrderParam) (*CreateOrderResponse, error)
ListOrder(ListOrderParam) (*ListOrderResponse, error)
CancelOrder(CancelOrderParam) (*CancelOrderResponse, error)
CancelAllOrder(CancelAllOrderParam) (*CancelAllOrderResponse, error)
QueryOrder(QueryOrderParam) (*QueryOrderResponse, error)
CreateStopOrder(CreateStopOrderParam) (*CreateStopOrderResponse, error)
ListStopOrder(ListStopOrderParam) (*ListStopOrderResponse, error)
CancelStopOrder(CancelStopOrderParam) (*CancelStopOrderResponse, error)
CancelAllStopOrder(CancelAllStopOrderParam) (*CancelAllStopOrderResponse, error)
QueryStopOrder(QueryStopOrderParam) (*QueryStopOrderResponse, error)
ListPosition(SymbolFuture) (*ListPositionResponse, error)
ListPositions() (*ListPositionsResponse, error)
TradingStop(TradingStopParam) (*TradingStopResponse, error)
SaveLeverage(SaveLeverageParam) (*SaveLeverageResponse, error)
APIKeyInfo() (*APIKeyInfoResponse, error)
// Wallet Data Endpoints
Balance(Coin) (*BalanceResponse, error)
}
// FutureInversePerpetualService :
type FutureInversePerpetualService struct {
client *Client
*FutureCommonService
}
// PremiumIndexKlineResponse :
type PremiumIndexKlineResponse struct {
CommonResponse `json:",inline"`
Result []PremiumIndexKlineResult `json:"result"`
}
// PremiumIndexKlineResult :
type PremiumIndexKlineResult struct {
Symbol SymbolFuture `json:"symbol"`
Period Period `json:"period"`
OpenTime int `json:"open_time"`
Open string `json:"open"`
High string `json:"high"`
Low string `json:"low"`
Close string `json:"close"`
}
// PremiumIndexKlineParam :
type PremiumIndexKlineParam struct {
Symbol SymbolFuture `url:"symbol"`
Interval Interval `url:"interval"`
From int64 `url:"from"`
Limit *int `url:"limit,omitempty"`
}
// PremiumIndexKline :
func (s *FutureInversePerpetualService) PremiumIndexKline(param PremiumIndexKlineParam) (*PremiumIndexKlineResponse, error) {
var res PremiumIndexKlineResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPublicly("/v2/public/premium-index-kline", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CreateOrderResponse :
type CreateOrderResponse struct {
CommonResponse `json:",inline"`
Result CreateOrderResult `json:"result"`
}
// CreateOrderResult :
type CreateOrderResult struct {
CreateOrder `json:",inline"`
}
// CreateOrder :
type CreateOrder struct {
UserID int `json:"user_id"`
OrderID string `json:"order_id"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price float64 `json:"price"`
Qty float64 `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
OrderStatus OrderStatus `json:"order_status"`
LastExecTime float64 `json:"last_exec_time"`
LastExecPrice float64 `json:"last_exec_price"`
LeavesQty float64 `json:"leaves_qty"`
CumExecQty float64 `json:"cum_exec_qty"`
CumExecValue float64 `json:"cum_exec_value"`
CumExecFee float64 `json:"cum_exec_fee"`
RejectReason string `json:"reject_reason"`
OrderLinkID string `json:"order_link_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// CreateOrderParam :
type CreateOrderParam struct {
Side Side `json:"side"`
Symbol SymbolFuture `json:"symbol"`
OrderType OrderType `json:"order_type"`
Qty int `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
Price *float64 `json:"price,omitempty"`
TakeProfit *float64 `json:"take_profit,omitempty"`
StopLoss *float64 `json:"stop_loss,omitempty"`
ReduceOnly *bool `json:"reduce_only,omitempty"`
CloseOnTrigger *bool `json:"close_on_trigger,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
}
// CreateOrder :
func (s *FutureInversePerpetualService) CreateOrder(param CreateOrderParam) (*CreateOrderResponse, error) {
var res CreateOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CreateOrderParam: %w", err)
}
if err := s.client.postJSON("/v2/private/order/create", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListOrderResponse :
type ListOrderResponse struct {
CommonResponse `json:",inline"`
Result ListOrderResult `json:"result"`
}
// ListOrderResult :
type ListOrderResult struct {
ListOrders []ListOrder `json:"data"`
}
// ListOrder :
type ListOrder struct {
UserID int `json:"user_id"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price string `json:"price"`
Qty string `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
OrderStatus OrderStatus `json:"order_status"`
LeavesQty string `json:"leaves_qty"`
LeavesValue string `json:"leaves_value"`
CumExecQty string `json:"cum_exec_qty"`
CumExecValue string `json:"cum_exec_value"`
CumExecFee string `json:"cum_exec_fee"`
RejectReason string `json:"reject_reason"`
OrderLinkID string `json:"order_link_id"`
CreatedAt string `json:"created_at"`
OrderID string `json:"order_id"`
TakeProfit string `json:"take_profit"`
StopLoss string `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
}
// ListOrderParam :
type ListOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
OrderStatus *OrderStatus `url:"order_status,omitempty"`
Direction *Direction `url:"direction,omitempty"`
Size *int `url:"size,omitempty"`
Cursor *string `url:"cursor,omitempty"`
}
// ListOrder :
func (s *FutureInversePerpetualService) ListOrder(param ListOrderParam) (*ListOrderResponse, error) {
var res ListOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/v2/private/order/list", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListPositionResponse :
type ListPositionResponse struct {
CommonResponse `json:",inline"`
Result ListPositionResult `json:"result"`
}
// ListPositionResult :
type ListPositionResult struct {
ID int `json:"id"`
UserID int `json:"user_id"`
RiskID int `json:"risk_id"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
Size float64 `json:"size"`
PositionValue string `json:"position_value"`
EntryPrice string `json:"entry_price"`
IsIsolated bool `json:"is_isolated"`
AutoAddMargin float64 `json:"auto_add_margin"`
Leverage string `json:"leverage"`
EffectiveLeverage string `json:"effective_leverage"`
PositionMargin string `json:"position_margin"`
LiqPrice string `json:"liq_price"`
BustPrice string `json:"bust_price"`
OccClosingFee string `json:"occ_closing_fee"`
OccFundingFee string `json:"occ_funding_fee"`
TakeProfit string `json:"take_profit"`
StopLoss string `json:"stop_loss"`
TrailingStop string `json:"trailing_stop"`
PositionStatus string `json:"position_status"`
DeleverageIndicator int `json:"deleverage_indicator"`
OcCalcData string `json:"oc_calc_data"`
OrderMargin string `json:"order_margin"`
WalletBalance string `json:"wallet_balance"`
RealisedPnl string `json:"realised_pnl"`
UnrealisedPnl float64 `json:"unrealised_pnl"`
CumRealisedPnl string `json:"cum_realised_pnl"`
CrossSeq float64 `json:"cross_seq"`
PositionSeq float64 `json:"position_seq"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// ListPosition :
func (s *FutureInversePerpetualService) ListPosition(symbol SymbolFuture) (*ListPositionResponse, error) {
var res ListPositionResponse
query := url.Values{}
query.Add("symbol", string(symbol))
if err := s.client.getPrivately("/v2/private/position/list", query, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListPositionsResponse :
type ListPositionsResponse struct {
CommonResponse `json:",inline"`
Result []ListPositionsResult `json:"result"`
}
// ListPositionsResult :
type ListPositionsResult struct {
IsValid bool `json:"is_valid"`
ListPositionResult `json:"data,inline"`
}
// ListPositions :
func (s *FutureInversePerpetualService) ListPositions() (*ListPositionsResponse, error) {
var res ListPositionsResponse
if err := s.client.getPrivately("/v2/private/position/list", nil, &res); err != nil {
return nil, err
}
return &res, nil
}
// TradingStopResponse :
type TradingStopResponse struct {
CommonResponse `json:",inline"`
Result TradingStopResult `json:"result"`
}
// TradingStopResult :
type TradingStopResult struct {
ID int `json:"id"`
UserID int `json:"user_id"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
Size float64 `json:"size"`
PositionValue float64 `json:"position_value"`
EntryPrice float64 `json:"entry_price"`
RiskID int `json:"risk_id"`
AutoAddMargin float64 `json:"auto_add_margin"`
Leverage float64 `json:"leverage"`
PositionMargin float64 `json:"position_margin"`
LiqPrice float64 `json:"liq_price"`
BustPrice float64 `json:"bust_price"`
OccClosingFee float64 `json:"occ_closing_fee"`
OccFundingFee float64 `json:"occ_funding_fee"`
TakeProfit float64 `json:"take_profit"`
StopLoss float64 `json:"stop_loss"`
TrailingStop float64 `json:"trailing_stop"`
PositionStatus string `json:"position_status"`
DeleverageIndicator int `json:"deleverage_indicator"`
OcCalcData string `json:"oc_calc_data"`
OrderMargin float64 `json:"order_margin"`
WalletBalance float64 `json:"wallet_balance"`
RealisedPnl float64 `json:"realised_pnl"`
CumRealisedPnl float64 `json:"cum_realised_pnl"`
CumCommission float64 `json:"cum_commission"`
CrossSeq float64 `json:"cross_seq"`
PositionSeq float64 `json:"position_seq"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
ExtFields map[string]interface{} `json:"ext_fields"`
}
// TradingStopParam :
type TradingStopParam struct {
Symbol SymbolFuture `json:"symbol"`
TakeProfit *float64 `json:"take_profit,omitempty"`
StopLoss *float64 `json:"stop_loss,omitempty"`
TrailingStop *float64 `json:"trailing_stop,omitempty"`
TpTriggerBy *TriggerByFuture `json:"tp_trigger_by,omitempty"`
SlTriggerBy *TriggerByFuture `json:"sl_trigger_by,omitempty"`
NewTrailingActive *float64 `json:"new_trailing_active,omitempty"`
SlSize *float64 `json:"sl_size,omitempty"`
TpSize *float64 `json:"tp_size,omitempty"`
}
// TradingStop :
func (s *FutureInversePerpetualService) TradingStop(param TradingStopParam) (*TradingStopResponse, error) {
var res TradingStopResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for TradingStopParam: %w", err)
}
if err := s.client.postJSON("/v2/private/position/trading-stop", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelOrderResponse :
type CancelOrderResponse struct {
CommonResponse `json:",inline"`
Result CancelOrderResult `json:"result"`
}
// CancelOrderResult :
type CancelOrderResult struct {
CancelOrder `json:",inline"`
}
// CancelOrder :
// so far, same as CreateOrder
type CancelOrder struct {
UserID int `json:"user_id"`
OrderID string `json:"order_id"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price float64 `json:"price"`
Qty float64 `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
OrderStatus OrderStatus `json:"order_status"`
LastExecTime float64 `json:"last_exec_time"`
LastExecPrice float64 `json:"last_exec_price"`
LeavesQty float64 `json:"leaves_qty"`
CumExecQty float64 `json:"cum_exec_qty"`
CumExecValue float64 `json:"cum_exec_value"`
CumExecFee float64 `json:"cum_exec_fee"`
RejectReason string `json:"reject_reason"`
OrderLinkID string `json:"order_link_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
}
// CancelOrderParam :
type CancelOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
OrderID *string `json:"order_id,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
}
// CancelOrder :
func (s *FutureInversePerpetualService) CancelOrder(param CancelOrderParam) (*CancelOrderResponse, error) {
var res CancelOrderResponse
if param.OrderID == nil && param.OrderLinkID == nil {
return nil, fmt.Errorf("either OrderID or OrderLinkID needed")
}
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelOrderParam: %w", err)
}
if err := s.client.postJSON("/v2/private/order/cancel", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelAllOrderResponse :
type CancelAllOrderResponse struct {
CommonResponse `json:",inline"`
Result []CancelAllOrderResult `json:"result"`
}
// CancelAllOrderResult :
type CancelAllOrderResult struct {
ClOrdID string `json:"clOrdID"`
OrderLinkID string `json:"order_link_id"`
UserID int `json:"user_id"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price string `json:"price"`
Qty float64 `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
CreateType string `json:"create_type"`
CancelType string `json:"cancel_type"`
OrderStatus OrderStatus `json:"order_status"`
LeavesQty float64 `json:"leaves_qty"`
LeavesValue string `json:"leaves_value"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
CrossStatus string `json:"cross_status"`
CrossSeq int `json:"cross_seq"`
}
// CancelAllOrderParam :
type CancelAllOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
}
// CancelAllOrder :
func (s *FutureInversePerpetualService) CancelAllOrder(param CancelAllOrderParam) (*CancelAllOrderResponse, error) {
var res CancelAllOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelAllOrderParam: %w", err)
}
if err := s.client.postJSON("/v2/private/order/cancelAll", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// QueryOrderResponse :
type QueryOrderResponse struct {
CommonResponse `json:",inline"`
Result []QueryOrderResult `json:"result"`
}
// QueryOrderResult :
type QueryOrderResult struct {
UserID int `json:"user_id"`
PositionIdx int `json:"position_idx"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price string `json:"price"`
Qty float64 `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
OrderStatus OrderStatus `json:"order_status"`
ExtFields map[string]interface{} `json:"ext_fields"`
LastExecTime string `json:"last_exec_time"`
LeavesQty int `json:"leaves_qty"`
LeavesValue string `json:"leaves_value"`
CumExecQty int `json:"cum_exec_qty"`
CumExecValue string `json:"cum_exec_value"`
CumExecFee string `json:"cum_exec_fee"`
RejectReason string `json:"reject_reason"`
CancelType string `json:"cancel_type"`
OrderLinkID string `json:"order_link_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
OrderID string `json:"order_id"`
TakeProfit string `json:"take_profit"`
StopLoss string `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
}
// QueryOrderParam :
type QueryOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
OrderID *string `url:"order_id,omitempty"`
OrderLinkID *string `url:"order_link_id,omitempty"`
}
// QueryOrder :
func (s *FutureInversePerpetualService) QueryOrder(param QueryOrderParam) (*QueryOrderResponse, error) {
var res QueryOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/v2/private/order", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CreateStopOrderResponse :
type CreateStopOrderResponse struct {
CommonResponse `json:",inline"`
Result CreateStopOrderResult `json:"result"`
}
// CreateStopOrderResult :
type CreateStopOrderResult struct {
UserID int `json:"user_id"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price string `json:"price"`
Qty string `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
Remark string `json:"remark"`
LeavesQty string `json:"leaves_qty"`
LeavesValue string `json:"leaves_value"`
StopPx string `json:"stop_px"`
RejectReason string `json:"reject_reason"`
StopOrderID string `json:"stop_order_id"`
OrderLinkID string `json:"order_link_id"`
TriggerBy TriggerByFuture `json:"trigger_by"`
BasePrice string `json:"base_price"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
TakeProfit string `json:"take_profit"`
StopLoss string `json:"stop_loss"`
}
// CreateStopOrderParam :
type CreateStopOrderParam struct {
Side Side `json:"side"`
Symbol SymbolFuture `json:"symbol"`
OrderType OrderType `json:"order_type"`
Qty int `json:"qty"`
BasePrice float64 `json:"base_price"`
StopPx float64 `json:"stop_px"`
TimeInForce TimeInForce `json:"time_in_force"`
Price *float64 `json:"price,omitempty"`
TriggerBy *TriggerByFuture `json:"trigger_by,omitempty"`
CloseOnTrigger *bool `json:"close_on_trigger,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
TakeProfit *float64 `json:"take_profit,omitempty"`
StopLoss *float64 `json:"stop_loss,omitempty"`
TpTriggerBy *TriggerByFuture `json:"tp_trigger_by,omitempty"`
SlTriggerBy *TriggerByFuture `json:"sl_trigger_by,omitempty"`
}
// CreateStopOrder :
func (s *FutureInversePerpetualService) CreateStopOrder(param CreateStopOrderParam) (*CreateStopOrderResponse, error) {
var res CreateStopOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CreateStopOrderParam: %w", err)
}
if err := s.client.postJSON("/v2/private/stop-order/create", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListStopOrderResponse :
type ListStopOrderResponse struct {
CommonResponse `json:",inline"`
Result ListStopOrderResult `json:"result"`
}
// ListStopOrderResult :
type ListStopOrderResult struct {
ListStopOrders []ListStopOrder `json:"data"`
}
// ListStopOrder :
type ListStopOrder struct {
UserID int `json:"user_id"`
PositionIdx int `json:"position_idx"`
StopOrderStatus OrderStatus `json:"stop_order_status"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price string `json:"price"`
Qty string `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
StopOrderType StopOrderTypeFuture `json:"stop_order_type"`
TriggerBy TriggerByFuture `json:"trigger_by"`
BasePrice string `json:"base_price"`
OrderLinkID string `json:"order_link_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
StopPx string `json:"stop_px"`
StopOrderID string `json:"stop_order_id"`
TakeProfit string `json:"take_profit"`
StopLoss string `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
Cursor string `json:"cursor"`
}
// ListStopOrderParam :
type ListStopOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
StopOrderStatus *OrderStatus `url:"stop_order_status,omitempty"`
Direction *Direction `url:"direction,omitempty"`
Limit *int `url:"limit,omitempty"`
Cursor *string `url:"cursor,omitempty"`
}
// ListStopOrder :
func (s *FutureInversePerpetualService) ListStopOrder(param ListStopOrderParam) (*ListStopOrderResponse, error) {
var res ListStopOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/v2/private/stop-order/list", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelStopOrderResponse :
type CancelStopOrderResponse struct {
CommonResponse `json:",inline"`
Result CancelStopOrderResult `json:"result"`
}
// CancelStopOrderResult :
type CancelStopOrderResult struct {
StopOrderID string `json:"stop_order_id"`
}
// CancelStopOrderParam :
type CancelStopOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
StopOrderID *string `json:"stop_order_id,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
}
// CancelStopOrder :
func (s *FutureInversePerpetualService) CancelStopOrder(param CancelStopOrderParam) (*CancelStopOrderResponse, error) {
var res CancelStopOrderResponse
if param.StopOrderID == nil && param.OrderLinkID == nil {
return nil, fmt.Errorf("either StopOrderID or OrderLinkID needed")
}
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelStopOrderParam: %w", err)
}
if err := s.client.postJSON("/v2/private/stop-order/cancel", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelAllStopOrderResponse :
type CancelAllStopOrderResponse struct {
CommonResponse `json:",inline"`
Result []CancelAllStopOrderResult `json:"result"`
}
// CancelAllStopOrderResult :
type CancelAllStopOrderResult struct {
ClOrdID string `json:"clOrdID"`
OrderLinkID string `json:"order_link_id"`
UserID int `json:"user_id"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price string `json:"price"`
Qty float64 `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
CreateType string `json:"create_type"`
CancelType string `json:"cancel_type"`
OrderStatus OrderStatus `json:"order_status"`
LeavesQty float64 `json:"leaves_qty"`
LeavesValue string `json:"leaves_value"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
CrossStatus string `json:"cross_status"`
CrossSeq int `json:"cross_seq"`
StopOrderType StopOrderTypeFuture `json:"stop_order_type"`
TriggerBy TriggerByFuture `json:"trigger_by"`
BasePrice string `json:"base_price"`
ExpectedDirection string `json:"expected_direction"`
}
// CancelAllStopOrderParam :
type CancelAllStopOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
}
// CancelAllStopOrder :
func (s *FutureInversePerpetualService) CancelAllStopOrder(param CancelAllStopOrderParam) (*CancelAllStopOrderResponse, error) {
var res CancelAllStopOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelAllStopOrderParam: %w", err)
}
if err := s.client.postJSON("/v2/private/stop-order/cancelAll", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// QueryStopOrderResponse :
type QueryStopOrderResponse struct {
CommonResponse `json:",inline"`
Result []QueryStopOrderResult `json:"result"`
}
// QueryStopOrderResult :
type QueryStopOrderResult struct {
UserID int `json:"user_id"`
PositionIdx int `json:"position_idx"`
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
OrderType OrderType `json:"order_type"`
Price string `json:"price"`
Qty float64 `json:"qty"`
StopPx string `json:"stop_px"`
BasePrice string `json:"base_price"`
TimeInForce TimeInForce `json:"time_in_force"`
StopOrderStatus OrderStatus `json:"stop_order_status"`
ExtFields map[string]interface{} `json:"ext_fields"`
LeavesQty int `json:"leaves_qty"`
LeavesValue string `json:"leaves_value"`
CumExecQty int `json:"cum_exec_qty"`
CumExecValue string `json:"cum_exec_value"`
CumExecFee string `json:"cum_exec_fee"`
RejectReason string `json:"reject_reason"`
OrderLinkID string `json:"order_link_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
OrderID string `json:"order_id"`
TriggerBy TriggerByFuture `json:"trigger_by"`
TakeProfit string `json:"take_profit"`
StopLoss string `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
}
// QueryStopOrderParam :
type QueryStopOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
StopOrderID *string `url:"stop_order_id,omitempty"`
OrderLinkID *string `url:"order_link_id,omitempty"`
}
// QueryStopOrder :
func (s *FutureInversePerpetualService) QueryStopOrder(param QueryStopOrderParam) (*QueryStopOrderResponse, error) {
var res QueryStopOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/v2/private/stop-order", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// SaveLeverageResponse :
type SaveLeverageResponse struct {
CommonResponse `json:",inline"`
Result float64 `json:"result"`
}
// SaveLeverageParam :
type SaveLeverageParam struct {
Symbol SymbolFuture `json:"symbol"`
Leverage float64 `json:"leverage"`
}
// SaveLeverage :
func (s *FutureInversePerpetualService) SaveLeverage(param SaveLeverageParam) (*SaveLeverageResponse, error) {
var res SaveLeverageResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelOrderParam: %w", err)
}
if err := s.client.postJSON("/v2/private/position/leverage/save", body, &res); err != nil {
return nil, err
}
return &res, nil
}