ccxt-ir 4.3.46.0.1__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.
Files changed (772) hide show
  1. ccxt/__init__.py +358 -0
  2. ccxt/abantether.py +316 -0
  3. ccxt/abstract/__init__.py +0 -0
  4. ccxt/abstract/abantether.py +5 -0
  5. ccxt/abstract/ace.py +15 -0
  6. ccxt/abstract/afratether.py +6 -0
  7. ccxt/abstract/alpaca.py +70 -0
  8. ccxt/abstract/arzinja.py +5 -0
  9. ccxt/abstract/arzplus.py +7 -0
  10. ccxt/abstract/ascendex.py +77 -0
  11. ccxt/abstract/bequant.py +115 -0
  12. ccxt/abstract/bigone.py +45 -0
  13. ccxt/abstract/binance.py +712 -0
  14. ccxt/abstract/binancecoinm.py +712 -0
  15. ccxt/abstract/binanceus.py +764 -0
  16. ccxt/abstract/binanceusdm.py +712 -0
  17. ccxt/abstract/bingx.py +113 -0
  18. ccxt/abstract/bit2c.py +27 -0
  19. ccxt/abstract/bitbank.py +27 -0
  20. ccxt/abstract/bitbay.py +53 -0
  21. ccxt/abstract/bitbns.py +40 -0
  22. ccxt/abstract/bitcoincom.py +115 -0
  23. ccxt/abstract/bitfinex.py +69 -0
  24. ccxt/abstract/bitfinex2.py +139 -0
  25. ccxt/abstract/bitflyer.py +38 -0
  26. ccxt/abstract/bitget.py +508 -0
  27. ccxt/abstract/bithumb.py +32 -0
  28. ccxt/abstract/bitimen.py +7 -0
  29. ccxt/abstract/bitir.py +7 -0
  30. ccxt/abstract/bitmart.py +99 -0
  31. ccxt/abstract/bitmex.py +97 -0
  32. ccxt/abstract/bitopro.py +29 -0
  33. ccxt/abstract/bitpanda.py +35 -0
  34. ccxt/abstract/bitpin.py +7 -0
  35. ccxt/abstract/bitrue.py +72 -0
  36. ccxt/abstract/bitso.py +43 -0
  37. ccxt/abstract/bitstamp.py +258 -0
  38. ccxt/abstract/bitteam.py +29 -0
  39. ccxt/abstract/bitvavo.py +27 -0
  40. ccxt/abstract/bl3p.py +19 -0
  41. ccxt/abstract/blockchaincom.py +28 -0
  42. ccxt/abstract/blofin.py +37 -0
  43. ccxt/abstract/btcalpha.py +18 -0
  44. ccxt/abstract/btcbox.py +13 -0
  45. ccxt/abstract/btcmarkets.py +39 -0
  46. ccxt/abstract/btcturk.py +20 -0
  47. ccxt/abstract/bybit.py +298 -0
  48. ccxt/abstract/cex.py +33 -0
  49. ccxt/abstract/coinbase.py +94 -0
  50. ccxt/abstract/coinbaseadvanced.py +94 -0
  51. ccxt/abstract/coinbaseexchange.py +67 -0
  52. ccxt/abstract/coinbaseinternational.py +39 -0
  53. ccxt/abstract/coincatch.py +94 -0
  54. ccxt/abstract/coincheck.py +33 -0
  55. ccxt/abstract/coinex.py +237 -0
  56. ccxt/abstract/coinlist.py +54 -0
  57. ccxt/abstract/coinmate.py +62 -0
  58. ccxt/abstract/coinmetro.py +34 -0
  59. ccxt/abstract/coinone.py +67 -0
  60. ccxt/abstract/coinsph.py +54 -0
  61. ccxt/abstract/coinspot.py +28 -0
  62. ccxt/abstract/cryptocom.py +107 -0
  63. ccxt/abstract/currencycom.py +68 -0
  64. ccxt/abstract/delta.py +50 -0
  65. ccxt/abstract/deribit.py +125 -0
  66. ccxt/abstract/digifinex.py +91 -0
  67. ccxt/abstract/eterex.py +5 -0
  68. ccxt/abstract/excoino.py +7 -0
  69. ccxt/abstract/exir.py +8 -0
  70. ccxt/abstract/exmo.py +55 -0
  71. ccxt/abstract/exnovin.py +6 -0
  72. ccxt/abstract/farhadexchange.py +5 -0
  73. ccxt/abstract/fmfwio.py +115 -0
  74. ccxt/abstract/gate.py +265 -0
  75. ccxt/abstract/gateio.py +265 -0
  76. ccxt/abstract/gemini.py +58 -0
  77. ccxt/abstract/hashkey.py +67 -0
  78. ccxt/abstract/hitbtc.py +115 -0
  79. ccxt/abstract/hitbtc3.py +115 -0
  80. ccxt/abstract/hitobit.py +8 -0
  81. ccxt/abstract/hollaex.py +33 -0
  82. ccxt/abstract/htx.py +548 -0
  83. ccxt/abstract/huobi.py +548 -0
  84. ccxt/abstract/huobijp.py +114 -0
  85. ccxt/abstract/hyperliquid.py +6 -0
  86. ccxt/abstract/idex.py +26 -0
  87. ccxt/abstract/independentreserve.py +37 -0
  88. ccxt/abstract/indodax.py +26 -0
  89. ccxt/abstract/jibitex.py +7 -0
  90. ccxt/abstract/kraken.py +57 -0
  91. ccxt/abstract/krakenfutures.py +38 -0
  92. ccxt/abstract/kucoin.py +214 -0
  93. ccxt/abstract/kucoinfutures.py +233 -0
  94. ccxt/abstract/kuna.py +182 -0
  95. ccxt/abstract/latoken.py +56 -0
  96. ccxt/abstract/lbank.py +61 -0
  97. ccxt/abstract/luno.py +37 -0
  98. ccxt/abstract/lykke.py +29 -0
  99. ccxt/abstract/mercado.py +25 -0
  100. ccxt/abstract/mexc.py +178 -0
  101. ccxt/abstract/ndax.py +97 -0
  102. ccxt/abstract/nobitex.py +7 -0
  103. ccxt/abstract/novadax.py +29 -0
  104. ccxt/abstract/oceanex.py +22 -0
  105. ccxt/abstract/okcoin.py +74 -0
  106. ccxt/abstract/okexchange.py +8 -0
  107. ccxt/abstract/okx.py +324 -0
  108. ccxt/abstract/ompfinex.py +7 -0
  109. ccxt/abstract/onetrading.py +35 -0
  110. ccxt/abstract/oxfun.py +34 -0
  111. ccxt/abstract/p2b.py +22 -0
  112. ccxt/abstract/paradex.py +40 -0
  113. ccxt/abstract/paymium.py +28 -0
  114. ccxt/abstract/phemex.py +115 -0
  115. ccxt/abstract/poloniex.py +69 -0
  116. ccxt/abstract/poloniexfutures.py +48 -0
  117. ccxt/abstract/probit.py +23 -0
  118. ccxt/abstract/ramzinex.py +7 -0
  119. ccxt/abstract/sarmayex.py +5 -0
  120. ccxt/abstract/sarrafex.py +7 -0
  121. ccxt/abstract/tabdeal.py +7 -0
  122. ccxt/abstract/tetherland.py +5 -0
  123. ccxt/abstract/timex.py +62 -0
  124. ccxt/abstract/tokocrypto.py +37 -0
  125. ccxt/abstract/tradeogre.py +16 -0
  126. ccxt/abstract/twox.py +5 -0
  127. ccxt/abstract/ubitex.py +7 -0
  128. ccxt/abstract/upbit.py +38 -0
  129. ccxt/abstract/vertex.py +19 -0
  130. ccxt/abstract/wallex.py +8 -0
  131. ccxt/abstract/wavesexchange.py +154 -0
  132. ccxt/abstract/wazirx.py +30 -0
  133. ccxt/abstract/whitebit.py +98 -0
  134. ccxt/abstract/woo.py +83 -0
  135. ccxt/abstract/woofipro.py +119 -0
  136. ccxt/abstract/xt.py +152 -0
  137. ccxt/abstract/yobit.py +16 -0
  138. ccxt/abstract/zaif.py +38 -0
  139. ccxt/abstract/zonda.py +53 -0
  140. ccxt/ace.py +1012 -0
  141. ccxt/afratether.py +293 -0
  142. ccxt/alpaca.py +1083 -0
  143. ccxt/arzinja.py +285 -0
  144. ccxt/arzplus.py +412 -0
  145. ccxt/ascendex.py +3330 -0
  146. ccxt/async_support/__init__.py +337 -0
  147. ccxt/async_support/abantether.py +316 -0
  148. ccxt/async_support/ace.py +1012 -0
  149. ccxt/async_support/afratether.py +293 -0
  150. ccxt/async_support/alpaca.py +1083 -0
  151. ccxt/async_support/arzinja.py +285 -0
  152. ccxt/async_support/arzplus.py +412 -0
  153. ccxt/async_support/ascendex.py +3330 -0
  154. ccxt/async_support/base/__init__.py +1 -0
  155. ccxt/async_support/base/exchange.py +1966 -0
  156. ccxt/async_support/base/throttler.py +50 -0
  157. ccxt/async_support/base/ws/__init__.py +38 -0
  158. ccxt/async_support/base/ws/aiohttp_client.py +125 -0
  159. ccxt/async_support/base/ws/cache.py +212 -0
  160. ccxt/async_support/base/ws/client.py +193 -0
  161. ccxt/async_support/base/ws/fast_client.py +96 -0
  162. ccxt/async_support/base/ws/functions.py +59 -0
  163. ccxt/async_support/base/ws/future.py +58 -0
  164. ccxt/async_support/base/ws/order_book.py +78 -0
  165. ccxt/async_support/base/ws/order_book_side.py +174 -0
  166. ccxt/async_support/bequant.py +33 -0
  167. ccxt/async_support/bigone.py +2113 -0
  168. ccxt/async_support/binance.py +12234 -0
  169. ccxt/async_support/binancecoinm.py +45 -0
  170. ccxt/async_support/binanceus.py +211 -0
  171. ccxt/async_support/binanceusdm.py +58 -0
  172. ccxt/async_support/bingx.py +4325 -0
  173. ccxt/async_support/bit2c.py +866 -0
  174. ccxt/async_support/bitbank.py +1001 -0
  175. ccxt/async_support/bitbay.py +17 -0
  176. ccxt/async_support/bitbns.py +1154 -0
  177. ccxt/async_support/bitcoincom.py +17 -0
  178. ccxt/async_support/bitfinex.py +1617 -0
  179. ccxt/async_support/bitfinex2.py +3552 -0
  180. ccxt/async_support/bitflyer.py +995 -0
  181. ccxt/async_support/bitget.py +8273 -0
  182. ccxt/async_support/bithumb.py +1061 -0
  183. ccxt/async_support/bitimen.py +401 -0
  184. ccxt/async_support/bitir.py +490 -0
  185. ccxt/async_support/bitmart.py +4415 -0
  186. ccxt/async_support/bitmex.py +2756 -0
  187. ccxt/async_support/bitopro.py +1630 -0
  188. ccxt/async_support/bitpanda.py +16 -0
  189. ccxt/async_support/bitpin.py +454 -0
  190. ccxt/async_support/bitrue.py +3027 -0
  191. ccxt/async_support/bitso.py +1670 -0
  192. ccxt/async_support/bitstamp.py +2203 -0
  193. ccxt/async_support/bitteam.py +2239 -0
  194. ccxt/async_support/bitvavo.py +1968 -0
  195. ccxt/async_support/bl3p.py +485 -0
  196. ccxt/async_support/blockchaincom.py +1104 -0
  197. ccxt/async_support/blofin.py +2066 -0
  198. ccxt/async_support/btcalpha.py +891 -0
  199. ccxt/async_support/btcbox.py +544 -0
  200. ccxt/async_support/btcmarkets.py +1221 -0
  201. ccxt/async_support/btcturk.py +911 -0
  202. ccxt/async_support/bybit.py +8159 -0
  203. ccxt/async_support/cex.py +1605 -0
  204. ccxt/async_support/coinbase.py +4475 -0
  205. ccxt/async_support/coinbaseadvanced.py +17 -0
  206. ccxt/async_support/coinbaseexchange.py +1734 -0
  207. ccxt/async_support/coinbaseinternational.py +1899 -0
  208. ccxt/async_support/coincatch.py +5069 -0
  209. ccxt/async_support/coincheck.py +815 -0
  210. ccxt/async_support/coinex.py +5526 -0
  211. ccxt/async_support/coinlist.py +2243 -0
  212. ccxt/async_support/coinmate.py +1067 -0
  213. ccxt/async_support/coinmetro.py +1797 -0
  214. ccxt/async_support/coinone.py +1127 -0
  215. ccxt/async_support/coinsph.py +1850 -0
  216. ccxt/async_support/coinspot.py +534 -0
  217. ccxt/async_support/cryptocom.py +2822 -0
  218. ccxt/async_support/currencycom.py +1950 -0
  219. ccxt/async_support/delta.py +3376 -0
  220. ccxt/async_support/deribit.py +3437 -0
  221. ccxt/async_support/digifinex.py +3960 -0
  222. ccxt/async_support/eterex.py +286 -0
  223. ccxt/async_support/excoino.py +399 -0
  224. ccxt/async_support/exir.py +375 -0
  225. ccxt/async_support/exmo.py +2462 -0
  226. ccxt/async_support/exnovin.py +360 -0
  227. ccxt/async_support/farhadexchange.py +266 -0
  228. ccxt/async_support/fmfwio.py +34 -0
  229. ccxt/async_support/gate.py +6976 -0
  230. ccxt/async_support/gateio.py +16 -0
  231. ccxt/async_support/gemini.py +1825 -0
  232. ccxt/async_support/hashkey.py +4150 -0
  233. ccxt/async_support/hitbtc.py +3423 -0
  234. ccxt/async_support/hitbtc3.py +16 -0
  235. ccxt/async_support/hitobit.py +391 -0
  236. ccxt/async_support/hollaex.py +1813 -0
  237. ccxt/async_support/htx.py +8506 -0
  238. ccxt/async_support/huobi.py +16 -0
  239. ccxt/async_support/huobijp.py +1801 -0
  240. ccxt/async_support/hyperliquid.py +2431 -0
  241. ccxt/async_support/idex.py +1766 -0
  242. ccxt/async_support/independentreserve.py +784 -0
  243. ccxt/async_support/indodax.py +1247 -0
  244. ccxt/async_support/jibitex.py +395 -0
  245. ccxt/async_support/kraken.py +2894 -0
  246. ccxt/async_support/krakenfutures.py +2601 -0
  247. ccxt/async_support/kucoin.py +4602 -0
  248. ccxt/async_support/kucoinfutures.py +2698 -0
  249. ccxt/async_support/kuna.py +1841 -0
  250. ccxt/async_support/latoken.py +1664 -0
  251. ccxt/async_support/lbank.py +2683 -0
  252. ccxt/async_support/luno.py +1067 -0
  253. ccxt/async_support/lykke.py +1270 -0
  254. ccxt/async_support/mercado.py +842 -0
  255. ccxt/async_support/mexc.py +5369 -0
  256. ccxt/async_support/ndax.py +2354 -0
  257. ccxt/async_support/nobitex.py +419 -0
  258. ccxt/async_support/novadax.py +1484 -0
  259. ccxt/async_support/oceanex.py +903 -0
  260. ccxt/async_support/okcoin.py +2936 -0
  261. ccxt/async_support/okexchange.py +349 -0
  262. ccxt/async_support/okx.py +7827 -0
  263. ccxt/async_support/ompfinex.py +472 -0
  264. ccxt/async_support/onetrading.py +1911 -0
  265. ccxt/async_support/oxfun.py +2773 -0
  266. ccxt/async_support/p2b.py +1194 -0
  267. ccxt/async_support/paradex.py +2015 -0
  268. ccxt/async_support/paymium.py +564 -0
  269. ccxt/async_support/phemex.py +4473 -0
  270. ccxt/async_support/poloniex.py +2232 -0
  271. ccxt/async_support/poloniexfutures.py +1717 -0
  272. ccxt/async_support/probit.py +1734 -0
  273. ccxt/async_support/ramzinex.py +476 -0
  274. ccxt/async_support/sarmayex.py +357 -0
  275. ccxt/async_support/sarrafex.py +478 -0
  276. ccxt/async_support/tabdeal.py +364 -0
  277. ccxt/async_support/tetherland.py +349 -0
  278. ccxt/async_support/timex.py +1593 -0
  279. ccxt/async_support/tokocrypto.py +2405 -0
  280. ccxt/async_support/tradeogre.py +608 -0
  281. ccxt/async_support/twox.py +326 -0
  282. ccxt/async_support/ubitex.py +409 -0
  283. ccxt/async_support/upbit.py +1833 -0
  284. ccxt/async_support/vertex.py +2922 -0
  285. ccxt/async_support/wallex.py +445 -0
  286. ccxt/async_support/wavesexchange.py +2473 -0
  287. ccxt/async_support/wazirx.py +1224 -0
  288. ccxt/async_support/whitebit.py +2469 -0
  289. ccxt/async_support/woo.py +3114 -0
  290. ccxt/async_support/woofipro.py +2533 -0
  291. ccxt/async_support/xt.py +4454 -0
  292. ccxt/async_support/yobit.py +1283 -0
  293. ccxt/async_support/zaif.py +725 -0
  294. ccxt/async_support/zonda.py +1828 -0
  295. ccxt/base/__init__.py +27 -0
  296. ccxt/base/decimal_to_precision.py +174 -0
  297. ccxt/base/errors.py +242 -0
  298. ccxt/base/exchange.py +5941 -0
  299. ccxt/base/precise.py +287 -0
  300. ccxt/base/types.py +502 -0
  301. ccxt/bequant.py +33 -0
  302. ccxt/bigone.py +2112 -0
  303. ccxt/binance.py +12233 -0
  304. ccxt/binancecoinm.py +45 -0
  305. ccxt/binanceus.py +211 -0
  306. ccxt/binanceusdm.py +58 -0
  307. ccxt/bingx.py +4324 -0
  308. ccxt/bit2c.py +866 -0
  309. ccxt/bitbank.py +1001 -0
  310. ccxt/bitbay.py +17 -0
  311. ccxt/bitbns.py +1154 -0
  312. ccxt/bitcoincom.py +17 -0
  313. ccxt/bitfinex.py +1617 -0
  314. ccxt/bitfinex2.py +3552 -0
  315. ccxt/bitflyer.py +995 -0
  316. ccxt/bitget.py +8272 -0
  317. ccxt/bithumb.py +1061 -0
  318. ccxt/bitimen.py +401 -0
  319. ccxt/bitir.py +490 -0
  320. ccxt/bitmart.py +4415 -0
  321. ccxt/bitmex.py +2756 -0
  322. ccxt/bitopro.py +1630 -0
  323. ccxt/bitpanda.py +16 -0
  324. ccxt/bitpin.py +454 -0
  325. ccxt/bitrue.py +3026 -0
  326. ccxt/bitso.py +1670 -0
  327. ccxt/bitstamp.py +2203 -0
  328. ccxt/bitteam.py +2239 -0
  329. ccxt/bitvavo.py +1968 -0
  330. ccxt/bl3p.py +485 -0
  331. ccxt/blockchaincom.py +1104 -0
  332. ccxt/blofin.py +2066 -0
  333. ccxt/btcalpha.py +891 -0
  334. ccxt/btcbox.py +544 -0
  335. ccxt/btcmarkets.py +1221 -0
  336. ccxt/btcturk.py +911 -0
  337. ccxt/bybit.py +8158 -0
  338. ccxt/cex.py +1605 -0
  339. ccxt/coinbase.py +4474 -0
  340. ccxt/coinbaseadvanced.py +17 -0
  341. ccxt/coinbaseexchange.py +1734 -0
  342. ccxt/coinbaseinternational.py +1899 -0
  343. ccxt/coincatch.py +5069 -0
  344. ccxt/coincheck.py +815 -0
  345. ccxt/coinex.py +5525 -0
  346. ccxt/coinlist.py +2243 -0
  347. ccxt/coinmate.py +1067 -0
  348. ccxt/coinmetro.py +1797 -0
  349. ccxt/coinone.py +1127 -0
  350. ccxt/coinsph.py +1850 -0
  351. ccxt/coinspot.py +534 -0
  352. ccxt/cryptocom.py +2822 -0
  353. ccxt/currencycom.py +1950 -0
  354. ccxt/delta.py +3376 -0
  355. ccxt/deribit.py +3437 -0
  356. ccxt/digifinex.py +3959 -0
  357. ccxt/eterex.py +286 -0
  358. ccxt/excoino.py +399 -0
  359. ccxt/exir.py +375 -0
  360. ccxt/exmo.py +2462 -0
  361. ccxt/exnovin.py +360 -0
  362. ccxt/farhadexchange.py +266 -0
  363. ccxt/fmfwio.py +34 -0
  364. ccxt/gate.py +6975 -0
  365. ccxt/gateio.py +16 -0
  366. ccxt/gemini.py +1824 -0
  367. ccxt/hashkey.py +4150 -0
  368. ccxt/hitbtc.py +3423 -0
  369. ccxt/hitbtc3.py +16 -0
  370. ccxt/hitobit.py +391 -0
  371. ccxt/hollaex.py +1813 -0
  372. ccxt/htx.py +8505 -0
  373. ccxt/huobi.py +16 -0
  374. ccxt/huobijp.py +1801 -0
  375. ccxt/hyperliquid.py +2430 -0
  376. ccxt/idex.py +1766 -0
  377. ccxt/independentreserve.py +784 -0
  378. ccxt/indodax.py +1247 -0
  379. ccxt/jibitex.py +395 -0
  380. ccxt/kraken.py +2894 -0
  381. ccxt/krakenfutures.py +2601 -0
  382. ccxt/kucoin.py +4601 -0
  383. ccxt/kucoinfutures.py +2698 -0
  384. ccxt/kuna.py +1841 -0
  385. ccxt/latoken.py +1664 -0
  386. ccxt/lbank.py +2682 -0
  387. ccxt/luno.py +1067 -0
  388. ccxt/lykke.py +1270 -0
  389. ccxt/mercado.py +842 -0
  390. ccxt/mexc.py +5369 -0
  391. ccxt/ndax.py +2354 -0
  392. ccxt/nobitex.py +419 -0
  393. ccxt/novadax.py +1484 -0
  394. ccxt/oceanex.py +903 -0
  395. ccxt/okcoin.py +2936 -0
  396. ccxt/okexchange.py +349 -0
  397. ccxt/okx.py +7826 -0
  398. ccxt/ompfinex.py +472 -0
  399. ccxt/onetrading.py +1911 -0
  400. ccxt/oxfun.py +2772 -0
  401. ccxt/p2b.py +1194 -0
  402. ccxt/paradex.py +2015 -0
  403. ccxt/paymium.py +564 -0
  404. ccxt/phemex.py +4473 -0
  405. ccxt/poloniex.py +2232 -0
  406. ccxt/poloniexfutures.py +1717 -0
  407. ccxt/pro/__init__.py +149 -0
  408. ccxt/pro/alpaca.py +685 -0
  409. ccxt/pro/ascendex.py +916 -0
  410. ccxt/pro/bequant.py +38 -0
  411. ccxt/pro/binance.py +3488 -0
  412. ccxt/pro/binancecoinm.py +28 -0
  413. ccxt/pro/binanceus.py +48 -0
  414. ccxt/pro/binanceusdm.py +31 -0
  415. ccxt/pro/bingx.py +1264 -0
  416. ccxt/pro/bitcoincom.py +34 -0
  417. ccxt/pro/bitfinex.py +621 -0
  418. ccxt/pro/bitfinex2.py +1083 -0
  419. ccxt/pro/bitget.py +1692 -0
  420. ccxt/pro/bithumb.py +368 -0
  421. ccxt/pro/bitmart.py +1449 -0
  422. ccxt/pro/bitmex.py +1656 -0
  423. ccxt/pro/bitopro.py +445 -0
  424. ccxt/pro/bitpanda.py +15 -0
  425. ccxt/pro/bitrue.py +447 -0
  426. ccxt/pro/bitstamp.py +522 -0
  427. ccxt/pro/bitvavo.py +1270 -0
  428. ccxt/pro/blockchaincom.py +738 -0
  429. ccxt/pro/blofin.py +692 -0
  430. ccxt/pro/bybit.py +2000 -0
  431. ccxt/pro/cex.py +1440 -0
  432. ccxt/pro/coinbase.py +678 -0
  433. ccxt/pro/coinbaseadvanced.py +16 -0
  434. ccxt/pro/coinbaseexchange.py +895 -0
  435. ccxt/pro/coinbaseinternational.py +620 -0
  436. ccxt/pro/coincatch.py +1464 -0
  437. ccxt/pro/coincheck.py +199 -0
  438. ccxt/pro/coinex.py +1061 -0
  439. ccxt/pro/coinone.py +395 -0
  440. ccxt/pro/cryptocom.py +947 -0
  441. ccxt/pro/currencycom.py +536 -0
  442. ccxt/pro/deribit.py +892 -0
  443. ccxt/pro/exmo.py +629 -0
  444. ccxt/pro/gate.py +1416 -0
  445. ccxt/pro/gateio.py +15 -0
  446. ccxt/pro/gemini.py +865 -0
  447. ccxt/pro/hashkey.py +802 -0
  448. ccxt/pro/hitbtc.py +1216 -0
  449. ccxt/pro/hollaex.py +563 -0
  450. ccxt/pro/htx.py +2215 -0
  451. ccxt/pro/huobi.py +15 -0
  452. ccxt/pro/huobijp.py +570 -0
  453. ccxt/pro/hyperliquid.py +525 -0
  454. ccxt/pro/idex.py +672 -0
  455. ccxt/pro/independentreserve.py +270 -0
  456. ccxt/pro/kraken.py +1356 -0
  457. ccxt/pro/krakenfutures.py +1492 -0
  458. ccxt/pro/kucoin.py +1133 -0
  459. ccxt/pro/kucoinfutures.py +1081 -0
  460. ccxt/pro/lbank.py +843 -0
  461. ccxt/pro/luno.py +303 -0
  462. ccxt/pro/mexc.py +1122 -0
  463. ccxt/pro/ndax.py +506 -0
  464. ccxt/pro/okcoin.py +698 -0
  465. ccxt/pro/okx.py +1851 -0
  466. ccxt/pro/onetrading.py +1275 -0
  467. ccxt/pro/oxfun.py +950 -0
  468. ccxt/pro/p2b.py +419 -0
  469. ccxt/pro/paradex.py +352 -0
  470. ccxt/pro/phemex.py +1441 -0
  471. ccxt/pro/poloniex.py +1166 -0
  472. ccxt/pro/poloniexfutures.py +990 -0
  473. ccxt/pro/probit.py +551 -0
  474. ccxt/pro/upbit.py +520 -0
  475. ccxt/pro/vertex.py +943 -0
  476. ccxt/pro/wazirx.py +749 -0
  477. ccxt/pro/whitebit.py +864 -0
  478. ccxt/pro/woo.py +1078 -0
  479. ccxt/pro/woofipro.py +1183 -0
  480. ccxt/pro/xt.py +1067 -0
  481. ccxt/probit.py +1734 -0
  482. ccxt/ramzinex.py +476 -0
  483. ccxt/sarmayex.py +357 -0
  484. ccxt/sarrafex.py +478 -0
  485. ccxt/static_dependencies/__init__.py +1 -0
  486. ccxt/static_dependencies/ecdsa/__init__.py +14 -0
  487. ccxt/static_dependencies/ecdsa/_version.py +520 -0
  488. ccxt/static_dependencies/ecdsa/curves.py +56 -0
  489. ccxt/static_dependencies/ecdsa/der.py +221 -0
  490. ccxt/static_dependencies/ecdsa/ecdsa.py +310 -0
  491. ccxt/static_dependencies/ecdsa/ellipticcurve.py +197 -0
  492. ccxt/static_dependencies/ecdsa/keys.py +332 -0
  493. ccxt/static_dependencies/ecdsa/numbertheory.py +531 -0
  494. ccxt/static_dependencies/ecdsa/rfc6979.py +100 -0
  495. ccxt/static_dependencies/ecdsa/util.py +266 -0
  496. ccxt/static_dependencies/ethereum/__init__.py +7 -0
  497. ccxt/static_dependencies/ethereum/abi/__init__.py +16 -0
  498. ccxt/static_dependencies/ethereum/abi/abi.py +19 -0
  499. ccxt/static_dependencies/ethereum/abi/base.py +152 -0
  500. ccxt/static_dependencies/ethereum/abi/codec.py +217 -0
  501. ccxt/static_dependencies/ethereum/abi/constants.py +3 -0
  502. ccxt/static_dependencies/ethereum/abi/decoding.py +565 -0
  503. ccxt/static_dependencies/ethereum/abi/encoding.py +720 -0
  504. ccxt/static_dependencies/ethereum/abi/exceptions.py +139 -0
  505. ccxt/static_dependencies/ethereum/abi/grammar.py +443 -0
  506. ccxt/static_dependencies/ethereum/abi/packed.py +13 -0
  507. ccxt/static_dependencies/ethereum/abi/py.typed +0 -0
  508. ccxt/static_dependencies/ethereum/abi/registry.py +643 -0
  509. ccxt/static_dependencies/ethereum/abi/tools/__init__.py +3 -0
  510. ccxt/static_dependencies/ethereum/abi/tools/_strategies.py +230 -0
  511. ccxt/static_dependencies/ethereum/abi/utils/__init__.py +0 -0
  512. ccxt/static_dependencies/ethereum/abi/utils/numeric.py +83 -0
  513. ccxt/static_dependencies/ethereum/abi/utils/padding.py +27 -0
  514. ccxt/static_dependencies/ethereum/abi/utils/string.py +19 -0
  515. ccxt/static_dependencies/ethereum/account/__init__.py +3 -0
  516. ccxt/static_dependencies/ethereum/account/encode_typed_data/__init__.py +4 -0
  517. ccxt/static_dependencies/ethereum/account/encode_typed_data/encoding_and_hashing.py +239 -0
  518. ccxt/static_dependencies/ethereum/account/encode_typed_data/helpers.py +40 -0
  519. ccxt/static_dependencies/ethereum/account/messages.py +263 -0
  520. ccxt/static_dependencies/ethereum/account/py.typed +0 -0
  521. ccxt/static_dependencies/ethereum/hexbytes/__init__.py +5 -0
  522. ccxt/static_dependencies/ethereum/hexbytes/_utils.py +54 -0
  523. ccxt/static_dependencies/ethereum/hexbytes/main.py +65 -0
  524. ccxt/static_dependencies/ethereum/hexbytes/py.typed +0 -0
  525. ccxt/static_dependencies/ethereum/typing/__init__.py +63 -0
  526. ccxt/static_dependencies/ethereum/typing/abi.py +6 -0
  527. ccxt/static_dependencies/ethereum/typing/bls.py +7 -0
  528. ccxt/static_dependencies/ethereum/typing/discovery.py +5 -0
  529. ccxt/static_dependencies/ethereum/typing/encoding.py +7 -0
  530. ccxt/static_dependencies/ethereum/typing/enums.py +17 -0
  531. ccxt/static_dependencies/ethereum/typing/ethpm.py +9 -0
  532. ccxt/static_dependencies/ethereum/typing/evm.py +20 -0
  533. ccxt/static_dependencies/ethereum/typing/networks.py +1122 -0
  534. ccxt/static_dependencies/ethereum/typing/py.typed +0 -0
  535. ccxt/static_dependencies/ethereum/utils/__init__.py +115 -0
  536. ccxt/static_dependencies/ethereum/utils/abi.py +72 -0
  537. ccxt/static_dependencies/ethereum/utils/address.py +171 -0
  538. ccxt/static_dependencies/ethereum/utils/applicators.py +151 -0
  539. ccxt/static_dependencies/ethereum/utils/conversions.py +190 -0
  540. ccxt/static_dependencies/ethereum/utils/currency.py +107 -0
  541. ccxt/static_dependencies/ethereum/utils/curried/__init__.py +269 -0
  542. ccxt/static_dependencies/ethereum/utils/debug.py +20 -0
  543. ccxt/static_dependencies/ethereum/utils/decorators.py +132 -0
  544. ccxt/static_dependencies/ethereum/utils/encoding.py +6 -0
  545. ccxt/static_dependencies/ethereum/utils/exceptions.py +4 -0
  546. ccxt/static_dependencies/ethereum/utils/functional.py +75 -0
  547. ccxt/static_dependencies/ethereum/utils/hexadecimal.py +74 -0
  548. ccxt/static_dependencies/ethereum/utils/humanize.py +188 -0
  549. ccxt/static_dependencies/ethereum/utils/logging.py +159 -0
  550. ccxt/static_dependencies/ethereum/utils/module_loading.py +31 -0
  551. ccxt/static_dependencies/ethereum/utils/numeric.py +43 -0
  552. ccxt/static_dependencies/ethereum/utils/py.typed +0 -0
  553. ccxt/static_dependencies/ethereum/utils/toolz.py +76 -0
  554. ccxt/static_dependencies/ethereum/utils/types.py +54 -0
  555. ccxt/static_dependencies/ethereum/utils/typing/__init__.py +18 -0
  556. ccxt/static_dependencies/ethereum/utils/typing/misc.py +14 -0
  557. ccxt/static_dependencies/ethereum/utils/units.py +31 -0
  558. ccxt/static_dependencies/keccak/__init__.py +3 -0
  559. ccxt/static_dependencies/keccak/keccak.py +197 -0
  560. ccxt/static_dependencies/lark/__init__.py +38 -0
  561. ccxt/static_dependencies/lark/__pyinstaller/__init__.py +6 -0
  562. ccxt/static_dependencies/lark/__pyinstaller/hook-lark.py +14 -0
  563. ccxt/static_dependencies/lark/ast_utils.py +59 -0
  564. ccxt/static_dependencies/lark/common.py +86 -0
  565. ccxt/static_dependencies/lark/exceptions.py +292 -0
  566. ccxt/static_dependencies/lark/grammar.py +130 -0
  567. ccxt/static_dependencies/lark/grammars/__init__.py +0 -0
  568. ccxt/static_dependencies/lark/indenter.py +143 -0
  569. ccxt/static_dependencies/lark/lark.py +658 -0
  570. ccxt/static_dependencies/lark/lexer.py +678 -0
  571. ccxt/static_dependencies/lark/load_grammar.py +1428 -0
  572. ccxt/static_dependencies/lark/parse_tree_builder.py +391 -0
  573. ccxt/static_dependencies/lark/parser_frontends.py +257 -0
  574. ccxt/static_dependencies/lark/parsers/__init__.py +0 -0
  575. ccxt/static_dependencies/lark/parsers/cyk.py +340 -0
  576. ccxt/static_dependencies/lark/parsers/earley.py +314 -0
  577. ccxt/static_dependencies/lark/parsers/earley_common.py +42 -0
  578. ccxt/static_dependencies/lark/parsers/earley_forest.py +801 -0
  579. ccxt/static_dependencies/lark/parsers/grammar_analysis.py +203 -0
  580. ccxt/static_dependencies/lark/parsers/lalr_analysis.py +332 -0
  581. ccxt/static_dependencies/lark/parsers/lalr_interactive_parser.py +158 -0
  582. ccxt/static_dependencies/lark/parsers/lalr_parser.py +122 -0
  583. ccxt/static_dependencies/lark/parsers/lalr_parser_state.py +110 -0
  584. ccxt/static_dependencies/lark/parsers/xearley.py +165 -0
  585. ccxt/static_dependencies/lark/reconstruct.py +107 -0
  586. ccxt/static_dependencies/lark/tools/__init__.py +70 -0
  587. ccxt/static_dependencies/lark/tools/nearley.py +202 -0
  588. ccxt/static_dependencies/lark/tools/serialize.py +32 -0
  589. ccxt/static_dependencies/lark/tools/standalone.py +196 -0
  590. ccxt/static_dependencies/lark/tree.py +267 -0
  591. ccxt/static_dependencies/lark/tree_matcher.py +186 -0
  592. ccxt/static_dependencies/lark/tree_templates.py +180 -0
  593. ccxt/static_dependencies/lark/utils.py +343 -0
  594. ccxt/static_dependencies/lark/visitors.py +596 -0
  595. ccxt/static_dependencies/marshmallow/__init__.py +81 -0
  596. ccxt/static_dependencies/marshmallow/base.py +65 -0
  597. ccxt/static_dependencies/marshmallow/class_registry.py +94 -0
  598. ccxt/static_dependencies/marshmallow/decorators.py +231 -0
  599. ccxt/static_dependencies/marshmallow/error_store.py +60 -0
  600. ccxt/static_dependencies/marshmallow/exceptions.py +71 -0
  601. ccxt/static_dependencies/marshmallow/fields.py +2114 -0
  602. ccxt/static_dependencies/marshmallow/orderedset.py +89 -0
  603. ccxt/static_dependencies/marshmallow/schema.py +1228 -0
  604. ccxt/static_dependencies/marshmallow/types.py +12 -0
  605. ccxt/static_dependencies/marshmallow/utils.py +378 -0
  606. ccxt/static_dependencies/marshmallow/validate.py +678 -0
  607. ccxt/static_dependencies/marshmallow/warnings.py +2 -0
  608. ccxt/static_dependencies/marshmallow_dataclass/__init__.py +1047 -0
  609. ccxt/static_dependencies/marshmallow_dataclass/collection_field.py +51 -0
  610. ccxt/static_dependencies/marshmallow_dataclass/lazy_class_attribute.py +45 -0
  611. ccxt/static_dependencies/marshmallow_dataclass/mypy.py +71 -0
  612. ccxt/static_dependencies/marshmallow_dataclass/typing.py +14 -0
  613. ccxt/static_dependencies/marshmallow_dataclass/union_field.py +82 -0
  614. ccxt/static_dependencies/marshmallow_oneofschema/__init__.py +1 -0
  615. ccxt/static_dependencies/marshmallow_oneofschema/one_of_schema.py +193 -0
  616. ccxt/static_dependencies/msgpack/__init__.py +55 -0
  617. ccxt/static_dependencies/msgpack/exceptions.py +48 -0
  618. ccxt/static_dependencies/msgpack/ext.py +168 -0
  619. ccxt/static_dependencies/msgpack/fallback.py +951 -0
  620. ccxt/static_dependencies/parsimonious/__init__.py +10 -0
  621. ccxt/static_dependencies/parsimonious/exceptions.py +105 -0
  622. ccxt/static_dependencies/parsimonious/expressions.py +479 -0
  623. ccxt/static_dependencies/parsimonious/grammar.py +487 -0
  624. ccxt/static_dependencies/parsimonious/nodes.py +325 -0
  625. ccxt/static_dependencies/parsimonious/utils.py +40 -0
  626. ccxt/static_dependencies/starknet/__init__.py +0 -0
  627. ccxt/static_dependencies/starknet/cairo/__init__.py +0 -0
  628. ccxt/static_dependencies/starknet/cairo/data_types.py +123 -0
  629. ccxt/static_dependencies/starknet/cairo/deprecated_parse/__init__.py +0 -0
  630. ccxt/static_dependencies/starknet/cairo/deprecated_parse/cairo_types.py +77 -0
  631. ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser.py +46 -0
  632. ccxt/static_dependencies/starknet/cairo/deprecated_parse/parser_transformer.py +138 -0
  633. ccxt/static_dependencies/starknet/cairo/felt.py +64 -0
  634. ccxt/static_dependencies/starknet/cairo/type_parser.py +121 -0
  635. ccxt/static_dependencies/starknet/cairo/v1/__init__.py +0 -0
  636. ccxt/static_dependencies/starknet/cairo/v1/type_parser.py +59 -0
  637. ccxt/static_dependencies/starknet/cairo/v2/__init__.py +0 -0
  638. ccxt/static_dependencies/starknet/cairo/v2/type_parser.py +77 -0
  639. ccxt/static_dependencies/starknet/ccxt_utils.py +7 -0
  640. ccxt/static_dependencies/starknet/common.py +15 -0
  641. ccxt/static_dependencies/starknet/constants.py +39 -0
  642. ccxt/static_dependencies/starknet/hash/__init__.py +0 -0
  643. ccxt/static_dependencies/starknet/hash/address.py +79 -0
  644. ccxt/static_dependencies/starknet/hash/compiled_class_hash_objects.py +111 -0
  645. ccxt/static_dependencies/starknet/hash/selector.py +16 -0
  646. ccxt/static_dependencies/starknet/hash/storage.py +12 -0
  647. ccxt/static_dependencies/starknet/hash/utils.py +78 -0
  648. ccxt/static_dependencies/starknet/models/__init__.py +0 -0
  649. ccxt/static_dependencies/starknet/models/typed_data.py +45 -0
  650. ccxt/static_dependencies/starknet/serialization/__init__.py +24 -0
  651. ccxt/static_dependencies/starknet/serialization/_calldata_reader.py +40 -0
  652. ccxt/static_dependencies/starknet/serialization/_context.py +142 -0
  653. ccxt/static_dependencies/starknet/serialization/data_serializers/__init__.py +10 -0
  654. ccxt/static_dependencies/starknet/serialization/data_serializers/_common.py +82 -0
  655. ccxt/static_dependencies/starknet/serialization/data_serializers/array_serializer.py +43 -0
  656. ccxt/static_dependencies/starknet/serialization/data_serializers/bool_serializer.py +37 -0
  657. ccxt/static_dependencies/starknet/serialization/data_serializers/byte_array_serializer.py +66 -0
  658. ccxt/static_dependencies/starknet/serialization/data_serializers/cairo_data_serializer.py +71 -0
  659. ccxt/static_dependencies/starknet/serialization/data_serializers/enum_serializer.py +71 -0
  660. ccxt/static_dependencies/starknet/serialization/data_serializers/felt_serializer.py +50 -0
  661. ccxt/static_dependencies/starknet/serialization/data_serializers/named_tuple_serializer.py +58 -0
  662. ccxt/static_dependencies/starknet/serialization/data_serializers/option_serializer.py +43 -0
  663. ccxt/static_dependencies/starknet/serialization/data_serializers/output_serializer.py +40 -0
  664. ccxt/static_dependencies/starknet/serialization/data_serializers/payload_serializer.py +72 -0
  665. ccxt/static_dependencies/starknet/serialization/data_serializers/struct_serializer.py +36 -0
  666. ccxt/static_dependencies/starknet/serialization/data_serializers/tuple_serializer.py +36 -0
  667. ccxt/static_dependencies/starknet/serialization/data_serializers/uint256_serializer.py +76 -0
  668. ccxt/static_dependencies/starknet/serialization/data_serializers/uint_serializer.py +100 -0
  669. ccxt/static_dependencies/starknet/serialization/data_serializers/unit_serializer.py +32 -0
  670. ccxt/static_dependencies/starknet/serialization/errors.py +10 -0
  671. ccxt/static_dependencies/starknet/serialization/factory.py +229 -0
  672. ccxt/static_dependencies/starknet/serialization/function_serialization_adapter.py +110 -0
  673. ccxt/static_dependencies/starknet/serialization/tuple_dataclass.py +59 -0
  674. ccxt/static_dependencies/starknet/utils/__init__.py +0 -0
  675. ccxt/static_dependencies/starknet/utils/constructor_args_translator.py +86 -0
  676. ccxt/static_dependencies/starknet/utils/iterable.py +13 -0
  677. ccxt/static_dependencies/starknet/utils/schema.py +13 -0
  678. ccxt/static_dependencies/starknet/utils/typed_data.py +182 -0
  679. ccxt/static_dependencies/starkware/__init__.py +0 -0
  680. ccxt/static_dependencies/starkware/crypto/__init__.py +0 -0
  681. ccxt/static_dependencies/starkware/crypto/fast_pedersen_hash.py +50 -0
  682. ccxt/static_dependencies/starkware/crypto/math_utils.py +78 -0
  683. ccxt/static_dependencies/starkware/crypto/signature.py +2344 -0
  684. ccxt/static_dependencies/starkware/crypto/utils.py +63 -0
  685. ccxt/static_dependencies/sympy/__init__.py +0 -0
  686. ccxt/static_dependencies/sympy/core/__init__.py +0 -0
  687. ccxt/static_dependencies/sympy/core/intfunc.py +35 -0
  688. ccxt/static_dependencies/sympy/external/__init__.py +0 -0
  689. ccxt/static_dependencies/sympy/external/gmpy.py +345 -0
  690. ccxt/static_dependencies/sympy/external/importtools.py +187 -0
  691. ccxt/static_dependencies/sympy/external/ntheory.py +637 -0
  692. ccxt/static_dependencies/sympy/external/pythonmpq.py +341 -0
  693. ccxt/static_dependencies/toolz/__init__.py +26 -0
  694. ccxt/static_dependencies/toolz/_signatures.py +784 -0
  695. ccxt/static_dependencies/toolz/_version.py +520 -0
  696. ccxt/static_dependencies/toolz/compatibility.py +30 -0
  697. ccxt/static_dependencies/toolz/curried/__init__.py +101 -0
  698. ccxt/static_dependencies/toolz/curried/exceptions.py +22 -0
  699. ccxt/static_dependencies/toolz/curried/operator.py +22 -0
  700. ccxt/static_dependencies/toolz/dicttoolz.py +339 -0
  701. ccxt/static_dependencies/toolz/functoolz.py +1049 -0
  702. ccxt/static_dependencies/toolz/itertoolz.py +1057 -0
  703. ccxt/static_dependencies/toolz/recipes.py +46 -0
  704. ccxt/static_dependencies/toolz/utils.py +9 -0
  705. ccxt/static_dependencies/typing_inspect/__init__.py +0 -0
  706. ccxt/static_dependencies/typing_inspect/typing_inspect.py +851 -0
  707. ccxt/tabdeal.py +364 -0
  708. ccxt/test/__init__.py +3 -0
  709. ccxt/test/base/__init__.py +29 -0
  710. ccxt/test/base/test_account.py +26 -0
  711. ccxt/test/base/test_balance.py +56 -0
  712. ccxt/test/base/test_borrow_interest.py +35 -0
  713. ccxt/test/base/test_borrow_rate.py +32 -0
  714. ccxt/test/base/test_calculate_fee.py +51 -0
  715. ccxt/test/base/test_crypto.py +127 -0
  716. ccxt/test/base/test_currency.py +76 -0
  717. ccxt/test/base/test_datetime.py +109 -0
  718. ccxt/test/base/test_decimal_to_precision.py +392 -0
  719. ccxt/test/base/test_deep_extend.py +68 -0
  720. ccxt/test/base/test_deposit_withdrawal.py +50 -0
  721. ccxt/test/base/test_exchange_datetime_functions.py +76 -0
  722. ccxt/test/base/test_funding_rate_history.py +29 -0
  723. ccxt/test/base/test_last_price.py +31 -0
  724. ccxt/test/base/test_ledger_entry.py +45 -0
  725. ccxt/test/base/test_ledger_item.py +48 -0
  726. ccxt/test/base/test_leverage_tier.py +33 -0
  727. ccxt/test/base/test_liquidation.py +50 -0
  728. ccxt/test/base/test_margin_mode.py +24 -0
  729. ccxt/test/base/test_margin_modification.py +35 -0
  730. ccxt/test/base/test_market.py +193 -0
  731. ccxt/test/base/test_number.py +411 -0
  732. ccxt/test/base/test_ohlcv.py +33 -0
  733. ccxt/test/base/test_open_interest.py +32 -0
  734. ccxt/test/base/test_order.py +64 -0
  735. ccxt/test/base/test_order_book.py +69 -0
  736. ccxt/test/base/test_position.py +60 -0
  737. ccxt/test/base/test_shared_methods.py +353 -0
  738. ccxt/test/base/test_status.py +24 -0
  739. ccxt/test/base/test_throttle.py +126 -0
  740. ccxt/test/base/test_ticker.py +92 -0
  741. ccxt/test/base/test_trade.py +47 -0
  742. ccxt/test/base/test_trading_fee.py +26 -0
  743. ccxt/test/base/test_transaction.py +39 -0
  744. ccxt/test/test_async.py +1649 -0
  745. ccxt/test/test_sync.py +1648 -0
  746. ccxt/test/tests_async.py +1558 -0
  747. ccxt/test/tests_helpers.py +287 -0
  748. ccxt/test/tests_init.py +39 -0
  749. ccxt/test/tests_sync.py +1555 -0
  750. ccxt/tetherland.py +349 -0
  751. ccxt/timex.py +1593 -0
  752. ccxt/tokocrypto.py +2405 -0
  753. ccxt/tradeogre.py +608 -0
  754. ccxt/twox.py +326 -0
  755. ccxt/ubitex.py +409 -0
  756. ccxt/upbit.py +1833 -0
  757. ccxt/vertex.py +2922 -0
  758. ccxt/wallex.py +445 -0
  759. ccxt/wavesexchange.py +2472 -0
  760. ccxt/wazirx.py +1224 -0
  761. ccxt/whitebit.py +2469 -0
  762. ccxt/woo.py +3114 -0
  763. ccxt/woofipro.py +2533 -0
  764. ccxt/xt.py +4453 -0
  765. ccxt/yobit.py +1283 -0
  766. ccxt/zaif.py +725 -0
  767. ccxt/zonda.py +1828 -0
  768. ccxt_ir-4.3.46.0.1.dist-info/LICENSE.txt +21 -0
  769. ccxt_ir-4.3.46.0.1.dist-info/METADATA +655 -0
  770. ccxt_ir-4.3.46.0.1.dist-info/RECORD +772 -0
  771. ccxt_ir-4.3.46.0.1.dist-info/WHEEL +6 -0
  772. ccxt_ir-4.3.46.0.1.dist-info/top_level.txt +1 -0
