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
@@ -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
+ async 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
+ await self.load_markets()
1994
+ request: dict = {
1995
+ 'timeout': self.parse_to_int(timeout / 1000) if (timeout > 0) else 0,
1996
+ }
1997
+ response = await 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
  async 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
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
2282
+ async 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
@@ -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
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1487
+ async 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
@@ -2592,7 +2592,7 @@ class bitrue(Exchange, ImplicitAPI):
2592
2592
  'fee': fee,
2593
2593
  }
2594
2594
 
2595
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
2595
+ async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
2596
2596
  """
2597
2597
  make a withdrawal
2598
2598
  :see: https://github.com/Bitrue-exchange/Spot-official-api-docs#withdraw-commit--withdraw_data
@@ -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
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1479
+ async 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
@@ -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
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1969
+ async 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
@@ -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,
@@ -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
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1633
+ async 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
@@ -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,
@@ -873,7 +873,7 @@ class blockchaincom(Exchange, ImplicitAPI):
873
873
  'fee': fee,
874
874
  }
875
875
 
876
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
876
+ async 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
@@ -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,
@@ -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,
@@ -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
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
1099
+ async 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
@@ -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,
@@ -7,7 +7,7 @@ from ccxt.async_support.base.exchange import Exchange
7
7
  from ccxt.abstract.bybit import ImplicitAPI
8
8
  import asyncio
9
9
  import hashlib
10
- 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
10
+ 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
11
11
  from typing import List
12
12
  from ccxt.base.errors import ExchangeError
13
13
  from ccxt.base.errors import AuthenticationError
@@ -50,6 +50,8 @@ class bybit(Exchange, ImplicitAPI):
50
50
  'borrowCrossMargin': True,
51
51
  'cancelAllOrders': True,
52
52
  'cancelOrder': True,
53
+ 'cancelOrders': True,
54
+ 'cancelOrdersForSymbols': True,
53
55
  'closeAllPositions': False,
54
56
  'closePosition': False,
55
57
  'createMarketBuyOrderWithCost': True,
@@ -115,7 +117,9 @@ class bybit(Exchange, ImplicitAPI):
115
117
  'fetchOrders': False,
116
118
  'fetchOrderTrades': True,
117
119
  'fetchPosition': True,
120
+ 'fetchPositionHistory': 'emulated',
118
121
  'fetchPositions': True,
122
+ 'fetchPositionsHistory': True,
119
123
  'fetchPremiumIndexOHLCV': True,
120
124
  'fetchSettlementHistory': True,
121
125
  'fetchTicker': True,
@@ -4089,6 +4093,84 @@ class bybit(Exchange, ImplicitAPI):
4089
4093
  row = self.safe_list(result, 'list', [])
4090
4094
  return self.parse_orders(row, market)
4091
4095
 
4096
+ async def cancel_orders_for_symbols(self, orders: List[CancellationRequest], params={}):
4097
+ """
4098
+ cancel multiple orders for multiple symbols
4099
+ :see: https://bybit-exchange.github.io/docs/v5/order/batch-cancel
4100
+ :param str[] ids: order ids
4101
+ :param str symbol: unified symbol of the market the order was made in
4102
+ :param dict [params]: extra parameters specific to the exchange API endpoint
4103
+ :param str[] [params.clientOrderIds]: client order ids
4104
+ :returns dict: an list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
4105
+ """
4106
+ await self.load_markets()
4107
+ ordersRequests = []
4108
+ category = None
4109
+ for i in range(0, len(orders)):
4110
+ order = orders[i]
4111
+ symbol = self.safe_string(order, 'symbol')
4112
+ market = self.market(symbol)
4113
+ currentCategory = None
4114
+ currentCategory, params = self.get_bybit_type('cancelOrders', market, params)
4115
+ if currentCategory == 'inverse':
4116
+ raise NotSupported(self.id + ' cancelOrdersForSymbols does not allow inverse orders')
4117
+ if (category is not None) and (category != currentCategory):
4118
+ raise ExchangeError(self.id + ' cancelOrdersForSymbols requires all orders to be of the same category(linear, spot or option))')
4119
+ category = currentCategory
4120
+ id = self.safe_string(order, 'id')
4121
+ clientOrderId = self.safe_string(order, 'clientOrderId')
4122
+ idKey = 'orderId'
4123
+ if clientOrderId is not None:
4124
+ idKey = 'orderLinkId'
4125
+ orderItem = {
4126
+ 'symbol': market['id'],
4127
+ }
4128
+ orderItem[idKey] = id if (idKey == 'orderId') else clientOrderId
4129
+ ordersRequests.append(orderItem)
4130
+ request = {
4131
+ 'category': category,
4132
+ 'request': ordersRequests,
4133
+ }
4134
+ response = await self.privatePostV5OrderCancelBatch(self.extend(request, params))
4135
+ #
4136
+ # {
4137
+ # "retCode": "0",
4138
+ # "retMsg": "OK",
4139
+ # "result": {
4140
+ # "list": [
4141
+ # {
4142
+ # "category": "spot",
4143
+ # "symbol": "BTCUSDT",
4144
+ # "orderId": "1636282505818800896",
4145
+ # "orderLinkId": "1636282505818800897"
4146
+ # },
4147
+ # {
4148
+ # "category": "spot",
4149
+ # "symbol": "BTCUSDT",
4150
+ # "orderId": "1636282505818800898",
4151
+ # "orderLinkId": "1636282505818800899"
4152
+ # }
4153
+ # ]
4154
+ # },
4155
+ # "retExtInfo": {
4156
+ # "list": [
4157
+ # {
4158
+ # "code": "0",
4159
+ # "msg": "OK"
4160
+ # },
4161
+ # {
4162
+ # "code": "0",
4163
+ # "msg": "OK"
4164
+ # }
4165
+ # ]
4166
+ # },
4167
+ # "time": "1709796158501"
4168
+ # }
4169
+ #
4170
+ result = self.safe_dict(response, 'result', {})
4171
+ row = self.safe_list(result, 'list', [])
4172
+ return self.parse_orders(row, None)
4173
+
4092
4174
  async def cancel_all_usdc_orders(self, symbol: Str = None, params={}):
4093
4175
  if symbol is None:
4094
4176
  raise ArgumentsRequired(self.id + ' cancelAllUsdcOrders() requires a symbol argument')
@@ -5534,7 +5616,7 @@ class bybit(Exchange, ImplicitAPI):
5534
5616
  }
5535
5617
  return self.safe_string(types, type, type)
5536
5618
 
5537
- async def withdraw(self, code: str, amount: float, address, tag=None, params={}):
5619
+ async def withdraw(self, code: str, amount: float, address: str, tag=None, params={}):
5538
5620
  """
