ccxt 4.2.10 → 4.2.12

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 (383) hide show
  1. package/README.md +5 -5
  2. package/build.sh +4 -4
  3. package/dist/ccxt.browser.js +695 -282
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/_virtual/agent.js +7 -0
  6. package/dist/cjs/_virtual/parse-proxy-response.js +7 -0
  7. package/dist/cjs/_virtual/promisify.js +7 -0
  8. package/dist/cjs/ccxt.js +1 -1
  9. package/dist/cjs/js/ccxt.js +474 -0
  10. package/dist/cjs/js/src/abstract/ace.js +9 -0
  11. package/dist/cjs/js/src/abstract/alpaca.js +9 -0
  12. package/dist/cjs/js/src/abstract/ascendex.js +9 -0
  13. package/dist/cjs/js/src/abstract/bigone.js +9 -0
  14. package/dist/cjs/js/src/abstract/binance.js +9 -0
  15. package/dist/cjs/js/src/abstract/bingx.js +9 -0
  16. package/dist/cjs/js/src/abstract/bit2c.js +9 -0
  17. package/dist/cjs/js/src/abstract/bitbank.js +9 -0
  18. package/dist/cjs/js/src/abstract/bitbns.js +9 -0
  19. package/dist/cjs/js/src/abstract/bitfinex.js +9 -0
  20. package/dist/cjs/js/src/abstract/bitfinex2.js +9 -0
  21. package/dist/cjs/js/src/abstract/bitflyer.js +9 -0
  22. package/dist/cjs/js/src/abstract/bitforex.js +9 -0
  23. package/dist/cjs/js/src/abstract/bitget.js +9 -0
  24. package/dist/cjs/js/src/abstract/bithumb.js +9 -0
  25. package/dist/cjs/js/src/abstract/bitmart.js +9 -0
  26. package/dist/cjs/js/src/abstract/bitmex.js +9 -0
  27. package/dist/cjs/js/src/abstract/bitopro.js +9 -0
  28. package/dist/cjs/js/src/abstract/bitpanda.js +9 -0
  29. package/dist/cjs/js/src/abstract/bitrue.js +9 -0
  30. package/dist/cjs/js/src/abstract/bitso.js +9 -0
  31. package/dist/cjs/js/src/abstract/bitstamp.js +9 -0
  32. package/dist/cjs/js/src/abstract/bitteam.js +9 -0
  33. package/dist/cjs/js/src/abstract/bitvavo.js +9 -0
  34. package/dist/cjs/js/src/abstract/bl3p.js +9 -0
  35. package/dist/cjs/js/src/abstract/blockchaincom.js +9 -0
  36. package/dist/cjs/js/src/abstract/btcalpha.js +9 -0
  37. package/dist/cjs/js/src/abstract/btcbox.js +9 -0
  38. package/dist/cjs/js/src/abstract/btcmarkets.js +9 -0
  39. package/dist/cjs/js/src/abstract/btcturk.js +9 -0
  40. package/dist/cjs/js/src/abstract/bybit.js +9 -0
  41. package/dist/cjs/js/src/abstract/cex.js +9 -0
  42. package/dist/cjs/js/src/abstract/coinbase.js +9 -0
  43. package/dist/cjs/js/src/abstract/coinbasepro.js +9 -0
  44. package/dist/cjs/js/src/abstract/coincheck.js +9 -0
  45. package/dist/cjs/js/src/abstract/coinex.js +9 -0
  46. package/dist/cjs/js/src/abstract/coinlist.js +9 -0
  47. package/dist/cjs/js/src/abstract/coinmate.js +9 -0
  48. package/dist/cjs/js/src/abstract/coinone.js +9 -0
  49. package/dist/cjs/js/src/abstract/coinsph.js +9 -0
  50. package/dist/cjs/js/src/abstract/coinspot.js +9 -0
  51. package/dist/cjs/js/src/abstract/cryptocom.js +9 -0
  52. package/dist/cjs/js/src/abstract/currencycom.js +9 -0
  53. package/dist/cjs/js/src/abstract/delta.js +9 -0
  54. package/dist/cjs/js/src/abstract/deribit.js +9 -0
  55. package/dist/cjs/js/src/abstract/digifinex.js +9 -0
  56. package/dist/cjs/js/src/abstract/exmo.js +9 -0
  57. package/dist/cjs/js/src/abstract/gate.js +9 -0
  58. package/dist/cjs/js/src/abstract/gemini.js +9 -0
  59. package/dist/cjs/js/src/abstract/hitbtc.js +9 -0
  60. package/dist/cjs/js/src/abstract/hollaex.js +9 -0
  61. package/dist/cjs/js/src/abstract/htx.js +9 -0
  62. package/dist/cjs/js/src/abstract/huobijp.js +9 -0
  63. package/dist/cjs/js/src/abstract/idex.js +9 -0
  64. package/dist/cjs/js/src/abstract/independentreserve.js +9 -0
  65. package/dist/cjs/js/src/abstract/indodax.js +9 -0
  66. package/dist/cjs/js/src/abstract/kraken.js +9 -0
  67. package/dist/cjs/js/src/abstract/krakenfutures.js +9 -0
  68. package/dist/cjs/js/src/abstract/kucoin.js +9 -0
  69. package/dist/cjs/js/src/abstract/kucoinfutures.js +9 -0
  70. package/dist/cjs/js/src/abstract/kuna.js +9 -0
  71. package/dist/cjs/js/src/abstract/latoken.js +9 -0
  72. package/dist/cjs/js/src/abstract/lbank.js +9 -0
  73. package/dist/cjs/js/src/abstract/luno.js +9 -0
  74. package/dist/cjs/js/src/abstract/lykke.js +9 -0
  75. package/dist/cjs/js/src/abstract/mercado.js +9 -0
  76. package/dist/cjs/js/src/abstract/mexc.js +9 -0
  77. package/dist/cjs/js/src/abstract/ndax.js +9 -0
  78. package/dist/cjs/js/src/abstract/novadax.js +9 -0
  79. package/dist/cjs/js/src/abstract/oceanex.js +9 -0
  80. package/dist/cjs/js/src/abstract/okcoin.js +9 -0
  81. package/dist/cjs/js/src/abstract/okx.js +9 -0
  82. package/dist/cjs/js/src/abstract/p2b.js +9 -0
  83. package/dist/cjs/js/src/abstract/paymium.js +9 -0
  84. package/dist/cjs/js/src/abstract/phemex.js +9 -0
  85. package/dist/cjs/js/src/abstract/poloniex.js +9 -0
  86. package/dist/cjs/js/src/abstract/poloniexfutures.js +9 -0
  87. package/dist/cjs/js/src/abstract/probit.js +9 -0
  88. package/dist/cjs/js/src/abstract/timex.js +9 -0
  89. package/dist/cjs/js/src/abstract/tokocrypto.js +9 -0
  90. package/dist/cjs/js/src/abstract/upbit.js +9 -0
  91. package/dist/cjs/js/src/abstract/wavesexchange.js +9 -0
  92. package/dist/cjs/js/src/abstract/wazirx.js +9 -0
  93. package/dist/cjs/js/src/abstract/whitebit.js +9 -0
  94. package/dist/cjs/js/src/abstract/woo.js +9 -0
  95. package/dist/cjs/js/src/abstract/yobit.js +9 -0
  96. package/dist/cjs/js/src/abstract/zaif.js +9 -0
  97. package/dist/cjs/js/src/abstract/zonda.js +9 -0
  98. package/dist/cjs/js/src/ace.js +1058 -0
  99. package/dist/cjs/js/src/alpaca.js +1125 -0
  100. package/dist/cjs/js/src/ascendex.js +3360 -0
  101. package/dist/cjs/js/src/base/Exchange.js +5110 -0
  102. package/dist/cjs/js/src/base/Precise.js +263 -0
  103. package/dist/cjs/js/src/base/errors.js +299 -0
  104. package/dist/cjs/js/src/base/functions/crypto.js +78 -0
  105. package/dist/cjs/js/src/base/functions/encode.js +44 -0
  106. package/dist/cjs/js/src/base/functions/generic.js +193 -0
  107. package/dist/cjs/js/src/base/functions/misc.js +96 -0
  108. package/dist/cjs/js/src/base/functions/number.js +297 -0
  109. package/dist/cjs/js/src/base/functions/platform.js +28 -0
  110. package/dist/cjs/js/src/base/functions/rsa.js +34 -0
  111. package/dist/cjs/js/src/base/functions/string.js +48 -0
  112. package/dist/cjs/js/src/base/functions/throttle.js +66 -0
  113. package/dist/cjs/js/src/base/functions/time.js +187 -0
  114. package/dist/cjs/js/src/base/functions/totp.js +24 -0
  115. package/dist/cjs/js/src/base/functions/type.js +162 -0
  116. package/dist/cjs/js/src/base/functions.js +157 -0
  117. package/dist/cjs/js/src/base/ws/Cache.js +254 -0
  118. package/dist/cjs/js/src/base/ws/Client.js +299 -0
  119. package/dist/cjs/js/src/base/ws/Future.js +34 -0
  120. package/dist/cjs/js/src/base/ws/OrderBook.js +107 -0
  121. package/dist/cjs/js/src/base/ws/OrderBookSide.js +281 -0
  122. package/dist/cjs/js/src/base/ws/WsClient.js +69 -0
  123. package/dist/cjs/js/src/bequant.js +33 -0
  124. package/dist/cjs/js/src/bigone.js +2142 -0
  125. package/dist/cjs/js/src/binance.js +9729 -0
  126. package/dist/cjs/js/src/binancecoinm.js +45 -0
  127. package/dist/cjs/js/src/binanceus.js +84 -0
  128. package/dist/cjs/js/src/binanceusdm.js +58 -0
  129. package/dist/cjs/js/src/bingx.js +3737 -0
  130. package/dist/cjs/js/src/bit2c.js +916 -0
  131. package/dist/cjs/js/src/bitbank.js +1000 -0
  132. package/dist/cjs/js/src/bitbay.js +17 -0
  133. package/dist/cjs/js/src/bitbns.js +1220 -0
  134. package/dist/cjs/js/src/bitcoincom.js +17 -0
  135. package/dist/cjs/js/src/bitfinex.js +1670 -0
  136. package/dist/cjs/js/src/bitfinex2.js +2990 -0
  137. package/dist/cjs/js/src/bitflyer.js +1045 -0
  138. package/dist/cjs/js/src/bitforex.js +852 -0
  139. package/dist/cjs/js/src/bitget.js +8284 -0
  140. package/dist/cjs/js/src/bithumb.js +1090 -0
  141. package/dist/cjs/js/src/bitmart.js +4454 -0
  142. package/dist/cjs/js/src/bitmex.js +2884 -0
  143. package/dist/cjs/js/src/bitopro.js +1724 -0
  144. package/dist/cjs/js/src/bitpanda.js +2002 -0
  145. package/dist/cjs/js/src/bitrue.js +3253 -0
  146. package/dist/cjs/js/src/bitso.js +1753 -0
  147. package/dist/cjs/js/src/bitstamp.js +2188 -0
  148. package/dist/cjs/js/src/bitteam.js +2309 -0
  149. package/dist/cjs/js/src/bitvavo.js +1968 -0
  150. package/dist/cjs/js/src/bl3p.js +447 -0
  151. package/dist/cjs/js/src/blockchaincom.js +1160 -0
  152. package/dist/cjs/js/src/btcalpha.js +929 -0
  153. package/dist/cjs/js/src/btcbox.js +565 -0
  154. package/dist/cjs/js/src/btcmarkets.js +1237 -0
  155. package/dist/cjs/js/src/btcturk.js +929 -0
  156. package/dist/cjs/js/src/bybit.js +7646 -0
  157. package/dist/cjs/js/src/cex.js +1693 -0
  158. package/dist/cjs/js/src/coinbase.js +3274 -0
  159. package/dist/cjs/js/src/coinbasepro.js +1866 -0
  160. package/dist/cjs/js/src/coincheck.js +843 -0
  161. package/dist/cjs/js/src/coinex.js +5414 -0
  162. package/dist/cjs/js/src/coinlist.js +2329 -0
  163. package/dist/cjs/js/src/coinmate.js +989 -0
  164. package/dist/cjs/js/src/coinone.js +1185 -0
  165. package/dist/cjs/js/src/coinsph.js +1933 -0
  166. package/dist/cjs/js/src/coinspot.js +548 -0
  167. package/dist/cjs/js/src/cryptocom.js +3007 -0
  168. package/dist/cjs/js/src/currencycom.js +2015 -0
  169. package/dist/cjs/js/src/delta.js +3256 -0
  170. package/dist/cjs/js/src/deribit.js +3306 -0
  171. package/dist/cjs/js/src/digifinex.js +4307 -0
  172. package/dist/cjs/js/src/exmo.js +2645 -0
  173. package/dist/cjs/js/src/fmfwio.js +34 -0
  174. package/dist/cjs/js/src/gate.js +7054 -0
  175. package/dist/cjs/js/src/gateio.js +16 -0
  176. package/dist/cjs/js/src/gemini.js +1801 -0
  177. package/dist/cjs/js/src/hitbtc.js +3660 -0
  178. package/dist/cjs/js/src/hitbtc3.js +19 -0
  179. package/dist/cjs/js/src/hollaex.js +1882 -0
  180. package/dist/cjs/js/src/htx.js +9024 -0
  181. package/dist/cjs/js/src/huobi.js +16 -0
  182. package/dist/cjs/js/src/huobijp.js +1918 -0
  183. package/dist/cjs/js/src/idex.js +1770 -0
  184. package/dist/cjs/js/src/independentreserve.js +759 -0
  185. package/dist/cjs/js/src/indodax.js +1069 -0
  186. package/dist/cjs/js/src/kraken.js +2861 -0
  187. package/dist/cjs/js/src/krakenfutures.js +2407 -0
  188. package/dist/cjs/js/src/kucoin.js +4489 -0
  189. package/dist/cjs/js/src/kucoinfutures.js +2475 -0
  190. package/dist/cjs/js/src/kuna.js +1949 -0
  191. package/dist/cjs/js/src/latoken.js +1729 -0
  192. package/dist/cjs/js/src/lbank.js +2825 -0
  193. package/dist/cjs/js/src/luno.js +1044 -0
  194. package/dist/cjs/js/src/lykke.js +1303 -0
  195. package/dist/cjs/js/src/mercado.js +897 -0
  196. package/dist/cjs/js/src/mexc.js +5407 -0
  197. package/dist/cjs/js/src/ndax.js +2450 -0
  198. package/dist/cjs/js/src/novadax.js +1556 -0
  199. package/dist/cjs/js/src/oceanex.js +964 -0
  200. package/dist/cjs/js/src/okcoin.js +3115 -0
  201. package/dist/cjs/js/src/okx.js +7329 -0
  202. package/dist/cjs/js/src/p2b.js +1243 -0
  203. package/dist/cjs/js/src/paymium.js +597 -0
  204. package/dist/cjs/js/src/phemex.js +4715 -0
  205. package/dist/cjs/js/src/poloniex.js +2356 -0
  206. package/dist/cjs/js/src/poloniexfutures.js +1794 -0
  207. package/dist/cjs/js/src/pro/alpaca.js +714 -0
  208. package/dist/cjs/js/src/pro/ascendex.js +957 -0
  209. package/dist/cjs/js/src/pro/bequant.js +33 -0
  210. package/dist/cjs/js/src/pro/binance.js +2796 -0
  211. package/dist/cjs/js/src/pro/binancecoinm.js +23 -0
  212. package/dist/cjs/js/src/pro/binanceus.js +51 -0
  213. package/dist/cjs/js/src/pro/binanceusdm.js +32 -0
  214. package/dist/cjs/js/src/pro/bingx.js +944 -0
  215. package/dist/cjs/js/src/pro/bitcoincom.js +29 -0
  216. package/dist/cjs/js/src/pro/bitfinex.js +672 -0
  217. package/dist/cjs/js/src/pro/bitfinex2.js +1159 -0
  218. package/dist/cjs/js/src/pro/bitget.js +1733 -0
  219. package/dist/cjs/js/src/pro/bitmart.js +1486 -0
  220. package/dist/cjs/js/src/pro/bitmex.js +1576 -0
  221. package/dist/cjs/js/src/pro/bitopro.js +327 -0
  222. package/dist/cjs/js/src/pro/bitpanda.js +1341 -0
  223. package/dist/cjs/js/src/pro/bitrue.js +462 -0
  224. package/dist/cjs/js/src/pro/bitstamp.js +547 -0
  225. package/dist/cjs/js/src/pro/bitvavo.js +704 -0
  226. package/dist/cjs/js/src/pro/blockchaincom.js +794 -0
  227. package/dist/cjs/js/src/pro/bybit.js +1843 -0
  228. package/dist/cjs/js/src/pro/cex.js +1510 -0
  229. package/dist/cjs/js/src/pro/coinbase.js +561 -0
  230. package/dist/cjs/js/src/pro/coinbasepro.js +968 -0
  231. package/dist/cjs/js/src/pro/coinex.js +1095 -0
  232. package/dist/cjs/js/src/pro/cryptocom.js +1020 -0
  233. package/dist/cjs/js/src/pro/currencycom.js +563 -0
  234. package/dist/cjs/js/src/pro/deribit.js +825 -0
  235. package/dist/cjs/js/src/pro/exmo.js +658 -0
  236. package/dist/cjs/js/src/pro/gate.js +1316 -0
  237. package/dist/cjs/js/src/pro/gateio.js +16 -0
  238. package/dist/cjs/js/src/pro/gemini.js +649 -0
  239. package/dist/cjs/js/src/pro/hitbtc.js +1293 -0
  240. package/dist/cjs/js/src/pro/hollaex.js +597 -0
  241. package/dist/cjs/js/src/pro/htx.js +2383 -0
  242. package/dist/cjs/js/src/pro/huobi.js +16 -0
  243. package/dist/cjs/js/src/pro/huobijp.js +606 -0
  244. package/dist/cjs/js/src/pro/idex.js +714 -0
  245. package/dist/cjs/js/src/pro/independentreserve.js +280 -0
  246. package/dist/cjs/js/src/pro/kraken.js +1364 -0
  247. package/dist/cjs/js/src/pro/krakenfutures.js +1500 -0
  248. package/dist/cjs/js/src/pro/kucoin.js +1052 -0
  249. package/dist/cjs/js/src/pro/kucoinfutures.js +981 -0
  250. package/dist/cjs/js/src/pro/luno.js +322 -0
  251. package/dist/cjs/js/src/pro/mexc.js +1170 -0
  252. package/dist/cjs/js/src/pro/ndax.js +545 -0
  253. package/dist/cjs/js/src/pro/okcoin.js +760 -0
  254. package/dist/cjs/js/src/pro/okx.js +1558 -0
  255. package/dist/cjs/js/src/pro/phemex.js +1511 -0
  256. package/dist/cjs/js/src/pro/poloniex.js +1253 -0
  257. package/dist/cjs/js/src/pro/poloniexfutures.js +1014 -0
  258. package/dist/cjs/js/src/pro/probit.js +586 -0
  259. package/dist/cjs/js/src/pro/upbit.js +234 -0
  260. package/dist/cjs/js/src/pro/wazirx.js +776 -0
  261. package/dist/cjs/js/src/pro/whitebit.js +927 -0
  262. package/dist/cjs/js/src/pro/woo.js +769 -0
  263. package/dist/cjs/js/src/probit.js +1865 -0
  264. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +401 -0
  265. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +195 -0
  266. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +308 -0
  267. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +554 -0
  268. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +94 -0
  269. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +70 -0
  270. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +91 -0
  271. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +16 -0
  272. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +1760 -0
  273. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +52 -0
  274. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +81 -0
  275. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +376 -0
  276. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +70 -0
  277. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +1580 -0
  278. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +74 -0
  279. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +24 -0
  280. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +158 -0
  281. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +429 -0
  282. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +176 -0
  283. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +324 -0
  284. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +163 -0
  285. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +245 -0
  286. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1018 -0
  287. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +383 -0
  288. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +258 -0
  289. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +53 -0
  290. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +120 -0
  291. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +69 -0
  292. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +7 -0
  293. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +83 -0
  294. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +240 -0
  295. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +91 -0
  296. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +130 -0
  297. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +214 -0
  298. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +239 -0
  299. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +93 -0
  300. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +354 -0
  301. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +16 -0
  302. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +20 -0
  303. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +30 -0
  304. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +239 -0
  305. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +372 -0
  306. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +273 -0
  307. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +139 -0
  308. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +14 -0
  309. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +16 -0
  310. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +81 -0
  311. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +292 -0
  312. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +103 -0
  313. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +140 -0
  314. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +175 -0
  315. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +95 -0
  316. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +7 -0
  317. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +383 -0
  318. package/dist/cjs/js/src/timex.js +1562 -0
  319. package/dist/cjs/js/src/tokocrypto.js +2542 -0
  320. package/dist/cjs/js/src/upbit.js +1844 -0
  321. package/dist/cjs/js/src/wavesexchange.js +2607 -0
  322. package/dist/cjs/js/src/wazirx.js +953 -0
  323. package/dist/cjs/js/src/whitebit.js +2309 -0
  324. package/dist/cjs/js/src/woo.js +2715 -0
  325. package/dist/cjs/js/src/yobit.js +1314 -0
  326. package/dist/cjs/js/src/zaif.js +736 -0
  327. package/dist/cjs/js/src/zonda.js +1883 -0
  328. package/dist/cjs/src/base/Exchange.js +11 -0
  329. package/dist/cjs/src/bingx.js +0 -10
  330. package/dist/cjs/src/bitget.js +14 -5
  331. package/dist/cjs/src/bybit.js +1 -1
  332. package/dist/cjs/src/kucoin.js +29 -5
  333. package/js/ccxt.d.ts +1 -1
  334. package/js/ccxt.js +1 -1
  335. package/js/src/abstract/bigone.d.ts +18 -0
  336. package/js/src/abstract/binance.d.ts +2 -0
  337. package/js/src/abstract/binancecoinm.d.ts +2 -0
  338. package/js/src/abstract/binanceus.d.ts +2 -0
  339. package/js/src/abstract/binanceusdm.d.ts +2 -0
  340. package/js/src/abstract/bybit.d.ts +1 -0
  341. package/js/src/abstract/gate.d.ts +11 -0
  342. package/js/src/abstract/gateio.d.ts +11 -0
  343. package/js/src/alpaca.js +18 -18
  344. package/js/src/base/Exchange.d.ts +6 -1
  345. package/js/src/base/Exchange.js +112 -12
  346. package/js/src/bigone.d.ts +1 -2
  347. package/js/src/bigone.js +340 -145
  348. package/js/src/binance.js +15 -8
  349. package/js/src/bingx.d.ts +0 -1
  350. package/js/src/bingx.js +9 -12
  351. package/js/src/bitfinex.d.ts +2 -2
  352. package/js/src/bitfinex.js +2 -3
  353. package/js/src/bitget.js +35 -13
  354. package/js/src/bitmart.d.ts +2 -2
  355. package/js/src/bitmart.js +3 -3
  356. package/js/src/bitmex.js +1 -0
  357. package/js/src/bybit.js +3 -1
  358. package/js/src/coinlist.js +2 -3
  359. package/js/src/coinsph.js +2 -3
  360. package/js/src/deribit.js +1 -0
  361. package/js/src/gate.d.ts +4 -4
  362. package/js/src/gate.js +22 -3
  363. package/js/src/hitbtc.d.ts +4 -4
  364. package/js/src/hitbtc.js +2 -3
  365. package/js/src/htx.js +4 -7
  366. package/js/src/huobijp.js +2 -3
  367. package/js/src/kraken.js +1 -0
  368. package/js/src/kucoin.js +29 -5
  369. package/js/src/mexc.js +2 -1
  370. package/js/src/okx.js +13 -3
  371. package/js/src/pro/binance.d.ts +2 -23
  372. package/js/src/pro/binance.js +58 -22
  373. package/js/src/pro/coinbase.d.ts +2 -2
  374. package/js/src/pro/coinbase.js +4 -1
  375. package/js/src/pro/coinbasepro.d.ts +2 -2
  376. package/js/src/pro/hitbtc.d.ts +2 -2
  377. package/js/src/pro/poloniex.d.ts +2 -2
  378. package/js/src/upbit.d.ts +3 -101
  379. package/js/src/upbit.js +12 -12
  380. package/js/src/woo.js +2 -0
  381. package/package.json +11 -11
  382. package/skip-tests.json +5 -0
  383. package/tests-manager.sh +2 -2
@@ -0,0 +1,1486 @@
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;