ccxt 4.3.5__py2.py3-none-any.whl → 4.3.7__py2.py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of ccxt might be problematic. Click here for more details.

Files changed (189) hide show
  1. ccxt/__init__.py +1 -1
  2. ccxt/abstract/binance.py +1 -0
  3. ccxt/abstract/binancecoinm.py +1 -0
  4. ccxt/abstract/binanceus.py +1 -0
  5. ccxt/abstract/binanceusdm.py +1 -0
  6. ccxt/abstract/bingx.py +1 -0
  7. ccxt/abstract/coinbase.py +5 -0
  8. ccxt/abstract/woo.py +1 -0
  9. ccxt/ace.py +5 -0
  10. ccxt/alpaca.py +6 -0
  11. ccxt/ascendex.py +2 -2
  12. ccxt/async_support/__init__.py +1 -1
  13. ccxt/async_support/ace.py +5 -0
  14. ccxt/async_support/alpaca.py +6 -0
  15. ccxt/async_support/ascendex.py +2 -2
  16. ccxt/async_support/base/exchange.py +30 -1
  17. ccxt/async_support/bigone.py +1 -1
  18. ccxt/async_support/binance.py +7 -3
  19. ccxt/async_support/bingx.py +43 -1
  20. ccxt/async_support/bitbank.py +4 -1
  21. ccxt/async_support/bitfinex.py +1 -1
  22. ccxt/async_support/bitfinex2.py +1 -1
  23. ccxt/async_support/bitflyer.py +1 -1
  24. ccxt/async_support/bitget.py +70 -4
  25. ccxt/async_support/bithumb.py +5 -1
  26. ccxt/async_support/bitmart.py +1 -1
  27. ccxt/async_support/bitmex.py +25 -1
  28. ccxt/async_support/bitopro.py +6 -1
  29. ccxt/async_support/bitrue.py +1 -1
  30. ccxt/async_support/bitso.py +4 -1
  31. ccxt/async_support/bitstamp.py +4 -1
  32. ccxt/async_support/bitteam.py +4 -0
  33. ccxt/async_support/bitvavo.py +4 -1
  34. ccxt/async_support/bl3p.py +3 -0
  35. ccxt/async_support/blockchaincom.py +1 -1
  36. ccxt/async_support/btcalpha.py +3 -0
  37. ccxt/async_support/btcbox.py +3 -0
  38. ccxt/async_support/btcmarkets.py +4 -1
  39. ccxt/async_support/btcturk.py +3 -0
  40. ccxt/async_support/bybit.py +196 -14
  41. ccxt/async_support/cex.py +6 -0
  42. ccxt/async_support/coinbase.py +98 -22
  43. ccxt/async_support/coinbaseinternational.py +3 -1
  44. ccxt/async_support/coinbasepro.py +7 -1
  45. ccxt/async_support/coincheck.py +3 -0
  46. ccxt/async_support/coinex.py +180 -79
  47. ccxt/async_support/coinlist.py +5 -1
  48. ccxt/async_support/coinmate.py +4 -1
  49. ccxt/async_support/coinone.py +3 -0
  50. ccxt/async_support/coinsph.py +5 -1
  51. ccxt/async_support/coinspot.py +3 -0
  52. ccxt/async_support/cryptocom.py +33 -2
  53. ccxt/async_support/delta.py +2 -2
  54. ccxt/async_support/deribit.py +1 -1
  55. ccxt/async_support/digifinex.py +3 -3
  56. ccxt/async_support/exmo.py +8 -3
  57. ccxt/async_support/gate.py +112 -24
  58. ccxt/async_support/gemini.py +1 -1
  59. ccxt/async_support/hitbtc.py +7 -6
  60. ccxt/async_support/hollaex.py +1 -1
  61. ccxt/async_support/htx.py +29 -1
  62. ccxt/async_support/huobijp.py +1 -1
  63. ccxt/async_support/hyperliquid.py +39 -2
  64. ccxt/async_support/idex.py +4 -1
  65. ccxt/async_support/independentreserve.py +3 -0
  66. ccxt/async_support/indodax.py +4 -1
  67. ccxt/async_support/kraken.py +28 -1
  68. ccxt/async_support/krakenfutures.py +26 -0
  69. ccxt/async_support/kucoin.py +3 -1
  70. ccxt/async_support/kucoinfutures.py +5 -3
  71. ccxt/async_support/kuna.py +1 -1
  72. ccxt/async_support/latoken.py +6 -0
  73. ccxt/async_support/lbank.py +1 -1
  74. ccxt/async_support/luno.py +3 -0
  75. ccxt/async_support/lykke.py +6 -1
  76. ccxt/async_support/mercado.py +4 -1
  77. ccxt/async_support/mexc.py +110 -4
  78. ccxt/async_support/ndax.py +5 -1
  79. ccxt/async_support/novadax.py +5 -1
  80. ccxt/async_support/okcoin.py +1 -1
  81. ccxt/async_support/okx.py +183 -4
  82. ccxt/async_support/onetrading.py +4 -1
  83. ccxt/async_support/p2b.py +3 -0
  84. ccxt/async_support/phemex.py +1 -1
  85. ccxt/async_support/poloniex.py +1 -1
  86. ccxt/async_support/probit.py +4 -1
  87. ccxt/async_support/timex.py +3 -0
  88. ccxt/async_support/tokocrypto.py +1 -1
  89. ccxt/async_support/tradeogre.py +3 -0
  90. ccxt/async_support/upbit.py +1 -1
  91. ccxt/async_support/wavesexchange.py +4 -1
  92. ccxt/async_support/wazirx.py +3 -0
  93. ccxt/async_support/whitebit.py +38 -1
  94. ccxt/async_support/woo.py +30 -1
  95. ccxt/async_support/yobit.py +4 -1
  96. ccxt/async_support/zaif.py +1 -1
  97. ccxt/async_support/zonda.py +1 -1
  98. ccxt/base/exchange.py +30 -1
  99. ccxt/bigone.py +1 -1
  100. ccxt/binance.py +7 -3
  101. ccxt/bingx.py +43 -1
  102. ccxt/bitbank.py +4 -1
  103. ccxt/bitfinex.py +1 -1
  104. ccxt/bitfinex2.py +1 -1
  105. ccxt/bitflyer.py +1 -1
  106. ccxt/bitget.py +70 -4
  107. ccxt/bithumb.py +5 -1
  108. ccxt/bitmart.py +1 -1
  109. ccxt/bitmex.py +25 -1
  110. ccxt/bitopro.py +6 -1
  111. ccxt/bitrue.py +1 -1
  112. ccxt/bitso.py +4 -1
  113. ccxt/bitstamp.py +4 -1
  114. ccxt/bitteam.py +4 -0
  115. ccxt/bitvavo.py +4 -1
  116. ccxt/bl3p.py +3 -0
  117. ccxt/blockchaincom.py +1 -1
  118. ccxt/btcalpha.py +3 -0
  119. ccxt/btcbox.py +3 -0
  120. ccxt/btcmarkets.py +4 -1
  121. ccxt/btcturk.py +3 -0
  122. ccxt/bybit.py +196 -14
  123. ccxt/cex.py +6 -0
  124. ccxt/coinbase.py +98 -22
  125. ccxt/coinbaseinternational.py +3 -1
  126. ccxt/coinbasepro.py +7 -1
  127. ccxt/coincheck.py +3 -0
  128. ccxt/coinex.py +180 -79
  129. ccxt/coinlist.py +5 -1
  130. ccxt/coinmate.py +4 -1
  131. ccxt/coinone.py +3 -0
  132. ccxt/coinsph.py +5 -1
  133. ccxt/coinspot.py +3 -0
  134. ccxt/cryptocom.py +33 -2
  135. ccxt/delta.py +2 -2
  136. ccxt/deribit.py +1 -1
  137. ccxt/digifinex.py +3 -3
  138. ccxt/exmo.py +8 -3
  139. ccxt/gate.py +112 -24
  140. ccxt/gemini.py +1 -1
  141. ccxt/hitbtc.py +7 -6
  142. ccxt/hollaex.py +1 -1
  143. ccxt/htx.py +29 -1
  144. ccxt/huobijp.py +1 -1
  145. ccxt/hyperliquid.py +39 -2
  146. ccxt/idex.py +4 -1
  147. ccxt/independentreserve.py +3 -0
  148. ccxt/indodax.py +4 -1
  149. ccxt/kraken.py +28 -1
  150. ccxt/krakenfutures.py +26 -0
  151. ccxt/kucoin.py +3 -1
  152. ccxt/kucoinfutures.py +5 -3
  153. ccxt/kuna.py +1 -1
  154. ccxt/latoken.py +6 -0
  155. ccxt/lbank.py +1 -1
  156. ccxt/luno.py +3 -0
  157. ccxt/lykke.py +6 -1
  158. ccxt/mercado.py +4 -1
  159. ccxt/mexc.py +110 -4
  160. ccxt/ndax.py +5 -1
  161. ccxt/novadax.py +5 -1
  162. ccxt/okcoin.py +1 -1
  163. ccxt/okx.py +183 -4
  164. ccxt/onetrading.py +4 -1
  165. ccxt/p2b.py +3 -0
  166. ccxt/phemex.py +1 -1
  167. ccxt/poloniex.py +1 -1
  168. ccxt/pro/__init__.py +1 -1
  169. ccxt/pro/bitget.py +1 -1
  170. ccxt/pro/bybit.py +1 -1
  171. ccxt/pro/coinbase.py +28 -28
  172. ccxt/probit.py +4 -1
  173. ccxt/test/test_async.py +2 -0
  174. ccxt/test/test_sync.py +2 -0
  175. ccxt/timex.py +3 -0
  176. ccxt/tokocrypto.py +1 -1
  177. ccxt/tradeogre.py +3 -0
  178. ccxt/upbit.py +1 -1
  179. ccxt/wavesexchange.py +4 -1
  180. ccxt/wazirx.py +3 -0
  181. ccxt/whitebit.py +38 -1
  182. ccxt/woo.py +30 -1
  183. ccxt/yobit.py +4 -1
  184. ccxt/zaif.py +1 -1
  185. ccxt/zonda.py +1 -1
  186. {ccxt-4.3.5.dist-info → ccxt-4.3.7.dist-info}/METADATA +4 -4
  187. {ccxt-4.3.5.dist-info → ccxt-4.3.7.dist-info}/RECORD +189 -189
  188. {ccxt-4.3.5.dist-info → ccxt-4.3.7.dist-info}/WHEEL +0 -0
  189. {ccxt-4.3.5.dist-info → ccxt-4.3.7.dist-info}/top_level.txt +0 -0