5539
5621
  make a withdrawal
5540
5622
  :see: https://bybit-exchange.github.io/docs/v5/asset/withdraw
@@ -5934,31 +6016,57 @@ class bybit(Exchange, ImplicitAPI):
5934
6016
  # "tradeMode": 0
5935
6017
  # }
5936
6018
  #
6019
+ # fetchPositionsHistory
6020
+ #
6021
+ # {
6022
+ # symbol: 'XRPUSDT',
6023
+ # orderType: 'Market',
6024
+ # leverage: '10',
6025
+ # updatedTime: '1712717265572',
6026
+ # side: 'Sell',
6027
+ # orderId: '071749f3-a9fa-427b-b5ca-27b2f52b81de',
6028
+ # closedPnl: '-0.00049568',
6029
+ # avgEntryPrice: '0.6045',
6030
+ # qty: '3',
6031
+ # cumEntryValue: '1.8135',
6032
+ # createdTime: '1712717265566',
6033
+ # orderPrice: '0.5744',
6034
+ # closedSize: '3',
6035
+ # avgExitPrice: '0.605',
6036
+ # execType: 'Trade',
6037
+ # fillCount: '1',
6038
+ # cumExitValue: '1.815'
6039
+ # }
6040
+ #
6041
+ closedSize = self.safe_string(position, 'closedSize')
6042
+ isHistory = (closedSize is not None)
5937
6043
  contract = self.safe_string(position, 'symbol')
5938
6044
  market = self.safe_market(contract, market, None, 'contract')
5939
- size = Precise.string_abs(self.safe_string(position, 'size'))
6045
+ size = Precise.string_abs(self.safe_string_2(position, 'size', 'qty'))
5940
6046
  side = self.safe_string(position, 'side')
