ccxt 4.2.18 → 4.2.19

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 (426) hide show
  1. package/README.md +8 -8
  2. package/dist/ccxt.browser.js +34202 -33193
  3. package/dist/ccxt.browser.min.js +2 -2
  4. package/dist/cjs/ccxt.js +12 -1
  5. package/dist/cjs/src/alpaca.js +18 -18
  6. package/dist/cjs/src/ascendex.js +13 -6
  7. package/dist/cjs/src/base/Exchange.js +266 -27
  8. package/dist/cjs/src/bigone.js +434 -168
  9. package/dist/cjs/src/binance.js +163 -34
  10. package/dist/cjs/src/binanceus.js +8 -0
  11. package/dist/cjs/src/bingx.js +183 -41
  12. package/dist/cjs/src/bitfinex.js +2 -3
  13. package/dist/cjs/src/bitget.js +59 -16
  14. package/dist/cjs/src/bitmart.js +5 -5
  15. package/dist/cjs/src/bitmex.js +4 -6
  16. package/dist/cjs/src/bitpanda.js +5 -1991
  17. package/dist/cjs/src/bitstamp.js +8 -0
  18. package/dist/cjs/src/bybit.js +27 -47
  19. package/dist/cjs/src/coinbase.js +176 -26
  20. package/dist/cjs/src/coincheck.js +1 -0
  21. package/dist/cjs/src/coinex.js +3 -0
  22. package/dist/cjs/src/coinlist.js +13 -6
  23. package/dist/cjs/src/coinone.js +2 -2
  24. package/dist/cjs/src/coinsph.js +4 -5
  25. package/dist/cjs/src/delta.js +7 -1
  26. package/dist/cjs/src/deribit.js +17 -4
  27. package/dist/cjs/src/gate.js +151 -169
  28. package/dist/cjs/src/gemini.js +1 -1
  29. package/dist/cjs/src/hitbtc.js +2 -3
  30. package/dist/cjs/src/htx.js +157 -7
  31. package/dist/cjs/src/huobijp.js +2 -3
  32. package/dist/cjs/src/independentreserve.js +7 -5
  33. package/dist/cjs/src/kraken.js +86 -54
  34. package/dist/cjs/src/kucoin.js +5 -0
  35. package/dist/cjs/src/kucoinfutures.js +131 -77
  36. package/dist/cjs/src/lbank.js +60 -33
  37. package/dist/cjs/src/luno.js +84 -2
  38. package/dist/cjs/src/mexc.js +3 -3
  39. package/dist/cjs/src/oceanex.js +1 -1
  40. package/dist/cjs/src/okx.js +23 -11
  41. package/dist/cjs/{js/src/bitpanda.js → src/onetrading.js} +39 -39
  42. package/dist/cjs/src/phemex.js +37 -27
  43. package/dist/cjs/src/poloniexfutures.js +1 -0
  44. package/dist/cjs/src/pro/binance.js +66 -25
  45. package/dist/cjs/src/pro/bitget.js +1 -1
  46. package/dist/cjs/src/pro/bitpanda.js +5 -1330
  47. package/dist/cjs/src/pro/coinbase.js +4 -1
  48. package/dist/cjs/src/pro/hitbtc.js +5 -4
  49. package/dist/cjs/src/pro/htx.js +6 -1
  50. package/dist/cjs/src/pro/kraken.js +1 -1
  51. package/dist/cjs/src/pro/krakenfutures.js +7 -1
  52. package/dist/cjs/src/pro/kucoin.js +46 -36
  53. package/dist/cjs/src/pro/kucoinfutures.js +45 -37
  54. package/dist/cjs/src/pro/lbank.js +881 -0
  55. package/dist/cjs/src/pro/okx.js +52 -2
  56. package/dist/cjs/{js/src/pro/bitpanda.js → src/pro/onetrading.js} +4 -7
  57. package/dist/cjs/src/pro/poloniex.js +2 -2
  58. package/dist/cjs/src/pro/poloniexfutures.js +43 -35
  59. package/dist/cjs/src/pro/woo.js +126 -0
  60. package/dist/cjs/src/probit.js +4 -2
  61. package/dist/cjs/src/upbit.js +12 -12
  62. package/dist/cjs/src/wavesexchange.js +1 -1
  63. package/dist/cjs/src/whitebit.js +1 -0
  64. package/dist/cjs/src/woo.js +56 -0
  65. package/js/ccxt.d.ts +11 -2
  66. package/js/ccxt.js +8 -2
  67. package/js/src/abstract/bitpanda.d.ts +4 -4
  68. package/js/src/abstract/bitstamp.d.ts +8 -0
  69. package/js/src/abstract/gate.d.ts +1 -0
  70. package/js/src/abstract/gateio.d.ts +1 -0
  71. package/js/src/abstract/htx.d.ts +3 -0
  72. package/js/src/abstract/huobi.d.ts +3 -0
  73. package/js/src/abstract/luno.d.ts +1 -0
  74. package/js/src/abstract/onetrading.d.ts +38 -0
  75. package/js/src/ascendex.js +2 -0
  76. package/js/src/bingx.js +1 -1
  77. package/js/src/bitget.js +22 -3
  78. package/js/src/bitpanda.d.ts +2 -72
  79. package/js/src/bitpanda.js +5 -1991
  80. package/js/src/bitstamp.js +8 -0
  81. package/js/src/deribit.js +11 -3
  82. package/js/src/gate.d.ts +1 -0
  83. package/js/src/gate.js +50 -110
  84. package/js/src/htx.js +3 -0
  85. package/js/src/kraken.d.ts +1 -0
  86. package/js/src/kraken.js +39 -38
  87. package/js/src/lbank.js +1 -0
  88. package/js/src/luno.d.ts +3 -1
  89. package/js/src/luno.js +84 -2
  90. package/js/src/mexc.js +1 -2
  91. package/js/src/onetrading.d.ts +74 -0
  92. package/js/src/onetrading.js +2003 -0
  93. package/js/src/poloniexfutures.js +1 -0
  94. package/js/src/pro/binance.js +6 -1
  95. package/js/src/pro/bitpanda.d.ts +2 -34
  96. package/js/src/pro/bitpanda.js +5 -1330
  97. package/js/src/pro/lbank.d.ts +29 -0
  98. package/js/src/pro/lbank.js +882 -0
  99. package/js/src/pro/onetrading.d.ts +36 -0
  100. package/js/src/pro/onetrading.js +1339 -0
  101. package/package.json +2 -2
  102. package/rollup.config.js +2 -0
  103. package/skip-tests.json +2 -1
  104. package/test-commonjs.cjs +25 -1
  105. package/dist/cjs/js/ccxt.js +0 -478
  106. package/dist/cjs/js/src/abstract/alpaca.js +0 -9
  107. package/dist/cjs/js/src/abstract/ascendex.js +0 -9
  108. package/dist/cjs/js/src/abstract/bigone.js +0 -9
  109. package/dist/cjs/js/src/abstract/binance.js +0 -9
  110. package/dist/cjs/js/src/abstract/bingx.js +0 -9
  111. package/dist/cjs/js/src/abstract/bit2c.js +0 -9
  112. package/dist/cjs/js/src/abstract/bitbank.js +0 -9
  113. package/dist/cjs/js/src/abstract/bitbns.js +0 -9
  114. package/dist/cjs/js/src/abstract/bitfinex.js +0 -9
  115. package/dist/cjs/js/src/abstract/bitfinex2.js +0 -9
  116. package/dist/cjs/js/src/abstract/bitflyer.js +0 -9
  117. package/dist/cjs/js/src/abstract/bitforex.js +0 -9
  118. package/dist/cjs/js/src/abstract/bitget.js +0 -9
  119. package/dist/cjs/js/src/abstract/bithumb.js +0 -9
  120. package/dist/cjs/js/src/abstract/bitmart.js +0 -9
  121. package/dist/cjs/js/src/abstract/bitmex.js +0 -9
  122. package/dist/cjs/js/src/abstract/bitopro.js +0 -9
  123. package/dist/cjs/js/src/abstract/bitpanda.js +0 -9
  124. package/dist/cjs/js/src/abstract/bitrue.js +0 -9
  125. package/dist/cjs/js/src/abstract/bitso.js +0 -9
  126. package/dist/cjs/js/src/abstract/bitstamp.js +0 -9
  127. package/dist/cjs/js/src/abstract/bitteam.js +0 -9
  128. package/dist/cjs/js/src/abstract/bitvavo.js +0 -9
  129. package/dist/cjs/js/src/abstract/bl3p.js +0 -9
  130. package/dist/cjs/js/src/abstract/blockchaincom.js +0 -9
  131. package/dist/cjs/js/src/abstract/btcalpha.js +0 -9
  132. package/dist/cjs/js/src/abstract/btcbox.js +0 -9
  133. package/dist/cjs/js/src/abstract/btcmarkets.js +0 -9
  134. package/dist/cjs/js/src/abstract/btcturk.js +0 -9
  135. package/dist/cjs/js/src/abstract/bybit.js +0 -9
  136. package/dist/cjs/js/src/abstract/cex.js +0 -9
  137. package/dist/cjs/js/src/abstract/coinbase.js +0 -9
  138. package/dist/cjs/js/src/abstract/coinbasepro.js +0 -9
  139. package/dist/cjs/js/src/abstract/coincheck.js +0 -9
  140. package/dist/cjs/js/src/abstract/coinex.js +0 -9
  141. package/dist/cjs/js/src/abstract/coinlist.js +0 -9
  142. package/dist/cjs/js/src/abstract/coinmate.js +0 -9
  143. package/dist/cjs/js/src/abstract/coinone.js +0 -9
  144. package/dist/cjs/js/src/abstract/coinsph.js +0 -9
  145. package/dist/cjs/js/src/abstract/coinspot.js +0 -9
  146. package/dist/cjs/js/src/abstract/cryptocom.js +0 -9
  147. package/dist/cjs/js/src/abstract/currencycom.js +0 -9
  148. package/dist/cjs/js/src/abstract/delta.js +0 -9
  149. package/dist/cjs/js/src/abstract/deribit.js +0 -9
  150. package/dist/cjs/js/src/abstract/digifinex.js +0 -9
  151. package/dist/cjs/js/src/abstract/exmo.js +0 -9
  152. package/dist/cjs/js/src/abstract/gate.js +0 -9
  153. package/dist/cjs/js/src/abstract/gemini.js +0 -9
  154. package/dist/cjs/js/src/abstract/hitbtc.js +0 -9
  155. package/dist/cjs/js/src/abstract/hollaex.js +0 -9
  156. package/dist/cjs/js/src/abstract/htx.js +0 -9
  157. package/dist/cjs/js/src/abstract/huobijp.js +0 -9
  158. package/dist/cjs/js/src/abstract/idex.js +0 -9
  159. package/dist/cjs/js/src/abstract/independentreserve.js +0 -9
  160. package/dist/cjs/js/src/abstract/indodax.js +0 -9
  161. package/dist/cjs/js/src/abstract/kraken.js +0 -9
  162. package/dist/cjs/js/src/abstract/krakenfutures.js +0 -9
  163. package/dist/cjs/js/src/abstract/kucoin.js +0 -9
  164. package/dist/cjs/js/src/abstract/kucoinfutures.js +0 -9
  165. package/dist/cjs/js/src/abstract/kuna.js +0 -9
  166. package/dist/cjs/js/src/abstract/latoken.js +0 -9
  167. package/dist/cjs/js/src/abstract/lbank.js +0 -9
  168. package/dist/cjs/js/src/abstract/luno.js +0 -9
  169. package/dist/cjs/js/src/abstract/lykke.js +0 -9
  170. package/dist/cjs/js/src/abstract/mercado.js +0 -9
  171. package/dist/cjs/js/src/abstract/mexc.js +0 -9
  172. package/dist/cjs/js/src/abstract/ndax.js +0 -9
  173. package/dist/cjs/js/src/abstract/novadax.js +0 -9
  174. package/dist/cjs/js/src/abstract/oceanex.js +0 -9
  175. package/dist/cjs/js/src/abstract/okcoin.js +0 -9
  176. package/dist/cjs/js/src/abstract/okx.js +0 -9
  177. package/dist/cjs/js/src/abstract/p2b.js +0 -9
  178. package/dist/cjs/js/src/abstract/paymium.js +0 -9
  179. package/dist/cjs/js/src/abstract/phemex.js +0 -9
  180. package/dist/cjs/js/src/abstract/poloniex.js +0 -9
  181. package/dist/cjs/js/src/abstract/poloniexfutures.js +0 -9
  182. package/dist/cjs/js/src/abstract/probit.js +0 -9
  183. package/dist/cjs/js/src/abstract/timex.js +0 -9
  184. package/dist/cjs/js/src/abstract/tokocrypto.js +0 -9
  185. package/dist/cjs/js/src/abstract/upbit.js +0 -9
  186. package/dist/cjs/js/src/abstract/wavesexchange.js +0 -9
  187. package/dist/cjs/js/src/abstract/wazirx.js +0 -9
  188. package/dist/cjs/js/src/abstract/whitebit.js +0 -9
  189. package/dist/cjs/js/src/abstract/woo.js +0 -9
  190. package/dist/cjs/js/src/abstract/yobit.js +0 -9
  191. package/dist/cjs/js/src/abstract/zaif.js +0 -9
  192. package/dist/cjs/js/src/abstract/zonda.js +0 -9
  193. package/dist/cjs/js/src/ace.js +0 -1058
  194. package/dist/cjs/js/src/alpaca.js +0 -1125
  195. package/dist/cjs/js/src/ascendex.js +0 -3365
  196. package/dist/cjs/js/src/base/Exchange.js +0 -5260
  197. package/dist/cjs/js/src/base/Precise.js +0 -263
  198. package/dist/cjs/js/src/base/errors.js +0 -299
  199. package/dist/cjs/js/src/base/functions/crypto.js +0 -78
  200. package/dist/cjs/js/src/base/functions/encode.js +0 -44
  201. package/dist/cjs/js/src/base/functions/generic.js +0 -193
  202. package/dist/cjs/js/src/base/functions/misc.js +0 -96
  203. package/dist/cjs/js/src/base/functions/number.js +0 -297
  204. package/dist/cjs/js/src/base/functions/platform.js +0 -28
  205. package/dist/cjs/js/src/base/functions/rsa.js +0 -34
  206. package/dist/cjs/js/src/base/functions/string.js +0 -48
  207. package/dist/cjs/js/src/base/functions/throttle.js +0 -66
  208. package/dist/cjs/js/src/base/functions/time.js +0 -187
  209. package/dist/cjs/js/src/base/functions/totp.js +0 -24
  210. package/dist/cjs/js/src/base/functions/type.js +0 -162
  211. package/dist/cjs/js/src/base/functions.js +0 -157
  212. package/dist/cjs/js/src/base/ws/Cache.js +0 -254
  213. package/dist/cjs/js/src/base/ws/Client.js +0 -299
  214. package/dist/cjs/js/src/base/ws/Future.js +0 -34
  215. package/dist/cjs/js/src/base/ws/OrderBook.js +0 -107
  216. package/dist/cjs/js/src/base/ws/OrderBookSide.js +0 -281
  217. package/dist/cjs/js/src/base/ws/WsClient.js +0 -69
  218. package/dist/cjs/js/src/bequant.js +0 -33
  219. package/dist/cjs/js/src/bigone.js +0 -2213
  220. package/dist/cjs/js/src/binance.js +0 -9851
  221. package/dist/cjs/js/src/binancecoinm.js +0 -45
  222. package/dist/cjs/js/src/binanceus.js +0 -92
  223. package/dist/cjs/js/src/binanceusdm.js +0 -58
  224. package/dist/cjs/js/src/bingx.js +0 -3872
  225. package/dist/cjs/js/src/bit2c.js +0 -916
  226. package/dist/cjs/js/src/bitbank.js +0 -1000
  227. package/dist/cjs/js/src/bitbay.js +0 -17
  228. package/dist/cjs/js/src/bitbns.js +0 -1220
  229. package/dist/cjs/js/src/bitcoincom.js +0 -17
  230. package/dist/cjs/js/src/bitfinex.js +0 -1670
  231. package/dist/cjs/js/src/bitfinex2.js +0 -2990
  232. package/dist/cjs/js/src/bitflyer.js +0 -1045
  233. package/dist/cjs/js/src/bitforex.js +0 -852
  234. package/dist/cjs/js/src/bitget.js +0 -8295
  235. package/dist/cjs/js/src/bithumb.js +0 -1090
  236. package/dist/cjs/js/src/bitmart.js +0 -4454
  237. package/dist/cjs/js/src/bitmex.js +0 -2881
  238. package/dist/cjs/js/src/bitopro.js +0 -1724
  239. package/dist/cjs/js/src/bitrue.js +0 -3253
  240. package/dist/cjs/js/src/bitso.js +0 -1753
  241. package/dist/cjs/js/src/bitstamp.js +0 -2188
  242. package/dist/cjs/js/src/bitteam.js +0 -2309
  243. package/dist/cjs/js/src/bitvavo.js +0 -1968
  244. package/dist/cjs/js/src/bl3p.js +0 -447
  245. package/dist/cjs/js/src/blockchaincom.js +0 -1160
  246. package/dist/cjs/js/src/btcalpha.js +0 -929
  247. package/dist/cjs/js/src/btcbox.js +0 -565
  248. package/dist/cjs/js/src/btcmarkets.js +0 -1237
  249. package/dist/cjs/js/src/btcturk.js +0 -929
  250. package/dist/cjs/js/src/bybit.js +0 -7624
  251. package/dist/cjs/js/src/cex.js +0 -1693
  252. package/dist/cjs/js/src/coinbase.js +0 -3424
  253. package/dist/cjs/js/src/coinbasepro.js +0 -1866
  254. package/dist/cjs/js/src/coincheck.js +0 -844
  255. package/dist/cjs/js/src/coinex.js +0 -5417
  256. package/dist/cjs/js/src/coinlist.js +0 -2337
  257. package/dist/cjs/js/src/coinmate.js +0 -989
  258. package/dist/cjs/js/src/coinone.js +0 -1185
  259. package/dist/cjs/js/src/coinsph.js +0 -1933
  260. package/dist/cjs/js/src/coinspot.js +0 -548
  261. package/dist/cjs/js/src/cryptocom.js +0 -3007
  262. package/dist/cjs/js/src/currencycom.js +0 -2015
  263. package/dist/cjs/js/src/delta.js +0 -3262
  264. package/dist/cjs/js/src/deribit.js +0 -3310
  265. package/dist/cjs/js/src/digifinex.js +0 -4307
  266. package/dist/cjs/js/src/exmo.js +0 -2645
  267. package/dist/cjs/js/src/fmfwio.js +0 -34
  268. package/dist/cjs/js/src/gate.js +0 -7077
  269. package/dist/cjs/js/src/gateio.js +0 -16
  270. package/dist/cjs/js/src/gemini.js +0 -1801
  271. package/dist/cjs/js/src/hitbtc.js +0 -3660
  272. package/dist/cjs/js/src/hitbtc3.js +0 -19
  273. package/dist/cjs/js/src/hollaex.js +0 -1882
  274. package/dist/cjs/js/src/htx.js +0 -9174
  275. package/dist/cjs/js/src/huobi.js +0 -16
  276. package/dist/cjs/js/src/huobijp.js +0 -1918
  277. package/dist/cjs/js/src/idex.js +0 -1770
  278. package/dist/cjs/js/src/independentreserve.js +0 -761
  279. package/dist/cjs/js/src/indodax.js +0 -1069
  280. package/dist/cjs/js/src/kraken.js +0 -2891
  281. package/dist/cjs/js/src/krakenfutures.js +0 -2407
  282. package/dist/cjs/js/src/kucoin.js +0 -4494
  283. package/dist/cjs/js/src/kucoinfutures.js +0 -2529
  284. package/dist/cjs/js/src/kuna.js +0 -1949
  285. package/dist/cjs/js/src/latoken.js +0 -1729
  286. package/dist/cjs/js/src/lbank.js +0 -2851
  287. package/dist/cjs/js/src/luno.js +0 -1044
  288. package/dist/cjs/js/src/lykke.js +0 -1303
  289. package/dist/cjs/js/src/mercado.js +0 -897
  290. package/dist/cjs/js/src/mexc.js +0 -5407
  291. package/dist/cjs/js/src/ndax.js +0 -2450
  292. package/dist/cjs/js/src/novadax.js +0 -1556
  293. package/dist/cjs/js/src/oceanex.js +0 -964
  294. package/dist/cjs/js/src/okcoin.js +0 -3115
  295. package/dist/cjs/js/src/okx.js +0 -7331
  296. package/dist/cjs/js/src/p2b.js +0 -1243
  297. package/dist/cjs/js/src/paymium.js +0 -597
  298. package/dist/cjs/js/src/phemex.js +0 -4725
  299. package/dist/cjs/js/src/poloniex.js +0 -2356
  300. package/dist/cjs/js/src/poloniexfutures.js +0 -1794
  301. package/dist/cjs/js/src/pro/alpaca.js +0 -714
  302. package/dist/cjs/js/src/pro/ascendex.js +0 -957
  303. package/dist/cjs/js/src/pro/bequant.js +0 -33
  304. package/dist/cjs/js/src/pro/binance.js +0 -2796
  305. package/dist/cjs/js/src/pro/binancecoinm.js +0 -23
  306. package/dist/cjs/js/src/pro/binanceus.js +0 -51
  307. package/dist/cjs/js/src/pro/binanceusdm.js +0 -32
  308. package/dist/cjs/js/src/pro/bingx.js +0 -944
  309. package/dist/cjs/js/src/pro/bitcoincom.js +0 -29
  310. package/dist/cjs/js/src/pro/bitfinex.js +0 -672
  311. package/dist/cjs/js/src/pro/bitfinex2.js +0 -1159
  312. package/dist/cjs/js/src/pro/bitget.js +0 -1733
  313. package/dist/cjs/js/src/pro/bitmart.js +0 -1486
  314. package/dist/cjs/js/src/pro/bitmex.js +0 -1576
  315. package/dist/cjs/js/src/pro/bitopro.js +0 -327
  316. package/dist/cjs/js/src/pro/bitrue.js +0 -462
  317. package/dist/cjs/js/src/pro/bitstamp.js +0 -547
  318. package/dist/cjs/js/src/pro/bitvavo.js +0 -704
  319. package/dist/cjs/js/src/pro/blockchaincom.js +0 -794
  320. package/dist/cjs/js/src/pro/bybit.js +0 -1843
  321. package/dist/cjs/js/src/pro/cex.js +0 -1510
  322. package/dist/cjs/js/src/pro/coinbase.js +0 -561
  323. package/dist/cjs/js/src/pro/coinbasepro.js +0 -968
  324. package/dist/cjs/js/src/pro/coinex.js +0 -1095
  325. package/dist/cjs/js/src/pro/cryptocom.js +0 -1020
  326. package/dist/cjs/js/src/pro/currencycom.js +0 -563
  327. package/dist/cjs/js/src/pro/deribit.js +0 -825
  328. package/dist/cjs/js/src/pro/exmo.js +0 -658
  329. package/dist/cjs/js/src/pro/gate.js +0 -1316
  330. package/dist/cjs/js/src/pro/gateio.js +0 -16
  331. package/dist/cjs/js/src/pro/gemini.js +0 -649
  332. package/dist/cjs/js/src/pro/hitbtc.js +0 -1294
  333. package/dist/cjs/js/src/pro/hollaex.js +0 -597
  334. package/dist/cjs/js/src/pro/htx.js +0 -2388
  335. package/dist/cjs/js/src/pro/huobi.js +0 -16
  336. package/dist/cjs/js/src/pro/huobijp.js +0 -606
  337. package/dist/cjs/js/src/pro/idex.js +0 -714
  338. package/dist/cjs/js/src/pro/independentreserve.js +0 -280
  339. package/dist/cjs/js/src/pro/kraken.js +0 -1364
  340. package/dist/cjs/js/src/pro/krakenfutures.js +0 -1506
  341. package/dist/cjs/js/src/pro/kucoin.js +0 -1062
  342. package/dist/cjs/js/src/pro/kucoinfutures.js +0 -989
  343. package/dist/cjs/js/src/pro/luno.js +0 -322
  344. package/dist/cjs/js/src/pro/mexc.js +0 -1170
  345. package/dist/cjs/js/src/pro/ndax.js +0 -545
  346. package/dist/cjs/js/src/pro/okcoin.js +0 -760
  347. package/dist/cjs/js/src/pro/okx.js +0 -1608
  348. package/dist/cjs/js/src/pro/phemex.js +0 -1511
  349. package/dist/cjs/js/src/pro/poloniex.js +0 -1253
  350. package/dist/cjs/js/src/pro/poloniexfutures.js +0 -1022
  351. package/dist/cjs/js/src/pro/probit.js +0 -586
  352. package/dist/cjs/js/src/pro/upbit.js +0 -234
  353. package/dist/cjs/js/src/pro/wazirx.js +0 -776
  354. package/dist/cjs/js/src/pro/whitebit.js +0 -927
  355. package/dist/cjs/js/src/pro/woo.js +0 -895
  356. package/dist/cjs/js/src/probit.js +0 -1867
  357. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +0 -401
  358. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -195
  359. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -308
  360. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +0 -554
  361. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -94
  362. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -70
  363. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -91
  364. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -16
  365. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +0 -1760
  366. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -52
  367. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +0 -81
  368. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +0 -376
  369. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -70
  370. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +0 -1580
  371. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -74
  372. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +0 -24
  373. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +0 -158
  374. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +0 -429
  375. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +0 -176
  376. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +0 -324
  377. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +0 -163
  378. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +0 -245
  379. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +0 -1018
  380. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +0 -383
  381. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +0 -258
  382. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +0 -53
  383. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +0 -120
  384. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +0 -69
  385. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +0 -7
  386. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +0 -83
  387. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +0 -240
  388. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +0 -91
  389. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +0 -130
  390. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +0 -214
  391. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +0 -239
  392. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +0 -93
  393. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +0 -354
  394. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +0 -16
  395. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +0 -20
  396. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +0 -30
  397. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +0 -239
  398. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +0 -372
  399. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +0 -273
  400. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +0 -139
  401. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +0 -14
  402. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +0 -16
  403. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +0 -81
  404. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +0 -292
  405. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +0 -103
  406. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +0 -140
  407. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +0 -175
  408. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +0 -95
  409. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +0 -7
  410. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +0 -383
  411. package/dist/cjs/js/src/timex.js +0 -1562
  412. package/dist/cjs/js/src/tokocrypto.js +0 -2542
  413. package/dist/cjs/js/src/upbit.js +0 -1844
  414. package/dist/cjs/js/src/wavesexchange.js +0 -2607
  415. package/dist/cjs/js/src/wazirx.js +0 -953
  416. package/dist/cjs/js/src/whitebit.js +0 -2310
  417. package/dist/cjs/js/src/woo.js +0 -2769
  418. package/dist/cjs/js/src/yobit.js +0 -1314
  419. package/dist/cjs/js/src/zaif.js +0 -736
  420. package/dist/cjs/js/src/zonda.js +0 -1883
  421. package/dist/cjs/src/abstract/bitpanda.js +0 -9
  422. package/test.ts +0 -0
  423. /package/dist/cjs/{js/src/abstract/ace.js → src/abstract/onetrading.js} +0 -0
  424. /package/dist/cjs/{js/src → src}/pro/coincheck.js +0 -0
  425. /package/dist/cjs/{js/src → src}/pro/coinone.js +0 -0
  426. /package/js/src/abstract/{bitpanda.js → onetrading.js} +0 -0