ccxt/bithumb.py CHANGED
@@ -66,7 +66,11 @@ class bithumb(Exchange, ImplicitAPI):
66
66
  'fetchOrder': True,
67
67
  'fetchOrderBook': True,
68
68
  'fetchPosition': False,
69
+ 'fetchPositionHistory': False,
70
+ 'fetchPositionMode': False,
69
71
  'fetchPositions': False,
72
+ 'fetchPositionsForSymbol': False,
73
+ 'fetchPositionsHistory': False,
70
74
  'fetchPositionsRisk': False,
71
75
  'fetchPremiumIndexOHLCV': False,
72
76
  'fetchTicker': True,
@@ -928,7 +932,7 @@ class bithumb(Exchange, ImplicitAPI):
928
932
  }
929
933
  return self.cancel_order(order['id'], order['symbol'], self.extend(request, params))
930
934
 
931
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
935
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
932
936
  """
933
937
  make a withdrawal
934
938
  :see: https://apidocs.bithumb.com/reference/%EC%BD%94%EC%9D%B8-%EC%B6%9C%EA%B8%88%ED%95%98%EA%B8%B0-%EA%B0%9C%EC%9D%B8
ccxt/bitmart.py CHANGED
@@ -2961,7 +2961,7 @@ class bitmart(Exchange, ImplicitAPI):
2961
2961
  return code
2962
2962
  return self.network_id_to_code(networkId)
2963
2963
 
2964
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
2964
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
2965
2965
  """
