ccxt 4.2.11 → 4.2.13

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 (392) hide show
  1. package/README.md +5 -5
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +1347 -490
  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 +2209 -0
  125. package/dist/cjs/js/src/binance.js +9736 -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 +3807 -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 +8291 -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 +3424 -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 +7072 -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 +9049 -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 +761 -0
  185. package/dist/cjs/js/src/indodax.js +1069 -0
  186. package/dist/cjs/js/src/kraken.js +2857 -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 +2851 -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 +7330 -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 +4722 -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 +1608 -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 +1867 -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 +2765 -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/js/ccxt.d.ts +1 -1
  329. package/js/ccxt.js +1 -1
  330. package/js/src/abstract/bigone.d.ts +18 -0
  331. package/js/src/abstract/binance.d.ts +2 -0
  332. package/js/src/abstract/binancecoinm.d.ts +2 -0
  333. package/js/src/abstract/binanceus.d.ts +2 -0
  334. package/js/src/abstract/binanceusdm.d.ts +2 -0
  335. package/js/src/abstract/bingx.d.ts +2 -0
  336. package/js/src/abstract/bybit.d.ts +1 -0
  337. package/js/src/abstract/gate.d.ts +11 -0
  338. package/js/src/abstract/gateio.d.ts +11 -0
  339. package/js/src/abstract/okx.d.ts +1 -0
  340. package/js/src/alpaca.js +18 -18
  341. package/js/src/base/Exchange.d.ts +5 -1
  342. package/js/src/base/Exchange.js +101 -12
  343. package/js/src/bigone.d.ts +3 -2
  344. package/js/src/bigone.js +429 -167
  345. package/js/src/binance.js +48 -34
  346. package/js/src/bingx.js +115 -38
  347. package/js/src/bitfinex.d.ts +2 -2
  348. package/js/src/bitfinex.js +2 -3
  349. package/js/src/bitget.js +33 -13
  350. package/js/src/bitmart.d.ts +2 -2
  351. package/js/src/bitmart.js +5 -5
  352. package/js/src/bitmex.js +1 -0
  353. package/js/src/bybit.js +2 -0
  354. package/js/src/coinbase.d.ts +26 -3
  355. package/js/src/coinbase.js +176 -26
  356. package/js/src/coinlist.js +3 -4
  357. package/js/src/coinone.js +1 -1
  358. package/js/src/coinsph.js +2 -3
  359. package/js/src/deribit.js +1 -0
  360. package/js/src/gate.d.ts +4 -4
  361. package/js/src/gate.js +96 -59
  362. package/js/src/gemini.js +1 -1
  363. package/js/src/hitbtc.d.ts +4 -4
  364. package/js/src/hitbtc.js +2 -3
  365. package/js/src/htx.d.ts +1 -0
  366. package/js/src/htx.js +29 -7
  367. package/js/src/huobijp.js +2 -3
  368. package/js/src/independentreserve.js +7 -5
  369. package/js/src/kraken.js +3 -6
  370. package/js/src/lbank.js +59 -33
  371. package/js/src/mexc.js +2 -1
  372. package/js/src/oceanex.js +1 -1
  373. package/js/src/okx.js +14 -3
  374. package/js/src/phemex.js +9 -2
  375. package/js/src/pro/binance.d.ts +2 -23
  376. package/js/src/pro/binance.js +58 -22
  377. package/js/src/pro/coinbase.d.ts +2 -2
  378. package/js/src/pro/coinbase.js +4 -1
  379. package/js/src/pro/coinbasepro.d.ts +2 -2
  380. package/js/src/pro/hitbtc.d.ts +2 -2
  381. package/js/src/pro/kraken.js +1 -1
  382. package/js/src/pro/okx.d.ts +1 -0
  383. package/js/src/pro/okx.js +52 -2
  384. package/js/src/pro/poloniex.d.ts +2 -2
  385. package/js/src/probit.js +4 -2
  386. package/js/src/upbit.d.ts +3 -101
  387. package/js/src/upbit.js +12 -12
  388. package/js/src/wavesexchange.js +1 -1
  389. package/js/src/woo.d.ts +2 -0
  390. package/js/src/woo.js +52 -0
  391. package/package.json +1 -1
  392. package/skip-tests.json +5 -0