5941
6047
  if side is not None:
5942
6048
  if side == 'Buy':
5943
- side = 'long'
6049
+ side = 'short' if isHistory else 'long'
5944
6050
  elif side == 'Sell':
5945
- side = 'short'
6051
+ side = 'long' if isHistory else 'short'
5946
6052
  else:
5947
6053
  side = None
5948
- notional = self.safe_string(position, 'positionValue')
6054
+ notional = self.safe_string_2(position, 'positionValue', 'cumExitValue')
5949
6055
  unrealisedPnl = self.omit_zero(self.safe_string(position, 'unrealisedPnl'))
5950
- initialMarginString = self.safe_string(position, 'positionIM')
6056
+ initialMarginString = self.safe_string_n(position, ['positionIM', 'cumEntryValue'])
5951
6057
  maintenanceMarginString = self.safe_string(position, 'positionMM')
5952
- timestamp = self.parse8601(self.safe_string(position, 'updated_at'))
5953
- if timestamp is None:
5954
- timestamp = self.safe_integer_n(position, ['updatedTime', 'updatedAt'])
6058
+ timestamp = self.safe_integer_n(position, ['createdTime', 'createdAt'])
6059
+ lastUpdateTimestamp = self.parse8601(self.safe_string(position, 'updated_at'))
6060
+ if lastUpdateTimestamp is None:
6061
+ lastUpdateTimestamp = self.safe_integer_n(position, ['updatedTime', 'updatedAt', 'updatedTime'])
5955
6062
  tradeMode = self.safe_integer(position, 'tradeMode', 0)
5956
6063
  marginMode = None
5957
6064
  if (not self.options['enableUnifiedAccount']) or (self.options['enableUnifiedAccount'] and market['inverse']):
5958
6065
  # tradeMode would work for classic and UTA(inverse)
5959
- marginMode = 'isolated' if (tradeMode == 1) else 'cross'
6066
+ if not isHistory: # cannot tell marginMode for fetchPositionsHistory, and closedSize will only be defined for fetchPositionsHistory response
6067
+ marginMode = 'isolated' if (tradeMode == 1) else 'cross'
5960
6068
  collateralString = self.safe_string(position, 'positionBalance')
5961
- entryPrice = self.omit_zero(self.safe_string_2(position, 'entryPrice', 'avgPrice'))
6069
+ entryPrice = self.omit_zero(self.safe_string_n(position, ['entryPrice', 'avgPrice', 'avgEntryPrice']))
5962
6070
  liquidationPrice = self.omit_zero(self.safe_string(position, 'liqPrice'))
5963
6071
  leverage = self.safe_string(position, 'leverage')
5964
6072
  if liquidationPrice is not None:
@@ -5997,7 +6105,7 @@ class bybit(Exchange, ImplicitAPI):
5997
6105
  'symbol': market['symbol'],
5998
6106
  'timestamp': timestamp,
5999
6107
  'datetime': self.iso8601(timestamp),
6000
- 'lastUpdateTimestamp': None,
6108
+ 'lastUpdateTimestamp': lastUpdateTimestamp,
6001
6109
  'initialMargin': self.parse_number(initialMarginString),
6002
6110
  'initialMarginPercentage': self.parse_number(Precise.string_div(initialMarginString, notional)),
6003
6111
  'maintenanceMargin': self.parse_number(maintenanceMarginString),
@@ -6006,12 +6114,13 @@ class bybit(Exchange, ImplicitAPI):
6006
6114
  'notional': self.parse_number(notional),
6007
6115
  'leverage': self.parse_number(leverage),
6008
6116
  'unrealizedPnl': self.parse_number(unrealisedPnl),
6117
+ 'realizedPnl': self.safe_number(position, 'closedPnl'),
6009
6118
  'contracts': self.parse_number(size), # in USD for inverse swaps
6010
6119
  'contractSize': self.safe_number(market, 'contractSize'),
6011
6120
  'marginRatio': self.parse_number(marginRatio),
6012
6121
  'liquidationPrice': self.parse_number(liquidationPrice),
6013
6122
  'markPrice': self.safe_number(position, 'markPrice'),
6014
- 'lastPrice': None,
6123
+ 'lastPrice': self.safe_number(position, 'avgExitPrice'),
6015
6124
  'collateral': self.parse_number(collateralString),