2966
2966
  make a withdrawal
2967
2967
  :param str code: unified currency code
ccxt/bitmex.py CHANGED
@@ -48,6 +48,7 @@ class bitmex(Exchange, ImplicitAPI):
48
48
  'option': False,
49
49
  'addMargin': None,
50
50
  'cancelAllOrders': True,
51
+ 'cancelAllOrdersAfter': True,
51
52
  'cancelOrder': True,
52
53
  'cancelOrders': True,
53
54
  'closeAllPositions': False,
@@ -87,7 +88,9 @@ class bitmex(Exchange, ImplicitAPI):
87
88
  'fetchOrderBook': True,
88
89
  'fetchOrders': True,
89
90
  'fetchPosition': False,
91
+ 'fetchPositionHistory': False,
90
92
  'fetchPositions': True,
93
+ 'fetchPositionsHistory': False,
91
94
  'fetchPositionsRisk': False,
92
95
  'fetchPremiumIndexOHLCV': False,
93
96
  'fetchTicker': True,
@@ -1979,6 +1982,27 @@ class bitmex(Exchange, ImplicitAPI):
1979
1982
  #
1980
1983
  return self.parse_orders(response, market)
1981
1984
 
1985
+ def cancel_all_orders_after(self, timeout: Int, params={}):
1986
+ """
1987
+ dead man's switch, cancel all orders after the given timeout
1988
+ :see: https://www.bitmex.com/api/explorer/#not /Order/Order_cancelAllAfter
1989
+ :param number timeout: time in milliseconds, 0 represents cancel the timer
1990
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1991
+ :returns dict: the api result
1992
+ """
1993
+ self.load_markets()
1994
+ request: dict = {
1995
+ 'timeout': self.parse_to_int(timeout / 1000) if (timeout > 0) else 0,
1996
+ }
1997
+ response = self.privatePostOrderCancelAllAfter(self.extend(request, params))
1998
+ #
1999
+ # {
2000
+ # now: '2024-04-09T09:01:56.560Z',
2001
+ # cancelTime: '2024-04-09T09:01:56.660Z'
2002
+ # }
2003
+ #
2004
+ return response
2005
+
1982
2006
  def fetch_leverages(self, symbols: List[str] = None, params={}) -> Leverages:
1983
2007
  """
1984
2008
  fetch the set leverage for all contract markets
@@ -2255,7 +2279,7 @@ class bitmex(Exchange, ImplicitAPI):
2255
2279
  'takeProfitPrice': None,
2256
2280
  })
2257
2281
 
2258
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
2282
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
2259
2283
  """
2260
2284
  make a withdrawal
2261
2285
  :see: https://www.bitmex.com/api/explorer/#not /User/User_requestWithdrawal
ccxt/bitopro.py CHANGED
@@ -73,8 +73,13 @@ class bitopro(Exchange, ImplicitAPI):
73
73
  'fetchOrderBook': True,
74
74
  'fetchOrders': False,
75
75
  'fetchOrderTrades': False,
76
+ 'fetchPosition': False,
77
+ 'fetchPositionHistory': False,
76
78
  'fetchPositionMode': False,