ccxt/pro/bitmex.py ADDED
@@ -0,0 +1,1656 @@
1
+ # -*- coding: utf-8 -*-
2
+
3
+ # PLEASE DO NOT EDIT THIS FILE, IT IS GENERATED AND WILL BE OVERWRITTEN:
4
+ # https://github.com/ccxt/ccxt/blob/master/CONTRIBUTING.md#how-to-contribute-code
5
+
6
+ import ccxt.async_support
7
+ from ccxt.async_support.base.ws.cache import ArrayCache, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide, ArrayCacheByTimestamp
8
+ import hashlib
9
+ from ccxt.base.types import Balances, Int, Liquidation, Order, OrderBook, Position, Str, Strings, Ticker, Tickers, Trade
10
+ from ccxt.async_support.base.ws.client import Client
11
+ from typing import List
12
+ from ccxt.base.errors import ExchangeError
13
+ from ccxt.base.errors import AuthenticationError
14
+ from ccxt.base.errors import RateLimitExceeded
15
+
16
+
17
+ class bitmex(ccxt.async_support.bitmex):
18
+
19
+ def describe(self):
20
+ return self.deep_extend(super(bitmex, self).describe(), {
21
+ 'has': {
22
+ 'ws': True,
23
+ 'watchBalance': True,
24
+ 'watchLiquidations': True,
25
+ 'watchLiquidationsForSymbols': True,
26
+ 'watchMyLiquidations': None,
27
+ 'watchMyLiquidationsForSymbols': None,
28
+ 'watchMyTrades': True,
29
+ 'watchOHLCV': True,
30
+ 'watchOrderBook': True,
31
+ 'watchOrderBookForSymbols': True,
32
+ 'watchOrders': True,
33
+ 'watchPostions': True,
34
+ 'watchTicker': True,
35
+ 'watchTickers': True,
36
+ 'watchTrades': True,
37
+ 'watchTradesForSymbols': True,
38
+ },
39
+ 'urls': {
40
+ 'test': {
41
+ 'ws': 'wss://ws.testnet.bitmex.com/realtime',
42
+ },
43
+ 'api': {
44
+ 'ws': 'wss://ws.bitmex.com/realtime',
45
+ },
46
+ },
47
+ # 'versions': {
48
+ # 'ws': '0.2.0',
49
+ # },
50
+ 'options': {
51
+ 'watchOrderBookLevel': 'orderBookL2', # 'orderBookL2' = L2 full order book, 'orderBookL2_25' = L2 top 25, 'orderBook10' L3 top 10
52
+ 'tradesLimit': 1000,
53
+ 'OHLCVLimit': 1000,
54
+ },
55
+ 'exceptions': {
56
+ 'ws': {
57
+ 'exact': {
58
+ },
59
+ 'broad': {
60
+ 'Rate limit exceeded': RateLimitExceeded,
61
+ },
62
+ },
63
+ },
64
+ })
65
+
66
+ async def watch_ticker(self, symbol: str, params={}) -> Ticker:
67
+ """
68
+ watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
69
+ :param str symbol: unified symbol of the market to fetch the ticker for
70
+ :param dict [params]: extra parameters specific to the exchange API endpoint
71
+ :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
72
+ """
73
+ await self.load_markets()
74
+ symbol = self.symbol(symbol)
75
+ tickers = await self.watch_tickers([symbol], params)
76
+ return tickers[symbol]
77
+
78
+ async def watch_tickers(self, symbols: Strings = None, params={}) -> Tickers:
79
+ """
80
+ watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
81
+ :param str[] symbols: unified symbol of the market to fetch the ticker for
82
+ :param dict [params]: extra parameters specific to the exchange API endpoint
83
+ :returns dict: a `ticker structure <https://docs.ccxt.com/#/?id=ticker-structure>`
84
+ """
85
+ await self.load_markets()
86
+ symbols = self.market_symbols(symbols, None, True)
87
+ name = 'instrument'
88
+ url = self.urls['api']['ws']
89
+ messageHashes = []
90
+ rawSubscriptions = []
91
+ if symbols is not None:
92
+ for i in range(0, len(symbols)):
93
+ symbol = symbols[i]
94
+ market = self.market(symbol)
95
+ subscription = name + ':' + market['id']
96
+ rawSubscriptions.append(subscription)
97
+ messageHash = 'ticker:' + symbol
98
+ messageHashes.append(messageHash)
99
+ else:
100
+ rawSubscriptions.append(name)
101
+ messageHashes.append('alltickers')
102
+ request: dict = {
103
+ 'op': 'subscribe',
104
+ 'args': rawSubscriptions,
105
+ }
106
+ ticker = await self.watch_multiple(url, messageHashes, self.extend(request, params), rawSubscriptions)
107
+ if self.newUpdates:
108
+ result: dict = {}
109
+ result[ticker['symbol']] = ticker
110
+ return result
111
+ return self.filter_by_array(self.tickers, 'symbol', symbols)
112
+
113
+ def handle_ticker(self, client: Client, message):
114
+ #
115
+ # {
116
+ # "table": "instrument",
117
+ # "action": "partial",
118
+ # "keys": ["symbol"],
119
+ # "types": {
120
+ # "symbol": "symbol",
121
+ # "rootSymbol": "symbol",
122
+ # "state": "symbol",
123
+ # "typ": "symbol",
124
+ # "listing": "timestamp",
125
+ # "front": "timestamp",
126
+ # "expiry": "timestamp",
127
+ # "settle": "timestamp",
128
+ # "relistInterval": "timespan",
129
+ # "inverseLeg": "symbol",
130
+ # "sellLeg": "symbol",
131
+ # "buyLeg": "symbol",
132
+ # "optionStrikePcnt": "float",
133
+ # "optionStrikeRound": "float",
134
+ # "optionStrikePrice": "float",
135
+ # "optionMultiplier": "float",
136
+ # "positionCurrency": "symbol",
137
+ # "underlying": "symbol",
138
+ # "quoteCurrency": "symbol",
139
+ # "underlyingSymbol": "symbol",
140
+ # "reference": "symbol",
141
+ # "referenceSymbol": "symbol",
142
+ # "calcInterval": "timespan",
143
+ # "publishInterval": "timespan",
144
+ # "publishTime": "timespan",
145
+ # "maxOrderQty": "long",
146
+ # "maxPrice": "float",
147
+ # "lotSize": "long",
148
+ # "tickSize": "float",
149
+ # "multiplier": "long",
150
+ # "settlCurrency": "symbol",
151
+ # "underlyingToPositionMultiplier": "long",
152
+ # "underlyingToSettleMultiplier": "long",
153
+ # "quoteToSettleMultiplier": "long",
154
+ # "isQuanto": "boolean",
155
+ # "isInverse": "boolean",
156
+ # "initMargin": "float",
157
+ # "maintMargin": "float",
158
+ # "riskLimit": "long",
159
+ # "riskStep": "long",
160
+ # "limit": "float",
161
+ # "capped": "boolean",
162
+ # "taxed": "boolean",
163
+ # "deleverage": "boolean",
164
+ # "makerFee": "float",
165
+ # "takerFee": "float",
166
+ # "settlementFee": "float",
167
+ # "insuranceFee": "float",
168
+ # "fundingBaseSymbol": "symbol",
169
+ # "fundingQuoteSymbol": "symbol",
170
+ # "fundingPremiumSymbol": "symbol",
171
+ # "fundingTimestamp": "timestamp",
172
+ # "fundingInterval": "timespan",
173
+ # "fundingRate": "float",
174
+ # "indicativeFundingRate": "float",
175
+ # "rebalanceTimestamp": "timestamp",
176
+ # "rebalanceInterval": "timespan",
177
+ # "openingTimestamp": "timestamp",
178
+ # "closingTimestamp": "timestamp",
179
+ # "sessionInterval": "timespan",
180
+ # "prevClosePrice": "float",
181
+ # "limitDownPrice": "float",
182
+ # "limitUpPrice": "float",
183
+ # "bankruptLimitDownPrice": "float",
184
+ # "bankruptLimitUpPrice": "float",
185
+ # "prevTotalVolume": "long",
186
+ # "totalVolume": "long",
187
+ # "volume": "long",
188
+ # "volume24h": "long",
189
+ # "prevTotalTurnover": "long",
190
+ # "totalTurnover": "long",
191
+ # "turnover": "long",
192
+ # "turnover24h": "long",
193
+ # "homeNotional24h": "float",
194
+ # "foreignNotional24h": "float",
195
+ # "prevPrice24h": "float",
196
+ # "vwap": "float",
197
+ # "highPrice": "float",
198
+ # "lowPrice": "float",
199
+ # "lastPrice": "float",
200
+ # "lastPriceProtected": "float",
201
+ # "lastTickDirection": "symbol",
202
+ # "lastChangePcnt": "float",
203
+ # "bidPrice": "float",
204
+ # "midPrice": "float",
205
+ # "askPrice": "float",
206
+ # "impactBidPrice": "float",
207
+ # "impactMidPrice": "float",
208
+ # "impactAskPrice": "float",
209
+ # "hasLiquidity": "boolean",
210
+ # "openInterest": "long",
211
+ # "openValue": "long",
212
+ # "fairMethod": "symbol",
213
+ # "fairBasisRate": "float",
214
+ # "fairBasis": "float",
215
+ # "fairPrice": "float",
216
+ # "markMethod": "symbol",
217
+ # "markPrice": "float",
218
+ # "indicativeTaxRate": "float",
219
+ # "indicativeSettlePrice": "float",
220
+ # "optionUnderlyingPrice": "float",
221
+ # "settledPrice": "float",
222
+ # "timestamp": "timestamp"
223
+ # },
224
+ # "foreignKeys": {
225
+ # "inverseLeg": "instrument",
226
+ # "sellLeg": "instrument",
227
+ # "buyLeg": "instrument"
228
+ # },
229
+ # "attributes": {symbol: "unique"},
230
+ # "filter": {symbol: "XBTUSD"},
231
+ # "data": [
232
+ # {
233
+ # "symbol": "XBTUSD",
234
+ # "rootSymbol": "XBT",
235
+ # "state": "Open",
236
+ # "typ": "FFWCSX",
237
+ # "listing": "2016-05-13T12:00:00.000Z",
238
+ # "front": "2016-05-13T12:00:00.000Z",
239
+ # "expiry": null,
240
+ # "settle": null,
241
+ # "relistInterval": null,
242
+ # "inverseLeg": '',
243
+ # "sellLeg": '',
244
+ # "buyLeg": '',
245
+ # "optionStrikePcnt": null,
246
+ # "optionStrikeRound": null,
247
+ # "optionStrikePrice": null,
248
+ # "optionMultiplier": null,
249
+ # "positionCurrency": "USD",
250
+ # "underlying": "XBT",
251
+ # "quoteCurrency": "USD",
252
+ # "underlyingSymbol": "XBT=",
253
+ # "reference": "BMEX",
254
+ # "referenceSymbol": ".BXBT",
255
+ # "calcInterval": null,
256
+ # "publishInterval": null,
257
+ # "publishTime": null,
258
+ # "maxOrderQty": 10000000,
259
+ # "maxPrice": 1000000,
260
+ # "lotSize": 1,
261
+ # "tickSize": 0.5,
262
+ # "multiplier": -100000000,
263
+ # "settlCurrency": "XBt",
264
+ # "underlyingToPositionMultiplier": null,
265
+ # "underlyingToSettleMultiplier": -100000000,
266
+ # "quoteToSettleMultiplier": null,
267
+ # "isQuanto": False,
268
+ # "isInverse": True,
269
+ # "initMargin": 0.01,
270
+ # "maintMargin": 0.005,
271
+ # "riskLimit": 20000000000,
272
+ # "riskStep": 10000000000,
273
+ # "limit": null,
274
+ # "capped": False,
275
+ # "taxed": True,
276
+ # "deleverage": True,
277
+ # "makerFee": -0.00025,
278
+ # "takerFee": 0.00075,
279
+ # "settlementFee": 0,
280
+ # "insuranceFee": 0,
281
+ # "fundingBaseSymbol": ".XBTBON8H",
282
+ # "fundingQuoteSymbol": ".USDBON8H",
283
+ # "fundingPremiumSymbol": ".XBTUSDPI8H",
284
+ # "fundingTimestamp": "2020-01-29T12:00:00.000Z",
285
+ # "fundingInterval": "2000-01-01T08:00:00.000Z",
286
+ # "fundingRate": 0.000597,
287
+ # "indicativeFundingRate": 0.000652,
288
+ # "rebalanceTimestamp": null,
289
+ # "rebalanceInterval": null,
290
+ # "openingTimestamp": "2020-01-29T11:00:00.000Z",
291
+ # "closingTimestamp": "2020-01-29T12:00:00.000Z",
292
+ # "sessionInterval": "2000-01-01T01:00:00.000Z",
293
+ # "prevClosePrice": 9063.96,
294
+ # "limitDownPrice": null,
295
+ # "limitUpPrice": null,
296
+ # "bankruptLimitDownPrice": null,
297
+ # "bankruptLimitUpPrice": null,
298
+ # "prevTotalVolume": 1989881049026,
299
+ # "totalVolume": 1990196740950,
300
+ # "volume": 315691924,
301
+ # "volume24h": 4491824765,
302
+ # "prevTotalTurnover": 27865497128425564,
303
+ # "totalTurnover": 27868891594857150,
304
+ # "turnover": 3394466431587,
305
+ # "turnover24h": 48863390064843,
306
+ # "homeNotional24h": 488633.9006484273,
307
+ # "foreignNotional24h": 4491824765,
308
+ # "prevPrice24h": 9091,
309
+ # "vwap": 9192.8663,
310
+ # "highPrice": 9440,
311
+ # "lowPrice": 8886,
312
+ # "lastPrice": 9287,
313
+ # "lastPriceProtected": 9287,
314
+ # "lastTickDirection": "PlusTick",
315
+ # "lastChangePcnt": 0.0216,
316
+ # "bidPrice": 9286,
317
+ # "midPrice": 9286.25,
318
+ # "askPrice": 9286.5,
319
+ # "impactBidPrice": 9285.9133,
320
+ # "impactMidPrice": 9286.75,
321
+ # "impactAskPrice": 9287.6382,
322
+ # "hasLiquidity": True,
323
+ # "openInterest": 967826984,
324
+ # "openValue": 10432207060536,
325
+ # "fairMethod": "FundingRate",
326
+ # "fairBasisRate": 0.6537149999999999,
327
+ # "fairBasis": 0.33,
328
+ # "fairPrice": 9277.2,
329
+ # "markMethod": "FairPrice",
330
+ # "markPrice": 9277.2,
331
+ # "indicativeTaxRate": 0,
332
+ # "indicativeSettlePrice": 9276.87,
333
+ # "optionUnderlyingPrice": null,
334
+ # "settledPrice": null,
335
+ # "timestamp": "2020-01-29T11:31:37.114Z"
336
+ # }
337
+ # ]
338
+ # }
339
+ #
340
+ data = self.safe_list(message, 'data', [])
341
+ tickers: dict = {}
342
+ for i in range(0, len(data)):
343
+ update = data[i]
344
+ marketId = self.safe_string(update, 'symbol')
345
+ symbol = self.safe_symbol(marketId)
346
+ if not (symbol in self.tickers):
347
+ self.tickers[symbol] = self.parse_ticker({})
348
+ updatedTicker = self.parse_ticker(update)
349
+ fullParsedTicker = self.deep_extend(self.tickers[symbol], updatedTicker)
350
+ tickers[symbol] = fullParsedTicker
351
+ self.tickers[symbol] = fullParsedTicker
352
+ messageHash = 'ticker:' + symbol
353
+ client.resolve(fullParsedTicker, messageHash)
354
+ client.resolve(fullParsedTicker, 'alltickers')
355
+ return message
356
+
357
+ async def watch_liquidations(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Liquidation]:
358
+ """
359
+ watch the public liquidations of a trading pair
360
+ :see: https://www.bitmex.com/app/wsAPI#Liquidation
361
+ :param str symbol: unified CCXT market symbol
362
+ :param int [since]: the earliest time in ms to fetch liquidations for
363
+ :param int [limit]: the maximum number of liquidation structures to retrieve
364
+ :param dict [params]: exchange specific parameters for the bitmex api endpoint
365
+ :returns dict: an array of `liquidation structures <https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure>`
366
+ """
367
+ return self.watch_liquidations_for_symbols([symbol], since, limit, params)
368
+
369
+ async def watch_liquidations_for_symbols(self, symbols: List[str] = None, since: Int = None, limit: Int = None, params={}) -> List[Liquidation]:
370
+ """
371
+ watch the public liquidations of a trading pair
372
+ :see: https://www.bitmex.com/app/wsAPI#Liquidation
373
+ :param str symbol: unified CCXT market symbol
374
+ :param int [since]: the earliest time in ms to fetch liquidations for
375
+ :param int [limit]: the maximum number of liquidation structures to retrieve
376
+ :param dict [params]: exchange specific parameters for the bitmex api endpoint
377
+ :returns dict: an array of `liquidation structures <https://github.com/ccxt/ccxt/wiki/Manual#liquidation-structure>`
378
+ """
379
+ await self.load_markets()
380
+ symbols = self.market_symbols(symbols, None, True, True)
381
+ messageHashes = []
382
+ subscriptionHashes = []
383
+ if self.is_empty(symbols):
384
+ subscriptionHashes.append('liquidation')
385
+ messageHashes.append('liquidations')
386
+ else:
387
+ for i in range(0, len(symbols)):
388
+ symbol = symbols[i]
389
+ market = self.market(symbol)
390
+ subscriptionHashes.append('liquidation:' + market['id'])
391
+ messageHashes.append('liquidations::' + symbol)
392
+ url = self.urls['api']['ws']
393
+ request = {
394
+ 'op': 'subscribe',
395
+ 'args': subscriptionHashes,
396
+ }
397
+ newLiquidations = await self.watch_multiple(url, messageHashes, self.deep_extend(request, params), subscriptionHashes)
398
+ if self.newUpdates:
399
+ return newLiquidations
400
+ return self.filter_by_symbols_since_limit(self.liquidations, symbols, since, limit, True)
401
+
402
+ def handle_liquidation(self, client: Client, message):
403
+ #
404
+ # {
405
+ # "table":"liquidation",
406
+ # "action":"partial",
407
+ # "keys":[
408
+ # "orderID"
409
+ # ],
410
+ # "types":{
411
+ # "orderID":"guid",
412
+ # "symbol":"symbol",
413
+ # "side":"symbol",
414
+ # "price":"float",
415
+ # "leavesQty":"long"
416
+ # },
417
+ # "filter":{},
418
+ # "data":[
419
+ # {
420
+ # "orderID":"e0a568ee-7830-4428-92c3-73e82b9576ce",
421
+ # "symbol":"XPLAUSDT",
422
+ # "side":"Sell",
423
+ # "price":0.206,
424
+ # "leavesQty":340
425
+ # }
426
+ # ]
427
+ # }
428
+ #
429
+ rawLiquidations = self.safe_value(message, 'data', [])
430
+ newLiquidations = []
431
+ for i in range(0, len(rawLiquidations)):
432
+ rawLiquidation = rawLiquidations[i]
433
+ liquidation = self.parse_liquidation(rawLiquidation)
434
+ symbol = liquidation['symbol']
435
+ liquidations = self.safe_value(self.liquidations, symbol)
436
+ if liquidations is None:
437
+ limit = self.safe_integer(self.options, 'liquidationsLimit', 1000)
438
+ liquidations = ArrayCache(limit)
439
+ liquidations.append(liquidation)
440
+ self.liquidations[symbol] = liquidations
441
+ newLiquidations.append(liquidation)
442
+ client.resolve(newLiquidations, 'liquidations')
443
+ liquidationsBySymbol = self.index_by(newLiquidations, 'symbol')
444
+ symbols = list(liquidationsBySymbol.keys())
445
+ for i in range(0, len(symbols)):
446
+ symbol = symbols[i]
447
+ client.resolve(liquidationsBySymbol[symbol], 'liquidations::' + symbol)
448
+
449
+ async def watch_balance(self, params={}) -> Balances:
450
+ """
451
+ watch balance and get the amount of funds available for trading or funds locked in orders
452
+ :param dict [params]: extra parameters specific to the exchange API endpoint
453
+ :returns dict: a `balance structure <https://docs.ccxt.com/#/?id=balance-structure>`
454
+ """
455
+ await self.load_markets()
456
+ await self.authenticate()
457
+ messageHash = 'margin'
458
+ url = self.urls['api']['ws']
459
+ request: dict = {
460
+ 'op': 'subscribe',
461
+ 'args': [
462
+ messageHash,
463
+ ],
464
+ }
465
+ return await self.watch(url, messageHash, self.extend(request, params), messageHash)
466
+
467
+ def handle_balance(self, client: Client, message):
468
+ #
469
+ # {
470
+ # "table": "margin",
471
+ # "action": "partial",
472
+ # "keys": ["account"],
473
+ # "types": {
474
+ # "account": "long",
475
+ # "currency": "symbol",
476
+ # "riskLimit": "long",
477
+ # "prevState": "symbol",
478
+ # "state": "symbol",
479
+ # "action": "symbol",
480
+ # "amount": "long",
481
+ # "pendingCredit": "long",
482
+ # "pendingDebit": "long",
483
+ # "confirmedDebit": "long",
484
+ # "prevRealisedPnl": "long",
485
+ # "prevUnrealisedPnl": "long",
486
+ # "grossComm": "long",
487
+ # "grossOpenCost": "long",
488
+ # "grossOpenPremium": "long",
489
+ # "grossExecCost": "long",
490
+ # "grossMarkValue": "long",
491
+ # "riskValue": "long",
492
+ # "taxableMargin": "long",
493
+ # "initMargin": "long",
494
+ # "maintMargin": "long",
495
+ # "sessionMargin": "long",
496
+ # "targetExcessMargin": "long",
497
+ # "varMargin": "long",
498
+ # "realisedPnl": "long",
499
+ # "unrealisedPnl": "long",
500
+ # "indicativeTax": "long",
501
+ # "unrealisedProfit": "long",
502
+ # "syntheticMargin": "long",
503
+ # "walletBalance": "long",
504
+ # "marginBalance": "long",
505
+ # "marginBalancePcnt": "float",
506
+ # "marginLeverage": "float",
507
+ # "marginUsedPcnt": "float",
508
+ # "excessMargin": "long",
509
+ # "excessMarginPcnt": "float",
510
+ # "availableMargin": "long",
511
+ # "withdrawableMargin": "long",
512
+ # "timestamp": "timestamp",
513
+ # "grossLastValue": "long",
514
+ # "commission": "float"
515
+ # },
516
+ # "foreignKeys": {},
517
+ # "attributes": {account: "sorted"},
518
+ # "filter": {account: 1455728},
519
+ # "data": [
520
+ # {
521
+ # "account": 1455728,
522
+ # "currency": "XBt",
523
+ # "riskLimit": 1000000000000,
524
+ # "prevState": '',
525
+ # "state": '',
526
+ # "action": '',
527
+ # "amount": 263542,
528
+ # "pendingCredit": 0,
529
+ # "pendingDebit": 0,
530
+ # "confirmedDebit": 0,
531
+ # "prevRealisedPnl": 0,
532
+ # "prevUnrealisedPnl": 0,
533
+ # "grossComm": 0,
534
+ # "grossOpenCost": 0,
535
+ # "grossOpenPremium": 0,
536
+ # "grossExecCost": 0,
537
+ # "grossMarkValue": 0,
538
+ # "riskValue": 0,
539
+ # "taxableMargin": 0,
540
+ # "initMargin": 0,
541
+ # "maintMargin": 0,
542
+ # "sessionMargin": 0,
543
+ # "targetExcessMargin": 0,
544
+ # "varMargin": 0,
545
+ # "realisedPnl": 0,
546
+ # "unrealisedPnl": 0,
547
+ # "indicativeTax": 0,
548
+ # "unrealisedProfit": 0,
549
+ # "syntheticMargin": null,
550
+ # "walletBalance": 263542,
551
+ # "marginBalance": 263542,
552
+ # "marginBalancePcnt": 1,
553
+ # "marginLeverage": 0,
554
+ # "marginUsedPcnt": 0,
555
+ # "excessMargin": 263542,
556
+ # "excessMarginPcnt": 1,
557
+ # "availableMargin": 263542,
558
+ # "withdrawableMargin": 263542,
559
+ # "timestamp": "2020-08-03T12:01:01.246Z",
560
+ # "grossLastValue": 0,
561
+ # "commission": null
562
+ # }
563
+ # ]
564
+ # }
565
+ #
566
+ data = self.safe_value(message, 'data')
567
+ balance = self.parse_balance(data)
568
+ self.balance = self.extend(self.balance, balance)
569
+ messageHash = self.safe_string(message, 'table')
570
+ client.resolve(self.balance, messageHash)
571
+
572
+ def handle_trades(self, client: Client, message):
573
+ #
574
+ # initial snapshot
575
+ #
576
+ # {
577
+ # "table": "trade",
578
+ # "action": "partial",
579
+ # "keys": [],
580
+ # "types": {
581
+ # "timestamp": "timestamp",
582
+ # "symbol": "symbol",
583
+ # "side": "symbol",
584
+ # "size": "long",
585
+ # "price": "float",
586
+ # "tickDirection": "symbol",
587
+ # "trdMatchID": "guid",
588
+ # "grossValue": "long",
589
+ # "homeNotional": "float",
590
+ # "foreignNotional": "float"
591
+ # },
592
+ # "foreignKeys": {symbol: "instrument", side: "side"},
593
+ # "attributes": {timestamp: "sorted", symbol: "grouped"},
594
+ # "filter": {symbol: "XBTUSD"},
595
+ # "data": [
596
+ # {
597
+ # "timestamp": "2020-01-30T17:03:07.854Z",
598
+ # "symbol": "XBTUSD",
599
+ # "side": "Buy",
600
+ # "size": 15000,
601
+ # "price": 9378,
602
+ # "tickDirection": "ZeroPlusTick",
603
+ # "trdMatchID": "5b426e7f-83d1-2c80-295d-ee995b8ceb4a",
604
+ # "grossValue": 159945000,
605
+ # "homeNotional": 1.59945,
606
+ # "foreignNotional": 15000
607
+ # }
608
+ # ]
609
+ # }
610
+ #
611
+ # updates
612
+ #
613
+ # {
614
+ # "table": "trade",
615
+ # "action": "insert",
616
+ # "data": [
617
+ # {
618
+ # "timestamp": "2020-01-30T17:31:40.160Z",
619
+ # "symbol": "XBTUSD",
620
+ # "side": "Sell",
621
+ # "size": 37412,
622
+ # "price": 9521.5,
623
+ # "tickDirection": "ZeroMinusTick",
624
+ # "trdMatchID": "a4bfc6bc-6cf1-1a11-622e-270eef8ca5c7",
625
+ # "grossValue": 392938236,
626
+ # "homeNotional": 3.92938236,
627
+ # "foreignNotional": 37412
628
+ # }
629
+ # ]
630
+ # }
631
+ #
632
+ table = 'trade'
633
+ data = self.safe_value(message, 'data', [])
634
+ dataByMarketIds = self.group_by(data, 'symbol')
635
+ marketIds = list(dataByMarketIds.keys())
636
+ for i in range(0, len(marketIds)):
637
+ marketId = marketIds[i]
638
+ market = self.safe_market(marketId)
639
+ symbol = market['symbol']
640
+ messageHash = table + ':' + symbol
641
+ trades = self.parse_trades(dataByMarketIds[marketId], market)
642
+ stored = self.safe_value(self.trades, symbol)
643
+ if stored is None:
644
+ limit = self.safe_integer(self.options, 'tradesLimit', 1000)
645
+ stored = ArrayCache(limit)
646
+ self.trades[symbol] = stored
647
+ for j in range(0, len(trades)):
648
+ stored.append(trades[j])
649
+ client.resolve(stored, messageHash)
650
+
651
+ async def watch_trades(self, symbol: str, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
652
+ """
653
+ get the list of most recent trades for a particular symbol
654
+ :param str symbol: unified symbol of the market to fetch trades for
655
+ :param int [since]: timestamp in ms of the earliest trade to fetch
656
+ :param int [limit]: the maximum amount of trades to fetch
657
+ :param dict [params]: extra parameters specific to the exchange API endpoint
658
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
659
+ """
660
+ return await self.watch_trades_for_symbols([symbol], since, limit, params)
661
+
662
+ async def authenticate(self, params={}):
663
+ url = self.urls['api']['ws']
664
+ client = self.client(url)
665
+ messageHash = 'authenticated'
666
+ future = client.future(messageHash)
667
+ authenticated = self.safe_value(client.subscriptions, messageHash)
668
+ if authenticated is None:
669
+ self.check_required_credentials()
670
+ timestamp = self.milliseconds()
671
+ payload = 'GET' + '/realtime' + str(timestamp)
672
+ signature = self.hmac(self.encode(payload), self.encode(self.secret), hashlib.sha256)
673
+ request: dict = {
674
+ 'op': 'authKeyExpires',
675
+ 'args': [
676
+ self.apiKey,
677
+ timestamp,
678
+ signature,
679
+ ],
680
+ }
681
+ message = self.extend(request, params)
682
+ self.watch(url, messageHash, message, messageHash)
683
+ return await future
684
+
685
+ def handle_authentication_message(self, client: Client, message):
686
+ authenticated = self.safe_bool(message, 'success', False)
687
+ messageHash = 'authenticated'
688
+ if authenticated:
689
+ # we resolve the future here permanently so authentication only happens once
690
+ future = self.safe_value(client.futures, messageHash)
691
+ future.resolve(True)
692
+ else:
693
+ error = AuthenticationError(self.json(message))
694
+ client.reject(error, messageHash)
695
+ if messageHash in client.subscriptions:
696
+ del client.subscriptions[messageHash]
697
+
698
+ async def watch_positions(self, symbols: Strings = None, since: Int = None, limit: Int = None, params={}) -> List[Position]:
699
+ """
700
+ :see: https://www.bitmex.com/app/wsAPI
701
+ watch all open positions
702
+ :param str[]|None symbols: list of unified market symbols
703
+ :param dict params: extra parameters specific to the exchange API endpoint
704
+ :returns dict[]: a list of `position structure <https://docs.ccxt.com/en/latest/manual.html#position-structure>`
705
+ """
706
+ await self.load_markets()
707
+ await self.authenticate()
708
+ subscriptionHash = 'position'
709
+ messageHash = 'positions'
710
+ if not self.is_empty(symbols):
711
+ messageHash = '::' + ','.join(symbols)
712
+ url = self.urls['api']['ws']
713
+ request: dict = {
714
+ 'op': 'subscribe',
715
+ 'args': [
716
+ subscriptionHash,
717
+ ],
718
+ }
719
+ newPositions = await self.watch(url, messageHash, request, subscriptionHash)
720
+ if self.newUpdates:
721
+ return newPositions
722
+ return self.filter_by_symbols_since_limit(self.positions, symbols, since, limit, True)
723
+
724
+ def handle_positions(self, client, message):
725
+ #
726
+ # partial
727
+ # {
728
+ # table: 'position',
729
+ # action: 'partial',
730
+ # keys: ['account', 'symbol'],
731
+ # types: {
732
+ # account: 'long',
733
+ # symbol: 'symbol',
734
+ # currency: 'symbol',
735
+ # underlying: 'symbol',
736
+ # quoteCurrency: 'symbol',
737
+ # commission: 'float',
738
+ # initMarginReq: 'float',
739
+ # maintMarginReq: 'float',
740
+ # riskLimit: 'long',
741
+ # leverage: 'float',
742
+ # crossMargin: 'boolean',
743
+ # deleveragePercentile: 'float',
744
+ # rebalancedPnl: 'long',
745
+ # prevRealisedPnl: 'long',
746
+ # prevUnrealisedPnl: 'long',
747
+ # openingQty: 'long',
748
+ # openOrderBuyQty: 'long',
749
+ # openOrderBuyCost: 'long',
750
+ # openOrderBuyPremium: 'long',
751
+ # openOrderSellQty: 'long',
752
+ # openOrderSellCost: 'long',
753
+ # openOrderSellPremium: 'long',
754
+ # currentQty: 'long',
755
+ # currentCost: 'long',
756
+ # currentComm: 'long',
757
+ # realisedCost: 'long',
758
+ # unrealisedCost: 'long',
759
+ # grossOpenPremium: 'long',
760
+ # isOpen: 'boolean',
761
+ # markPrice: 'float',
762
+ # markValue: 'long',
763
+ # riskValue: 'long',
764
+ # homeNotional: 'float',
765
+ # foreignNotional: 'float',
766
+ # posState: 'symbol',
767
+ # posCost: 'long',
768
+ # posCross: 'long',
769
+ # posComm: 'long',
770
+ # posLoss: 'long',
771
+ # posMargin: 'long',
772
+ # posMaint: 'long',
773
+ # initMargin: 'long',
774
+ # maintMargin: 'long',
775
+ # realisedPnl: 'long',
776
+ # unrealisedPnl: 'long',
777
+ # unrealisedPnlPcnt: 'float',
778
+ # unrealisedRoePcnt: 'float',
779
+ # avgCostPrice: 'float',
780
+ # avgEntryPrice: 'float',
781
+ # breakEvenPrice: 'float',
782
+ # marginCallPrice: 'float',
783
+ # liquidationPrice: 'float',
784
+ # bankruptPrice: 'float',
785
+ # timestamp: 'timestamp'
786
+ # },
787
+ # filter: {account: 412475},
788
+ # data: [
789
+ # {
790
+ # account: 412475,
791
+ # symbol: 'XBTUSD',
792
+ # currency: 'XBt',
793
+ # underlying: 'XBT',
794
+ # quoteCurrency: 'USD',
795
+ # commission: 0.00075,
796
+ # initMarginReq: 0.01,
797
+ # maintMarginReq: 0.0035,
798
+ # riskLimit: 20000000000,
799
+ # leverage: 100,
800
+ # crossMargin: True,
801
+ # deleveragePercentile: 1,
802
+ # rebalancedPnl: 0,
803
+ # prevRealisedPnl: 0,
804
+ # prevUnrealisedPnl: 0,
805
+ # openingQty: 400,
806
+ # openOrderBuyQty: 0,
807
+ # openOrderBuyCost: 0,
808
+ # openOrderBuyPremium: 0,
809
+ # openOrderSellQty: 0,
810
+ # openOrderSellCost: 0,
811
+ # openOrderSellPremium: 0,
812
+ # currentQty: 400,
813
+ # currentCost: -912269,
814
+ # currentComm: 684,
815
+ # realisedCost: 0,
816
+ # unrealisedCost: -912269,
817
+ # grossOpenPremium: 0,
818
+ # isOpen: True,
819
+ # markPrice: 43772,
820
+ # markValue: -913828,
821
+ # riskValue: 913828,
822
+ # homeNotional: 0.00913828,
823
+ # foreignNotional: -400,
824
+ # posCost: -912269,
825
+ # posCross: 1559,
826
+ # posComm: 694,
827
+ # posLoss: 0,
828
+ # posMargin: 11376,
829
+ # posMaint: 3887,
830
+ # initMargin: 0,
831
+ # maintMargin: 9817,
832
+ # realisedPnl: -684,
833
+ # unrealisedPnl: -1559,
834
+ # unrealisedPnlPcnt: -0.0017,
835
+ # unrealisedRoePcnt: -0.1709,
836
+ # avgCostPrice: 43846.7643,
837
+ # avgEntryPrice: 43846.7643,
838
+ # breakEvenPrice: 43880,
839
+ # marginCallPrice: 20976,
840
+ # liquidationPrice: 20976,
841
+ # bankruptPrice: 20941,
842
+ # timestamp: '2023-12-07T00:09:00.709Z'
843
+ # }
844
+ # ]
845
+ # }
846
+ # update
847
+ # {
848
+ # table: 'position',
849
+ # action: 'update',
850
+ # data: [
851
+ # {
852
+ # account: 412475,
853
+ # symbol: 'XBTUSD',
854
+ # currency: 'XBt',
855
+ # currentQty: 400,
856
+ # markPrice: 43772.75,
857
+ # markValue: -913812,
858
+ # riskValue: 913812,
859
+ # homeNotional: 0.00913812,
860
+ # posCross: 1543,
861
+ # posComm: 693,
862
+ # posMargin: 11359,
863
+ # posMaint: 3886,
864
+ # maintMargin: 9816,
865
+ # unrealisedPnl: -1543,
866
+ # unrealisedRoePcnt: -0.1691,
867
+ # liquidationPrice: 20976,
868
+ # timestamp: '2023-12-07T00:09:10.760Z'
869
+ # }
870
+ # ]
871
+ # }
872
+ #
873
+ if self.positions is None:
874
+ self.positions = ArrayCacheBySymbolBySide()
875
+ cache = self.positions
876
+ rawPositions = self.safe_value(message, 'data', [])
877
+ newPositions = []
878
+ for i in range(0, len(rawPositions)):
879
+ rawPosition = rawPositions[i]
880
+ position = self.parse_position(rawPosition)
881
+ newPositions.append(position)
882
+ cache.append(position)
883
+ messageHashes = self.find_message_hashes(client, 'positions::')
884
+ for i in range(0, len(messageHashes)):
885
+ messageHash = messageHashes[i]
886
+ parts = messageHash.split('::')
887
+ symbolsString = parts[1]
888
+ symbols = symbolsString.split(',')
889
+ positions = self.filter_by_array(newPositions, 'symbol', symbols, False)
890
+ if not self.is_empty(positions):
891
+ client.resolve(positions, messageHash)
892
+ client.resolve(newPositions, 'positions')
893
+
894
+ async def watch_orders(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Order]:
895
+ """
896
+ watches information on multiple orders made by the user
897
+ :param str symbol: unified market symbol of the market orders were made in
898
+ :param int [since]: the earliest time in ms to fetch orders for
899
+ :param int [limit]: the maximum number of order structures to retrieve
900
+ :param dict [params]: extra parameters specific to the exchange API endpoint
901
+ :returns dict[]: a list of `order structures <https://docs.ccxt.com/#/?id=order-structure>`
902
+ """
903
+ await self.load_markets()
904
+ await self.authenticate()
905
+ name = 'order'
906
+ subscriptionHash = name
907
+ messageHash = name
908
+ if symbol is not None:
909
+ symbol = self.symbol(symbol)
910
+ messageHash += ':' + symbol
911
+ url = self.urls['api']['ws']
912
+ request: dict = {
913
+ 'op': 'subscribe',
914
+ 'args': [
915
+ subscriptionHash,
916
+ ],
917
+ }
918
+ orders = await self.watch(url, messageHash, request, subscriptionHash)
919
+ if self.newUpdates:
920
+ limit = orders.getLimit(symbol, limit)
921
+ return self.filter_by_symbol_since_limit(orders, symbol, since, limit, True)
922
+
923
+ def handle_orders(self, client: Client, message):
924
+ #
925
+ # {
926
+ # "table": "order",
927
+ # "action": "partial",
928
+ # "keys": ["orderID"],
929
+ # "types": {
930
+ # "orderID": "guid",
931
+ # "clOrdID": "string",
932
+ # "clOrdLinkID": "symbol",
933
+ # "account": "long",
934
+ # "symbol": "symbol",
935
+ # "side": "symbol",
936
+ # "simpleOrderQty": "float",
937
+ # "orderQty": "long",
938
+ # "price": "float",
939
+ # "displayQty": "long",
940
+ # "stopPx": "float",
941
+ # "pegOffsetValue": "float",
942
+ # "pegPriceType": "symbol",
943
+ # "currency": "symbol",
944
+ # "settlCurrency": "symbol",
945
+ # "ordType": "symbol",
946
+ # "timeInForce": "symbol",
947
+ # "execInst": "symbol",
948
+ # "contingencyType": "symbol",
949
+ # "exDestination": "symbol",
950
+ # "ordStatus": "symbol",
951
+ # "triggered": "symbol",
952
+ # "workingIndicator": "boolean",
953
+ # "ordRejReason": "symbol",
954
+ # "simpleLeavesQty": "float",
955
+ # "leavesQty": "long",
956
+ # "simpleCumQty": "float",
957
+ # "cumQty": "long",
958
+ # "avgPx": "float",
959
+ # "multiLegReportingType": "symbol",
960
+ # "text": "string",
961
+ # "transactTime": "timestamp",
962
+ # "timestamp": "timestamp"
963
+ # },
964
+ # "foreignKeys": {symbol: 'instrument', side: "side", ordStatus: "ordStatus"},
965
+ # "attributes": {
966
+ # "orderID": "grouped",
967
+ # "account": "grouped",
968
+ # "ordStatus": "grouped",
969
+ # "workingIndicator": "grouped"
970
+ # },
971
+ # "filter": {account: 1455728},
972
+ # "data": [
973
+ # {
974
+ # "orderID": "56222c7a-9956-413a-82cf-99f4812c214b",
975
+ # "clOrdID": '',
976
+ # "clOrdLinkID": '',
977
+ # "account": 1455728,
978
+ # "symbol": "XBTUSD",
979
+ # "side": "Sell",
980
+ # "simpleOrderQty": null,
981
+ # "orderQty": 1,
982
+ # "price": 40000,
983
+ # "displayQty": null,
984
+ # "stopPx": null,
985
+ # "pegOffsetValue": null,
986
+ # "pegPriceType": '',
987
+ # "currency": "USD",
988
+ # "settlCurrency": "XBt",
989
+ # "ordType": "Limit",
990
+ # "timeInForce": "GoodTillCancel",
991
+ # "execInst": '',
992
+ # "contingencyType": '',
993
+ # "exDestination": "XBME",
994
+ # "ordStatus": "New",
995
+ # "triggered": '',
996
+ # "workingIndicator": True,
997
+ # "ordRejReason": '',
998
+ # "simpleLeavesQty": null,
999
+ # "leavesQty": 1,
1000
+ # "simpleCumQty": null,
1001
+ # "cumQty": 0,
1002
+ # "avgPx": null,
1003
+ # "multiLegReportingType": "SingleSecurity",
1004
+ # "text": "Submitted via API.",
1005
+ # "transactTime": "2021-01-02T21:38:49.246Z",
1006
+ # "timestamp": "2021-01-02T21:38:49.246Z"
1007
+ # }
1008
+ # ]
1009
+ # }
1010
+ #
1011
+ # {
1012
+ # "table": "order",
1013
+ # "action": "insert",
1014
+ # "data": [
1015
+ # {
1016
+ # "orderID": "fa993d8e-f7e4-46ed-8097-04f8e9393585",
1017
+ # "clOrdID": '',
1018
+ # "clOrdLinkID": '',
1019
+ # "account": 1455728,
1020
+ # "symbol": "XBTUSD",
1021
+ # "side": "Sell",
1022
+ # "simpleOrderQty": null,
1023
+ # "orderQty": 1,
1024
+ # "price": 40000,
1025
+ # "displayQty": null,
1026
+ # "stopPx": null,
1027
+ # "pegOffsetValue": null,
1028
+ # "pegPriceType": '',
1029
+ # "currency": "USD",
1030
+ # "settlCurrency": "XBt",
1031
+ # "ordType": "Limit",
1032
+ # "timeInForce": "GoodTillCancel",
1033
+ # "execInst": '',
1034
+ # "contingencyType": '',
1035
+ # "exDestination": "XBME",
1036
+ # "ordStatus": "New",
1037
+ # "triggered": '',
1038
+ # "workingIndicator": True,
1039
+ # "ordRejReason": '',
1040
+ # "simpleLeavesQty": null,
1041
+ # "leavesQty": 1,
1042
+ # "simpleCumQty": null,
1043
+ # "cumQty": 0,
1044
+ # "avgPx": null,
1045
+ # "multiLegReportingType": "SingleSecurity",
1046
+ # "text": "Submitted via API.",
1047
+ # "transactTime": "2021-01-02T23:49:02.286Z",
1048
+ # "timestamp": "2021-01-02T23:49:02.286Z"
1049
+ # }
1050
+ # ]
1051
+ # }
1052
+ #
1053
+ #
1054
+ #
1055
+ # {
1056
+ # "table": "order",
1057
+ # "action": "update",
1058
+ # "data": [
1059
+ # {
1060
+ # "orderID": "fa993d8e-f7e4-46ed-8097-04f8e9393585",
1061
+ # "ordStatus": "Canceled",
1062
+ # "workingIndicator": False,
1063
+ # "leavesQty": 0,
1064
+ # "text": "Canceled: Canceled via API.\nSubmitted via API.",
1065
+ # "timestamp": "2021-01-02T23:50:51.272Z",
1066
+ # "clOrdID": '',
1067
+ # "account": 1455728,
1068
+ # "symbol": "XBTUSD"
1069
+ # }
1070
+ # ]
1071
+ # }
1072
+ #
1073
+ data = self.safe_value(message, 'data', [])
1074
+ messageHash = 'order'
1075
+ # initial subscription response with multiple orders
1076
+ dataLength = len(data)
1077
+ if dataLength > 0:
1078
+ if self.orders is None:
1079
+ limit = self.safe_integer(self.options, 'ordersLimit', 1000)
1080
+ self.orders = ArrayCacheBySymbolById(limit)
1081
+ stored = self.orders
1082
+ symbols: dict = {}
1083
+ for i in range(0, dataLength):
1084
+ currentOrder = data[i]
1085
+ orderId = self.safe_string(currentOrder, 'orderID')
1086
+ previousOrder = self.safe_value(stored.hashmap, orderId)
1087
+ rawOrder = currentOrder
1088
+ if previousOrder is not None:
1089
+ rawOrder = self.extend(previousOrder['info'], currentOrder)
1090
+ order = self.parse_order(rawOrder)
1091
+ stored.append(order)
1092
+ symbol = order['symbol']
1093
+ symbols[symbol] = True
1094
+ client.resolve(self.orders, messageHash)
1095
+ keys = list(symbols.keys())
1096
+ for i in range(0, len(keys)):
1097
+ symbol = keys[i]
1098
+ client.resolve(self.orders, messageHash + ':' + symbol)
1099
+
1100
+ async def watch_my_trades(self, symbol: Str = None, since: Int = None, limit: Int = None, params={}) -> List[Trade]:
1101
+ """
1102
+ watches information on multiple trades made by the user
1103
+ :param str symbol: unified market symbol of the market trades were made in
1104
+ :param int [since]: the earliest time in ms to fetch trades for
1105
+ :param int [limit]: the maximum number of trade structures to retrieve
1106
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1107
+ :returns dict[]: a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
1108
+ """
1109
+ await self.load_markets()
1110
+ await self.authenticate()
1111
+ name = 'execution'
1112
+ subscriptionHash = name
1113
+ messageHash = name
1114
+ if symbol is not None:
1115
+ symbol = self.symbol(symbol)
1116
+ messageHash += ':' + symbol
1117
+ url = self.urls['api']['ws']
1118
+ request: dict = {
1119
+ 'op': 'subscribe',
1120
+ 'args': [
1121
+ subscriptionHash,
1122
+ ],
1123
+ }
1124
+ trades = await self.watch(url, messageHash, request, subscriptionHash)
1125
+ if self.newUpdates:
1126
+ limit = trades.getLimit(symbol, limit)
1127
+ return self.filter_by_symbol_since_limit(trades, symbol, since, limit, True)
1128
+
1129
+ def handle_my_trades(self, client: Client, message):
1130
+ #
1131
+ # {
1132
+ # "table":"execution",
1133
+ # "action":"insert",
1134
+ # "data":[
1135
+ # {
1136
+ # "execID":"0193e879-cb6f-2891-d099-2c4eb40fee21",
1137
+ # "orderID":"00000000-0000-0000-0000-000000000000",
1138
+ # "clOrdID":"",
1139
+ # "clOrdLinkID":"",
1140
+ # "account":2,
1141
+ # "symbol":"XBTUSD",
1142
+ # "side":"Sell",
1143
+ # "lastQty":1,
1144
+ # "lastPx":1134.37,
1145
+ # "underlyingLastPx":null,
1146
+ # "lastMkt":"XBME",
1147
+ # "lastLiquidityInd":"RemovedLiquidity",
1148
+ # "simpleOrderQty":null,
1149
+ # "orderQty":1,
1150
+ # "price":1134.37,
1151
+ # "displayQty":null,
1152
+ # "stopPx":null,
1153
+ # "pegOffsetValue":null,
1154
+ # "pegPriceType":"",
1155
+ # "currency":"USD",
1156
+ # "settlCurrency":"XBt",
1157
+ # "execType":"Trade",
1158
+ # "ordType":"Limit",
1159
+ # "timeInForce":"ImmediateOrCancel",
1160
+ # "execInst":"",
1161
+ # "contingencyType":"",
1162
+ # "exDestination":"XBME",
1163
+ # "ordStatus":"Filled",
1164
+ # "triggered":"",
1165
+ # "workingIndicator":false,
1166
+ # "ordRejReason":"",
1167
+ # "simpleLeavesQty":0,
1168
+ # "leavesQty":0,
1169
+ # "simpleCumQty":0.001,
1170
+ # "cumQty":1,
1171
+ # "avgPx":1134.37,
1172
+ # "commission":0.00075,
1173
+ # "tradePublishIndicator":"DoNotPublishTrade",
1174
+ # "multiLegReportingType":"SingleSecurity",
1175
+ # "text":"Liquidation",
1176
+ # "trdMatchID":"7f4ab7f6-0006-3234-76f4-ae1385aad00f",
1177
+ # "execCost":88155,
1178
+ # "execComm":66,
1179
+ # "homeNotional":-0.00088155,
1180
+ # "foreignNotional":1,
1181
+ # "transactTime":"2017-04-04T22:07:46.035Z",
1182
+ # "timestamp":"2017-04-04T22:07:46.035Z"
1183
+ # }
1184
+ # ]
1185
+ # }
1186
+ #
1187
+ messageHash = self.safe_string(message, 'table')
1188
+ data = self.safe_value(message, 'data', [])
1189
+ dataByExecType = self.group_by(data, 'execType')
1190
+ rawTrades = self.safe_value(dataByExecType, 'Trade', [])
1191
+ trades = self.parse_trades(rawTrades)
1192
+ if self.myTrades is None:
1193
+ limit = self.safe_integer(self.options, 'tradesLimit', 1000)
1194
+ self.myTrades = ArrayCacheBySymbolById(limit)
1195
+ stored = self.myTrades
1196
+ symbols: dict = {}
1197
+ for j in range(0, len(trades)):
1198
+ trade = trades[j]
1199
+ symbol = trade['symbol']
1200
+ stored.append(trade)
1201
+ symbols[symbol] = trade
1202
+ numTrades = len(trades)
1203
+ if numTrades > 0:
1204
+ client.resolve(stored, messageHash)
1205
+ keys = list(symbols.keys())
1206
+ for i in range(0, len(keys)):
1207
+ client.resolve(stored, messageHash + ':' + keys[i])
1208
+
1209
+ async def watch_order_book(self, symbol: str, limit: Int = None, params={}) -> OrderBook:
1210
+ """
1211
+ watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
1212
+ :param str symbol: unified symbol of the market to fetch the order book for
1213
+ :param int [limit]: the maximum amount of order book entries to return
1214
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1215
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
1216
+ """
1217
+ return await self.watch_order_book_for_symbols([symbol], limit, params)
1218
+
1219
+ async def watch_order_book_for_symbols(self, symbols: List[str], limit: Int = None, params={}) -> OrderBook:
1220
+ """
1221
+ watches information on open orders with bid(buy) and ask(sell) prices, volumes and other data
1222
+ :param str[] symbols: unified array of symbols
1223
+ :param int [limit]: the maximum amount of order book entries to return
1224
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1225
+ :returns dict: A dictionary of `order book structures <https://docs.ccxt.com/#/?id=order-book-structure>` indexed by market symbols
1226
+ """
1227
+ table = None
1228
+ if limit is None:
1229
+ table = self.safe_string(self.options, 'watchOrderBookLevel', 'orderBookL2')
1230
+ elif limit == 25:
1231
+ table = 'orderBookL2_25'
1232
+ elif limit == 10:
1233
+ table = 'orderBookL10'
1234
+ else:
1235
+ raise ExchangeError(self.id + ' watchOrderBookForSymbols limit argument must be None(L2), 25(L2) or 10(L3)')
1236
+ await self.load_markets()
1237
+ symbols = self.market_symbols(symbols)
1238
+ topics = []
1239
+ messageHashes = []
1240
+ for i in range(0, len(symbols)):
1241
+ symbol = symbols[i]
1242
+ market = self.market(symbol)
1243
+ topic = table + ':' + market['id']
1244
+ topics.append(topic)
1245
+ messageHash = table + ':' + symbol
1246
+ messageHashes.append(messageHash)
1247
+ url = self.urls['api']['ws']
1248
+ request: dict = {
1249
+ 'op': 'subscribe',
1250
+ 'args': topics,
1251
+ }
1252
+ orderbook = await self.watch_multiple(url, messageHashes, self.deep_extend(request, params), topics)
1253
+ return orderbook.limit()
1254
+
1255
+ async def watch_trades_for_symbols(self, symbols: List[str], since: Int = None, limit: Int = None, params={}) -> List[Trade]:
1256
+ """
1257
+ get the list of most recent trades for a list of symbols
1258
+ :param str[] symbols: unified symbol of the market to fetch trades for
1259
+ :param int [since]: timestamp in ms of the earliest trade to fetch
1260
+ :param int [limit]: the maximum amount of trades to fetch
1261
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1262
+ :returns dict[]: a list of `trade structures <https://docs.ccxt.com/#/?id=public-trades>`
1263
+ """
1264
+ await self.load_markets()
1265
+ symbols = self.market_symbols(symbols, None, False)
1266
+ table = 'trade'
1267
+ topics = []
1268
+ messageHashes = []
1269
+ for i in range(0, len(symbols)):
1270
+ symbol = symbols[i]
1271
+ market = self.market(symbol)
1272
+ topic = table + ':' + market['id']
1273
+ topics.append(topic)
1274
+ messageHash = table + ':' + symbol
1275
+ messageHashes.append(messageHash)
1276
+ url = self.urls['api']['ws']
1277
+ request: dict = {
1278
+ 'op': 'subscribe',
1279
+ 'args': topics,
1280
+ }
1281
+ trades = await self.watch_multiple(url, messageHashes, self.deep_extend(request, params), topics)
1282
+ if self.newUpdates:
1283
+ first = self.safe_value(trades, 0)
1284
+ tradeSymbol = self.safe_string(first, 'symbol')
1285
+ limit = trades.getLimit(tradeSymbol, limit)
1286
+ return self.filter_by_since_limit(trades, since, limit, 'timestamp', True)
1287
+
1288
+ async def watch_ohlcv(self, symbol: str, timeframe='1m', since: Int = None, limit: Int = None, params={}) -> List[list]:
1289
+ """
1290
+ watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1291
+ :param str symbol: unified symbol of the market to fetch OHLCV data for
1292
+ :param str timeframe: the length of time each candle represents
1293
+ :param int [since]: timestamp in ms of the earliest candle to fetch
1294
+ :param int [limit]: the maximum amount of candles to fetch
1295
+ :param dict [params]: extra parameters specific to the exchange API endpoint
1296
+ :returns int[][]: A list of candles ordered, open, high, low, close, volume
1297
+ """
1298
+ await self.load_markets()
1299
+ market = self.market(symbol)
1300
+ symbol = market['symbol']
1301
+ table = 'tradeBin' + self.safe_string(self.timeframes, timeframe, timeframe)
1302
+ messageHash = table + ':' + market['id']
1303
+ url = self.urls['api']['ws']
1304
+ request: dict = {
1305
+ 'op': 'subscribe',
1306
+ 'args': [
1307
+ messageHash,
1308
+ ],
1309
+ }
1310
+ ohlcv = await self.watch(url, messageHash, self.extend(request, params), messageHash)
1311
+ if self.newUpdates:
1312
+ limit = ohlcv.getLimit(symbol, limit)
1313
+ return self.filter_by_since_limit(ohlcv, since, limit, 0, True)
1314
+
1315
+ def handle_ohlcv(self, client: Client, message):
1316
+ #
1317
+ # {
1318
+ # "table": "tradeBin1m",
1319
+ # "action": "partial",
1320
+ # "keys": [],
1321
+ # "types": {
1322
+ # "timestamp": "timestamp",
1323
+ # "symbol": "symbol",
1324
+ # "open": "float",
1325
+ # "high": "float",
1326
+ # "low": "float",
1327
+ # "close": "float",
1328
+ # "trades": "long",
1329
+ # "volume": "long",
1330
+ # "vwap": "float",
1331
+ # "lastSize": "long",
1332
+ # "turnover": "long",
1333
+ # "homeNotional": "float",
1334
+ # "foreignNotional": "float"
1335
+ # },
1336
+ # "foreignKeys": {symbol: "instrument"},
1337
+ # "attributes": {timestamp: "sorted", symbol: "grouped"},
1338
+ # "filter": {symbol: "XBTUSD"},
1339
+ # "data": [
1340
+ # {
1341
+ # "timestamp": "2020-02-03T01:13:00.000Z",
1342
+ # "symbol": "XBTUSD",
1343
+ # "open": 9395,
1344
+ # "high": 9395.5,
1345
+ # "low": 9394.5,
1346
+ # "close": 9395,
1347
+ # "trades": 221,
1348
+ # "volume": 839204,
1349
+ # "vwap": 9394.9643,
1350
+ # "lastSize": 1874,
1351
+ # "turnover": 8932641535,
1352
+ # "homeNotional": 89.32641534999999,
1353
+ # "foreignNotional": 839204
1354
+ # }
1355
+ # ]
1356
+ # }
1357
+ #
1358
+ #
1359
+ # {
1360
+ # "table": "tradeBin1m",
1361
+ # "action": "insert",
1362
+ # "data": [
1363
+ # {
1364
+ # "timestamp": "2020-02-03T18:28:00.000Z",
1365
+ # "symbol": "XBTUSD",
1366
+ # "open": 9256,
1367
+ # "high": 9256.5,
1368
+ # "low": 9256,
1369
+ # "close": 9256,
1370
+ # "trades": 29,
1371
+ # "volume": 79057,
1372
+ # "vwap": 9256.688,
1373
+ # "lastSize": 100,
1374
+ # "turnover": 854077082,
1375
+ # "homeNotional": 8.540770820000002,
1376
+ # "foreignNotional": 79057
1377
+ # }
1378
+ # ]
1379
+ # }
1380
+ #
1381
+ table = self.safe_string(message, 'table')
1382
+ interval = table.replace('tradeBin', '')
1383
+ timeframe = self.find_timeframe(interval)
1384
+ duration = self.parse_timeframe(timeframe)
1385
+ candles = self.safe_value(message, 'data', [])
1386
+ results: dict = {}
1387
+ for i in range(0, len(candles)):
1388
+ candle = candles[i]
1389
+ marketId = self.safe_string(candle, 'symbol')
1390
+ market = self.safe_market(marketId)
1391
+ symbol = market['symbol']
1392
+ messageHash = table + ':' + market['id']
1393
+ result = [
1394
+ self.parse8601(self.safe_string(candle, 'timestamp')) - duration * 1000,
1395
+ None, # set open price to None, see: https://github.com/ccxt/ccxt/pull/21356#issuecomment-1969565862
1396
+ self.safe_float(candle, 'high'),
1397
+ self.safe_float(candle, 'low'),
1398
+ self.safe_float(candle, 'close'),
1399
+ self.safe_float(candle, 'volume'),
1400
+ ]
1401
+ self.ohlcvs[symbol] = self.safe_value(self.ohlcvs, symbol, {})
1402
+ stored = self.safe_value(self.ohlcvs[symbol], timeframe)
1403
+ if stored is None:
1404
+ limit = self.safe_integer(self.options, 'OHLCVLimit', 1000)
1405
+ stored = ArrayCacheByTimestamp(limit)
1406
+ self.ohlcvs[symbol][timeframe] = stored
1407
+ stored.append(result)
1408
+ results[messageHash] = stored
1409
+ messageHashes = list(results.keys())
1410
+ for i in range(0, len(messageHashes)):
1411
+ messageHash = messageHashes[i]
1412
+ client.resolve(results[messageHash], messageHash)
1413
+
1414
+ async def watch_heartbeat(self, params={}):
1415
+ await self.load_markets()
1416
+ event = 'heartbeat'
1417
+ url = self.urls['api']['ws']
1418
+ return await self.watch(url, event)
1419
+
1420
+ def handle_order_book(self, client: Client, message):
1421
+ #
1422
+ # first snapshot
1423
+ #
1424
+ # {
1425
+ # "table": "orderBookL2",
1426
+ # "action": "partial",
1427
+ # "keys": ['symbol', "id", "side"],
1428
+ # "types": {
1429
+ # "symbol": "symbol",
1430
+ # "id": "long",
1431
+ # "side": "symbol",
1432
+ # "size": "long",
1433
+ # "price": "float"
1434
+ # },
1435
+ # "foreignKeys": {symbol: "instrument", side: "side"},
1436
+ # "attributes": {symbol: "parted", id: "sorted"},
1437
+ # "filter": {symbol: "XBTUSD"},
1438
+ # "data": [
1439
+ # {symbol: "XBTUSD", id: 8700000100, side: "Sell", size: 1, price: 999999},
1440
+ # {symbol: "XBTUSD", id: 8700000200, side: "Sell", size: 3, price: 999998},
1441
+ # {symbol: "XBTUSD", id: 8716991250, side: "Sell", size: 26, price: 830087.5},
1442
+ # {symbol: "XBTUSD", id: 8728701950, side: "Sell", size: 1720, price: 712980.5},
1443
+ # ]
1444
+ # }
1445
+ #
1446
+ # subsequent updates
1447
+ #
1448
+ # {
1449
+ # "table": "orderBookL2",
1450
+ # "action": "update",
1451
+ # "data": [
1452
+ # {
1453
+ # "table": "orderBookL2",
1454
+ # "action": "insert",
1455
+ # "data": [
1456
+ # {
1457
+ # "symbol": "ETH_USDT",
1458
+ # "id": 85499965912,
1459
+ # "side": "Buy",
1460
+ # "size": 83000000,
1461
+ # "price": 1704.4,
1462
+ # "timestamp": "2023-03-26T22:29:00.299Z"
1463
+ # }
1464
+ # ]
1465
+ # }
1466
+ # ...
1467
+ # ]
1468
+ # }
1469
+ #
1470
+ action = self.safe_string(message, 'action')
1471
+ table = self.safe_string(message, 'table')
1472
+ if table is None:
1473
+ return # protecting from weird updates
1474
+ data = self.safe_value(message, 'data', [])
1475
+ # if it's an initial snapshot
1476
+ if action == 'partial':
1477
+ filter = self.safe_dict(message, 'filter', {})
1478
+ marketId = self.safe_value(filter, 'symbol')
1479
+ if marketId is None:
1480
+ return # protecting from weird update
1481
+ market = self.safe_market(marketId)
1482
+ symbol = market['symbol']
1483
+ if table == 'orderBookL2':
1484
+ self.orderbooks[symbol] = self.indexed_order_book()
1485
+ elif table == 'orderBookL2_25':
1486
+ self.orderbooks[symbol] = self.indexed_order_book({}, 25)
1487
+ elif table == 'orderBook10':
1488
+ self.orderbooks[symbol] = self.indexed_order_book({}, 10)
1489
+ orderbook = self.orderbooks[symbol]
1490
+ orderbook['symbol'] = symbol
1491
+ for i in range(0, len(data)):
1492
+ price = self.safe_float(data[i], 'price')
1493
+ size = self.convertFromRawQuantity(symbol, self.safe_string(data[i], 'size'))
1494
+ id = self.safe_string(data[i], 'id')
1495
+ side = self.safe_string(data[i], 'side')
1496
+ side = 'bids' if (side == 'Buy') else 'asks'
1497
+ bookside = orderbook[side]
1498
+ bookside.storeArray([price, size, id])
1499
+ datetime = self.safe_string(data[i], 'timestamp')
1500
+ orderbook['timestamp'] = self.parse8601(datetime)
1501
+ orderbook['datetime'] = datetime
1502
+ messageHash = table + ':' + symbol
1503
+ client.resolve(orderbook, messageHash)
1504
+ else:
1505
+ numUpdatesByMarketId: dict = {}
1506
+ for i in range(0, len(data)):
1507
+ marketId = self.safe_value(data[i], 'symbol')
1508
+ if marketId is None:
1509
+ return # protecting from weird update
1510
+ if not (marketId in numUpdatesByMarketId):
1511
+ numUpdatesByMarketId[marketId] = 0
1512
+ numUpdatesByMarketId[marketId] = self.sum(numUpdatesByMarketId, 1)
1513
+ market = self.safe_market(marketId)
1514
+ symbol = market['symbol']
1515
+ orderbook = self.orderbooks[symbol]
1516
+ price = self.safe_number(data[i], 'price')
1517
+ size = 0 if (action == 'delete') else self.convertFromRawQuantity(symbol, self.safe_string(data[i], 'size', '0'))
1518
+ id = self.safe_string(data[i], 'id')
1519
+ side = self.safe_string(data[i], 'side')
1520
+ side = 'bids' if (side == 'Buy') else 'asks'
1521
+ bookside = orderbook[side]
1522
+ bookside.storeArray([price, size, id])
1523
+ datetime = self.safe_string(data[i], 'timestamp')
1524
+ orderbook['timestamp'] = self.parse8601(datetime)
1525
+ orderbook['datetime'] = datetime
1526
+ marketIds = list(numUpdatesByMarketId.keys())
1527
+ for i in range(0, len(marketIds)):
1528
+ marketId = marketIds[i]
1529
+ market = self.safe_market(marketId)
1530
+ symbol = market['symbol']
1531
+ messageHash = table + ':' + symbol
1532
+ orderbook = self.orderbooks[symbol]
1533
+ client.resolve(orderbook, messageHash)
1534
+
1535
+ def handle_system_status(self, client: Client, message):
1536
+ #
1537
+ # todo answer the question whether handleSystemStatus should be renamed
1538
+ # and unified for any usage pattern that
1539
+ # involves system status and maintenance updates
1540
+ #
1541
+ # {
1542
+ # "info": "Welcome to the BitMEX Realtime API.",
1543
+ # "version": "2019-11-22T00:24:37.000Z",
1544
+ # "timestamp": "2019-11-23T09:02:27.771Z",
1545
+ # "docs": "https://www.bitmex.com/app/wsAPI",
1546
+ # "limit": {remaining: 39}
1547
+ # }
1548
+ #
1549
+ return message
1550
+
1551
+ def handle_subscription_status(self, client: Client, message):
1552
+ #
1553
+ # {
1554
+ # "success": True,
1555
+ # "subscribe": "orderBookL2:XBTUSD",
1556
+ # "request": {op: "subscribe", args: ["orderBookL2:XBTUSD"]}
1557
+ # }
1558
+ #
1559
+ return message
1560
+
1561
+ def handle_error_message(self, client: Client, message):
1562
+ #
1563
+ # generic error format
1564
+ #
1565
+ # {"error": errorMessage}
1566
+ #
1567
+ # examples
1568
+ #
1569
+ # {
1570
+ # "status": 429,
1571
+ # "error": "Rate limit exceeded, retry in 1 seconds.",
1572
+ # "meta": {"retryAfter": 1},
1573
+ # "request": {"op": "subscribe", "args": "orderBook"},
1574
+ # }
1575
+ #
1576
+ # {"error": "Rate limit exceeded, retry in 29 seconds."}
1577
+ #
1578
+ error = self.safe_string(message, 'error')
1579
+ if error is not None:
1580
+ request = self.safe_value(message, 'request', {})
1581
+ args = self.safe_value(request, 'args', [])
1582
+ numArgs = len(args)
1583
+ if numArgs > 0:
1584
+ messageHash = args[0]
1585
+ broad = self.exceptions['ws']['broad']
1586
+ broadKey = self.find_broadly_matched_key(broad, error)
1587
+ exception = None
1588
+ if broadKey is None:
1589
+ exception = ExchangeError(error) # c# requirement for now
1590
+ else:
1591
+ exception = broad[broadKey](error)
1592
+ client.reject(exception, messageHash)
1593
+ return False
1594
+ return True
1595
+
1596
+ def handle_message(self, client: Client, message):
1597
+ #
1598
+ # {
1599
+ # "info": "Welcome to the BitMEX Realtime API.",
1600
+ # "version": "2019-11-22T00:24:37.000Z",
1601
+ # "timestamp": "2019-11-23T09:04:42.569Z",
1602
+ # "docs": "https://www.bitmex.com/app/wsAPI",
1603
+ # "limit": {remaining: 38}
1604
+ # }
1605
+ #
1606
+ # {
1607
+ # "success": True,
1608
+ # "subscribe": "orderBookL2:XBTUSD",
1609
+ # "request": {op: "subscribe", args: ["orderBookL2:XBTUSD"]}
1610
+ # }
1611
+ #
1612
+ # {
1613
+ # "table": "orderBookL2",
1614
+ # "action": "update",
1615
+ # "data": [
1616
+ # {symbol: "XBTUSD", id: 8799284800, side: "Sell", size: 721000},
1617
+ # {symbol: "XBTUSD", id: 8799285100, side: "Sell", size: 70590},
1618
+ # {symbol: "XBTUSD", id: 8799285550, side: "Sell", size: 217652},
1619
+ # {symbol: "XBTUSD", id: 8799285850, side: "Sell", size: 105578},
1620
+ # {symbol: "XBTUSD", id: 8799286350, side: "Sell", size: 172093},
1621
+ # {symbol: "XBTUSD", id: 8799286650, side: "Sell", size: 201125},
1622
+ # {symbol: "XBTUSD", id: 8799288950, side: "Buy", size: 47552},
1623
+ # {symbol: "XBTUSD", id: 8799289250, side: "Buy", size: 78217},
1624
+ # {symbol: "XBTUSD", id: 8799289700, side: "Buy", size: 193677},
1625
+ # {symbol: "XBTUSD", id: 8799290000, side: "Buy", size: 818161},
1626
+ # {symbol: "XBTUSD", id: 8799290500, side: "Buy", size: 218806},
1627
+ # {symbol: "XBTUSD", id: 8799290800, side: "Buy", size: 102946}
1628
+ # ]
1629
+ # }
1630
+ #
1631
+ if self.handle_error_message(client, message):
1632
+ table = self.safe_string(message, 'table')
1633
+ methods: dict = {
1634
+ 'orderBookL2': self.handle_order_book,
1635
+ 'orderBookL2_25': self.handle_order_book,
1636
+ 'orderBook10': self.handle_order_book,
1637
+ 'instrument': self.handle_ticker,
1638
+ 'trade': self.handle_trades,
1639
+ 'tradeBin1m': self.handle_ohlcv,
1640
+ 'tradeBin5m': self.handle_ohlcv,
1641
+ 'tradeBin1h': self.handle_ohlcv,
1642
+ 'tradeBin1d': self.handle_ohlcv,
1643
+ 'order': self.handle_orders,
1644
+ 'execution': self.handle_my_trades,
1645
+ 'margin': self.handle_balance,
1646
+ 'liquidation': self.handle_liquidation,
1647
+ 'position': self.handle_positions,
1648
+ }
1649
+ method = self.safe_value(methods, table)
1650
+ if method is None:
1651
+ request = self.safe_value(message, 'request', {})
1652
+ op = self.safe_value(request, 'op')
1653
+ if op == 'authKeyExpires':
1654
+ self.handle_authentication_message(client, message)
1655
+ else:
1656
+ method(client, message)