6016
6125
  'marginMode': marginMode,
6017
6126
  'side': side,
@@ -7805,6 +7914,79 @@ class bybit(Exchange, ImplicitAPI):
7805
7914
  'quoteVolume': None,
7806
7915
  }
7807
7916
 
7917
+ async def fetch_positions_history(self, symbols: Strings = None, since: Int = None, limit: Int = None, params={}) -> List[Position]:
7918
+ """
7919
+ fetches historical positions
7920
+ :see: https://bybit-exchange.github.io/docs/v5/position/close-pnl
7921
+ :param str [symbol]: unified market symbols, symbols must have the same subType(must all be linear or all be inverse)
7922
+ :param int [since]: timestamp in ms of the earliest position to fetch, params["until"] - since <= 7 days
7923
+ :param int [limit]: the maximum amount of records to fetch, default=50, max=100
7924
+ :param dict params: extra parameters specific to the exchange api endpoint
7925
+ :param int [params.until]: timestamp in ms of the latest position to fetch, params["until"] - since <= 7 days
7926
+ :param str [params.subType]: 'linear' or 'inverse'
7927
+ :returns dict[]: a list of `position structures <https://docs.ccxt.com/#/?id=position-structure>`
7928
+ """
7929
+ await self.load_markets()
7930
+ market = None
7931
+ subType = None
7932
+ symbolsLength = 0
7933
+ if symbols is not None:
7934
+ symbolsLength = len(symbols)
7935
+ if symbolsLength > 0:
7936
+ market = self.market(symbols[0])
7937
+ until = self.safe_integer(params, 'until')
7938
+ subType, params = self.handle_sub_type_and_params('fetchPositionsHistory', market, params, 'linear')
7939
+ params = self.omit(params, 'until')
7940
+ request = {
7941
+ 'category': subType,
7942
+ }
7943
+ if (symbols is not None) and (symbolsLength == 1):
7944
+ request['symbol'] = market['id']
7945
+ if since is not None:
7946
+ request['startTime'] = since
7947
+ if limit is not None:
7948
+ request['limit'] = limit
7949
+ if until is not None:
7950
+ request['endTime'] = until
7951
+ response = await self.privateGetV5PositionClosedPnl(self.extend(request, params))
7952
+ #
7953
+ # {
7954
+ # retCode: '0',
7955
+ # retMsg: 'OK',
7956
+ # result: {
7957
+ # nextPageCursor: '071749f3-a9fa-427b-b5ca-27b2f52b81de%3A1712717265566520788%2C071749f3-a9fa-427b-b5ca-27b2f52b81de%3A1712717265566520788',
7958
+ # category: 'linear',
7959
+ # list: [
7960
+ # {
7961
+ # symbol: 'XRPUSDT',
7962
+ # orderType: 'Market',
7963
+ # leverage: '10',
7964
+ # updatedTime: '1712717265572',
7965
+ # side: 'Sell',
7966
+ # orderId: '071749f3-a9fa-427b-b5ca-27b2f52b81de',
7967
+ # closedPnl: '-0.00049568',
7968
+ # avgEntryPrice: '0.6045',
7969
+ # qty: '3',
7970
+ # cumEntryValue: '1.8135',
7971
+ # createdTime: '1712717265566',
7972
+ # orderPrice: '0.5744',
7973
+ # closedSize: '3',
7974
+ # avgExitPrice: '0.605',
7975
+ # execType: 'Trade',
7976
+ # fillCount: '1',
7977
+ # cumExitValue: '1.815'
7978
+ # }
7979
+ # ]
7980
+ # },
7981
+ # retExtInfo: {},
7982
+ # time: '1712717286073'
7983
+ # }
7984
+ #
7985
+ result = self.safe_dict(response, 'result')
7986
+ rawPositions = self.safe_list(result, 'list')
7987
+ positions = self.parse_positions(rawPositions, symbols, params)
7988
+ return self.filter_by_since_limit(positions, since, limit)
7989
+
7808
7990
  def sign(self, path, api='public', method='GET', params={}, headers=None, body=None):
7809
7991
  url = self.implode_hostname(self.urls['api'][api]) + '/' + path
7810
7992
  if api == 'public':
ccxt/async_support/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,