77
79
  'fetchPositions': False,
80
+ 'fetchPositionsForSymbol': False,
81
+ 'fetchPositionsHistory': False,
82
+ 'fetchPositionsRisk': False,
78
83
  'fetchPremiumIndexOHLCV': False,
79
84
  'fetchTicker': True,
80
85
  'fetchTickers': True,
@@ -1479,7 +1484,7 @@ class bitopro(Exchange, ImplicitAPI):
1479
1484
  #
1480
1485
  return self.parse_transaction(result, currency)
1481
1486
 
1482
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1487
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
1483
1488
  """
1484
1489
  make a withdrawal
1485
1490
  :see: https://github.com/bitoex/bitopro-offical-api-docs/blob/master/api/v3/private/create_an_withdraw_invoice.md
ccxt/bitrue.py CHANGED
@@ -2591,7 +2591,7 @@ class bitrue(Exchange, ImplicitAPI):
2591
2591
  'fee': fee,
2592
2592
  }
2593
2593
 
2594
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
2594
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
2595
2595
  """
2596
2596
  make a withdrawal
2597
2597
  :see: https://github.com/Bitrue-exchange/Spot-official-api-docs#withdraw-commit--withdraw_data
ccxt/bitso.py CHANGED
@@ -77,8 +77,11 @@ class bitso(Exchange, ImplicitAPI):
77
77
  'fetchOrderBook': True,
78
78
  'fetchOrderTrades': True,
79
79
  'fetchPosition': False,
80
+ 'fetchPositionHistory': False,
80
81
  'fetchPositionMode': False,
81
82
  'fetchPositions': False,
83
+ 'fetchPositionsForSymbol': False,
84
+ 'fetchPositionsHistory': False,
82
85
  'fetchPositionsRisk': False,
83
86
  'fetchPremiumIndexOHLCV': False,
84
87
  'fetchTicker': True,
@@ -1473,7 +1476,7 @@ class bitso(Exchange, ImplicitAPI):
1473
1476
  result[code]['info'][code] = withdrawFee
1474
1477
  return result
1475
1478
 
1476
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1479
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
1477
1480
  """
1478
1481
  make a withdrawal
1479
1482
  :param str code: unified currency code
ccxt/bitstamp.py CHANGED
@@ -82,8 +82,11 @@ class bitstamp(Exchange, ImplicitAPI):
82
82
  'fetchOrder': True,
83
83
  'fetchOrderBook': True,
84
84
  'fetchPosition': False,
85
+ 'fetchPositionHistory': False,
85
86
  'fetchPositionMode': False,
86
87
  'fetchPositions': False,
88
+ 'fetchPositionsForSymbol': False,
89
+ 'fetchPositionsHistory': False,
87
90
  'fetchPositionsRisk': False,
88
91
  'fetchPremiumIndexOHLCV': False,
89
92
  'fetchTicker': True,
@@ -1963,7 +1966,7 @@ class bitstamp(Exchange, ImplicitAPI):
1963
1966
  'info': response,
1964
1967
  }
1965
1968
 
1966
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1969
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
1967
1970
  """
1968
1971
  make a withdrawal
1969
1972
  :see: https://www.bitstamp.net/api/#tag/Withdrawals/operation/RequestFiatWithdrawal
ccxt/bitteam.py CHANGED
@@ -96,7 +96,11 @@ class bitteam(Exchange, ImplicitAPI):
96
96
  'fetchOrders': True,
97
97
  'fetchOrderTrades': False,
98
98
  'fetchPosition': False,
99
+ 'fetchPositionHistory': False,
100
+ 'fetchPositionMode': False,
99
101
  'fetchPositions': False,
102
+ 'fetchPositionsForSymbol': False,
103
+ 'fetchPositionsHistory': False,
100
104
  'fetchPositionsRisk': False,
101
105
  'fetchPremiumIndexOHLCV': False,
102
106
  'fetchStatus': False,
ccxt/bitvavo.py CHANGED
@@ -88,8 +88,11 @@ class bitvavo(Exchange, ImplicitAPI):
88
88
  'fetchOrderBook': True,
89
89
  'fetchOrders': True,
90
90
  'fetchPosition': False,
91
+ 'fetchPositionHistory': False,
91
92
  'fetchPositionMode': False,
92
93
  'fetchPositions': False,
94
+ 'fetchPositionsForSymbol': False,
95
+ 'fetchPositionsHistory': False,
93
96
  'fetchPositionsRisk': False,
94
97
  'fetchPremiumIndexOHLCV': False,
95
98
  'fetchTicker': True,
@@ -1627,7 +1630,7 @@ class bitvavo(Exchange, ImplicitAPI):
1627
1630
  request['paymentId'] = tag
1628
1631
  return self.extend(request, params)
1629
1632
 
