-
-
Notifications
You must be signed in to change notification settings - Fork 71
/
future_inverse_future.go
789 lines (681 loc) · 29.9 KB
/
future_inverse_future.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
package bybit
import (
"encoding/json"
"fmt"
"net/url"
"github.com/google/go-querystring/query"
)
// FutureInverseFutureServiceI :
type FutureInverseFutureServiceI 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)
OpenInterest(OpenInterestParam) (*OpenInterestResponse, error)
BigDeal(BigDealParam) (*BigDealResponse, error)
AccountRatio(AccountRatioParam) (*AccountRatioResponse, error)
// Account Data Endpoints
CreateFuturesOrder(CreateFuturesOrderParam) (*CreateFuturesOrderResponse, error)
ListFuturesOrder(ListFuturesOrderParam) (*ListFuturesOrderResponse, error)
CancelFuturesOrder(CancelFuturesOrderParam) (*CancelFuturesOrderResponse, error)
CancelAllFuturesOrder(CancelAllFuturesOrderParam) (*CancelAllFuturesOrderResponse, error)
QueryFuturesOrder(QueryFuturesOrderParam) (*QueryFuturesOrderResponse, error)
CreateFuturesStopOrder(CreateFuturesStopOrderParam) (*CreateFuturesStopOrderResponse, error)
ListFuturesStopOrder(ListFuturesStopOrderParam) (*ListFuturesStopOrderResponse, error)
CancelFuturesStopOrder(CancelFuturesStopOrderParam) (*CancelFuturesStopOrderResponse, error)
CancelAllFuturesStopOrder(CancelAllFuturesStopOrderParam) (*CancelAllFuturesStopOrderResponse, error)
QueryFuturesStopOrder(QueryFuturesStopOrderParam) (*QueryFuturesStopOrderResponse, error)
ListFuturesPositions(SymbolFuture) (*ListFuturesPositionsResponse, error)
FuturesTradingStop(FuturesTradingStopParam) (*FuturesTradingStopResponse, error)
FuturesSaveLeverage(FuturesSaveLeverageParam) (*FuturesSaveLeverageResponse, error)
APIKeyInfo() (*APIKeyInfoResponse, error)
// Wallet Data Endpoints
Balance(Coin) (*BalanceResponse, error)
}
// FutureInverseFutureService :
type FutureInverseFutureService struct {
client *Client
*FutureCommonService
}
// CreateFuturesOrderResponse :
type CreateFuturesOrderResponse struct {
CommonResponse `json:",inline"`
Result CreateFuturesOrderResult `json:"result"`
}
// CreateFuturesOrderResult :
type CreateFuturesOrderResult 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"`
TakeProfit string `json:"take_profit"`
StopLoss string `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
}
// CreateFuturesOrderParam :
type CreateFuturesOrderParam 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"`
PositionIdx *int `json:"position_idx,omitempty"`
ReduceOnly *bool `json:"reduce_only,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"`
}
// CreateFuturesOrder :
func (s *FutureInverseFutureService) CreateFuturesOrder(param CreateFuturesOrderParam) (*CreateFuturesOrderResponse, error) {
var res CreateFuturesOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CreateFuturesOrderParam: %w", err)
}
if err := s.client.postJSON("/futures/private/order/create", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListFuturesOrderResponse :
type ListFuturesOrderResponse struct {
CommonResponse `json:",inline"`
Result ListFuturesOrderResult `json:"result"`
}
// ListFuturesOrderResult :
type ListFuturesOrderResult struct {
ListFuturesOrders []ListFuturesOrder `json:"data"`
}
// ListFuturesOrder :
type ListFuturesOrder 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 string `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
OrderLinkID string `json:"order_link_id"`
OrderID string `json:"order_id"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
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"`
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"`
}
// ListFuturesOrderParam :
type ListFuturesOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
OrderStatus *OrderStatus `url:"order_status,omitempty"`
Direction *Direction `url:"direction,omitempty"`
Limit *int `url:"limit,omitempty"`
Cursor *string `url:"cursor,omitempty"`
}
// ListFuturesOrder :
func (s *FutureInverseFutureService) ListFuturesOrder(param ListFuturesOrderParam) (*ListFuturesOrderResponse, error) {
var res ListFuturesOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/futures/private/order/list", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelFuturesOrderResponse :
type CancelFuturesOrderResponse struct {
CommonResponse `json:",inline"`
Result CancelFuturesOrderResult `json:"result"`
}
// CancelFuturesOrderResult :
type CancelFuturesOrderResult 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"`
}
// CancelFuturesOrderParam :
type CancelFuturesOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
OrderID *string `json:"order_id,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
}
// CancelFuturesOrder :
func (s *FutureInverseFutureService) CancelFuturesOrder(param CancelFuturesOrderParam) (*CancelFuturesOrderResponse, error) {
var res CancelFuturesOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelFuturesOrderParam: %w", err)
}
if err := s.client.postJSON("/futures/private/order/cancel", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelAllFuturesOrderResponse :
type CancelAllFuturesOrderResponse struct {
CommonResponse `json:",inline"`
Result []CancelAllFuturesOrderResult `json:"result"`
}
// CancelAllFuturesOrderResult :
type CancelAllFuturesOrderResult struct {
ClOrdID string `json:"clOrdID"`
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"`
}
// CancelAllFuturesOrderParam :
type CancelAllFuturesOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
}
// CancelAllFuturesOrder :
func (s *FutureInverseFutureService) CancelAllFuturesOrder(param CancelAllFuturesOrderParam) (*CancelAllFuturesOrderResponse, error) {
var res CancelAllFuturesOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelAllFuturesOrderParam: %w", err)
}
if err := s.client.postJSON("/futures/private/order/cancelAll", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// QueryFuturesOrderResponse :
type QueryFuturesOrderResponse struct {
CommonResponse `json:",inline"`
Result QueryFuturesOrderResult `json:"result"`
}
// QueryFuturesOrderResult :
type QueryFuturesOrderResult 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"`
}
// QueryFuturesOrderParam :
type QueryFuturesOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
OrderID *string `url:"order_id,omitempty"`
OrderLinkID *string `url:"order_link_id,omitempty"`
}
// QueryFuturesOrder :
func (s *FutureInverseFutureService) QueryFuturesOrder(param QueryFuturesOrderParam) (*QueryFuturesOrderResponse, error) {
var res QueryFuturesOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/futures/private/order", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CreateFuturesStopOrderResponse :
type CreateFuturesStopOrderResponse struct {
CommonResponse `json:",inline"`
Result CreateFuturesStopOrderResult `json:"result"`
}
// CreateFuturesStopOrderResult :
type CreateFuturesStopOrderResult 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"`
}
// CreateFuturesStopOrderParam :
type CreateFuturesStopOrderParam struct {
Side Side `json:"side"`
Symbol SymbolFuture `json:"symbol"`
OrderType OrderType `json:"order_type"`
Qty float64 `json:"qty"`
BasePrice float64 `json:"base_price"`
StopPx float64 `json:"stop_px"`
TimeInForce TimeInForce `json:"time_in_force"`
PositionIdx *int `json:"position_idx,omitempty"`
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"`
}
// CreateFuturesStopOrder :
func (s *FutureInverseFutureService) CreateFuturesStopOrder(param CreateFuturesStopOrderParam) (*CreateFuturesStopOrderResponse, error) {
var res CreateFuturesStopOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CreateFuturesStopOrderParam: %w", err)
}
if err := s.client.postJSON("/futures/private/stop-order/create", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListFuturesStopOrderResponse :
type ListFuturesStopOrderResponse struct {
CommonResponse `json:",inline"`
Result ListFuturesStopOrderResult `json:"result"`
}
// ListFuturesStopOrderResult :
type ListFuturesStopOrderResult struct {
ListFuturesStopOrders []ListFuturesStopOrder `json:"data"`
}
// ListFuturesStopOrder :
type ListFuturesStopOrder 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"`
StopOrderType StopOrderTypeFuture `json:"stop_order_type"`
Price string `json:"price"`
Qty string `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
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"`
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"`
Cursor string `json:"cursor"`
}
// ListFuturesStopOrderParam :
type ListFuturesStopOrderParam 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"`
}
// ListFuturesStopOrder :
func (s *FutureInverseFutureService) ListFuturesStopOrder(param ListFuturesStopOrderParam) (*ListFuturesStopOrderResponse, error) {
var res ListFuturesStopOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/futures/private/stop-order/list", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelFuturesStopOrderResponse :
type CancelFuturesStopOrderResponse struct {
CommonResponse `json:",inline"`
Result CancelFuturesStopOrderResult `json:"result"`
}
// CancelFuturesStopOrderResult :
type CancelFuturesStopOrderResult struct {
StopOrderID string `json:"stop_order_id"`
}
// CancelFuturesStopOrderParam :
type CancelFuturesStopOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
StopOrderID *string `json:"stop_order_id,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
}
// CancelFuturesStopOrder :
func (s *FutureInverseFutureService) CancelFuturesStopOrder(param CancelFuturesStopOrderParam) (*CancelFuturesStopOrderResponse, error) {
var res CancelFuturesStopOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelFuturesStopOrderParam: %w", err)
}
if err := s.client.postJSON("/futures/private/stop-order/cancel", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelAllFuturesStopOrderResponse :
type CancelAllFuturesStopOrderResponse struct {
CommonResponse `json:",inline"`
Result []CancelAllFuturesStopOrderResult `json:"result"`
}
// CancelAllFuturesStopOrderResult :
type CancelAllFuturesStopOrderResult struct {
ClOrdID string `json:"clOrdID"`
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"`
}
// CancelAllFuturesStopOrderParam :
type CancelAllFuturesStopOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
}
// CancelAllFuturesStopOrder :
func (s *FutureInverseFutureService) CancelAllFuturesStopOrder(param CancelAllFuturesStopOrderParam) (*CancelAllFuturesStopOrderResponse, error) {
var res CancelAllFuturesStopOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelAllFuturesStopOrderParam: %w", err)
}
if err := s.client.postJSON("/futures/private/stop-order/cancelAll", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// QueryFuturesStopOrderResponse :
type QueryFuturesStopOrderResponse struct {
CommonResponse `json:",inline"`
Result QueryFuturesStopOrderResult `json:"result"`
}
// QueryFuturesStopOrderResult :
type QueryFuturesStopOrderResult 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"`
OrderStatus OrderStatus `json:"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"`
}
// QueryFuturesStopOrderParam :
type QueryFuturesStopOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
StopOrderID *string `url:"stop_order_id,omitempty"`
OrderLinkID *string `url:"order_link_id,omitempty"`
}
// QueryFuturesStopOrder :
func (s *FutureInverseFutureService) QueryFuturesStopOrder(param QueryFuturesStopOrderParam) (*QueryFuturesStopOrderResponse, error) {
var res QueryFuturesStopOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/futures/private/stop-order", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListFuturesPositionsResponse :
type ListFuturesPositionsResponse struct {
CommonResponse `json:",inline"`
Result []ListFuturesPositionsResult `json:"result"`
}
// ListFuturesPositionsResult :
type ListFuturesPositionsResult struct {
Data ListFuturesPositionsResultData `json:"data"`
}
// ListFuturesPositionsResultData :
type ListFuturesPositionsResultData struct {
ID int `json:"id"`
PositionIdx int `json:"position_idx"`
Mode int `json:"mode"`
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"`
TpSlMode TpSlMode `json:"tp_sl_mode"`
}
// ListFuturesPositions :
func (s *FutureInverseFutureService) ListFuturesPositions(symbol SymbolFuture) (*ListFuturesPositionsResponse, error) {
var res ListFuturesPositionsResponse
query := url.Values{}
query.Add("symbol", string(symbol))
if err := s.client.getPrivately("/futures/private/position/list", query, &res); err != nil {
return nil, err
}
return &res, nil
}
// FuturesTradingStopResponse :
type FuturesTradingStopResponse struct {
CommonResponse `json:",inline"`
Result FuturesTradingStopResult `json:"result"`
}
// FuturesTradingStopResult :
type FuturesTradingStopResult 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"`
}
// FuturesTradingStopParam :
type FuturesTradingStopParam struct {
Symbol SymbolFuture `json:"symbol"`
PositionIdx *int `json:"position_idx,omitempty"`
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"`
}
// FuturesTradingStop :
func (s *FutureInverseFutureService) FuturesTradingStop(param FuturesTradingStopParam) (*FuturesTradingStopResponse, error) {
var res FuturesTradingStopResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for FuturesTradingStopParam: %w", err)
}
if err := s.client.postJSON("/futures/private/position/trading-stop", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// FuturesSaveLeverageResponse :
type FuturesSaveLeverageResponse struct {
CommonResponse `json:",inline"`
Result float64 `json:"result"`
}
// FuturesSaveLeverageParam :
type FuturesSaveLeverageParam struct {
Symbol SymbolFuture `json:"symbol"`
BuyLeverage float64 `json:"buy_leverage"`
SellLeverage float64 `json:"sell_leverage"`
}
// FuturesSaveLeverage :
func (s *FutureInverseFutureService) FuturesSaveLeverage(param FuturesSaveLeverageParam) (*FuturesSaveLeverageResponse, error) {
var res FuturesSaveLeverageResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for FuturesSaveLeverageParam: %w", err)
}
if err := s.client.postJSON("/futures/private/position/leverage/save", body, &res); err != nil {
return nil, err
}
return &res, nil
}