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,2015 @@
1
+ 'use strict';
2
+
3
+ var currencycom$1 = require('./abstract/currencycom.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 currencycom
13
+ * @augments Exchange
14
+ */
15
+ class currencycom extends currencycom$1 {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'currencycom',
19
+ 'name': 'Currency.com',
20
+ 'countries': ['BY'],
21
+ 'rateLimit': 100,
22
+ 'certified': false,
23
+ 'pro': true,
24
+ 'version': 'v2',
25
+ // new metainfo interface
26
+ 'has': {
27
+ 'CORS': undefined,
28
+ 'spot': true,
29
+ 'margin': true,
30
+ 'swap': true,
31
+ 'future': false,
32
+ 'option': false,
33
+ 'addMargin': undefined,
34
+ 'cancelAllOrders': undefined,
35
+ 'cancelOrder': true,
36
+ 'cancelOrders': undefined,
37
+ 'createDepositAddress': undefined,
38
+ 'createLimitOrder': true,
39
+ 'createMarketOrder': true,
40
+ 'createOrder': true,
41
+ 'createStopLimitOrder': true,
42
+ 'createStopMarketOrder': true,
43
+ 'createStopOrder': true,
44
+ 'editOrder': 'emulated',
45
+ 'fetchAccounts': true,
46
+ 'fetchBalance': true,
47
+ 'fetchBidsAsks': undefined,
48
+ 'fetchBorrowRateHistory': undefined,
49
+ 'fetchCanceledOrders': undefined,
50
+ 'fetchClosedOrder': undefined,
51
+ 'fetchClosedOrders': undefined,
52
+ 'fetchCrossBorrowRate': false,
53
+ 'fetchCrossBorrowRates': false,
54
+ 'fetchCurrencies': true,
55
+ 'fetchDeposit': undefined,
56
+ 'fetchDepositAddress': true,
57
+ 'fetchDepositAddresses': false,
58
+ 'fetchDepositAddressesByNetwork': false,
59
+ 'fetchDeposits': true,
60
+ 'fetchDepositsWithdrawals': true,
61
+ 'fetchFundingHistory': false,
62
+ 'fetchFundingRate': false,
63
+ 'fetchFundingRateHistory': false,
64
+ 'fetchFundingRates': false,
65
+ 'fetchIndexOHLCV': false,
66
+ 'fetchIsolatedBorrowRate': false,
67
+ 'fetchIsolatedBorrowRates': false,
68
+ 'fetchL2OrderBook': true,
69
+ 'fetchLedger': true,
70
+ 'fetchLedgerEntry': false,
71
+ 'fetchLeverage': true,
72
+ 'fetchLeverageTiers': false,
73
+ 'fetchMarginMode': false,
74
+ 'fetchMarkets': true,
75
+ 'fetchMarkOHLCV': false,
76
+ 'fetchMyTrades': true,
77
+ 'fetchOHLCV': true,
78
+ 'fetchOpenOrder': undefined,
79
+ 'fetchOpenOrders': true,
80
+ 'fetchOrder': true,
81
+ 'fetchOrderBook': true,
82
+ 'fetchOrderBooks': undefined,
83
+ 'fetchOrders': undefined,
84
+ 'fetchOrderTrades': undefined,
85
+ 'fetchPosition': undefined,
86
+ 'fetchPositionMode': false,
87
+ 'fetchPositions': true,
88
+ 'fetchPositionsRisk': undefined,
89
+ 'fetchPremiumIndexOHLCV': false,
90
+ 'fetchTicker': true,
91
+ 'fetchTickers': true,
92
+ 'fetchTime': true,
93
+ 'fetchTrades': true,
94
+ 'fetchTradingFee': false,
95
+ 'fetchTradingFees': true,
96
+ 'fetchTradingLimits': undefined,
97
+ 'fetchTransactionFee': undefined,
98
+ 'fetchTransactionFees': undefined,
99
+ 'fetchTransactions': 'emulated',
100
+ 'fetchTransfers': undefined,
101
+ 'fetchWithdrawal': undefined,
102
+ 'fetchWithdrawals': true,
103
+ 'reduceMargin': undefined,
104
+ 'setLeverage': undefined,
105
+ 'setMarginMode': undefined,
106
+ 'setPositionMode': undefined,
107
+ 'signIn': undefined,
108
+ 'transfer': undefined,
109
+ 'withdraw': undefined,
110
+ },
111
+ 'timeframes': {
112
+ '1m': '1m',
113
+ '5m': '5m',
114
+ '10m': '10m',
115
+ '15m': '15m',
116
+ '30m': '30m',
117
+ '1h': '1h',
118
+ '4h': '4h',
119
+ '1d': '1d',
120
+ '1w': '1w',
121
+ },
122
+ 'hostname': 'backend.currency.com',
123
+ 'urls': {
124
+ 'logo': 'https://user-images.githubusercontent.com/1294454/83718672-36745c00-a63e-11ea-81a9-677b1f789a4d.jpg',
125
+ 'api': {
126
+ 'public': 'https://api-adapter.{hostname}/api',
127
+ 'private': 'https://api-adapter.{hostname}/api',
128
+ 'marketcap': 'https://marketcap.{hostname}/api',
129
+ },
130
+ 'test': {
131
+ 'public': 'https://demo-api-adapter.{hostname}/api',
132
+ 'private': 'https://demo-api-adapter.{hostname}/api',
133
+ },
134
+ 'www': 'https://www.currency.com',
135
+ 'referral': 'https://currency.com/trading/signup?c=362jaimv&pid=referral',
136
+ 'doc': [
137
+ 'https://currency.com/api',
138
+ ],
139
+ 'fees': 'https://currency.com/fees-charges',
140
+ },
141
+ // rate-limits are described at: https://currency.com/api-get-started
142
+ 'api': {
143
+ 'public': {
144
+ 'get': {
145
+ 'v1/time': 1,
146
+ 'v1/exchangeInfo': 1,
147
+ 'v1/depth': 1,
148
+ 'v1/aggTrades': 1,
149
+ 'v1/klines': 1,
150
+ 'v1/ticker/24hr': 1,
151
+ 'v2/time': 1,
152
+ 'v2/exchangeInfo': 1,
153
+ 'v2/depth': 1,
154
+ 'v2/aggTrades': 1,
155
+ 'v2/klines': 1,
156
+ 'v2/ticker/24hr': 1,
157
+ },
158
+ },
159
+ 'marketcap': {
160
+ 'get': {
161
+ 'v1/assets': 1,
162
+ 'v1/candles': 1,
163
+ 'v1/orderbook': 1,
164
+ 'v1/summary': 1,
165
+ 'v1/ticker': 1,
166
+ 'v1/token/assets': 1,
167
+ 'v1/token/orderbook': 1,
168
+ 'v1/token/summary': 1,
169
+ 'v1/token/ticker': 1,
170
+ 'v1/token/trades': 1,
171
+ 'v1/token_crypto/OHLC': 1,
172
+ 'v1/token_crypto/assets': 1,
173
+ 'v1/token_crypto/orderbook': 1,
174
+ 'v1/token_crypto/summary': 1,
175
+ 'v1/token_crypto/ticker': 1,
176
+ 'v1/token_crypto/trades': 1,
177
+ 'v1/trades': 1,
178
+ },
179
+ },
180
+ 'private': {
181
+ 'get': {
182
+ 'v1/account': 1,
183
+ 'v1/currencies': 1,
184
+ 'v1/deposits': 1,
185
+ 'v1/depositAddress': 1,
186
+ 'v1/ledger': 1,
187
+ 'v1/leverageSettings': 1,
188
+ 'v1/myTrades': 1,
189
+ 'v1/openOrders': 1,
190
+ 'v1/tradingPositions': 1,
191
+ 'v1/tradingPositionsHistory': 1,
192
+ 'v1/transactions': 1,
193
+ 'v1/withdrawals': 1,
194
+ 'v2/account': 1,
195
+ 'v2/currencies': 1,
196
+ 'v2/deposits': 1,
197
+ 'v2/depositAddress': 1,
198
+ 'v2/ledger': 1,
199
+ 'v2/leverageSettings': 1,
200
+ 'v2/myTrades': 1,
201
+ 'v2/openOrders': 1,
202
+ 'v2/tradingPositions': 1,
203
+ 'v2/tradingPositionsHistory': 1,
204
+ 'v2/transactions': 1,
205
+ 'v2/withdrawals': 1,
206
+ 'v2/fetchOrder': 1,
207
+ },
208
+ 'post': {
209
+ 'v1/order': 1,
210
+ 'v1/updateTradingPosition': 1,
211
+ 'v1/updateTradingOrder': 1,
212
+ 'v1/closeTradingPosition': 1,
213
+ 'v2/order': 1,
214
+ 'v2/updateTradingPosition': 1,
215
+ 'v2/updateTradingOrder': 1,
216
+ 'v2/closeTradingPosition': 1,
217
+ },
218
+ 'delete': {
219
+ 'v1/order': 1,
220
+ 'v2/order': 1,
221
+ },
222
+ },
223
+ },
224
+ 'fees': {
225
+ 'trading': {
226
+ 'feeSide': 'get',
227
+ 'tierBased': false,
228
+ 'percentage': true,
229
+ 'taker': this.parseNumber('0.002'),
230
+ 'maker': this.parseNumber('0.002'),
231
+ },
232
+ },
233
+ 'precisionMode': number.TICK_SIZE,
234
+ // exchange-specific options
235
+ 'options': {
236
+ 'defaultTimeInForce': 'GTC',
237
+ 'warnOnFetchOpenOrdersWithoutSymbol': true,
238
+ 'recvWindow': 5 * 1000,
239
+ 'timeDifference': 0,
240
+ 'adjustForTimeDifference': false,
241
+ 'parseOrderToPrecision': false,
242
+ 'newOrderRespType': {
243
+ 'market': 'FULL',
244
+ 'limit': 'RESULT',
245
+ 'stop': 'RESULT',
246
+ },
247
+ 'leverage_markets_suffix': '_LEVERAGE',
248
+ 'collateralCurrencies': ['USD', 'EUR', 'USDT'],
249
+ },
250
+ 'exceptions': {
251
+ 'broad': {
252
+ 'FIELD_VALIDATION_ERROR Cancel is available only for LIMIT order': errors.InvalidOrder,
253
+ 'API key does not exist': errors.AuthenticationError,
254
+ 'Order would trigger immediately.': errors.InvalidOrder,
255
+ 'Account has insufficient balance for requested action.': errors.InsufficientFunds,
256
+ 'Rest API trading is not enabled.': errors.ExchangeNotAvailable,
257
+ 'Combination of parameters invalid': errors.BadRequest,
258
+ 'Invalid limit price': errors.BadRequest,
259
+ 'Only leverage symbol allowed here:': errors.BadSymbol,
260
+ 'market data service is not available': errors.ExchangeNotAvailable,
261
+ 'your time is ahead of server': errors.InvalidNonce,
262
+ 'Can not find account': errors.BadRequest,
263
+ 'You mentioned an invalid value for the price parameter': errors.BadRequest, // -1030
264
+ },
265
+ 'exact': {
266
+ '-1000': errors.ExchangeNotAvailable,
267
+ '-1013': errors.InvalidOrder,
268
+ // '-1021': InvalidNonce, // {"code":"-1021","msg":"your time is ahead of server"} // see above in the broad section
269
+ '-1022': errors.AuthenticationError,
270
+ '-1030': errors.InvalidOrder,
271
+ '-1100': errors.InvalidOrder,
272
+ '-1104': errors.ExchangeError,
273
+ '-1025': errors.AuthenticationError,
274
+ '-1128': errors.BadRequest,
275
+ '-2010': errors.ExchangeError,
276
+ '-2011': errors.OrderNotFound,
277
+ '-2013': errors.OrderNotFound,
278
+ '-2014': errors.AuthenticationError,
279
+ '-2015': errors.AuthenticationError, // "Invalid API-key, IP, or permissions for action."
280
+ },
281
+ },
282
+ 'commonCurrencies': {
283
+ 'ACN': 'Accenture',
284
+ 'AMC': 'AMC Entertainment Holdings',
285
+ 'BNS': 'Bank of Nova Scotia',
286
+ 'CAR': 'Avis Budget Group Inc',
287
+ 'CLR': 'Continental Resources',
288
+ 'EDU': 'New Oriental Education & Technology Group Inc',
289
+ 'ETN': 'Eaton',
290
+ 'FOX': 'Fox Corporation',
291
+ 'GM': 'General Motors Co',
292
+ 'IQ': 'iQIYI',
293
+ 'OSK': 'Oshkosh',
294
+ 'PLAY': "Dave & Buster's Entertainment",
295
+ },
296
+ });
297
+ }
298
+ nonce() {
299
+ return this.milliseconds() - this.options['timeDifference'];
300
+ }
301
+ async fetchTime(params = {}) {
302
+ /**
303
+ * @method
304
+ * @name currencycom#fetchTime
305
+ * @description fetches the current integer timestamp in milliseconds from the exchange server
306
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
307
+ * @returns {int} the current integer timestamp in milliseconds from the exchange server
308
+ */
309
+ const response = await this.publicGetV2Time(params);
310
+ //
311
+ // {
312
+ // "serverTime": 1590998366609
313
+ // }
314
+ //
315
+ return this.safeInteger(response, 'serverTime');
316
+ }
317
+ async fetchCurrencies(params = {}) {
318
+ /**
319
+ * @method
320
+ * @name currencycom#fetchCurrencies
321
+ * @description fetches all available currencies on an exchange
322
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
323
+ * @returns {object} an associative dictionary of currencies
324
+ */
325
+ // requires authentication
326
+ if (!this.checkRequiredCredentials(false)) {
327
+ return undefined;
328
+ }
329
+ const response = await this.privateGetV2Currencies(params);
330
+ //
331
+ // [
332
+ // {
333
+ // "name": "Euro",
334
+ // "displaySymbol": "EUR.cx",
335
+ // "precision": "2",
336
+ // "type": "FIAT",
337
+ // "minWithdrawal": "90.0",
338
+ // "maxWithdrawal": "1.0E+8",
339
+ // "commissionMin": "0.02", // some instruments do not have this property
340
+ // "commissionPercent": "1.5", // some instruments do not have this property
341
+ // "minDeposit": "90.0",
342
+ // },
343
+ // {
344
+ // "name": "Bitcoin",
345
+ // "displaySymbol": "BTC",
346
+ // "precision": "8",
347
+ // "type": "CRYPTO", // only a few major currencies have this value, others like USDT have a value of "TOKEN"
348
+ // "minWithdrawal": "0.00020",
349
+ // "commissionFixed": "0.00010",
350
+ // "minDeposit": "0.00010",
351
+ // },
352
+ // ]
353
+ //
354
+ const result = {};
355
+ for (let i = 0; i < response.length; i++) {
356
+ const currency = response[i];
357
+ const id = this.safeString(currency, 'displaySymbol');
358
+ const code = this.safeCurrencyCode(id);
359
+ const fee = this.safeNumber(currency, 'commissionFixed');
360
+ result[code] = {
361
+ 'id': id,
362
+ 'code': code,
363
+ 'type': this.safeStringLower(currency, 'type'),
364
+ 'name': this.safeString(currency, 'name'),
365
+ 'active': undefined,
366
+ 'deposit': undefined,
367
+ 'withdraw': undefined,
368
+ 'fee': fee,
369
+ 'precision': this.parseNumber(this.parsePrecision(this.safeString(currency, 'precision'))),
370
+ 'limits': {
371
+ 'amount': {
372
+ 'min': undefined,
373
+ 'max': undefined,
374
+ },
375
+ 'withdraw': {
376
+ 'min': this.safeNumber(currency, 'minWithdrawal'),
377
+ 'max': this.safeNumber(currency, 'maxWithdrawal'),
378
+ },
379
+ 'deposit': {
380
+ 'min': this.safeNumber(currency, 'minDeposit'),
381
+ 'max': undefined,
382
+ },
383
+ },
384
+ 'info': currency,
385
+ };
386
+ }
387
+ return result;
388
+ }
389
+ async fetchMarkets(params = {}) {
390
+ /**
391
+ * @method
392
+ * @name currencycom#fetchMarkets
393
+ * @description retrieves data on all markets for currencycom
394
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
395
+ * @returns {object[]} an array of objects representing market data
396
+ */
397
+ const response = await this.publicGetV2ExchangeInfo(params);
398
+ //
399
+ // {
400
+ // "timezone": "UTC",
401
+ // "serverTime": "1645186287261",
402
+ // "rateLimits": [
403
+ // { rateLimitType: "REQUEST_WEIGHT", interval: "MINUTE", intervalNum: "1", limit: "1200" },
404
+ // { rateLimitType: "ORDERS", interval: "SECOND", intervalNum: "1", limit: "10" },
405
+ // { rateLimitType: "ORDERS", interval: "DAY", intervalNum: "1", limit: "864000" },
406
+ // ],
407
+ // "exchangeFilters": [],
408
+ // "symbols": [
409
+ // {
410
+ // "symbol": "BTC/USDT", // BTC/USDT, BTC/USDT_LEVERAGE
411
+ // "name": "Bitcoin / Tether",
412
+ // "status": "TRADING", // TRADING, BREAK, HALT
413
+ // "baseAsset": "BTC",
414
+ // "baseAssetPrecision": "4",
415
+ // "quoteAsset": "USDT",
416
+ // "quoteAssetId": "USDT", // USDT, USDT_LEVERAGE
417
+ // "quotePrecision": "4",
418
+ // "orderTypes": [ "LIMIT", "MARKET" ], // LIMIT, MARKET, STOP
419
+ // "filters": [
420
+ // { filterType: "LOT_SIZE", minQty: "0.0001", maxQty: "100", stepSize: "0.0001", },
421
+ // { filterType: "MIN_NOTIONAL", minNotional: "5", },
422
+ // ],
423
+ // "marketModes": [ "REGULAR" ], // CLOSE_ONLY, LONG_ONLY, REGULAR
424
+ // "marketType": "SPOT", // SPOT, LEVERAGE
425
+ // "longRate": -0.0684932, // LEVERAGE only
426
+ // "shortRate": -0.0684932, // LEVERAGE only
427
+ // "swapChargeInterval": 1440, // LEVERAGE only
428
+ // "country": "",
429
+ // "sector": "",
430
+ // "industry": "",
431
+ // "tradingHours": "UTC; Mon - 22:00, 22:05 -; Tue - 22:00, 22:05 -; Wed - 22:00, 22:05 -; Thu - 22:00, 22:05 -; Fri - 22:00, 23:01 -; Sat - 22:00, 22:05 -; Sun - 21:00, 22:05 -",
432
+ // "tickSize": "0.01",
433
+ // "tickValue": "403.4405", // not available in BTC/USDT_LEVERAGE, but available in BTC/USD_LEVERAGE
434
+ // "exchangeFee": "0.2", // SPOT only
435
+ // "tradingFee": 0.075, // LEVERAGE only
436
+ // "makerFee": -0.025, // LEVERAGE only
437
+ // "takerFee": 0.06, // LEVERAGE only
438
+ // "maxSLGap": 50, // LEVERAGE only
439
+ // "minSLGap": 1, // LEVERAGE only
440
+ // "maxTPGap": 50, // LEVERAGE only
441
+ // "minTPGap": 0.5, // LEVERAGE only
442
+ // "assetType": "CRYPTOCURRENCY",
443
+ // },
444
+ // ]
445
+ // }
446
+ //
447
+ if (this.options['adjustForTimeDifference']) {
448
+ await this.loadTimeDifference();
449
+ }
450
+ const markets = this.safeValue(response, 'symbols', []);
451
+ const result = [];
452
+ for (let i = 0; i < markets.length; i++) {
453
+ const market = markets[i];
454
+ const id = this.safeString(market, 'symbol');
455
+ const baseId = this.safeString(market, 'baseAsset');
456
+ const quoteId = this.safeString(market, 'quoteAsset');
457
+ const base = this.safeCurrencyCode(baseId);
458
+ const quote = this.safeCurrencyCode(quoteId);
459
+ let symbol = base + '/' + quote;
460
+ const typeRaw = this.safeString(market, 'marketType');
461
+ const spot = (typeRaw === 'SPOT');
462
+ const futures = false;
463
+ const swap = (typeRaw === 'LEVERAGE');
464
+ const type = swap ? 'swap' : 'spot';
465
+ const margin = undefined;
466
+ if (swap) {
467
+ symbol = symbol.replace(this.options['leverage_markets_suffix'], '');
468
+ symbol += ':' + quote;
469
+ }
470
+ const active = this.safeString(market, 'status') === 'TRADING';
471
+ // to set taker & maker fees, we use one from the below data - pairs either have 'exchangeFee' or 'tradingFee', if none of them (rare cases), then they should have 'takerFee & makerFee'
472
+ const exchangeFee = this.safeString2(market, 'exchangeFee', 'tradingFee');
473
+ let makerFee = this.safeString(market, 'makerFee', exchangeFee);
474
+ let takerFee = this.safeString(market, 'takerFee', exchangeFee);
475
+ makerFee = Precise["default"].stringDiv(makerFee, '100');
476
+ takerFee = Precise["default"].stringDiv(takerFee, '100');
477
+ const filters = this.safeValue(market, 'filters', []);
478
+ const filtersByType = this.indexBy(filters, 'filterType');
479
+ let limitPriceMin = undefined;
480
+ let limitPriceMax = undefined;
481
+ let precisionPrice = this.safeNumber(market, 'tickSize');
482
+ if ('PRICE_FILTER' in filtersByType) {
483
+ const filter = this.safeValue(filtersByType, 'PRICE_FILTER', {});
484
+ precisionPrice = this.safeNumber(filter, 'tickSize');
485
+ // PRICE_FILTER reports zero values for maxPrice
486
+ // since they updated filter types in November 2018
487
+ // https://github.com/ccxt/ccxt/issues/4286
488
+ // therefore limits['price']['max'] doesn't have any meaningful value except undefined
489
+ limitPriceMin = this.safeNumber(filter, 'minPrice');
490
+ const maxPrice = this.safeString(filter, 'maxPrice');
491
+ if ((maxPrice !== undefined) && (Precise["default"].stringGt(maxPrice, '0'))) {
492
+ limitPriceMax = maxPrice;
493
+ }
494
+ }
495
+ let precisionAmount = this.parseNumber(this.parsePrecision(this.safeString(market, 'baseAssetPrecision')));
496
+ let limitAmount = {
497
+ 'min': undefined,
498
+ 'max': undefined,
499
+ };
500
+ if ('LOT_SIZE' in filtersByType) {
501
+ const filter = this.safeValue(filtersByType, 'LOT_SIZE', {});
502
+ precisionAmount = this.safeNumber(filter, 'stepSize');
503
+ limitAmount = {
504
+ 'min': this.safeNumber(filter, 'minQty'),
505
+ 'max': this.safeNumber(filter, 'maxQty'),
506
+ };
507
+ }
508
+ let limitMarket = {
509
+ 'min': undefined,
510
+ 'max': undefined,
511
+ };
512
+ if ('MARKET_LOT_SIZE' in filtersByType) {
513
+ const filter = this.safeValue(filtersByType, 'MARKET_LOT_SIZE', {});
514
+ limitMarket = {
515
+ 'min': this.safeNumber(filter, 'minQty'),
516
+ 'max': this.safeNumber(filter, 'maxQty'),
517
+ };
518
+ }
519
+ let costMin = undefined;
520
+ if ('MIN_NOTIONAL' in filtersByType) {
521
+ const filter = this.safeValue(filtersByType, 'MIN_NOTIONAL', {});
522
+ costMin = this.safeNumber(filter, 'minNotional');
523
+ }
524
+ const isContract = swap || futures;
525
+ result.push({
526
+ 'id': id,
527
+ 'symbol': symbol,
528
+ 'base': base,
529
+ 'quote': quote,
530
+ 'settle': undefined,
531
+ 'baseId': baseId,
532
+ 'quoteId': quoteId,
533
+ 'settleId': undefined,
534
+ 'type': type,
535
+ 'spot': spot,
536
+ 'margin': margin,
537
+ 'swap': swap,
538
+ 'future': futures,
539
+ 'option': false,
540
+ 'active': active,
541
+ 'contract': isContract,
542
+ 'linear': isContract ? true : undefined,
543
+ 'inverse': undefined,
544
+ 'taker': this.parseNumber(takerFee),
545
+ 'maker': this.parseNumber(makerFee),
546
+ 'contractSize': undefined,
547
+ 'expiry': undefined,
548
+ 'expiryDatetime': undefined,
549
+ 'strike': undefined,
550
+ 'optionType': undefined,
551
+ 'precision': {
552
+ 'amount': precisionAmount,
553
+ 'price': precisionPrice,
554
+ },
555
+ 'limits': {
556
+ 'leverage': {
557
+ 'min': undefined,
558
+ 'max': undefined,
559
+ },
560
+ 'amount': limitAmount,
561
+ 'market': limitMarket,
562
+ 'price': {
563
+ 'min': limitPriceMin,
564
+ 'max': this.parseNumber(limitPriceMax),
565
+ },
566
+ 'cost': {
567
+ 'min': costMin,
568
+ 'max': undefined,
569
+ },
570
+ },
571
+ 'created': undefined,
572
+ 'info': market,
573
+ });
574
+ }
575
+ return result;
576
+ }
577
+ async fetchAccounts(params = {}) {
578
+ /**
579
+ * @method
580
+ * @name currencycom#fetchAccounts
581
+ * @description fetch all the accounts associated with a profile
582
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
583
+ * @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
584
+ */
585
+ const response = await this.privateGetV2Account(params);
586
+ //
587
+ // {
588
+ // "makerCommission": "0.20",
589
+ // "takerCommission": "0.20",
590
+ // "buyerCommission": "0.20",
591
+ // "sellerCommission": "0.20",
592
+ // "canTrade": true,
593
+ // "canWithdraw": true,
594
+ // "canDeposit": true,
595
+ // "updateTime": "1645266330",
596
+ // "userId": "644722",
597
+ // "balances": [
598
+ // {
599
+ // "accountId": "120702016179403605",
600
+ // "collateralCurrency": false,
601
+ // "asset": "CAKE",
602
+ // "free": "3.1",
603
+ // "locked": "0.0",
604
+ // "default": false,
605
+ // },
606
+ // {
607
+ // "accountId": "109698017713125316",
608
+ // "collateralCurrency": true,
609
+ // "asset": "USD",
610
+ // "free": "17.58632",
611
+ // "locked": "0.0",
612
+ // "default": true,
613
+ // }
614
+ // ]
615
+ // }
616
+ //
617
+ const accounts = this.safeValue(response, 'balances', []);
618
+ const result = [];
619
+ for (let i = 0; i < accounts.length; i++) {
620
+ const account = accounts[i];
621
+ const accountId = this.safeString(account, 'accountId'); // must be string, because the numeric value is far too big for integer, and causes bugs
622
+ const currencyId = this.safeString(account, 'asset');
623
+ const currencyCode = this.safeCurrencyCode(currencyId);
624
+ result.push({
625
+ 'id': accountId,
626
+ 'type': undefined,
627
+ 'currency': currencyCode,
628
+ 'info': account,
629
+ });
630
+ }
631
+ return result;
632
+ }
633
+ async fetchTradingFees(params = {}) {
634
+ /**
635
+ * @method
636
+ * @name currencycom#fetchTradingFees
637
+ * @description fetch the trading fees for multiple markets
638
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
639
+ * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
640
+ */
641
+ await this.loadMarkets();
642
+ const response = await this.privateGetV2Account(params);
643
+ //
644
+ // {
645
+ // "makerCommission": "0.20",
646
+ // "takerCommission": "0.20",
647
+ // "buyerCommission": "0.20",
648
+ // "sellerCommission": "0.20",
649
+ // "canTrade": true,
650
+ // "canWithdraw": true,
651
+ // "canDeposit": true,
652
+ // "updateTime": "1645738976",
653
+ // "userId": "-1924114235",
654
+ // "balances": []
655
+ // }
656
+ //
657
+ const makerFee = this.safeNumber(response, 'makerCommission');
658
+ const takerFee = this.safeNumber(response, 'takerCommission');
659
+ const result = {};
660
+ for (let i = 0; i < this.symbols.length; i++) {
661
+ const symbol = this.symbols[i];
662
+ result[symbol] = {
663
+ 'info': response,
664
+ 'symbol': symbol,
665
+ 'maker': makerFee,
666
+ 'taker': takerFee,
667
+ 'percentage': true,
668
+ 'tierBased': false,
669
+ };
670
+ }
671
+ return result;
672
+ }
673
+ parseBalance(response, type = undefined) {
674
+ //
675
+ // {
676
+ // "makerCommission":0.20,
677
+ // "takerCommission":0.20,
678
+ // "buyerCommission":0.20,
679
+ // "sellerCommission":0.20,
680
+ // "canTrade":true,
681
+ // "canWithdraw":true,
682
+ // "canDeposit":true,
683
+ // "updateTime":1591056268,
684
+ // "balances":[
685
+ // {
686
+ // "accountId":5470306579272368,
687
+ // "collateralCurrency":true,
688
+ // "asset":"ETH",
689
+ // "free":0.0,
690
+ // "locked":0.0,
691
+ // "default":false,
692
+ // },
693
+ // ]
694
+ // }
695
+ //
696
+ const result = { 'info': response };
697
+ const balances = this.safeValue(response, 'balances', []);
698
+ for (let i = 0; i < balances.length; i++) {
699
+ const balance = balances[i];
700
+ const currencyId = this.safeString(balance, 'asset');
701
+ const code = this.safeCurrencyCode(currencyId);
702
+ const account = this.account();
703
+ account['free'] = this.safeString(balance, 'free');
704
+ account['used'] = this.safeString(balance, 'locked');
705
+ result[code] = account;
706
+ }
707
+ return this.safeBalance(result);
708
+ }
709
+ async fetchBalance(params = {}) {
710
+ /**
711
+ * @method
712
+ * @name currencycom#fetchBalance
713
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
714
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
715
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
716
+ */
717
+ await this.loadMarkets();
718
+ const response = await this.privateGetV2Account(params);
719
+ //
720
+ // {
721
+ // "makerCommission": "0.20",
722
+ // "takerCommission": "0.20",
723
+ // "buyerCommission": "0.20",
724
+ // "sellerCommission": "0.20",
725
+ // "canTrade": true,
726
+ // "canWithdraw": true,
727
+ // "canDeposit": true,
728
+ // "updateTime": "1645266330",
729
+ // "userId": "644722",
730
+ // "balances": [
731
+ // {
732
+ // "accountId": "120702016179403605",
733
+ // "collateralCurrency": false,
734
+ // "asset": "CAKE",
735
+ // "free": "1.784",
736
+ // "locked": "0.0",
737
+ // "default": false,
738
+ // },
739
+ // {
740
+ // "accountId": "109698017413175316",
741
+ // "collateralCurrency": true,
742
+ // "asset": "USD",
743
+ // "free": "7.58632",
744
+ // "locked": "0.0",
745
+ // "default": true,
746
+ // }
747
+ // ]
748
+ // }
749
+ //
750
+ return this.parseBalance(response);
751
+ }
752
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
753
+ /**
754
+ * @method
755
+ * @name currencycom#fetchOrderBook
756
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
757
+ * @param {string} symbol unified symbol of the market to fetch the order book for
758
+ * @param {int} [limit] the maximum amount of order book entries to return
759
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
760
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
761
+ */
762
+ await this.loadMarkets();
763
+ const market = this.market(symbol);
764
+ const request = {
765
+ 'symbol': market['id'],
766
+ };
767
+ if (limit !== undefined) {
768
+ request['limit'] = limit; // default 100, max 1000, valid limits 5, 10, 20, 50, 100, 500, 1000, 5000
769
+ }
770
+ const response = await this.publicGetV2Depth(this.extend(request, params));
771
+ //
772
+ // {
773
+ // "lastUpdateId":1590999849037,
774
+ // "asks":[
775
+ // [0.02495,60.0345],
776
+ // [0.02496,34.1],
777
+ // ...
778
+ // ],
779
+ // "bids":[
780
+ // [0.02487,72.4144854],
781
+ // [0.02486,24.043],
782
+ // ...
783
+ // ]
784
+ // }
785
+ //
786
+ const orderbook = this.parseOrderBook(response, symbol);
787
+ orderbook['nonce'] = this.safeInteger(response, 'lastUpdateId');
788
+ return orderbook;
789
+ }
790
+ parseTicker(ticker, market = undefined) {
791
+ //
792
+ // fetchTicker
793
+ //
794
+ // {
795
+ // "symbol":"ETH/BTC",
796
+ // "priceChange":"0.00030",
797
+ // "priceChangePercent":"1.21",
798
+ // "weightedAvgPrice":"0.02481",
799
+ // "prevClosePrice":"0.02447",
800
+ // "lastPrice":"0.02477",
801
+ // "lastQty":"60.0",
802
+ // "bidPrice":"0.02477",
803
+ // "askPrice":"0.02484",
804
+ // "openPrice":"0.02447",
805
+ // "highPrice":"0.02524",
806
+ // "lowPrice":"0.02438",
807
+ // "volume":"11.97",
808
+ // "quoteVolume":"0.298053",
809
+ // "openTime":1590969600000,
810
+ // "closeTime":1591000072693
811
+ // }
812
+ //
813
+ // fetchTickers
814
+ //
815
+ // {
816
+ // "symbol": "SHIB/USD_LEVERAGE",
817
+ // "weightedAvgPrice": "0.000027595",
818
+ // "lastPrice": "0.00002737",
819
+ // "lastQty": "1.11111111E8",
820
+ // "bidPrice": "0.00002737",
821
+ // "askPrice": "0.00002782",
822
+ // "highPrice": "0.00002896",
823
+ // "lowPrice": "0.00002738",
824
+ // "volume": "16472160000",
825
+ // "quoteVolume": "454796.3376",
826
+ // "openTime": "1645187472000",
827
+ // "closeTime": "1645273872000",
828
+ // }
829
+ //
830
+ // ws:marketData.subscribe
831
+ //
832
+ // {
833
+ // "symbolName":"TXN",
834
+ // "bid":139.85,
835
+ // "bidQty":2500,
836
+ // "ofr":139.92000000000002,
837
+ // "ofrQty":2500,
838
+ // "timestamp":1597850971558
839
+ // }
840
+ //
841
+ const timestamp = this.safeInteger2(ticker, 'closeTime', 'timestamp');
842
+ const marketId = this.safeString2(ticker, 'symbol', 'symbolName');
843
+ market = this.safeMarket(marketId, market, '/');
844
+ const last = this.safeString(ticker, 'lastPrice');
845
+ return this.safeTicker({
846
+ 'symbol': market['symbol'],
847
+ 'timestamp': timestamp,
848
+ 'datetime': this.iso8601(timestamp),
849
+ 'high': this.safeString(ticker, 'highPrice'),
850
+ 'low': this.safeString(ticker, 'lowPrice'),
851
+ 'bid': this.safeString2(ticker, 'bidPrice', 'bid'),
852
+ 'bidVolume': this.safeString(ticker, 'bidQty'),
853
+ 'ask': this.safeString2(ticker, 'askPrice', 'ofr'),
854
+ 'askVolume': this.safeString(ticker, 'ofrQty'),
855
+ 'vwap': this.safeString(ticker, 'weightedAvgPrice'),
856
+ 'open': this.safeString(ticker, 'openPrice'),
857
+ 'close': last,
858
+ 'last': last,
859
+ 'previousClose': this.safeString(ticker, 'prevClosePrice'),
860
+ 'change': this.safeString(ticker, 'priceChange'),
861
+ 'percentage': this.safeString(ticker, 'priceChangePercent'),
862
+ 'average': undefined,
863
+ 'baseVolume': this.safeString(ticker, 'volume'),
864
+ 'quoteVolume': this.safeString(ticker, 'quoteVolume'),
865
+ 'info': ticker,
866
+ }, market);
867
+ }
868
+ async fetchTicker(symbol, params = {}) {
869
+ /**
870
+ * @method
871
+ * @name currencycom#fetchTicker
872
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
873
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
874
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
875
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
876
+ */
877
+ await this.loadMarkets();
878
+ const market = this.market(symbol);
879
+ const request = {
880
+ 'symbol': market['id'],
881
+ };
882
+ const response = await this.publicGetV2Ticker24hr(this.extend(request, params));
883
+ //
884
+ // {
885
+ // "symbol":"ETH/BTC",
886
+ // "priceChange":"0.00030",
887
+ // "priceChangePercent":"1.21",
888
+ // "weightedAvgPrice":"0.02481",
889
+ // "prevClosePrice":"0.02447",
890
+ // "lastPrice":"0.02477",
891
+ // "lastQty":"60.0",
892
+ // "bidPrice":"0.02477",
893
+ // "askPrice":"0.02484",
894
+ // "openPrice":"0.02447",
895
+ // "highPrice":"0.02524",
896
+ // "lowPrice":"0.02438",
897
+ // "volume":"11.97",
898
+ // "quoteVolume":"0.298053",
899
+ // "openTime":1590969600000,
900
+ // "closeTime":1591000072693
901
+ // }
902
+ //
903
+ return this.parseTicker(response, market);
904
+ }
905
+ async fetchTickers(symbols = undefined, params = {}) {
906
+ /**
907
+ * @method
908
+ * @name currencycom#fetchTickers
909
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
910
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
911
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
912
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
913
+ */
914
+ await this.loadMarkets();
915
+ const response = await this.publicGetV2Ticker24hr(params);
916
+ //
917
+ // [
918
+ // {
919
+ // "symbol": "SHIB/USD_LEVERAGE",
920
+ // "weightedAvgPrice": "0.000027595",
921
+ // "lastPrice": "0.00002737",
922
+ // "lastQty": "1.11111111E8",
923
+ // "bidPrice": "0.00002737",
924
+ // "askPrice": "0.00002782",
925
+ // "highPrice": "0.00002896",
926
+ // "lowPrice": "0.00002738",
927
+ // "volume": "16472160000",
928
+ // "quoteVolume": "454796.3376",
929
+ // "openTime": "1645187472000",
930
+ // "closeTime": "1645273872000",
931
+ // }
932
+ // ]
933
+ //
934
+ return this.parseTickers(response, symbols);
935
+ }
936
+ parseOHLCV(ohlcv, market = undefined) {
937
+ //
938
+ // [
939
+ // 1590971040000,
940
+ // "0.02454",
941
+ // "0.02456",
942
+ // "0.02452",
943
+ // "0.02456",
944
+ // 249
945
+ // ]
946
+ //
947
+ return [
948
+ this.safeInteger(ohlcv, 0),
949
+ this.safeNumber(ohlcv, 1),
950
+ this.safeNumber(ohlcv, 2),
951
+ this.safeNumber(ohlcv, 3),
952
+ this.safeNumber(ohlcv, 4),
953
+ this.safeNumber(ohlcv, 5),
954
+ ];
955
+ }
956
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
957
+ /**
958
+ * @method
959
+ * @name currencycom#fetchOHLCV
960
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
961
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
962
+ * @param {string} timeframe the length of time each candle represents
963
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
964
+ * @param {int} [limit] the maximum amount of candles to fetch
965
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
966
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
967
+ */
968
+ await this.loadMarkets();
969
+ const market = this.market(symbol);
970
+ const request = {
971
+ 'symbol': market['id'],
972
+ 'interval': this.safeString(this.timeframes, timeframe, timeframe),
973
+ };
974
+ if (since !== undefined) {
975
+ request['startTime'] = since;
976
+ }
977
+ if (limit !== undefined) {
978
+ request['limit'] = limit; // default 500, max 1000
979
+ }
980
+ const response = await this.publicGetV2Klines(this.extend(request, params));
981
+ //
982
+ // [
983
+ // [1590971040000,"0.02454","0.02456","0.02452","0.02456",249],
984
+ // [1590971100000,"0.02455","0.02457","0.02452","0.02456",300],
985
+ // [1590971160000,"0.02455","0.02456","0.02453","0.02454",286],
986
+ // ]
987
+ //
988
+ return this.parseOHLCVs(response, market, timeframe, since, limit);
989
+ }
990
+ parseTrade(trade, market = undefined) {
991
+ //
992
+ // fetchTrades (public aggregate trades)
993
+ //
994
+ // {
995
+ // "a":"1658318071", // Aggregate tradeId
996
+ // "p":"0.02476", // Price
997
+ // "q":"0.0", // Official doc says: "Quantity (should be ignored)"
998
+ // "T":"1591001423382", // Epoch timestamp in MS
999
+ // "m":false // Was the buyer the maker
1000
+ // }
1001
+ //
1002
+ // createOrder fills (private)
1003
+ //
1004
+ // {
1005
+ // "price": "9807.05",
1006
+ // "qty": "0.01",
1007
+ // "commission": "0",
1008
+ // "commissionAsset": "dUSD"
1009
+ // }
1010
+ //
1011
+ // fetchMyTrades
1012
+ //
1013
+ // {
1014
+ // "symbol": "DOGE/USD",
1015
+ // "id": "116046000",
1016
+ // "orderId": "00000000-0000-0000-0000-000006dbb8ad",
1017
+ // "price": "0.14094",
1018
+ // "qty": "40.0",
1019
+ // "commission": "0.01",
1020
+ // "commissionAsset": "USD",
1021
+ // "time": "1645283022351",
1022
+ // "buyer": false,
1023
+ // "maker": false,
1024
+ // "isBuyer": false,
1025
+ // "isMaker": false
1026
+ // }
1027
+ //
1028
+ const timestamp = this.safeInteger2(trade, 'T', 'time');
1029
+ const priceString = this.safeString2(trade, 'p', 'price');
1030
+ const amountString = this.safeString2(trade, 'q', 'qty');
1031
+ const id = this.safeString2(trade, 'a', 'id');
1032
+ let side = undefined;
1033
+ const orderId = this.safeString(trade, 'orderId');
1034
+ let takerOrMaker = undefined;
1035
+ if ('m' in trade) {
1036
+ side = trade['m'] ? 'sell' : 'buy'; // this is reversed intentionally [TODO: needs reason to be mentioned]
1037
+ takerOrMaker = 'taker'; // in public trades, it's always taker
1038
+ }
1039
+ else if ('isBuyer' in trade) {
1040
+ side = (trade['isBuyer']) ? 'buy' : 'sell'; // this is a true side
1041
+ takerOrMaker = trade['isMaker'] ? 'maker' : 'taker';
1042
+ }
1043
+ let fee = undefined;
1044
+ if ('commission' in trade) {
1045
+ fee = {
1046
+ 'cost': this.safeString(trade, 'commission'),
1047
+ 'currency': this.safeCurrencyCode(this.safeString(trade, 'commissionAsset')),
1048
+ };
1049
+ }
1050
+ const marketId = this.safeString(trade, 'symbol');
1051
+ const symbol = this.safeSymbol(marketId, market);
1052
+ return this.safeTrade({
1053
+ 'id': id,
1054
+ 'order': orderId,
1055
+ 'timestamp': timestamp,
1056
+ 'datetime': this.iso8601(timestamp),
1057
+ 'symbol': symbol,
1058
+ 'type': undefined,
1059
+ 'takerOrMaker': takerOrMaker,
1060
+ 'side': side,
1061
+ 'price': priceString,
1062
+ 'amount': amountString,
1063
+ 'cost': undefined,
1064
+ 'fee': fee,
1065
+ 'info': trade,
1066
+ }, market);
1067
+ }
1068
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
1069
+ /**
1070
+ * @method
1071
+ * @name currencycom#fetchTrades
1072
+ * @description get the list of most recent trades for a particular symbol
1073
+ * @param {string} symbol unified symbol of the market to fetch trades for
1074
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
1075
+ * @param {int} [limit] the maximum amount of trades to fetch
1076
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1077
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1078
+ */
1079
+ await this.loadMarkets();
1080
+ const market = this.market(symbol);
1081
+ const request = {
1082
+ 'symbol': market['id'],
1083
+ // 'limit': 500, // default 500, max 1000
1084
+ };
1085
+ if (limit !== undefined) {
1086
+ request['limit'] = Math.min(limit, 1000); // default 500, max 1000
1087
+ }
1088
+ if (since !== undefined) {
1089
+ request['startTime'] = since;
1090
+ }
1091
+ const response = await this.publicGetV2AggTrades(this.extend(request, params));
1092
+ //
1093
+ // [
1094
+ // {
1095
+ // "a":"1658318071", // Aggregate tradeId
1096
+ // "p":"0.02476", // Price
1097
+ // "q":"0.0", // Official doc says: "Quantity (should be ignored)"
1098
+ // "T":"1591001423382", // Epoch timestamp in MS
1099
+ // "m":false // Was the buyer the maker
1100
+ // },
1101
+ // ]
1102
+ //
1103
+ return this.parseTrades(response, market, since, limit);
1104
+ }
1105
+ parseOrder(order, market = undefined) {
1106
+ //
1107
+ // createOrder
1108
+ //
1109
+ // limit
1110
+ //
1111
+ // {
1112
+ // "symbol": "BTC/USD",
1113
+ // "orderId": "00000000-0000-0000-0000-000006eacaa0",
1114
+ // "transactTime": "1645281669295",
1115
+ // "price": "30000.00000000",
1116
+ // "origQty": "0.0002", // might not be present for "market" order
1117
+ // "executedQty": "0.0", // positive for BUY, negative for SELL. This property might not be present in Leverage markets
1118
+ // "margin": 0.1, // present in leverage markets
1119
+ // "status": "NEW", // NEW, FILLED, ...
1120
+ // "timeInForce": "GTC",
1121
+ // "type": "LIMIT", // LIMIT, MARKET
1122
+ // "side": "BUY",
1123
+ // "fills": [ // this field might not be present if there were no fills
1124
+ // {
1125
+ // "price": "0.14094",
1126
+ // "qty": "40.0",
1127
+ // "commission": "0",
1128
+ // "commissionAsset": "dUSD",
1129
+ // },
1130
+ // ],
1131
+ // }
1132
+ //
1133
+ // fetchOrder (fetchOpenOrders is an array same structure, with some extra fields)
1134
+ //
1135
+ // {
1136
+ // "symbol": "BTC/USD_LEVERAGE",
1137
+ // "accountId": "123456789012345678",
1138
+ // "orderId": "00a01234-0123-54c4-0000-123451234567",
1139
+ // "price": "25779.35",
1140
+ // "status": "MODIFIED",
1141
+ // "type": "LIMIT",
1142
+ // "timeInForceType": "GTC",
1143
+ // "side": "BUY",
1144
+ // "guaranteedStopLoss": false,
1145
+ // "trailingStopLoss": false,
1146
+ // "margin": "0.05",
1147
+ // "takeProfit": "27020.00",
1148
+ // "stopLoss": "24500.35",
1149
+ // "fills": [], // might not be present
1150
+ // "timestamp": "1685958369623", // "time" in "fetchOpenOrders"
1151
+ // "expireTime": "1686167960000", // "expireTimestamp" in "fetchOpenOrders"
1152
+ // "quantity": "0.00040", // "origQty" in "fetchOpenOrders"
1153
+ // "executedQty": "0.0", // present in "fetchOpenOrders"
1154
+ // "updateTime": "1685958369542", // present in "fetchOpenOrders"
1155
+ // "leverage": true, // present in "fetchOpenOrders"
1156
+ // "working": true // present in "fetchOpenOrders"
1157
+ // }
1158
+ //
1159
+ // cancelOrder
1160
+ //
1161
+ // {
1162
+ // "symbol": "DOGE/USD",
1163
+ // "orderId": "00000000-0000-0003-0000-000006db714c",
1164
+ // "price": "0.13",
1165
+ // "origQty": "30.0",
1166
+ // "executedQty": "0.0",
1167
+ // "status": "CANCELED",
1168
+ // "timeInForce": "GTC",
1169
+ // "type": "LIMIT",
1170
+ // "side": "BUY",
1171
+ // }
1172
+ //
1173
+ const marketId = this.safeString(order, 'symbol');
1174
+ const symbol = this.safeSymbol(marketId, market, '/');
1175
+ const id = this.safeString(order, 'orderId');
1176
+ const price = this.safeString(order, 'price');
1177
+ const amount = this.safeString2(order, 'origQty', 'quantity');
1178
+ const filledRaw = this.safeString(order, 'executedQty');
1179
+ const filled = Precise["default"].stringAbs(filledRaw);
1180
+ const status = this.parseOrderStatus(this.safeString(order, 'status'));
1181
+ const timeInForce = this.parseOrderTimeInForce(this.safeString2(order, 'timeInForce', 'timeInForceType'));
1182
+ const type = this.parseOrderType(this.safeString(order, 'type'));
1183
+ const side = this.parseOrderSide(this.safeString(order, 'side'));
1184
+ const timestamp = this.safeIntegerN(order, ['time', 'transactTime', 'timestamp']);
1185
+ const fills = this.safeValue(order, 'fills');
1186
+ return this.safeOrder({
1187
+ 'info': order,
1188
+ 'id': id,
1189
+ 'timestamp': timestamp,
1190
+ 'datetime': this.iso8601(timestamp),
1191
+ 'lastTradeTimestamp': undefined,
1192
+ 'symbol': symbol,
1193
+ 'type': type,
1194
+ 'timeInForce': timeInForce,
1195
+ 'side': side,
1196
+ 'price': price,
1197
+ 'stopPrice': undefined,
1198
+ 'triggerPrice': undefined,
1199
+ 'amount': amount,
1200
+ 'cost': undefined,
1201
+ 'average': undefined,
1202
+ 'filled': filled,
1203
+ 'remaining': undefined,
1204
+ 'status': status,
1205
+ 'fee': undefined,
1206
+ 'trades': fills,
1207
+ }, market);
1208
+ }
1209
+ parseOrderStatus(status) {
1210
+ const statuses = {
1211
+ 'NEW': 'open',
1212
+ 'CREATED': 'open',
1213
+ 'MODIFIED': 'open',
1214
+ 'PARTIALLY_FILLED': 'open',
1215
+ 'FILLED': 'closed',
1216
+ 'CANCELED': 'canceled',
1217
+ 'PENDING_CANCEL': 'canceling',
1218
+ 'REJECTED': 'rejected',
1219
+ 'EXPIRED': 'expired',
1220
+ };
1221
+ return this.safeString(statuses, status, status);
1222
+ }
1223
+ parseOrderType(status) {
1224
+ const statuses = {
1225
+ 'MARKET': 'market',
1226
+ 'LIMIT': 'limit',
1227
+ 'STOP': 'stop',
1228
+ // temporarily we remove custom mappings
1229
+ // 'LIMIT_MAKER': '',
1230
+ // 'STOP_LOSS': 'stop-loss',
1231
+ // 'STOP_LOSS_LIMIT': 'stop-limit',
1232
+ // 'TAKE_PROFIT': 'take-profit',
1233
+ // 'TAKE_PROFIT_LIMIT': 'take-profit',
1234
+ };
1235
+ return this.safeString(statuses, status, status);
1236
+ }
1237
+ parseOrderTimeInForce(status) {
1238
+ const statuses = {
1239
+ 'GTC': 'GTC',
1240
+ 'FOK': 'FOK',
1241
+ 'IOC': 'IOC',
1242
+ };
1243
+ return this.safeString(statuses, status, status);
1244
+ }
1245
+ parseOrderSide(status) {
1246
+ const statuses = {
1247
+ 'BUY': 'buy',
1248
+ 'SELL': 'sell',
1249
+ };
1250
+ return this.safeString(statuses, status, status);
1251
+ }
1252
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1253
+ /**
1254
+ * @method
1255
+ * @name currencycom#createOrder
1256
+ * @description create a trade order
1257
+ * @param {string} symbol unified symbol of the market to create an order in
1258
+ * @param {string} type 'market' or 'limit'
1259
+ * @param {string} side 'buy' or 'sell'
1260
+ * @param {float} amount how much of currency you want to trade in units of base currency
1261
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1262
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1263
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1264
+ */
1265
+ await this.loadMarkets();
1266
+ const market = this.market(symbol);
1267
+ let accountId = undefined;
1268
+ if (market['margin']) {
1269
+ accountId = this.safeString(this.options, 'accountId');
1270
+ accountId = this.safeString(params, 'accountId', accountId);
1271
+ if (accountId === undefined) {
1272
+ throw new errors.ArgumentsRequired(this.id + " createOrder() requires an accountId parameter or an exchange.options['accountId'] option for " + market['type'] + ' markets');
1273
+ }
1274
+ }
1275
+ const newOrderRespType = this.safeValue(this.options['newOrderRespType'], type, 'RESULT');
1276
+ const request = {
1277
+ 'symbol': market['id'],
1278
+ 'quantity': this.amountToPrecision(symbol, amount),
1279
+ 'type': type.toUpperCase(),
1280
+ 'side': side.toUpperCase(),
1281
+ 'newOrderRespType': newOrderRespType, // 'RESULT' for full order or 'FULL' for order with fills
1282
+ // 'leverage': 1,
1283
+ // 'accountId': 5470306579272968, // required for leverage markets
1284
+ // 'takeProfit': '123.45',
1285
+ // 'stopLoss': '54.321',
1286
+ // 'guaranteedStopLoss': '54.321',
1287
+ };
1288
+ if (type === 'limit') {
1289
+ request['price'] = this.priceToPrecision(symbol, price);
1290
+ request['timeInForce'] = this.options['defaultTimeInForce'];
1291
+ }
1292
+ else {
1293
+ if (type === 'stop') {
1294
+ request['type'] = 'STOP';
1295
+ request['price'] = this.priceToPrecision(symbol, price);
1296
+ }
1297
+ else if (type === 'market') {
1298
+ const stopPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
1299
+ params = this.omit(params, ['triggerPrice', 'stopPrice']);
1300
+ if (stopPrice !== undefined) {
1301
+ request['type'] = 'STOP';
1302
+ request['price'] = this.priceToPrecision(symbol, stopPrice);
1303
+ }
1304
+ }
1305
+ }
1306
+ const response = await this.privatePostV2Order(this.extend(request, params));
1307
+ //
1308
+ // limit
1309
+ //
1310
+ // {
1311
+ // "symbol": "BTC/USD",
1312
+ // "orderId": "00000000-0000-0000-0000-000006eaaaa0",
1313
+ // "transactTime": "1645281669295",
1314
+ // "price": "30000.00000000",
1315
+ // "origQty": "0.0002",
1316
+ // "executedQty": "0.0", // positive for BUY, negative for SELL
1317
+ // "status": "NEW",
1318
+ // "timeInForce": "GTC",
1319
+ // "type": "LIMIT",
1320
+ // "side": "BUY",
1321
+ // }
1322
+ //
1323
+ // market
1324
+ //
1325
+ // {
1326
+ // "symbol": "DOGE/USD",
1327
+ // "orderId": "00000000-0000-0000-0000-000006eab8ad",
1328
+ // "transactTime": "1645283022252",
1329
+ // "price": "0.14066000",
1330
+ // "origQty": "40",
1331
+ // "executedQty": "40.0", // positive for BUY, negative for SELL
1332
+ // "status": "FILLED",
1333
+ // "timeInForce": "FOK",
1334
+ // "type": "MARKET",
1335
+ // "side": "BUY",
1336
+ // "fills": [
1337
+ // {
1338
+ // "price": "0.14094",
1339
+ // "qty": "40.0",
1340
+ // "commission": "0",
1341
+ // "commissionAsset": "dUSD"
1342
+ // }
1343
+ // ]
1344
+ // }
1345
+ //
1346
+ return this.parseOrder(response, market);
1347
+ }
1348
+ async fetchOrder(id, symbol = undefined, params = {}) {
1349
+ /**
1350
+ * @method
1351
+ * @name currencycom#fetchOrder
1352
+ * @description fetches information on an order made by the user
1353
+ * @see https://apitradedoc.currency.com/swagger-ui.html#/rest-api/getOrderUsingGET
1354
+ * @param {string} symbol unified symbol of the market the order was made in
1355
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1356
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1357
+ */
1358
+ if (symbol === undefined) {
1359
+ throw new errors.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
1360
+ }
1361
+ await this.loadMarkets();
1362
+ const market = this.market(symbol);
1363
+ const request = {
1364
+ 'orderId': id,
1365
+ 'symbol': market['id'],
1366
+ };
1367
+ const response = await this.privateGetV2FetchOrder(this.extend(request, params));
1368
+ //
1369
+ // {
1370
+ // "accountId": "109698017413125316",
1371
+ // "orderId": "2810f1c5-0079-54c4-0000-000080421601",
1372
+ // "quantity": "20.0",
1373
+ // "price": "0.06",
1374
+ // "timestamp": "1661157503788",
1375
+ // "status": "CREATED",
1376
+ // "type": "LIMIT",
1377
+ // "timeInForceType": "GTC",
1378
+ // "side": "BUY",
1379
+ // "margin": "0.1",
1380
+ // "fills": [ // might not be present
1381
+ // {
1382
+ // "price": "0.14094",
1383
+ // "qty": "40.0",
1384
+ // "commission": "0",
1385
+ // "commissionAsset": "dUSD"
1386
+ // }
1387
+ // ]
1388
+ // }
1389
+ //
1390
+ return this.parseOrder(response);
1391
+ }
1392
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1393
+ /**
1394
+ * @method
1395
+ * @name currencycom#fetchOpenOrders
1396
+ * @description fetch all unfilled currently open orders
1397
+ * @param {string} symbol unified market symbol
1398
+ * @param {int} [since] the earliest time in ms to fetch open orders for
1399
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
1400
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1401
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1402
+ */
1403
+ await this.loadMarkets();
1404
+ let market = undefined;
1405
+ const request = {};
1406
+ if (symbol !== undefined) {
1407
+ market = this.market(symbol);
1408
+ request['symbol'] = market['id'];
1409
+ }
1410
+ else if (this.options['warnOnFetchOpenOrdersWithoutSymbol']) {
1411
+ const symbols = this.symbols;
1412
+ const numSymbols = symbols.length;
1413
+ const fetchOpenOrdersRateLimit = this.parseToInt(numSymbols / 2);
1414
+ throw new errors.ExchangeError(this.id + ' fetchOpenOrders() WARNING: fetching open orders without specifying a symbol is rate-limited to one call per ' + fetchOpenOrdersRateLimit.toString() + ' seconds. Do not call this method frequently to avoid ban. Set ' + this.id + '.options["warnOnFetchOpenOrdersWithoutSymbol"] = false to suppress this warning message.');
1415
+ }
1416
+ const response = await this.privateGetV2OpenOrders(this.extend(request, params));
1417
+ //
1418
+ // [
1419
+ // {
1420
+ // "symbol": "DOGE/USD",
1421
+ // "orderId": "00000000-0000-0003-0000-000004bac57a",
1422
+ // "price": "0.13",
1423
+ // "origQty": "39.0",
1424
+ // "executedQty": "0.0", // positive for BUY, negative for SELL
1425
+ // "status": "NEW",
1426
+ // "timeInForce": "GTC",
1427
+ // "type": "LIMIT",
1428
+ // "side": "BUY",
1429
+ // "time": "1645284216240",
1430
+ // "updateTime": "1645284216240",
1431
+ // "leverage": false,
1432
+ // "working": true
1433
+ // },
1434
+ // ]
1435
+ //
1436
+ return this.parseOrders(response, market, since, limit, params);
1437
+ }
1438
+ async cancelOrder(id, symbol = undefined, params = {}) {
1439
+ /**
1440
+ * @method
1441
+ * @name currencycom#cancelOrder
1442
+ * @description cancels an open order
1443
+ * @param {string} id order id
1444
+ * @param {string} symbol unified symbol of the market the order was made in
1445
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1446
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1447
+ */
1448
+ if (symbol === undefined) {
1449
+ throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
1450
+ }
1451
+ await this.loadMarkets();
1452
+ const market = this.market(symbol);
1453
+ const origClientOrderId = this.safeValue(params, 'origClientOrderId');
1454
+ const request = {
1455
+ 'symbol': market['id'],
1456
+ // 'orderId': parseInt (id),
1457
+ // 'origClientOrderId': id,
1458
+ };
1459
+ if (origClientOrderId === undefined) {
1460
+ request['orderId'] = id;
1461
+ }
1462
+ else {
1463
+ request['origClientOrderId'] = origClientOrderId;
1464
+ }
1465
+ const response = await this.privateDeleteV2Order(this.extend(request, params));
1466
+ //
1467
+ // {
1468
+ // "symbol": "DOGE/USD",
1469
+ // "orderId": "00000000-0000-0003-0000-000006db764c",
1470
+ // "price": "0.13",
1471
+ // "origQty": "30.0",
1472
+ // "executedQty": "0.0", // positive for BUY, negative for SELL
1473
+ // "status": "CANCELED",
1474
+ // "timeInForce": "GTC",
1475
+ // "type": "LIMIT",
1476
+ // "side": "BUY",
1477
+ // }
1478
+ //
1479
+ return this.parseOrder(response, market);
1480
+ }
1481
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1482
+ /**
1483
+ * @method
1484
+ * @name currencycom#fetchMyTrades
1485
+ * @description fetch all trades made by the user
1486
+ * @param {string} symbol unified market symbol
1487
+ * @param {int} [since] the earliest time in ms to fetch trades for
1488
+ * @param {int} [limit] the maximum number of trades structures to retrieve
1489
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1490
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1491
+ */
1492
+ if (symbol === undefined) {
1493
+ throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
1494
+ }
1495
+ await this.loadMarkets();
1496
+ const market = this.market(symbol);
1497
+ const request = {
1498
+ 'symbol': market['id'],
1499
+ };
1500
+ if (limit !== undefined) {
1501
+ request['limit'] = limit;
1502
+ }
1503
+ const response = await this.privateGetV2MyTrades(this.extend(request, params));
1504
+ //
1505
+ // [
1506
+ // {
1507
+ // "symbol": "DOGE/USD",
1508
+ // "id": "116046000",
1509
+ // "orderId": "00000000-0000-0000-0000-000006dbb8ad",
1510
+ // "price": "0.14094",
1511
+ // "qty": "40.0",
1512
+ // "commission": "0.01",
1513
+ // "commissionAsset": "USD",
1514
+ // "time": "1645283022351",
1515
+ // "buyer": false,
1516
+ // "maker": false,
1517
+ // "isBuyer": false,
1518
+ // "isMaker": false
1519
+ // },
1520
+ // ]
1521
+ //
1522
+ return this.parseTrades(response, market, since, limit);
1523
+ }
1524
+ async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
1525
+ /**
1526
+ * @method
1527
+ * @name currencycom#fetchDeposits
1528
+ * @description fetch all deposits made to an account
1529
+ * @param {string} code unified currency code
1530
+ * @param {int} [since] the earliest time in ms to fetch deposits for
1531
+ * @param {int} [limit] the maximum number of deposits structures to retrieve
1532
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1533
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1534
+ */
1535
+ return await this.fetchTransactionsByMethod('privateGetV2Deposits', code, since, limit, params);
1536
+ }
1537
+ async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
1538
+ /**
1539
+ * @method
1540
+ * @name currencycom#fetchWithdrawals
1541
+ * @description fetch all withdrawals made from an account
1542
+ * @param {string} code unified currency code
1543
+ * @param {int} [since] the earliest time in ms to fetch withdrawals for
1544
+ * @param {int} [limit] the maximum number of withdrawals structures to retrieve
1545
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1546
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1547
+ */
1548
+ return await this.fetchTransactionsByMethod('privateGetV2Withdrawals', code, since, limit, params);
1549
+ }
1550
+ async fetchDepositsWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
1551
+ /**
1552
+ * @method
1553
+ * @name currencycom#fetchDepositsWithdrawals
1554
+ * @description fetch history of deposits and withdrawals
1555
+ * @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
1556
+ * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
1557
+ * @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
1558
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1559
+ * @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1560
+ */
1561
+ return await this.fetchTransactionsByMethod('privateGetV2Transactions', code, since, limit, params);
1562
+ }
1563
+ async fetchTransactionsByMethod(method, code = undefined, since = undefined, limit = undefined, params = {}) {
1564
+ await this.loadMarkets();
1565
+ const request = {};
1566
+ let currency = undefined;
1567
+ if (code !== undefined) {
1568
+ currency = this.currency(code);
1569
+ }
1570
+ if (since !== undefined) {
1571
+ request['startTime'] = since;
1572
+ }
1573
+ if (limit !== undefined) {
1574
+ request['limit'] = limit;
1575
+ }
1576
+ let response = undefined;
1577
+ if (method === 'privateGetV2Deposits') {
1578
+ response = await this.privateGetV2Deposits(this.extend(request, params));
1579
+ }
1580
+ else if (method === 'privateGetV2Withdrawals') {
1581
+ response = await this.privateGetV2Withdrawals(this.extend(request, params));
1582
+ }
1583
+ else if (method === 'privateGetV2Transactions') {
1584
+ response = await this.privateGetV2Transactions(this.extend(request, params));
1585
+ }
1586
+ else {
1587
+ throw new errors.NotSupported(this.id + ' fetchTransactionsByMethod() not support this method');
1588
+ }
1589
+ //
1590
+ // [
1591
+ // {
1592
+ // "id": "616769213",
1593
+ // "balance": "2.088",
1594
+ // "amount": "1.304", // negative for 'withdrawal'
1595
+ // "currency": "CAKE",
1596
+ // "type": "deposit",
1597
+ // "timestamp": "1645282121023",
1598
+ // "paymentMethod": "BLOCKCHAIN",
1599
+ // "blockchainTransactionHash": "0x57c68c1f2ae74d5eda5a2a00516361d241a5c9e1ee95bf32573523857c38c112",
1600
+ // "status": "PROCESSED",
1601
+ // "commission": "0.14", // this property only exists in withdrawal
1602
+ // },
1603
+ // ]
1604
+ //
1605
+ return this.parseTransactions(response, currency, since, limit, params);
1606
+ }
1607
+ parseTransaction(transaction, currency = undefined) {
1608
+ //
1609
+ // {
1610
+ // "id": "616769213",
1611
+ // "balance": "2.088",
1612
+ // "amount": "1.304", // negative for 'withdrawal'
1613
+ // "currency": "CAKE",
1614
+ // "type": "deposit",
1615
+ // "timestamp": "1645282121023",
1616
+ // "paymentMethod": "BLOCKCHAIN",
1617
+ // "blockchainTransactionHash": "0x57c68c1f2ae74d5eda5a2a00516361d241a5c9e1ee95bf32573523857c38c112",
1618
+ // "status": "PROCESSED",
1619
+ // "commission": "0.14", // this property only exists in withdrawal
1620
+ // }
1621
+ //
1622
+ const timestamp = this.safeInteger(transaction, 'timestamp');
1623
+ const currencyId = this.safeString(transaction, 'currency');
1624
+ const code = this.safeCurrencyCode(currencyId, currency);
1625
+ const feeCost = this.safeString(transaction, 'commission');
1626
+ const fee = {
1627
+ 'currency': undefined,
1628
+ 'cost': undefined,
1629
+ 'rate': undefined,
1630
+ };
1631
+ if (feeCost !== undefined) {
1632
+ fee['currency'] = code;
1633
+ fee['cost'] = feeCost;
1634
+ }
1635
+ return {
1636
+ 'info': transaction,
1637
+ 'id': this.safeString(transaction, 'id'),
1638
+ 'txid': this.safeString(transaction, 'blockchainTransactionHash'),
1639
+ 'type': this.parseTransactionType(this.safeString(transaction, 'type')),
1640
+ 'currency': code,
1641
+ 'network': undefined,
1642
+ 'amount': this.safeNumber(transaction, 'amount'),
1643
+ 'status': this.parseTransactionStatus(this.safeString(transaction, 'state')),
1644
+ 'timestamp': timestamp,
1645
+ 'datetime': this.iso8601(timestamp),
1646
+ 'address': undefined,
1647
+ 'addressFrom': undefined,
1648
+ 'addressTo': undefined,
1649
+ 'tag': undefined,
1650
+ 'tagFrom': undefined,
1651
+ 'tagTo': undefined,
1652
+ 'updated': undefined,
1653
+ 'internal': undefined,
1654
+ 'comment': undefined,
1655
+ 'fee': fee,
1656
+ };
1657
+ }
1658
+ parseTransactionStatus(status) {
1659
+ const statuses = {
1660
+ 'APPROVAL': 'pending',
1661
+ 'PROCESSED': 'ok',
1662
+ };
1663
+ return this.safeString(statuses, status, status);
1664
+ }
1665
+ parseTransactionType(type) {
1666
+ const types = {
1667
+ 'deposit': 'deposit',
1668
+ 'withdrawal': 'withdrawal',
1669
+ };
1670
+ return this.safeString(types, type, type);
1671
+ }
1672
+ async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
1673
+ /**
1674
+ * @method
1675
+ * @name currencycom#fetchLedger
1676
+ * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
1677
+ * @param {string} code unified currency code, default is undefined
1678
+ * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
1679
+ * @param {int} [limit] max number of ledger entrys to return, default is undefined
1680
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1681
+ * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
1682
+ */
1683
+ await this.loadMarkets();
1684
+ const request = {};
1685
+ let currency = undefined;
1686
+ if (code !== undefined) {
1687
+ currency = this.currency(code);
1688
+ }
1689
+ if (since !== undefined) {
1690
+ request['startTime'] = since;
1691
+ }
1692
+ if (limit !== undefined) {
1693
+ request['limit'] = limit;
1694
+ }
1695
+ const response = await this.privateGetV2Ledger(this.extend(request, params));
1696
+ // in the below example, first item expresses withdrawal/deposit type, second example expresses trade
1697
+ //
1698
+ // [
1699
+ // {
1700
+ // "id": "619031398",
1701
+ // "balance": "0.0",
1702
+ // "amount": "-1.088",
1703
+ // "currency": "CAKE",
1704
+ // "type": "withdrawal",
1705
+ // "timestamp": "1645460496425",
1706
+ // "commission": "0.13",
1707
+ // "paymentMethod": "BLOCKCHAIN", // present in withdrawal/deposit
1708
+ // "blockchainTransactionHash": "0x400ac905557c3d34638b1c60eba110b3ee0f97f4eb0f7318015ab76e7f16b7d6", // present in withdrawal/deposit
1709
+ // "status": "PROCESSED"
1710
+ // },
1711
+ // {
1712
+ // "id": "619031034",
1713
+ // "balance": "8.17223588",
1714
+ // "amount": "-0.01326294",
1715
+ // "currency": "USD",
1716
+ // "type": "exchange_commission",
1717
+ // "timestamp": "1645460461235",
1718
+ // "commission": "0.01326294",
1719
+ // "status": "PROCESSED"
1720
+ // },
1721
+ // ]
1722
+ //
1723
+ return this.parseLedger(response, currency, since, limit);
1724
+ }
1725
+ parseLedgerEntry(item, currency = undefined) {
1726
+ const id = this.safeString(item, 'id');
1727
+ const amountString = this.safeString(item, 'amount');
1728
+ const amount = Precise["default"].stringAbs(amountString);
1729
+ const timestamp = this.safeInteger(item, 'timestamp');
1730
+ const currencyId = this.safeString(item, 'currency');
1731
+ const code = this.safeCurrencyCode(currencyId, currency);
1732
+ const feeCost = this.safeString(item, 'commission');
1733
+ let fee = undefined;
1734
+ if (feeCost !== undefined) {
1735
+ fee = { 'currency': code, 'cost': feeCost };
1736
+ }
1737
+ const direction = Precise["default"].stringLt(amountString, '0') ? 'out' : 'in';
1738
+ const result = {
1739
+ 'id': id,
1740
+ 'timestamp': timestamp,
1741
+ 'datetime': this.iso8601(timestamp),
1742
+ 'direction': direction,
1743
+ 'account': undefined,
1744
+ 'referenceId': this.safeString(item, 'blockchainTransactionHash'),
1745
+ 'referenceAccount': undefined,
1746
+ 'type': this.parseLedgerEntryType(this.safeString(item, 'type')),
1747
+ 'currency': code,
1748
+ 'amount': amount,
1749
+ 'before': undefined,
1750
+ 'after': this.safeString(item, 'balance'),
1751
+ 'status': this.parseLedgerEntryStatus(this.safeString(item, 'status')),
1752
+ 'fee': fee,
1753
+ 'info': item,
1754
+ };
1755
+ return result;
1756
+ }
1757
+ parseLedgerEntryStatus(status) {
1758
+ const statuses = {
1759
+ 'APPROVAL': 'pending',
1760
+ 'PROCESSED': 'ok',
1761
+ 'CANCELLED': 'canceled',
1762
+ };
1763
+ return this.safeString(statuses, status, status);
1764
+ }
1765
+ parseLedgerEntryType(type) {
1766
+ const types = {
1767
+ 'deposit': 'transaction',
1768
+ 'withdrawal': 'transaction',
1769
+ 'exchange_commission': 'fee',
1770
+ };
1771
+ return this.safeString(types, type, type);
1772
+ }
1773
+ async fetchLeverage(symbol, params = {}) {
1774
+ /**
1775
+ * @method
1776
+ * @name currencycom#fetchLeverage
1777
+ * @description fetch the set leverage for a market
1778
+ * @param {string} symbol unified market symbol
1779
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1780
+ * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
1781
+ */
1782
+ await this.loadMarkets();
1783
+ const market = this.market(symbol);
1784
+ const request = {
1785
+ 'symbol': market['id'],
1786
+ };
1787
+ const response = await this.privateGetV2LeverageSettings(this.extend(request, params));
1788
+ //
1789
+ // {
1790
+ // "values": [ 1, 2, 5, 10, ],
1791
+ // "value": "10",
1792
+ // }
1793
+ //
1794
+ return this.safeNumber(response, 'value');
1795
+ }
1796
+ async fetchDepositAddress(code, params = {}) {
1797
+ /**
1798
+ * @method
1799
+ * @name currencycom#fetchDepositAddress
1800
+ * @description fetch the deposit address for a currency associated with this account
1801
+ * @param {string} code unified currency code
1802
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1803
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1804
+ */
1805
+ await this.loadMarkets();
1806
+ const currency = this.currency(code);
1807
+ const request = {
1808
+ 'coin': currency['id'],
1809
+ };
1810
+ const response = await this.privateGetV2DepositAddress(this.extend(request, params));
1811
+ //
1812
+ // { "address":"0x97d64eb014ac779194991e7264f01c74c90327f0" }
1813
+ //
1814
+ return this.parseDepositAddress(response, currency);
1815
+ }
1816
+ parseDepositAddress(depositAddress, currency = undefined) {
1817
+ const address = this.safeString(depositAddress, 'address');
1818
+ this.checkAddress(address);
1819
+ currency = this.safeCurrency(undefined, currency);
1820
+ return {
1821
+ 'currency': currency['code'],
1822
+ 'address': address,
1823
+ 'tag': undefined,
1824
+ 'network': undefined,
1825
+ 'info': depositAddress,
1826
+ };
1827
+ }
1828
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1829
+ let url = this.urls['api'][api] + '/' + path;
1830
+ if (path === 'historicalTrades') {
1831
+ headers = {
1832
+ 'X-MBX-APIKEY': this.apiKey,
1833
+ };
1834
+ }
1835
+ if (api === 'private') {
1836
+ this.checkRequiredCredentials();
1837
+ let query = this.urlencode(this.extend({
1838
+ 'timestamp': this.nonce(),
1839
+ 'recvWindow': this.options['recvWindow'],
1840
+ }, params));
1841
+ const signature = this.hmac(this.encode(query), this.encode(this.secret), sha256.sha256);
1842
+ query += '&' + 'signature=' + signature;
1843
+ headers = {
1844
+ 'X-MBX-APIKEY': this.apiKey,
1845
+ };
1846
+ if ((method === 'GET') || (method === 'DELETE')) {
1847
+ url += '?' + query;
1848
+ }
1849
+ else {
1850
+ body = query;
1851
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
1852
+ }
1853
+ }
1854
+ else {
1855
+ if (Object.keys(params).length) {
1856
+ url += '?' + this.urlencode(params);
1857
+ }
1858
+ }
1859
+ url = this.implodeHostname(url);
1860
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1861
+ }
1862
+ async fetchPositions(symbols = undefined, params = {}) {
1863
+ /**
1864
+ * @method
1865
+ * @name currencycom#fetchPositions
1866
+ * @description fetch all open positions
1867
+ * @param {string[]|undefined} symbols list of unified market symbols
1868
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1869
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
1870
+ */
1871
+ await this.loadMarkets();
1872
+ const response = await this.privateGetV2TradingPositions(params);
1873
+ //
1874
+ // {
1875
+ // "positions": [
1876
+ // {
1877
+ // "accountId": "109698017416453793",
1878
+ // "id": "00a18490-0079-54c4-0000-0000803e73d3",
1879
+ // "instrumentId": "45463225268524228",
1880
+ // "orderId": "00a18490-0079-54c4-0000-0000803e73d2",
1881
+ // "openQuantity": "13.6",
1882
+ // "openPrice": "0.75724",
1883
+ // "closeQuantity": "0.0",
1884
+ // "closePrice": "0",
1885
+ // "rpl": "-0.007723848",
1886
+ // "rplConverted": "0",
1887
+ // "upl": "-0.006664",
1888
+ // "uplConverted": "-0.006664",
1889
+ // "swap": "0",
1890
+ // "swapConverted": "0",
1891
+ // "fee": "-0.007723848",
1892
+ // "dividend": "0",
1893
+ // "margin": "0.2",
1894
+ // "state": "ACTIVE",
1895
+ // "currency": "USD",
1896
+ // "createdTimestamp": "1645473877236",
1897
+ // "openTimestamp": "1645473877193",
1898
+ // "type": "NET",
1899
+ // "cost": "2.0583600",
1900
+ // "symbol": "XRP/USD_LEVERAGE"
1901
+ // }
1902
+ // ]
1903
+ // }
1904
+ //
1905
+ const data = this.safeValue(response, 'positions', []);
1906
+ return this.parsePositions(data, symbols);
1907
+ }
1908
+ parsePosition(position, market = undefined) {
1909
+ //
1910
+ // {
1911
+ // "accountId": "109698017416453793",
1912
+ // "id": "00a18490-0079-54c4-0000-0000803e73d3",
1913
+ // "instrumentId": "45463225268524228",
1914
+ // "orderId": "00a18490-0079-54c4-0000-0000803e73d2",
1915
+ // "openQuantity": "13.6",
1916
+ // "openPrice": "0.75724",
1917
+ // "closeQuantity": "0.0",
1918
+ // "closePrice": "0",
1919
+ // "rpl": "-0.007723848",
1920
+ // "rplConverted": "0",
1921
+ // "upl": "-0.006664",
1922
+ // "uplConverted": "-0.006664",
1923
+ // "swap": "0",
1924
+ // "swapConverted": "0",
1925
+ // "fee": "-0.007723848",
1926
+ // "dividend": "0",
1927
+ // "margin": "0.2",
1928
+ // "state": "ACTIVE",
1929
+ // "currency": "USD",
1930
+ // "createdTimestamp": "1645473877236",
1931
+ // "openTimestamp": "1645473877193",
1932
+ // "type": "NET",
1933
+ // "cost": "2.0583600",
1934
+ // "symbol": "XRP/USD_LEVERAGE"
1935
+ // }
1936
+ //
1937
+ market = this.safeMarket(this.safeString(position, 'symbol'), market);
1938
+ const symbol = market['symbol'];
1939
+ const timestamp = this.safeNumber(position, 'createdTimestamp');
1940
+ const quantityRaw = this.safeString(position, 'openQuantity');
1941
+ const side = Precise["default"].stringGt(quantityRaw, '0') ? 'long' : 'short';
1942
+ const quantity = Precise["default"].stringAbs(quantityRaw);
1943
+ const entryPrice = this.safeNumber(position, 'openPrice');
1944
+ const unrealizedProfit = this.safeNumber(position, 'upl');
1945
+ const marginCoeff = this.safeString(position, 'margin');
1946
+ const leverage = Precise["default"].stringDiv('1', marginCoeff);
1947
+ return this.safePosition({
1948
+ 'info': position,
1949
+ 'symbol': symbol,
1950
+ 'timestamp': timestamp,
1951
+ 'datetime': this.iso8601(timestamp),
1952
+ 'lastUpdateTimestamp': undefined,
1953
+ 'contracts': this.parseNumber(quantity),
1954
+ 'contractSize': undefined,
1955
+ 'entryPrice': entryPrice,
1956
+ 'collateral': undefined,
1957
+ 'side': side,
1958
+ // 'realizedProfit': this.safeNumber (position, 'rpl'),
1959
+ 'unrealizedProfit': unrealizedProfit,
1960
+ 'leverage': leverage,
1961
+ 'percentage': undefined,
1962
+ 'marginMode': undefined,
1963
+ 'notional': undefined,
1964
+ 'markPrice': undefined,
1965
+ 'lastPrice': undefined,
1966
+ 'liquidationPrice': undefined,
1967
+ 'initialMargin': undefined,
1968
+ 'initialMarginPercentage': undefined,
1969
+ 'maintenanceMargin': this.parseNumber(marginCoeff),
1970
+ 'maintenanceMarginPercentage': undefined,
1971
+ 'marginRatio': undefined,
1972
+ 'id': undefined,
1973
+ 'unrealizedPnl': undefined,
1974
+ 'hedged': undefined,
1975
+ 'stopLossPrice': undefined,
1976
+ 'takeProfitPrice': undefined,
1977
+ });
1978
+ }
1979
+ handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1980
+ if ((httpCode === 418) || (httpCode === 429)) {
1981
+ throw new errors.DDoSProtection(this.id + ' ' + httpCode.toString() + ' ' + reason + ' ' + body);
1982
+ }
1983
+ // error response in a form: { "code": -1013, "msg": "Invalid quantity." }
1984
+ // following block cointains legacy checks against message patterns in "msg" property
1985
+ // will switch "code" checks eventually, when we know all of them
1986
+ if (httpCode >= 400) {
1987
+ if (body.indexOf('Price * QTY is zero or less') >= 0) {
1988
+ throw new errors.InvalidOrder(this.id + ' order cost = amount * price is zero or less ' + body);
1989
+ }
1990
+ if (body.indexOf('LOT_SIZE') >= 0) {
1991
+ throw new errors.InvalidOrder(this.id + ' order amount should be evenly divisible by lot size ' + body);
1992
+ }
1993
+ if (body.indexOf('PRICE_FILTER') >= 0) {
1994
+ throw new errors.InvalidOrder(this.id + ' order price is invalid, i.e. exceeds allowed price precision, exceeds min price or max price limits or is invalid float value in general, use this.priceToPrecision (symbol, amount) ' + body);
1995
+ }
1996
+ }
1997
+ if (response === undefined) {
1998
+ return undefined; // fallback to default error handler
1999
+ }
2000
+ //
2001
+ // {"code":-1128,"msg":"Combination of optional parameters invalid."}
2002
+ //
2003
+ const errorCode = this.safeString(response, 'code');
2004
+ if ((errorCode !== undefined) && (errorCode !== '0')) {
2005
+ const feedback = this.id + ' ' + this.json(response);
2006
+ this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
2007
+ const message = this.safeString(response, 'msg');
2008
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
2009
+ throw new errors.ExchangeError(feedback);
2010
+ }
2011
+ return undefined;
2012
+ }
2013
+ }
2014
+
2015
+ module.exports = currencycom;