1630
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1633
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
1631
1634
  """
1632
1635
  make a withdrawal
1633
1636
  :param str code: unified currency code
ccxt/bl3p.py CHANGED
@@ -61,8 +61,11 @@ class bl3p(Exchange, ImplicitAPI):
61
61
  'fetchOpenInterestHistory': False,
62
62
  'fetchOrderBook': True,
63
63
  'fetchPosition': False,
64
+ 'fetchPositionHistory': False,
64
65
  'fetchPositionMode': False,
65
66
  'fetchPositions': False,
67
+ 'fetchPositionsForSymbol': False,
68
+ 'fetchPositionsHistory': False,
66
69
  'fetchPositionsRisk': False,
67
70
  'fetchPremiumIndexOHLCV': False,
68
71
  'fetchTicker': True,
ccxt/blockchaincom.py CHANGED
@@ -873,7 +873,7 @@ class blockchaincom(Exchange, ImplicitAPI):
873
873
  'fee': fee,
874
874
  }
875
875
 
876
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
876
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
877
877
  """
878
878
  make a withdrawal
879
879
  :see: https://api.blockchain.com/v3/#/payments/createWithdrawal
ccxt/btcalpha.py CHANGED
@@ -73,8 +73,11 @@ class btcalpha(Exchange, ImplicitAPI):
73
73
  'fetchOrderBook': True,
74
74
  'fetchOrders': True,
75
75
  'fetchPosition': False,
76
+ 'fetchPositionHistory': False,
76
77
  'fetchPositionMode': False,
77
78
  'fetchPositions': False,
79
+ 'fetchPositionsForSymbol': False,
80
+ 'fetchPositionsHistory': False,
78
81
  'fetchPositionsRisk': False,
79
82
  'fetchPremiumIndexOHLCV': False,
80
83
  'fetchTicker': True,
ccxt/btcbox.py CHANGED
@@ -65,8 +65,11 @@ class btcbox(Exchange, ImplicitAPI):
65
65
  'fetchOrderBook': True,
66
66
  'fetchOrders': True,
67
67
  'fetchPosition': False,
68
+ 'fetchPositionHistory': False,
68
69
  'fetchPositionMode': False,
69
70
  'fetchPositions': False,
71
+ 'fetchPositionsForSymbol': False,
72
+ 'fetchPositionsHistory': False,
70
73
  'fetchPositionsRisk': False,
71
74
  'fetchPremiumIndexOHLCV': False,
72
75
  'fetchTicker': True,
ccxt/btcmarkets.py CHANGED
@@ -73,8 +73,11 @@ class btcmarkets(Exchange, ImplicitAPI):
73
73
  'fetchOrderBook': True,
74
74
  'fetchOrders': True,
75
75
  'fetchPosition': False,
76
+ 'fetchPositionHistory': False,
76
77
  'fetchPositionMode': False,
77
78
  'fetchPositions': False,
79
+ 'fetchPositionsForSymbol': False,
80
+ 'fetchPositionsHistory': False,
78
81
  'fetchPositionsRisk': False,
79
82
  'fetchPremiumIndexOHLCV': False,
80
83
  'fetchTicker': True,
@@ -1093,7 +1096,7 @@ class btcmarkets(Exchange, ImplicitAPI):
1093
1096
  #
1094
1097
  return self.parse_trades(response, market, since, limit)
1095
1098
 
