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,1918 @@
1
+ 'use strict';
2
+
3
+ var huobijp$1 = require('./abstract/huobijp.js');
4
+ var errors = require('./base/errors.js');
5
+ var Precise = require('./base/Precise.js');
6
+ var number = require('./base/functions/number.js');
7
+ var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * @class huobijp
13
+ * @augments Exchange
14
+ */
15
+ class huobijp extends huobijp$1 {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'huobijp',
19
+ 'name': 'Huobi Japan',
20
+ 'countries': ['JP'],
21
+ 'rateLimit': 100,
22
+ 'userAgent': this.userAgents['chrome39'],
23
+ 'certified': false,
24
+ 'version': 'v1',
25
+ 'hostname': 'api-cloud.bittrade.co.jp',
26
+ 'pro': true,
27
+ 'has': {
28
+ 'CORS': undefined,
29
+ 'spot': true,
30
+ 'margin': undefined,
31
+ 'swap': false,
32
+ 'future': false,
33
+ 'option': false,
34
+ 'cancelAllOrders': true,
35
+ 'cancelOrder': true,
36
+ 'cancelOrders': true,
37
+ 'createMarketBuyOrderWithCost': true,
38
+ 'createMarketOrderWithCost': false,
39
+ 'createMarketSellOrderWithCost': false,
40
+ 'createOrder': true,
41
+ 'createStopLimitOrder': false,
42
+ 'createStopMarketOrder': false,
43
+ 'createStopOrder': false,
44
+ 'fetchAccounts': true,
45
+ 'fetchBalance': true,
46
+ 'fetchClosedOrders': true,
47
+ 'fetchCurrencies': true,
48
+ 'fetchDepositAddress': false,
49
+ 'fetchDepositAddressesByNetwork': false,
50
+ 'fetchDeposits': true,
51
+ 'fetchFundingHistory': false,
52
+ 'fetchFundingRate': false,
53
+ 'fetchFundingRateHistory': false,
54
+ 'fetchFundingRates': false,
55
+ 'fetchIndexOHLCV': false,
56
+ 'fetchMarkets': true,
57
+ 'fetchMarkOHLCV': false,
58
+ 'fetchMyTrades': true,
59
+ 'fetchOHLCV': true,
60
+ 'fetchOpenOrders': true,
61
+ 'fetchOrder': true,
62
+ 'fetchOrderBook': true,
63
+ 'fetchOrders': true,
64
+ 'fetchOrderTrades': true,
65
+ 'fetchPremiumIndexOHLCV': false,
66
+ 'fetchTicker': true,
67
+ 'fetchTickers': true,
68
+ 'fetchTime': true,
69
+ 'fetchTrades': true,
70
+ 'fetchTradingLimits': true,
71
+ 'fetchWithdrawals': true,
72
+ 'withdraw': true,
73
+ },
74
+ 'timeframes': {
75
+ '1m': '1min',
76
+ '5m': '5min',
77
+ '15m': '15min',
78
+ '30m': '30min',
79
+ '1h': '60min',
80
+ '4h': '4hour',
81
+ '1d': '1day',
82
+ '1w': '1week',
83
+ '1M': '1mon',
84
+ '1y': '1year',
85
+ },
86
+ 'urls': {
87
+ 'logo': 'https://user-images.githubusercontent.com/1294454/85734211-85755480-b705-11ea-8b35-0b7f1db33a2f.jpg',
88
+ 'api': {
89
+ 'market': 'https://{hostname}',
90
+ 'public': 'https://{hostname}',
91
+ 'private': 'https://{hostname}',
92
+ 'v2Public': 'https://{hostname}',
93
+ 'v2Private': 'https://{hostname}',
94
+ },
95
+ 'www': 'https://www.huobi.co.jp',
96
+ 'referral': 'https://www.huobi.co.jp/register/?invite_code=znnq3',
97
+ 'doc': 'https://api-doc.huobi.co.jp',
98
+ 'fees': 'https://www.huobi.co.jp/support/fee',
99
+ },
100
+ 'api': {
101
+ 'v2Public': {
102
+ 'get': {
103
+ 'reference/currencies': 1,
104
+ 'market-status': 1, // 获取当前市场状态
105
+ },
106
+ },
107
+ 'v2Private': {
108
+ 'get': {
109
+ 'account/ledger': 1,
110
+ 'account/withdraw/quota': 1,
111
+ 'account/withdraw/address': 1,
112
+ 'account/deposit/address': 1,
113
+ 'account/repayment': 5,
114
+ 'reference/transact-fee-rate': 1,
115
+ 'account/asset-valuation': 0.2,
116
+ 'point/account': 5,
117
+ 'sub-user/user-list': 1,
118
+ 'sub-user/user-state': 1,
119
+ 'sub-user/account-list': 1,
120
+ 'sub-user/deposit-address': 1,
121
+ 'sub-user/query-deposit': 1,
122
+ 'user/api-key': 1,
123
+ 'user/uid': 1,
124
+ 'algo-orders/opening': 1,
125
+ 'algo-orders/history': 1,
126
+ 'algo-orders/specific': 1,
127
+ 'c2c/offers': 1,
128
+ 'c2c/offer': 1,
129
+ 'c2c/transactions': 1,
130
+ 'c2c/repayment': 1,
131
+ 'c2c/account': 1,
132
+ 'etp/reference': 1,
133
+ 'etp/transactions': 5,
134
+ 'etp/transaction': 5,
135
+ 'etp/rebalance': 1,
136
+ 'etp/limit': 1, // 获取ETP持仓限额
137
+ },
138
+ 'post': {
139
+ 'account/transfer': 1,
140
+ 'account/repayment': 5,
141
+ 'point/transfer': 5,
142
+ 'sub-user/management': 1,
143
+ 'sub-user/creation': 1,
144
+ 'sub-user/tradable-market': 1,
145
+ 'sub-user/transferability': 1,
146
+ 'sub-user/api-key-generation': 1,
147
+ 'sub-user/api-key-modification': 1,
148
+ 'sub-user/api-key-deletion': 1,
149
+ 'sub-user/deduct-mode': 1,
150
+ 'algo-orders': 1,
151
+ 'algo-orders/cancel-all-after': 1,
152
+ 'algo-orders/cancellation': 1,
153
+ 'c2c/offer': 1,
154
+ 'c2c/cancellation': 1,
155
+ 'c2c/cancel-all': 1,
156
+ 'c2c/repayment': 1,
157
+ 'c2c/transfer': 1,
158
+ 'etp/creation': 5,
159
+ 'etp/redemption': 5,
160
+ 'etp/{transactId}/cancel': 10,
161
+ 'etp/batch-cancel': 50, // 杠杆ETP批量撤单
162
+ },
163
+ },
164
+ 'market': {
165
+ 'get': {
166
+ 'history/kline': 1,
167
+ 'detail/merged': 1,
168
+ 'depth': 1,
169
+ 'trade': 1,
170
+ 'history/trade': 1,
171
+ 'detail': 1,
172
+ 'tickers': 1,
173
+ 'etp': 1, // 获取杠杆ETP实时净值
174
+ },
175
+ },
176
+ 'public': {
177
+ 'get': {
178
+ 'common/symbols': 1,
179
+ 'common/currencys': 1,
180
+ 'common/timestamp': 1,
181
+ 'common/exchange': 1,
182
+ 'settings/currencys': 1, // ?language=en-US
183
+ },
184
+ },
185
+ 'private': {
186
+ 'get': {
187
+ 'account/accounts': 0.2,
188
+ 'account/accounts/{id}/balance': 0.2,
189
+ 'account/accounts/{sub-uid}': 1,
190
+ 'account/history': 4,
191
+ 'cross-margin/loan-info': 1,
192
+ 'margin/loan-info': 1,
193
+ 'fee/fee-rate/get': 1,
194
+ 'order/openOrders': 0.4,
195
+ 'order/orders': 0.4,
196
+ 'order/orders/{id}': 0.4,
197
+ 'order/orders/{id}/matchresults': 0.4,
198
+ 'order/orders/getClientOrder': 0.4,
199
+ 'order/history': 1,
200
+ 'order/matchresults': 1,
201
+ // 'dw/withdraw-virtual/addresses', // 查询虚拟币提现地址(Deprecated)
202
+ 'query/deposit-withdraw': 1,
203
+ // 'margin/loan-info', // duplicate
204
+ 'margin/loan-orders': 0.2,
205
+ 'margin/accounts/balance': 0.2,
206
+ 'cross-margin/loan-orders': 1,
207
+ 'cross-margin/accounts/balance': 1,
208
+ 'points/actions': 1,
209
+ 'points/orders': 1,
210
+ 'subuser/aggregate-balance': 10,
211
+ 'stable-coin/exchange_rate': 1,
212
+ 'stable-coin/quote': 1,
213
+ },
214
+ 'post': {
215
+ 'account/transfer': 1,
216
+ 'futures/transfer': 1,
217
+ 'order/batch-orders': 0.4,
218
+ 'order/orders/place': 0.2,
219
+ 'order/orders/submitCancelClientOrder': 0.2,
220
+ 'order/orders/batchCancelOpenOrders': 0.4,
221
+ // 'order/orders', // 创建一个新的订单请求 (仅创建订单,不执行下单)
222
+ // 'order/orders/{id}/place', // 执行一个订单 (仅执行已创建的订单)
223
+ 'order/orders/{id}/submitcancel': 0.2,
224
+ 'order/orders/batchcancel': 0.4,
225
+ // 'dw/balance/transfer', // 资产划转
226
+ 'dw/withdraw/api/create': 1,
227
+ // 'dw/withdraw-virtual/create', // 申请提现虚拟币
228
+ // 'dw/withdraw-virtual/{id}/place', // 确认申请虚拟币提现(Deprecated)
229
+ 'dw/withdraw-virtual/{id}/cancel': 1,
230
+ 'dw/transfer-in/margin': 10,
231
+ 'dw/transfer-out/margin': 10,
232
+ 'margin/orders': 10,
233
+ 'margin/orders/{id}/repay': 10,
234
+ 'cross-margin/transfer-in': 1,
235
+ 'cross-margin/transfer-out': 1,
236
+ 'cross-margin/orders': 1,
237
+ 'cross-margin/orders/{id}/repay': 1,
238
+ 'stable-coin/exchange': 1,
239
+ 'subuser/transfer': 10,
240
+ },
241
+ },
242
+ },
243
+ 'fees': {
244
+ 'trading': {
245
+ 'feeSide': 'get',
246
+ 'tierBased': false,
247
+ 'percentage': true,
248
+ 'maker': this.parseNumber('0.002'),
249
+ 'taker': this.parseNumber('0.002'),
250
+ },
251
+ },
252
+ 'precisionMode': number.TICK_SIZE,
253
+ 'exceptions': {
254
+ 'broad': {
255
+ 'contract is restricted of closing positions on API. Please contact customer service': errors.OnMaintenance,
256
+ 'maintain': errors.OnMaintenance,
257
+ },
258
+ 'exact': {
259
+ // err-code
260
+ 'bad-request': errors.BadRequest,
261
+ 'base-date-limit-error': errors.BadRequest,
262
+ 'api-not-support-temp-addr': errors.PermissionDenied,
263
+ 'timeout': errors.RequestTimeout,
264
+ 'gateway-internal-error': errors.ExchangeNotAvailable,
265
+ 'account-frozen-balance-insufficient-error': errors.InsufficientFunds,
266
+ 'invalid-amount': errors.InvalidOrder,
267
+ 'order-limitorder-amount-min-error': errors.InvalidOrder,
268
+ 'order-limitorder-amount-max-error': errors.InvalidOrder,
269
+ 'order-marketorder-amount-min-error': errors.InvalidOrder,
270
+ 'order-limitorder-price-min-error': errors.InvalidOrder,
271
+ 'order-limitorder-price-max-error': errors.InvalidOrder,
272
+ 'order-holding-limit-failed': errors.InvalidOrder,
273
+ 'order-orderprice-precision-error': errors.InvalidOrder,
274
+ 'order-etp-nav-price-max-error': errors.InvalidOrder,
275
+ 'order-orderstate-error': errors.OrderNotFound,
276
+ 'order-queryorder-invalid': errors.OrderNotFound,
277
+ 'order-update-error': errors.ExchangeNotAvailable,
278
+ 'api-signature-check-failed': errors.AuthenticationError,
279
+ 'api-signature-not-valid': errors.AuthenticationError,
280
+ 'base-record-invalid': errors.OrderNotFound,
281
+ 'base-symbol-trade-disabled': errors.BadSymbol,
282
+ 'base-symbol-error': errors.BadSymbol,
283
+ 'system-maintenance': errors.OnMaintenance,
284
+ // err-msg
285
+ 'invalid symbol': errors.BadSymbol,
286
+ 'symbol trade not open now': errors.BadSymbol,
287
+ 'invalid-address': errors.BadRequest,
288
+ 'base-currency-chain-error': errors.BadRequest,
289
+ 'dw-insufficient-balance': errors.InsufficientFunds, // {"status":"error","err-code":"dw-insufficient-balance","err-msg":"Insufficient balance. You can only transfer `12.3456` at most.","data":null}
290
+ },
291
+ },
292
+ 'options': {
293
+ 'defaultNetwork': 'ERC20',
294
+ 'networks': {
295
+ 'ETH': 'erc20',
296
+ 'TRX': 'trc20',
297
+ 'HRC20': 'hrc20',
298
+ 'HECO': 'hrc20',
299
+ 'HT': 'hrc20',
300
+ 'ALGO': 'algo',
301
+ 'OMNI': '',
302
+ },
303
+ // https://github.com/ccxt/ccxt/issues/5376
304
+ 'fetchOrdersByStatesMethod': 'private_get_order_orders',
305
+ 'fetchOpenOrdersMethod': 'fetch_open_orders_v1',
306
+ 'createMarketBuyOrderRequiresPrice': true,
307
+ 'fetchMarketsMethod': 'publicGetCommonSymbols',
308
+ 'fetchBalanceMethod': 'privateGetAccountAccountsIdBalance',
309
+ 'createOrderMethod': 'privatePostOrderOrdersPlace',
310
+ 'language': 'en-US',
311
+ 'broker': {
312
+ 'id': 'AA03022abc',
313
+ },
314
+ },
315
+ 'commonCurrencies': {
316
+ // https://github.com/ccxt/ccxt/issues/6081
317
+ // https://github.com/ccxt/ccxt/issues/3365
318
+ // https://github.com/ccxt/ccxt/issues/2873
319
+ 'GET': 'Themis',
320
+ 'GTC': 'Game.com',
321
+ 'HIT': 'HitChain',
322
+ // https://github.com/ccxt/ccxt/issues/7399
323
+ // https://coinmarketcap.com/currencies/pnetwork/
324
+ // https://coinmarketcap.com/currencies/penta/markets/
325
+ // https://en.cryptonomist.ch/blog/eidoo/the-edo-to-pnt-upgrade-what-you-need-to-know-updated/
326
+ 'PNT': 'Penta',
327
+ 'SBTC': 'Super Bitcoin',
328
+ 'BIFI': 'Bitcoin File', // conflict with Beefy.Finance https://github.com/ccxt/ccxt/issues/8706
329
+ },
330
+ });
331
+ }
332
+ async fetchTime(params = {}) {
333
+ /**
334
+ * @method
335
+ * @name huobijp#fetchTime
336
+ * @description fetches the current integer timestamp in milliseconds from the exchange server
337
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
338
+ * @returns {int} the current integer timestamp in milliseconds from the exchange server
339
+ */
340
+ const response = await this.publicGetCommonTimestamp(params);
341
+ return this.safeInteger(response, 'data');
342
+ }
343
+ async fetchTradingLimits(symbols = undefined, params = {}) {
344
+ // this method should not be called directly, use loadTradingLimits () instead
345
+ // by default it will try load withdrawal fees of all currencies (with separate requests)
346
+ // however if you define symbols = [ 'ETH/BTC', 'LTC/BTC' ] in args it will only load those
347
+ await this.loadMarkets();
348
+ if (symbols === undefined) {
349
+ symbols = this.symbols;
350
+ }
351
+ const result = {};
352
+ for (let i = 0; i < symbols.length; i++) {
353
+ const symbol = symbols[i];
354
+ result[symbol] = await this.fetchTradingLimitsById(this.marketId(symbol), params);
355
+ }
356
+ return result;
357
+ }
358
+ async fetchTradingLimitsById(id, params = {}) {
359
+ const request = {
360
+ 'symbol': id,
361
+ };
362
+ const response = await this.publicGetCommonExchange(this.extend(request, params));
363
+ //
364
+ // { status: "ok",
365
+ // "data": { symbol: "aidocbtc",
366
+ // "buy-limit-must-less-than": 1.1,
367
+ // "sell-limit-must-greater-than": 0.9,
368
+ // "limit-order-must-greater-than": 1,
369
+ // "limit-order-must-less-than": 5000000,
370
+ // "market-buy-order-must-greater-than": 0.0001,
371
+ // "market-buy-order-must-less-than": 100,
372
+ // "market-sell-order-must-greater-than": 1,
373
+ // "market-sell-order-must-less-than": 500000,
374
+ // "circuit-break-when-greater-than": 10000,
375
+ // "circuit-break-when-less-than": 10,
376
+ // "market-sell-order-rate-must-less-than": 0.1,
377
+ // "market-buy-order-rate-must-less-than": 0.1 } }
378
+ //
379
+ return this.parseTradingLimits(this.safeValue(response, 'data', {}));
380
+ }
381
+ parseTradingLimits(limits, symbol = undefined, params = {}) {
382
+ //
383
+ // { symbol: "aidocbtc",
384
+ // "buy-limit-must-less-than": 1.1,
385
+ // "sell-limit-must-greater-than": 0.9,
386
+ // "limit-order-must-greater-than": 1,
387
+ // "limit-order-must-less-than": 5000000,
388
+ // "market-buy-order-must-greater-than": 0.0001,
389
+ // "market-buy-order-must-less-than": 100,
390
+ // "market-sell-order-must-greater-than": 1,
391
+ // "market-sell-order-must-less-than": 500000,
392
+ // "circuit-break-when-greater-than": 10000,
393
+ // "circuit-break-when-less-than": 10,
394
+ // "market-sell-order-rate-must-less-than": 0.1,
395
+ // "market-buy-order-rate-must-less-than": 0.1 }
396
+ //
397
+ return {
398
+ 'info': limits,
399
+ 'limits': {
400
+ 'amount': {
401
+ 'min': this.safeNumber(limits, 'limit-order-must-greater-than'),
402
+ 'max': this.safeNumber(limits, 'limit-order-must-less-than'),
403
+ },
404
+ },
405
+ };
406
+ }
407
+ costToPrecision(symbol, cost) {
408
+ return this.decimalToPrecision(cost, number.TRUNCATE, this.markets[symbol]['precision']['cost'], this.precisionMode);
409
+ }
410
+ async fetchMarkets(params = {}) {
411
+ /**
412
+ * @method
413
+ * @name huobijp#fetchMarkets
414
+ * @description retrieves data on all markets for huobijp
415
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
416
+ * @returns {object[]} an array of objects representing market data
417
+ */
418
+ const method = this.options['fetchMarketsMethod'];
419
+ const response = await this[method](params);
420
+ //
421
+ // {
422
+ // "status": "ok",
423
+ // "data": [
424
+ // {
425
+ // "base-currency": "xrp",
426
+ // "quote-currency": "btc",
427
+ // "price-precision": 9,
428
+ // "amount-precision": 2,
429
+ // "symbol-partition": "default",
430
+ // "symbol": "xrpbtc",
431
+ // "state": "online",
432
+ // "value-precision": 8,
433
+ // "min-order-amt": 1,
434
+ // "max-order-amt": 5000000,
435
+ // "min-order-value": 0.0001,
436
+ // "limit-order-min-order-amt": 1,
437
+ // "limit-order-max-order-amt": 5000000,
438
+ // "limit-order-max-buy-amt": 5000000,
439
+ // "limit-order-max-sell-amt": 5000000,
440
+ // "sell-market-min-order-amt": 1,
441
+ // "sell-market-max-order-amt": 500000,
442
+ // "buy-market-max-order-value": 100,
443
+ // "leverage-ratio": 5,
444
+ // "super-margin-leverage-ratio": 3,
445
+ // "api-trading": "enabled",
446
+ // "tags": ""
447
+ // }
448
+ // ...
449
+ // ]
450
+ // }
451
+ //
452
+ const markets = this.safeValue(response, 'data', []);
453
+ const numMarkets = markets.length;
454
+ if (numMarkets < 1) {
455
+ throw new errors.NetworkError(this.id + ' fetchMarkets() returned empty response: ' + this.json(markets));
456
+ }
457
+ const result = [];
458
+ for (let i = 0; i < markets.length; i++) {
459
+ const market = markets[i];
460
+ const baseId = this.safeString(market, 'base-currency');
461
+ const quoteId = this.safeString(market, 'quote-currency');
462
+ const base = this.safeCurrencyCode(baseId);
463
+ const quote = this.safeCurrencyCode(quoteId);
464
+ const state = this.safeString(market, 'state');
465
+ const leverageRatio = this.safeString(market, 'leverage-ratio', '1');
466
+ const superLeverageRatio = this.safeString(market, 'super-margin-leverage-ratio', '1');
467
+ const margin = Precise["default"].stringGt(leverageRatio, '1') || Precise["default"].stringGt(superLeverageRatio, '1');
468
+ const fee = (base === 'OMG') ? this.parseNumber('0') : this.parseNumber('0.002');
469
+ result.push({
470
+ 'id': baseId + quoteId,
471
+ 'symbol': base + '/' + quote,
472
+ 'base': base,
473
+ 'quote': quote,
474
+ 'settle': undefined,
475
+ 'baseId': baseId,
476
+ 'quoteId': quoteId,
477
+ 'settleId': undefined,
478
+ 'type': 'spot',
479
+ 'spot': true,
480
+ 'margin': margin,
481
+ 'swap': false,
482
+ 'future': false,
483
+ 'option': false,
484
+ 'active': (state === 'online'),
485
+ 'contract': false,
486
+ 'linear': undefined,
487
+ 'inverse': undefined,
488
+ 'taker': fee,
489
+ 'maker': fee,
490
+ 'contractSize': undefined,
491
+ 'expiry': undefined,
492
+ 'expiryDatetime': undefined,
493
+ 'strike': undefined,
494
+ 'optionType': undefined,
495
+ 'precision': {
496
+ 'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'price-precision'))),
497
+ 'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'amount-precision'))),
498
+ 'cost': this.parseNumber(this.parsePrecision(this.safeString(market, 'value-precision'))),
499
+ },
500
+ 'limits': {
501
+ 'leverage': {
502
+ 'min': this.parseNumber('1'),
503
+ 'max': this.parseNumber(leverageRatio),
504
+ 'superMax': this.parseNumber(superLeverageRatio),
505
+ },
506
+ 'amount': {
507
+ 'min': this.safeNumber(market, 'min-order-amt'),
508
+ 'max': this.safeNumber(market, 'max-order-amt'),
509
+ },
510
+ 'price': {
511
+ 'min': undefined,
512
+ 'max': undefined,
513
+ },
514
+ 'cost': {
515
+ 'min': this.safeNumber(market, 'min-order-value'),
516
+ 'max': undefined,
517
+ },
518
+ },
519
+ 'created': undefined,
520
+ 'info': market,
521
+ });
522
+ }
523
+ return result;
524
+ }
525
+ parseTicker(ticker, market = undefined) {
526
+ //
527
+ // fetchTicker
528
+ //
529
+ // {
530
+ // "amount": 26228.672978342216,
531
+ // "open": 9078.95,
532
+ // "close": 9146.86,
533
+ // "high": 9155.41,
534
+ // "id": 209988544334,
535
+ // "count": 265846,
536
+ // "low": 8988.0,
537
+ // "version": 209988544334,
538
+ // "ask": [ 9146.87, 0.156134 ],
539
+ // "vol": 2.3822168242201668E8,
540
+ // "bid": [ 9146.86, 0.080758 ],
541
+ // }
542
+ //
543
+ // fetchTickers
544
+ // {
545
+ // "symbol": "bhdht",
546
+ // "open": 2.3938,
547
+ // "high": 2.4151,
548
+ // "low": 2.3323,
549
+ // "close": 2.3909,
550
+ // "amount": 628.992,
551
+ // "vol": 1493.71841095,
552
+ // "count": 2088,
553
+ // "bid": 2.3643,
554
+ // "bidSize": 0.7136,
555
+ // "ask": 2.4061,
556
+ // "askSize": 0.4156
557
+ // }
558
+ //
559
+ const symbol = this.safeSymbol(undefined, market);
560
+ const timestamp = this.safeInteger(ticker, 'ts');
561
+ let bid = undefined;
562
+ let bidVolume = undefined;
563
+ let ask = undefined;
564
+ let askVolume = undefined;
565
+ if ('bid' in ticker) {
566
+ if (Array.isArray(ticker['bid'])) {
567
+ bid = this.safeString(ticker['bid'], 0);
568
+ bidVolume = this.safeString(ticker['bid'], 1);
569
+ }
570
+ else {
571
+ bid = this.safeString(ticker, 'bid');
572
+ bidVolume = this.safeString(ticker, 'bidSize');
573
+ }
574
+ }
575
+ if ('ask' in ticker) {
576
+ if (Array.isArray(ticker['ask'])) {
577
+ ask = this.safeString(ticker['ask'], 0);
578
+ askVolume = this.safeString(ticker['ask'], 1);
579
+ }
580
+ else {
581
+ ask = this.safeString(ticker, 'ask');
582
+ askVolume = this.safeString(ticker, 'askSize');
583
+ }
584
+ }
585
+ const open = this.safeString(ticker, 'open');
586
+ const close = this.safeString(ticker, 'close');
587
+ const baseVolume = this.safeString(ticker, 'amount');
588
+ const quoteVolume = this.safeString(ticker, 'vol');
589
+ return this.safeTicker({
590
+ 'symbol': symbol,
591
+ 'timestamp': timestamp,
592
+ 'datetime': this.iso8601(timestamp),
593
+ 'high': this.safeString(ticker, 'high'),
594
+ 'low': this.safeString(ticker, 'low'),
595
+ 'bid': bid,
596
+ 'bidVolume': bidVolume,
597
+ 'ask': ask,
598
+ 'askVolume': askVolume,
599
+ 'vwap': undefined,
600
+ 'open': open,
601
+ 'close': close,
602
+ 'last': close,
603
+ 'previousClose': undefined,
604
+ 'change': undefined,
605
+ 'percentage': undefined,
606
+ 'average': undefined,
607
+ 'baseVolume': baseVolume,
608
+ 'quoteVolume': quoteVolume,
609
+ 'info': ticker,
610
+ }, market);
611
+ }
612
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
613
+ /**
614
+ * @method
615
+ * @name huobijp#fetchOrderBook
616
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
617
+ * @param {string} symbol unified symbol of the market to fetch the order book for
618
+ * @param {int} [limit] the maximum amount of order book entries to return
619
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
620
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
621
+ */
622
+ await this.loadMarkets();
623
+ const market = this.market(symbol);
624
+ const request = {
625
+ 'symbol': market['id'],
626
+ 'type': 'step0',
627
+ };
628
+ const response = await this.marketGetDepth(this.extend(request, params));
629
+ //
630
+ // {
631
+ // "status": "ok",
632
+ // "ch": "market.btcusdt.depth.step0",
633
+ // "ts": 1583474832790,
634
+ // "tick": {
635
+ // "bids": [
636
+ // [ 9100.290000000000000000, 0.200000000000000000 ],
637
+ // [ 9099.820000000000000000, 0.200000000000000000 ],
638
+ // [ 9099.610000000000000000, 0.205000000000000000 ],
639
+ // ],
640
+ // "asks": [
641
+ // [ 9100.640000000000000000, 0.005904000000000000 ],
642
+ // [ 9101.010000000000000000, 0.287311000000000000 ],
643
+ // [ 9101.030000000000000000, 0.012121000000000000 ],
644
+ // ],
645
+ // "ts":1583474832008,
646
+ // "version":104999698780
647
+ // }
648
+ // }
649
+ //
650
+ if ('tick' in response) {
651
+ if (!response['tick']) {
652
+ throw new errors.BadSymbol(this.id + ' fetchOrderBook() returned empty response: ' + this.json(response));
653
+ }
654
+ const tick = this.safeValue(response, 'tick');
655
+ const timestamp = this.safeInteger(tick, 'ts', this.safeInteger(response, 'ts'));
656
+ const result = this.parseOrderBook(tick, symbol, timestamp);
657
+ result['nonce'] = this.safeInteger(tick, 'version');
658
+ return result;
659
+ }
660
+ throw new errors.ExchangeError(this.id + ' fetchOrderBook() returned unrecognized response: ' + this.json(response));
661
+ }
662
+ async fetchTicker(symbol, params = {}) {
663
+ /**
664
+ * @method
665
+ * @name huobijp#fetchTicker
666
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
667
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
668
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
669
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
670
+ */
671
+ await this.loadMarkets();
672
+ const market = this.market(symbol);
673
+ const request = {
674
+ 'symbol': market['id'],
675
+ };
676
+ const response = await this.marketGetDetailMerged(this.extend(request, params));
677
+ //
678
+ // {
679
+ // "status": "ok",
680
+ // "ch": "market.btcusdt.detail.merged",
681
+ // "ts": 1583494336669,
682
+ // "tick": {
683
+ // "amount": 26228.672978342216,
684
+ // "open": 9078.95,
685
+ // "close": 9146.86,
686
+ // "high": 9155.41,
687
+ // "id": 209988544334,
688
+ // "count": 265846,
689
+ // "low": 8988.0,
690
+ // "version": 209988544334,
691
+ // "ask": [ 9146.87, 0.156134 ],
692
+ // "vol": 2.3822168242201668E8,
693
+ // "bid": [ 9146.86, 0.080758 ],
694
+ // }
695
+ // }
696
+ //
697
+ const ticker = this.parseTicker(response['tick'], market);
698
+ const timestamp = this.safeInteger(response, 'ts');
699
+ ticker['timestamp'] = timestamp;
700
+ ticker['datetime'] = this.iso8601(timestamp);
701
+ return ticker;
702
+ }
703
+ async fetchTickers(symbols = undefined, params = {}) {
704
+ /**
705
+ * @method
706
+ * @name huobijp#fetchTickers
707
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
708
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
709
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
710
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
711
+ */
712
+ await this.loadMarkets();
713
+ symbols = this.marketSymbols(symbols);
714
+ const response = await this.marketGetTickers(params);
715
+ const tickers = this.safeValue(response, 'data', []);
716
+ const timestamp = this.safeInteger(response, 'ts');
717
+ const result = {};
718
+ for (let i = 0; i < tickers.length; i++) {
719
+ const marketId = this.safeString(tickers[i], 'symbol');
720
+ const market = this.safeMarket(marketId);
721
+ const symbol = market['symbol'];
722
+ const ticker = this.parseTicker(tickers[i], market);
723
+ ticker['timestamp'] = timestamp;
724
+ ticker['datetime'] = this.iso8601(timestamp);
725
+ result[symbol] = ticker;
726
+ }
727
+ return this.filterByArrayTickers(result, 'symbol', symbols);
728
+ }
729
+ parseTrade(trade, market = undefined) {
730
+ //
731
+ // fetchTrades (public)
732
+ //
733
+ // {
734
+ // "amount": 0.010411000000000000,
735
+ // "trade-id": 102090736910,
736
+ // "ts": 1583497692182,
737
+ // "id": 10500517034273194594947,
738
+ // "price": 9096.050000000000000000,
739
+ // "direction": "sell"
740
+ // }
741
+ //
742
+ // fetchMyTrades (private)
743
+ //
744
+ // {
745
+ // "symbol": "swftcbtc",
746
+ // "fee-currency": "swftc",
747
+ // "filled-fees": "0",
748
+ // "source": "spot-api",
749
+ // "id": 83789509854000,
750
+ // "type": "buy-limit",
751
+ // "order-id": 83711103204909,
752
+ // 'filled-points': "0.005826843283532154",
753
+ // "fee-deduct-currency": "ht",
754
+ // 'filled-amount': "45941.53",
755
+ // "price": "0.0000001401",
756
+ // "created-at": 1597933260729,
757
+ // "match-id": 100087455560,
758
+ // "role": "maker",
759
+ // "trade-id": 100050305348
760
+ // },
761
+ //
762
+ const marketId = this.safeString(trade, 'symbol');
763
+ const symbol = this.safeSymbol(marketId, market);
764
+ const timestamp = this.safeInteger2(trade, 'ts', 'created-at');
765
+ const order = this.safeString(trade, 'order-id');
766
+ let side = this.safeString(trade, 'direction');
767
+ let type = this.safeString(trade, 'type');
768
+ if (type !== undefined) {
769
+ const typeParts = type.split('-');
770
+ side = typeParts[0];
771
+ type = typeParts[1];
772
+ }
773
+ const takerOrMaker = this.safeString(trade, 'role');
774
+ const price = this.safeString(trade, 'price');
775
+ const amount = this.safeString2(trade, 'filled-amount', 'amount');
776
+ const cost = Precise["default"].stringMul(price, amount);
777
+ let fee = undefined;
778
+ let feeCost = this.safeString(trade, 'filled-fees');
779
+ let feeCurrency = this.safeCurrencyCode(this.safeString(trade, 'fee-currency'));
780
+ const filledPoints = this.safeString(trade, 'filled-points');
781
+ if (filledPoints !== undefined) {
782
+ if ((feeCost === undefined) || (Precise["default"].stringEq(feeCost, '0.0'))) {
783
+ feeCost = filledPoints;
784
+ feeCurrency = this.safeCurrencyCode(this.safeString(trade, 'fee-deduct-currency'));
785
+ }
786
+ }
787
+ if (feeCost !== undefined) {
788
+ fee = {
789
+ 'cost': feeCost,
790
+ 'currency': feeCurrency,
791
+ };
792
+ }
793
+ const tradeId = this.safeString2(trade, 'trade-id', 'tradeId');
794
+ const id = this.safeString(trade, 'id', tradeId);
795
+ return this.safeTrade({
796
+ 'info': trade,
797
+ 'id': id,
798
+ 'symbol': symbol,
799
+ 'order': order,
800
+ 'timestamp': timestamp,
801
+ 'datetime': this.iso8601(timestamp),
802
+ 'type': type,
803
+ 'side': side,
804
+ 'takerOrMaker': takerOrMaker,
805
+ 'price': price,
806
+ 'amount': amount,
807
+ 'cost': cost,
808
+ 'fee': fee,
809
+ });
810
+ }
811
+ async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
812
+ /**
813
+ * @method
814
+ * @name huobijp#fetchOrderTrades
815
+ * @description fetch all the trades made from a single order
816
+ * @param {string} id order id
817
+ * @param {string} symbol unified market symbol
818
+ * @param {int} [since] the earliest time in ms to fetch trades for
819
+ * @param {int} [limit] the maximum number of trades to retrieve
820
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
821
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
822
+ */
823
+ await this.loadMarkets();
824
+ const request = {
825
+ 'id': id,
826
+ };
827
+ const response = await this.privateGetOrderOrdersIdMatchresults(this.extend(request, params));
828
+ return this.parseTrades(response['data'], undefined, since, limit);
829
+ }
830
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
831
+ /**
832
+ * @method
833
+ * @name huobijp#fetchMyTrades
834
+ * @description fetch all trades made by the user
835
+ * @param {string} symbol unified market symbol
836
+ * @param {int} [since] the earliest time in ms to fetch trades for
837
+ * @param {int} [limit] the maximum number of trades structures to retrieve
838
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
839
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
840
+ */
841
+ await this.loadMarkets();
842
+ let market = undefined;
843
+ const request = {};
844
+ if (symbol !== undefined) {
845
+ market = this.market(symbol);
846
+ request['symbol'] = market['id'];
847
+ }
848
+ if (limit !== undefined) {
849
+ request['size'] = limit; // 1-100 orders, default is 100
850
+ }
851
+ if (since !== undefined) {
852
+ request['start-time'] = since; // a date within 120 days from today
853
+ // request['end-time'] = this.sum (since, 172800000); // 48 hours window
854
+ }
855
+ const response = await this.privateGetOrderMatchresults(this.extend(request, params));
856
+ return this.parseTrades(response['data'], market, since, limit);
857
+ }
858
+ async fetchTrades(symbol, since = undefined, limit = 1000, params = {}) {
859
+ /**
860
+ * @method
861
+ * @name huobijp#fetchTrades
862
+ * @description get the list of most recent trades for a particular symbol
863
+ * @param {string} symbol unified symbol of the market to fetch trades for
864
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
865
+ * @param {int} [limit] the maximum amount of trades to fetch
866
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
867
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
868
+ */
869
+ await this.loadMarkets();
870
+ const market = this.market(symbol);
871
+ const request = {
872
+ 'symbol': market['id'],
873
+ };
874
+ if (limit !== undefined) {
875
+ request['size'] = Math.min(limit, 2000);
876
+ }
877
+ const response = await this.marketGetHistoryTrade(this.extend(request, params));
878
+ //
879
+ // {
880
+ // "status": "ok",
881
+ // "ch": "market.btcusdt.trade.detail",
882
+ // "ts": 1583497692365,
883
+ // "data": [
884
+ // {
885
+ // "id": 105005170342,
886
+ // "ts": 1583497692182,
887
+ // "data": [
888
+ // {
889
+ // "amount": 0.010411000000000000,
890
+ // "trade-id": 102090736910,
891
+ // "ts": 1583497692182,
892
+ // "id": 10500517034273194594947,
893
+ // "price": 9096.050000000000000000,
894
+ // "direction": "sell"
895
+ // }
896
+ // ]
897
+ // },
898
+ // // ...
899
+ // ]
900
+ // }
901
+ //
902
+ const data = this.safeValue(response, 'data', []);
903
+ let result = [];
904
+ for (let i = 0; i < data.length; i++) {
905
+ const trades = this.safeValue(data[i], 'data', []);
906
+ for (let j = 0; j < trades.length; j++) {
907
+ const trade = this.parseTrade(trades[j], market);
908
+ result.push(trade);
909
+ }
910
+ }
911
+ result = this.sortBy(result, 'timestamp');
912
+ return this.filterBySymbolSinceLimit(result, market['symbol'], since, limit);
913
+ }
914
+ parseOHLCV(ohlcv, market = undefined) {
915
+ //
916
+ // {
917
+ // "amount":1.2082,
918
+ // "open":0.025096,
919
+ // "close":0.025095,
920
+ // "high":0.025096,
921
+ // "id":1591515300,
922
+ // "count":6,
923
+ // "low":0.025095,
924
+ // "vol":0.0303205097
925
+ // }
926
+ //
927
+ return [
928
+ this.safeTimestamp(ohlcv, 'id'),
929
+ this.safeNumber(ohlcv, 'open'),
930
+ this.safeNumber(ohlcv, 'high'),
931
+ this.safeNumber(ohlcv, 'low'),
932
+ this.safeNumber(ohlcv, 'close'),
933
+ this.safeNumber(ohlcv, 'amount'),
934
+ ];
935
+ }
936
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = 1000, params = {}) {
937
+ /**
938
+ * @method
939
+ * @name huobijp#fetchOHLCV
940
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
941
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
942
+ * @param {string} timeframe the length of time each candle represents
943
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
944
+ * @param {int} [limit] the maximum amount of candles to fetch
945
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
946
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
947
+ */
948
+ await this.loadMarkets();
949
+ const market = this.market(symbol);
950
+ const request = {
951
+ 'symbol': market['id'],
952
+ 'period': this.safeString(this.timeframes, timeframe, timeframe),
953
+ };
954
+ if (limit !== undefined) {
955
+ request['size'] = limit;
956
+ }
957
+ const response = await this.marketGetHistoryKline(this.extend(request, params));
958
+ //
959
+ // {
960
+ // "status":"ok",
961
+ // "ch":"market.ethbtc.kline.1min",
962
+ // "ts":1591515374371,
963
+ // "data":[
964
+ // {"amount":0.0,"open":0.025095,"close":0.025095,"high":0.025095,"id":1591515360,"count":0,"low":0.025095,"vol":0.0},
965
+ // {"amount":1.2082,"open":0.025096,"close":0.025095,"high":0.025096,"id":1591515300,"count":6,"low":0.025095,"vol":0.0303205097},
966
+ // {"amount":0.0648,"open":0.025096,"close":0.025096,"high":0.025096,"id":1591515240,"count":2,"low":0.025096,"vol":0.0016262208},
967
+ // ]
968
+ // }
969
+ //
970
+ const data = this.safeValue(response, 'data', []);
971
+ return this.parseOHLCVs(data, market, timeframe, since, limit);
972
+ }
973
+ async fetchAccounts(params = {}) {
974
+ /**
975
+ * @method
976
+ * @name huobijp#fetchAccounts
977
+ * @description fetch all the accounts associated with a profile
978
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
979
+ * @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
980
+ */
981
+ await this.loadMarkets();
982
+ const response = await this.privateGetAccountAccounts(params);
983
+ return response['data'];
984
+ }
985
+ async fetchCurrencies(params = {}) {
986
+ /**
987
+ * @method
988
+ * @name huobijp#fetchCurrencies
989
+ * @description fetches all available currencies on an exchange
990
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
991
+ * @returns {object} an associative dictionary of currencies
992
+ */
993
+ const request = {
994
+ 'language': this.options['language'],
995
+ };
996
+ const response = await this.publicGetSettingsCurrencys(this.extend(request, params));
997
+ //
998
+ // {
999
+ // "status":"ok",
1000
+ // "data":[
1001
+ // {
1002
+ // "currency-addr-with-tag":false,
1003
+ // "fast-confirms":12,
1004
+ // "safe-confirms":12,
1005
+ // "currency-type":"eth",
1006
+ // "quote-currency":true,
1007
+ // "withdraw-enable-timestamp":1609430400000,
1008
+ // "deposit-enable-timestamp":1609430400000,
1009
+ // "currency-partition":"all",
1010
+ // "support-sites":["OTC","INSTITUTION","MINEPOOL"],
1011
+ // "withdraw-precision":6,
1012
+ // "visible-assets-timestamp":1508839200000,
1013
+ // "deposit-min-amount":"1",
1014
+ // "withdraw-min-amount":"10",
1015
+ // "show-precision":"8",
1016
+ // "tags":"",
1017
+ // "weight":23,
1018
+ // "full-name":"Tether USDT",
1019
+ // "otc-enable":1,
1020
+ // "visible":true,
1021
+ // "white-enabled":false,
1022
+ // "country-disabled":false,
1023
+ // "deposit-enabled":true,
1024
+ // "withdraw-enabled":true,
1025
+ // "name":"usdt",
1026
+ // "state":"online",
1027
+ // "display-name":"USDT",
1028
+ // "suspend-withdraw-desc":null,
1029
+ // "withdraw-desc":"Minimum withdrawal amount: 10 USDT (ERC20). !>_<!To ensure the safety of your funds, your withdrawal request will be manually reviewed if your security strategy or password is changed. Please wait for phone calls or emails from our staff.!>_<!Please make sure that your computer and browser are secure and your information is protected from being tampered or leaked.",
1030
+ // "suspend-deposit-desc":null,
1031
+ // "deposit-desc":"Please don’t deposit any other digital assets except USDT to the above address. Otherwise, you may lose your assets permanently. !>_<!Depositing to the above address requires confirmations of the entire network. It will arrive after 12 confirmations, and it will be available to withdraw after 12 confirmations. !>_<!Minimum deposit amount: 1 USDT. Any deposits less than the minimum will not be credited or refunded.!>_<!Your deposit address won’t change often. If there are any changes, we will notify you via announcement or email.!>_<!Please make sure that your computer and browser are secure and your information is protected from being tampered or leaked.",
1032
+ // "suspend-visible-desc":null
1033
+ // }
1034
+ // ]
1035
+ // }
1036
+ //
1037
+ const currencies = this.safeValue(response, 'data', []);
1038
+ const result = {};
1039
+ for (let i = 0; i < currencies.length; i++) {
1040
+ const currency = currencies[i];
1041
+ const id = this.safeValue(currency, 'name');
1042
+ const code = this.safeCurrencyCode(id);
1043
+ const depositEnabled = this.safeValue(currency, 'deposit-enabled');
1044
+ const withdrawEnabled = this.safeValue(currency, 'withdraw-enabled');
1045
+ const countryDisabled = this.safeValue(currency, 'country-disabled');
1046
+ const visible = this.safeValue(currency, 'visible', false);
1047
+ const state = this.safeString(currency, 'state');
1048
+ const active = visible && depositEnabled && withdrawEnabled && (state === 'online') && !countryDisabled;
1049
+ const name = this.safeString(currency, 'display-name');
1050
+ const precision = this.parseNumber(this.parsePrecision(this.safeString(currency, 'withdraw-precision')));
1051
+ result[code] = {
1052
+ 'id': id,
1053
+ 'code': code,
1054
+ 'type': 'crypto',
1055
+ // 'payin': currency['deposit-enabled'],
1056
+ // 'payout': currency['withdraw-enabled'],
1057
+ // 'transfer': undefined,
1058
+ 'name': name,
1059
+ 'active': active,
1060
+ 'deposit': depositEnabled,
1061
+ 'withdraw': withdrawEnabled,
1062
+ 'fee': undefined,
1063
+ 'precision': precision,
1064
+ 'limits': {
1065
+ 'amount': {
1066
+ 'min': precision,
1067
+ 'max': undefined,
1068
+ },
1069
+ 'deposit': {
1070
+ 'min': this.safeNumber(currency, 'deposit-min-amount'),
1071
+ 'max': undefined,
1072
+ },
1073
+ 'withdraw': {
1074
+ 'min': this.safeNumber(currency, 'withdraw-min-amount'),
1075
+ 'max': undefined,
1076
+ },
1077
+ },
1078
+ 'info': currency,
1079
+ };
1080
+ }
1081
+ return result;
1082
+ }
1083
+ parseBalance(response) {
1084
+ const balances = this.safeValue(response['data'], 'list', []);
1085
+ const result = { 'info': response };
1086
+ for (let i = 0; i < balances.length; i++) {
1087
+ const balance = balances[i];
1088
+ const currencyId = this.safeString(balance, 'currency');
1089
+ const code = this.safeCurrencyCode(currencyId);
1090
+ let account = undefined;
1091
+ if (code in result) {
1092
+ account = result[code];
1093
+ }
1094
+ else {
1095
+ account = this.account();
1096
+ }
1097
+ if (balance['type'] === 'trade') {
1098
+ account['free'] = this.safeString(balance, 'balance');
1099
+ }
1100
+ if (balance['type'] === 'frozen') {
1101
+ account['used'] = this.safeString(balance, 'balance');
1102
+ }
1103
+ result[code] = account;
1104
+ }
1105
+ return this.safeBalance(result);
1106
+ }
1107
+ async fetchBalance(params = {}) {
1108
+ /**
1109
+ * @method
1110
+ * @name huobijp#fetchBalance
1111
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
1112
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1113
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1114
+ */
1115
+ await this.loadMarkets();
1116
+ await this.loadAccounts();
1117
+ const method = this.options['fetchBalanceMethod'];
1118
+ const request = {
1119
+ 'id': this.accounts[0]['id'],
1120
+ };
1121
+ const response = await this[method](this.extend(request, params));
1122
+ return this.parseBalance(response);
1123
+ }
1124
+ async fetchOrdersByStates(states, symbol = undefined, since = undefined, limit = undefined, params = {}) {
1125
+ await this.loadMarkets();
1126
+ const request = {
1127
+ 'states': states,
1128
+ };
1129
+ let market = undefined;
1130
+ if (symbol !== undefined) {
1131
+ market = this.market(symbol);
1132
+ request['symbol'] = market['id'];
1133
+ }
1134
+ const method = this.safeString(this.options, 'fetchOrdersByStatesMethod', 'private_get_order_orders');
1135
+ const response = await this[method](this.extend(request, params));
1136
+ //
1137
+ // { "status": "ok",
1138
+ // "data": [ { id: 13997833014,
1139
+ // "symbol": "ethbtc",
1140
+ // "account-id": 3398321,
1141
+ // "amount": "0.045000000000000000",
1142
+ // "price": "0.034014000000000000",
1143
+ // "created-at": 1545836976871,
1144
+ // "type": "sell-limit",
1145
+ // "field-amount": "0.045000000000000000",
1146
+ // "field-cash-amount": "0.001530630000000000",
1147
+ // "field-fees": "0.000003061260000000",
1148
+ // "finished-at": 1545837948214,
1149
+ // "source": "spot-api",
1150
+ // "state": "filled",
1151
+ // "canceled-at": 0 } ] }
1152
+ //
1153
+ return this.parseOrders(response['data'], market, since, limit);
1154
+ }
1155
+ async fetchOrder(id, symbol = undefined, params = {}) {
1156
+ /**
1157
+ * @method
1158
+ * @name huobijp#fetchOrder
1159
+ * @description fetches information on an order made by the user
1160
+ * @param {string} symbol unified symbol of the market the order was made in
1161
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1162
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1163
+ */
1164
+ await this.loadMarkets();
1165
+ const request = {
1166
+ 'id': id,
1167
+ };
1168
+ const response = await this.privateGetOrderOrdersId(this.extend(request, params));
1169
+ const order = this.safeValue(response, 'data');
1170
+ return this.parseOrder(order);
1171
+ }
1172
+ async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1173
+ /**
1174
+ * @method
1175
+ * @name huobijp#fetchOrders
1176
+ * @description fetches information on multiple orders made by the user
1177
+ * @param {string} symbol unified market symbol of the market orders were made in
1178
+ * @param {int} [since] the earliest time in ms to fetch orders for
1179
+ * @param {int} [limit] the maximum number of order structures to retrieve
1180
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1181
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1182
+ */
1183
+ return await this.fetchOrdersByStates('pre-submitted,submitted,partial-filled,filled,partial-canceled,canceled', symbol, since, limit, params);
1184
+ }
1185
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1186
+ /**
1187
+ * @method
1188
+ * @name huobijp#fetchOpenOrders
1189
+ * @description fetch all unfilled currently open orders
1190
+ * @param {string} symbol unified market symbol
1191
+ * @param {int} [since] the earliest time in ms to fetch open orders for
1192
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
1193
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1194
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1195
+ */
1196
+ const method = this.safeString(this.options, 'fetchOpenOrdersMethod', 'fetch_open_orders_v1');
1197
+ return await this[method](symbol, since, limit, params);
1198
+ }
1199
+ async fetchOpenOrdersV1(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1200
+ if (symbol === undefined) {
1201
+ throw new errors.ArgumentsRequired(this.id + ' fetchOpenOrdersV1() requires a symbol argument');
1202
+ }
1203
+ return await this.fetchOrdersByStates('pre-submitted,submitted,partial-filled', symbol, since, limit, params);
1204
+ }
1205
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1206
+ /**
1207
+ * @method
1208
+ * @name huobijp#fetchClosedOrders
1209
+ * @description fetches information on multiple closed orders made by the user
1210
+ * @param {string} symbol unified market symbol of the market orders were made in
1211
+ * @param {int} [since] the earliest time in ms to fetch orders for
1212
+ * @param {int} [limit] the maximum number of order structures to retrieve
1213
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1214
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1215
+ */
1216
+ return await this.fetchOrdersByStates('filled,partial-canceled,canceled', symbol, since, limit, params);
1217
+ }
1218
+ async fetchOpenOrdersV2(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1219
+ await this.loadMarkets();
1220
+ const request = {};
1221
+ let market = undefined;
1222
+ if (symbol !== undefined) {
1223
+ market = this.market(symbol);
1224
+ request['symbol'] = market['id'];
1225
+ }
1226
+ let accountId = this.safeString(params, 'account-id');
1227
+ if (accountId === undefined) {
1228
+ // pick the first account
1229
+ await this.loadAccounts();
1230
+ for (let i = 0; i < this.accounts.length; i++) {
1231
+ const account = this.accounts[i];
1232
+ if (account['type'] === 'spot') {
1233
+ accountId = this.safeString(account, 'id');
1234
+ if (accountId !== undefined) {
1235
+ break;
1236
+ }
1237
+ }
1238
+ }
1239
+ }
1240
+ request['account-id'] = accountId;
1241
+ if (limit !== undefined) {
1242
+ request['size'] = limit;
1243
+ }
1244
+ const omitted = this.omit(params, 'account-id');
1245
+ const response = await this.privateGetOrderOpenOrders(this.extend(request, omitted));
1246
+ //
1247
+ // {
1248
+ // "status":"ok",
1249
+ // "data":[
1250
+ // {
1251
+ // "symbol":"ethusdt",
1252
+ // "source":"api",
1253
+ // "amount":"0.010000000000000000",
1254
+ // "account-id":1528640,
1255
+ // "created-at":1561597491963,
1256
+ // "price":"400.000000000000000000",
1257
+ // "filled-amount":"0.0",
1258
+ // "filled-cash-amount":"0.0",
1259
+ // "filled-fees":"0.0",
1260
+ // "id":38477101630,
1261
+ // "state":"submitted",
1262
+ // "type":"sell-limit"
1263
+ // }
1264
+ // ]
1265
+ // }
1266
+ //
1267
+ const data = this.safeValue(response, 'data', []);
1268
+ return this.parseOrders(data, market, since, limit);
1269
+ }
1270
+ parseOrderStatus(status) {
1271
+ const statuses = {
1272
+ 'partial-filled': 'open',
1273
+ 'partial-canceled': 'canceled',
1274
+ 'filled': 'closed',
1275
+ 'canceled': 'canceled',
1276
+ 'submitted': 'open',
1277
+ };
1278
+ return this.safeString(statuses, status, status);
1279
+ }
1280
+ parseOrder(order, market = undefined) {
1281
+ //
1282
+ // { id: 13997833014,
1283
+ // "symbol": "ethbtc",
1284
+ // "account-id": 3398321,
1285
+ // "amount": "0.045000000000000000",
1286
+ // "price": "0.034014000000000000",
1287
+ // "created-at": 1545836976871,
1288
+ // "type": "sell-limit",
1289
+ // "field-amount": "0.045000000000000000", // they have fixed it for filled-amount
1290
+ // "field-cash-amount": "0.001530630000000000", // they have fixed it for filled-cash-amount
1291
+ // "field-fees": "0.000003061260000000", // they have fixed it for filled-fees
1292
+ // "finished-at": 1545837948214,
1293
+ // "source": "spot-api",
1294
+ // "state": "filled",
1295
+ // "canceled-at": 0 }
1296
+ //
1297
+ // { id: 20395337822,
1298
+ // "symbol": "ethbtc",
1299
+ // "account-id": 5685075,
1300
+ // "amount": "0.001000000000000000",
1301
+ // "price": "0.0",
1302
+ // "created-at": 1545831584023,
1303
+ // "type": "buy-market",
1304
+ // "field-amount": "0.029100000000000000", // they have fixed it for filled-amount
1305
+ // "field-cash-amount": "0.000999788700000000", // they have fixed it for filled-cash-amount
1306
+ // "field-fees": "0.000058200000000000", // they have fixed it for filled-fees
1307
+ // "finished-at": 1545831584181,
1308
+ // "source": "spot-api",
1309
+ // "state": "filled",
1310
+ // "canceled-at": 0 }
1311
+ //
1312
+ const id = this.safeString(order, 'id');
1313
+ let side = undefined;
1314
+ let type = undefined;
1315
+ let status = undefined;
1316
+ if ('type' in order) {
1317
+ const orderType = order['type'].split('-');
1318
+ side = orderType[0];
1319
+ type = orderType[1];
1320
+ status = this.parseOrderStatus(this.safeString(order, 'state'));
1321
+ }
1322
+ const marketId = this.safeString(order, 'symbol');
1323
+ market = this.safeMarket(marketId, market);
1324
+ const timestamp = this.safeInteger(order, 'created-at');
1325
+ const clientOrderId = this.safeString(order, 'client-order-id');
1326
+ const amount = this.safeString(order, 'amount');
1327
+ const filled = this.safeString2(order, 'filled-amount', 'field-amount'); // typo in their API, filled amount
1328
+ const price = this.safeString(order, 'price');
1329
+ const cost = this.safeString2(order, 'filled-cash-amount', 'field-cash-amount'); // same typo
1330
+ const feeCost = this.safeString2(order, 'filled-fees', 'field-fees'); // typo in their API, filled fees
1331
+ let fee = undefined;
1332
+ if (feeCost !== undefined) {
1333
+ const feeCurrency = (side === 'sell') ? market['quote'] : market['base'];
1334
+ fee = {
1335
+ 'cost': feeCost,
1336
+ 'currency': feeCurrency,
1337
+ };
1338
+ }
1339
+ return this.safeOrder({
1340
+ 'info': order,
1341
+ 'id': id,
1342
+ 'clientOrderId': clientOrderId,
1343
+ 'timestamp': timestamp,
1344
+ 'datetime': this.iso8601(timestamp),
1345
+ 'lastTradeTimestamp': undefined,
1346
+ 'symbol': market['symbol'],
1347
+ 'type': type,
1348
+ 'timeInForce': undefined,
1349
+ 'postOnly': undefined,
1350
+ 'side': side,
1351
+ 'price': price,
1352
+ 'stopPrice': undefined,
1353
+ 'triggerPrice': undefined,
1354
+ 'average': undefined,
1355
+ 'cost': cost,
1356
+ 'amount': amount,
1357
+ 'filled': filled,
1358
+ 'remaining': undefined,
1359
+ 'status': status,
1360
+ 'fee': fee,
1361
+ 'trades': undefined,
1362
+ }, market);
1363
+ }
1364
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1365
+ /**
1366
+ * @method
1367
+ * @name huobijp#createMarketBuyOrderWithCost
1368
+ * @description create a market buy order by providing the symbol and cost
1369
+ * @param {string} symbol unified symbol of the market to create an order in
1370
+ * @param {float} cost how much you want to trade in units of the quote currency
1371
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1372
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1373
+ */
1374
+ await this.loadMarkets();
1375
+ const market = this.market(symbol);
1376
+ if (!market['spot']) {
1377
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
1378
+ }
1379
+ params['createMarketBuyOrderRequiresPrice'] = false;
1380
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1381
+ }
1382
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1383
+ /**
1384
+ * @method
1385
+ * @name huobijp#createOrder
1386
+ * @description create a trade order
1387
+ * @param {string} symbol unified symbol of the market to create an order in
1388
+ * @param {string} type 'market' or 'limit'
1389
+ * @param {string} side 'buy' or 'sell'
1390
+ * @param {float} amount how much of currency you want to trade in units of base currency
1391
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1392
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1393
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1394
+ */
1395
+ await this.loadMarkets();
1396
+ await this.loadAccounts();
1397
+ const market = this.market(symbol);
1398
+ const request = {
1399
+ 'account-id': this.accounts[0]['id'],
1400
+ 'symbol': market['id'],
1401
+ 'type': side + '-' + type,
1402
+ };
1403
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'client-order-id'); // must be 64 chars max and unique within 24 hours
1404
+ if (clientOrderId === undefined) {
1405
+ const broker = this.safeValue(this.options, 'broker', {});
1406
+ const brokerId = this.safeString(broker, 'id');
1407
+ request['client-order-id'] = brokerId + this.uuid();
1408
+ }
1409
+ else {
1410
+ request['client-order-id'] = clientOrderId;
1411
+ }
1412
+ params = this.omit(params, ['clientOrderId', 'client-order-id']);
1413
+ if ((type === 'market') && (side === 'buy')) {
1414
+ let quoteAmount = undefined;
1415
+ let createMarketBuyOrderRequiresPrice = true;
1416
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1417
+ const cost = this.safeNumber(params, 'cost');
1418
+ params = this.omit(params, 'cost');
1419
+ if (cost !== undefined) {
1420
+ quoteAmount = this.amountToPrecision(symbol, cost);
1421
+ }
1422
+ else if (createMarketBuyOrderRequiresPrice) {
1423
+ if (price === undefined) {
1424
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument');
1425
+ }
1426
+ else {
1427
+ // despite that cost = amount * price is in quote currency and should have quote precision
1428
+ // the exchange API requires the cost supplied in 'amount' to be of base precision
1429
+ // more about it here:
1430
+ // https://github.com/ccxt/ccxt/pull/4395
1431
+ // https://github.com/ccxt/ccxt/issues/7611
1432
+ // we use amountToPrecision here because the exchange requires cost in base precision
1433
+ const amountString = this.numberToString(amount);
1434
+ const priceString = this.numberToString(price);
1435
+ quoteAmount = this.amountToPrecision(symbol, Precise["default"].stringMul(amountString, priceString));
1436
+ }
1437
+ }
1438
+ else {
1439
+ quoteAmount = this.amountToPrecision(symbol, amount);
1440
+ }
1441
+ request['amount'] = quoteAmount;
1442
+ }
1443
+ else {
1444
+ request['amount'] = this.amountToPrecision(symbol, amount);
1445
+ }
1446
+ if (type === 'limit' || type === 'ioc' || type === 'limit-maker' || type === 'stop-limit' || type === 'stop-limit-fok') {
1447
+ request['price'] = this.priceToPrecision(symbol, price);
1448
+ }
1449
+ const method = this.options['createOrderMethod'];
1450
+ const response = await this[method](this.extend(request, params));
1451
+ const id = this.safeString(response, 'data');
1452
+ return this.safeOrder({
1453
+ 'info': response,
1454
+ 'id': id,
1455
+ 'timestamp': undefined,
1456
+ 'datetime': undefined,
1457
+ 'lastTradeTimestamp': undefined,
1458
+ 'status': undefined,
1459
+ 'symbol': symbol,
1460
+ 'type': type,
1461
+ 'side': side,
1462
+ 'price': price,
1463
+ 'amount': amount,
1464
+ 'filled': undefined,
1465
+ 'remaining': undefined,
1466
+ 'cost': undefined,
1467
+ 'trades': undefined,
1468
+ 'fee': undefined,
1469
+ 'clientOrderId': undefined,
1470
+ 'average': undefined,
1471
+ }, market);
1472
+ }
1473
+ async cancelOrder(id, symbol = undefined, params = {}) {
1474
+ /**
1475
+ * @method
1476
+ * @name huobijp#cancelOrder
1477
+ * @description cancels an open order
1478
+ * @param {string} id order id
1479
+ * @param {string} symbol not used by huobijp cancelOrder ()
1480
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1481
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1482
+ */
1483
+ const response = await this.privatePostOrderOrdersIdSubmitcancel({ 'id': id });
1484
+ //
1485
+ // {
1486
+ // "status": "ok",
1487
+ // "data": "10138899000",
1488
+ // }
1489
+ //
1490
+ return this.extend(this.parseOrder(response), {
1491
+ 'id': id,
1492
+ 'status': 'canceled',
1493
+ });
1494
+ }
1495
+ async cancelOrders(ids, symbol = undefined, params = {}) {
1496
+ /**
1497
+ * @method
1498
+ * @name huobijp#cancelOrders
1499
+ * @description cancel multiple orders
1500
+ * @param {string[]} ids order ids
1501
+ * @param {string} symbol not used by huobijp cancelOrders ()
1502
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1503
+ * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1504
+ */
1505
+ await this.loadMarkets();
1506
+ const clientOrderIds = this.safeValue2(params, 'clientOrderIds', 'client-order-ids');
1507
+ params = this.omit(params, ['clientOrderIds', 'client-order-ids']);
1508
+ const request = {};
1509
+ if (clientOrderIds === undefined) {
1510
+ request['order-ids'] = ids;
1511
+ }
1512
+ else {
1513
+ request['client-order-ids'] = clientOrderIds;
1514
+ }
1515
+ const response = await this.privatePostOrderOrdersBatchcancel(this.extend(request, params));
1516
+ //
1517
+ // {
1518
+ // "status": "ok",
1519
+ // "data": {
1520
+ // "success": [
1521
+ // "5983466"
1522
+ // ],
1523
+ // "failed": [
1524
+ // {
1525
+ // "err-msg": "Incorrect order state",
1526
+ // "order-state": 7,
1527
+ // "order-id": "",
1528
+ // "err-code": "order-orderstate-error",
1529
+ // "client-order-id": "first"
1530
+ // },
1531
+ // {
1532
+ // "err-msg": "Incorrect order state",
1533
+ // "order-state": 7,
1534
+ // "order-id": "",
1535
+ // "err-code": "order-orderstate-error",
1536
+ // "client-order-id": "second"
1537
+ // },
1538
+ // {
1539
+ // "err-msg": "The record is not found.",
1540
+ // "order-id": "",
1541
+ // "err-code": "base-not-found",
1542
+ // "client-order-id": "third"
1543
+ // }
1544
+ // ]
1545
+ // }
1546
+ // }
1547
+ //
1548
+ return response;
1549
+ }
1550
+ async cancelAllOrders(symbol = undefined, params = {}) {
1551
+ /**
1552
+ * @method
1553
+ * @name huobijp#cancelAllOrders
1554
+ * @description cancel all open orders
1555
+ * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1556
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1557
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1558
+ */
1559
+ await this.loadMarkets();
1560
+ const request = {
1561
+ // 'account-id' string false NA The account id used for this cancel Refer to GET /v1/account/accounts
1562
+ // 'symbol': market['id'], // a list of comma-separated symbols, all symbols by default
1563
+ // 'types' 'string', buy-market, sell-market, buy-limit, sell-limit, buy-ioc, sell-ioc, buy-stop-limit, sell-stop-limit, buy-limit-fok, sell-limit-fok, buy-stop-limit-fok, sell-stop-limit-fok
1564
+ // 'side': 'buy', // or 'sell'
1565
+ // 'size': 100, // the number of orders to cancel 1-100
1566
+ };
1567
+ let market = undefined;
1568
+ if (symbol !== undefined) {
1569
+ market = this.market(symbol);
1570
+ request['symbol'] = market['id'];
1571
+ }
1572
+ const response = await this.privatePostOrderOrdersBatchCancelOpenOrders(this.extend(request, params));
1573
+ //
1574
+ // {
1575
+ // "code": 200,
1576
+ // "data": {
1577
+ // "success-count": 2,
1578
+ // "failed-count": 0,
1579
+ // "next-id": 5454600
1580
+ // }
1581
+ // }
1582
+ //
1583
+ return response;
1584
+ }
1585
+ currencyToPrecision(code, fee, networkCode = undefined) {
1586
+ return this.decimalToPrecision(fee, 0, this.currencies[code]['precision'], this.precisionMode);
1587
+ }
1588
+ safeNetwork(networkId) {
1589
+ const lastCharacterIndex = networkId.length - 1;
1590
+ const lastCharacter = networkId[lastCharacterIndex];
1591
+ if (lastCharacter === '1') {
1592
+ networkId = networkId.slice(0, lastCharacterIndex);
1593
+ }
1594
+ const networksById = {};
1595
+ return this.safeString(networksById, networkId, networkId);
1596
+ }
1597
+ parseDepositAddress(depositAddress, currency = undefined) {
1598
+ //
1599
+ // {
1600
+ // "currency": "usdt",
1601
+ // "address": "0xf7292eb9ba7bc50358e27f0e025a4d225a64127b",
1602
+ // "addressTag": "",
1603
+ // "chain": "usdterc20", // trc20usdt, hrc20usdt, usdt, algousdt
1604
+ // }
1605
+ //
1606
+ const address = this.safeString(depositAddress, 'address');
1607
+ const tag = this.safeString(depositAddress, 'addressTag');
1608
+ const currencyId = this.safeString(depositAddress, 'currency');
1609
+ currency = this.safeCurrency(currencyId, currency);
1610
+ const code = this.safeCurrencyCode(currencyId, currency);
1611
+ const networkId = this.safeString(depositAddress, 'chain');
1612
+ const networks = this.safeValue(currency, 'networks', {});
1613
+ const networksById = this.indexBy(networks, 'id');
1614
+ const networkValue = this.safeValue(networksById, networkId, networkId);
1615
+ const network = this.safeString(networkValue, 'network');
1616
+ this.checkAddress(address);
1617
+ return {
1618
+ 'currency': code,
1619
+ 'address': address,
1620
+ 'tag': tag,
1621
+ 'network': network,
1622
+ 'info': depositAddress,
1623
+ };
1624
+ }
1625
+ async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
1626
+ /**
1627
+ * @method
1628
+ * @name huobijp#fetchDeposits
1629
+ * @description fetch all deposits made to an account
1630
+ * @param {string} code unified currency code
1631
+ * @param {int} [since] the earliest time in ms to fetch deposits for
1632
+ * @param {int} [limit] the maximum number of deposits structures to retrieve
1633
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1634
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1635
+ */
1636
+ if (limit === undefined || limit > 100) {
1637
+ limit = 100;
1638
+ }
1639
+ await this.loadMarkets();
1640
+ let currency = undefined;
1641
+ if (code !== undefined) {
1642
+ currency = this.currency(code);
1643
+ }
1644
+ const request = {
1645
+ 'type': 'deposit',
1646
+ 'from': 0, // From 'id' ... if you want to get results after a particular transaction id, pass the id in params.from
1647
+ };
1648
+ if (currency !== undefined) {
1649
+ request['currency'] = currency['id'];
1650
+ }
1651
+ if (limit !== undefined) {
1652
+ request['size'] = limit; // max 100
1653
+ }
1654
+ const response = await this.privateGetQueryDepositWithdraw(this.extend(request, params));
1655
+ // return response
1656
+ return this.parseTransactions(response['data'], currency, since, limit);
1657
+ }
1658
+ async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
1659
+ /**
1660
+ * @method
1661
+ * @name huobijp#fetchWithdrawals
1662
+ * @description fetch all withdrawals made from an account
1663
+ * @param {string} code unified currency code
1664
+ * @param {int} [since] the earliest time in ms to fetch withdrawals for
1665
+ * @param {int} [limit] the maximum number of withdrawals structures to retrieve
1666
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1667
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1668
+ */
1669
+ if (limit === undefined || limit > 100) {
1670
+ limit = 100;
1671
+ }
1672
+ await this.loadMarkets();
1673
+ let currency = undefined;
1674
+ if (code !== undefined) {
1675
+ currency = this.currency(code);
1676
+ }
1677
+ const request = {
1678
+ 'type': 'withdraw',
1679
+ 'from': 0, // From 'id' ... if you want to get results after a particular transaction id, pass the id in params.from
1680
+ };
1681
+ if (currency !== undefined) {
1682
+ request['currency'] = currency['id'];
1683
+ }
1684
+ if (limit !== undefined) {
1685
+ request['size'] = limit; // max 100
1686
+ }
1687
+ const response = await this.privateGetQueryDepositWithdraw(this.extend(request, params));
1688
+ // return response
1689
+ return this.parseTransactions(response['data'], currency, since, limit);
1690
+ }
1691
+ parseTransaction(transaction, currency = undefined) {
1692
+ //
1693
+ // fetchDeposits
1694
+ //
1695
+ // {
1696
+ // "id": 8211029,
1697
+ // "type": "deposit",
1698
+ // "currency": "eth",
1699
+ // "chain": "eth",
1700
+ // 'tx-hash': "bd315....",
1701
+ // "amount": 0.81162421,
1702
+ // "address": "4b8b....",
1703
+ // 'address-tag": '",
1704
+ // "fee": 0,
1705
+ // "state": "safe",
1706
+ // "created-at": 1542180380965,
1707
+ // "updated-at": 1542180788077
1708
+ // }
1709
+ //
1710
+ // fetchWithdrawals
1711
+ //
1712
+ // {
1713
+ // "id": 6908275,
1714
+ // "type": "withdraw",
1715
+ // "currency": "btc",
1716
+ // "chain": "btc",
1717
+ // 'tx-hash': "c1a1a....",
1718
+ // "amount": 0.80257005,
1719
+ // "address": "1QR....",
1720
+ // 'address-tag": '",
1721
+ // "fee": 0.0005,
1722
+ // "state": "confirmed",
1723
+ // "created-at": 1552107295685,
1724
+ // "updated-at": 1552108032859
1725
+ // }
1726
+ //
1727
+ // withdraw
1728
+ //
1729
+ // {
1730
+ // "status": "ok",
1731
+ // "data": "99562054"
1732
+ // }
1733
+ //
1734
+ const timestamp = this.safeInteger(transaction, 'created-at');
1735
+ const code = this.safeCurrencyCode(this.safeString(transaction, 'currency'));
1736
+ let type = this.safeString(transaction, 'type');
1737
+ if (type === 'withdraw') {
1738
+ type = 'withdrawal';
1739
+ }
1740
+ let feeCost = this.safeString(transaction, 'fee');
1741
+ if (feeCost !== undefined) {
1742
+ feeCost = Precise["default"].stringAbs(feeCost);
1743
+ }
1744
+ return {
1745
+ 'info': transaction,
1746
+ 'id': this.safeString2(transaction, 'id', 'data'),
1747
+ 'txid': this.safeString(transaction, 'tx-hash'),
1748
+ 'timestamp': timestamp,
1749
+ 'datetime': this.iso8601(timestamp),
1750
+ 'network': this.safeStringUpper(transaction, 'chain'),
1751
+ 'address': this.safeString(transaction, 'address'),
1752
+ 'addressTo': undefined,
1753
+ 'addressFrom': undefined,
1754
+ 'tag': this.safeString(transaction, 'address-tag'),
1755
+ 'tagTo': undefined,
1756
+ 'tagFrom': undefined,
1757
+ 'type': type,
1758
+ 'amount': this.safeNumber(transaction, 'amount'),
1759
+ 'currency': code,
1760
+ 'status': this.parseTransactionStatus(this.safeString(transaction, 'state')),
1761
+ 'updated': this.safeInteger(transaction, 'updated-at'),
1762
+ 'comment': undefined,
1763
+ 'internal': undefined,
1764
+ 'fee': {
1765
+ 'currency': code,
1766
+ 'cost': this.parseNumber(feeCost),
1767
+ 'rate': undefined,
1768
+ },
1769
+ };
1770
+ }
1771
+ parseTransactionStatus(status) {
1772
+ const statuses = {
1773
+ // deposit statuses
1774
+ 'unknown': 'failed',
1775
+ 'confirming': 'pending',
1776
+ 'confirmed': 'ok',
1777
+ 'safe': 'ok',
1778
+ 'orphan': 'failed',
1779
+ // withdrawal statuses
1780
+ 'submitted': 'pending',
1781
+ 'canceled': 'canceled',
1782
+ 'reexamine': 'pending',
1783
+ 'reject': 'failed',
1784
+ 'pass': 'pending',
1785
+ 'wallet-reject': 'failed',
1786
+ // 'confirmed': 'ok', // present in deposit statuses
1787
+ 'confirm-error': 'failed',
1788
+ 'repealed': 'failed',
1789
+ 'wallet-transfer': 'pending',
1790
+ 'pre-transfer': 'pending',
1791
+ };
1792
+ return this.safeString(statuses, status, status);
1793
+ }
1794
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
1795
+ /**
1796
+ * @method
1797
+ * @name huobijp#withdraw
1798
+ * @description make a withdrawal
1799
+ * @param {string} code unified currency code
1800
+ * @param {float} amount the amount to withdraw
1801
+ * @param {string} address the address to withdraw to
1802
+ * @param {string} tag
1803
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1804
+ * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1805
+ */
1806
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
1807
+ await this.loadMarkets();
1808
+ this.checkAddress(address);
1809
+ const currency = this.currency(code);
1810
+ const request = {
1811
+ 'address': address,
1812
+ 'amount': amount,
1813
+ 'currency': currency['id'].toLowerCase(),
1814
+ };
1815
+ if (tag !== undefined) {
1816
+ request['addr-tag'] = tag; // only for XRP?
1817
+ }
1818
+ const networks = this.safeValue(this.options, 'networks', {});
1819
+ let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
1820
+ network = this.safeStringLower(networks, network, network); // handle ETH>ERC20 alias
1821
+ if (network !== undefined) {
1822
+ // possible chains - usdterc20, trc20usdt, hrc20usdt, usdt, algousdt
1823
+ if (network === 'erc20') {
1824
+ request['chain'] = currency['id'] + network;
1825
+ }
1826
+ else {
1827
+ request['chain'] = network + currency['id'];
1828
+ }
1829
+ params = this.omit(params, 'network');
1830
+ }
1831
+ const response = await this.privatePostDwWithdrawApiCreate(this.extend(request, params));
1832
+ //
1833
+ // {
1834
+ // "status": "ok",
1835
+ // "data": "99562054"
1836
+ // }
1837
+ //
1838
+ return this.parseTransaction(response, currency);
1839
+ }
1840
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1841
+ let url = '/';
1842
+ if (api === 'market') {
1843
+ url += api;
1844
+ }
1845
+ else if ((api === 'public') || (api === 'private')) {
1846
+ url += this.version;
1847
+ }
1848
+ else if ((api === 'v2Public') || (api === 'v2Private')) {
1849
+ url += 'v2';
1850
+ }
1851
+ url += '/' + this.implodeParams(path, params);
1852
+ const query = this.omit(params, this.extractParams(path));
1853
+ if (api === 'private' || api === 'v2Private') {
1854
+ this.checkRequiredCredentials();
1855
+ const timestamp = this.ymdhms(this.milliseconds(), 'T');
1856
+ let request = {
1857
+ 'SignatureMethod': 'HmacSHA256',
1858
+ 'SignatureVersion': '2',
1859
+ 'AccessKeyId': this.apiKey,
1860
+ 'Timestamp': timestamp,
1861
+ };
1862
+ if (method !== 'POST') {
1863
+ request = this.extend(request, query);
1864
+ }
1865
+ const requestSorted = this.keysort(request);
1866
+ let auth = this.urlencode(requestSorted);
1867
+ // unfortunately, PHP demands double quotes for the escaped newline symbol
1868
+ // eslint-disable-next-line quotes
1869
+ const payload = [method, this.hostname, url, auth].join("\n");
1870
+ const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256.sha256, 'base64');
1871
+ auth += '&' + this.urlencode({ 'Signature': signature });
1872
+ url += '?' + auth;
1873
+ if (method === 'POST') {
1874
+ body = this.json(query);
1875
+ headers = {
1876
+ 'Content-Type': 'application/json',
1877
+ };
1878
+ }
1879
+ else {
1880
+ headers = {
1881
+ 'Content-Type': 'application/x-www-form-urlencoded',
1882
+ };
1883
+ }
1884
+ }
1885
+ else {
1886
+ if (Object.keys(params).length) {
1887
+ url += '?' + this.urlencode(params);
1888
+ }
1889
+ }
1890
+ url = this.implodeParams(this.urls['api'][api], {
1891
+ 'hostname': this.hostname,
1892
+ }) + url;
1893
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1894
+ }
1895
+ handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1896
+ if (response === undefined) {
1897
+ return undefined; // fallback to default error handler
1898
+ }
1899
+ if ('status' in response) {
1900
+ //
1901
+ // {"status":"error","err-code":"order-limitorder-amount-min-error","err-msg":"limit order amount error, min: `0.001`","data":null}
1902
+ //
1903
+ const status = this.safeString(response, 'status');
1904
+ if (status === 'error') {
1905
+ const code = this.safeString(response, 'err-code');
1906
+ const feedback = this.id + ' ' + body;
1907
+ this.throwBroadlyMatchedException(this.exceptions['broad'], body, feedback);
1908
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
1909
+ const message = this.safeString(response, 'err-msg');
1910
+ this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
1911
+ throw new errors.ExchangeError(feedback);
1912
+ }
1913
+ }
1914
+ return undefined;
1915
+ }
1916
+ }
1917
+
1918
+ module.exports = huobijp;