@@ -1,1486 +0,0 @@
1
- 'use strict';
2
-
3
- var bitmart$1 = require('../bitmart.js');
4
- var errors = require('../base/errors.js');
5
- var Cache = require('../base/ws/Cache.js');
6
- var sha256 = require('../static_dependencies/noble-hashes/sha256.js');
7
- var OrderBookSide = require('../base/ws/OrderBookSide.js');
8
-
9
- // ---------------------------------------------------------------------------
10
- // ---------------------------------------------------------------------------
11
- class bitmart extends bitmart$1 {
12
- describe() {
13
- return this.deepExtend(super.describe(), {
14
- 'has': {
15
- 'createOrderWs': false,
16
- 'editOrderWs': false,
17
- 'fetchOpenOrdersWs': false,
18
- 'fetchOrderWs': false,
19
- 'cancelOrderWs': false,
20
- 'cancelOrdersWs': false,
21
- 'cancelAllOrdersWs': false,
22
- 'ws': true,
23
- 'watchBalance': true,
24
- 'watchTicker': true,
25
- 'watchTickers': true,
26
- 'watchOrderBook': true,
27
- 'watchOrders': true,
28
- 'watchTrades': true,
29
- 'watchOHLCV': true,
30
- 'watchPosition': 'emulated',
31
- 'watchPositions': true,
32
- },
33
- 'urls': {
34
- 'api': {
35
- 'ws': {
36
- 'spot': {
37
- 'public': 'wss://ws-manager-compress.{hostname}/api?protocol=1.1',
38
- 'private': 'wss://ws-manager-compress.{hostname}/user?protocol=1.1',
39
- },
40
- 'swap': {
41
- 'public': 'wss://openapi-ws.{hostname}/api?protocol=1.1',
42
- 'private': 'wss://openapi-ws.{hostname}/user?protocol=1.1',
43
- },
44
- },
45
- },
46
- },
47
- 'options': {
48
- 'defaultType': 'spot',
49
- 'watchBalance': {
50
- 'fetchBalanceSnapshot': true,
51
- 'awaitBalanceSnapshot': false, // whether to wait for the balance snapshot before providing updates
52
- },
53
- 'watchOrderBook': {
54
- 'depth': 'depth/increase100', // depth/increase100, depth5, depth20, depth50
55
- },
56
- 'ws': {
57
- 'inflate': true,
58
- },
59
- 'timeframes': {
60
- '1m': '1m',
61
- '3m': '3m',
62
- '5m': '5m',
63
- '15m': '15m',
64
- '30m': '30m',
65
- '45m': '45m',
66
- '1h': '1H',
67
- '2h': '2H',
68
- '3h': '3H',
69
- '4h': '4H',
70
- '1d': '1D',
71
- '1w': '1W',
72
- '1M': '1M',
73
- },
74
- },
75
- 'streaming': {
76
- 'keepAlive': 15000,
77
- },
78
- });
79
- }
80
- async subscribe(channel, symbol, type, params = {}) {
81
- const market = this.market(symbol);
82
- const url = this.implodeHostname(this.urls['api']['ws'][type]['public']);
83
- let request = {};
84
- let messageHash = undefined;
85
- if (type === 'spot') {
86
- messageHash = 'spot/' + channel + ':' + market['id'];
87
- request = {
88
- 'op': 'subscribe',
89
- 'args': [messageHash],
90
- };
91
- }
92
- else {
93
- messageHash = 'futures/' + channel + ':' + market['id'];
94
- request = {
95
- 'action': 'subscribe',
96
- 'args': [messageHash],
97
- };
98
- }
99
- return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
100
- }
101
- async watchBalance(params = {}) {
102
- /**
103
- * @method
104
- * @name bitmart#watchBalance
105
- * @see https://developer-pro.bitmart.com/en/spot/#private-balance-change
106
- * @see https://developer-pro.bitmart.com/en/futures/#private-assets-channel
107
- * @description watch balance and get the amount of funds available for trading or funds locked in orders
108
- * @param {object} [params] extra parameters specific to the exchange API endpoint
109
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
110
- */
111
- await this.loadMarkets();
112
- let type = 'spot';
113
- [type, params] = this.handleMarketTypeAndParams('watchBalance', undefined, params);
114
- await this.authenticate(type, params);
115
- let request = {};
116
- if (type === 'spot') {
117
- request = {
118
- 'op': 'subscribe',
119
- 'args': ['spot/user/balance:BALANCE_UPDATE'],
120
- };
121
- }
122
- else {
123
- request = {
124
- 'action': 'subscribe',
125
- 'args': ['futures/asset:USDT', 'futures/asset:BTC', 'futures/asset:ETH'],
126
- };
127
- }
128
- const messageHash = 'balance:' + type;
129
- const url = this.implodeHostname(this.urls['api']['ws'][type]['private']);
130
- const client = this.client(url);
131
- this.setBalanceCache(client, type, messageHash);
132
- let fetchBalanceSnapshot = undefined;
133
- let awaitBalanceSnapshot = undefined;
134
- [fetchBalanceSnapshot, params] = this.handleOptionAndParams(this.options, 'watchBalance', 'fetchBalanceSnapshot', true);
135
- [awaitBalanceSnapshot, params] = this.handleOptionAndParams(this.options, 'watchBalance', 'awaitBalanceSnapshot', false);
136
- if (fetchBalanceSnapshot && awaitBalanceSnapshot) {
137
- await client.future(type + ':fetchBalanceSnapshot');
138
- }
139
- return await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
140
- }
141
- setBalanceCache(client, type, subscribeHash) {
142
- if (subscribeHash in client.subscriptions) {
143
- return;
144
- }
145
- const options = this.safeValue(this.options, 'watchBalance');
146
- const snapshot = this.safeValue(options, 'fetchBalanceSnapshot', true);
147
- if (snapshot) {
148
- const messageHash = type + ':' + 'fetchBalanceSnapshot';
149
- if (!(messageHash in client.futures)) {
150
- client.future(messageHash);
151
- this.spawn(this.loadBalanceSnapshot, client, messageHash, type);
152
- }
153
- }
154
- this.balance[type] = {};
155
- // without this comment, transpilation breaks for some reason...
156
- }
157
- async loadBalanceSnapshot(client, messageHash, type) {
158
- const response = await this.fetchBalance({ 'type': type });
159
- this.balance[type] = this.extend(response, this.safeValue(this.balance, type, {}));
160
- // don't remove the future from the .futures cache
161
- const future = client.futures[messageHash];
162
- future.resolve();
163
- client.resolve(this.balance[type], 'balance:' + type);
164
- }
165
- handleBalance(client, message) {
166
- //
167
- // spot
168
- // {
169
- // "data":[
170
- // {
171
- // "balance_details":[
172
- // {
173
- // "av_bal":"0.206000000000000000000000000000",
174
- // "ccy":"LTC",
175
- // "fz_bal":"0.100000000000000000000000000000"
176
- // }
177
- // ],
178
- // "event_time":"1701632345415",
179
- // "event_type":"TRANSACTION_COMPLETED"
180
- // }
181
- // ],
182
- // "table":"spot/user/balance"
183
- // }
184
- // swap
185
- // {
186
- // group: 'futures/asset:USDT',
187
- // data: {
188
- // currency: 'USDT',
189
- // available_balance: '37.19688649135',
190
- // position_deposit: '0.788687546',
191
- // frozen_balance: '0'
192
- // }
193
- // }
194
- //
195
- const channel = this.safeString2(message, 'table', 'group');
196
- const data = this.safeValue(message, 'data');
197
- if (data === undefined) {
198
- return;
199
- }
200
- const isSpot = (channel.indexOf('spot') >= 0);
201
- const type = isSpot ? 'spot' : 'swap';
202
- this.balance[type]['info'] = message;
203
- if (isSpot) {
204
- if (!Array.isArray(data)) {
205
- return;
206
- }
207
- for (let i = 0; i < data.length; i++) {
208
- const timestamp = this.safeInteger(message, 'event_time');
209
- this.balance[type]['timestamp'] = timestamp;
210
- this.balance[type]['datetime'] = this.iso8601(timestamp);
211
- const balanceDetails = this.safeValue(data[i], 'balance_details', []);
212
- for (let ii = 0; ii < balanceDetails.length; ii++) {
213
- const rawBalance = balanceDetails[i];
214
- const account = this.account();
215
- const currencyId = this.safeString(rawBalance, 'ccy');
216
- const code = this.safeCurrencyCode(currencyId);
217
- account['free'] = this.safeString(rawBalance, 'av_bal');
218
- account['used'] = this.safeString(rawBalance, 'fz_bal');
219
- this.balance[type][code] = account;
220
- }
221
- }
222
- }
223
- else {
224
- const currencyId = this.safeString(data, 'currency');
225
- const code = this.safeCurrencyCode(currencyId);
226
- const account = this.account();
227
- account['free'] = this.safeString(data, 'available_balance');
228
- account['used'] = this.safeString(data, 'frozen_balance');
229
- this.balance[type][code] = account;
230
- }
231
- this.balance[type] = this.safeBalance(this.balance[type]);
232
- const messageHash = 'balance:' + type;
233
- client.resolve(this.balance[type], messageHash);
234
- }
235
- async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
236
- /**
237
- * @method
238
- * @name bitmart#watchTrades
239
- * @see https://developer-pro.bitmart.com/en/spot/#public-trade-channel
240
- * @see https://developer-pro.bitmart.com/en/futures/#public-trade-channel
241
- * @description get the list of most recent trades for a particular symbol
242
- * @param {string} symbol unified symbol of the market to fetch trades for
243
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
244
- * @param {int} [limit] the maximum amount of trades to fetch
245
- * @param {object} [params] extra parameters specific to the exchange API endpoint
246
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
247
- */
248
- await this.loadMarkets();
249
- symbol = this.symbol(symbol);
250
- const market = this.market(symbol);
251
- let type = 'spot';
252
- [type, params] = this.handleMarketTypeAndParams('watchTrades', market, params);
253
- const trades = await this.subscribe('trade', symbol, type, params);
254
- if (this.newUpdates) {
255
- limit = trades.getLimit(symbol, limit);
256
- }
257
- return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
258
- }
259
- async watchTicker(symbol, params = {}) {
260
- /**
261
- * @method
262
- * @name bitmart#watchTicker
263
- * @see https://developer-pro.bitmart.com/en/spot/#public-ticker-channel
264
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
265
- * @param {string} symbol unified symbol of the market to fetch the ticker for
266
- * @param {object} [params] extra parameters specific to the exchange API endpoint
267
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
268
- */
269
- await this.loadMarkets();
270
- symbol = this.symbol(symbol);
271
- const market = this.market(symbol);
272
- let type = 'spot';
273
- [type, params] = this.handleMarketTypeAndParams('watchTicker', market, params);
274
- if (type === 'swap') {
275
- throw new errors.NotSupported(this.id + ' watchTicker() does not support ' + type + ' markets. Use watchTickers() instead');
276
- }
277
- return await this.subscribe('ticker', symbol, type, params);
278
- }
279
- async watchTickers(symbols = undefined, params = {}) {
280
- /**
281
- * @method
282
- * @name bitmart#watchTickers
283
- * @see https://developer-pro.bitmart.com/en/futures/#overview
284
- * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
285
- * @param {string[]} symbols unified symbol of the market to fetch the ticker for
286
- * @param {object} [params] extra parameters specific to the exchange API endpoint
287
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
288
- */
289
- await this.loadMarkets();
290
- const market = this.getMarketFromSymbols(symbols);
291
- let type = 'spot';
292
- [type, params] = this.handleMarketTypeAndParams('watchTickers', market, params);
293
- const url = this.implodeHostname(this.urls['api']['ws'][type]['public']);
294
- symbols = this.marketSymbols(symbols);
295
- let messageHash = 'tickers::' + type;
296
- if (symbols !== undefined) {
297
- messageHash += '::' + symbols.join(',');
298
- }
299
- let request = undefined;
300
- let tickers = undefined;
301
- const isSpot = (type === 'spot');
302
- if (isSpot) {
303
- if (symbols === undefined) {
304
- throw new errors.ArgumentsRequired(this.id + ' watchTickers() for ' + type + ' market type requires symbols argument to be provided');
305
- }
306
- const marketIds = this.marketIds(symbols);
307
- const finalArray = [];
308
- for (let i = 0; i < marketIds.length; i++) {
309
- finalArray.push('spot/ticker:' + marketIds[i]);
310
- }
311
- request = {
312
- 'op': 'subscribe',
313
- 'args': finalArray,
314
- };
315
- tickers = await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
316
- }
317
- else {
318
- request = {
319
- 'action': 'subscribe',
320
- 'args': ['futures/ticker'],
321
- };
322
- tickers = await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
323
- }
324
- if (this.newUpdates) {
325
- return tickers;
326
- }
327
- return this.filterByArray(this.tickers, 'symbol', symbols);
328
- }
329
- async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
330
- /**
331
- * @method
332
- * @name bitmart#watchOrders
333
- * @see https://developer-pro.bitmart.com/en/spot/#private-order-channel
334
- * @see https://developer-pro.bitmart.com/en/futures/#private-order-channel
335
- * @description watches information on multiple orders made by the user
336
- * @param {string} symbol unified market symbol of the market orders were made in
337
- * @param {int} [since] the earliest time in ms to fetch orders for
338
- * @param {int} [limit] the maximum number of order structures to retrieve
339
- * @param {object} [params] extra parameters specific to the exchange API endpoint
340
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
341
- */
342
- await this.loadMarkets();
343
- let market = undefined;
344
- let messageHash = 'orders';
345
- if (symbol !== undefined) {
346
- symbol = this.symbol(symbol);
347
- market = this.market(symbol);
348
- messageHash = 'orders::' + symbol;
349
- }
350
- let type = 'spot';
351
- [type, params] = this.handleMarketTypeAndParams('watchOrders', market, params);
352
- await this.authenticate(type, params);
353
- let request = undefined;
354
- if (type === 'spot') {
355
- if (symbol === undefined) {
356
- throw new errors.ArgumentsRequired(this.id + ' watchOrders() requires a symbol argument for spot markets');
357
- }
358
- request = {
359
- 'op': 'subscribe',
360
- 'args': ['spot/user/order:' + market['id']],
361
- };
362
- }
363
- else {
364
- request = {
365
- 'action': 'subscribe',
366
- 'args': ['futures/order'],
367
- };
368
- }
369
- const url = this.implodeHostname(this.urls['api']['ws'][type]['private']);
370
- const newOrders = await this.watch(url, messageHash, this.deepExtend(request, params), messageHash);
371
- if (this.newUpdates) {
372
- return newOrders;
373
- }
374
- return this.filterBySymbolSinceLimit(this.orders, symbol, since, limit, true);
375
- }
376
- handleOrders(client, message) {
377
- //
378
- // spot
379
- // {
380
- // "data":[
381
- // {
382
- // "symbol": "LTC_USDT",
383
- // "notional": '',
384
- // "side": "buy",
385
- // "last_fill_time": "0",
386
- // "ms_t": "1646216634000",
387
- // "type": "limit",
388
- // "filled_notional": "0.000000000000000000000000000000",
389
- // "last_fill_price": "0",
390
- // "size": "0.500000000000000000000000000000",
391
- // "price": "50.000000000000000000000000000000",
392
- // "last_fill_count": "0",
393
- // "filled_size": "0.000000000000000000000000000000",
394
- // "margin_trading": "0",
395
- // "state": "8",
396
- // "order_id": "24807076628",
397
- // "order_type": "0"
398
- // }
399
- // ],
400
- // "table":"spot/user/order"
401
- // }
402
- // swap
403
- // {
404
- // "group":"futures/order",
405
- // "data":[
406
- // {
407
- // "action":2,
408
- // "order":{
409
- // "order_id":"2312045036986775",
410
- // "client_order_id":"",
411
- // "price":"71.61707928",
412
- // "size":"1",
413
- // "symbol":"LTCUSDT",
414
- // "state":1,
415
- // "side":4,
416
- // "type":"market",
417
- // "leverage":"1",
418
- // "open_type":"cross",
419
- // "deal_avg_price":"0",
420
- // "deal_size":"0",
421
- // "create_time":1701625324646,
422
- // "update_time":1701625324640,
423
- // "plan_order_id":"",
424
- // "last_trade":null
425
- // }
426
- // }
427
- // ]
428
- // }
429
- //
430
- const orders = this.safeValue(message, 'data');
431
- if (orders === undefined) {
432
- return;
433
- }
434
- const ordersLength = orders.length;
435
- const newOrders = [];
436
- const symbols = {};
437
- if (ordersLength > 0) {
438
- const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
439
- if (this.orders === undefined) {
440
- this.orders = new Cache.ArrayCacheBySymbolById(limit);
441
- }
442
- const stored = this.orders;
443
- for (let i = 0; i < orders.length; i++) {
444
- const order = this.parseWsOrder(orders[i]);
445
- stored.append(order);
446
- newOrders.push(order);
447
- const symbol = order['symbol'];
448
- symbols[symbol] = true;
449
- }
450
- }
451
- const messageHash = 'orders';
452
- const symbolKeys = Object.keys(symbols);
453
- for (let i = 0; i < symbolKeys.length; i++) {
454
- const symbol = symbolKeys[i];
455
- const symbolSpecificMessageHash = messageHash + '::' + symbol;
456
- client.resolve(newOrders, symbolSpecificMessageHash);
457
- }
458
- client.resolve(newOrders, messageHash);
459
- }
460
- parseWsOrder(order, market = undefined) {
461
- //
462
- // spot
463
- // {
464
- // "symbol": "LTC_USDT",
465
- // "notional": '',
466
- // "side": "buy",
467
- // "last_fill_time": "0",
468
- // "ms_t": "1646216634000",
469
- // "type": "limit",
470
- // "filled_notional": "0.000000000000000000000000000000",
471
- // "last_fill_price": "0",
472
- // "size": "0.500000000000000000000000000000",
473
- // "price": "50.000000000000000000000000000000",
474
- // "last_fill_count": "0",
475
- // "filled_size": "0.000000000000000000000000000000",
476
- // "margin_trading": "0",
477
- // "state": "8",
478
- // "order_id": "24807076628",
479
- // "order_type": "0"
480
- // }
481
- // swap
482
- // {
483
- // "action":2,
484
- // "order":{
485
- // "order_id":"2312045036986775",
486
- // "client_order_id":"",
487
- // "price":"71.61707928",
488
- // "size":"1",
489
- // "symbol":"LTCUSDT",
490
- // "state":1,
491
- // "side":4,
492
- // "type":"market",
493
- // "leverage":"1",
494
- // "open_type":"cross",
495
- // "deal_avg_price":"0",
496
- // "deal_size":"0",
497
- // "create_time":1701625324646,
498
- // "update_time":1701625324640,
499
- // "plan_order_id":"",
500
- // "last_trade":null
501
- // }
502
- // }
503
- //
504
- const action = this.safeNumber(order, 'action');
505
- const isSpot = (action === undefined);
506
- if (isSpot) {
507
- const marketId = this.safeString(order, 'symbol');
508
- market = this.safeMarket(marketId, market, '_', 'spot');
509
- const id = this.safeString(order, 'order_id');
510
- const clientOrderId = this.safeString(order, 'clientOid');
511
- const price = this.safeString(order, 'price');
512
- const filled = this.safeString(order, 'filled_size');
513
- const amount = this.safeString(order, 'size');
514
- const type = this.safeString(order, 'type');
515
- const rawState = this.safeString(order, 'state');
516
- const status = this.parseOrderStatusByType(market['type'], rawState);
517
- const timestamp = this.safeInteger(order, 'ms_t');
518
- const symbol = market['symbol'];
519
- const side = this.safeStringLower(order, 'side');
520
- return this.safeOrder({
521
- 'info': order,
522
- 'symbol': symbol,
523
- 'id': id,
524
- 'clientOrderId': clientOrderId,
525
- 'timestamp': undefined,
526
- 'datetime': undefined,
527
- 'lastTradeTimestamp': timestamp,
528
- 'type': type,
529
- 'timeInForce': undefined,
530
- 'postOnly': undefined,
531
- 'side': side,
532
- 'price': price,
533
- 'stopPrice': undefined,
534
- 'triggerPrice': undefined,
535
- 'amount': amount,
536
- 'cost': undefined,
537
- 'average': undefined,
538
- 'filled': filled,
539
- 'remaining': undefined,
540
- 'status': status,
541
- 'fee': undefined,
542
- 'trades': undefined,
543
- }, market);
544
- }
545
- else {
546
- const orderInfo = this.safeValue(order, 'order');
547
- const marketId = this.safeString(orderInfo, 'symbol');
548
- const symbol = this.safeSymbol(marketId, market, '', 'swap');
549
- const orderId = this.safeString(orderInfo, 'order_id');
550
- const timestamp = this.safeInteger(orderInfo, 'create_time');
551
- const updatedTimestamp = this.safeInteger(orderInfo, 'update_time');
552
- const lastTrade = this.safeValue(orderInfo, 'last_trade');
553
- const cachedOrders = this.orders;
554
- const orders = this.safeValue(cachedOrders.hashmap, symbol, {});
555
- const cachedOrder = this.safeValue(orders, orderId);
556
- let trades = undefined;
557
- if (cachedOrder !== undefined) {
558
- trades = this.safeValue(order, 'trades');
559
- }
560
- if (lastTrade !== undefined) {
561
- if (trades === undefined) {
562
- trades = [];
563
- }
564
- trades.push(lastTrade);
565
- }
566
- return this.safeOrder({
567
- 'info': order,
568
- 'symbol': symbol,
569
- 'id': orderId,
570
- 'clientOrderId': this.safeString(orderInfo, 'client_order_id'),
571
- 'timestamp': timestamp,
572
- 'datetime': this.iso8601(timestamp),
573
- 'lastTradeTimestamp': updatedTimestamp,
574
- 'type': this.safeString(orderInfo, 'type'),
575
- 'timeInForce': undefined,
576
- 'postOnly': undefined,
577
- 'side': this.parseWsOrderSide(this.safeString(orderInfo, 'side')),
578
- 'price': this.safeString(orderInfo, 'price'),
579
- 'stopPrice': undefined,
580
- 'triggerPrice': undefined,
581
- 'amount': this.safeString(orderInfo, 'size'),
582
- 'cost': undefined,
583
- 'average': this.safeString(orderInfo, 'deal_avg_price'),
584
- 'filled': this.safeString(orderInfo, 'deal_size'),
585
- 'remaining': undefined,
586
- 'status': this.parseWsOrderStatus(this.safeString(order, 'action')),
587
- 'fee': undefined,
588
- 'trades': trades,
589
- }, market);
590
- }
591
- }
592
- parseWsOrderStatus(statusId) {
593
- const statuses = {
594
- '1': 'closed',
595
- '2': 'open',
596
- '3': 'canceled',
597
- '4': 'closed',
598
- '5': 'canceled',
599
- '6': 'open',
600
- '7': 'open',
601
- '8': 'closed',
602
- '9': 'closed', // active adl match deal
603
- };
604
- return this.safeString(statuses, statusId, statusId);
605
- }
606
- parseWsOrderSide(sideId) {
607
- const sides = {
608
- '1': 'buy',
609
- '2': 'buy',
610
- '3': 'sell',
611
- '4': 'sell', // sell_open_short
612
- };
613
- return this.safeString(sides, sideId, sideId);
614
- }
615
- async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
616
- /**
617
- * @method
618
- * @name bitmart#watchPositions
619
- * @see https://developer-pro.bitmart.com/en/futures/#private-position-channel
620
- * @description watch all open positions
621
- * @param {string[]|undefined} symbols list of unified market symbols
622
- * @param {object} params extra parameters specific to the exchange API endpoint
623
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
624
- */
625
- await this.loadMarkets();
626
- const type = 'swap';
627
- await this.authenticate(type, params);
628
- symbols = this.marketSymbols(symbols, 'swap', true, true, false);
629
- let messageHash = 'positions';
630
- if (symbols !== undefined) {
631
- messageHash += '::' + symbols.join(',');
632
- }
633
- const subscriptionHash = 'futures/position';
634
- const request = {
635
- 'action': 'subscribe',
636
- 'args': ['futures/position'],
637
- };
638
- const url = this.implodeHostname(this.urls['api']['ws'][type]['private']);
639
- const newPositions = await this.watch(url, messageHash, this.deepExtend(request, params), subscriptionHash);
640
- if (this.newUpdates) {
641
- return newPositions;
642
- }
643
- return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit);
644
- }
645
- handlePositions(client, message) {
646
- //
647
- // {
648
- // "group":"futures/position",
649
- // "data":[
650
- // {
651
- // "symbol":"LTCUSDT",
652
- // "hold_volume":"5",
653
- // "position_type":2,
654
- // "open_type":2,
655
- // "frozen_volume":"0",
656
- // "close_volume":"0",
657
- // "hold_avg_price":"71.582",
658
- // "close_avg_price":"0",
659
- // "open_avg_price":"71.582",
660
- // "liquidate_price":"0",
661
- // "create_time":1701623327513,
662
- // "update_time":1701627620439
663
- // },
664
- // {
665
- // "symbol":"LTCUSDT",
666
- // "hold_volume":"6",
667
- // "position_type":1,
668
- // "open_type":2,
669
- // "frozen_volume":"0",
670
- // "close_volume":"0",
671
- // "hold_avg_price":"71.681666666666666667",
672
- // "close_avg_price":"0",
673
- // "open_avg_price":"71.681666666666666667",
674
- // "liquidate_price":"0",
675
- // "create_time":1701621167225,
676
- // "update_time":1701628152614
677
- // }
678
- // ]
679
- // }
680
- //
681
- const data = this.safeValue(message, 'data', []);
682
- const cache = this.positions;
683
- if (this.positions === undefined) {
684
- this.positions = new Cache.ArrayCacheBySymbolBySide();
685
- }
686
- const newPositions = [];
687
- for (let i = 0; i < data.length; i++) {
688
- const rawPosition = data[i];
689
- const position = this.parseWsPosition(rawPosition);
690
- newPositions.push(position);
691
- cache.append(position);
692
- }
693
- const messageHashes = this.findMessageHashes(client, 'positions::');
694
- for (let i = 0; i < messageHashes.length; i++) {
695
- const messageHash = messageHashes[i];
696
- const parts = messageHash.split('::');
697
- const symbolsString = parts[1];
698
- const symbols = symbolsString.split(',');
699
- const positions = this.filterByArray(newPositions, 'symbol', symbols, false);
700
- if (!this.isEmpty(positions)) {
701
- client.resolve(positions, messageHash);
702
- }
703
- }
704
- client.resolve(newPositions, 'positions');
705
- }
706
- parseWsPosition(position, market = undefined) {
707
- //
708
- // {
709
- // "symbol":"LTCUSDT",
710
- // "hold_volume":"6",
711
- // "position_type":1,
712
- // "open_type":2,
713
- // "frozen_volume":"0",
714
- // "close_volume":"0",
715
- // "hold_avg_price":"71.681666666666666667",
716
- // "close_avg_price":"0",
717
- // "open_avg_price":"71.681666666666666667",
718
- // "liquidate_price":"0",
719
- // "create_time":1701621167225,
720
- // "update_time":1701628152614
721
- // }
722
- //
723
- const marketId = this.safeString(position, 'symbol');
724
- market = this.safeMarket(marketId, market, undefined, 'swap');
725
- const symbol = market['symbol'];
726
- const openTimestamp = this.safeInteger(position, 'create_time');
727
- const timestamp = this.safeInteger(position, 'update_time');
728
- const side = this.safeNumber(position, 'position_type');
729
- const marginModeId = this.safeNumber(position, 'open_type');
730
- return this.safePosition({
731
- 'info': position,
732
- 'id': undefined,
733
- 'symbol': symbol,
734
- 'timestamp': openTimestamp,
735
- 'datetime': this.iso8601(openTimestamp),
736
- 'lastUpdateTimestamp': timestamp,
737
- 'hedged': undefined,
738
- 'side': (side === 1) ? 'long' : 'short',
739
- 'contracts': this.safeNumber(position, 'hold_volume'),
740
- 'contractSize': this.safeNumber(market, 'contractSize'),
741
- 'entryPrice': this.safeNumber(position, 'open_avg_price'),
742
- 'markPrice': this.safeNumber(position, 'hold_avg_price'),
743
- 'lastPrice': undefined,
744
- 'notional': undefined,
745
- 'leverage': undefined,
746
- 'collateral': undefined,
747
- 'initialMargin': undefined,
748
- 'initialMarginPercentage': undefined,
749
- 'maintenanceMargin': undefined,
750
- 'maintenanceMarginPercentage': undefined,
751
- 'unrealizedPnl': undefined,
752
- 'realizedPnl': undefined,
753
- 'liquidationPrice': this.safeNumber(position, 'liquidate_price'),
754
- 'marginMode': (marginModeId === 1) ? 'isolated' : 'cross',
755
- 'percentage': undefined,
756
- 'marginRatio': undefined,
757
- 'stopLossPrice': undefined,
758
- 'takeProfitPrice': undefined,
759
- });
760
- }
761
- handleTrade(client, message) {
762
- //
763
- // spot
764
- // {
765
- // "table": "spot/trade",
766
- // "data": [
767
- // {
768
- // "price": "52700.50",
769
- // "s_t": 1630982050,
770
- // "side": "buy",
771
- // "size": "0.00112",
772
- // "symbol": "BTC_USDT"
773
- // },
774
- // ]
775
- // }
776
- //
777
- // swap
778
- // {
779
- // "group":"futures/trade:BTCUSDT",
780
- // "data":[
781
- // {
782
- // "trade_id":6798697637,
783
- // "contract_id":1,
784
- // "symbol":"BTCUSDT",
785
- // "deal_price":"39735.8",
786
- // "deal_vol":"2",
787
- // "type":0,
788
- // "way":1,
789
- // "create_time":1701618503,
790
- // "create_time_mill":1701618503517,
791
- // "created_at":"2023-12-03T15:48:23.517518538Z"
792
- // }
793
- // ]
794
- // }
795
- //
796
- const channel = this.safeString2(message, 'table', 'group');
797
- const isSpot = (channel.indexOf('spot') >= 0);
798
- const data = this.safeValue(message, 'data');
799
- if (data === undefined) {
800
- return;
801
- }
802
- let stored = undefined;
803
- for (let i = 0; i < data.length; i++) {
804
- const trade = this.parseWsTrade(data[i]);
805
- const symbol = trade['symbol'];
806
- const tradesLimit = this.safeInteger(this.options, 'tradesLimit', 1000);
807
- stored = this.safeValue(this.trades, symbol);
808
- if (stored === undefined) {
809
- stored = new Cache.ArrayCache(tradesLimit);
810
- this.trades[symbol] = stored;
811
- }
812
- stored.append(trade);
813
- }
814
- let messageHash = channel;
815
- if (isSpot) {
816
- messageHash += ':' + this.safeString(data[0], 'symbol');
817
- }
818
- client.resolve(stored, messageHash);
819
- return message;
820
- }
821
- parseWsTrade(trade, market = undefined) {
822
- // spot
823
- // {
824
- // "price": "52700.50",
825
- // "s_t": 1630982050,
826
- // "side": "buy",
827
- // "size": "0.00112",
828
- // "symbol": "BTC_USDT"
829
- // }
830
- // swap
831
- // {
832
- // "trade_id":6798697637,
833
- // "contract_id":1,
834
- // "symbol":"BTCUSDT",
835
- // "deal_price":"39735.8",
836
- // "deal_vol":"2",
837
- // "type":0,
838
- // "way":1,
839
- // "create_time":1701618503,
840
- // "create_time_mill":1701618503517,
841
- // "created_at":"2023-12-03T15:48:23.517518538Z"
842
- // }
843
- //
844
- const contractId = this.safeString(trade, 'contract_id');
845
- const marketType = (contractId === undefined) ? 'spot' : 'swap';
846
- const marketDelimiter = (marketType === 'spot') ? '_' : '';
847
- const timestamp = this.safeInteger(trade, 'create_time_mill', this.safeTimestamp(trade, 's_t'));
848
- const marketId = this.safeString(trade, 'symbol');
849
- return this.safeTrade({
850
- 'info': trade,
851
- 'id': this.safeString(trade, 'trade_id'),
852
- 'order': undefined,
853
- 'timestamp': timestamp,
854
- 'datetime': this.iso8601(timestamp),
855
- 'symbol': this.safeSymbol(marketId, market, marketDelimiter, marketType),
856
- 'type': undefined,
857
- 'side': this.safeString(trade, 'side'),
858
- 'price': this.safeString2(trade, 'price', 'deal_price'),
859
- 'amount': this.safeString2(trade, 'size', 'deal_vol'),
860
- 'cost': undefined,
861
- 'takerOrMaker': undefined,
862
- 'fee': undefined,
863
- }, market);
864
- }
865
- handleTicker(client, message) {
866
- //
867
- // {
868
- // "data": [
869
- // {
870
- // "base_volume_24h": "78615593.81",
871
- // "high_24h": "52756.97",
872
- // "last_price": "52638.31",
873
- // "low_24h": "50991.35",
874
- // "open_24h": "51692.03",
875
- // "s_t": 1630981727,
876
- // "symbol": "BTC_USDT"
877
- // }
878
- // ],
879
- // "table": "spot/ticker"
880
- // }
881
- // {
882
- // "group":"futures/ticker",
883
- // "data":{
884
- // "symbol":"BTCUSDT",
885
- // "volume_24":"117387.58",
886
- // "fair_price":"146.24",
887
- // "last_price":"146.24",
888
- // "range":"147.17",
889
- // "ask_price": "147.11",
890
- // "ask_vol": "1",
891
- // "bid_price": "142.11",
892
- // "bid_vol": "1"
893
- // }
894
- // }
895
- //
896
- const table = this.safeString(message, 'table');
897
- const isSpot = (table !== undefined);
898
- const data = this.safeValue(message, 'data');
899
- if (data === undefined) {
900
- return;
901
- }
902
- if (isSpot) {
903
- for (let i = 0; i < data.length; i++) {
904
- const ticker = this.parseTicker(data[i]);
905
- const symbol = ticker['symbol'];
906
- const marketId = this.safeString(ticker['info'], 'symbol');
907
- const messageHash = table + ':' + marketId;
908
- this.tickers[symbol] = ticker;
909
- client.resolve(ticker, messageHash);
910
- this.resolveMessageHashesForSymbol(client, symbol, ticker, 'tickers::');
911
- }
912
- }
913
- else {
914
- // on each update for contract markets, single ticker is provided
915
- const ticker = this.parseWsSwapTicker(data);
916
- const symbol = this.safeString(ticker, 'symbol');
917
- this.tickers[symbol] = ticker;
918
- client.resolve(ticker, 'tickers::swap');
919
- this.resolveMessageHashesForSymbol(client, symbol, ticker, 'tickers::');
920
- }
921
- return message;
922
- }
923
- resolveMessageHashesForSymbol(client, symbol, result, prexif) {
924
- const prefixSeparator = '::';
925
- const symbolsSeparator = ',';
926
- const messageHashes = this.findMessageHashes(client, prexif);
927
- for (let i = 0; i < messageHashes.length; i++) {
928
- const messageHash = messageHashes[i];
929
- const parts = messageHash.split(prefixSeparator);
930
- const length = parts.length;
931
- const symbolsString = parts[length - 1];
932
- const symbols = symbolsString.split(symbolsSeparator);
933
- if (this.inArray(symbol, symbols)) {
934
- const response = {};
935
- response[symbol] = result;
936
- client.resolve(response, messageHash);
937
- }
938
- }
939
- }
940
- parseWsSwapTicker(ticker, market = undefined) {
941
- //
942
- // {
943
- // "symbol":"BTCUSDT",
944
- // "volume_24":"117387.58",
945
- // "fair_price":"146.24",
946
- // "last_price":"146.24",
947
- // "range":"147.17",
948
- // "ask_price": "147.11",
949
- // "ask_vol": "1",
950
- // "bid_price": "142.11",
951
- // "bid_vol": "1"
952
- // }
953
- const marketId = this.safeString(ticker, 'symbol');
954
- return this.safeTicker({
955
- 'symbol': this.safeSymbol(marketId, market, '', 'swap'),
956
- 'timestamp': undefined,
957
- 'datetime': undefined,
958
- 'high': undefined,
959
- 'low': undefined,
960
- 'bid': this.safeString(ticker, 'bid_price'),
961
- 'bidVolume': this.safeString(ticker, 'bid_vol'),
962
- 'ask': this.safeString(ticker, 'ask_price'),
963
- 'askVolume': this.safeString(ticker, 'ask_vol'),
964
- 'vwap': undefined,
965
- 'open': undefined,
966
- 'close': undefined,
967
- 'last': this.safeString(ticker, 'last_price'),
968
- 'previousClose': undefined,
969
- 'change': undefined,
970
- 'percentage': undefined,
971
- 'average': this.safeString(ticker, 'fair_price'),
972
- 'baseVolume': undefined,
973
- 'quoteVolume': this.safeString(ticker, 'volume_24'),
974
- 'info': ticker,
975
- }, market);
976
- }
977
- async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
978
- /**
979
- * @method
980
- * @name bitmart#watchOHLCV
981
- * @see https://developer-pro.bitmart.com/en/spot/#public-kline-channel
982
- * @see https://developer-pro.bitmart.com/en/futures/#public-klinebin-channel
983
- * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
984
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
985
- * @param {string} timeframe the length of time each candle represents
986
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
987
- * @param {int} [limit] the maximum amount of candles to fetch
988
- * @param {object} [params] extra parameters specific to the exchange API endpoint
989
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
990
- */
991
- await this.loadMarkets();
992
- symbol = this.symbol(symbol);
993
- const market = this.market(symbol);
994
- let type = 'spot';
995
- [type, params] = this.handleMarketTypeAndParams('watchOrderBook', market, params);
996
- const timeframes = this.safeValue(this.options, 'timeframes', {});
997
- const interval = this.safeString(timeframes, timeframe);
998
- let name = undefined;
999
- if (type === 'spot') {
1000
- name = 'kline' + interval;
1001
- }
1002
- else {
1003
- name = 'klineBin' + interval;
1004
- }
1005
- const ohlcv = await this.subscribe(name, symbol, type, params);
1006
- if (this.newUpdates) {
1007
- limit = ohlcv.getLimit(symbol, limit);
1008
- }
1009
- return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
1010
- }
1011
- handleOHLCV(client, message) {
1012
- //
1013
- // {
1014
- // "data": [
1015
- // {
1016
- // "candle": [
1017
- // 1631056350,
1018
- // "46532.83",
1019
- // "46555.71",
1020
- // "46511.41",
1021
- // "46555.71",
1022
- // "0.25"
1023
- // ],
1024
- // "symbol": "BTC_USDT"
1025
- // }
1026
- // ],
1027
- // "table": "spot/kline1m"
1028
- // }
1029
- // swap
1030
- // {
1031
- // "group":"futures/klineBin1m:BTCUSDT",
1032
- // "data":{
1033
- // "symbol":"BTCUSDT",
1034
- // "items":[
1035
- // {
1036
- // "o":"39635.8",
1037
- // "h":"39636",
1038
- // "l":"39614.4",
1039
- // "c":"39629.7",
1040
- // "v":"31852",
1041
- // "ts":1701617761
1042
- // }
1043
- // ]
1044
- // }
1045
- // }
1046
- //
1047
- const channel = this.safeString2(message, 'table', 'group');
1048
- const isSpot = (channel.indexOf('spot') >= 0);
1049
- const data = this.safeValue(message, 'data');
1050
- if (data === undefined) {
1051
- return;
1052
- }
1053
- const parts = channel.split('/');
1054
- const part1 = this.safeString(parts, 1, '');
1055
- let interval = part1.replace('kline', '');
1056
- interval = interval.replace('Bin', '');
1057
- const intervalParts = interval.split(':');
1058
- interval = this.safeString(intervalParts, 0);
1059
- // use a reverse lookup in a static map instead
1060
- const timeframes = this.safeValue(this.options, 'timeframes', {});
1061
- const timeframe = this.findTimeframe(interval, timeframes);
1062
- const duration = this.parseTimeframe(timeframe);
1063
- const durationInMs = duration * 1000;
1064
- if (isSpot) {
1065
- for (let i = 0; i < data.length; i++) {
1066
- const marketId = this.safeString(data[i], 'symbol');
1067
- const market = this.safeMarket(marketId);
1068
- const symbol = market['symbol'];
1069
- const rawOHLCV = this.safeValue(data[i], 'candle');
1070
- const parsed = this.parseOHLCV(rawOHLCV, market);
1071
- parsed[0] = this.parseToInt(parsed[0] / durationInMs) * durationInMs;
1072
- this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
1073
- let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
1074
- if (stored === undefined) {
1075
- const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
1076
- stored = new Cache.ArrayCacheByTimestamp(limit);
1077
- this.ohlcvs[symbol][timeframe] = stored;
1078
- }
1079
- stored.append(parsed);
1080
- const messageHash = channel + ':' + marketId;
1081
- client.resolve(stored, messageHash);
1082
- }
1083
- }
1084
- else {
1085
- const marketId = this.safeString(data, 'symbol');
1086
- const market = this.safeMarket(marketId, undefined, undefined, 'swap');
1087
- const symbol = market['symbol'];
1088
- const items = this.safeValue(data, 'items', []);
1089
- this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
1090
- let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
1091
- if (stored === undefined) {
1092
- const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
1093
- stored = new Cache.ArrayCacheByTimestamp(limit);
1094
- this.ohlcvs[symbol][timeframe] = stored;
1095
- }
1096
- for (let i = 0; i < items.length; i++) {
1097
- const candle = items[i];
1098
- const parsed = this.parseOHLCV(candle, market);
1099
- stored.append(parsed);
1100
- }
1101
- client.resolve(stored, channel);
1102
- }
1103
- }
1104
- async watchOrderBook(symbol, limit = undefined, params = {}) {
1105
- /**
1106
- * @method
1107
- * @name bitmart#watchOrderBook
1108
- * @see https://developer-pro.bitmart.com/en/spot/#public-depth-all-channel
1109
- * @see https://developer-pro.bitmart.com/en/spot/#public-depth-increase-channel
1110
- * @see https://developer-pro.bitmart.com/en/futures/#public-depth-channel
1111
- * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1112
- * @param {string} symbol unified symbol of the market to fetch the order book for
1113
- * @param {int} [limit] the maximum amount of order book entries to return
1114
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1115
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1116
- */
1117
- await this.loadMarkets();
1118
- const options = this.safeValue(this.options, 'watchOrderBook', {});
1119
- let depth = this.safeString(options, 'depth', 'depth/increase100');
1120
- symbol = this.symbol(symbol);
1121
- const market = this.market(symbol);
1122
- let type = 'spot';
1123
- [type, params] = this.handleMarketTypeAndParams('watchOrderBook', market, params);
1124
- if (type === 'swap' && depth === 'depth/increase100') {
1125
- depth = 'depth50';
1126
- }
1127
- const orderbook = await this.subscribe(depth, symbol, type, params);
1128
- return orderbook.limit();
1129
- }
1130
- handleDelta(bookside, delta) {
1131
- const price = this.safeFloat(delta, 0);
1132
- const amount = this.safeFloat(delta, 1);
1133
- bookside.store(price, amount);
1134
- }
1135
- handleDeltas(bookside, deltas) {
1136
- for (let i = 0; i < deltas.length; i++) {
1137
- this.handleDelta(bookside, deltas[i]);
1138
- }
1139
- }
1140
- handleOrderBookMessage(client, message, orderbook) {
1141
- //
1142
- // {
1143
- // "asks": [
1144
- // [ '46828.38', "0.21847" ],
1145
- // [ '46830.68', "0.08232" ],
1146
- // [ '46832.08', "0.09285" ],
1147
- // [ '46837.82', "0.02028" ],
1148
- // [ '46839.43', "0.15068" ]
1149
- // ],
1150
- // "bids": [
1151
- // [ '46820.78', "0.00444" ],
1152
- // [ '46814.33', "0.00234" ],
1153
- // [ '46813.50', "0.05021" ],
1154
- // [ '46808.14', "0.00217" ],
1155
- // [ '46808.04', "0.00013" ]
1156
- // ],
1157
- // "ms_t": 1631044962431,
1158
- // "symbol": "BTC_USDT"
1159
- // }
1160
- //
1161
- const asks = this.safeValue(message, 'asks', []);
1162
- const bids = this.safeValue(message, 'bids', []);
1163
- this.handleDeltas(orderbook['asks'], asks);
1164
- this.handleDeltas(orderbook['bids'], bids);
1165
- const timestamp = this.safeInteger(message, 'ms_t');
1166
- const marketId = this.safeString(message, 'symbol');
1167
- const symbol = this.safeSymbol(marketId);
1168
- orderbook['symbol'] = symbol;
1169
- orderbook['timestamp'] = timestamp;
1170
- orderbook['datetime'] = this.iso8601(timestamp);
1171
- return orderbook;
1172
- }
1173
- handleOrderBook(client, message) {
1174
- //
1175
- // spot depth-all
1176
- // {
1177
- // "data": [
1178
- // {
1179
- // "asks": [
1180
- // [ '46828.38', "0.21847" ],
1181
- // [ '46830.68', "0.08232" ],
1182
- // ...
1183
- // ],
1184
- // "bids": [
1185
- // [ '46820.78', "0.00444" ],
1186
- // [ '46814.33', "0.00234" ],
1187
- // ...
1188
- // ],
1189
- // "ms_t": 1631044962431,
1190
- // "symbol": "BTC_USDT"
1191
- // }
1192
- // ],
1193
- // "table": "spot/depth5"
1194
- // }
1195
- // spot increse depth snapshot
1196
- // {
1197
- // "data":[
1198
- // {
1199
- // "asks":[
1200
- // [
1201
- // "43652.52",
1202
- // "0.02039"
1203
- // ],
1204
- // ...
1205
- // ],
1206
- // "bids":[
1207
- // [
1208
- // "43652.51",
1209
- // "0.00500"
1210
- // ],
1211
- // ...
1212
- // ],
1213
- // "ms_t":1703376836487,
1214
- // "symbol":"BTC_USDT",
1215
- // "type":"snapshot", // or update
1216
- // "version":2141731
1217
- // }
1218
- // ],
1219
- // "table":"spot/depth/increase100"
1220
- // }
1221
- // swap
1222
- // {
1223
- // "group":"futures/depth50:BTCUSDT",
1224
- // "data":{
1225
- // "symbol":"BTCUSDT",
1226
- // "way":1,
1227
- // "depths":[
1228
- // {
1229
- // "price":"39509.8",
1230
- // "vol":"2379"
1231
- // },
1232
- // {
1233
- // "price":"39509.6",
1234
- // "vol":"6815"
1235
- // },
1236
- // ...
1237
- // ],
1238
- // "ms_t":1701566021194
1239
- // }
1240
- // }
1241
- //
1242
- const data = this.safeValue(message, 'data');
1243
- if (data === undefined) {
1244
- return;
1245
- }
1246
- const depths = this.safeValue(data, 'depths');
1247
- const isSpot = (depths === undefined);
1248
- const table = this.safeString2(message, 'table', 'group');
1249
- // find limit subscribed to
1250
- const limitsToCheck = ['100', '50', '20', '10', '5'];
1251
- let limit = 0;
1252
- for (let i = 0; i < limitsToCheck.length; i++) {
1253
- const limitString = limitsToCheck[i];
1254
- if (table.indexOf(limitString) >= 0) {
1255
- limit = this.parseToInt(limitString);
1256
- break;
1257
- }
1258
- }
1259
- if (isSpot) {
1260
- for (let i = 0; i < data.length; i++) {
1261
- const update = data[i];
1262
- const marketId = this.safeString(update, 'symbol');
1263
- const symbol = this.safeSymbol(marketId);
1264
- let orderbook = this.safeValue(this.orderbooks, symbol);
1265
- if (orderbook === undefined) {
1266
- orderbook = this.orderBook({}, limit);
1267
- orderbook['symbol'] = symbol;
1268
- this.orderbooks[symbol] = orderbook;
1269
- }
1270
- const type = this.safeValue(update, 'type');
1271
- if ((type === 'snapshot') || (!(table.indexOf('increase') >= 0))) {
1272
- orderbook.reset({});
1273
- }
1274
- this.handleOrderBookMessage(client, update, orderbook);
1275
- const timestamp = this.safeInteger(update, 'ms_t');
1276
- orderbook['timestamp'] = timestamp;
1277
- orderbook['datetime'] = this.iso8601(timestamp);
1278
- const messageHash = table + ':' + marketId;
1279
- client.resolve(orderbook, messageHash);
1280
- }
1281
- }
1282
- else {
1283
- const marketId = this.safeString(data, 'symbol');
1284
- const symbol = this.safeSymbol(marketId);
1285
- let orderbook = this.safeValue(this.orderbooks, symbol);
1286
- if (orderbook === undefined) {
1287
- orderbook = this.orderBook({}, limit);
1288
- orderbook['symbol'] = symbol;
1289
- this.orderbooks[symbol] = orderbook;
1290
- }
1291
- const way = this.safeNumber(data, 'way');
1292
- const side = (way === 1) ? 'bids' : 'asks';
1293
- if (way === 1) {
1294
- orderbook[side] = new OrderBookSide.Bids([], limit);
1295
- }
1296
- else {
1297
- orderbook[side] = new OrderBookSide.Asks([], limit);
1298
- }
1299
- for (let i = 0; i < depths.length; i++) {
1300
- const depth = depths[i];
1301
- const price = this.safeNumber(depth, 'price');
1302
- const amount = this.safeNumber(depth, 'vol');
1303
- const orderbookSide = this.safeValue(orderbook, side);
1304
- orderbookSide.store(price, amount);
1305
- }
1306
- const bidsLength = orderbook['bids'].length;
1307
- const asksLength = orderbook['asks'].length;
1308
- if ((bidsLength === 0) || (asksLength === 0)) {
1309
- return;
1310
- }
1311
- const timestamp = this.safeInteger(data, 'ms_t');
1312
- orderbook['timestamp'] = timestamp;
1313
- orderbook['datetime'] = this.iso8601(timestamp);
1314
- const messageHash = table;
1315
- client.resolve(orderbook, messageHash);
1316
- }
1317
- }
1318
- async authenticate(type, params = {}) {
1319
- this.checkRequiredCredentials();
1320
- const url = this.implodeHostname(this.urls['api']['ws'][type]['private']);
1321
- const messageHash = 'authenticated';
1322
- const client = this.client(url);
1323
- const future = client.future(messageHash);
1324
- const authenticated = this.safeValue(client.subscriptions, messageHash);
1325
- if (authenticated === undefined) {
1326
- const timestamp = this.milliseconds().toString();
1327
- const memo = this.uid;
1328
- const path = 'bitmart.WebSocket';
1329
- const auth = timestamp + '#' + memo + '#' + path;
1330
- const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
1331
- let request = undefined;
1332
- if (type === 'spot') {
1333
- request = {
1334
- 'op': 'login',
1335
- 'args': [
1336
- this.apiKey,
1337
- timestamp,
1338
- signature,
1339
- ],
1340
- };
1341
- }
1342
- else {
1343
- request = {
1344
- 'action': 'access',
1345
- 'args': [
1346
- this.apiKey,
1347
- timestamp,
1348
- signature,
1349
- 'web',
1350
- ],
1351
- };
1352
- }
1353
- const message = this.extend(request, params);
1354
- this.watch(url, messageHash, message, messageHash);
1355
- }
1356
- return future;
1357
- }
1358
- handleSubscriptionStatus(client, message) {
1359
- //
1360
- // {"event":"subscribe","channel":"spot/depth:BTC-USDT"}
1361
- //
1362
- return message;
1363
- }
1364
- handleAuthenticate(client, message) {
1365
- //
1366
- // spot
1367
- // { event: "login" }
1368
- // swap
1369
- // { action: 'access', success: true }
1370
- //
1371
- const messageHash = 'authenticated';
1372
- const future = this.safeValue(client.futures, messageHash);
1373
- future.resolve(true);
1374
- }
1375
- handleErrorMessage(client, message) {
1376
- //
1377
- // { event: "error", message: "Invalid sign", errorCode: 30013 }
1378
- // {"event":"error","message":"Unrecognized request: {\"event\":\"subscribe\",\"channel\":\"spot/depth:BTC-USDT\"}","errorCode":30039}
1379
- // {
1380
- // action: '',
1381
- // group: 'futures/trade:BTCUSDT',
1382
- // success: false,
1383
- // request: { action: '', args: [ 'futures/trade:BTCUSDT' ] },
1384
- // error: 'Invalid action [] for group [futures/trade:BTCUSDT]'
1385
- // }
1386
- //
1387
- const errorCode = this.safeString(message, 'errorCode');
1388
- const error = this.safeString(message, 'error');
1389
- try {
1390
- if (errorCode !== undefined || error !== undefined) {
1391
- const feedback = this.id + ' ' + this.json(message);
1392
- this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
1393
- const messageString = this.safeValue(message, 'message', error);
1394
- this.throwBroadlyMatchedException(this.exceptions['broad'], messageString, feedback);
1395
- const action = this.safeString(message, 'action');
1396
- if (action === 'access') {
1397
- throw new errors.AuthenticationError(feedback);
1398
- }
1399
- throw new errors.ExchangeError(feedback);
1400
- }
1401
- return false;
1402
- }
1403
- catch (e) {
1404
- if ((e instanceof errors.AuthenticationError)) {
1405
- const messageHash = 'authenticated';
1406
- client.reject(e, messageHash);
1407
- if (messageHash in client.subscriptions) {
1408
- delete client.subscriptions[messageHash];
1409
- }
1410
- }
1411
- client.reject(e);
1412
- return true;
1413
- }
1414
- }
1415
- handleMessage(client, message) {
1416
- if (this.handleErrorMessage(client, message)) {
1417
- return;
1418
- }
1419
- //
1420
- // {"event":"error","message":"Unrecognized request: {\"event\":\"subscribe\",\"channel\":\"spot/depth:BTC-USDT\"}","errorCode":30039}
1421
- // {"event":"subscribe","channel":"spot/depth:BTC-USDT"}
1422
- // {
1423
- // "table": "spot/depth",
1424
- // "action": "partial",
1425
- // "data": [
1426
- // {
1427
- // "instrument_id": "BTC-USDT",
1428
- // "asks": [
1429
- // ["5301.8", "0.03763319", "1"],
1430
- // ["5302.4", "0.00305", "2"],
1431
- // ],
1432
- // "bids": [
1433
- // ["5301.7", "0.58911427", "6"],
1434
- // ["5301.6", "0.01222922", "4"],
1435
- // ],
1436
- // "timestamp": "2020-03-16T03:25:00.440Z",
1437
- // "checksum": -2088736623
1438
- // }
1439
- // ]
1440
- // }
1441
- //
1442
- // { data: '', table: "spot/user/order" }
1443
- //
1444
- const channel = this.safeString2(message, 'table', 'group');
1445
- if (channel === undefined) {
1446
- const event = this.safeString2(message, 'event', 'action');
1447
- if (event !== undefined) {
1448
- const methods = {
1449
- // 'info': this.handleSystemStatus,
1450
- 'login': this.handleAuthenticate,
1451
- 'access': this.handleAuthenticate,
1452
- 'subscribe': this.handleSubscriptionStatus,
1453
- };
1454
- const method = this.safeValue(methods, event);
1455
- if (method === undefined) {
1456
- return message;
1457
- }
1458
- else {
1459
- return method.call(this, client, message);
1460
- }
1461
- }
1462
- }
1463
- else {
1464
- const methods = {
1465
- 'depth': this.handleOrderBook,
1466
- 'ticker': this.handleTicker,
1467
- 'trade': this.handleTrade,
1468
- 'kline': this.handleOHLCV,
1469
- 'order': this.handleOrders,
1470
- 'position': this.handlePositions,
1471
- 'balance': this.handleBalance,
1472
- 'asset': this.handleBalance,
1473
- };
1474
- const keys = Object.keys(methods);
1475
- for (let i = 0; i < keys.length; i++) {
1476
- const key = keys[i];
1477
- if (channel.indexOf(key) >= 0) {
1478
- const method = this.safeValue(methods, key);
1479
- return method.call(this, client, message);
1480
- }
1481
- }
1482
- }
1483
- }
1484
- }
1485
-
1486
- module.exports = bitmart;