1096
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1099
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
1097
1100
  """
1098
1101
  make a withdrawal
1099
1102
  :see: https://docs.btcmarkets.net/v3/#tag/Fund-Management-APIs/paths/~1v3~1withdrawals/post
ccxt/btcturk.py CHANGED
@@ -66,8 +66,11 @@ class btcturk(Exchange, ImplicitAPI):
66
66
  'fetchOrderBook': True,
67
67
  'fetchOrders': True,
68
68
  'fetchPosition': False,
69
+ 'fetchPositionHistory': False,
69
70
  'fetchPositionMode': False,
70
71
  'fetchPositions': False,
72
+ 'fetchPositionsForSymbol': False,
73
+ 'fetchPositionsHistory': False,
71
74
  'fetchPositionsRisk': False,
72
75
  'fetchPremiumIndexOHLCV': False,
73
76
  'fetchTicker': True,
ccxt/bybit.py CHANGED
@@ -6,7 +6,7 @@
6
6
  from ccxt.base.exchange import Exchange
7
7
  from ccxt.abstract.bybit import ImplicitAPI
8
8
  import hashlib
9
- from ccxt.base.types import Balances, Currencies, Currency, Greeks, Int, Leverage, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, OrderSide, OrderType, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
9
+ from ccxt.base.types import Balances, Currencies, Currency, Greeks, Int, Leverage, Market, MarketInterface, Num, Option, OptionChain, Order, OrderBook, OrderRequest, CancellationRequest, OrderSide, OrderType, Position, Str, Strings, Ticker, Tickers, Trade, TradingFeeInterface, TradingFees, Transaction, TransferEntry
10
10
  from typing import List
11
11
  from ccxt.base.errors import ExchangeError
12
12
  from ccxt.base.errors import AuthenticationError
@@ -49,6 +49,8 @@ class bybit(Exchange, ImplicitAPI):
49
49
  'borrowCrossMargin': True,
50
50
  'cancelAllOrders': True,
51
51
  'cancelOrder': True,
52
+ 'cancelOrders': True,
53
+ 'cancelOrdersForSymbols': True,
52
54
  'closeAllPositions': False,
53
55
  'closePosition': False,
54
56
  'createMarketBuyOrderWithCost': True,
@@ -114,7 +116,9 @@ class bybit(Exchange, ImplicitAPI):
114
116
  'fetchOrders': False,
115
117
  'fetchOrderTrades': True,
116
118
  'fetchPosition': True,
119
+ 'fetchPositionHistory': 'emulated',
117
120
  'fetchPositions': True,
121
+ 'fetchPositionsHistory': True,
118
122
  'fetchPremiumIndexOHLCV': True,
119
123
  'fetchSettlementHistory': True,
120
124
  'fetchTicker': True,
@@ -4088,6 +4092,84 @@ class bybit(Exchange, ImplicitAPI):
4088
4092
  row = self.safe_list(result, 'list', [])
4089
4093
  return self.parse_orders(row, market)
4090
4094
 
4095
+ def cancel_orders_for_symbols(self, orders: List[CancellationRequest], params={}):
4096
+ """
4097
+ cancel multiple orders for multiple symbols
4098
+ :see: https://bybit-exchange.github.io/docs/v5/order/batch-cancel
4099
+ :param str[] ids: order ids
4100
+ :param str symbol: unified symbol of the market the order was made in
4101
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4102
+ :param str[] [params.clientOrderIds]: client order ids
4103
+ :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
4104
+ """
4105
+ self.load_markets()
4106
+ ordersRequests = []
4107
+ category = None
4108
+ for i in range(0, len(orders)):
4109
+ order = orders[i]
4110
+ symbol = self.safe_string(order, 'symbol')
4111
+ market = self.market(symbol)
4112
+ currentCategory = None
4113
+ currentCategory, params = self.get_bybit_type('cancelOrders', market, params)
4114
+ if currentCategory == 'inverse':
4115
+ raise NotSupported(self.id + ' cancelOrdersForSymbols does not allow inverse orders')
4116
+ if (category is not None) and (category != currentCategory):
4117
+ raise ExchangeError(self.id + ' cancelOrdersForSymbols requires all orders to be of the same category(linear, spot or option))')
4118
+ category = currentCategory
4119
+ id = self.safe_string(order, 'id')
4120
+ clientOrderId = self.safe_string(order, 'clientOrderId')
4121
+ idKey = 'orderId'
4122
+ if clientOrderId is not None:
4123
+ idKey = 'orderLinkId'
4124
+ orderItem = {
4125
+ 'symbol': market['id'],
4126
+ }
4127
+ orderItem[idKey] = id if (idKey == 'orderId') else clientOrderId
4128
+ ordersRequests.append(orderItem)
4129
+ request = {
4130
+ 'category': category,
4131
+ 'request': ordersRequests,
4132
+ }
4133
+ response = self.privatePostV5OrderCancelBatch(self.extend(request, params))
4134
+ #
4135
+ # {
4136
+ # "retCode": "0",
4137
+ # "retMsg": "OK",
4138
+ # "result": {
4139
+ # "list": [
4140
+ # {
4141
+ # "category": "spot",
4142
+ # "symbol": "BTCUSDT",
4143
+ # "orderId": "1636282505818800896",
4144
+ # "orderLinkId": "1636282505818800897"
4145
+ # },
4146
+ # {
4147
+ # "category": "spot",
4148
+ # "symbol": "BTCUSDT",
4149
+ # "orderId": "1636282505818800898",
4150
+ # "orderLinkId": "1636282505818800899"
4151
+ # }
4152
+ # ]
4153
+ # },
4154
+ # "retExtInfo": {
4155
+ # "list": [
4156
+ # {
4157
+ # "code": "0",
4158
+ # "msg": "OK"
4159
+ # },
4160
+ # {
4161
+ # "code": "0",
4162
+ # "msg": "OK"
4163
+ # }
4164
+ # ]
4165
+ # },
4166
+ # "time": "1709796158501"
4167
+ # }
4168
+ #
4169
+ result = self.safe_dict(response, 'result', {})
4170
+ row = self.safe_list(result, 'list', [])
4171
+ return self.parse_orders(row, None)
4172
+
4091
4173
  def cancel_all_usdc_orders(self, symbol: Str = None, params={}):
4092
4174
  if symbol is None:
4093
4175
  raise ArgumentsRequired(self.id + ' cancelAllUsdcOrders() requires a symbol argument')
@@ -5533,7 +5615,7 @@ class bybit(Exchange, ImplicitAPI):
5533
5615
  }
5534
5616
  return self.safe_string(types, type, type)
5535
5617
 
5536
- def withdraw(self, code: str, amount: float, address, tag=None, params={}):
5618
+ def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
5537
5619
  """
5538
5620
  make a withdrawal
5539
5621
  :see: https://bybit-exchange.github.io/docs/v5/asset/withdraw
@@ -5933,31 +6015,57 @@ class bybit(Exchange, ImplicitAPI):
5933
6015
  # "tradeMode": 0
5934
6016
  # }
5935
6017
  #
