forked from hirokisan/bybit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
future_usdt_perpetual.go
855 lines (715 loc) · 29 KB
/
future_usdt_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
package bybit
import (
"encoding/json"
"fmt"
"net/url"
"github.com/google/go-querystring/query"
)
// FutureUSDTPerpetualServiceI :
type FutureUSDTPerpetualServiceI interface {
// Market Data Endpoints
OrderBook(SymbolFuture) (*OrderBookResponse, error)
ListLinearKline(ListLinearKlineParam) (*ListLinearKlineResponse, error)
Tickers(SymbolFuture) (*TickersResponse, error)
Symbols() (*SymbolsResponse, error)
OpenInterest(OpenInterestParam) (*OpenInterestResponse, error)
BigDeal(BigDealParam) (*BigDealResponse, error)
AccountRatio(AccountRatioParam) (*AccountRatioResponse, error)
// Account Data Endpoints
CreateLinearOrder(CreateLinearOrderParam) (*CreateLinearOrderResponse, error)
ListLinearOrder(ListLinearOrderParam) (*ListLinearOrderResponse, error)
CancelLinearOrder(CancelLinearOrderParam) (*CancelLinearOrderResponse, error)
LinearCancelAllOrder(LinearCancelAllParam) (*LinearCancelAllResponse, error)
ReplaceLinearOrder(ReplaceLinearOrderParam) (*ReplaceLinearOrderResponse, error)
QueryLinearOrder(QueryLinearOrderParam) (*QueryLinearOrderResponse, error)
CreateLinearStopOrder(CreateLinearStopOrderParam) (*CreateLinearStopOrderResponse, error)
ListLinearStopOrder(ListLinearStopOrderParam) (*ListLinearStopOrderResponse, error)
CancelLinearStopOrder(CancelLinearStopOrderParam) (*CancelLinearStopOrderResponse, error)
CancelAllLinearStopOrder(CancelAllLinearStopOrderParam) (*CancelAllLinearStopOrderResponse, error)
QueryLinearStopOrder(QueryLinearStopOrderParam) (*QueryLinearStopOrderResponse, error)
ListLinearPosition(SymbolFuture) (*ListLinearPositionResponse, error)
ListLinearPositions() (*ListLinearPositionsResponse, error)
SaveLinearLeverage(SaveLinearLeverageParam) (*SaveLinearLeverageResponse, error)
LinearTradingStop(LinearTradingStopParam) (*LinearTradingStopResponse, error)
LinearExecutionList(LinearExecutionListParam) (*LinearExecutionListResponse, error)
APIKeyInfo() (*APIKeyInfoResponse, error)
// Wallet Data Endpoints
Balance(Coin) (*BalanceResponse, error)
}
// FutureUSDTPerpetualService :
type FutureUSDTPerpetualService struct {
client *Client
*FutureCommonService
}
// ListLinearKlineParam :
type ListLinearKlineParam struct {
Symbol SymbolFuture `url:"symbol"`
Interval Interval `url:"interval"`
From int64 `url:"from"`
Limit *int `url:"limit,omitempty"`
}
// ListLinearKlineResponse :
type ListLinearKlineResponse struct {
CommonResponse `json:",inline"`
Result []ListLinearKlineResult `json:"result"`
}
// ListLinearKlineResult :
type ListLinearKlineResult struct {
Symbol SymbolFuture `json:"symbol"`
Period Period `json:"period"`
Interval string `json:"interval"`
StartAt int `json:"start_at"`
OpenTime int `json:"open_time"`
Volume float64 `json:"volume"`
Open float64 `json:"open"`
High float64 `json:"high"`
Low float64 `json:"low"`
Close float64 `json:"close"`
Turnover float64 `json:"turnover"`
}
// ListLinearKline :
func (s *FutureCommonService) ListLinearKline(param ListLinearKlineParam) (*ListLinearKlineResponse, error) {
var res ListLinearKlineResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPublicly("/public/linear/kline", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CreateLinearOrderResponse :
type CreateLinearOrderResponse struct {
CommonResponse `json:",inline"`
Result CreateLinearOrderResult `json:"result"`
}
// CreateLinearOrderResult :
type CreateLinearOrderResult struct {
CreateLinearOrder `json:",inline"`
}
// CreateLinearOrder :
type CreateLinearOrder struct {
OrderID string `json:"order_id"`
UserID int `json:"user_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"`
LastExecPrice float64 `json:"last_exec_price"`
CumExecQty float64 `json:"cum_exec_qty"`
CumExecValue float64 `json:"cum_exec_value"`
CumExecFee float64 `json:"cum_exec_fee"`
ReduceOnly bool `json:"reduce_only"`
CloseOnTrigger bool `json:"close_on_trigger"`
OrderLinkID string `json:"order_link_id"`
CreatedTime string `json:"created_time"`
UpdatedTime string `json:"updated_time"`
TakeProfit float64 `json:"take_profit"`
StopLoss float64 `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
}
// CreateLinearOrderParam :
type CreateLinearOrderParam struct {
Side Side `json:"side"`
Symbol SymbolFuture `json:"symbol"`
OrderType OrderType `json:"order_type"`
Qty float64 `json:"qty"`
TimeInForce TimeInForce `json:"time_in_force"`
ReduceOnly bool `json:"reduce_only"`
CloseOnTrigger bool `json:"close_on_trigger"`
Price *float64 `json:"price,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"`
OrderLinkID *string `json:"order_link_id,omitempty"`
PositionIdx *int `json:"position_idx,omitempty"`
}
// CreateLinearOrder :
func (s *FutureUSDTPerpetualService) CreateLinearOrder(param CreateLinearOrderParam) (*CreateLinearOrderResponse, error) {
var res CreateLinearOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CreateLinearOrderParam: %w", err)
}
if err := s.client.postJSON("/private/linear/order/create", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListLinearOrderResponse :
type ListLinearOrderResponse struct {
CommonResponse `json:",inline"`
Result ListLinearOrderResult `json:"result"`
}
// ListLinearOrderResult :
type ListLinearOrderResult struct {
CurrentPage int `json:"current_page"`
Content []ListLinearOrderResultContent `json:"data"`
}
// ListLinearOrderResultContent :
type ListLinearOrderResultContent struct {
OrderID string `json:"order_id"`
UserID int `json:"user_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"`
LastExecPrice float64 `json:"last_exec_price"`
CumExecQty float64 `json:"cum_exec_qty"`
CumExecValue float64 `json:"cum_exec_value"`
CumExecFee float64 `json:"cum_exec_fee"`
ReduceOnly bool `json:"reduce_only"`
CloseOnTrigger bool `json:"close_on_trigger"`
OrderLinkID string `json:"order_link_id"`
CreatedTime string `json:"created_time"`
UpdatedTime string `json:"updated_time"`
TakeProfit float64 `json:"take_profit"`
StopLoss float64 `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
}
// ListLinearOrderParam :
type ListLinearOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
OrderID *string `url:"order_id,omitempty"`
OrderLinkID *string `url:"order_link_id,omitempty"`
Order *Order `url:"order,omitempty"`
Page *int `url:"page,omitempty"`
Limit *int `url:"limit,omitempty"`
OrderStatus *OrderStatus `url:"order_status,omitempty"`
}
// ListLinearOrder :
func (s *FutureUSDTPerpetualService) ListLinearOrder(param ListLinearOrderParam) (*ListLinearOrderResponse, error) {
var res ListLinearOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/private/linear/order/list", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListLinearPositionResponse :
type ListLinearPositionResponse struct {
CommonResponse `json:",inline"`
Result []ListLinearPositionResult `json:"result"`
}
// ListLinearPositionResult :
type ListLinearPositionResult struct {
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"`
LiqPrice float64 `json:"liq_price"`
BustPrice float64 `json:"bust_price"`
Leverage float64 `json:"leverage"`
AutoAddMargin float64 `json:"auto_add_margin"`
IsIsolated bool `json:"is_isolated"`
PositionMargin float64 `json:"position_margin"`
OccClosingFee float64 `json:"occ_closing_fee"`
RealisedPnl float64 `json:"realised_pnl"`
CumRealisedPnl float64 `json:"cum_realised_pnl"`
FreeQty float64 `json:"free_qty"`
TpSlMode TpSlMode `json:"tp_sl_mode"`
DeleverageIndicator int `json:"deleverage_indicator"`
UnrealisedPnl float64 `json:"unrealised_pnl"`
RiskID int `json:"risk_id"`
}
// ListLinearPosition :
func (s *FutureUSDTPerpetualService) ListLinearPosition(symbol SymbolFuture) (*ListLinearPositionResponse, error) {
var res ListLinearPositionResponse
query := url.Values{}
query.Add("symbol", string(symbol))
if err := s.client.getPrivately("/private/linear/position/list", query, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListLinearPositionsResponse :
type ListLinearPositionsResponse struct {
CommonResponse `json:",inline"`
Result []ListLinearPositionsResult `json:"result"`
}
// ListLinearPositionsResult :
type ListLinearPositionsResult struct {
IsValid bool `json:"is_valid"`
ListLinearPositionResult `json:"data,inline"`
}
// ListLinearPositions :
func (s *FutureUSDTPerpetualService) ListLinearPositions() (*ListLinearPositionsResponse, error) {
var res ListLinearPositionsResponse
if err := s.client.getPrivately("/private/linear/position/list", nil, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelLinearOrderResponse :
type CancelLinearOrderResponse struct {
CommonResponse `json:",inline"`
Result CancelLinearOrderResult `json:"result"`
}
// CancelLinearOrderResult :
type CancelLinearOrderResult struct {
CancelLinearOrder `json:",inline"`
}
// CancelLinearOrder :
type CancelLinearOrder struct {
OrderID string `json:"order_id"`
}
// CancelLinearOrderParam :
type CancelLinearOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
OrderID *string `json:"order_id,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
}
// CancelLinearOrder :
func (s *FutureUSDTPerpetualService) CancelLinearOrder(param CancelLinearOrderParam) (*CancelLinearOrderResponse, error) {
var res CancelLinearOrderResponse
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 CancelLinearOrderParam: %w", err)
}
if err := s.client.postJSON("/private/linear/order/cancel", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// SaveLinearLeverageResponse :
type SaveLinearLeverageResponse struct {
CommonResponse `json:",inline"`
}
// SaveLinearLeverageParam :
type SaveLinearLeverageParam struct {
Symbol SymbolFuture `json:"symbol"`
BuyLeverage float64 `json:"buy_leverage"`
SellLeverage float64 `json:"sell_leverage"`
}
// SaveLinearLeverage :
func (s *FutureUSDTPerpetualService) SaveLinearLeverage(param SaveLinearLeverageParam) (*SaveLinearLeverageResponse, error) {
var res SaveLinearLeverageResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for SaveLinearLeverageParam: %w", err)
}
if err := s.client.postJSON("/private/linear/position/set-leverage", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// LinearTradingStopResponse :
type LinearTradingStopResponse struct {
CommonResponse `json:",inline"`
}
// LinearTradingStopParam :
type LinearTradingStopParam struct {
Symbol SymbolFuture `json:"symbol"`
Side Side `json:"side"`
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"`
SlSize *float64 `json:"sl_size,omitempty"`
TpSize *float64 `json:"tp_size,omitempty"`
PositionIdx *int `json:"position_idx,omitempty"`
}
// LinearTradingStop :
func (s *FutureUSDTPerpetualService) LinearTradingStop(param LinearTradingStopParam) (*LinearTradingStopResponse, error) {
var res LinearTradingStopResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for LinearTradingStopParam: %w", err)
}
if err := s.client.postJSON("/private/linear/position/trading-stop", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// LinearExecutionListResponse :
type LinearExecutionListResponse struct {
CommonResponse `json:",inline"`
Result LinearExecutionListResult `json:"result"`
}
// LinearExecutionListResult :
type LinearExecutionListResult struct {
CurrentPage int `json:"current_page"`
LinearExecutionLists []LinearExecutionList `json:"data"`
}
// LinearExecutionList :
type LinearExecutionList struct {
OrderID string `json:"order_id"`
OrderLinkID string `json:"order_link_id"`
Side Side `json:"side"`
Symbol SymbolFuture `json:"symbol"`
OrderPrice float64 `json:"order_price"`
OrderQty float64 `json:"order_qty"`
OrderType OrderType `json:"order_type"`
FeeRate float64 `json:"fee_rate"`
ExecPrice float64 `json:"exec_price"`
ExecType ExecType `json:"exec_type"`
ExecQty float64 `json:"exec_qty"`
ExecFee float64 `json:"exec_fee"`
ExecValue float64 `json:"exec_value"`
LeavesQty float64 `json:"leaves_qty"`
ClosedSize float64 `json:"closed_size"`
LastLiquidityInd string `json:"last_liquidity_ind"`
TradeTimeMs float64 `json:"trade_time_ms"`
}
// LinearExecutionListParam :
type LinearExecutionListParam struct {
Symbol SymbolFuture `url:"symbol"`
StartTime *int `url:"start_time,omitempty"`
EndTime *int `url:"end_time,omitempty"`
ExecType *ExecType `url:"exec_type,omitempty"`
Page *int `url:"page,omitempty"`
Limit *int `url:"limit,omitempty"`
}
// LinearExecutionList :
func (s *FutureUSDTPerpetualService) LinearExecutionList(param LinearExecutionListParam) (*LinearExecutionListResponse, error) {
var res LinearExecutionListResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/private/linear/trade/execution/list", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// LinearCancelAllParam : Parameters to be supplied to cancel all endpoint
type LinearCancelAllParam struct {
Symbol SymbolFuture `json:"symbol"`
}
// LinearCancelAllResponse : Response from cancel all endpoint
type LinearCancelAllResponse struct {
CommonResponse `json:",inline"`
Result LinearCancelAllResult `json:"result"`
}
type LinearCancelAllResult []string
// LinearCancelAllOrder : Cancel all active orders that are unfilled or partially filled. Fully filled orders cannot be cancelled.
func (s *FutureUSDTPerpetualService) LinearCancelAllOrder(param LinearCancelAllParam) (*LinearCancelAllResponse, error) {
var res LinearCancelAllResponse
body, err := json.Marshal(param)
if err != nil {
return &res, fmt.Errorf("json marshal for LinearCancelAllParam: %w", err)
}
if err := s.client.postJSON("/private/linear/order/cancel-all", body, &res); err != nil {
return &res, err
}
return &res, nil
}
// ReplaceLinearOrderResponse :
type ReplaceLinearOrderResponse struct {
CommonResponse `json:",inline"`
Result ReplaceLinearOrderResult `json:"result"`
}
// ReplaceLinearOrderResult :
type ReplaceLinearOrderResult struct {
OrderID string `json:"order_id"`
}
// ReplaceLinearOrderParam :
type ReplaceLinearOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
OrderID *string `json:"order_id,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
NewQuantity *float64 `json:"p_r_qty,omitempty"`
NewPrice *float64 `json:"p_r_price,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"`
}
// ReplaceLinearOrder :
func (s *FutureUSDTPerpetualService) ReplaceLinearOrder(param ReplaceLinearOrderParam) (*ReplaceLinearOrderResponse, error) {
var res ReplaceLinearOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for ReplaceLinearOrderResult: %w", err)
}
if err := s.client.postJSON("/private/linear/order/replace", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// QueryLinearOrderResponse :
type QueryLinearOrderResponse struct {
CommonResponse `json:",inline"`
Result []QueryLinearOrderResult `json:"result"`
}
// QueryLinearOrderResult :
type QueryLinearOrderResult struct {
OrderID string `json:"order_id"`
UserID int `json:"user_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"`
LastExecPrice float64 `json:"last_exec_price"`
CumExecQty float64 `json:"cum_exec_qty"`
CumExecValue float64 `json:"cum_exec_value"`
CumExecFee float64 `json:"cum_exec_fee"`
ReduceOnly bool `json:"reduce_only"`
CloseOnTrigger bool `json:"close_on_trigger"`
OrderLinkID string `json:"order_link_id"`
CreatedTime string `json:"created_time"`
UpdatedTime string `json:"updated_time"`
TakeProfit float64 `json:"take_profit"`
StopLoss float64 `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
}
// QueryLinearOrderParam :
type QueryLinearOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
OrderID *string `url:"order_id,omitempty"`
OrderLinkID *string `url:"order_link_id,omitempty"`
}
// QueryLinearOrder :
func (s *FutureUSDTPerpetualService) QueryLinearOrder(param QueryLinearOrderParam) (*QueryLinearOrderResponse, error) {
var res QueryLinearOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/private/linear/order/search", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CreateLinearStopOrderResponse :
type CreateLinearStopOrderResponse struct {
CommonResponse `json:",inline"`
Result CreateLinearStopOrderResult `json:"result"`
}
// CreateLinearStopOrderResult :
type CreateLinearStopOrderResult struct {
StopOrderID string `json:"stop_order_id"`
UserID int `json:"user_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"`
TriggerPrice float64 `json:"trigger_price"`
OrderLinkID string `json:"order_link_id"`
CreatedTime string `json:"created_time"`
UpdatedTime string `json:"updated_time"`
BasePrice string `json:"base_price"`
TriggerBy TriggerByFuture `json:"trigger_by"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
TakeProfit float64 `json:"take_profit"`
StopLoss float64 `json:"stop_loss"`
ReduceOnly bool `json:"reduce_only"`
CloseOnTrigger bool `json:"close_on_trigger"`
PositionIdx int `json:"position_idx"`
}
// CreateLinearStopOrderParam :
type CreateLinearStopOrderParam 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"`
TriggerBy TriggerByFuture `json:"trigger_by"`
ReduceOnly bool `json:"reduce_only"`
CloseOnTrigger bool `json:"close_on_trigger"`
Price *float64 `json:"price,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"`
PositionIdx *int `json:"position_idx,omitempty"`
}
// CreateLinearStopOrder :
func (s *FutureUSDTPerpetualService) CreateLinearStopOrder(param CreateLinearStopOrderParam) (*CreateLinearStopOrderResponse, error) {
var res CreateLinearStopOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CreateLinearStopOrderParam: %w", err)
}
if err := s.client.postJSON("/private/linear/stop-order/create", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// ListLinearStopOrderResponse :
type ListLinearStopOrderResponse struct {
CommonResponse `json:",inline"`
Result ListLinearStopOrderResult `json:"result"`
}
// ListLinearStopOrderResult :
type ListLinearStopOrderResult struct {
CurrentPage int `json:"current_page"`
LastPage int `json:"last_page"`
Content []ListLinearStopOrderResultContent `json:"data"`
}
// ListLinearStopOrderResultContent :
type ListLinearStopOrderResultContent struct {
StopOrderID string `json:"stop_order_id"`
UserID int `json:"user_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"`
TriggerPrice float64 `json:"trigger_price"`
OrderLinkID string `json:"order_link_id"`
CreatedTime string `json:"created_time"`
UpdatedTime string `json:"updated_time"`
TakeProfit float64 `json:"take_profit"`
StopLoss float64 `json:"stop_loss"`
TriggerBy TriggerByFuture `json:"trigger_by"`
BasePrice string `json:"base_price"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
ReduceOnly bool `json:"reduce_only"`
CloseOnTrigger bool `json:"close_on_trigger"`
}
// ListLinearStopOrderParam :
type ListLinearStopOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
StopOrderID *string `url:"stop_order_id,omitempty"`
OrderLinkID *string `url:"order_link_id,omitempty"`
StopOrderStatus *OrderStatus `url:"stop_order_status,omitempty"`
Order *Order `url:"order,omitempty"`
Page *int `url:"page,omitempty"`
Limit *int `url:"limit,omitempty"`
}
// ListLinearStopOrder :
func (s *FutureUSDTPerpetualService) ListLinearStopOrder(param ListLinearStopOrderParam) (*ListLinearStopOrderResponse, error) {
var res ListLinearStopOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/private/linear/stop-order/list", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelLinearStopOrderResponse :
type CancelLinearStopOrderResponse struct {
CommonResponse `json:",inline"`
Result CancelLinearStopOrderResult `json:"result"`
}
// CancelLinearStopOrderResult :
type CancelLinearStopOrderResult struct {
StopOrderID string `json:"stop_order_id"`
}
// CancelLinearStopOrderParam :
type CancelLinearStopOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
StopOrderID *string `json:"stop_order_id,omitempty"`
OrderLinkID *string `json:"order_link_id,omitempty"`
}
// CancelLinearStopOrder :
func (s *FutureUSDTPerpetualService) CancelLinearStopOrder(param CancelLinearStopOrderParam) (*CancelLinearStopOrderResponse, error) {
var res CancelLinearStopOrderResponse
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 CancelLinearStopOrderParam: %w", err)
}
if err := s.client.postJSON("/private/linear/stop-order/cancel", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// CancelAllLinearStopOrderResponse :
type CancelAllLinearStopOrderResponse struct {
CommonResponse `json:",inline"`
Result CancelAllLinearStopOrderResult `json:"result"`
}
// CancelAllLinearStopOrderResult :
type CancelAllLinearStopOrderResult []string
// CancelAllLinearStopOrderParam :
type CancelAllLinearStopOrderParam struct {
Symbol SymbolFuture `json:"symbol"`
}
// CancelAllLinearStopOrder :
func (s *FutureUSDTPerpetualService) CancelAllLinearStopOrder(param CancelAllLinearStopOrderParam) (*CancelAllLinearStopOrderResponse, error) {
var res CancelAllLinearStopOrderResponse
body, err := json.Marshal(param)
if err != nil {
return nil, fmt.Errorf("json marshal for CancelAllLinearStopOrderParam: %w", err)
}
if err := s.client.postJSON("/private/linear/stop-order/cancel-all", body, &res); err != nil {
return nil, err
}
return &res, nil
}
// QueryLinearStopOrderResponse :
type QueryLinearStopOrderResponse struct {
CommonResponse `json:",inline"`
Result []QueryLinearStopOrderResult `json:"result"`
}
// QueryLinearStopOrderResult :
type QueryLinearStopOrderResult struct {
StopOrderID string `json:"stop_order_id"`
UserID int `json:"user_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"`
TriggerPrice float64 `json:"trigger_price"`
BasePrice string `json:"base_price"`
OrderLinkID string `json:"order_link_id"`
CreatedTime string `json:"created_time"`
UpdatedTime string `json:"updated_time"`
TakeProfit float64 `json:"take_profit"`
StopLoss float64 `json:"stop_loss"`
TpTriggerBy TriggerByFuture `json:"tp_trigger_by"`
SlTriggerBy TriggerByFuture `json:"sl_trigger_by"`
TriggerBy TriggerByFuture `json:"trigger_by"`
ReduceOnly bool `json:"reduce_only"`
CloseOnTrigger bool `json:"close_on_trigger"`
}
// QueryLinearStopOrderParam :
type QueryLinearStopOrderParam struct {
Symbol SymbolFuture `url:"symbol"`
StopOrderID *string `url:"stop_order_id,omitempty"`
OrderLinkID *string `url:"order_link_id,omitempty"`
}
// QueryLinearStopOrder :
func (s *FutureUSDTPerpetualService) QueryLinearStopOrder(param QueryLinearStopOrderParam) (*QueryLinearStopOrderResponse, error) {
var res QueryLinearStopOrderResponse
queryString, err := query.Values(param)
if err != nil {
return nil, err
}
if err := s.client.getPrivately("/private/linear/stop-order/search", queryString, &res); err != nil {
return nil, err
}
return &res, nil
}