@@ -0,0 +1,1020 @@
1
+ 'use strict';
2
+
3
+ var cryptocom$1 = require('../cryptocom.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
+
8
+ // ---------------------------------------------------------------------------
9
+ // ---------------------------------------------------------------------------
10
+ class cryptocom extends cryptocom$1 {
11
+ describe() {
12
+ return this.deepExtend(super.describe(), {
13
+ 'has': {
14
+ 'ws': true,
15
+ 'watchBalance': true,
16
+ 'watchTicker': true,
17
+ 'watchTickers': false,
18
+ 'watchMyTrades': true,
19
+ 'watchTrades': true,
20
+ 'watchTradesForSymbols': true,
21
+ 'watchOrderBook': true,
22
+ 'watchOrderBookForSymbols': true,
23
+ 'watchOrders': true,
24
+ 'watchOHLCV': true,
25
+ 'watchPositions': true,
26
+ 'createOrderWs': true,
27
+ 'cancelOrderWs': true,
28
+ 'cancelAllOrders': true,
29
+ },
30
+ 'urls': {
31
+ 'api': {
32
+ 'ws': {
33
+ 'public': 'wss://stream.crypto.com/exchange/v1/market',
34
+ 'private': 'wss://stream.crypto.com/exchange/v1/user',
35
+ },
36
+ },
37
+ 'test': {
38
+ 'public': 'wss://uat-stream.3ona.co/exchange/v1/market',
39
+ 'private': 'wss://uat-stream.3ona.co/exchange/v1/user',
40
+ },
41
+ },
42
+ 'options': {
43
+ 'watchPositions': {
44
+ 'fetchPositionsSnapshot': true,
45
+ 'awaitPositionsSnapshot': true, // whether to wait for the positions snapshot before providing updates
46
+ },
47
+ },
48
+ 'streaming': {},
49
+ });
50
+ }
51
+ async pong(client, message) {
52
+ // {
53
+ // "id": 1587523073344,
54
+ // "method": "public/heartbeat",
55
+ // "code": 0
56
+ // }
57
+ try {
58
+ await client.send({ 'id': this.safeInteger(message, 'id'), 'method': 'public/respond-heartbeat' });
59
+ }
60
+ catch (e) {
61
+ const error = new errors.NetworkError(this.id + ' pong failed with error ' + this.json(e));
62
+ client.reset(error);
63
+ }
64
+ }
65
+ async watchOrderBook(symbol, limit = undefined, params = {}) {
66
+ /**
67
+ * @method
68
+ * @name cryptocom#watchOrderBook
69
+ * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
70
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#book-instrument_name
71
+ * @param {string} symbol unified symbol of the market to fetch the order book for
72
+ * @param {int} [limit] the maximum amount of order book entries to return
73
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
74
+ * @param {string} [params.bookSubscriptionType] The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
75
+ * @param {int} [params.bookUpdateFrequency] Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
76
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
77
+ */
78
+ return await this.watchOrderBookForSymbols([symbol], limit, params);
79
+ }
80
+ async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
81
+ /**
82
+ * @method
83
+ * @name cryptocom#watchOrderBook
84
+ * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
85
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#book-instrument_name
86
+ * @param {string[]} symbols unified array of symbols
87
+ * @param {int} [limit] the maximum amount of order book entries to return
88
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
89
+ * @param {string} [params.bookSubscriptionType] The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
90
+ * @param {int} [params.bookUpdateFrequency] Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
91
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
92
+ */
93
+ await this.loadMarkets();
94
+ symbols = this.marketSymbols(symbols);
95
+ const topics = [];
96
+ const messageHashes = [];
97
+ if (!limit) {
98
+ limit = 50;
99
+ }
100
+ const topicParams = this.safeValue(params, 'params');
101
+ if (topicParams === undefined) {
102
+ params['params'] = {};
103
+ }
104
+ let bookSubscriptionType = undefined;
105
+ [bookSubscriptionType, params] = this.handleOptionAndParams2(params, 'watchOrderBook', 'watchOrderBookForSymbols', 'bookSubscriptionType', 'SNAPSHOT_AND_UPDATE');
106
+ if (bookSubscriptionType !== undefined) {
107
+ params['params']['bookSubscriptionType'] = bookSubscriptionType;
108
+ }
109
+ let bookUpdateFrequency = undefined;
110
+ [bookUpdateFrequency, params] = this.handleOptionAndParams2(params, 'watchOrderBook', 'watchOrderBookForSymbols', 'bookUpdateFrequency');
111
+ if (bookUpdateFrequency !== undefined) {
112
+ params['params']['bookSubscriptionType'] = bookSubscriptionType;
113
+ }
114
+ for (let i = 0; i < symbols.length; i++) {
115
+ const symbol = symbols[i];
116
+ const market = this.market(symbol);
117
+ const currentTopic = 'book' + '.' + market['id'] + '.' + limit.toString();
118
+ const messageHash = 'orderbook:' + market['symbol'];
119
+ messageHashes.push(messageHash);
120
+ topics.push(currentTopic);
121
+ }
122
+ const orderbook = await this.watchPublicMultiple(messageHashes, topics, params);
123
+ return orderbook.limit();
124
+ }
125
+ handleDelta(bookside, delta) {
126
+ const price = this.safeFloat(delta, 0);
127
+ const amount = this.safeFloat(delta, 1);
128
+ const count = this.safeInteger(delta, 2);
129
+ bookside.store(price, amount, count);
130
+ }
131
+ handleDeltas(bookside, deltas) {
132
+ for (let i = 0; i < deltas.length; i++) {
133
+ this.handleDelta(bookside, deltas[i]);
134
+ }
135
+ }
136
+ handleOrderBook(client, message) {
137
+ //
138
+ // snapshot
139
+ // {
140
+ // "instrument_name":"LTC_USDT",
141
+ // "subscription":"book.LTC_USDT.150",
142
+ // "channel":"book",
143
+ // "depth":150,
144
+ // "data": [
145
+ // {
146
+ // "bids": [
147
+ // [122.21, 0.74041, 4]
148
+ // ],
149
+ // "asks": [
150
+ // [122.29, 0.00002, 1]
151
+ // ]
152
+ // "t": 1648123943803,
153
+ // "s":754560122
154
+ // }
155
+ // ]
156
+ // }
157
+ // update
158
+ // {
159
+ // "instrument_name":"BTC_USDT",
160
+ // "subscription":"book.BTC_USDT.50",
161
+ // "channel":"book.update",
162
+ // "depth":50,
163
+ // "data":[
164
+ // {
165
+ // "update":{
166
+ // "asks":[
167
+ // [
168
+ // "43755.46",
169
+ // "0.10000",
170
+ // "1"
171
+ // ],
172
+ // ...
173
+ // ],
174
+ // "bids":[
175
+ // [
176
+ // "43737.46",
177
+ // "0.14096",
178
+ // "1"
179
+ // ],
180
+ // ...
181
+ // ]
182
+ // },
183
+ // "t":1704484068898,
184
+ // "tt":1704484068892,
185
+ // "u":78795598253024,
186
+ // "pu":78795598162080,
187
+ // "cs":-781431132
188
+ // }
189
+ // ]
190
+ // }
191
+ //
192
+ const marketId = this.safeString(message, 'instrument_name');
193
+ const market = this.safeMarket(marketId);
194
+ const symbol = market['symbol'];
195
+ let data = this.safeValue(message, 'data');
196
+ data = this.safeValue(data, 0);
197
+ const timestamp = this.safeInteger(data, 't');
198
+ let orderbook = this.safeValue(this.orderbooks, symbol);
199
+ if (orderbook === undefined) {
200
+ const limit = this.safeInteger(message, 'depth');
201
+ orderbook = this.countedOrderBook({}, limit);
202
+ }
203
+ const channel = this.safeString(message, 'channel');
204
+ const nonce = this.safeInteger2(data, 'u', 's');
205
+ let books = data;
206
+ if (channel === 'book') { // snapshot
207
+ orderbook.reset({});
208
+ orderbook['symbol'] = symbol;
209
+ orderbook['timestamp'] = timestamp;
210
+ orderbook['datetime'] = this.iso8601(timestamp);
211
+ orderbook['nonce'] = nonce;
212
+ }
213
+ else {
214
+ books = this.safeValue(data, 'update', {});
215
+ const previousNonce = this.safeInteger(data, 'pu');
216
+ const currentNonce = orderbook['nonce'];
217
+ if (currentNonce !== previousNonce) {
218
+ throw new errors.InvalidNonce(this.id + ' watchOrderBook() ' + symbol + ' ' + previousNonce + ' != ' + nonce);
219
+ }
220
+ }
221
+ this.handleDeltas(orderbook['asks'], this.safeValue(books, 'asks', []));
222
+ this.handleDeltas(orderbook['bids'], this.safeValue(books, 'bids', []));
223
+ orderbook['nonce'] = nonce;
224
+ this.orderbooks[symbol] = orderbook;
225
+ const messageHash = 'orderbook:' + symbol;
226
+ client.resolve(orderbook, messageHash);
227
+ }
228
+ async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
229
+ /**
230
+ * @method
231
+ * @name cryptocom#watchTrades
232
+ * @description get the list of most recent trades for a particular symbol
233
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#trade-instrument_name
234
+ * @param {string} symbol unified symbol of the market to fetch trades for
235
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
236
+ * @param {int} [limit] the maximum amount of trades to fetch
237
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
238
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
239
+ */
240
+ return await this.watchTradesForSymbols([symbol], since, limit, params);
241
+ }
242
+ async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
243
+ /**
244
+ * @method
245
+ * @name cryptocom#watchTradesForSymbols
246
+ * @description get the list of most recent trades for a particular symbol
247
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#trade-instrument_name
248
+ * @param {string} symbol unified symbol of the market to fetch trades for
249
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
250
+ * @param {int} [limit] the maximum amount of trades to fetch
251
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
252
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
253
+ */
254
+ await this.loadMarkets();
255
+ symbols = this.marketSymbols(symbols);
256
+ const topics = [];
257
+ for (let i = 0; i < symbols.length; i++) {
258
+ const symbol = symbols[i];
259
+ const market = this.market(symbol);
260
+ const currentTopic = 'trade' + '.' + market['id'];
261
+ topics.push(currentTopic);
262
+ }
263
+ const trades = await this.watchPublicMultiple(topics, topics, params);
264
+ if (this.newUpdates) {
265
+ const first = this.safeValue(trades, 0);
266
+ const tradeSymbol = this.safeString(first, 'symbol');
267
+ limit = trades.getLimit(tradeSymbol, limit);
268
+ }
269
+ return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
270
+ }
271
+ handleTrades(client, message) {
272
+ //
273
+ // {
274
+ // "code": 0,
275
+ // "method": "subscribe",
276
+ // "result": {
277
+ // "instrument_name": "BTC_USDT",
278
+ // "subscription": "trade.BTC_USDT",
279
+ // "channel": "trade",
280
+ // "data": [
281
+ // {
282
+ // "dataTime":1648122434405,
283
+ // "d":"2358394540212355488",
284
+ // "s":"SELL",
285
+ // "p":42980.85,
286
+ // "q":0.002325,
287
+ // "t":1648122434404,
288
+ // "i":"BTC_USDT"
289
+ // }
290
+ // (...)
291
+ // ]
292
+ // }
293
+ //
294
+ const channel = this.safeString(message, 'channel');
295
+ const marketId = this.safeString(message, 'instrument_name');
296
+ const symbolSpecificMessageHash = this.safeString(message, 'subscription');
297
+ const market = this.safeMarket(marketId);
298
+ const symbol = market['symbol'];
299
+ let stored = this.safeValue(this.trades, symbol);
300
+ if (stored === undefined) {
301
+ const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
302
+ stored = new Cache.ArrayCache(limit);
303
+ this.trades[symbol] = stored;
304
+ }
305
+ const data = this.safeValue(message, 'data', []);
306
+ const dataLength = data.length;
307
+ if (dataLength === 0) {
308
+ return;
309
+ }
310
+ const parsedTrades = this.parseTrades(data, market);
311
+ for (let j = 0; j < parsedTrades.length; j++) {
312
+ stored.append(parsedTrades[j]);
313
+ }
314
+ const channelReplaced = channel.replace('.' + marketId, '');
315
+ client.resolve(stored, symbolSpecificMessageHash);
316
+ client.resolve(stored, channelReplaced);
317
+ }
318
+ async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
319
+ /**
320
+ * @method
321
+ * @name cryptocom#watchMyTrades
322
+ * @description watches information on multiple trades made by the user
323
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-trade-instrument_name
324
+ * @param {string} symbol unified market symbol of the market trades were made in
325
+ * @param {int} [since] the earliest time in ms to fetch trades for
326
+ * @param {int} [limit] the maximum number of trade structures to retrieve
327
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
328
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure
329
+ */
330
+ await this.loadMarkets();
331
+ let market = undefined;
332
+ if (symbol !== undefined) {
333
+ market = this.market(symbol);
334
+ symbol = market['symbol'];
335
+ }
336
+ let messageHash = 'user.trade';
337
+ messageHash = (market !== undefined) ? (messageHash + '.' + market['id']) : messageHash;
338
+ const trades = await this.watchPrivateSubscribe(messageHash, params);
339
+ if (this.newUpdates) {
340
+ limit = trades.getLimit(symbol, limit);
341
+ }
342
+ return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
343
+ }
344
+ async watchTicker(symbol, params = {}) {
345
+ /**
346
+ * @method
347
+ * @name cryptocom#watchTicker
348
+ * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
349
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#ticker-instrument_name
350
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
351
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
352
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
353
+ */
354
+ await this.loadMarkets();
355
+ const market = this.market(symbol);
356
+ const messageHash = 'ticker' + '.' + market['id'];
357
+ return await this.watchPublic(messageHash, params);
358
+ }
359
+ handleTicker(client, message) {
360
+ //
361
+ // {
362
+ // "info":{
363
+ // "instrument_name":"BTC_USDT",
364
+ // "subscription":"ticker.BTC_USDT",
365
+ // "channel":"ticker",
366
+ // "data":[
367
+ // {
368
+ // "i":"BTC_USDT",
369
+ // "b":43063.19,
370
+ // "k":43063.2,
371
+ // "a":43063.19,
372
+ // "t":1648121165658,
373
+ // "v":43573.912409,
374
+ // "h":43498.51,
375
+ // "l":41876.58,
376
+ // "c":1087.43
377
+ // }
378
+ // ]
379
+ // }
380
+ // }
381
+ //
382
+ const messageHash = this.safeString(message, 'subscription');
383
+ const marketId = this.safeString(message, 'instrument_name');
384
+ const market = this.safeMarket(marketId);
385
+ const data = this.safeValue(message, 'data', []);
386
+ for (let i = 0; i < data.length; i++) {
387
+ const ticker = data[i];
388
+ const parsed = this.parseTicker(ticker, market);
389
+ const symbol = parsed['symbol'];
390
+ this.tickers[symbol] = parsed;
391
+ client.resolve(parsed, messageHash);
392
+ }
393
+ }
394
+ async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
395
+ /**
396
+ * @method
397
+ * @name cryptocom#watchOHLCV
398
+ * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
399
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#candlestick-time_frame-instrument_name
400
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
401
+ * @param {string} timeframe the length of time each candle represents
402
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
403
+ * @param {int} [limit] the maximum amount of candles to fetch
404
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
405
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
406
+ */
407
+ await this.loadMarkets();
408
+ const market = this.market(symbol);
409
+ symbol = market['symbol'];
410
+ const interval = this.safeString(this.timeframes, timeframe, timeframe);
411
+ const messageHash = 'candlestick' + '.' + interval + '.' + market['id'];
412
+ const ohlcv = await this.watchPublic(messageHash, params);
413
+ if (this.newUpdates) {
414
+ limit = ohlcv.getLimit(symbol, limit);
415
+ }
416
+ return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
417
+ }
418
+ handleOHLCV(client, message) {
419
+ //
420
+ // {
421
+ // "instrument_name": "BTC_USDT",
422
+ // "subscription": "candlestick.1m.BTC_USDT",
423
+ // "channel": "candlestick",
424
+ // "depth": 300,
425
+ // "interval": "1m",
426
+ // "data": [ [Object] ]
427
+ // }
428
+ //
429
+ const messageHash = this.safeString(message, 'subscription');
430
+ const marketId = this.safeString(message, 'instrument_name');
431
+ const market = this.safeMarket(marketId);
432
+ const symbol = market['symbol'];
433
+ const interval = this.safeString(message, 'interval');
434
+ const timeframe = this.findTimeframe(interval);
435
+ this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
436
+ let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
437
+ if (stored === undefined) {
438
+ const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
439
+ stored = new Cache.ArrayCacheByTimestamp(limit);
440
+ this.ohlcvs[symbol][timeframe] = stored;
441
+ }
442
+ const data = this.safeValue(message, 'data');
443
+ for (let i = 0; i < data.length; i++) {
444
+ const tick = data[i];
445
+ const parsed = this.parseOHLCV(tick, market);
446
+ stored.append(parsed);
447
+ }
448
+ client.resolve(stored, messageHash);
449
+ }
450
+ async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
451
+ /**
452
+ * @method
453
+ * @name cryptocom#watchOrders
454
+ * @description watches information on multiple orders made by the user
455
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-order-instrument_name
456
+ * @param {string} symbol unified market symbol of the market orders were made in
457
+ * @param {int} [since] the earliest time in ms to fetch orders for
458
+ * @param {int} [limit] the maximum number of order structures to retrieve
459
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
460
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
461
+ */
462
+ await this.loadMarkets();
463
+ let market = undefined;
464
+ if (symbol !== undefined) {
465
+ market = this.market(symbol);
466
+ symbol = market['symbol'];
467
+ }
468
+ let messageHash = 'user.order';
469
+ messageHash = (market !== undefined) ? (messageHash + '.' + market['id']) : messageHash;
470
+ const orders = await this.watchPrivateSubscribe(messageHash, params);
471
+ if (this.newUpdates) {
472
+ limit = orders.getLimit(symbol, limit);
473
+ }
474
+ return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
475
+ }
476
+ handleOrders(client, message, subscription = undefined) {
477
+ //
478
+ // {
479
+ // "method": "subscribe",
480
+ // "result": {
481
+ // "instrument_name": "ETH_CRO",
482
+ // "subscription": "user.order.ETH_CRO",
483
+ // "channel": "user.order",
484
+ // "data": [
485
+ // {
486
+ // "status": "ACTIVE",
487
+ // "side": "BUY",
488
+ // "price": 1,
489
+ // "quantity": 1,
490
+ // "order_id": "366455245775097673",
491
+ // "client_oid": "my_order_0002",
492
+ // "create_time": 1588758017375,
493
+ // "update_time": 1588758017411,
494
+ // "type": "LIMIT",
495
+ // "instrument_name": "ETH_CRO",
496
+ // "cumulative_quantity": 0,
497
+ // "cumulative_value": 0,
498
+ // "avg_price": 0,
499
+ // "fee_currency": "CRO",
500
+ // "time_in_force":"GOOD_TILL_CANCEL"
501
+ // }
502
+ // ],
503
+ // "channel": "user.order.ETH_CRO"
504
+ // }
505
+ // }
506
+ //
507
+ const channel = this.safeString(message, 'channel');
508
+ const symbolSpecificMessageHash = this.safeString(message, 'subscription');
509
+ const orders = this.safeValue(message, 'data', []);
510
+ const ordersLength = orders.length;
511
+ if (ordersLength > 0) {
512
+ if (this.orders === undefined) {
513
+ const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
514
+ this.orders = new Cache.ArrayCacheBySymbolById(limit);
515
+ }
516
+ const stored = this.orders;
517
+ const parsed = this.parseOrders(orders);
518
+ for (let i = 0; i < parsed.length; i++) {
519
+ stored.append(parsed[i]);
520
+ }
521
+ client.resolve(stored, symbolSpecificMessageHash);
522
+ // non-symbol specific
523
+ client.resolve(stored, channel); // channel might have a symbol-specific suffix
524
+ client.resolve(stored, 'user.order');
525
+ }
526
+ }
527
+ async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
528
+ /**
529
+ * @method
530
+ * @name cryptocom#watchPositions
531
+ * @description watch all open positions
532
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-position_balance
533
+ * @param {string[]|undefined} symbols list of unified market symbols
534
+ * @param {object} params extra parameters specific to the exchange API endpoint
535
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
536
+ */
537
+ await this.loadMarkets();
538
+ await this.authenticate();
539
+ const url = this.urls['api']['ws']['private'];
540
+ const id = this.nonce();
541
+ const request = {
542
+ 'method': 'subscribe',
543
+ 'params': {
544
+ 'channels': ['user.position_balance'],
545
+ },
546
+ 'nonce': id,
547
+ };
548
+ let messageHash = 'positions';
549
+ symbols = this.marketSymbols(symbols);
550
+ if (!this.isEmpty(symbols)) {
551
+ messageHash = '::' + symbols.join(',');
552
+ }
553
+ const client = this.client(url);
554
+ this.setPositionsCache(client, symbols);
555
+ const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
556
+ const awaitPositionsSnapshot = this.safeValue('watchPositions', 'awaitPositionsSnapshot', true);
557
+ if (fetchPositionsSnapshot && awaitPositionsSnapshot && this.positions === undefined) {
558
+ const snapshot = await client.future('fetchPositionsSnapshot');
559
+ return this.filterBySymbolsSinceLimit(snapshot, symbols, since, limit, true);
560
+ }
561
+ const newPositions = await this.watch(url, messageHash, this.extend(request, params));
562
+ if (this.newUpdates) {
563
+ return newPositions;
564
+ }
565
+ return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
566
+ }
567
+ setPositionsCache(client, type, symbols = undefined) {
568
+ const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', false);
569
+ if (fetchPositionsSnapshot) {
570
+ const messageHash = 'fetchPositionsSnapshot';
571
+ if (!(messageHash in client.futures)) {
572
+ client.future(messageHash);
573
+ this.spawn(this.loadPositionsSnapshot, client, messageHash);
574
+ }
575
+ }
576
+ else {
577
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
578
+ }
579
+ }
580
+ async loadPositionsSnapshot(client, messageHash) {
581
+ const positions = await this.fetchPositions();
582
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
583
+ const cache = this.positions;
584
+ for (let i = 0; i < positions.length; i++) {
585
+ const position = positions[i];
586
+ const contracts = this.safeNumber(position, 'contracts', 0);
587
+ if (contracts > 0) {
588
+ cache.append(position);
589
+ }
590
+ }
591
+ // don't remove the future from the .futures cache
592
+ const future = client.futures[messageHash];
593
+ future.resolve(cache);
594
+ client.resolve(cache, 'positions');
595
+ }
596
+ handlePositions(client, message) {
597
+ //
598
+ // {
599
+ // "subscription": "user.position_balance",
600
+ // "channel": "user.position_balance",
601
+ // "data": [{
602
+ // "balances": [{
603
+ // "instrument_name": "USD",
604
+ // "quantity": "8.9979961950886",
605
+ // "update_timestamp_ms": 1695598760597,
606
+ // }],
607
+ // "positions": [{
608
+ // "account_id": "96a0edb1-afb5-4c7c-af89-5cb610319e2c",
609
+ // "instrument_name": "LTCUSD-PERP",
610
+ // "type": "PERPETUAL_SWAP",
611
+ // "quantity": "1.8",
612
+ // "cost": "114.766",
613
+ // "open_position_pnl": "-0.0216206",
614
+ // "session_pnl": "0.00962994",
615
+ // "update_timestamp_ms": 1695598760597,
616
+ // "open_pos_cost": "114.766",
617
+ // }],
618
+ // }],
619
+ // }
620
+ //
621
+ // each account is connected to a different endpoint
622
+ // and has exactly one subscriptionhash which is the account type
623
+ const data = this.safeValue(message, 'data', []);
624
+ const firstData = this.safeValue(data, 0, {});
625
+ const rawPositions = this.safeValue(firstData, 'positions', []);
626
+ if (this.positions === undefined) {
627
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
628
+ }
629
+ const cache = this.positions;
630
+ const newPositions = [];
631
+ for (let i = 0; i < rawPositions.length; i++) {
632
+ const rawPosition = rawPositions[i];
633
+ const position = this.parsePosition(rawPosition);
634
+ newPositions.push(position);
635
+ cache.append(position);
636
+ }
637
+ const messageHashes = this.findMessageHashes(client, 'positions::');
638
+ for (let i = 0; i < messageHashes.length; i++) {
639
+ const messageHash = messageHashes[i];
640
+ const parts = messageHash.split('::');
641
+ const symbolsString = parts[1];
642
+ const symbols = symbolsString.split(',');
643
+ const positions = this.filterByArray(newPositions, 'symbol', symbols, false);
644
+ if (!this.isEmpty(positions)) {
645
+ client.resolve(positions, messageHash);
646
+ }
647
+ }
648
+ client.resolve(newPositions, 'positions');
649
+ }
650
+ async watchBalance(params = {}) {
651
+ /**
652
+ * @method
653
+ * @name cryptocom#watchBalance
654
+ * @description watch balance and get the amount of funds available for trading or funds locked in orders
655
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#user-balance
656
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
657
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
658
+ */
659
+ const messageHash = 'user.balance';
660
+ return await this.watchPrivateSubscribe(messageHash, params);
661
+ }
662
+ handleBalance(client, message) {
663
+ //
664
+ // {
665
+ // "id": 1,
666
+ // "method": "subscribe",
667
+ // "code": 0,
668
+ // "result": {
669
+ // "subscription": "user.balance",
670
+ // "channel": "user.balance",
671
+ // "data": [
672
+ // {
673
+ // "total_available_balance": "5.84684368",
674
+ // "total_margin_balance": "5.84684368",
675
+ // "total_initial_margin": "0",
676
+ // "total_maintenance_margin": "0",
677
+ // "total_position_cost": "0",
678
+ // "total_cash_balance": "6.44412101",
679
+ // "total_collateral_value": "5.846843685",
680
+ // "total_session_unrealized_pnl": "0",
681
+ // "instrument_name": "USD",
682
+ // "total_session_realized_pnl": "0",
683
+ // "position_balances": [
684
+ // {
685
+ // "quantity": "0.0002119875",
686
+ // "reserved_qty": "0",
687
+ // "collateral_weight": "0.9",
688
+ // "collateral_amount": "5.37549592",
689
+ // "market_value": "5.97277325",
690
+ // "max_withdrawal_balance": "0.00021198",
691
+ // "instrument_name": "BTC",
692
+ // "hourly_interest_rate": "0"
693
+ // },
694
+ // ],
695
+ // "total_effective_leverage": "0",
696
+ // "position_limit": "3000000",
697
+ // "used_position_limit": "0",
698
+ // "total_borrow": "0",
699
+ // "margin_score": "0",
700
+ // "is_liquidating": false,
701
+ // "has_risk": false,
702
+ // "terminatable": true
703
+ // }
704
+ // ]
705
+ // }
706
+ // }
707
+ //
708
+ const messageHash = this.safeString(message, 'subscription');
709
+ const data = this.safeValue(message, 'data', []);
710
+ const positionBalances = this.safeValue(data[0], 'position_balances', []);
711
+ this.balance['info'] = data;
712
+ for (let i = 0; i < positionBalances.length; i++) {
713
+ const balance = positionBalances[i];
714
+ const currencyId = this.safeString(balance, 'instrument_name');
715
+ const code = this.safeCurrencyCode(currencyId);
716
+ const account = this.account();
717
+ account['total'] = this.safeString(balance, 'quantity');
718
+ account['used'] = this.safeString(balance, 'reserved_qty');
719
+ this.balance[code] = account;
720
+ this.balance = this.safeBalance(this.balance);
721
+ }
722
+ client.resolve(this.balance, messageHash);
723
+ const messageHashRequest = this.safeString(message, 'id');
724
+ client.resolve(this.balance, messageHashRequest);
725
+ }
726
+ async createOrderWs(symbol, type, side, amount, price = undefined, params = {}) {
727
+ /**
728
+ * @method
729
+ * @name cryptocom#createOrderWs
730
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-create-order
731
+ * @description create a trade order
732
+ * @param {string} symbol unified symbol of the market to create an order in
733
+ * @param {string} type 'market' or 'limit'
734
+ * @param {string} side 'buy' or 'sell'
735
+ * @param {float} amount how much of currency you want to trade in units of base currency
736
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
737
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
738
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
739
+ */
740
+ await this.loadMarkets();
741
+ params = this.createOrderRequest(symbol, type, side, amount, price, params);
742
+ const request = {
743
+ 'method': 'private/create-order',
744
+ 'params': params,
745
+ };
746
+ const messageHash = this.nonce();
747
+ return await this.watchPrivateRequest(messageHash, request);
748
+ }
749
+ handleOrder(client, message) {
750
+ //
751
+ // {
752
+ // "id": 1,
753
+ // "method": "private/create-order",
754
+ // "code": 0,
755
+ // "result": {
756
+ // "client_oid": "c5f682ed-7108-4f1c-b755-972fcdca0f02",
757
+ // "order_id": "18342311"
758
+ // }
759
+ // }
760
+ //
761
+ const messageHash = this.safeString(message, 'id');
762
+ const rawOrder = this.safeValue(message, 'result', {});
763
+ const order = this.parseOrder(rawOrder);
764
+ client.resolve(order, messageHash);
765
+ }
766
+ async cancelOrderWs(id, symbol = undefined, params = {}) {
767
+ /**
768
+ * @method
769
+ * @name cryptocom#cancelOrder
770
+ * @description cancels an open order
771
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-order
772
+ * @param {string} id the order id of the order to cancel
773
+ * @param {string} [symbol] unified symbol of the market the order was made in
774
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
775
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
776
+ */
777
+ await this.loadMarkets();
778
+ params = this.extend({
779
+ 'order_id': id,
780
+ }, params);
781
+ const request = {
782
+ 'method': 'private/cancel-order',
783
+ 'params': params,
784
+ };
785
+ const messageHash = this.nonce();
786
+ return await this.watchPrivateRequest(messageHash, request);
787
+ }
788
+ async cancelAllOrdersWs(symbol = undefined, params = {}) {
789
+ /**
790
+ * @method
791
+ * @name cryptocom#cancelAllOrdersWs
792
+ * @description cancel all open orders
793
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#private-cancel-all-orders
794
+ * @param {string} symbol unified market symbol of the orders to cancel
795
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
796
+ * @returns {object} Returns exchange raw message {@link https://docs.ccxt.com/#/?id=order-structure}
797
+ */
798
+ await this.loadMarkets();
799
+ let market = undefined;
800
+ const request = {
801
+ 'method': 'private/cancel-all-orders',
802
+ 'params': this.extend({}, params),
803
+ };
804
+ if (symbol !== undefined) {
805
+ market = this.market(symbol);
806
+ request['params']['instrument_name'] = market['id'];
807
+ }
808
+ const messageHash = this.nonce();
809
+ return await this.watchPrivateRequest(messageHash, request);
810
+ }
811
+ handleCancelAllOrders(client, message) {
812
+ //
813
+ // {
814
+ // "id": 1688914586647,
815
+ // "method": "private/cancel-all-orders",
816
+ // "code": 0
817
+ // }
818
+ //
819
+ const messageHash = this.safeString(message, 'id');
820
+ client.resolve(message, messageHash);
821
+ }
822
+ async watchPublic(messageHash, params = {}) {
823
+ const url = this.urls['api']['ws']['public'];
824
+ const id = this.nonce();
825
+ const request = {
826
+ 'method': 'subscribe',
827
+ 'params': {
828
+ 'channels': [messageHash],
829
+ },
830
+ 'nonce': id,
831
+ };
832
+ const message = this.extend(request, params);
833
+ return await this.watch(url, messageHash, message, messageHash);
834
+ }
835
+ async watchPublicMultiple(messageHashes, topics, params = {}) {
836
+ const url = this.urls['api']['ws']['public'];
837
+ const id = this.nonce();
838
+ const request = {
839
+ 'method': 'subscribe',
840
+ 'params': {
841
+ 'channels': topics,
842
+ },
843
+ 'nonce': id,
844
+ };
845
+ const message = this.deepExtend(request, params);
846
+ return await this.watchMultiple(url, messageHashes, message, messageHashes);
847
+ }
848
+ async watchPrivateRequest(nonce, params = {}) {
849
+ await this.authenticate();
850
+ const url = this.urls['api']['ws']['private'];
851
+ const request = {
852
+ 'id': nonce,
853
+ 'nonce': nonce,
854
+ };
855
+ const message = this.extend(request, params);
856
+ return await this.watch(url, nonce.toString(), message, true);
857
+ }
858
+ async watchPrivateSubscribe(messageHash, params = {}) {
859
+ await this.authenticate();
860
+ const url = this.urls['api']['ws']['private'];
861
+ const id = this.nonce();
862
+ const request = {
863
+ 'method': 'subscribe',
864
+ 'params': {
865
+ 'channels': [messageHash],
866
+ },
867
+ 'nonce': id,
868
+ };
869
+ const message = this.extend(request, params);
870
+ return await this.watch(url, messageHash, message, messageHash);
871
+ }
872
+ handleErrorMessage(client, message) {
873
+ //
874
+ // {
875
+ // "id": 0,
876
+ // "code": 10004,
877
+ // "method": "subscribe",
878
+ // "message": "invalid channel {"channels":["trade.BTCUSD-PERP"]}"
879
+ // }
880
+ //
881
+ const errorCode = this.safeString(message, 'code');
882
+ try {
883
+ if (errorCode && errorCode !== '0') {
884
+ const feedback = this.id + ' ' + this.json(message);
885
+ this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
886
+ const messageString = this.safeValue(message, 'message');
887
+ if (messageString !== undefined) {
888
+ this.throwBroadlyMatchedException(this.exceptions['broad'], messageString, feedback);
889
+ }
890
+ }
891
+ return false;
892
+ }
893
+ catch (e) {
894
+ if (e instanceof errors.AuthenticationError) {
895
+ const messageHash = 'authenticated';
896
+ client.reject(e, messageHash);
897
+ if (messageHash in client.subscriptions) {
898
+ delete client.subscriptions[messageHash];
899
+ }
900
+ }
901
+ else {
902
+ client.reject(e);
903
+ }
904
+ return true;
905
+ }
906
+ }
907
+ handleSubscribe(client, message) {
908
+ const methods = {
909
+ 'candlestick': this.handleOHLCV,
910
+ 'ticker': this.handleTicker,
911
+ 'trade': this.handleTrades,
912
+ 'book': this.handleOrderBook,
913
+ 'book.update': this.handleOrderBook,
914
+ 'user.order': this.handleOrders,
915
+ 'user.trade': this.handleTrades,
916
+ 'user.balance': this.handleBalance,
917
+ 'user.position_balance': this.handlePositions,
918
+ };
919
+ const result = this.safeValue2(message, 'result', 'info');
920
+ const channel = this.safeString(result, 'channel');
921
+ if ((channel !== undefined) && channel.indexOf('user.trade') > -1) {
922
+ // channel might be user.trade.BTC_USDT
923
+ this.handleTrades(client, result);
924
+ }
925
+ if ((channel !== undefined) && channel.startsWith('user.order')) {
926
+ // channel might be user.order.BTC_USDT
927
+ this.handleOrders(client, result);
928
+ }
929
+ const method = this.safeValue(methods, channel);
930
+ if (method !== undefined) {
931
+ method.call(this, client, result);
932
+ }
933
+ }
934
+ handleMessage(client, message) {
935
+ //
936
+ // ping
937
+ // {
938
+ // "id": 1587523073344,
939
+ // "method": "public/heartbeat",
940
+ // "code": 0
941
+ // }
942
+ // auth
943
+ // { id: 1648132625434, method: "public/auth", code: 0 }
944
+ // ohlcv
945
+ // {
946
+ // "code": 0,
947
+ // "method": "subscribe",
948
+ // "result": {
949
+ // "instrument_name": "BTC_USDT",
950
+ // "subscription": "candlestick.1m.BTC_USDT",
951
+ // "channel": "candlestick",
952
+ // "depth": 300,
953
+ // "interval": "1m",
954
+ // "data": [ [Object] ]
955
+ // }
956
+ // }
957
+ // ticker
958
+ // {
959
+ // "info":{
960
+ // "instrument_name":"BTC_USDT",
961
+ // "subscription":"ticker.BTC_USDT",
962
+ // "channel":"ticker",
963
+ // "data":[ { } ]
964
+ //
965
+ if (this.handleErrorMessage(client, message)) {
966
+ return;
967
+ }
968
+ const method = this.safeString(message, 'method');
969
+ const methods = {
970
+ '': this.handlePing,
971
+ 'public/heartbeat': this.handlePing,
972
+ 'public/auth': this.handleAuthenticate,
973
+ 'private/create-order': this.handleOrder,
974
+ 'private/cancel-order': this.handleOrder,
975
+ 'private/cancel-all-orders': this.handleCancelAllOrders,
976
+ 'private/close-position': this.handleOrder,
977
+ 'subscribe': this.handleSubscribe,
978
+ };
979
+ const callMethod = this.safeValue(methods, method);
980
+ if (callMethod !== undefined) {
981
+ callMethod.call(this, client, message);
982
+ }
983
+ }
984
+ async authenticate(params = {}) {
985
+ this.checkRequiredCredentials();
986
+ const url = this.urls['api']['ws']['private'];
987
+ const client = this.client(url);
988
+ const messageHash = 'authenticated';
989
+ const future = client.future(messageHash);
990
+ const authenticated = this.safeValue(client.subscriptions, messageHash);
991
+ if (authenticated === undefined) {
992
+ const method = 'public/auth';
993
+ const nonce = this.nonce().toString();
994
+ const auth = method + nonce + this.apiKey + nonce;
995
+ const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
996
+ const request = {
997
+ 'id': nonce,
998
+ 'nonce': nonce,
999
+ 'method': method,
1000
+ 'api_key': this.apiKey,
1001
+ 'sig': signature,
1002
+ };
1003
+ const message = this.extend(request, params);
1004
+ this.watch(url, messageHash, message, messageHash);
1005
+ }
1006
+ return future;
1007
+ }
1008
+ handlePing(client, message) {
1009
+ this.spawn(this.pong, client, message);
1010
+ }
1011
+ handleAuthenticate(client, message) {
1012
+ //
1013
+ // { id: 1648132625434, method: "public/auth", code: 0 }
1014
+ //
1015
+ const future = this.safeValue(client.futures, 'authenticated');
1016
+ future.resolve(true);
1017
+ }
1018
+ }
1019
+
1020
+ module.exports = cryptocom;