6018
+ # fetchPositionsHistory
6019
+ #
6020
+ # {
6021
+ # symbol: 'XRPUSDT',
6022
+ # orderType: 'Market',
6023
+ # leverage: '10',
6024
+ # updatedTime: '1712717265572',
6025
+ # side: 'Sell',
6026
+ # orderId: '071749f3-a9fa-427b-b5ca-27b2f52b81de',
6027
+ # closedPnl: '-0.00049568',
6028
+ # avgEntryPrice: '0.6045',
6029
+ # qty: '3',
6030
+ # cumEntryValue: '1.8135',
6031
+ # createdTime: '1712717265566',
6032
+ # orderPrice: '0.5744',
6033
+ # closedSize: '3',
6034
+ # avgExitPrice: '0.605',
6035
+ # execType: 'Trade',
6036
+ # fillCount: '1',
6037
+ # cumExitValue: '1.815'
6038
+ # }
6039
+ #
6040
+ closedSize = self.safe_string(position, 'closedSize')
6041
+ isHistory = (closedSize is not None)
5936
6042
  contract = self.safe_string(position, 'symbol')
5937
6043
  market = self.safe_market(contract, market, None, 'contract')
5938
- size = Precise.string_abs(self.safe_string(position, 'size'))
6044
+ size = Precise.string_abs(self.safe_string_2(position, 'size', 'qty'))
5939
6045
  side = self.safe_string(position, 'side')
5940
6046
  if side is not None:
5941
6047
  if side == 'Buy':
5942
- side = 'long'
6048
+ side = 'short' if isHistory else 'long'
5943
6049
  elif side == 'Sell':
5944
- side = 'short'
6050
+ side = 'long' if isHistory else 'short'
5945
6051
  else:
5946
6052
  side = None
5947
- notional = self.safe_string(position, 'positionValue')
6053
+ notional = self.safe_string_2(position, 'positionValue', 'cumExitValue')
5948
6054
  unrealisedPnl = self.omit_zero(self.safe_string(position, 'unrealisedPnl'))
5949
- initialMarginString = self.safe_string(position, 'positionIM')
6055
+ initialMarginString = self.safe_string_n(position, ['positionIM', 'cumEntryValue'])
5950
6056
  maintenanceMarginString = self.safe_string(position, 'positionMM')
5951
- timestamp = self.parse8601(self.safe_string(position, 'updated_at'))
5952
- if timestamp is None:
5953
- timestamp = self.safe_integer_n(position, ['updatedTime', 'updatedAt'])
6057
+ timestamp = self.safe_integer_n(position, ['createdTime', 'createdAt'])
6058
+ lastUpdateTimestamp = self.parse8601(self.safe_string(position, 'updated_at'))
6059
+ if lastUpdateTimestamp is None:
6060
+ lastUpdateTimestamp = self.safe_integer_n(position, ['updatedTime', 'updatedAt', 'updatedTime'])
5954
6061
  tradeMode = self.safe_integer(position, 'tradeMode', 0)
5955
6062
  marginMode = None
5956
6063
  if (not self.options['enableUnifiedAccount']) or (self.options['enableUnifiedAccount'] and market['inverse']):
5957
6064
  # tradeMode would work for classic and UTA(inverse)
5958
- marginMode = 'isolated' if (tradeMode == 1) else 'cross'
6065
+ if not isHistory: # cannot tell marginMode for fetchPositionsHistory, and closedSize will only be defined for fetchPositionsHistory response
6066
+ marginMode = 'isolated' if (tradeMode == 1) else 'cross'
5959
6067
  collateralString = self.safe_string(position, 'positionBalance')
5960
- entryPrice = self.omit_zero(self.safe_string_2(position, 'entryPrice', 'avgPrice'))
6068
+ entryPrice = self.omit_zero(self.safe_string_n(position, ['entryPrice', 'avgPrice', 'avgEntryPrice']))
5961
6069
  liquidationPrice = self.omit_zero(self.safe_string(position, 'liqPrice'))
5962
6070
  leverage = self.safe_string(position, 'leverage')
5963
6071
  if liquidationPrice is not None:
@@ -5996,7 +6104,7 @@ class bybit(Exchange, ImplicitAPI):
5996
6104
  'symbol': market['symbol'],
5997
6105
  'timestamp': timestamp,
5998
6106
  'datetime': self.iso8601(timestamp),
5999
- 'lastUpdateTimestamp': None,
6107
+ 'lastUpdateTimestamp': lastUpdateTimestamp,
6000
6108
  'initialMargin': self.parse_number(initialMarginString),
6001
6109
  'initialMarginPercentage': self.parse_number(Precise.string_div(initialMarginString, notional)),
6002
6110
  'maintenanceMargin': self.parse_number(maintenanceMarginString),
@@ -6005,12 +6113,13 @@ class bybit(Exchange, ImplicitAPI):
6005
6113
  'notional': self.parse_number(notional),
6006
6114
  'leverage': self.parse_number(leverage),
6007
6115
  'unrealizedPnl': self.parse_number(unrealisedPnl),
6116
+ 'realizedPnl': self.safe_number(position, 'closedPnl'),
6008
6117
  'contracts': self.parse_number(size), # in USD for inverse swaps
6009
6118
  'contractSize': self.safe_number(market, 'contractSize'),
6010
6119
  'marginRatio': self.parse_number(marginRatio),
6011
6120
  'liquidationPrice': self.parse_number(liquidationPrice),
6012
6121
  'markPrice': self.safe_number(position, 'markPrice'),
6013
- 'lastPrice': None,
6122
+ 'lastPrice': self.safe_number(position, 'avgExitPrice'),
6014
6123
  'collateral': self.parse_number(collateralString),
6015
6124
  'marginMode': marginMode,
6016
6125
  'side': side,
@@ -7804,6 +7913,79 @@ class bybit(Exchange, ImplicitAPI):
7804
7913
  'quoteVolume': None,
7805
7914
  }
7806
7915
 
7916
+ def fetch_positions_history(self, symbols: Strings = None, since: Int = None, limit: Int = None, params={}) -> List[Position]:
7917
+ """
7918
+ fetches historical positions
7919
+ :see: https://bybit-exchange.github.io/docs/v5/position/close-pnl
7920
+ :param str [symbol]: unified market symbols, symbols must have the same subType(must all be linear or all be inverse)
7921
+ :param int [since]: timestamp in ms of the earliest position to fetch, params["until"] - since <= 7 days
7922
+ :param int [limit]: the maximum amount of records to fetch, default=50, max=100
7923
+ :param dict params: extra parameters specific to the exchange api endpoint
7924
+ :param int [params.until]: timestamp in ms of the latest position to fetch, params["until"] - since <= 7 days
7925
+ :param str [params.subType]: 'linear' or 'inverse'
7926
+ :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
7927
+ """
7928
+ self.load_markets()
7929
+ market = None
7930
+ subType = None
7931
+ symbolsLength = 0
7932
+ if symbols is not None:
7933
+ symbolsLength = len(symbols)
7934
+ if symbolsLength > 0:
7935
+ market = self.market(symbols[0])
7936
+ until = self.safe_integer(params, 'until')
7937
+ subType, params = self.handle_sub_type_and_params('fetchPositionsHistory', market, params, 'linear')
7938
+ params = self.omit(params, 'until')
7939
+ request = {
7940
+ 'category': subType,
7941
+ }
7942
+ if (symbols is not None) and (symbolsLength == 1):
7943
+ request['symbol'] = market['id']
7944
+ if since is not None:
7945
+ request['startTime'] = since
7946
+ if limit is not None:
7947
+ request['limit'] = limit
7948
+ if until is not None:
7949
+ request['endTime'] = until
7950
+ response = self.privateGetV5PositionClosedPnl(self.extend(request, params))
7951
+ #
7952
+ # {
7953
+ # retCode: '0',
7954
+ # retMsg: 'OK',
7955
+ # result: {
7956
+ # nextPageCursor: '071749f3-a9fa-427b-b5ca-27b2f52b81de%3A1712717265566520788%2C071749f3-a9fa-427b-b5ca-27b2f52b81de%3A1712717265566520788',
7957
+ # category: 'linear',
7958
+ # list: [
7959
+ # {
7960
+ # symbol: 'XRPUSDT',
7961
+ # orderType: 'Market',
7962
+ # leverage: '10',
7963
+ # updatedTime: '1712717265572',
7964
+ # side: 'Sell',
7965
+ # orderId: '071749f3-a9fa-427b-b5ca-27b2f52b81de',
7966
+ # closedPnl: '-0.00049568',
7967
+ # avgEntryPrice: '0.6045',
7968
+ # qty: '3',
7969
+ # cumEntryValue: '1.8135',
7970
+ # createdTime: '1712717265566',
7971
+ # orderPrice: '0.5744',
7972
+ # closedSize: '3',
7973
+ # avgExitPrice: '0.605',
7974
+ # execType: 'Trade',
7975
+ # fillCount: '1',
7976
+ # cumExitValue: '1.815'
7977
+ # }
7978
+ # ]
7979
+ # },
7980
+ # retExtInfo: {},
7981
+ # time: '1712717286073'
7982
+ # }
7983
+ #
7984
+ result = self.safe_dict(response, 'result')
7985
+ rawPositions = self.safe_list(result, 'list')
7986
+ positions = self.parse_positions(rawPositions, symbols, params)
7987
+ return self.filter_by_since_limit(positions, since, limit)
7988
+
7807
7989
  def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
7808
7990
  url = self.implode_hostname(self.urls['api'][api]) + '/' + path
7809
7991
  if api == 'public':
ccxt/cex.py CHANGED
@@ -75,7 +75,13 @@ class cex(Exchange, ImplicitAPI):
75
75
  'fetchOrder': True,
76
76
  'fetchOrderBook': True,
77
77
  'fetchOrders': True,
78
+ 'fetchPosition': False,
79
+ 'fetchPositionHistory': False,
78
80
  'fetchPositionMode': False,
81
+ 'fetchPositions': False,
82
+ 'fetchPositionsForSymbol': False,
83
+ 'fetchPositionsHistory': False,
84
+ 'fetchPositionsRisk': False,
79
85
  'fetchPremiumIndexOHLCV': False,
80
86
  'fetchTicker': True,
81
87
  'fetchTickers': True,