-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathclient.py
More file actions
2246 lines (1954 loc) · 82.1 KB
/
client.py
File metadata and controls
2246 lines (1954 loc) · 82.1 KB
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
import requests
import json
from pybitget.enums import *
from pybitget import utils
from pybitget import exceptions
from pybitget import logger
class Client(object):
def __init__(self, api_key, api_secret_key, passphrase, use_server_time=False, verbose=False):
self.API_KEY = api_key
self.API_SECRET_KEY = api_secret_key
self.PASSPHRASE = passphrase
self.use_server_time = use_server_time
self.verbose = verbose
def _request(self, method, request_path, params, cursor=False):
if method == GET:
request_path = request_path + utils.parse_params_to_str(params)
# url
url = API_URL + request_path
# Get local time
timestamp = utils.get_timestamp()
# sign & header
if self.use_server_time:
# Get server time interface
timestamp = self._get_timestamp()
body = json.dumps(params) if method == POST else ""
sign = utils.sign(utils.pre_hash(timestamp, method, request_path, str(body)), self.API_SECRET_KEY)
header = utils.get_header(self.API_KEY, sign, timestamp, self.PASSPHRASE)
# send request
response = None
if method == GET:
response = requests.get(url, headers=header)
elif method == POST:
response = requests.post(url, data=body, headers=header)
elif method == DELETE:
response = requests.delete(url, headers=header)
# exception handle
if not str(response.status_code).startswith('2'):
raise exceptions.BitgetAPIException(response)
try:
res_header = response.headers
if cursor:
r = dict()
try:
r['before'] = res_header['BEFORE']
r['after'] = res_header['AFTER']
except:
pass
return response.json(), r
else:
return response.json()
except ValueError:
raise exceptions.BitgetRequestException('Invalid Response: %s' % response.text)
def _request_without_params(self, method, request_path):
return self._request(method, request_path, {})
def _request_with_params(self, method, request_path, params, cursor=False):
return self._request(method, request_path, params, cursor)
def _get_timestamp(self):
url = API_URL + SERVER_TIMESTAMP_URL
response = requests.get(url)
if response.status_code == 200:
return response.json()['data']
else:
return ""
""" --- MIX-MarkettApi """
def mix_get_vip_fee_rate(self):
"""
VIP fee rate: https://bitgetlimited.github.io/apidoc/en/mix/#vip-fee-rate
Limit rule: 10 times/1s (IP)
Required: None
:return:
"""
return self._request_without_params(GET, MIX_MARKET_V1_URL + '/contract-vip-level')
def mix_get_symbols_info(self, productType):
"""
Get All symbols: https://bitgetlimited.github.io/apidoc/en/mix/#get-all-symbols
Limit rule: 20 times/1s (IP)
Required: productType
:return:
"""
params = {}
if productType:
params["productType"] = productType
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/contracts', params)
else:
logger.error("pls check args")
return False
def mix_get_depth(self, symbol, limit=100):
"""
Get Depth: https://bitgetlimited.github.io/apidoc/en/mix/#get-depth
Limit rule: 20 times/1s (IP)
Required: symbol
:param symbol: Symbol Id (Must be capitalized)
:type symbol: str
:param limit: Depth gear 5,15,50,100 default 100
:type limit: str
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
params["limit"] = limit
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/depth', params)
else:
logger.error("pls check args")
return False
def mix_get_single_symbol_ticker(self, symbol):
"""
Get Single Symbol Ticker: https://bitgetlimited.github.io/apidoc/en/mix/#get-single-symbol-ticker
Limit rule: 20 times/1s (IP)
Required: symbol
:param symbol: Symbol Id (Must be capitalized)
:type symbol: str
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/ticker', params)
else:
logger.error("pls check args")
return False
def mix_get_all_symbol_ticker(self, productType):
"""
Get All Symbol Ticker: https://bitgetlimited.github.io/apidoc/en/mix/#get-all-symbol-ticker
Limit rule: 20 times/1s (IP)
Required: productType
:return:
"""
params = {}
if productType:
params["productType"] = productType
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/tickers', params)
else:
logger.error("pls check args")
return False
def mix_get_fills(self, symbol, limit=100):
"""
Get recent trades: https://bitgetlimited.github.io/apidoc/en/mix/#get-fills
Limit rule: 20 times/1s (IP)
Required: symbol, limit
:param symbol: Symbol Id (Must be capitalized)
:type symbol: str
:param limit: Default limit is 100
:type limit: str
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
params["limit"] = limit
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/fills', params)
else:
logger.error("pls check args")
return False
def mix_get_candles(self, symbol, granularity, startTime, endTime, kLineType='market', limit=100):
"""
Get Candle Data: https://bitgetlimited.github.io/apidoc/en/mix/#get-candle-data
Limit rule: 20 times/1s (IP)
Required: symbol, granularity, startTime, endTime
:return:
"""
params = {}
if symbol and granularity and startTime and endTime:
params["symbol"] = symbol
params["granularity"] = granularity
params["startTime"] = startTime
params["endTime"] = endTime
params["kLineType"] = kLineType
params["limit"] = limit
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/candles', params)
else:
logger.error("pls check args")
return False
def mix_get_history_candles(self, symbol, granularity, startTime, endTime, limit=100):
"""
Get History Candle Data: https://bitgetlimited.github.io/apidoc/en/mix/#get-history-candle-data
Limit rule: 20 times/1s (IP)
Required: symbol, granularity, startTime, endTime
:return:
"""
params = {}
if symbol and granularity and startTime and endTime:
params["symbol"] = symbol
params["granularity"] = granularity
params["startTime"] = startTime
params["endTime"] = endTime
params["limit"] = limit
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/history-candles', params)
else:
logger.error("pls check args")
return False
def mix_get_symbol_index_price(self, symbol):
"""
Get Symbol Index Price: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-index-price
Limit rule: 20 times/1s (IP)
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/index', params)
else:
logger.error("pls check args")
return False
def mix_get_symbol_next_funding(self, symbol):
"""
Get Symbol Next Funding Time: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-next-funding-time
Limit rule: 20 times/1s (IP)
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/funding-time', params)
else:
logger.error("pls check args")
return False
def mix_get_history_fund_rate(self, symbol, pageSize=20, pageNo=1, nextPage=False):
"""
Get History Funding Rate: https://bitgetlimited.github.io/apidoc/en/mix/#get-history-funding-rate
Limit rule: 20 times/1s (IP)
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
params["pageSize"] = pageSize
params["pageNo"] = pageNo
params["nextPage"] = nextPage
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/history-fundRate', params)
else:
logger.error("pls check args")
return False
def mix_get_current_fund_rate(self, symbol):
"""
Get Current Funding Rate: https://bitgetlimited.github.io/apidoc/en/mix/#get-current-funding-rate
Limit rule: 20 times/1s (IP)
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/current-fundRate', params)
else:
logger.error("pls check args")
return False
def mix_get_open_interest(self, symbol):
"""
Get Open Interest: https://bitgetlimited.github.io/apidoc/en/mix/#get-open-interest
Limit rule: 20 times/1s (IP)
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/open-interest', params)
else:
logger.error("pls check args")
return False
def mix_get_market_price(self, symbol):
"""
Get Symbol Mark Price: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-mark-price
Limit rule: 20 times/1s (IP)
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/mark-price', params)
else:
logger.error("pls check args")
return False
def mix_get_leverage(self, symbol):
"""
Get Symbol Leverage: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-leverage
Limit rule: 20/sec (IP)
Required: symbol.
"""
params = {}
if symbol:
params["symbol"] = symbol
return self._request_with_params(GET, MIX_MARKET_V1_URL + '/symbol-leverage', params)
else:
logger.error("pls check args")
return False
""" --- MIX-AccountApi """
def mix_get_account(self, symbol, marginCoin):
"""
Get Single Account: https://bitgetlimited.github.io/apidoc/en/mix/#get-single-account
Required: symbol, marginCoin
:return:
"""
params = {}
if symbol and marginCoin:
params['symbol'] = symbol
params['marginCoin'] = marginCoin
return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/account', params)
else:
logger.error("pls check args")
return False
def mix_get_accounts(self, productType):
"""
Get Account List: https://bitgetlimited.github.io/apidoc/en/mix/#get-account-list
productType: Umcbl (USDT professional contract) dmcbl (mixed contract) sumcbl (USDT professional contract simulation disk) sdmcbl (mixed contract simulation disk)
:return:
"""
params = {}
if productType:
params['productType'] = productType
return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/accounts', params)
else:
logger.error("pls check args")
return False
def mix_get_sub_account_contract_assets(self, productType):
"""
Get sub Account Contract Assets: https://bitgetlimited.github.io/apidoc/en/mix/#get-sub-account-contract-assets
Limit rule: 1 times/10s (uid)
Required: productType
:return:
"""
params = {}
if productType:
params['productType'] = productType
return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/sub-account-contract-assets', params)
else:
logger.error("pls check args")
return False
def mix_get_open_count(self, symbol, marginCoin, openPrice, openAmount, leverage=20):
"""
Get Open Count: https://bitgetlimited.github.io/apidoc/en/mix/#get-open-count
Limit rule: 20 times/1s (IP)
Required: symbol, marginCoin, openPrice, openAmount
"""
params = {}
if symbol and marginCoin and openPrice and openAmount:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["openPrice"] = openPrice
params["openAmount"] = openAmount
params["leverage"] = leverage
return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/open-count', params)
else:
logger.error("pls check args")
return False
def mix_adjust_leverage(self, symbol, marginCoin, leverage, holdSide=None):
"""
Change Leverage: https://bitgetlimited.github.io/apidoc/en/mix/#change-leverage
Limit rule: 5 times/1s (uid)
The leverage could set to different number in fixed margin mode(holdSide is required)
Required: symbol, marginCoin, leverage
"""
params = {}
if symbol and marginCoin and leverage:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["leverage"] = leverage
if holdSide is not None:
params["holdSide"] = holdSide
return self._request_with_params(POST, MIX_ACCOUNT_V1_URL + '/setLeverage', params)
else:
logger.error("pls check args")
return False
def mix_adjust_margin(self, symbol, marginCoin, amount, holdSide=None):
"""
Change Margin: https://bitgetlimited.github.io/apidoc/en/mix/#change-margin
Limit rule: 5 times/1s (uid)
Required: symbol, marginCoin, marginMode
"""
params = {}
if symbol and marginCoin and amount:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["marginMode"] = amount
if holdSide is not None:
params["holdSide"] = holdSide
return self._request_with_params(POST, MIX_ACCOUNT_V1_URL + '/setMargin', params)
else:
logger.error("pls check args")
return False
def mix_adjust_margintype(self, symbol, marginCoin, marginMode):
"""
Change Margin Mode: https://bitgetlimited.github.io/apidoc/en/mix/#change-margin-mode
Limit rule: 5 times/1s (uid)
Required: symbol, marginCoin, marginMode
"""
params = {}
if symbol and marginCoin and marginMode:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["marginMode"] = marginMode
return self._request_with_params(POST, MIX_ACCOUNT_V1_URL + '/setMarginMode', params)
else:
logger.error("pls check args")
return False
def mix_adjust_hold_mode(self, productType, holdMode):
"""
Change Hold Mode: https://bitgetlimited.github.io/apidoc/en/mix/#change-hold-mode
Limit rule: 5 times/1s (uid)
Required: productType, holdMode
"""
params = {}
if productType and holdMode:
params["productType"] = productType
params["holdMode"] = holdMode
return self._request_with_params(POST, MIX_ACCOUNT_V1_URL + '/setPositionMode', params)
else:
logger.error("pls check args")
return False
def mix_get_single_position(self, symbol, marginCoin=None):
"""
Obtain the user's single position information.
Get Symbol Position: https://bitgetlimited.github.io/apidoc/en/mix/#get-symbol-position
:param symbol: Name of symbol
:type symbol: str
:param marginCoin: Margin currency (Must be capitalized)
:type marginCoin: str
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
if marginCoin is not None:
params["marginCoin"] = marginCoin
return self._request_with_params(GET, MIX_POSITION_V1_URL + '/singlePosition', params)
else:
logger.error("pls check args")
return False
def mix_get_all_positions(self, productType, marginCoin=None):
"""
Obtain all position information of the user.
Get All Position: https://bitgetlimited.github.io/apidoc/en/mix/#get-all-position
:param productType: Umcbl (USDT professional contract) dmcbl (mixed contract) sumcbl (USDT professional contract simulation disk) sdmcbl (mixed contract simulation disk)
:type productType: str
:param marginCoin: Margin currency (Must be capitalized)
:type marginCoin: str
:return:
"""
params = {}
if productType:
params["productType"] = productType
if marginCoin is not None:
params["marginCoin"] = marginCoin
return self._request_with_params(GET, MIX_POSITION_V1_URL + '/allPosition', params)
else:
logger.error("pls check args")
return False
def mix_get_accountBill(self, symbol, marginCoin, startTime, endTime, lastEndId='', pageSize=20, next=False):
"""
Get Account Bill: https://bitgetlimited.github.io/apidoc/en/mix/#get-account-bill
Limit rule: 10/sec (uid)
Required: symbol, marginCoin, startTime, endTime
:return:
"""
params = {}
if symbol and marginCoin and startTime and endTime:
params['symbol'] = symbol
params['marginCoin'] = marginCoin
params['startTime'] = startTime
params['endTime'] = endTime
params['lastEndId'] = lastEndId
params['pageSize'] = pageSize
params['next'] = next
return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/accountBill', params)
else:
logger.error("pls check args")
return False
def mix_get_accountBusinessBill(self, productType, startTime, endTime, lastEndId='', pageSize=20, next=False):
"""
Get Business Account Bill: https://bitgetlimited.github.io/apidoc/en/mix/#get-business-account-bill
Limit rule: 5/sec (uid)
Required: productType, startTime, endTime
:return:
"""
params = {}
if productType and startTime and endTime:
params['productType'] = productType
params['startTime'] = startTime
params['endTime'] = endTime
params['lastEndId'] = lastEndId
params['pageSize'] = pageSize
params['next'] = next
return self._request_with_params(GET, MIX_ACCOUNT_V1_URL + '/accountBusinessBill', params)
else:
logger.error("pls check args")
return False
""" --- MIX-tradeApi """
def mix_place_order(self, symbol, marginCoin, size, side, orderType,
price='', clientOrderId=None, reduceOnly=False,
timeInForceValue='normal', presetTakeProfitPrice='', presetStopLossPrice=''):
"""
place an order: https://bitgetlimited.github.io/apidoc/en/mix/#place-order
Limit rule: 10 times/1s (uid)
Trader Limit rule: 1 times/1s (uid)
Required: symbol, marginCoin, size, price, side, orderType.
price: Mandatory in case of price limit
marginCoin: Deposit currency
size: It is quantity when the price is limited. The market price is the limit. The sales is the quantity
side:open_long open_short close_long close_short
orderType: limit(fixed price) market(market price)
timeInForceValue: normal(Ordinary price limit order) postOnly(It is only a maker. The market price is not allowed to use this) ioc(Close immediately and cancel the remaining) fok(Complete transaction or immediate cancellation)
presetTakeProfitPrice: Default stop profit price
presetStopLossPrice:Preset stop loss price
:return:
"""
params = {}
if symbol and marginCoin and side and orderType and size:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["price"] = price
params["size"] = size
params["side"] = side
params["orderType"] = orderType
params["reduceOnly"] = reduceOnly
params["timeInForceValue"] = timeInForceValue
if clientOrderId is not None:
params["clientOid"] = clientOrderId
params["presetTakeProfitPrice"] = presetTakeProfitPrice
params["presetStopLossPrice"] = presetStopLossPrice
return self._request_with_params(POST, MIX_ORDER_V1_URL + '/placeOrder', params)
else:
logger.error("pls check args")
return False
def mix_reversal(self, symbol, marginCoin, side, orderType,
size=None, clientOrderId=None, timeInForceValue='normal', reverse=False):
"""
Reversal: https://bitgetlimited.github.io/apidoc/en/mix/#reversal
Limit rule: 10 times/1s (uid), counted together with placeOrder
Reversal share the same interface with Place order.
Required: symbol, marginCoin, side, orderType
:return:
"""
params = {}
if symbol and marginCoin and side and orderType:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["side"] = side
params["orderType"] = orderType
if size is not None:
params["size"] = size
if clientOrderId is not None:
params["clientOid"] = clientOrderId
params["timeInForceValue"] = timeInForceValue
params["reverse"] = reverse
return self._request_with_params(POST, MIX_ORDER_V1_URL + '/placeOrder', params)
else:
logger.error("pls check args")
return False
def mix_batch_orders(self, symbol, marginCoin, orderDataList):
"""
Batch Order: https://bitgetlimited.github.io/apidoc/en/mix/#batch-order
Limit rule: 10 times/1s (uid)
Trader Limit rule: 1 times/1s (uid)
Required: symbol, marginCoin, orderDataList
"""
params = {}
if symbol and marginCoin and orderDataList:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["orderDataList"] = orderDataList
return self._request_with_params(POST, MIX_ORDER_V1_URL + '/batch-orders', params)
else:
logger.error("pls check args")
return False
def mix_cancel_order(self, symbol, marginCoin, orderId='', clientOid=''):
"""
Cancel Order: https://bitgetlimited.github.io/apidoc/en/mix/#cancel-order
Limit rule: 10 times/1s (uid)
Required: symbol, marginCoin, orderId or clientOid
- Order Id, int64 in string format, 'orderId' or 'clientOid' must have one
- Client Order Id, 'orderId' or 'clientOid' must have one
"""
params = {}
if symbol and marginCoin and (orderId != '' or clientOid != ''):
params["symbol"] = symbol
params["marginCoin"] = marginCoin
if orderId != '':
params["orderId"] = orderId
elif clientOid != '':
params["clientOid"] = clientOid
return self._request_with_params(POST, MIX_ORDER_V1_URL + '/cancel-order', params)
else:
logger.error("pls check args")
return False
def mix_batch_cancel_orders(self, symbol, marginCoin, orderId: list = None, clientOid: list = None):
""" Batch Cancel Order
https://bitgetlimited.github.io/apidoc/en/mix/#batch-cancel-order
Limit rule: 10 times/1s (uid)
Required: symbol, marginCoin, orderIds or clientOids
- Order Id list, int64 in string format, 'orderIds' or 'clientOids' must have one
- Client Order Id list, 'orderIds' or 'clientOids' must have one
"""
params = {}
if symbol and marginCoin and orderIds:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
if orderId is not None:
params["orderId"] = orderId
elif clientOid is not None:
params["clientOid"] = clientOid
return self._request_with_params(POST, MIX_ORDER_V1_URL + '/cancel-batch-orders', params)
else:
logger.error("pls check args")
return False
def mix_cancel_all_orders(self, productType, marginCoin):
""" Cancel All Order
https://bitgetlimited.github.io/apidoc/en/mix/#cancel-all-order
Limit rule: 10 times/1s (uid)
Required: productType, marginCoin
"""
params = {}
if productType and marginCoin:
params["productType"] = productType
params["marginCoin"] = marginCoin
return self._request_with_params(POST, MIX_ORDER_V1_URL + '/cancel-all-orders', params)
else:
logger.error("pls check args")
return False
def mix_get_open_order(self, symbol):
"""
Get the current order: https://bitgetlimited.github.io/apidoc/en/mix/#get-open-order
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
return self._request_with_params(GET, MIX_ORDER_V1_URL + '/current', params)
else:
logger.error("pls check args")
return False
def mix_get_all_open_orders(self, productType, marginCoin=None):
"""
Get All Open Order:::https://bitgetlimited.github.io/apidoc/en/mix/#get-all-open-order
Required: productType
:return:
"""
params = {}
if productType:
params["productType"] = productType
if marginCoin is not None:
params["marginCoin"] = marginCoin
return self._request_with_params(GET, MIX_ORDER_V1_URL + '/marginCoinCurrent', params)
else:
logger.error("pls check args")
return False
def mix_get_history_orders(self, symbol, startTime, endTime, pageSize, lastEndId='', isPre=False):
"""
Get History Orders: https://bitgetlimited.github.io/apidoc/en/mix/#get-history-orders
Limit rule: 20 times/2s (uid)
Required: symbol, startTime, endTime, pageSize
:param symbol: Symbol Id (Must be capitalized)
:type symbol: str
:param startTime: Start time, milliseconds
:type startTime: str
:param endTime: End time, milliseconds
:type endTime: str
:param pageSize: page Size
:type pageSize: str
:param lastEndId: last end Id of last query
:type lastEndId: str
:param isPre: true: order by order Id asc; default false
:type isPre: Boolean
:return:
"""
params = {}
if symbol and startTime and endTime and pageSize:
params["symbol"] = symbol
params["startTime"] = startTime
params["endTime"] = endTime
params["pageSize"] = pageSize
params["lastEndId"] = lastEndId
params["isPre"] = isPre
return self._request_with_params(GET, MIX_ORDER_V1_URL + '/history', params)
else:
logger.error("pls check args")
return False
def mix_get_productType_history_orders(self, productType, startTime, endTime, pageSize, lastEndId='', isPre=False):
"""
Get ProductType History Orders: https://bitgetlimited.github.io/apidoc/en/mix/#get-producttype-history-orders
Limit rule: 5/1s (uid)
Required: productType, startTime, endTime, pageSize
:param productType
:type productType: str
:param startTime: Start time, milliseconds
:type startTime: str
:param endTime: End time, milliseconds
:type endTime: str
:param pageSize: page Size
:type pageSize: str
:param lastEndId: last end Id of last query
:type lastEndId: str
:param isPre: true: order by order Id asc; default false
:type isPre: Boolean
:return:
"""
params = {}
if productType and startTime and endTime and pageSize:
params["productType"] = productType
params["startTime"] = startTime
params["endTime"] = endTime
params["pageSize"] = pageSize
params["lastEndId"] = lastEndId
params["isPre"] = isPre
return self._request_with_params(GET, MIX_ORDER_V1_URL + '/historyProductType', params)
else:
logger.error("pls check args")
return False
def mix_get_order_details(self, symbol, orderId=None, clientOrderId=None):
"""
Get Order Details: https://bitgetlimited.github.io/apidoc/en/mix/#get-order-details
Limit rule: 20 times/2s (uid)
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
if orderId is not None:
params["orderId"] = orderId
if clientOrderId is not None:
params["clientOid"] = clientOrderId
return self._request_with_params(GET, MIX_ORDER_V1_URL + '/detail', params)
else:
logger.error("pls check args")
return False
def mix_get_order_fill_detail(self, symbol, orderId=None, startTime=None, endTime=None, lastEndId=None):
"""
Get Order fill detail: https://bitgetlimited.github.io/apidoc/en/mix/#get-order-fill-detail
Limit rule: 20 times/2s (uid)
Required: symbol
:return:
"""
params = {}
if symbol:
params["symbol"] = symbol
if orderId is not None:
params["orderId"] = orderId
if startTime is not None:
params["startTime"] = startTime
if endTime is not None:
params["endTime"] = endTime
if lastEndId is not None:
params["lastEndId"] = lastEndId
return self._request_with_params(GET, MIX_ORDER_V1_URL + '/fills', params)
else:
logger.error("pls check args")
return False
def mix_get_productType_order_fill_detail(self, productType, startTime=None, endTime=None, lastEndId=None):
"""
Get ProductType Order fill detail: https://bitgetlimited.github.io/apidoc/en/mix/#get-producttype-order-fill-detail
Limit rule: 10 times/1s (uid)
Required: productType
:return:
"""
params = {}
if productType:
params["productType"] = productType
if startTime is not None:
params["startTime"] = startTime
if endTime is not None:
params["endTime"] = endTime
if lastEndId is not None:
params["lastEndId"] = lastEndId
return self._request_with_params(GET, MIX_ORDER_V1_URL + '/allFills', params)
else:
logger.error("pls check args")
return False
def mix_place_plan_order(self, symbol, marginCoin, size, side, orderType, triggerPrice, triggerType
, executePrice=None, clientOrderId=None, presetTakeProfitPrice=None, presetStopLossPrice=None, reduceOnly=False):
"""
Place Plan order: https://bitgetlimited.github.io/apidoc/en/mix/#place-plan-order
Limit rule: 10 times/1s (uid)
Required: symbol, marginCoin, size, side, orderType, triggerPrice, triggerType
:return:
"""
params = {}
if symbol and marginCoin and side and size and orderType and triggerPrice and triggerType:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["size"] = size
params["side"] = side
params["orderType"] = orderType
params["triggerPrice"] = triggerPrice
params["triggerType"] = triggerType
params["reduceOnly"] = reduceOnly
if executePrice is not None:
params["executePrice"] = executePrice
if clientOrderId is not None:
params["clientOid"] = clientOrderId
if presetTakeProfitPrice is not None:
params["presetTakeProfitPrice"] = presetTakeProfitPrice
if presetStopLossPrice is not None:
params["presetStopLossPrice"] = presetStopLossPrice
return self._request_with_params(POST, MIX_PLAN_V1_URL + '/placePlan', params)
else:
logger.error("pls check args")
return False
def mix_modify_plan_order(self, symbol, marginCoin, orderId, orderType, triggerPrice, triggerType
, executePrice=None):
"""
Modify Plan Order: https://bitgetlimited.github.io/apidoc/en/mix/#modify-plan-order
Limit rule: 10 times/1s (uid)
Required: symbol, marginCoin, orderId, orderType, triggerPrice, triggerType
:return:
"""
params = {}
if symbol and marginCoin and orderId and orderType and triggerPrice and triggerType:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["orderId"] = orderId
params["orderType"] = orderType
params["triggerPrice"] = triggerPrice
params["triggerType"] = triggerType
if executePrice is not None:
params["executePrice"] = executePrice
return self._request_with_params(POST, MIX_PLAN_V1_URL + '/modifyPlan', params)
else:
logger.error("pls check args")
return False
def mix_modify_plan_order_tpsl(self, symbol, marginCoin, orderId
, presetTakeProfitPrice=None, presetStopLossPrice=None):
"""
Modify Plan Order TPSL: https://bitgetlimited.github.io/apidoc/en/mix/#modify-plan-order-tpsl
Limit rule: 10 times/1s (uid)
Required: symbol, marginCoin, orderId
:return:
"""
params = {}
if symbol and marginCoin and orderId:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["orderId"] = orderId
if presetTakeProfitPrice is not None:
params["presetTakeProfitPrice"] = presetTakeProfitPrice
if presetStopLossPrice is not None:
params["presetStopLossPrice"] = presetStopLossPrice
return self._request_with_params(POST, MIX_PLAN_V1_URL + '/modifyPlanPreset', params)
else:
logger.error("pls check args")
return False
def mix_place_stop_order(self, symbol, marginCoin, triggerPrice, planType, holdSide,
triggerType='fill_price', size=None, rangeRate=None):
"""
Place Stop Order: https://bitgetlimited.github.io/apidoc/en/mix/#place-stop-order
Limit rule: 10 times/1s (uid)
Required: symbol, marginCoin, triggerPrice, planType, holdSide
:return:
"""
params = {}
if symbol and marginCoin and planType and holdSide and triggerPrice:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["planType"] = planType
params["holdSide"] = holdSide
params["triggerPrice"] = triggerPrice
params["triggerType"] = triggerType
if size is not None:
params["size"] = size
if rangeRate is not None:
params["rangeRate"] = rangeRate
return self._request_with_params(POST, MIX_PLAN_V1_URL + '/placeTPSL', params)
else:
logger.error("pls check args")
return False
def mix_place_trailing_stop_order(self, symbol, marginCoin, triggerPrice, side,
triggerType=None, size=None, rangeRate=None):
"""
Place Trailing Stop Order: https://bitgetlimited.github.io/apidoc/en/mix/#place-trailing-stop-order
Limit rule: 10 times/1s (uid)
Required: symbol, marginCoin, triggerPrice, side
:return:
"""
params = {}
if symbol and marginCoin and side and triggerPrice:
params["symbol"] = symbol
params["marginCoin"] = marginCoin
params["side"] = side
params["triggerPrice"] = triggerPrice
if triggerType is not None:
params["triggerType"] = triggerType
if size is not None:
params["size"] = size
if rangeRate is not None:
params["rangeRate"] = rangeRate
return self._request_with_params(POST, MIX_PLAN_V1_URL + '/placeTrailStop', params)
else:
logger.error("pls check args")
return False
def mix_place_PositionsTPSL(self, symbol, marginCoin, planType, triggerPrice, triggerType, holdSide=None):
"""
Place Position TPSL: https://bitgetlimited.github.io/apidoc/en/mix/#place-position-tpsl
Limit rule: 10 times/1s (uid)
When the position take profit and stop loss are triggered, the full amount of the position will be entrusted at the market price by default.
Required: marginCoin, symbol, planType, triggerPrice, triggerType
triggertype: fill_price, market_price
"""
params = {}
if marginCoin and symbol and planType and triggerPrice and triggerType: