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,2356 @@
1
+ 'use strict';
2
+
3
+ var poloniex$1 = require('./abstract/poloniex.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 poloniex
13
+ * @augments Exchange
14
+ */
15
+ class poloniex extends poloniex$1 {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'poloniex',
19
+ 'name': 'Poloniex',
20
+ 'countries': ['US'],
21
+ // 200 requests per second for some unauthenticated market endpoints => 1000ms / 200 = 5ms between requests
22
+ 'rateLimit': 5,
23
+ 'certified': false,
24
+ 'pro': true,
25
+ 'has': {
26
+ 'CORS': undefined,
27
+ 'spot': true,
28
+ 'margin': undefined,
29
+ 'swap': false,
30
+ 'future': false,
31
+ 'option': false,
32
+ 'cancelAllOrders': true,
33
+ 'cancelOrder': true,
34
+ 'createDepositAddress': true,
35
+ 'createMarketBuyOrderWithCost': true,
36
+ 'createMarketOrderWithCost': false,
37
+ 'createMarketSellOrderWithCost': false,
38
+ 'createOrder': true,
39
+ 'editOrder': true,
40
+ 'fetchBalance': true,
41
+ 'fetchClosedOrder': false,
42
+ 'fetchCurrencies': true,
43
+ 'fetchDepositAddress': true,
44
+ 'fetchDeposits': true,
45
+ 'fetchDepositsWithdrawals': true,
46
+ 'fetchDepositWithdrawFee': 'emulated',
47
+ 'fetchDepositWithdrawFees': true,
48
+ 'fetchMarginMode': false,
49
+ 'fetchMarkets': true,
50
+ 'fetchMyTrades': true,
51
+ 'fetchOHLCV': true,
52
+ 'fetchOpenInterestHistory': false,
53
+ 'fetchOpenOrder': false,
54
+ 'fetchOpenOrders': true,
55
+ 'fetchOrder': true,
56
+ 'fetchOrderBook': true,
57
+ 'fetchOrderBooks': false,
58
+ 'fetchOrderTrades': true,
59
+ 'fetchPosition': false,
60
+ 'fetchPositionMode': false,
61
+ 'fetchTicker': true,
62
+ 'fetchTickers': true,
63
+ 'fetchTime': true,
64
+ 'fetchTrades': true,
65
+ 'fetchTradingFee': false,
66
+ 'fetchTradingFees': true,
67
+ 'fetchTransactions': 'emulated',
68
+ 'fetchTransfer': false,
69
+ 'fetchTransfers': false,
70
+ 'fetchWithdrawals': true,
71
+ 'transfer': true,
72
+ 'withdraw': true,
73
+ },
74
+ 'timeframes': {
75
+ '1m': 'MINUTE_1',
76
+ '5m': 'MINUTE_5',
77
+ '10m': 'MINUTE_10',
78
+ '15m': 'MINUTE_15',
79
+ '30m': 'MINUTE_30',
80
+ '1h': 'HOUR_1',
81
+ '2h': 'HOUR_2',
82
+ '4h': 'HOUR_4',
83
+ '6h': 'HOUR_6',
84
+ '12h': 'HOUR_12',
85
+ '1d': 'DAY_1',
86
+ '3d': 'DAY_3',
87
+ '1w': 'WEEK_1',
88
+ '1M': 'MONTH_1',
89
+ },
90
+ 'urls': {
91
+ 'logo': 'https://user-images.githubusercontent.com/1294454/27766817-e9456312-5ee6-11e7-9b3c-b628ca5626a5.jpg',
92
+ 'api': {
93
+ 'rest': 'https://api.poloniex.com',
94
+ },
95
+ 'test': {
96
+ 'rest': 'https://sand-spot-api-gateway.poloniex.com',
97
+ },
98
+ 'www': 'https://www.poloniex.com',
99
+ 'doc': 'https://docs.poloniex.com',
100
+ 'fees': 'https://poloniex.com/fees',
101
+ 'referral': 'https://poloniex.com/signup?c=UBFZJRPJ',
102
+ },
103
+ 'api': {
104
+ 'public': {
105
+ 'get': {
106
+ 'markets': 20,
107
+ 'markets/{symbol}': 1,
108
+ 'currencies': 20,
109
+ 'currencies/{currency}': 20,
110
+ 'v2/currencies': 20,
111
+ 'v2/currencies/{currency}': 20,
112
+ 'timestamp': 1,
113
+ 'markets/price': 1,
114
+ 'markets/{symbol}/price': 1,
115
+ 'markets/markPrice': 1,
116
+ 'markets/{symbol}/markPrice': 1,
117
+ 'markets/{symbol}/markPriceComponents': 1,
118
+ 'markets/{symbol}/orderBook': 1,
119
+ 'markets/{symbol}/candles': 1,
120
+ 'markets/{symbol}/trades': 20,
121
+ 'markets/ticker24h': 20,
122
+ 'markets/{symbol}/ticker24h': 20,
123
+ 'markets/collateralInfo': 1,
124
+ 'markets/{currency}/collateralInfo': 1,
125
+ 'markets/borrowRatesInfo': 1,
126
+ },
127
+ },
128
+ 'private': {
129
+ 'get': {
130
+ 'accounts': 4,
131
+ 'accounts/balances': 4,
132
+ 'accounts/{id}/balances': 4,
133
+ 'accounts/activity': 20,
134
+ 'accounts/transfer': 20,
135
+ 'accounts/transfer/{id}': 4,
136
+ 'feeinfo': 20,
137
+ 'accounts/interest/history': 1,
138
+ 'subaccounts': 4,
139
+ 'subaccounts/balances': 20,
140
+ 'subaccounts/{id}/balances': 4,
141
+ 'subaccounts/transfer': 20,
142
+ 'subaccounts/transfer/{id}': 4,
143
+ 'wallets/addresses': 20,
144
+ 'wallets/addresses/{currency}': 20,
145
+ 'wallets/activity': 20,
146
+ 'margin/accountMargin': 4,
147
+ 'margin/borrowStatus': 4,
148
+ 'margin/maxSize': 4,
149
+ 'orders': 20,
150
+ 'orders/{id}': 4,
151
+ 'orders/killSwitchStatus': 4,
152
+ 'smartorders': 20,
153
+ 'smartorders/{id}': 4,
154
+ 'orders/history': 20,
155
+ 'smartorders/history': 20,
156
+ 'trades': 20,
157
+ 'orders/{id}/trades': 4,
158
+ },
159
+ 'post': {
160
+ 'accounts/transfer': 4,
161
+ 'subaccounts/transfer': 20,
162
+ 'wallets/address': 20,
163
+ 'wallets/withdraw': 20,
164
+ 'v2/wallets/withdraw': 20,
165
+ 'orders': 4,
166
+ 'orders/batch': 20,
167
+ 'orders/killSwitch': 4,
168
+ 'smartorders': 4,
169
+ },
170
+ 'delete': {
171
+ 'orders/{id}': 4,
172
+ 'orders/cancelByIds': 20,
173
+ 'orders': 20,
174
+ 'smartorders/{id}': 4,
175
+ 'smartorders/cancelByIds': 20,
176
+ 'smartorders': 20,
177
+ },
178
+ 'put': {
179
+ 'orders/{id}': 20,
180
+ 'smartorders/{id}': 20,
181
+ },
182
+ },
183
+ },
184
+ 'fees': {
185
+ 'trading': {
186
+ 'feeSide': 'get',
187
+ // starting from Jan 8 2020
188
+ 'maker': this.parseNumber('0.0009'),
189
+ 'taker': this.parseNumber('0.0009'),
190
+ },
191
+ 'funding': {},
192
+ },
193
+ 'commonCurrencies': {
194
+ 'AIR': 'AirCoin',
195
+ 'APH': 'AphroditeCoin',
196
+ 'BCC': 'BTCtalkcoin',
197
+ 'BCHABC': 'BCHABC',
198
+ 'BDG': 'Badgercoin',
199
+ 'BTM': 'Bitmark',
200
+ 'CON': 'Coino',
201
+ 'ETHTRON': 'ETH',
202
+ 'GOLD': 'GoldEagles',
203
+ 'GPUC': 'GPU',
204
+ 'HOT': 'Hotcoin',
205
+ 'ITC': 'Information Coin',
206
+ 'KEY': 'KEYCoin',
207
+ 'MASK': 'NFTX Hashmasks Index',
208
+ 'MEME': 'Degenerator Meme',
209
+ 'PLX': 'ParallaxCoin',
210
+ 'REPV2': 'REP',
211
+ 'STR': 'XLM',
212
+ 'SOC': 'SOCC',
213
+ 'TRADE': 'Unitrade',
214
+ 'TRXETH': 'TRX',
215
+ 'XAP': 'API Coin',
216
+ // this is not documented in the API docs for Poloniex
217
+ // https://github.com/ccxt/ccxt/issues/7084
218
+ // when the user calls withdraw ('USDT', amount, address, tag, params)
219
+ // with params = { 'currencyToWithdrawAs': 'USDTTRON' }
220
+ // or params = { 'currencyToWithdrawAs': 'USDTETH' }
221
+ // fetchWithdrawals ('USDT') returns the corresponding withdrawals
222
+ // with a USDTTRON or a USDTETH currency id, respectfully
223
+ // therefore we have map them back to the original code USDT
224
+ // otherwise the returned withdrawals are filtered out
225
+ 'USDTBSC': 'USDT',
226
+ 'USDTTRON': 'USDT',
227
+ 'USDTETH': 'USDT',
228
+ 'UST': 'USTC',
229
+ },
230
+ 'options': {
231
+ 'createMarketBuyOrderRequiresPrice': true,
232
+ 'networks': {
233
+ 'BEP20': 'BSC',
234
+ 'ERC20': 'ETH',
235
+ 'TRC20': 'TRON',
236
+ },
237
+ 'limits': {
238
+ 'cost': {
239
+ 'min': {
240
+ 'BTC': 0.0001,
241
+ 'ETH': 0.0001,
242
+ 'USDT': 1.0,
243
+ 'TRX': 100,
244
+ 'BNB': 0.06,
245
+ 'USDC': 1.0,
246
+ 'USDJ': 1.0,
247
+ 'TUSD': 0.0001,
248
+ 'DAI': 1.0,
249
+ 'PAX': 1.0,
250
+ 'BUSD': 1.0,
251
+ },
252
+ },
253
+ },
254
+ 'accountsByType': {
255
+ 'spot': 'spot',
256
+ 'future': 'futures',
257
+ },
258
+ 'accountsById': {
259
+ 'exchange': 'spot',
260
+ 'futures': 'future',
261
+ },
262
+ },
263
+ 'precisionMode': number.TICK_SIZE,
264
+ 'exceptions': {
265
+ 'exact': {
266
+ // General
267
+ '500': errors.ExchangeNotAvailable,
268
+ '603': errors.RequestTimeout,
269
+ '601': errors.BadRequest,
270
+ '415': errors.ExchangeError,
271
+ '602': errors.ArgumentsRequired,
272
+ // Accounts
273
+ '21604': errors.BadRequest,
274
+ '21600': errors.AuthenticationError,
275
+ '21605': errors.AuthenticationError,
276
+ '21102': errors.ExchangeError,
277
+ '21100': errors.AuthenticationError,
278
+ '21704': errors.AuthenticationError,
279
+ '21700': errors.BadRequest,
280
+ '21705': errors.BadRequest,
281
+ '21707': errors.ExchangeError,
282
+ '21708': errors.BadRequest,
283
+ '21601': errors.AccountSuspended,
284
+ '21711': errors.ExchangeError,
285
+ '21709': errors.InsufficientFunds,
286
+ '250000': errors.ExchangeError,
287
+ '250001': errors.BadRequest,
288
+ '250002': errors.BadRequest,
289
+ '250003': errors.BadRequest,
290
+ '250004': errors.BadRequest,
291
+ '250005': errors.InsufficientFunds,
292
+ '250008': errors.BadRequest,
293
+ '250012': errors.ExchangeError,
294
+ // Trading
295
+ '21110': errors.BadRequest,
296
+ '10040': errors.BadSymbol,
297
+ '10060': errors.ExchangeError,
298
+ '10020': errors.BadSymbol,
299
+ '10041': errors.BadSymbol,
300
+ '21340': errors.OnMaintenance,
301
+ '21341': errors.InvalidOrder,
302
+ '21342': errors.InvalidOrder,
303
+ '21343': errors.InvalidOrder,
304
+ '21351': errors.AccountSuspended,
305
+ '21352': errors.BadSymbol,
306
+ '21353': errors.PermissionDenied,
307
+ '21354': errors.PermissionDenied,
308
+ '21359': errors.OrderNotFound,
309
+ '21360': errors.InvalidOrder,
310
+ '24106': errors.BadRequest,
311
+ '24201': errors.ExchangeNotAvailable,
312
+ // Orders
313
+ '21301': errors.OrderNotFound,
314
+ '21302': errors.ExchangeError,
315
+ '21304': errors.ExchangeError,
316
+ '21305': errors.OrderNotFound,
317
+ '21307': errors.ExchangeError,
318
+ '21309': errors.InvalidOrder,
319
+ '21310': errors.InvalidOrder,
320
+ '21311': errors.InvalidOrder,
321
+ '21312': errors.InvalidOrder,
322
+ '21314': errors.InvalidOrder,
323
+ '21315': errors.InvalidOrder,
324
+ '21317': errors.InvalidOrder,
325
+ '21319': errors.InvalidOrder,
326
+ '21320': errors.InvalidOrder,
327
+ '21321': errors.InvalidOrder,
328
+ '21322': errors.InvalidOrder,
329
+ '21324': errors.BadRequest,
330
+ '21327': errors.InvalidOrder,
331
+ '21328': errors.InvalidOrder,
332
+ '21330': errors.InvalidOrder,
333
+ '21335': errors.InvalidOrder,
334
+ '21336': errors.InvalidOrder,
335
+ '21337': errors.InvalidOrder,
336
+ '21344': errors.InvalidOrder,
337
+ '21345': errors.InvalidOrder,
338
+ '21346': errors.InvalidOrder,
339
+ '21348': errors.InvalidOrder,
340
+ '21347': errors.InvalidOrder,
341
+ '21349': errors.InvalidOrder,
342
+ '21350': errors.InvalidOrder,
343
+ '21355': errors.ExchangeError,
344
+ '21356': errors.BadRequest,
345
+ '24101': errors.BadSymbol,
346
+ '24102': errors.InvalidOrder,
347
+ '24103': errors.InvalidOrder,
348
+ '24104': errors.InvalidOrder,
349
+ '24105': errors.InvalidOrder,
350
+ '25020': errors.InvalidOrder,
351
+ // Smartorders
352
+ '25000': errors.InvalidOrder,
353
+ '25001': errors.InvalidOrder,
354
+ '25002': errors.InvalidOrder,
355
+ '25003': errors.ExchangeError,
356
+ '25004': errors.InvalidOrder,
357
+ '25005': errors.ExchangeError,
358
+ '25006': errors.InvalidOrder,
359
+ '25007': errors.InvalidOrder,
360
+ '25008': errors.InvalidOrder,
361
+ '25009': errors.ExchangeError,
362
+ '25010': errors.PermissionDenied,
363
+ '25011': errors.InvalidOrder,
364
+ '25012': errors.ExchangeError,
365
+ '25013': errors.OrderNotFound,
366
+ '25014': errors.OrderNotFound,
367
+ '25015': errors.OrderNotFound,
368
+ '25016': errors.ExchangeError,
369
+ '25017': errors.ExchangeError,
370
+ '25018': errors.BadRequest,
371
+ '25019': errors.BadSymbol, // Invalid symbol
372
+ },
373
+ 'broad': {},
374
+ },
375
+ });
376
+ }
377
+ parseOHLCV(ohlcv, market = undefined) {
378
+ //
379
+ // [
380
+ // [
381
+ // "22814.01",
382
+ // "22937.42",
383
+ // "22832.57",
384
+ // "22937.42",
385
+ // "3916.58764051",
386
+ // "0.171199",
387
+ // "2982.64647063",
388
+ // "0.130295",
389
+ // 33,
390
+ // 0,
391
+ // "22877.449915304470460711",
392
+ // "MINUTE_5",
393
+ // 1659664800000,
394
+ // 1659665099999
395
+ // ]
396
+ // ]
397
+ //
398
+ return [
399
+ this.safeInteger(ohlcv, 12),
400
+ this.safeNumber(ohlcv, 2),
401
+ this.safeNumber(ohlcv, 1),
402
+ this.safeNumber(ohlcv, 0),
403
+ this.safeNumber(ohlcv, 3),
404
+ this.safeNumber(ohlcv, 5),
405
+ ];
406
+ }
407
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
408
+ /**
409
+ * @method
410
+ * @name poloniex#fetchOHLCV
411
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
412
+ * @see https://docs.poloniex.com/#public-endpoints-market-data-candles
413
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
414
+ * @param {string} timeframe the length of time each candle represents
415
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
416
+ * @param {int} [limit] the maximum amount of candles to fetch
417
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
418
+ * @param {int} [params.until] timestamp in ms
419
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
420
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
421
+ */
422
+ await this.loadMarkets();
423
+ let paginate = false;
424
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
425
+ if (paginate) {
426
+ return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 500);
427
+ }
428
+ const market = this.market(symbol);
429
+ let request = {
430
+ 'symbol': market['id'],
431
+ 'interval': this.safeString(this.timeframes, timeframe, timeframe),
432
+ };
433
+ if (since !== undefined) {
434
+ request['startTime'] = since;
435
+ }
436
+ if (limit !== undefined) {
437
+ // limit should in between 100 and 500
438
+ request['limit'] = limit;
439
+ }
440
+ [request, params] = this.handleUntilOption('endTime', request, params);
441
+ const response = await this.publicGetMarketsSymbolCandles(this.extend(request, params));
442
+ //
443
+ // [
444
+ // [
445
+ // "22814.01",
446
+ // "22937.42",
447
+ // "22832.57",
448
+ // "22937.42",
449
+ // "3916.58764051",
450
+ // "0.171199",
451
+ // "2982.64647063",
452
+ // "0.130295",
453
+ // 33,
454
+ // 0,
455
+ // "22877.449915304470460711",
456
+ // "MINUTE_5",
457
+ // 1659664800000,
458
+ // 1659665099999
459
+ // ]
460
+ // ]
461
+ //
462
+ return this.parseOHLCVs(response, market, timeframe, since, limit);
463
+ }
464
+ async loadMarkets(reload = false, params = {}) {
465
+ const markets = await super.loadMarkets(reload, params);
466
+ const currenciesByNumericId = this.safeValue(this.options, 'currenciesByNumericId');
467
+ if ((currenciesByNumericId === undefined) || reload) {
468
+ this.options['currenciesByNumericId'] = this.indexBy(this.currencies, 'numericId');
469
+ }
470
+ return markets;
471
+ }
472
+ async fetchMarkets(params = {}) {
473
+ /**
474
+ * @method
475
+ * @name poloniex#fetchMarkets
476
+ * @description retrieves data on all markets for poloniex
477
+ * @see https://docs.poloniex.com/#public-endpoints-reference-data-symbol-information
478
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
479
+ * @returns {object[]} an array of objects representing market data
480
+ */
481
+ const markets = await this.publicGetMarkets(params);
482
+ //
483
+ // [
484
+ // {
485
+ // "symbol" : "BTS_BTC",
486
+ // "baseCurrencyName" : "BTS",
487
+ // "quoteCurrencyName" : "BTC",
488
+ // "displayName" : "BTS/BTC",
489
+ // "state" : "NORMAL",
490
+ // "visibleStartTime" : 1659018816626,
491
+ // "tradableStartTime" : 1659018816626,
492
+ // "symbolTradeLimit" : {
493
+ // "symbol" : "BTS_BTC",
494
+ // "priceScale" : 10,
495
+ // "quantityScale" : 0,
496
+ // "amountScale" : 8,
497
+ // "minQuantity" : "100",
498
+ // "minAmount" : "0.00001",
499
+ // "highestBid" : "0",
500
+ // "lowestAsk" : "0"
501
+ // }
502
+ // }
503
+ // ]
504
+ //
505
+ return this.parseMarkets(markets);
506
+ }
507
+ parseMarket(market) {
508
+ const id = this.safeString(market, 'symbol');
509
+ const baseId = this.safeString(market, 'baseCurrencyName');
510
+ const quoteId = this.safeString(market, 'quoteCurrencyName');
511
+ const base = this.safeCurrencyCode(baseId);
512
+ const quote = this.safeCurrencyCode(quoteId);
513
+ const state = this.safeString(market, 'state');
514
+ const active = state === 'NORMAL';
515
+ const symbolTradeLimit = this.safeValue(market, 'symbolTradeLimit');
516
+ // these are known defaults
517
+ return {
518
+ 'id': id,
519
+ 'symbol': base + '/' + quote,
520
+ 'base': base,
521
+ 'quote': quote,
522
+ 'settle': undefined,
523
+ 'baseId': baseId,
524
+ 'quoteId': quoteId,
525
+ 'settleId': undefined,
526
+ 'type': 'spot',
527
+ 'spot': true,
528
+ 'margin': false,
529
+ 'swap': false,
530
+ 'future': false,
531
+ 'option': false,
532
+ 'active': active,
533
+ 'contract': false,
534
+ 'linear': undefined,
535
+ 'inverse': undefined,
536
+ 'contractSize': undefined,
537
+ 'expiry': undefined,
538
+ 'expiryDatetime': undefined,
539
+ 'strike': undefined,
540
+ 'optionType': undefined,
541
+ 'precision': {
542
+ 'amount': this.parseNumber(this.parsePrecision(this.safeString(symbolTradeLimit, 'quantityScale'))),
543
+ 'price': this.parseNumber(this.parsePrecision(this.safeString(symbolTradeLimit, 'priceScale'))),
544
+ },
545
+ 'limits': {
546
+ 'amount': {
547
+ 'min': this.safeNumber(symbolTradeLimit, 'minQuantity'),
548
+ 'max': undefined,
549
+ },
550
+ 'price': {
551
+ 'min': undefined,
552
+ 'max': undefined,
553
+ },
554
+ 'cost': {
555
+ 'min': this.safeNumber(symbolTradeLimit, 'minAmount'),
556
+ 'max': undefined,
557
+ },
558
+ },
559
+ 'created': this.safeInteger(market, 'tradableStartTime'),
560
+ 'info': market,
561
+ };
562
+ }
563
+ async fetchTime(params = {}) {
564
+ /**
565
+ * @method
566
+ * @name poloniex#fetchTime
567
+ * @description fetches the current integer timestamp in milliseconds from the exchange server
568
+ * @see https://docs.poloniex.com/#public-endpoints-reference-data-system-timestamp
569
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
570
+ * @returns {int} the current integer timestamp in milliseconds from the exchange server
571
+ */
572
+ const response = await this.publicGetTimestamp(params);
573
+ return this.safeInteger(response, 'serverTime');
574
+ }
575
+ parseTicker(ticker, market = undefined) {
576
+ //
577
+ // {
578
+ // "symbol" : "BTC_USDT",
579
+ // "open" : "26053.33",
580
+ // "low" : "26053.33",
581
+ // "high" : "26798.02",
582
+ // "close" : "26447.58",
583
+ // "quantity" : "6116.210188",
584
+ // "amount" : "161082122.88450926",
585
+ // "tradeCount" : "134709",
586
+ // "startTime" : "1692784440000",
587
+ // "closeTime" : "1692870839630",
588
+ // "displayName" : "BTC/USDT",
589
+ // "dailyChange" : "0.0151",
590
+ // "bid" : "26447.57",
591
+ // "bidQuantity" : "0.016313",
592
+ // "ask" : "26447.58",
593
+ // "askQuantity" : "0.068307",
594
+ // "ts" : "1692870845446",
595
+ // "markPrice" : "26444.11"
596
+ // }
597
+ //
598
+ const timestamp = this.safeInteger(ticker, 'ts');
599
+ const marketId = this.safeString(ticker, 'symbol');
600
+ market = this.safeMarket(marketId);
601
+ const close = this.safeString(ticker, 'close');
602
+ const relativeChange = this.safeString(ticker, 'dailyChange');
603
+ const percentage = Precise["default"].stringMul(relativeChange, '100');
604
+ const bidVolume = this.safeString(ticker, 'bidQuantity');
605
+ const askVolume = this.safeString(ticker, 'askQuantity');
606
+ return this.safeTicker({
607
+ 'id': marketId,
608
+ 'symbol': market['symbol'],
609
+ 'timestamp': timestamp,
610
+ 'datetime': this.iso8601(timestamp),
611
+ 'high': this.safeString(ticker, 'high'),
612
+ 'low': this.safeString(ticker, 'low'),
613
+ 'bid': this.safeString(ticker, 'bid'),
614
+ 'bidVolume': bidVolume,
615
+ 'ask': this.safeString(ticker, 'ask'),
616
+ 'askVolume': askVolume,
617
+ 'vwap': undefined,
618
+ 'open': this.safeString(ticker, 'open'),
619
+ 'close': close,
620
+ 'last': close,
621
+ 'previousClose': undefined,
622
+ 'change': undefined,
623
+ 'percentage': percentage,
624
+ 'average': undefined,
625
+ 'baseVolume': this.safeString(ticker, 'quantity'),
626
+ 'quoteVolume': this.safeString(ticker, 'amount'),
627
+ 'info': ticker,
628
+ }, market);
629
+ }
630
+ async fetchTickers(symbols = undefined, params = {}) {
631
+ /**
632
+ * @method
633
+ * @name poloniex#fetchTickers
634
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
635
+ * @see https://docs.poloniex.com/#public-endpoints-market-data-ticker
636
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
637
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
638
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
639
+ */
640
+ await this.loadMarkets();
641
+ symbols = this.marketSymbols(symbols);
642
+ const response = await this.publicGetMarketsTicker24h(params);
643
+ //
644
+ // [
645
+ // {
646
+ // "symbol" : "BTC_USDT",
647
+ // "open" : "26053.33",
648
+ // "low" : "26053.33",
649
+ // "high" : "26798.02",
650
+ // "close" : "26447.58",
651
+ // "quantity" : "6116.210188",
652
+ // "amount" : "161082122.88450926",
653
+ // "tradeCount" : "134709",
654
+ // "startTime" : "1692784440000",
655
+ // "closeTime" : "1692870839630",
656
+ // "displayName" : "BTC/USDT",
657
+ // "dailyChange" : "0.0151",
658
+ // "bid" : "26447.57",
659
+ // "bidQuantity" : "0.016313",
660
+ // "ask" : "26447.58",
661
+ // "askQuantity" : "0.068307",
662
+ // "ts" : "1692870845446",
663
+ // "markPrice" : "26444.11"
664
+ // }
665
+ // ]
666
+ //
667
+ return this.parseTickers(response, symbols);
668
+ }
669
+ async fetchCurrencies(params = {}) {
670
+ /**
671
+ * @method
672
+ * @name poloniex#fetchCurrencies
673
+ * @description fetches all available currencies on an exchange
674
+ * @see https://docs.poloniex.com/#public-endpoints-reference-data-currency-information
675
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
676
+ * @returns {object} an associative dictionary of currencies
677
+ */
678
+ const response = await this.publicGetCurrencies(this.extend(params, { 'includeMultiChainCurrencies': true }));
679
+ //
680
+ // [
681
+ // {
682
+ // "1CR": {
683
+ // "id": 1,
684
+ // "name": "1CRedit",
685
+ // "description": "BTC Clone",
686
+ // "type": "address",
687
+ // "withdrawalFee": "0.01000000",
688
+ // "minConf": 10000,
689
+ // "depositAddress": null,
690
+ // "blockchain": "1CR",
691
+ // "delisted": false,
692
+ // "tradingState": "NORMAL",
693
+ // "walletState": "DISABLED",
694
+ // "walletDepositState": "DISABLED",
695
+ // "walletWithdrawalState": "DISABLED",
696
+ // "parentChain": null,
697
+ // "isMultiChain": false,
698
+ // "isChildChain": false,
699
+ // "childChains": []
700
+ // }
701
+ // }
702
+ // ]
703
+ //
704
+ const result = {};
705
+ for (let i = 0; i < response.length; i++) {
706
+ const item = this.safeValue(response, i);
707
+ const ids = Object.keys(item);
708
+ const id = this.safeValue(ids, 0);
709
+ const currency = this.safeValue(item, id);
710
+ const code = this.safeCurrencyCode(id);
711
+ const name = this.safeString(currency, 'name');
712
+ const networkId = this.safeString(currency, 'blockchain');
713
+ const networkCode = this.networkIdToCode(networkId, code);
714
+ const delisted = this.safeValue(currency, 'delisted');
715
+ const walletEnabled = this.safeString(currency, 'walletState') === 'ENABLED';
716
+ const depositEnabled = this.safeString(currency, 'walletDepositState') === 'ENABLED';
717
+ const withdrawEnabled = this.safeString(currency, 'walletWithdrawalState') === 'ENABLED';
718
+ const active = !delisted && walletEnabled && depositEnabled && withdrawEnabled;
719
+ const numericId = this.safeInteger(currency, 'id');
720
+ const feeString = this.safeString(currency, 'withdrawalFee');
721
+ const parentChain = this.safeValue(currency, 'parentChain');
722
+ const noParentChain = parentChain === undefined;
723
+ if (this.safeValue(result, code) === undefined) {
724
+ result[code] = {
725
+ 'id': id,
726
+ 'code': code,
727
+ 'info': undefined,
728
+ 'name': name,
729
+ 'active': active,
730
+ 'deposit': depositEnabled,
731
+ 'withdraw': withdrawEnabled,
732
+ 'fee': this.parseNumber(feeString),
733
+ 'precision': undefined,
734
+ 'limits': {
735
+ 'amount': {
736
+ 'min': undefined,
737
+ 'max': undefined,
738
+ },
739
+ 'deposit': {
740
+ 'min': undefined,
741
+ 'max': undefined,
742
+ },
743
+ 'withdraw': {
744
+ 'min': undefined,
745
+ 'max': undefined,
746
+ },
747
+ },
748
+ };
749
+ }
750
+ let minFeeString = this.safeString(result[code], 'fee');
751
+ if (feeString !== undefined) {
752
+ minFeeString = (minFeeString === undefined) ? feeString : Precise["default"].stringMin(feeString, minFeeString);
753
+ }
754
+ let depositAvailable = this.safeValue(result[code], 'deposit');
755
+ depositAvailable = (depositEnabled) ? depositEnabled : depositAvailable;
756
+ let withdrawAvailable = this.safeValue(result[code], 'withdraw');
757
+ withdrawAvailable = (withdrawEnabled) ? withdrawEnabled : withdrawAvailable;
758
+ const networks = this.safeValue(result[code], 'networks', {});
759
+ if (networkCode !== undefined) {
760
+ networks[networkCode] = {
761
+ 'info': currency,
762
+ 'id': networkId,
763
+ 'network': networkCode,
764
+ 'currencyId': id,
765
+ 'numericId': numericId,
766
+ 'deposit': depositEnabled,
767
+ 'withdraw': withdrawEnabled,
768
+ 'active': active,
769
+ 'fee': this.parseNumber(feeString),
770
+ 'precision': undefined,
771
+ 'limits': {
772
+ 'amount': {
773
+ 'min': undefined,
774
+ 'max': undefined,
775
+ },
776
+ 'withdraw': {
777
+ 'min': undefined,
778
+ 'max': undefined,
779
+ },
780
+ 'deposit': {
781
+ 'min': undefined,
782
+ 'max': undefined,
783
+ },
784
+ },
785
+ };
786
+ }
787
+ result[code]['networks'] = networks;
788
+ const info = this.safeValue(result[code], 'info', []);
789
+ const rawInfo = {};
790
+ rawInfo[id] = currency;
791
+ info.push(rawInfo);
792
+ result[code]['info'] = info;
793
+ if (noParentChain) {
794
+ result[code]['id'] = id;
795
+ result[code]['name'] = name;
796
+ }
797
+ result[code]['active'] = depositAvailable && withdrawAvailable;
798
+ result[code]['deposit'] = depositAvailable;
799
+ result[code]['withdraw'] = withdrawAvailable;
800
+ result[code]['fee'] = this.parseNumber(minFeeString);
801
+ }
802
+ return result;
803
+ }
804
+ async fetchTicker(symbol, params = {}) {
805
+ /**
806
+ * @method
807
+ * @name poloniex#fetchTicker
808
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
809
+ * @see https://docs.poloniex.com/#public-endpoints-market-data-ticker
810
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
811
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
812
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
813
+ */
814
+ await this.loadMarkets();
815
+ const market = this.market(symbol);
816
+ const request = {
817
+ 'symbol': market['id'],
818
+ };
819
+ const response = await this.publicGetMarketsSymbolTicker24h(this.extend(request, params));
820
+ //
821
+ // {
822
+ // "symbol" : "BTC_USDT",
823
+ // "open" : "26053.33",
824
+ // "low" : "26053.33",
825
+ // "high" : "26798.02",
826
+ // "close" : "26447.58",
827
+ // "quantity" : "6116.210188",
828
+ // "amount" : "161082122.88450926",
829
+ // "tradeCount" : "134709",
830
+ // "startTime" : "1692784440000",
831
+ // "closeTime" : "1692870839630",
832
+ // "displayName" : "BTC/USDT",
833
+ // "dailyChange" : "0.0151",
834
+ // "bid" : "26447.57",
835
+ // "bidQuantity" : "0.016313",
836
+ // "ask" : "26447.58",
837
+ // "askQuantity" : "0.068307",
838
+ // "ts" : "1692870845446",
839
+ // "markPrice" : "26444.11"
840
+ // }
841
+ //
842
+ return this.parseTicker(response, market);
843
+ }
844
+ parseTrade(trade, market = undefined) {
845
+ //
846
+ // fetchTrades
847
+ //
848
+ // {
849
+ // "id" : "60014521",
850
+ // "price" : "23162.94",
851
+ // "quantity" : "0.00009",
852
+ // "amount" : "2.0846646",
853
+ // "takerSide" : "SELL",
854
+ // "ts" : 1659684602042,
855
+ // "createTime" : 1659684602036
856
+ // }
857
+ //
858
+ // fetchMyTrades
859
+ //
860
+ // {
861
+ // "id": "32164924331503616",
862
+ // "symbol": "LINK_USDT",
863
+ // "accountType": "SPOT",
864
+ // "orderId": "32164923987566592",
865
+ // "side": "SELL",
866
+ // "type": "MARKET",
867
+ // "matchRole": "TAKER",
868
+ // "createTime": 1648635115525,
869
+ // "price": "11",
870
+ // "quantity": "0.5",
871
+ // "amount": "5.5",
872
+ // "feeCurrency": "USDT",
873
+ // "feeAmount": "0.007975",
874
+ // "pageId": "32164924331503616",
875
+ // "clientOrderId": "myOwnId-321"
876
+ // }
877
+ //
878
+ // fetchOrderTrades (taker trades)
879
+ //
880
+ // {
881
+ // "id": "30341456333942784",
882
+ // "symbol": "LINK_USDT",
883
+ // "accountType": "SPOT",
884
+ // "orderId": "30249408733945856",
885
+ // "side": "BUY",
886
+ // "type": "LIMIT",
887
+ // "matchRole": "MAKER",
888
+ // "createTime": 1648200366864,
889
+ // "price": "3.1",
890
+ // "quantity": "1",
891
+ // "amount": "3.1",
892
+ // "feeCurrency": "LINK",
893
+ // "feeAmount": "0.00145",
894
+ // "pageId": "30341456333942784",
895
+ // "clientOrderId": ""
896
+ // }
897
+ //
898
+ //
899
+ const id = this.safeString2(trade, 'id', 'tradeID');
900
+ const orderId = this.safeString(trade, 'orderId');
901
+ const timestamp = this.safeInteger2(trade, 'ts', 'createTime');
902
+ const marketId = this.safeString(trade, 'symbol');
903
+ market = this.safeMarket(marketId, market, '_');
904
+ const symbol = market['symbol'];
905
+ const side = this.safeStringLower2(trade, 'side', 'takerSide');
906
+ let fee = undefined;
907
+ const priceString = this.safeString(trade, 'price');
908
+ const amountString = this.safeString(trade, 'quantity');
909
+ const costString = this.safeString(trade, 'amount');
910
+ const feeCurrencyId = this.safeString(trade, 'feeCurrency');
911
+ const feeCostString = this.safeString(trade, 'feeAmount');
912
+ if (feeCostString !== undefined) {
913
+ const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
914
+ fee = {
915
+ 'cost': feeCostString,
916
+ 'currency': feeCurrencyCode,
917
+ };
918
+ }
919
+ return this.safeTrade({
920
+ 'id': id,
921
+ 'info': trade,
922
+ 'timestamp': timestamp,
923
+ 'datetime': this.iso8601(timestamp),
924
+ 'symbol': symbol,
925
+ 'order': orderId,
926
+ 'type': this.safeStringLower(trade, 'type'),
927
+ 'side': side,
928
+ 'takerOrMaker': this.safeStringLower(trade, 'matchRole'),
929
+ 'price': priceString,
930
+ 'amount': amountString,
931
+ 'cost': costString,
932
+ 'fee': fee,
933
+ }, market);
934
+ }
935
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
936
+ /**
937
+ * @method
938
+ * @name poloniex#fetchTrades
939
+ * @description get the list of most recent trades for a particular symbol
940
+ * @see https://docs.poloniex.com/#public-endpoints-market-data-trades
941
+ * @param {string} symbol unified symbol of the market to fetch trades for
942
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
943
+ * @param {int} [limit] the maximum amount of trades to fetch
944
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
945
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
946
+ */
947
+ await this.loadMarkets();
948
+ const market = this.market(symbol);
949
+ const request = {
950
+ 'symbol': market['id'],
951
+ };
952
+ if (limit !== undefined) {
953
+ request['limit'] = limit;
954
+ }
955
+ const trades = await this.publicGetMarketsSymbolTrades(this.extend(request, params));
956
+ //
957
+ // [
958
+ // {
959
+ // "id" : "60014521",
960
+ // "price" : "23162.94",
961
+ // "quantity" : "0.00009",
962
+ // "amount" : "2.0846646",
963
+ // "takerSide" : "SELL",
964
+ // "ts" : 1659684602042,
965
+ // "createTime" : 1659684602036
966
+ // }
967
+ // ]
968
+ //
969
+ return this.parseTrades(trades, market, since, limit);
970
+ }
971
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
972
+ /**
973
+ * @method
974
+ * @name poloniex#fetchMyTrades
975
+ * @description fetch all trades made by the user
976
+ * @see https://docs.poloniex.com/#authenticated-endpoints-trades-trade-history
977
+ * @param {string} symbol unified market symbol
978
+ * @param {int} [since] the earliest time in ms to fetch trades for
979
+ * @param {int} [limit] the maximum number of trades structures to retrieve
980
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
981
+ * @param {int} [params.until] the latest time in ms to fetch entries for
982
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
983
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
984
+ */
985
+ await this.loadMarkets();
986
+ let paginate = false;
987
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
988
+ if (paginate) {
989
+ return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params);
990
+ }
991
+ let market = undefined;
992
+ if (symbol !== undefined) {
993
+ market = this.market(symbol);
994
+ }
995
+ let request = {
996
+ // 'from': 12345678, // A 'trade Id'. The query begins at ‘from'.
997
+ // 'direction': 'PRE', // PRE, NEXT The direction before or after ‘from'.
998
+ };
999
+ if (since !== undefined) {
1000
+ request['startTime'] = since;
1001
+ }
1002
+ if (limit !== undefined) {
1003
+ request['limit'] = limit;
1004
+ }
1005
+ [request, params] = this.handleUntilOption('endTime', request, params);
1006
+ const response = await this.privateGetTrades(this.extend(request, params));
1007
+ //
1008
+ // [
1009
+ // {
1010
+ // "id": "32164924331503616",
1011
+ // "symbol": "LINK_USDT",
1012
+ // "accountType": "SPOT",
1013
+ // "orderId": "32164923987566592",
1014
+ // "side": "SELL",
1015
+ // "type": "MARKET",
1016
+ // "matchRole": "TAKER",
1017
+ // "createTime": 1648635115525,
1018
+ // "price": "11",
1019
+ // "quantity": "0.5",
1020
+ // "amount": "5.5",
1021
+ // "feeCurrency": "USDT",
1022
+ // "feeAmount": "0.007975",
1023
+ // "pageId": "32164924331503616",
1024
+ // "clientOrderId": "myOwnId-321"
1025
+ // }
1026
+ // ]
1027
+ //
1028
+ const result = this.parseTrades(response, market, since, limit);
1029
+ return result;
1030
+ }
1031
+ parseOrderStatus(status) {
1032
+ const statuses = {
1033
+ 'NEW': 'open',
1034
+ 'PARTIALLY_FILLED': 'open',
1035
+ 'FILLED': 'closed',
1036
+ 'PENDING_CANCEL': 'canceled',
1037
+ 'PARTIALLY_CANCELED': 'canceled',
1038
+ 'CANCELED': 'canceled',
1039
+ 'FAILED': 'canceled',
1040
+ };
1041
+ return this.safeString(statuses, status, status);
1042
+ }
1043
+ parseOrder(order, market = undefined) {
1044
+ //
1045
+ // fetchOpenOrder
1046
+ //
1047
+ // {
1048
+ // "id" : "7xxxxxxxxxxxxxxx6",
1049
+ // "clientOrderId" : "",
1050
+ // "symbol" : "ETH_USDT",
1051
+ // "state" : "NEW",
1052
+ // "accountType" : "SPOT",
1053
+ // "side" : "BUY",
1054
+ // "type" : "LIMIT",
1055
+ // "timeInForce" : "GTC",
1056
+ // "quantity" : "0.001",
1057
+ // "price" : "1600",
1058
+ // "avgPrice" : "0",
1059
+ // "amount" : "0",
1060
+ // "filledQuantity" : "0",
1061
+ // "filledAmount" : "0",
1062
+ // "createTime" : 16xxxxxxxxx26,
1063
+ // "updateTime" : 16xxxxxxxxx36
1064
+ // }
1065
+ //
1066
+ // fetchOpenOrders
1067
+ //
1068
+ // {
1069
+ // "id": "24993088082542592",
1070
+ // "clientOrderId": "",
1071
+ // "symbol": "ELON_USDC",
1072
+ // "state": "NEW",
1073
+ // "accountType": "SPOT",
1074
+ // "side": "SELL",
1075
+ // "type": "MARKET",
1076
+ // "timeInForce": "GTC",
1077
+ // "quantity": "1.00",
1078
+ // "price": "0.00",
1079
+ // "avgPrice": "0.00",
1080
+ // "amount": "0.00",
1081
+ // "filledQuantity": "0.00",
1082
+ // "filledAmount": "0.00",
1083
+ // "createTime": 1646925216548,
1084
+ // "updateTime": 1646925216548
1085
+ // }
1086
+ //
1087
+ // createOrder, editOrder
1088
+ //
1089
+ // {
1090
+ // "id": "29772698821328896",
1091
+ // "clientOrderId": "1234Abc"
1092
+ // }
1093
+ //
1094
+ let timestamp = this.safeInteger2(order, 'timestamp', 'createTime');
1095
+ if (timestamp === undefined) {
1096
+ timestamp = this.parse8601(this.safeString(order, 'date'));
1097
+ }
1098
+ const marketId = this.safeString(order, 'symbol');
1099
+ market = this.safeMarket(marketId, market, '_');
1100
+ const symbol = market['symbol'];
1101
+ let resultingTrades = this.safeValue(order, 'resultingTrades');
1102
+ if (!Array.isArray(resultingTrades)) {
1103
+ resultingTrades = this.safeValue(resultingTrades, this.safeString(market, 'id', marketId));
1104
+ }
1105
+ const price = this.safeString2(order, 'price', 'rate');
1106
+ const amount = this.safeString(order, 'quantity');
1107
+ const filled = this.safeString(order, 'filledQuantity');
1108
+ const status = this.parseOrderStatus(this.safeString(order, 'state'));
1109
+ const side = this.safeStringLower(order, 'side');
1110
+ const rawType = this.safeString(order, 'type');
1111
+ const type = this.parseOrderType(rawType);
1112
+ const id = this.safeStringN(order, ['orderNumber', 'id', 'orderId']);
1113
+ let fee = undefined;
1114
+ const feeCurrency = this.safeString(order, 'tokenFeeCurrency');
1115
+ let feeCost = undefined;
1116
+ let feeCurrencyCode = undefined;
1117
+ const rate = this.safeString(order, 'fee');
1118
+ if (feeCurrency === undefined) {
1119
+ feeCurrencyCode = (side === 'buy') ? market['base'] : market['quote'];
1120
+ }
1121
+ else {
1122
+ // poloniex accepts a 30% discount to pay fees in TRX
1123
+ feeCurrencyCode = this.safeCurrencyCode(feeCurrency);
1124
+ feeCost = this.safeString(order, 'tokenFee');
1125
+ }
1126
+ if (feeCost !== undefined) {
1127
+ fee = {
1128
+ 'rate': rate,
1129
+ 'cost': feeCost,
1130
+ 'currency': feeCurrencyCode,
1131
+ };
1132
+ }
1133
+ const clientOrderId = this.safeString(order, 'clientOrderId');
1134
+ const triggerPrice = this.safeString2(order, 'triggerPrice', 'stopPrice');
1135
+ return this.safeOrder({
1136
+ 'info': order,
1137
+ 'id': id,
1138
+ 'clientOrderId': clientOrderId,
1139
+ 'timestamp': timestamp,
1140
+ 'datetime': this.iso8601(timestamp),
1141
+ 'lastTradeTimestamp': this.safeInteger(order, 'updateTime'),
1142
+ 'status': status,
1143
+ 'symbol': symbol,
1144
+ 'type': type,
1145
+ 'timeInForce': this.safeString(order, 'timeInForce'),
1146
+ 'postOnly': undefined,
1147
+ 'side': side,
1148
+ 'price': price,
1149
+ 'stopPrice': triggerPrice,
1150
+ 'triggerPrice': triggerPrice,
1151
+ 'cost': undefined,
1152
+ 'average': this.safeString(order, 'avgPrice'),
1153
+ 'amount': amount,
1154
+ 'filled': filled,
1155
+ 'remaining': undefined,
1156
+ 'trades': resultingTrades,
1157
+ 'fee': fee,
1158
+ }, market);
1159
+ }
1160
+ parseOrderType(status) {
1161
+ const statuses = {
1162
+ 'MARKET': 'market',
1163
+ 'LIMIT': 'limit',
1164
+ 'STOP-LIMIT': 'limit',
1165
+ 'STOP-MARKET': 'market',
1166
+ };
1167
+ return this.safeString(statuses, status, status);
1168
+ }
1169
+ parseOpenOrders(orders, market, result) {
1170
+ for (let i = 0; i < orders.length; i++) {
1171
+ const order = orders[i];
1172
+ const extended = this.extend(order, {
1173
+ 'status': 'open',
1174
+ 'type': 'limit',
1175
+ 'side': order['type'],
1176
+ 'price': order['rate'],
1177
+ });
1178
+ result.push(this.parseOrder(extended, market));
1179
+ }
1180
+ return result;
1181
+ }
1182
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1183
+ /**
1184
+ * @method
1185
+ * @name poloniex#fetchOpenOrders
1186
+ * @description fetch all unfilled currently open orders
1187
+ * @see https://docs.poloniex.com/#authenticated-endpoints-orders-open-orders
1188
+ * @see https://docs.poloniex.com/#authenticated-endpoints-smart-orders-open-orders // trigger orders
1189
+ * @param {string} symbol unified market symbol
1190
+ * @param {int} [since] the earliest time in ms to fetch open orders for
1191
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
1192
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1193
+ * @param {boolean} [params.stop] set true to fetch trigger orders instead of regular orders
1194
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1195
+ */
1196
+ await this.loadMarkets();
1197
+ let market = undefined;
1198
+ const request = {};
1199
+ if (symbol !== undefined) {
1200
+ market = this.market(symbol);
1201
+ request['symbol'] = market['id'];
1202
+ }
1203
+ if (limit !== undefined) {
1204
+ request['limit'] = limit;
1205
+ }
1206
+ const isTrigger = this.safeValue2(params, 'trigger', 'stop');
1207
+ params = this.omit(params, ['trigger', 'stop']);
1208
+ let response = undefined;
1209
+ if (isTrigger) {
1210
+ response = await this.privateGetSmartorders(this.extend(request, params));
1211
+ }
1212
+ else {
1213
+ response = await this.privateGetOrders(this.extend(request, params));
1214
+ }
1215
+ //
1216
+ // [
1217
+ // {
1218
+ // "id" : "7xxxxxxxxxxxxxxx6",
1219
+ // "clientOrderId" : "",
1220
+ // "symbol" : "ETH_USDT",
1221
+ // "state" : "NEW",
1222
+ // "accountType" : "SPOT",
1223
+ // "side" : "BUY",
1224
+ // "type" : "LIMIT",
1225
+ // "timeInForce" : "GTC",
1226
+ // "quantity" : "0.001",
1227
+ // "price" : "1600",
1228
+ // "avgPrice" : "0",
1229
+ // "amount" : "0",
1230
+ // "filledQuantity" : "0",
1231
+ // "filledAmount" : "0",
1232
+ // "stopPrice": "3750.00", // for trigger orders
1233
+ // "createTime" : 16xxxxxxxxx26,
1234
+ // "updateTime" : 16xxxxxxxxx36
1235
+ // }
1236
+ // ]
1237
+ //
1238
+ const extension = { 'status': 'open' };
1239
+ return this.parseOrders(response, market, since, limit, extension);
1240
+ }
1241
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1242
+ /**
1243
+ * @method
1244
+ * @name poloniex#createOrder
1245
+ * @description create a trade order
1246
+ * @see https://docs.poloniex.com/#authenticated-endpoints-orders-create-order
1247
+ * @see https://docs.poloniex.com/#authenticated-endpoints-smart-orders-create-order // trigger orders
1248
+ * @param {string} symbol unified symbol of the market to create an order in
1249
+ * @param {string} type 'market' or 'limit'
1250
+ * @param {string} side 'buy' or 'sell'
1251
+ * @param {float} amount how much of currency you want to trade in units of base currency
1252
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1253
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1254
+ * @param {float} [params.triggerPrice] *spot only* The price at which a trigger order is triggered at
1255
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
1256
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1257
+ */
1258
+ await this.loadMarkets();
1259
+ const market = this.market(symbol);
1260
+ if (!market['spot']) {
1261
+ throw new errors.NotSupported(this.id + ' createOrder() does not support ' + market['type'] + ' orders, only spot orders are accepted');
1262
+ }
1263
+ let request = {
1264
+ 'symbol': market['id'],
1265
+ 'side': side,
1266
+ // 'timeInForce': timeInForce,
1267
+ // 'accountType': 'SPOT',
1268
+ // 'amount': amount,
1269
+ };
1270
+ const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
1271
+ [request, params] = this.orderRequest(symbol, type, side, amount, request, price, params);
1272
+ let response = undefined;
1273
+ if (triggerPrice !== undefined) {
1274
+ response = await this.privatePostSmartorders(this.extend(request, params));
1275
+ }
1276
+ else {
1277
+ response = await this.privatePostOrders(this.extend(request, params));
1278
+ }
1279
+ //
1280
+ // {
1281
+ // "id" : "78923648051920896",
1282
+ // "clientOrderId" : ""
1283
+ // }
1284
+ //
1285
+ response = this.extend(response, {
1286
+ 'type': side,
1287
+ });
1288
+ return this.parseOrder(response, market);
1289
+ }
1290
+ orderRequest(symbol, type, side, amount, request, price = undefined, params = {}) {
1291
+ let upperCaseType = type.toUpperCase();
1292
+ const isMarket = upperCaseType === 'MARKET';
1293
+ const isPostOnly = this.isPostOnly(isMarket, upperCaseType === 'LIMIT_MAKER', params);
1294
+ const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
1295
+ params = this.omit(params, ['postOnly', 'triggerPrice', 'stopPrice']);
1296
+ if (triggerPrice !== undefined) {
1297
+ upperCaseType = (price === undefined) ? 'STOP' : 'STOP_LIMIT';
1298
+ request['stopPrice'] = triggerPrice;
1299
+ }
1300
+ else if (isPostOnly) {
1301
+ upperCaseType = 'LIMIT_MAKER';
1302
+ }
1303
+ request['type'] = upperCaseType;
1304
+ if (isMarket) {
1305
+ if (side === 'buy') {
1306
+ let quoteAmount = undefined;
1307
+ let createMarketBuyOrderRequiresPrice = true;
1308
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
1309
+ const cost = this.safeNumber(params, 'cost');
1310
+ params = this.omit(params, 'cost');
1311
+ if (cost !== undefined) {
1312
+ quoteAmount = this.costToPrecision(symbol, cost);
1313
+ }
1314
+ else if (createMarketBuyOrderRequiresPrice) {
1315
+ if (price === undefined) {
1316
+ 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 (quote quantity) in the amount argument');
1317
+ }
1318
+ else {
1319
+ const amountString = this.numberToString(amount);
1320
+ const priceString = this.numberToString(price);
1321
+ const costRequest = Precise["default"].stringMul(amountString, priceString);
1322
+ quoteAmount = this.costToPrecision(symbol, costRequest);
1323
+ }
1324
+ }
1325
+ else {
1326
+ quoteAmount = this.costToPrecision(symbol, amount);
1327
+ }
1328
+ request['amount'] = quoteAmount;
1329
+ }
1330
+ else {
1331
+ request['quantity'] = this.amountToPrecision(symbol, amount);
1332
+ }
1333
+ }
1334
+ else {
1335
+ request['quantity'] = this.amountToPrecision(symbol, amount);
1336
+ request['price'] = this.priceToPrecision(symbol, price);
1337
+ }
1338
+ const clientOrderId = this.safeString(params, 'clientOrderId');
1339
+ if (clientOrderId !== undefined) {
1340
+ request['clientOrderId'] = clientOrderId;
1341
+ params = this.omit(params, 'clientOrderId');
1342
+ }
1343
+ // remember the timestamp before issuing the request
1344
+ return [request, params];
1345
+ }
1346
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1347
+ /**
1348
+ * @method
1349
+ * @name poloniex#editOrder
1350
+ * @description edit a trade order
1351
+ * @see https://docs.poloniex.com/#authenticated-endpoints-orders-cancel-replace-order
1352
+ * @see https://docs.poloniex.com/#authenticated-endpoints-smart-orders-cancel-replace-order
1353
+ * @param {string} id order id
1354
+ * @param {string} symbol unified symbol of the market to create an order in
1355
+ * @param {string} type 'market' or 'limit'
1356
+ * @param {string} side 'buy' or 'sell'
1357
+ * @param {float} [amount] how much of the currency you want to trade in units of the base currency
1358
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1359
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1360
+ * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
1361
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1362
+ */
1363
+ await this.loadMarkets();
1364
+ const market = this.market(symbol);
1365
+ if (!market['spot']) {
1366
+ throw new errors.NotSupported(this.id + ' editOrder() does not support ' + market['type'] + ' orders, only spot orders are accepted');
1367
+ }
1368
+ let request = {
1369
+ 'id': id,
1370
+ // 'timeInForce': timeInForce,
1371
+ };
1372
+ const triggerPrice = this.safeNumber2(params, 'stopPrice', 'triggerPrice');
1373
+ [request, params] = this.orderRequest(symbol, type, side, amount, request, price, params);
1374
+ let response = undefined;
1375
+ if (triggerPrice !== undefined) {
1376
+ response = await this.privatePutSmartordersId(this.extend(request, params));
1377
+ }
1378
+ else {
1379
+ response = await this.privatePutOrdersId(this.extend(request, params));
1380
+ }
1381
+ //
1382
+ // {
1383
+ // "id" : "78923648051920896",
1384
+ // "clientOrderId" : ""
1385
+ // }
1386
+ //
1387
+ response = this.extend(response, {
1388
+ 'type': side,
1389
+ });
1390
+ return this.parseOrder(response, market);
1391
+ }
1392
+ async cancelOrder(id, symbol = undefined, params = {}) {
1393
+ //
1394
+ // @method
1395
+ // @name poloniex#cancelOrder
1396
+ // @description cancels an open order
1397
+ // @see https://docs.poloniex.com/#authenticated-endpoints-orders-cancel-order-by-id
1398
+ // @see https://docs.poloniex.com/#authenticated-endpoints-smart-orders-cancel-order-by-id // trigger orders
1399
+ // @param {string} id order id
1400
+ // @param {string} symbol unified symbol of the market the order was made in
1401
+ // @param {object} [params] extra parameters specific to the exchange API endpoint
1402
+ // @param {boolean} [params.trigger] true if canceling a trigger order
1403
+ // @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1404
+ //
1405
+ await this.loadMarkets();
1406
+ const request = {};
1407
+ const clientOrderId = this.safeValue(params, 'clientOrderId');
1408
+ if (clientOrderId !== undefined) {
1409
+ id = clientOrderId;
1410
+ }
1411
+ request['id'] = id;
1412
+ const isTrigger = this.safeValue2(params, 'trigger', 'stop');
1413
+ params = this.omit(params, ['clientOrderId', 'trigger', 'stop']);
1414
+ let response = undefined;
1415
+ if (isTrigger) {
1416
+ response = await this.privateDeleteSmartordersId(this.extend(request, params));
1417
+ }
1418
+ else {
1419
+ response = await this.privateDeleteOrdersId(this.extend(request, params));
1420
+ }
1421
+ //
1422
+ // {
1423
+ // "orderId":"210832697138888704",
1424
+ // "clientOrderId":"",
1425
+ // "state":"PENDING_CANCEL",
1426
+ // "code":200,
1427
+ // "message":""
1428
+ // }
1429
+ //
1430
+ return this.parseOrder(response);
1431
+ }
1432
+ async cancelAllOrders(symbol = undefined, params = {}) {
1433
+ /**
1434
+ * @method
1435
+ * @name poloniex#cancelAllOrders
1436
+ * @description cancel all open orders
1437
+ * @see https://docs.poloniex.com/#authenticated-endpoints-orders-cancel-all-orders
1438
+ * @see https://docs.poloniex.com/#authenticated-endpoints-smart-orders-cancel-all-orders // trigger orders
1439
+ * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1440
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1441
+ * @param {boolean} [params.trigger] true if canceling trigger orders
1442
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1443
+ */
1444
+ await this.loadMarkets();
1445
+ const request = {
1446
+ // 'accountTypes': 'SPOT',
1447
+ 'symbols': [],
1448
+ };
1449
+ let market = undefined;
1450
+ if (symbol !== undefined) {
1451
+ market = this.market(symbol);
1452
+ request['symbols'] = [
1453
+ market['id'],
1454
+ ];
1455
+ }
1456
+ const isTrigger = this.safeValue2(params, 'trigger', 'stop');
1457
+ params = this.omit(params, ['trigger', 'stop']);
1458
+ let response = undefined;
1459
+ if (isTrigger) {
1460
+ response = await this.privateDeleteSmartorders(this.extend(request, params));
1461
+ }
1462
+ else {
1463
+ response = await this.privateDeleteOrders(this.extend(request, params));
1464
+ }
1465
+ //
1466
+ // [
1467
+ // {
1468
+ // "orderId" : "78xxxxxxxx80",
1469
+ // "clientOrderId" : "",
1470
+ // "state" : "NEW",
1471
+ // "code" : 200,
1472
+ // "message" : ""
1473
+ // }, {
1474
+ // "orderId" : "78xxxxxxxxx80",
1475
+ // "clientOrderId" : "",
1476
+ // "state" : "NEW",
1477
+ // "code" : 200,
1478
+ // "message" : ""
1479
+ // }
1480
+ // ]
1481
+ //
1482
+ return this.parseOrders(response, market);
1483
+ }
1484
+ async fetchOrder(id, symbol = undefined, params = {}) {
1485
+ /**
1486
+ * @method
1487
+ * @name poloniex#fetchOrder
1488
+ * @description fetch an order by it's id
1489
+ * @see https://docs.poloniex.com/#authenticated-endpoints-orders-order-details
1490
+ * @see https://docs.poloniex.com/#authenticated-endpoints-smart-orders-open-orders // trigger orders
1491
+ * @param {string} id order id
1492
+ * @param {string} symbol unified market symbol, default is undefined
1493
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1494
+ * @param {boolean} [params.trigger] true if fetching a trigger order
1495
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1496
+ */
1497
+ await this.loadMarkets();
1498
+ id = id.toString();
1499
+ const request = {
1500
+ 'id': id,
1501
+ };
1502
+ const isTrigger = this.safeValue2(params, 'trigger', 'stop');
1503
+ params = this.omit(params, ['trigger', 'stop']);
1504
+ let response = undefined;
1505
+ if (isTrigger) {
1506
+ response = await this.privateGetSmartordersId(this.extend(request, params));
1507
+ response = this.safeValue(response, 0);
1508
+ }
1509
+ else {
1510
+ response = await this.privateGetOrdersId(this.extend(request, params));
1511
+ }
1512
+ //
1513
+ // {
1514
+ // "id": "21934611974062080",
1515
+ // "clientOrderId": "123",
1516
+ // "symbol": "TRX_USDC",
1517
+ // "state": "NEW",
1518
+ // "accountType": "SPOT",
1519
+ // "side": "SELL",
1520
+ // "type": "LIMIT",
1521
+ // "timeInForce": "GTC",
1522
+ // "quantity": "1.00",
1523
+ // "price": "10.00",
1524
+ // "avgPrice": "0.00",
1525
+ // "amount": "0.00",
1526
+ // "filledQuantity": "0.00",
1527
+ // "filledAmount": "0.00",
1528
+ // "stopPrice": "3750.00", // for trigger orders
1529
+ // "createTime": 1646196019020,
1530
+ // "updateTime": 1646196019020
1531
+ // }
1532
+ //
1533
+ const order = this.parseOrder(response);
1534
+ order['id'] = id;
1535
+ return order;
1536
+ }
1537
+ async fetchOrderStatus(id, symbol = undefined, params = {}) {
1538
+ await this.loadMarkets();
1539
+ const orders = await this.fetchOpenOrders(symbol, undefined, undefined, params);
1540
+ const indexed = this.indexBy(orders, 'id');
1541
+ return (id in indexed) ? 'open' : 'closed';
1542
+ }
1543
+ async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
1544
+ /**
1545
+ * @method
1546
+ * @name poloniex#fetchOrderTrades
1547
+ * @description fetch all the trades made from a single order
1548
+ * @see https://docs.poloniex.com/#authenticated-endpoints-trades-trades-by-order-id
1549
+ * @param {string} id order id
1550
+ * @param {string} symbol unified market symbol
1551
+ * @param {int} [since] the earliest time in ms to fetch trades for
1552
+ * @param {int} [limit] the maximum number of trades to retrieve
1553
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1554
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1555
+ */
1556
+ await this.loadMarkets();
1557
+ const request = {
1558
+ 'id': id,
1559
+ };
1560
+ const trades = await this.privateGetOrdersIdTrades(this.extend(request, params));
1561
+ //
1562
+ // [
1563
+ // {
1564
+ // "id": "30341456333942784",
1565
+ // "symbol": "LINK_USDT",
1566
+ // "accountType": "SPOT",
1567
+ // "orderId": "30249408733945856",
1568
+ // "side": "BUY",
1569
+ // "type": "LIMIT",
1570
+ // "matchRole": "MAKER",
1571
+ // "createTime": 1648200366864,
1572
+ // "price": "3.1",
1573
+ // "quantity": "1",
1574
+ // "amount": "3.1",
1575
+ // "feeCurrency": "LINK",
1576
+ // "feeAmount": "0.00145",
1577
+ // "pageId": "30341456333942784",
1578
+ // "clientOrderId": ""
1579
+ // }
1580
+ // ]
1581
+ //
1582
+ return this.parseTrades(trades);
1583
+ }
1584
+ parseBalance(response) {
1585
+ const result = {
1586
+ 'info': response,
1587
+ 'timestamp': undefined,
1588
+ 'datetime': undefined,
1589
+ };
1590
+ for (let i = 0; i < response.length; i++) {
1591
+ const account = this.safeValue(response, i, {});
1592
+ const balances = this.safeValue(account, 'balances');
1593
+ for (let j = 0; j < balances.length; j++) {
1594
+ const balance = this.safeValue(balances, j);
1595
+ const currencyId = this.safeString(balance, 'currency');
1596
+ const code = this.safeCurrencyCode(currencyId);
1597
+ const newAccount = this.account();
1598
+ newAccount['free'] = this.safeString(balance, 'available');
1599
+ newAccount['used'] = this.safeString(balance, 'hold');
1600
+ result[code] = newAccount;
1601
+ }
1602
+ }
1603
+ return this.safeBalance(result);
1604
+ }
1605
+ async fetchBalance(params = {}) {
1606
+ /**
1607
+ * @method
1608
+ * @name poloniex#fetchBalance
1609
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
1610
+ * @see https://docs.poloniex.com/#authenticated-endpoints-accounts-all-account-balances
1611
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1612
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1613
+ */
1614
+ await this.loadMarkets();
1615
+ const request = {
1616
+ 'accountType': 'SPOT',
1617
+ };
1618
+ const response = await this.privateGetAccountsBalances(this.extend(request, params));
1619
+ //
1620
+ // [
1621
+ // {
1622
+ // "accountId" : "7xxxxxxxxxx8",
1623
+ // "accountType" : "SPOT",
1624
+ // "balances" : [
1625
+ // {
1626
+ // "currencyId" : "214",
1627
+ // "currency" : "USDT",
1628
+ // "available" : "2.00",
1629
+ // "hold" : "0.00"
1630
+ // }
1631
+ // ]
1632
+ // }
1633
+ // ]
1634
+ //
1635
+ return this.parseBalance(response);
1636
+ }
1637
+ async fetchTradingFees(params = {}) {
1638
+ /**
1639
+ * @method
1640
+ * @name poloniex#fetchTradingFees
1641
+ * @description fetch the trading fees for multiple markets
1642
+ * @see https://docs.poloniex.com/#authenticated-endpoints-accounts-fee-info
1643
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1644
+ * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
1645
+ */
1646
+ await this.loadMarkets();
1647
+ const response = await this.privateGetFeeinfo(params);
1648
+ //
1649
+ // {
1650
+ // "trxDiscount" : false,
1651
+ // "makerRate" : "0.00145",
1652
+ // "takerRate" : "0.00155",
1653
+ // "volume30D" : "0.00"
1654
+ // }
1655
+ //
1656
+ const result = {};
1657
+ for (let i = 0; i < this.symbols.length; i++) {
1658
+ const symbol = this.symbols[i];
1659
+ result[symbol] = {
1660
+ 'info': response,
1661
+ 'symbol': symbol,
1662
+ 'maker': this.safeNumber(response, 'makerRate'),
1663
+ 'taker': this.safeNumber(response, 'takerRate'),
1664
+ 'percentage': true,
1665
+ 'tierBased': true,
1666
+ };
1667
+ }
1668
+ return result;
1669
+ }
1670
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
1671
+ /**
1672
+ * @method
1673
+ * @name poloniex#fetchOrderBook
1674
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1675
+ * @see https://docs.poloniex.com/#public-endpoints-market-data-order-book
1676
+ * @param {string} symbol unified symbol of the market to fetch the order book for
1677
+ * @param {int} [limit] the maximum amount of order book entries to return
1678
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1679
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1680
+ */
1681
+ await this.loadMarkets();
1682
+ const market = this.market(symbol);
1683
+ const request = {
1684
+ 'symbol': market['id'],
1685
+ };
1686
+ if (limit !== undefined) {
1687
+ request['limit'] = limit; // The default value of limit is 10. Valid limit values are: 5, 10, 20, 50, 100, 150.
1688
+ }
1689
+ const response = await this.publicGetMarketsSymbolOrderBook(this.extend(request, params));
1690
+ //
1691
+ // {
1692
+ // "time" : 1659695219507,
1693
+ // "scale" : "-1",
1694
+ // "asks" : [ "23139.82", "0.317981", "23140", "0.191091", "23170.06", "0.01", "23200", "0.107758", "23230.55", "0.01", "23247.2", "0.154", "23254", "0.005121", "23263", "0.038", "23285.4", "0.308", "23300", "0.108896" ],
1695
+ // "bids" : [ "23139.74", "0.432092", "23139.73", "0.198592", "23123.21", "0.000886", "23123.2", "0.308", "23121.4", "0.154", "23105", "0.000789", "23100", "0.078175", "23069.1", "0.026276", "23068.83", "0.001329", "23051", "0.000048" ],
1696
+ // "ts" : 1659695219513
1697
+ // }
1698
+ //
1699
+ const timestamp = this.safeInteger(response, 'time');
1700
+ const asks = this.safeValue(response, 'asks');
1701
+ const bids = this.safeValue(response, 'bids');
1702
+ const asksResult = [];
1703
+ const bidsResult = [];
1704
+ for (let i = 0; i < asks.length; i++) {
1705
+ if ((i % 2) < 1) {
1706
+ const price = this.safeNumber(asks, i);
1707
+ const amount = this.safeNumber(asks, this.sum(i, 1));
1708
+ asksResult.push([price, amount]);
1709
+ }
1710
+ }
1711
+ for (let i = 0; i < bids.length; i++) {
1712
+ if ((i % 2) < 1) {
1713
+ const price = this.safeNumber(bids, i);
1714
+ const amount = this.safeNumber(bids, this.sum(i, 1));
1715
+ bidsResult.push([price, amount]);
1716
+ }
1717
+ }
1718
+ return {
1719
+ 'symbol': market['symbol'],
1720
+ 'bids': this.sortBy(bidsResult, 0, true),
1721
+ 'asks': this.sortBy(asksResult, 0),
1722
+ 'timestamp': timestamp,
1723
+ 'datetime': this.iso8601(timestamp),
1724
+ 'nonce': undefined,
1725
+ };
1726
+ }
1727
+ async createDepositAddress(code, params = {}) {
1728
+ /**
1729
+ * @method
1730
+ * @name poloniex#createDepositAddress
1731
+ * @description create a currency deposit address
1732
+ * @see https://docs.poloniex.com/#authenticated-endpoints-wallets-deposit-addresses
1733
+ * @param {string} code unified currency code of the currency for the deposit address
1734
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1735
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1736
+ */
1737
+ await this.loadMarkets();
1738
+ const currency = this.currency(code);
1739
+ const request = {
1740
+ 'currency': currency['id'],
1741
+ };
1742
+ const networks = this.safeValue(this.options, 'networks', {});
1743
+ let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
1744
+ network = this.safeString(networks, network, network); // handle ERC20>ETH alias
1745
+ if (network !== undefined) {
1746
+ request['currency'] += network; // when network the currency need to be changed to currency+network https://docs.poloniex.com/#withdraw on MultiChain Currencies section
1747
+ params = this.omit(params, 'network');
1748
+ }
1749
+ else {
1750
+ if (currency['id'] === 'USDT') {
1751
+ throw new errors.ArgumentsRequired(this.id + ' createDepositAddress requires a network parameter for ' + code + '.');
1752
+ }
1753
+ }
1754
+ const response = await this.privatePostWalletsAddress(this.extend(request, params));
1755
+ //
1756
+ // {
1757
+ // "address" : "0xfxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxf"
1758
+ // }
1759
+ //
1760
+ let address = this.safeString(response, 'address');
1761
+ let tag = undefined;
1762
+ this.checkAddress(address);
1763
+ if (currency !== undefined) {
1764
+ const depositAddress = this.safeString(currency['info'], 'depositAddress');
1765
+ if (depositAddress !== undefined) {
1766
+ tag = address;
1767
+ address = depositAddress;
1768
+ }
1769
+ }
1770
+ return {
1771
+ 'currency': code,
1772
+ 'address': address,
1773
+ 'tag': tag,
1774
+ 'network': network,
1775
+ 'info': response,
1776
+ };
1777
+ }
1778
+ async fetchDepositAddress(code, params = {}) {
1779
+ /**
1780
+ * @method
1781
+ * @name poloniex#fetchDepositAddress
1782
+ * @description fetch the deposit address for a currency associated with this account
1783
+ * @see https://docs.poloniex.com/#authenticated-endpoints-wallets-deposit-addresses
1784
+ * @param {string} code unified currency code
1785
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1786
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1787
+ */
1788
+ await this.loadMarkets();
1789
+ const currency = this.currency(code);
1790
+ const request = {
1791
+ 'currency': currency['id'],
1792
+ };
1793
+ const networks = this.safeValue(this.options, 'networks', {});
1794
+ let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
1795
+ network = this.safeString(networks, network, network); // handle ERC20>ETH alias
1796
+ if (network !== undefined) {
1797
+ request['currency'] += network; // when network the currency need to be changed to currency+network https://docs.poloniex.com/#withdraw on MultiChain Currencies section
1798
+ params = this.omit(params, 'network');
1799
+ }
1800
+ else {
1801
+ if (currency['id'] === 'USDT') {
1802
+ throw new errors.ArgumentsRequired(this.id + ' fetchDepositAddress requires a network parameter for ' + code + '.');
1803
+ }
1804
+ }
1805
+ const response = await this.privateGetWalletsAddresses(this.extend(request, params));
1806
+ //
1807
+ // {
1808
+ // "USDTTRON" : "Txxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxp"
1809
+ // }
1810
+ //
1811
+ let address = this.safeString(response, request['currency']);
1812
+ let tag = undefined;
1813
+ this.checkAddress(address);
1814
+ if (currency !== undefined) {
1815
+ const depositAddress = this.safeString(currency['info'], 'depositAddress');
1816
+ if (depositAddress !== undefined) {
1817
+ tag = address;
1818
+ address = depositAddress;
1819
+ }
1820
+ }
1821
+ return {
1822
+ 'currency': code,
1823
+ 'address': address,
1824
+ 'tag': tag,
1825
+ 'network': network,
1826
+ 'info': response,
1827
+ };
1828
+ }
1829
+ async transfer(code, amount, fromAccount, toAccount, params = {}) {
1830
+ /**
1831
+ * @method
1832
+ * @name poloniex#transfer
1833
+ * @description transfer currency internally between wallets on the same account
1834
+ * @see https://docs.poloniex.com/#authenticated-endpoints-accounts-accounts-transfer
1835
+ * @param {string} code unified currency code
1836
+ * @param {float} amount amount to transfer
1837
+ * @param {string} fromAccount account to transfer from
1838
+ * @param {string} toAccount account to transfer to
1839
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1840
+ * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
1841
+ */
1842
+ await this.loadMarkets();
1843
+ const currency = this.currency(code);
1844
+ amount = this.currencyToPrecision(code, amount);
1845
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
1846
+ const fromId = this.safeString(accountsByType, fromAccount, fromAccount);
1847
+ const toId = this.safeString(accountsByType, toAccount, fromAccount);
1848
+ const request = {
1849
+ 'amount': amount,
1850
+ 'currency': currency['id'],
1851
+ 'fromAccount': fromId,
1852
+ 'toAccount': toId,
1853
+ };
1854
+ const response = await this.privatePostAccountsTransfer(this.extend(request, params));
1855
+ //
1856
+ // {
1857
+ // "transferId" : "168041074"
1858
+ // }
1859
+ //
1860
+ return this.parseTransfer(response, currency);
1861
+ }
1862
+ parseTransfer(transfer, currency = undefined) {
1863
+ //
1864
+ // {
1865
+ // "transferId" : "168041074"
1866
+ // }
1867
+ //
1868
+ return {
1869
+ 'info': transfer,
1870
+ 'id': this.safeString(transfer, 'transferId'),
1871
+ 'timestamp': undefined,
1872
+ 'datetime': undefined,
1873
+ 'currency': this.safeString(currency, 'id'),
1874
+ 'amount': undefined,
1875
+ 'fromAccount': undefined,
1876
+ 'toAccount': undefined,
1877
+ 'status': undefined,
1878
+ };
1879
+ }
1880
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
1881
+ /**
1882
+ * @method
1883
+ * @name poloniex#withdraw
1884
+ * @description make a withdrawal
1885
+ * @see https://docs.poloniex.com/#authenticated-endpoints-wallets-withdraw-currency
1886
+ * @param {string} code unified currency code
1887
+ * @param {float} amount the amount to withdraw
1888
+ * @param {string} address the address to withdraw to
1889
+ * @param {string} tag
1890
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1891
+ * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1892
+ */
1893
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
1894
+ this.checkAddress(address);
1895
+ await this.loadMarkets();
1896
+ const currency = this.currency(code);
1897
+ const request = {
1898
+ 'currency': currency['id'],
1899
+ 'amount': amount,
1900
+ 'address': address,
1901
+ };
1902
+ if (tag !== undefined) {
1903
+ request['paymentId'] = tag;
1904
+ }
1905
+ const networks = this.safeValue(this.options, 'networks', {});
1906
+ let network = this.safeStringUpper(params, 'network'); // this line allows the user to specify either ERC20 or ETH
1907
+ network = this.safeString(networks, network, network); // handle ERC20>ETH alias
1908
+ if (network !== undefined) {
1909
+ request['currency'] += network; // when network the currency need to be changed to currency+network https://docs.poloniex.com/#withdraw on MultiChain Currencies section
1910
+ params = this.omit(params, 'network');
1911
+ }
1912
+ const response = await this.privatePostWalletsWithdraw(this.extend(request, params));
1913
+ //
1914
+ // {
1915
+ // "response": "Withdrew 1.00000000 USDT.",
1916
+ // "email2FA": false,
1917
+ // "withdrawalNumber": 13449869
1918
+ // }
1919
+ //
1920
+ return this.parseTransaction(response, currency);
1921
+ }
1922
+ async fetchTransactionsHelper(code = undefined, since = undefined, limit = undefined, params = {}) {
1923
+ await this.loadMarkets();
1924
+ const year = 31104000; // 60 * 60 * 24 * 30 * 12 = one year of history, why not
1925
+ const now = this.seconds();
1926
+ const start = (since !== undefined) ? this.parseToInt(since / 1000) : now - 10 * year;
1927
+ const request = {
1928
+ 'start': start,
1929
+ 'end': now, // UNIX timestamp, required
1930
+ };
1931
+ const response = await this.privateGetWalletsActivity(this.extend(request, params));
1932
+ //
1933
+ // {
1934
+ // "adjustments":[],
1935
+ // "deposits":[
1936
+ // {
1937
+ // "currency": "BTC",
1938
+ // "address": "1MEtiqJWru53FhhHrfJPPvd2tC3TPDVcmW",
1939
+ // "amount": "0.01063000",
1940
+ // "confirmations": 1,
1941
+ // "txid": "952b0e1888d6d491591facc0d37b5ebec540ac1efb241fdbc22bcc20d1822fb6",
1942
+ // "timestamp": 1507916888,
1943
+ // "status": "COMPLETE"
1944
+ // },
1945
+ // {
1946
+ // "currency": "ETH",
1947
+ // "address": "0x20108ba20b65c04d82909e91df06618107460197",
1948
+ // "amount": "4.00000000",
1949
+ // "confirmations": 38,
1950
+ // "txid": "0x4be260073491fe63935e9e0da42bd71138fdeb803732f41501015a2d46eb479d",
1951
+ // "timestamp": 1525060430,
1952
+ // "status": "COMPLETE"
1953
+ // }
1954
+ // ],
1955
+ // "withdrawals":[
1956
+ // {
1957
+ // "withdrawalNumber":13449869,
1958
+ // "currency":"USDTTRON", // not documented in API docs, see commonCurrencies in describe()
1959
+ // "address":"TXGaqPW23JdRWhsVwS2mRsGsegbdnAd3Rw",
1960
+ // "amount":"1.00000000",
1961
+ // "fee":"0.00000000",
1962
+ // "timestamp":1591573420,
1963
+ // "status":"COMPLETE: dadf427224b3d44b38a2c13caa4395e4666152556ca0b2f67dbd86a95655150f",
1964
+ // "ipAddress":"x.x.x.x",
1965
+ // "canCancel":0,
1966
+ // "canResendEmail":0,
1967
+ // "paymentID":null,
1968
+ // "scope":"crypto"
1969
+ // },
1970
+ // {
1971
+ // "withdrawalNumber": 8224394,
1972
+ // "currency": "EMC2",
1973
+ // "address": "EYEKyCrqTNmVCpdDV8w49XvSKRP9N3EUyF",
1974
+ // "amount": "63.10796020",
1975
+ // "fee": "0.01000000",
1976
+ // "timestamp": 1510819838,
1977
+ // "status": "COMPLETE: d37354f9d02cb24d98c8c4fc17aa42f475530b5727effdf668ee5a43ce667fd6",
1978
+ // "ipAddress": "x.x.x.x"
1979
+ // },
1980
+ // {
1981
+ // "withdrawalNumber": 9290444,
1982
+ // "currency": "ETH",
1983
+ // "address": "0x191015ff2e75261d50433fbd05bd57e942336149",
1984
+ // "amount": "0.15500000",
1985
+ // "fee": "0.00500000",
1986
+ // "timestamp": 1514099289,
1987
+ // "status": "COMPLETE: 0x12d444493b4bca668992021fd9e54b5292b8e71d9927af1f076f554e4bea5b2d",
1988
+ // "ipAddress": "x.x.x.x"
1989
+ // },
1990
+ // {
1991
+ // "withdrawalNumber": 11518260,
1992
+ // "currency": "BTC",
1993
+ // "address": "8JoDXAmE1GY2LRK8jD1gmAmgRPq54kXJ4t",
1994
+ // "amount": "0.20000000",
1995
+ // "fee": "0.00050000",
1996
+ // "timestamp": 1527918155,
1997
+ // "status": "COMPLETE: 1864f4ebb277d90b0b1ff53259b36b97fa1990edc7ad2be47c5e0ab41916b5ff",
1998
+ // "ipAddress": "x.x.x.x"
1999
+ // }
2000
+ // ]
2001
+ // }
2002
+ //
2003
+ return response;
2004
+ }
2005
+ async fetchDepositsWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
2006
+ /**
2007
+ * @method
2008
+ * @name poloniex#fetchDepositsWithdrawals
2009
+ * @description fetch history of deposits and withdrawals
2010
+ * @see https://docs.poloniex.com/#authenticated-endpoints-wallets-wallets-activity-records
2011
+ * @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
2012
+ * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
2013
+ * @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
2014
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2015
+ * @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2016
+ */
2017
+ await this.loadMarkets();
2018
+ const response = await this.fetchTransactionsHelper(code, since, limit, params);
2019
+ let currency = undefined;
2020
+ if (code !== undefined) {
2021
+ currency = this.currency(code);
2022
+ }
2023
+ const withdrawals = this.safeValue(response, 'withdrawals', []);
2024
+ const deposits = this.safeValue(response, 'deposits', []);
2025
+ const withdrawalTransactions = this.parseTransactions(withdrawals, currency, since, limit);
2026
+ const depositTransactions = this.parseTransactions(deposits, currency, since, limit);
2027
+ const transactions = this.arrayConcat(depositTransactions, withdrawalTransactions);
2028
+ return this.filterByCurrencySinceLimit(this.sortBy(transactions, 'timestamp'), code, since, limit);
2029
+ }
2030
+ async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
2031
+ /**
2032
+ * @method
2033
+ * @name poloniex#fetchWithdrawals
2034
+ * @description fetch all withdrawals made from an account
2035
+ * @see https://docs.poloniex.com/#authenticated-endpoints-wallets-wallets-activity-records
2036
+ * @param {string} code unified currency code
2037
+ * @param {int} [since] the earliest time in ms to fetch withdrawals for
2038
+ * @param {int} [limit] the maximum number of withdrawals structures to retrieve
2039
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2040
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2041
+ */
2042
+ const response = await this.fetchTransactionsHelper(code, since, limit, params);
2043
+ let currency = undefined;
2044
+ if (code !== undefined) {
2045
+ currency = this.currency(code);
2046
+ }
2047
+ const withdrawals = this.safeValue(response, 'withdrawals', []);
2048
+ const transactions = this.parseTransactions(withdrawals, currency, since, limit);
2049
+ return this.filterByCurrencySinceLimit(transactions, code, since, limit);
2050
+ }
2051
+ async fetchDepositWithdrawFees(codes = undefined, params = {}) {
2052
+ /**
2053
+ * @method
2054
+ * @name poloniex#fetchDepositWithdrawFees
2055
+ * @description fetch deposit and withdraw fees
2056
+ * @see https://docs.poloniex.com/#public-endpoints-reference-data-currency-information
2057
+ * @param {string[]|undefined} codes list of unified currency codes
2058
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2059
+ * @returns {object[]} a list of [fees structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
2060
+ */
2061
+ await this.loadMarkets();
2062
+ const response = await this.publicGetCurrencies(this.extend(params, { 'includeMultiChainCurrencies': true }));
2063
+ //
2064
+ // [
2065
+ // {
2066
+ // "1CR": {
2067
+ // "id": 1,
2068
+ // "name": "1CRedit",
2069
+ // "description": "BTC Clone",
2070
+ // "type": "address",
2071
+ // "withdrawalFee": "0.01000000",
2072
+ // "minConf": 10000,
2073
+ // "depositAddress": null,
2074
+ // "blockchain": "1CR",
2075
+ // "delisted": false,
2076
+ // "tradingState": "NORMAL",
2077
+ // "walletState": "DISABLED",
2078
+ // "parentChain": null,
2079
+ // "isMultiChain": false,
2080
+ // "isChildChain": false,
2081
+ // "childChains": []
2082
+ // }
2083
+ // }
2084
+ // ]
2085
+ //
2086
+ const data = {};
2087
+ for (let i = 0; i < response.length; i++) {
2088
+ const entry = response[i];
2089
+ const currencies = Object.keys(entry);
2090
+ const currencyId = this.safeString(currencies, 0);
2091
+ data[currencyId] = entry[currencyId];
2092
+ }
2093
+ return this.parseDepositWithdrawFees(data, codes);
2094
+ }
2095
+ parseDepositWithdrawFees(response, codes = undefined, currencyIdKey = undefined) {
2096
+ //
2097
+ // {
2098
+ // "1CR": {
2099
+ // "id": 1,
2100
+ // "name": "1CRedit",
2101
+ // "description": "BTC Clone",
2102
+ // "type": "address",
2103
+ // "withdrawalFee": "0.01000000",
2104
+ // "minConf": 10000,
2105
+ // "depositAddress": null,
2106
+ // "blockchain": "1CR",
2107
+ // "delisted": false,
2108
+ // "tradingState": "NORMAL",
2109
+ // "walletState": "DISABLED",
2110
+ // "parentChain": null,
2111
+ // "isMultiChain": false,
2112
+ // "isChildChain": false,
2113
+ // "childChains": []
2114
+ // },
2115
+ // }
2116
+ //
2117
+ const depositWithdrawFees = {};
2118
+ codes = this.marketCodes(codes);
2119
+ const responseKeys = Object.keys(response);
2120
+ for (let i = 0; i < responseKeys.length; i++) {
2121
+ const currencyId = responseKeys[i];
2122
+ const code = this.safeCurrencyCode(currencyId);
2123
+ const feeInfo = response[currencyId];
2124
+ if ((codes === undefined) || (this.inArray(code, codes))) {
2125
+ const currency = this.currency(code);
2126
+ depositWithdrawFees[code] = this.parseDepositWithdrawFee(feeInfo, currency);
2127
+ const childChains = this.safeValue(feeInfo, 'childChains');
2128
+ const chainsLength = childChains.length;
2129
+ if (chainsLength > 0) {
2130
+ for (let j = 0; j < childChains.length; j++) {
2131
+ let networkId = childChains[j];
2132
+ networkId = networkId.replace(code, '');
2133
+ const networkCode = this.networkIdToCode(networkId);
2134
+ const networkInfo = this.safeValue(response, networkId);
2135
+ const networkObject = {};
2136
+ const withdrawFee = this.safeNumber(networkInfo, 'withdrawalFee');
2137
+ networkObject[networkCode] = {
2138
+ 'withdraw': {
2139
+ 'fee': withdrawFee,
2140
+ 'percentage': (withdrawFee !== undefined) ? false : undefined,
2141
+ },
2142
+ 'deposit': {
2143
+ 'fee': undefined,
2144
+ 'percentage': undefined,
2145
+ },
2146
+ };
2147
+ depositWithdrawFees[code]['networks'] = this.extend(depositWithdrawFees[code]['networks'], networkObject);
2148
+ }
2149
+ }
2150
+ }
2151
+ }
2152
+ return depositWithdrawFees;
2153
+ }
2154
+ parseDepositWithdrawFee(fee, currency = undefined) {
2155
+ const depositWithdrawFee = this.depositWithdrawFee({});
2156
+ depositWithdrawFee['info'][currency['code']] = fee;
2157
+ const networkId = this.safeString(fee, 'blockchain');
2158
+ const withdrawFee = this.safeNumber(fee, 'withdrawalFee');
2159
+ const withdrawResult = {
2160
+ 'fee': withdrawFee,
2161
+ 'percentage': (withdrawFee !== undefined) ? false : undefined,
2162
+ };
2163
+ const depositResult = {
2164
+ 'fee': undefined,
2165
+ 'percentage': undefined,
2166
+ };
2167
+ depositWithdrawFee['withdraw'] = withdrawResult;
2168
+ depositWithdrawFee['deposit'] = depositResult;
2169
+ const networkCode = this.networkIdToCode(networkId);
2170
+ depositWithdrawFee['networks'][networkCode] = {
2171
+ 'withdraw': withdrawResult,
2172
+ 'deposit': depositResult,
2173
+ };
2174
+ return depositWithdrawFee;
2175
+ }
2176
+ async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
2177
+ /**
2178
+ * @method
2179
+ * @name poloniex#fetchDeposits
2180
+ * @description fetch all deposits made to an account
2181
+ * @see https://docs.poloniex.com/#authenticated-endpoints-wallets-wallets-activity-records
2182
+ * @param {string} code unified currency code
2183
+ * @param {int} [since] the earliest time in ms to fetch deposits for
2184
+ * @param {int} [limit] the maximum number of deposits structures to retrieve
2185
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2186
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2187
+ */
2188
+ const response = await this.fetchTransactionsHelper(code, since, limit, params);
2189
+ let currency = undefined;
2190
+ if (code !== undefined) {
2191
+ currency = this.currency(code);
2192
+ }
2193
+ const deposits = this.safeValue(response, 'deposits', []);
2194
+ const transactions = this.parseTransactions(deposits, currency, since, limit);
2195
+ return this.filterByCurrencySinceLimit(transactions, code, since, limit);
2196
+ }
2197
+ parseTransactionStatus(status) {
2198
+ const statuses = {
2199
+ 'COMPLETE': 'ok',
2200
+ 'COMPLETED': 'ok',
2201
+ 'AWAITING APPROVAL': 'pending',
2202
+ 'AWAITING_APPROVAL': 'pending',
2203
+ 'PENDING': 'pending',
2204
+ 'PROCESSING': 'pending',
2205
+ 'COMPLETE ERROR': 'failed',
2206
+ 'COMPLETE_ERROR': 'failed',
2207
+ };
2208
+ return this.safeString(statuses, status, status);
2209
+ }
2210
+ parseTransaction(transaction, currency = undefined) {
2211
+ //
2212
+ // deposits
2213
+ //
2214
+ // {
2215
+ // "txid": "f49d489616911db44b740612d19464521179c76ebe9021af85b6de1e2f8d68cd",
2216
+ // "amount": "49798.01987021",
2217
+ // "status": "COMPLETE",
2218
+ // "address": "DJVJZ58tJC8UeUv9Tqcdtn6uhWobouxFLT",
2219
+ // "currency": "DOGE",
2220
+ // "timestamp": 1524321838,
2221
+ // "confirmations": 3371,
2222
+ // "depositNumber": 134587098
2223
+ // }
2224
+ //
2225
+ // withdrawals
2226
+ //
2227
+ // {
2228
+ // "withdrawalRequestsId": 7397527,
2229
+ // "currency": "ETC",
2230
+ // "address": "0x26419a62055af459d2cd69bb7392f5100b75e304",
2231
+ // "amount": "13.19951600",
2232
+ // "fee": "0.01000000",
2233
+ // "timestamp": 1506010932,
2234
+ // "status": "COMPLETED",
2235
+ // "txid": "343346392f82ac16e8c2604f2a604b7b2382d0e9d8030f673821f8de4b5f5bk",
2236
+ // "ipAddress": "1.2.3.4",
2237
+ // "paymentID": null
2238
+ // }
2239
+ //
2240
+ // withdraw
2241
+ //
2242
+ // {
2243
+ // "withdrawalRequestsId": 33485231
2244
+ // }
2245
+ //
2246
+ const timestamp = this.safeTimestamp(transaction, 'timestamp');
2247
+ const currencyId = this.safeString(transaction, 'currency');
2248
+ const code = this.safeCurrencyCode(currencyId);
2249
+ let status = this.safeString(transaction, 'status', 'pending');
2250
+ status = this.parseTransactionStatus(status);
2251
+ const txid = this.safeString(transaction, 'txid');
2252
+ const type = ('withdrawalRequestsId' in transaction) ? 'withdrawal' : 'deposit';
2253
+ const id = this.safeString2(transaction, 'withdrawalRequestsId', 'depositNumber');
2254
+ const address = this.safeString(transaction, 'address');
2255
+ const tag = this.safeString(transaction, 'paymentID');
2256
+ let amountString = this.safeString(transaction, 'amount');
2257
+ const feeCostString = this.safeString(transaction, 'fee');
2258
+ if (type === 'withdrawal') {
2259
+ amountString = Precise["default"].stringSub(amountString, feeCostString);
2260
+ }
2261
+ return {
2262
+ 'info': transaction,
2263
+ 'id': id,
2264
+ 'currency': code,
2265
+ 'amount': this.parseNumber(amountString),
2266
+ 'network': undefined,
2267
+ 'address': address,
2268
+ 'addressTo': undefined,
2269
+ 'addressFrom': undefined,
2270
+ 'tag': tag,
2271
+ 'tagTo': undefined,
2272
+ 'tagFrom': undefined,
2273
+ 'status': status,
2274
+ 'type': type,
2275
+ 'updated': undefined,
2276
+ 'txid': txid,
2277
+ 'timestamp': timestamp,
2278
+ 'datetime': this.iso8601(timestamp),
2279
+ 'comment': undefined,
2280
+ 'internal': undefined,
2281
+ 'fee': {
2282
+ 'currency': code,
2283
+ 'cost': this.parseNumber(feeCostString),
2284
+ 'rate': undefined,
2285
+ },
2286
+ };
2287
+ }
2288
+ nonce() {
2289
+ return this.milliseconds();
2290
+ }
2291
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
2292
+ let url = this.urls['api']['rest'];
2293
+ const query = this.omit(params, this.extractParams(path));
2294
+ const implodedPath = this.implodeParams(path, params);
2295
+ if (api === 'public') {
2296
+ url += '/' + implodedPath;
2297
+ if (Object.keys(query).length) {
2298
+ url += '?' + this.urlencode(query);
2299
+ }
2300
+ }
2301
+ else {
2302
+ this.checkRequiredCredentials();
2303
+ const timestamp = this.nonce().toString();
2304
+ let auth = method + "\n"; // eslint-disable-line quotes
2305
+ url += '/' + implodedPath;
2306
+ auth += '/' + implodedPath;
2307
+ if ((method === 'POST') || (method === 'PUT') || (method === 'DELETE')) {
2308
+ auth += "\n"; // eslint-disable-line quotes
2309
+ if (Object.keys(query).length) {
2310
+ body = this.json(query);
2311
+ auth += 'requestBody=' + body + '&';
2312
+ }
2313
+ auth += 'signTimestamp=' + timestamp;
2314
+ }
2315
+ else {
2316
+ let sortedQuery = this.extend({ 'signTimestamp': timestamp }, query);
2317
+ sortedQuery = this.keysort(sortedQuery);
2318
+ auth += "\n" + this.urlencode(sortedQuery); // eslint-disable-line quotes
2319
+ if (Object.keys(query).length) {
2320
+ url += '?' + this.urlencode(query);
2321
+ }
2322
+ }
2323
+ const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256, 'base64');
2324
+ headers = {
2325
+ 'Content-Type': 'application/json',
2326
+ 'key': this.apiKey,
2327
+ 'signTimestamp': timestamp,
2328
+ 'signature': signature,
2329
+ };
2330
+ }
2331
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
2332
+ }
2333
+ handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2334
+ if (response === undefined) {
2335
+ return undefined;
2336
+ }
2337
+ //
2338
+ // {
2339
+ // "code" : 21709,
2340
+ // "message" : "Low available balance"
2341
+ // }
2342
+ //
2343
+ const responseCode = this.safeString(response, 'code');
2344
+ if ((responseCode !== undefined) && (responseCode !== '200')) {
2345
+ const codeInner = response['code'];
2346
+ const message = this.safeString(response, 'message');
2347
+ const feedback = this.id + ' ' + body;
2348
+ this.throwExactlyMatchedException(this.exceptions['exact'], codeInner, feedback);
2349
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
2350
+ throw new errors.ExchangeError(feedback); // unknown message
2351
+ }
2352
+ return undefined;
2353
+ }
2354
+ }
2355
+
2356
+ module.exports = poloniex;