ccxt 4.2.10 → 4.2.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (383) hide show
  1. package/README.md +5 -5
  2. package/build.sh +4 -4
  3. package/dist/ccxt.browser.js +695 -282
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/_virtual/agent.js +7 -0
  6. package/dist/cjs/_virtual/parse-proxy-response.js +7 -0
  7. package/dist/cjs/_virtual/promisify.js +7 -0
  8. package/dist/cjs/ccxt.js +1 -1
  9. package/dist/cjs/js/ccxt.js +474 -0
  10. package/dist/cjs/js/src/abstract/ace.js +9 -0
  11. package/dist/cjs/js/src/abstract/alpaca.js +9 -0
  12. package/dist/cjs/js/src/abstract/ascendex.js +9 -0
  13. package/dist/cjs/js/src/abstract/bigone.js +9 -0
  14. package/dist/cjs/js/src/abstract/binance.js +9 -0
  15. package/dist/cjs/js/src/abstract/bingx.js +9 -0
  16. package/dist/cjs/js/src/abstract/bit2c.js +9 -0
  17. package/dist/cjs/js/src/abstract/bitbank.js +9 -0
  18. package/dist/cjs/js/src/abstract/bitbns.js +9 -0
  19. package/dist/cjs/js/src/abstract/bitfinex.js +9 -0
  20. package/dist/cjs/js/src/abstract/bitfinex2.js +9 -0
  21. package/dist/cjs/js/src/abstract/bitflyer.js +9 -0
  22. package/dist/cjs/js/src/abstract/bitforex.js +9 -0
  23. package/dist/cjs/js/src/abstract/bitget.js +9 -0
  24. package/dist/cjs/js/src/abstract/bithumb.js +9 -0
  25. package/dist/cjs/js/src/abstract/bitmart.js +9 -0
  26. package/dist/cjs/js/src/abstract/bitmex.js +9 -0
  27. package/dist/cjs/js/src/abstract/bitopro.js +9 -0
  28. package/dist/cjs/js/src/abstract/bitpanda.js +9 -0
  29. package/dist/cjs/js/src/abstract/bitrue.js +9 -0
  30. package/dist/cjs/js/src/abstract/bitso.js +9 -0
  31. package/dist/cjs/js/src/abstract/bitstamp.js +9 -0
  32. package/dist/cjs/js/src/abstract/bitteam.js +9 -0
  33. package/dist/cjs/js/src/abstract/bitvavo.js +9 -0
  34. package/dist/cjs/js/src/abstract/bl3p.js +9 -0
  35. package/dist/cjs/js/src/abstract/blockchaincom.js +9 -0
  36. package/dist/cjs/js/src/abstract/btcalpha.js +9 -0
  37. package/dist/cjs/js/src/abstract/btcbox.js +9 -0
  38. package/dist/cjs/js/src/abstract/btcmarkets.js +9 -0
  39. package/dist/cjs/js/src/abstract/btcturk.js +9 -0
  40. package/dist/cjs/js/src/abstract/bybit.js +9 -0
  41. package/dist/cjs/js/src/abstract/cex.js +9 -0
  42. package/dist/cjs/js/src/abstract/coinbase.js +9 -0
  43. package/dist/cjs/js/src/abstract/coinbasepro.js +9 -0
  44. package/dist/cjs/js/src/abstract/coincheck.js +9 -0
  45. package/dist/cjs/js/src/abstract/coinex.js +9 -0
  46. package/dist/cjs/js/src/abstract/coinlist.js +9 -0
  47. package/dist/cjs/js/src/abstract/coinmate.js +9 -0
  48. package/dist/cjs/js/src/abstract/coinone.js +9 -0
  49. package/dist/cjs/js/src/abstract/coinsph.js +9 -0
  50. package/dist/cjs/js/src/abstract/coinspot.js +9 -0
  51. package/dist/cjs/js/src/abstract/cryptocom.js +9 -0
  52. package/dist/cjs/js/src/abstract/currencycom.js +9 -0
  53. package/dist/cjs/js/src/abstract/delta.js +9 -0
  54. package/dist/cjs/js/src/abstract/deribit.js +9 -0
  55. package/dist/cjs/js/src/abstract/digifinex.js +9 -0
  56. package/dist/cjs/js/src/abstract/exmo.js +9 -0
  57. package/dist/cjs/js/src/abstract/gate.js +9 -0
  58. package/dist/cjs/js/src/abstract/gemini.js +9 -0
  59. package/dist/cjs/js/src/abstract/hitbtc.js +9 -0
  60. package/dist/cjs/js/src/abstract/hollaex.js +9 -0
  61. package/dist/cjs/js/src/abstract/htx.js +9 -0
  62. package/dist/cjs/js/src/abstract/huobijp.js +9 -0
  63. package/dist/cjs/js/src/abstract/idex.js +9 -0
  64. package/dist/cjs/js/src/abstract/independentreserve.js +9 -0
  65. package/dist/cjs/js/src/abstract/indodax.js +9 -0
  66. package/dist/cjs/js/src/abstract/kraken.js +9 -0
  67. package/dist/cjs/js/src/abstract/krakenfutures.js +9 -0
  68. package/dist/cjs/js/src/abstract/kucoin.js +9 -0
  69. package/dist/cjs/js/src/abstract/kucoinfutures.js +9 -0
  70. package/dist/cjs/js/src/abstract/kuna.js +9 -0
  71. package/dist/cjs/js/src/abstract/latoken.js +9 -0
  72. package/dist/cjs/js/src/abstract/lbank.js +9 -0
  73. package/dist/cjs/js/src/abstract/luno.js +9 -0
  74. package/dist/cjs/js/src/abstract/lykke.js +9 -0
  75. package/dist/cjs/js/src/abstract/mercado.js +9 -0
  76. package/dist/cjs/js/src/abstract/mexc.js +9 -0
  77. package/dist/cjs/js/src/abstract/ndax.js +9 -0
  78. package/dist/cjs/js/src/abstract/novadax.js +9 -0
  79. package/dist/cjs/js/src/abstract/oceanex.js +9 -0
  80. package/dist/cjs/js/src/abstract/okcoin.js +9 -0
  81. package/dist/cjs/js/src/abstract/okx.js +9 -0
  82. package/dist/cjs/js/src/abstract/p2b.js +9 -0
  83. package/dist/cjs/js/src/abstract/paymium.js +9 -0
  84. package/dist/cjs/js/src/abstract/phemex.js +9 -0
  85. package/dist/cjs/js/src/abstract/poloniex.js +9 -0
  86. package/dist/cjs/js/src/abstract/poloniexfutures.js +9 -0
  87. package/dist/cjs/js/src/abstract/probit.js +9 -0
  88. package/dist/cjs/js/src/abstract/timex.js +9 -0
  89. package/dist/cjs/js/src/abstract/tokocrypto.js +9 -0
  90. package/dist/cjs/js/src/abstract/upbit.js +9 -0
  91. package/dist/cjs/js/src/abstract/wavesexchange.js +9 -0
  92. package/dist/cjs/js/src/abstract/wazirx.js +9 -0
  93. package/dist/cjs/js/src/abstract/whitebit.js +9 -0
  94. package/dist/cjs/js/src/abstract/woo.js +9 -0
  95. package/dist/cjs/js/src/abstract/yobit.js +9 -0
  96. package/dist/cjs/js/src/abstract/zaif.js +9 -0
  97. package/dist/cjs/js/src/abstract/zonda.js +9 -0
  98. package/dist/cjs/js/src/ace.js +1058 -0
  99. package/dist/cjs/js/src/alpaca.js +1125 -0
  100. package/dist/cjs/js/src/ascendex.js +3360 -0
  101. package/dist/cjs/js/src/base/Exchange.js +5110 -0
  102. package/dist/cjs/js/src/base/Precise.js +263 -0
  103. package/dist/cjs/js/src/base/errors.js +299 -0
  104. package/dist/cjs/js/src/base/functions/crypto.js +78 -0
  105. package/dist/cjs/js/src/base/functions/encode.js +44 -0
  106. package/dist/cjs/js/src/base/functions/generic.js +193 -0
  107. package/dist/cjs/js/src/base/functions/misc.js +96 -0
  108. package/dist/cjs/js/src/base/functions/number.js +297 -0
  109. package/dist/cjs/js/src/base/functions/platform.js +28 -0
  110. package/dist/cjs/js/src/base/functions/rsa.js +34 -0
  111. package/dist/cjs/js/src/base/functions/string.js +48 -0
  112. package/dist/cjs/js/src/base/functions/throttle.js +66 -0
  113. package/dist/cjs/js/src/base/functions/time.js +187 -0
  114. package/dist/cjs/js/src/base/functions/totp.js +24 -0
  115. package/dist/cjs/js/src/base/functions/type.js +162 -0
  116. package/dist/cjs/js/src/base/functions.js +157 -0
  117. package/dist/cjs/js/src/base/ws/Cache.js +254 -0
  118. package/dist/cjs/js/src/base/ws/Client.js +299 -0
  119. package/dist/cjs/js/src/base/ws/Future.js +34 -0
  120. package/dist/cjs/js/src/base/ws/OrderBook.js +107 -0
  121. package/dist/cjs/js/src/base/ws/OrderBookSide.js +281 -0
  122. package/dist/cjs/js/src/base/ws/WsClient.js +69 -0
  123. package/dist/cjs/js/src/bequant.js +33 -0
  124. package/dist/cjs/js/src/bigone.js +2142 -0
  125. package/dist/cjs/js/src/binance.js +9729 -0
  126. package/dist/cjs/js/src/binancecoinm.js +45 -0
  127. package/dist/cjs/js/src/binanceus.js +84 -0
  128. package/dist/cjs/js/src/binanceusdm.js +58 -0
  129. package/dist/cjs/js/src/bingx.js +3737 -0
  130. package/dist/cjs/js/src/bit2c.js +916 -0
  131. package/dist/cjs/js/src/bitbank.js +1000 -0
  132. package/dist/cjs/js/src/bitbay.js +17 -0
  133. package/dist/cjs/js/src/bitbns.js +1220 -0
  134. package/dist/cjs/js/src/bitcoincom.js +17 -0
  135. package/dist/cjs/js/src/bitfinex.js +1670 -0
  136. package/dist/cjs/js/src/bitfinex2.js +2990 -0
  137. package/dist/cjs/js/src/bitflyer.js +1045 -0
  138. package/dist/cjs/js/src/bitforex.js +852 -0
  139. package/dist/cjs/js/src/bitget.js +8284 -0
  140. package/dist/cjs/js/src/bithumb.js +1090 -0
  141. package/dist/cjs/js/src/bitmart.js +4454 -0
  142. package/dist/cjs/js/src/bitmex.js +2884 -0
  143. package/dist/cjs/js/src/bitopro.js +1724 -0
  144. package/dist/cjs/js/src/bitpanda.js +2002 -0
  145. package/dist/cjs/js/src/bitrue.js +3253 -0
  146. package/dist/cjs/js/src/bitso.js +1753 -0
  147. package/dist/cjs/js/src/bitstamp.js +2188 -0
  148. package/dist/cjs/js/src/bitteam.js +2309 -0
  149. package/dist/cjs/js/src/bitvavo.js +1968 -0
  150. package/dist/cjs/js/src/bl3p.js +447 -0
  151. package/dist/cjs/js/src/blockchaincom.js +1160 -0
  152. package/dist/cjs/js/src/btcalpha.js +929 -0
  153. package/dist/cjs/js/src/btcbox.js +565 -0
  154. package/dist/cjs/js/src/btcmarkets.js +1237 -0
  155. package/dist/cjs/js/src/btcturk.js +929 -0
  156. package/dist/cjs/js/src/bybit.js +7646 -0
  157. package/dist/cjs/js/src/cex.js +1693 -0
  158. package/dist/cjs/js/src/coinbase.js +3274 -0
  159. package/dist/cjs/js/src/coinbasepro.js +1866 -0
  160. package/dist/cjs/js/src/coincheck.js +843 -0
  161. package/dist/cjs/js/src/coinex.js +5414 -0
  162. package/dist/cjs/js/src/coinlist.js +2329 -0
  163. package/dist/cjs/js/src/coinmate.js +989 -0
  164. package/dist/cjs/js/src/coinone.js +1185 -0
  165. package/dist/cjs/js/src/coinsph.js +1933 -0
  166. package/dist/cjs/js/src/coinspot.js +548 -0
  167. package/dist/cjs/js/src/cryptocom.js +3007 -0
  168. package/dist/cjs/js/src/currencycom.js +2015 -0
  169. package/dist/cjs/js/src/delta.js +3256 -0
  170. package/dist/cjs/js/src/deribit.js +3306 -0
  171. package/dist/cjs/js/src/digifinex.js +4307 -0
  172. package/dist/cjs/js/src/exmo.js +2645 -0
  173. package/dist/cjs/js/src/fmfwio.js +34 -0
  174. package/dist/cjs/js/src/gate.js +7054 -0
  175. package/dist/cjs/js/src/gateio.js +16 -0
  176. package/dist/cjs/js/src/gemini.js +1801 -0
  177. package/dist/cjs/js/src/hitbtc.js +3660 -0
  178. package/dist/cjs/js/src/hitbtc3.js +19 -0
  179. package/dist/cjs/js/src/hollaex.js +1882 -0
  180. package/dist/cjs/js/src/htx.js +9024 -0
  181. package/dist/cjs/js/src/huobi.js +16 -0
  182. package/dist/cjs/js/src/huobijp.js +1918 -0
  183. package/dist/cjs/js/src/idex.js +1770 -0
  184. package/dist/cjs/js/src/independentreserve.js +759 -0
  185. package/dist/cjs/js/src/indodax.js +1069 -0
  186. package/dist/cjs/js/src/kraken.js +2861 -0
  187. package/dist/cjs/js/src/krakenfutures.js +2407 -0
  188. package/dist/cjs/js/src/kucoin.js +4489 -0
  189. package/dist/cjs/js/src/kucoinfutures.js +2475 -0
  190. package/dist/cjs/js/src/kuna.js +1949 -0
  191. package/dist/cjs/js/src/latoken.js +1729 -0
  192. package/dist/cjs/js/src/lbank.js +2825 -0
  193. package/dist/cjs/js/src/luno.js +1044 -0
  194. package/dist/cjs/js/src/lykke.js +1303 -0
  195. package/dist/cjs/js/src/mercado.js +897 -0
  196. package/dist/cjs/js/src/mexc.js +5407 -0
  197. package/dist/cjs/js/src/ndax.js +2450 -0
  198. package/dist/cjs/js/src/novadax.js +1556 -0
  199. package/dist/cjs/js/src/oceanex.js +964 -0
  200. package/dist/cjs/js/src/okcoin.js +3115 -0
  201. package/dist/cjs/js/src/okx.js +7329 -0
  202. package/dist/cjs/js/src/p2b.js +1243 -0
  203. package/dist/cjs/js/src/paymium.js +597 -0
  204. package/dist/cjs/js/src/phemex.js +4715 -0
  205. package/dist/cjs/js/src/poloniex.js +2356 -0
  206. package/dist/cjs/js/src/poloniexfutures.js +1794 -0
  207. package/dist/cjs/js/src/pro/alpaca.js +714 -0
  208. package/dist/cjs/js/src/pro/ascendex.js +957 -0
  209. package/dist/cjs/js/src/pro/bequant.js +33 -0
  210. package/dist/cjs/js/src/pro/binance.js +2796 -0
  211. package/dist/cjs/js/src/pro/binancecoinm.js +23 -0
  212. package/dist/cjs/js/src/pro/binanceus.js +51 -0
  213. package/dist/cjs/js/src/pro/binanceusdm.js +32 -0
  214. package/dist/cjs/js/src/pro/bingx.js +944 -0
  215. package/dist/cjs/js/src/pro/bitcoincom.js +29 -0
  216. package/dist/cjs/js/src/pro/bitfinex.js +672 -0
  217. package/dist/cjs/js/src/pro/bitfinex2.js +1159 -0
  218. package/dist/cjs/js/src/pro/bitget.js +1733 -0
  219. package/dist/cjs/js/src/pro/bitmart.js +1486 -0
  220. package/dist/cjs/js/src/pro/bitmex.js +1576 -0
  221. package/dist/cjs/js/src/pro/bitopro.js +327 -0
  222. package/dist/cjs/js/src/pro/bitpanda.js +1341 -0
  223. package/dist/cjs/js/src/pro/bitrue.js +462 -0
  224. package/dist/cjs/js/src/pro/bitstamp.js +547 -0
  225. package/dist/cjs/js/src/pro/bitvavo.js +704 -0
  226. package/dist/cjs/js/src/pro/blockchaincom.js +794 -0
  227. package/dist/cjs/js/src/pro/bybit.js +1843 -0
  228. package/dist/cjs/js/src/pro/cex.js +1510 -0
  229. package/dist/cjs/js/src/pro/coinbase.js +561 -0
  230. package/dist/cjs/js/src/pro/coinbasepro.js +968 -0
  231. package/dist/cjs/js/src/pro/coinex.js +1095 -0
  232. package/dist/cjs/js/src/pro/cryptocom.js +1020 -0
  233. package/dist/cjs/js/src/pro/currencycom.js +563 -0
  234. package/dist/cjs/js/src/pro/deribit.js +825 -0
  235. package/dist/cjs/js/src/pro/exmo.js +658 -0
  236. package/dist/cjs/js/src/pro/gate.js +1316 -0
  237. package/dist/cjs/js/src/pro/gateio.js +16 -0
  238. package/dist/cjs/js/src/pro/gemini.js +649 -0
  239. package/dist/cjs/js/src/pro/hitbtc.js +1293 -0
  240. package/dist/cjs/js/src/pro/hollaex.js +597 -0
  241. package/dist/cjs/js/src/pro/htx.js +2383 -0
  242. package/dist/cjs/js/src/pro/huobi.js +16 -0
  243. package/dist/cjs/js/src/pro/huobijp.js +606 -0
  244. package/dist/cjs/js/src/pro/idex.js +714 -0
  245. package/dist/cjs/js/src/pro/independentreserve.js +280 -0
  246. package/dist/cjs/js/src/pro/kraken.js +1364 -0
  247. package/dist/cjs/js/src/pro/krakenfutures.js +1500 -0
  248. package/dist/cjs/js/src/pro/kucoin.js +1052 -0
  249. package/dist/cjs/js/src/pro/kucoinfutures.js +981 -0
  250. package/dist/cjs/js/src/pro/luno.js +322 -0
  251. package/dist/cjs/js/src/pro/mexc.js +1170 -0
  252. package/dist/cjs/js/src/pro/ndax.js +545 -0
  253. package/dist/cjs/js/src/pro/okcoin.js +760 -0
  254. package/dist/cjs/js/src/pro/okx.js +1558 -0
  255. package/dist/cjs/js/src/pro/phemex.js +1511 -0
  256. package/dist/cjs/js/src/pro/poloniex.js +1253 -0
  257. package/dist/cjs/js/src/pro/poloniexfutures.js +1014 -0
  258. package/dist/cjs/js/src/pro/probit.js +586 -0
  259. package/dist/cjs/js/src/pro/upbit.js +234 -0
  260. package/dist/cjs/js/src/pro/wazirx.js +776 -0
  261. package/dist/cjs/js/src/pro/whitebit.js +927 -0
  262. package/dist/cjs/js/src/pro/woo.js +769 -0
  263. package/dist/cjs/js/src/probit.js +1865 -0
  264. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +401 -0
  265. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +195 -0
  266. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +308 -0
  267. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +554 -0
  268. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +94 -0
  269. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +70 -0
  270. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +91 -0
  271. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +16 -0
  272. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +1760 -0
  273. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +52 -0
  274. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +81 -0
  275. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +376 -0
  276. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +70 -0
  277. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +1580 -0
  278. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +74 -0
  279. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +24 -0
  280. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +158 -0
  281. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +429 -0
  282. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +176 -0
  283. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +324 -0
  284. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +163 -0
  285. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +245 -0
  286. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1018 -0
  287. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +383 -0
  288. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +258 -0
  289. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +53 -0
  290. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +120 -0
  291. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +69 -0
  292. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +7 -0
  293. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +83 -0
  294. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +240 -0
  295. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +91 -0
  296. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +130 -0
  297. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +214 -0
  298. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +239 -0
  299. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +93 -0
  300. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +354 -0
  301. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +16 -0
  302. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +20 -0
  303. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +30 -0
  304. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +239 -0
  305. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +372 -0
  306. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +273 -0
  307. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +139 -0
  308. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +14 -0
  309. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +16 -0
  310. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +81 -0
  311. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +292 -0
  312. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +103 -0
  313. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +140 -0
  314. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +175 -0
  315. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +95 -0
  316. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +7 -0
  317. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +383 -0
  318. package/dist/cjs/js/src/timex.js +1562 -0
  319. package/dist/cjs/js/src/tokocrypto.js +2542 -0
  320. package/dist/cjs/js/src/upbit.js +1844 -0
  321. package/dist/cjs/js/src/wavesexchange.js +2607 -0
  322. package/dist/cjs/js/src/wazirx.js +953 -0
  323. package/dist/cjs/js/src/whitebit.js +2309 -0
  324. package/dist/cjs/js/src/woo.js +2715 -0
  325. package/dist/cjs/js/src/yobit.js +1314 -0
  326. package/dist/cjs/js/src/zaif.js +736 -0
  327. package/dist/cjs/js/src/zonda.js +1883 -0
  328. package/dist/cjs/src/base/Exchange.js +11 -0
  329. package/dist/cjs/src/bingx.js +0 -10
  330. package/dist/cjs/src/bitget.js +14 -5
  331. package/dist/cjs/src/bybit.js +1 -1
  332. package/dist/cjs/src/kucoin.js +29 -5
  333. package/js/ccxt.d.ts +1 -1
  334. package/js/ccxt.js +1 -1
  335. package/js/src/abstract/bigone.d.ts +18 -0
  336. package/js/src/abstract/binance.d.ts +2 -0
  337. package/js/src/abstract/binancecoinm.d.ts +2 -0
  338. package/js/src/abstract/binanceus.d.ts +2 -0
  339. package/js/src/abstract/binanceusdm.d.ts +2 -0
  340. package/js/src/abstract/bybit.d.ts +1 -0
  341. package/js/src/abstract/gate.d.ts +11 -0
  342. package/js/src/abstract/gateio.d.ts +11 -0
  343. package/js/src/alpaca.js +18 -18
  344. package/js/src/base/Exchange.d.ts +6 -1
  345. package/js/src/base/Exchange.js +112 -12
  346. package/js/src/bigone.d.ts +1 -2
  347. package/js/src/bigone.js +340 -145
  348. package/js/src/binance.js +15 -8
  349. package/js/src/bingx.d.ts +0 -1
  350. package/js/src/bingx.js +9 -12
  351. package/js/src/bitfinex.d.ts +2 -2
  352. package/js/src/bitfinex.js +2 -3
  353. package/js/src/bitget.js +35 -13
  354. package/js/src/bitmart.d.ts +2 -2
  355. package/js/src/bitmart.js +3 -3
  356. package/js/src/bitmex.js +1 -0
  357. package/js/src/bybit.js +3 -1
  358. package/js/src/coinlist.js +2 -3
  359. package/js/src/coinsph.js +2 -3
  360. package/js/src/deribit.js +1 -0
  361. package/js/src/gate.d.ts +4 -4
  362. package/js/src/gate.js +22 -3
  363. package/js/src/hitbtc.d.ts +4 -4
  364. package/js/src/hitbtc.js +2 -3
  365. package/js/src/htx.js +4 -7
  366. package/js/src/huobijp.js +2 -3
  367. package/js/src/kraken.js +1 -0
  368. package/js/src/kucoin.js +29 -5
  369. package/js/src/mexc.js +2 -1
  370. package/js/src/okx.js +13 -3
  371. package/js/src/pro/binance.d.ts +2 -23
  372. package/js/src/pro/binance.js +58 -22
  373. package/js/src/pro/coinbase.d.ts +2 -2
  374. package/js/src/pro/coinbase.js +4 -1
  375. package/js/src/pro/coinbasepro.d.ts +2 -2
  376. package/js/src/pro/hitbtc.d.ts +2 -2
  377. package/js/src/pro/poloniex.d.ts +2 -2
  378. package/js/src/upbit.d.ts +3 -101
  379. package/js/src/upbit.js +12 -12
  380. package/js/src/woo.js +2 -0
  381. package/package.json +11 -11
  382. package/skip-tests.json +5 -0
  383. package/tests-manager.sh +2 -2
@@ -0,0 +1,3360 @@
1
+ 'use strict';
2
+
3
+ var ascendex$1 = require('./abstract/ascendex.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 ascendex
13
+ * @augments Exchange
14
+ */
15
+ class ascendex extends ascendex$1 {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'ascendex',
19
+ 'name': 'AscendEX',
20
+ 'countries': ['SG'],
21
+ // 8 requests per minute = 0.13333 per second => rateLimit = 750
22
+ // testing 400 works
23
+ 'rateLimit': 400,
24
+ 'certified': false,
25
+ 'pro': true,
26
+ // new metainfo interface
27
+ 'has': {
28
+ 'CORS': undefined,
29
+ 'spot': true,
30
+ 'margin': true,
31
+ 'swap': true,
32
+ 'future': false,
33
+ 'option': false,
34
+ 'addMargin': true,
35
+ 'cancelAllOrders': true,
36
+ 'cancelOrder': true,
37
+ 'createOrder': true,
38
+ 'createOrders': true,
39
+ 'createPostOnlyOrder': true,
40
+ 'createReduceOnlyOrder': true,
41
+ 'createStopLimitOrder': true,
42
+ 'createStopMarketOrder': true,
43
+ 'createStopOrder': true,
44
+ 'fetchAccounts': true,
45
+ 'fetchBalance': true,
46
+ 'fetchClosedOrders': true,
47
+ 'fetchCurrencies': true,
48
+ 'fetchDepositAddress': true,
49
+ 'fetchDepositAddresses': false,
50
+ 'fetchDepositAddressesByNetwork': false,
51
+ 'fetchDeposits': true,
52
+ 'fetchDepositsWithdrawals': true,
53
+ 'fetchDepositWithdrawFee': 'emulated',
54
+ 'fetchDepositWithdrawFees': true,
55
+ 'fetchFundingHistory': true,
56
+ 'fetchFundingRate': 'emulated',
57
+ 'fetchFundingRateHistory': false,
58
+ 'fetchFundingRates': true,
59
+ 'fetchIndexOHLCV': false,
60
+ 'fetchLeverage': false,
61
+ 'fetchLeverageTiers': true,
62
+ 'fetchMarginMode': false,
63
+ 'fetchMarketLeverageTiers': 'emulated',
64
+ 'fetchMarkets': true,
65
+ 'fetchMarkOHLCV': false,
66
+ 'fetchOHLCV': true,
67
+ 'fetchOpenOrders': true,
68
+ 'fetchOrder': true,
69
+ 'fetchOrderBook': true,
70
+ 'fetchOrders': false,
71
+ 'fetchPosition': false,
72
+ 'fetchPositionMode': false,
73
+ 'fetchPositions': true,
74
+ 'fetchPositionsRisk': false,
75
+ 'fetchPremiumIndexOHLCV': false,
76
+ 'fetchTicker': true,
77
+ 'fetchTickers': true,
78
+ 'fetchTime': true,
79
+ 'fetchTrades': true,
80
+ 'fetchTradingFee': false,
81
+ 'fetchTradingFees': true,
82
+ 'fetchTransactionFee': false,
83
+ 'fetchTransactionFees': false,
84
+ 'fetchTransactions': 'emulated',
85
+ 'fetchTransfer': false,
86
+ 'fetchTransfers': false,
87
+ 'fetchWithdrawal': false,
88
+ 'fetchWithdrawals': true,
89
+ 'reduceMargin': true,
90
+ 'setLeverage': true,
91
+ 'setMarginMode': true,
92
+ 'setPositionMode': false,
93
+ 'transfer': true,
94
+ },
95
+ 'timeframes': {
96
+ '1m': '1',
97
+ '5m': '5',
98
+ '15m': '15',
99
+ '30m': '30',
100
+ '1h': '60',
101
+ '2h': '120',
102
+ '4h': '240',
103
+ '6h': '360',
104
+ '12h': '720',
105
+ '1d': '1d',
106
+ '1w': '1w',
107
+ '1M': '1m',
108
+ },
109
+ 'version': 'v2',
110
+ 'urls': {
111
+ 'logo': 'https://user-images.githubusercontent.com/1294454/112027508-47984600-8b48-11eb-9e17-d26459cc36c6.jpg',
112
+ 'api': {
113
+ 'rest': 'https://ascendex.com',
114
+ },
115
+ 'test': {
116
+ 'rest': 'https://api-test.ascendex-sandbox.com',
117
+ },
118
+ 'www': 'https://ascendex.com',
119
+ 'doc': [
120
+ 'https://ascendex.github.io/ascendex-pro-api/#ascendex-pro-api-documentation',
121
+ ],
122
+ 'fees': 'https://ascendex.com/en/feerate/transactionfee-traderate',
123
+ 'referral': {
124
+ 'url': 'https://ascendex.com/en-us/register?inviteCode=EL6BXBQM',
125
+ 'discount': 0.25,
126
+ },
127
+ },
128
+ 'api': {
129
+ 'v1': {
130
+ 'public': {
131
+ 'get': {
132
+ 'assets': 1,
133
+ 'products': 1,
134
+ 'ticker': 1,
135
+ 'barhist/info': 1,
136
+ 'barhist': 1,
137
+ 'depth': 1,
138
+ 'trades': 1,
139
+ 'cash/assets': 1,
140
+ 'cash/products': 1,
141
+ 'margin/assets': 1,
142
+ 'margin/products': 1,
143
+ 'futures/collateral': 1,
144
+ 'futures/contracts': 1,
145
+ 'futures/ref-px': 1,
146
+ 'futures/market-data': 1,
147
+ 'futures/funding-rates': 1,
148
+ 'risk-limit-info': 1,
149
+ 'exchange-info': 1,
150
+ },
151
+ },
152
+ 'private': {
153
+ 'get': {
154
+ 'info': 1,
155
+ 'wallet/transactions': 1,
156
+ 'wallet/deposit/address': 1,
157
+ 'data/balance/snapshot': 1,
158
+ 'data/balance/history': 1,
159
+ },
160
+ 'accountCategory': {
161
+ 'get': {
162
+ 'balance': 1,
163
+ 'order/open': 1,
164
+ 'order/status': 1,
165
+ 'order/hist/current': 1,
166
+ 'risk': 1,
167
+ },
168
+ 'post': {
169
+ 'order': 1,
170
+ 'order/batch': 1,
171
+ },
172
+ 'delete': {
173
+ 'order': 1,
174
+ 'order/all': 1,
175
+ 'order/batch': 1,
176
+ },
177
+ },
178
+ 'accountGroup': {
179
+ 'get': {
180
+ 'cash/balance': 1,
181
+ 'margin/balance': 1,
182
+ 'margin/risk': 1,
183
+ 'futures/collateral-balance': 1,
184
+ 'futures/position': 1,
185
+ 'futures/risk': 1,
186
+ 'futures/funding-payments': 1,
187
+ 'order/hist': 1,
188
+ 'spot/fee': 1,
189
+ },
190
+ 'post': {
191
+ 'transfer': 1,
192
+ 'futures/transfer/deposit': 1,
193
+ 'futures/transfer/withdraw': 1,
194
+ },
195
+ },
196
+ },
197
+ },
198
+ 'v2': {
199
+ 'public': {
200
+ 'get': {
201
+ 'assets': 1,
202
+ 'futures/contract': 1,
203
+ 'futures/collateral': 1,
204
+ 'futures/pricing-data': 1,
205
+ 'futures/ticker': 1,
206
+ 'risk-limit-info': 1,
207
+ },
208
+ },
209
+ 'private': {
210
+ 'data': {
211
+ 'get': {
212
+ 'order/hist': 1,
213
+ },
214
+ },
215
+ 'get': {
216
+ 'account/info': 1,
217
+ },
218
+ 'accountGroup': {
219
+ 'get': {
220
+ 'order/hist': 1,
221
+ 'futures/position': 1,
222
+ 'futures/free-margin': 1,
223
+ 'futures/order/hist/current': 1,
224
+ 'futures/funding-payments': 1,
225
+ 'futures/order/open': 1,
226
+ 'futures/order/status': 1,
227
+ },
228
+ 'post': {
229
+ 'futures/isolated-position-margin': 1,
230
+ 'futures/margin-type': 1,
231
+ 'futures/leverage': 1,
232
+ 'futures/transfer/deposit': 1,
233
+ 'futures/transfer/withdraw': 1,
234
+ 'futures/order': 1,
235
+ 'futures/order/batch': 1,
236
+ 'futures/order/open': 1,
237
+ 'subuser/subuser-transfer': 1,
238
+ 'subuser/subuser-transfer-hist': 1,
239
+ },
240
+ 'delete': {
241
+ 'futures/order': 1,
242
+ 'futures/order/batch': 1,
243
+ 'futures/order/all': 1,
244
+ },
245
+ },
246
+ },
247
+ },
248
+ },
249
+ 'fees': {
250
+ 'trading': {
251
+ 'feeSide': 'get',
252
+ 'tierBased': true,
253
+ 'percentage': true,
254
+ 'taker': this.parseNumber('0.002'),
255
+ 'maker': this.parseNumber('0.002'),
256
+ },
257
+ },
258
+ 'precisionMode': number.TICK_SIZE,
259
+ 'options': {
260
+ 'account-category': 'cash',
261
+ 'account-group': undefined,
262
+ 'fetchClosedOrders': {
263
+ 'method': 'v2PrivateDataGetOrderHist', // 'v1PrivateAccountCategoryGetOrderHistCurrent'
264
+ },
265
+ 'defaultType': 'spot',
266
+ 'accountsByType': {
267
+ 'spot': 'cash',
268
+ 'swap': 'futures',
269
+ 'margin': 'margin',
270
+ },
271
+ 'transfer': {
272
+ 'fillResponseFromRequest': true,
273
+ },
274
+ 'networks': {
275
+ 'BSC': 'BEP20 (BSC)',
276
+ 'ARB': 'arbitrum',
277
+ 'SOL': 'Solana',
278
+ 'AVAX': 'avalanche C chain',
279
+ 'OMNI': 'Omni',
280
+ },
281
+ 'networksById': {
282
+ 'BEP20 (BSC)': 'BSC',
283
+ 'arbitrum': 'ARB',
284
+ 'Solana': 'SOL',
285
+ 'avalanche C chain': 'AVAX',
286
+ 'Omni': 'OMNI',
287
+ },
288
+ },
289
+ 'exceptions': {
290
+ 'exact': {
291
+ // not documented
292
+ '1900': errors.BadRequest,
293
+ '2100': errors.AuthenticationError,
294
+ '5002': errors.BadSymbol,
295
+ '6001': errors.BadSymbol,
296
+ '6010': errors.InsufficientFunds,
297
+ '60060': errors.InvalidOrder,
298
+ '600503': errors.InvalidOrder,
299
+ // documented
300
+ '100001': errors.BadRequest,
301
+ '100002': errors.BadRequest,
302
+ '100003': errors.BadRequest,
303
+ '100004': errors.BadRequest,
304
+ '100005': errors.BadRequest,
305
+ '100006': errors.BadRequest,
306
+ '100007': errors.BadRequest,
307
+ '100008': errors.BadSymbol,
308
+ '100009': errors.AuthenticationError,
309
+ '100010': errors.BadRequest,
310
+ '100011': errors.BadRequest,
311
+ '100012': errors.BadRequest,
312
+ '100013': errors.BadRequest,
313
+ '100101': errors.ExchangeError,
314
+ '150001': errors.BadRequest,
315
+ '200001': errors.AuthenticationError,
316
+ '200002': errors.ExchangeError,
317
+ '200003': errors.ExchangeError,
318
+ '200004': errors.ExchangeError,
319
+ '200005': errors.ExchangeError,
320
+ '200006': errors.ExchangeError,
321
+ '200007': errors.ExchangeError,
322
+ '200008': errors.ExchangeError,
323
+ '200009': errors.ExchangeError,
324
+ '200010': errors.AuthenticationError,
325
+ '200011': errors.ExchangeError,
326
+ '200012': errors.ExchangeError,
327
+ '200013': errors.ExchangeError,
328
+ '200014': errors.PermissionDenied,
329
+ '200015': errors.PermissionDenied,
330
+ '300001': errors.InvalidOrder,
331
+ '300002': errors.InvalidOrder,
332
+ '300003': errors.InvalidOrder,
333
+ '300004': errors.InvalidOrder,
334
+ '300005': errors.InvalidOrder,
335
+ '300006': errors.InvalidOrder,
336
+ '300007': errors.InvalidOrder,
337
+ '300008': errors.InvalidOrder,
338
+ '300009': errors.InvalidOrder,
339
+ '300011': errors.InsufficientFunds,
340
+ '300012': errors.BadSymbol,
341
+ '300013': errors.InvalidOrder,
342
+ '300014': errors.InvalidOrder,
343
+ '300020': errors.InvalidOrder,
344
+ '300021': errors.InvalidOrder,
345
+ '300031': errors.InvalidOrder,
346
+ '310001': errors.InsufficientFunds,
347
+ '310002': errors.InvalidOrder,
348
+ '310003': errors.InvalidOrder,
349
+ '310004': errors.BadSymbol,
350
+ '310005': errors.InvalidOrder,
351
+ '510001': errors.ExchangeError,
352
+ '900001': errors.ExchangeError, // HUMAN_CHALLENGE Human change do not pass
353
+ },
354
+ 'broad': {},
355
+ },
356
+ 'commonCurrencies': {
357
+ 'BOND': 'BONDED',
358
+ 'BTCBEAR': 'BEAR',
359
+ 'BTCBULL': 'BULL',
360
+ 'BYN': 'BeyondFi',
361
+ 'PLN': 'Pollen',
362
+ },
363
+ });
364
+ }
365
+ getAccount(params = {}) {
366
+ // get current or provided bitmax sub-account
367
+ const account = this.safeValue(params, 'account', this.options['account']);
368
+ const lowercaseAccount = account.toLowerCase();
369
+ return this.capitalize(lowercaseAccount);
370
+ }
371
+ async fetchCurrencies(params = {}) {
372
+ /**
373
+ * @method
374
+ * @name ascendex#fetchCurrencies
375
+ * @description fetches all available currencies on an exchange
376
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
377
+ * @returns {object} an associative dictionary of currencies
378
+ */
379
+ const assets = await this.v1PublicGetAssets(params);
380
+ //
381
+ // {
382
+ // "code":0,
383
+ // "data":[
384
+ // {
385
+ // "assetCode" : "LTCBULL",
386
+ // "assetName" : "3X Long LTC Token",
387
+ // "precisionScale" : 9,
388
+ // "nativeScale" : 4,
389
+ // "withdrawalFee" : "0.2",
390
+ // "minWithdrawalAmt" : "1.0",
391
+ // "status" : "Normal"
392
+ // },
393
+ // ]
394
+ // }
395
+ //
396
+ const margin = await this.v1PublicGetMarginAssets(params);
397
+ //
398
+ // {
399
+ // "code":0,
400
+ // "data":[
401
+ // {
402
+ // "assetCode":"BTT",
403
+ // "borrowAssetCode":"BTT-B",
404
+ // "interestAssetCode":"BTT-I",
405
+ // "nativeScale":0,
406
+ // "numConfirmations":1,
407
+ // "withdrawFee":"100.0",
408
+ // "minWithdrawalAmt":"1000.0",
409
+ // "statusCode":"Normal",
410
+ // "statusMessage":"",
411
+ // "interestRate":"0.001"
412
+ // }
413
+ // ]
414
+ // }
415
+ //
416
+ const cash = await this.v1PublicGetCashAssets(params);
417
+ //
418
+ // {
419
+ // "code":0,
420
+ // "data":[
421
+ // {
422
+ // "assetCode":"LTCBULL",
423
+ // "nativeScale":4,
424
+ // "numConfirmations":20,
425
+ // "withdrawFee":"0.2",
426
+ // "minWithdrawalAmt":"1.0",
427
+ // "statusCode":"Normal",
428
+ // "statusMessage":""
429
+ // }
430
+ // ]
431
+ // }
432
+ //
433
+ const assetsData = this.safeValue(assets, 'data', []);
434
+ const marginData = this.safeValue(margin, 'data', []);
435
+ const cashData = this.safeValue(cash, 'data', []);
436
+ const assetsById = this.indexBy(assetsData, 'assetCode');
437
+ const marginById = this.indexBy(marginData, 'assetCode');
438
+ const cashById = this.indexBy(cashData, 'assetCode');
439
+ const dataById = this.deepExtend(assetsById, marginById, cashById);
440
+ const ids = Object.keys(dataById);
441
+ const result = {};
442
+ for (let i = 0; i < ids.length; i++) {
443
+ const id = ids[i];
444
+ const currency = dataById[id];
445
+ const code = this.safeCurrencyCode(id);
446
+ const scale = this.safeString2(currency, 'precisionScale', 'nativeScale');
447
+ const precision = this.parseNumber(this.parsePrecision(scale));
448
+ const fee = this.safeNumber2(currency, 'withdrawFee', 'withdrawalFee');
449
+ const status = this.safeString2(currency, 'status', 'statusCode');
450
+ const active = (status === 'Normal');
451
+ const marginInside = ('borrowAssetCode' in currency);
452
+ result[code] = {
453
+ 'id': id,
454
+ 'code': code,
455
+ 'info': currency,
456
+ 'type': undefined,
457
+ 'margin': marginInside,
458
+ 'name': this.safeString(currency, 'assetName'),
459
+ 'active': active,
460
+ 'deposit': undefined,
461
+ 'withdraw': undefined,
462
+ 'fee': fee,
463
+ 'precision': precision,
464
+ 'limits': {
465
+ 'amount': {
466
+ 'min': precision,
467
+ 'max': undefined,
468
+ },
469
+ 'withdraw': {
470
+ 'min': this.safeNumber(currency, 'minWithdrawalAmt'),
471
+ 'max': undefined,
472
+ },
473
+ },
474
+ 'networks': {},
475
+ };
476
+ }
477
+ return result;
478
+ }
479
+ async fetchMarkets(params = {}) {
480
+ /**
481
+ * @method
482
+ * @name ascendex#fetchMarkets
483
+ * @description retrieves data on all markets for ascendex
484
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
485
+ * @returns {object[]} an array of objects representing market data
486
+ */
487
+ const products = await this.v1PublicGetProducts(params);
488
+ //
489
+ // {
490
+ // "code": 0,
491
+ // "data": [
492
+ // {
493
+ // "symbol": "LBA/BTC",
494
+ // "baseAsset": "LBA",
495
+ // "quoteAsset": "BTC",
496
+ // "status": "Normal",
497
+ // "minNotional": "0.000625",
498
+ // "maxNotional": "6.25",
499
+ // "marginTradable": false,
500
+ // "commissionType": "Quote",
501
+ // "commissionReserveRate": "0.001",
502
+ // "tickSize": "0.000000001",
503
+ // "lotSize": "1"
504
+ // },
505
+ // ]
506
+ // }
507
+ //
508
+ const cash = await this.v1PublicGetCashProducts(params);
509
+ //
510
+ // {
511
+ // "code": 0,
512
+ // "data": [
513
+ // {
514
+ // "symbol": "QTUM/BTC",
515
+ // "displayName": "QTUM/BTC",
516
+ // "domain": "BTC",
517
+ // "tradingStartTime": 1569506400000,
518
+ // "collapseDecimals": "0.0001,0.000001,0.00000001",
519
+ // "minQty": "0.000000001",
520
+ // "maxQty": "1000000000",
521
+ // "minNotional": "0.000625",
522
+ // "maxNotional": "12.5",
523
+ // "statusCode": "Normal",
524
+ // "statusMessage": "",
525
+ // "tickSize": "0.00000001",
526
+ // "useTick": false,
527
+ // "lotSize": "0.1",
528
+ // "useLot": false,
529
+ // "commissionType": "Quote",
530
+ // "commissionReserveRate": "0.001",
531
+ // "qtyScale": 1,
532
+ // "priceScale": 8,
533
+ // "notionalScale": 4
534
+ // }
535
+ // ]
536
+ // }
537
+ //
538
+ const perpetuals = await this.v2PublicGetFuturesContract(params);
539
+ //
540
+ // {
541
+ // "code": 0,
542
+ // "data": [
543
+ // {
544
+ // "symbol": "BTC-PERP",
545
+ // "status": "Normal",
546
+ // "displayName": "BTCUSDT",
547
+ // "settlementAsset": "USDT",
548
+ // "underlying": "BTC/USDT",
549
+ // "tradingStartTime": 1579701600000,
550
+ // "priceFilter": {
551
+ // "minPrice": "1",
552
+ // "maxPrice": "1000000",
553
+ // "tickSize": "1"
554
+ // },
555
+ // "lotSizeFilter": {
556
+ // "minQty": "0.0001",
557
+ // "maxQty": "1000000000",
558
+ // "lotSize": "0.0001"
559
+ // },
560
+ // "commissionType": "Quote",
561
+ // "commissionReserveRate": "0.001",
562
+ // "marketOrderPriceMarkup": "0.03",
563
+ // "marginRequirements": [
564
+ // {
565
+ // "positionNotionalLowerBound": "0",
566
+ // "positionNotionalUpperBound": "50000",
567
+ // "initialMarginRate": "0.01",
568
+ // "maintenanceMarginRate": "0.006"
569
+ // },
570
+ // ...
571
+ // ]
572
+ // }
573
+ // ]
574
+ // }
575
+ //
576
+ const productsData = this.safeValue(products, 'data', []);
577
+ const productsById = this.indexBy(productsData, 'symbol');
578
+ const cashData = this.safeValue(cash, 'data', []);
579
+ const perpetualsData = this.safeValue(perpetuals, 'data', []);
580
+ const cashAndPerpetualsData = this.arrayConcat(cashData, perpetualsData);
581
+ const cashAndPerpetualsById = this.indexBy(cashAndPerpetualsData, 'symbol');
582
+ const dataById = this.deepExtend(productsById, cashAndPerpetualsById);
583
+ const ids = Object.keys(dataById);
584
+ const result = [];
585
+ for (let i = 0; i < ids.length; i++) {
586
+ const id = ids[i];
587
+ const market = dataById[id];
588
+ const settleId = this.safeValue(market, 'settlementAsset');
589
+ const settle = this.safeCurrencyCode(settleId);
590
+ const status = this.safeString(market, 'status');
591
+ const domain = this.safeString(market, 'domain');
592
+ let active = false;
593
+ if (((status === 'Normal') || (status === 'InternalTrading')) && (domain !== 'LeveragedETF')) {
594
+ active = true;
595
+ }
596
+ const spot = settle === undefined;
597
+ const swap = !spot;
598
+ const linear = swap ? true : undefined;
599
+ let minQty = this.safeNumber(market, 'minQty');
600
+ let maxQty = this.safeNumber(market, 'maxQty');
601
+ let minPrice = this.safeNumber(market, 'tickSize');
602
+ let maxPrice = undefined;
603
+ const underlying = this.safeString2(market, 'underlying', 'symbol');
604
+ const parts = underlying.split('/');
605
+ const baseId = this.safeString(parts, 0);
606
+ const quoteId = this.safeString(parts, 1);
607
+ const base = this.safeCurrencyCode(baseId);
608
+ const quote = this.safeCurrencyCode(quoteId);
609
+ let symbol = base + '/' + quote;
610
+ if (swap) {
611
+ const lotSizeFilter = this.safeValue(market, 'lotSizeFilter');
612
+ minQty = this.safeNumber(lotSizeFilter, 'minQty');
613
+ maxQty = this.safeNumber(lotSizeFilter, 'maxQty');
614
+ const priceFilter = this.safeValue(market, 'priceFilter');
615
+ minPrice = this.safeNumber(priceFilter, 'minPrice');
616
+ maxPrice = this.safeNumber(priceFilter, 'maxPrice');
617
+ symbol = base + '/' + quote + ':' + settle;
618
+ }
619
+ const fee = this.safeNumber(market, 'commissionReserveRate');
620
+ const marginTradable = this.safeValue(market, 'marginTradable', false);
621
+ result.push({
622
+ 'id': id,
623
+ 'symbol': symbol,
624
+ 'base': base,
625
+ 'quote': quote,
626
+ 'settle': settle,
627
+ 'baseId': baseId,
628
+ 'quoteId': quoteId,
629
+ 'settleId': settleId,
630
+ 'type': swap ? 'swap' : 'spot',
631
+ 'spot': spot,
632
+ 'margin': spot ? marginTradable : undefined,
633
+ 'swap': swap,
634
+ 'future': false,
635
+ 'option': false,
636
+ 'active': active,
637
+ 'contract': swap,
638
+ 'linear': linear,
639
+ 'inverse': swap ? !linear : undefined,
640
+ 'taker': fee,
641
+ 'maker': fee,
642
+ 'contractSize': swap ? this.parseNumber('1') : undefined,
643
+ 'expiry': undefined,
644
+ 'expiryDatetime': undefined,
645
+ 'strike': undefined,
646
+ 'optionType': undefined,
647
+ 'precision': {
648
+ 'amount': this.safeNumber(market, 'lotSize'),
649
+ 'price': this.safeNumber(market, 'tickSize'),
650
+ },
651
+ 'limits': {
652
+ 'leverage': {
653
+ 'min': undefined,
654
+ 'max': undefined,
655
+ },
656
+ 'amount': {
657
+ 'min': minQty,
658
+ 'max': maxQty,
659
+ },
660
+ 'price': {
661
+ 'min': minPrice,
662
+ 'max': maxPrice,
663
+ },
664
+ 'cost': {
665
+ 'min': this.safeNumber(market, 'minNotional'),
666
+ 'max': this.safeNumber(market, 'maxNotional'),
667
+ },
668
+ },
669
+ 'created': this.safeInteger(market, 'tradingStartTime'),
670
+ 'info': market,
671
+ });
672
+ }
673
+ return result;
674
+ }
675
+ async fetchTime(params = {}) {
676
+ /**
677
+ * @method
678
+ * @name ascendex#fetchTime
679
+ * @description fetches the current integer timestamp in milliseconds from the ascendex server
680
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
681
+ * @returns {int} the current integer timestamp in milliseconds from the ascendex server
682
+ */
683
+ const request = {
684
+ 'requestTime': this.milliseconds(),
685
+ };
686
+ const response = await this.v1PublicGetExchangeInfo(this.extend(request, params));
687
+ //
688
+ // {
689
+ // "code": 0,
690
+ // "data": {
691
+ // "requestTimeEcho": 1656560463601,
692
+ // "requestReceiveAt": 1656560464331,
693
+ // "latency": 730
694
+ // }
695
+ // }
696
+ //
697
+ const data = this.safeValue(response, 'data');
698
+ return this.safeInteger(data, 'requestReceiveAt');
699
+ }
700
+ async fetchAccounts(params = {}) {
701
+ /**
702
+ * @method
703
+ * @name ascendex#fetchAccounts
704
+ * @description fetch all the accounts associated with a profile
705
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
706
+ * @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
707
+ */
708
+ let accountGroup = this.safeString(this.options, 'account-group');
709
+ let response = undefined;
710
+ if (accountGroup === undefined) {
711
+ response = await this.v1PrivateGetInfo(params);
712
+ //
713
+ // {
714
+ // "code":0,
715
+ // "data":{
716
+ // "email":"igor.kroitor@gmail.com",
717
+ // "accountGroup":8,
718
+ // "viewPermission":true,
719
+ // "tradePermission":true,
720
+ // "transferPermission":true,
721
+ // "cashAccount":["cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda"],
722
+ // "marginAccount":["martXoh1v1N3EMQC5FDtSj5VHso8aI2Z"],
723
+ // "futuresAccount":["futc9r7UmFJAyBY2rE3beA2JFxav2XFF"],
724
+ // "userUID":"U6491137460"
725
+ // }
726
+ // }
727
+ //
728
+ const data = this.safeValue(response, 'data', {});
729
+ accountGroup = this.safeString(data, 'accountGroup');
730
+ this.options['account-group'] = accountGroup;
731
+ }
732
+ return [
733
+ {
734
+ 'id': accountGroup,
735
+ 'type': undefined,
736
+ 'currency': undefined,
737
+ 'info': response,
738
+ },
739
+ ];
740
+ }
741
+ parseBalance(response) {
742
+ const timestamp = this.milliseconds();
743
+ const result = {
744
+ 'info': response,
745
+ 'timestamp': timestamp,
746
+ 'datetime': this.iso8601(timestamp),
747
+ };
748
+ const balances = this.safeValue(response, 'data', []);
749
+ for (let i = 0; i < balances.length; i++) {
750
+ const balance = balances[i];
751
+ const code = this.safeCurrencyCode(this.safeString(balance, 'asset'));
752
+ const account = this.account();
753
+ account['free'] = this.safeString(balance, 'availableBalance');
754
+ account['total'] = this.safeString(balance, 'totalBalance');
755
+ result[code] = account;
756
+ }
757
+ return this.safeBalance(result);
758
+ }
759
+ parseMarginBalance(response) {
760
+ const timestamp = this.milliseconds();
761
+ const result = {
762
+ 'info': response,
763
+ 'timestamp': timestamp,
764
+ 'datetime': this.iso8601(timestamp),
765
+ };
766
+ const balances = this.safeValue(response, 'data', []);
767
+ for (let i = 0; i < balances.length; i++) {
768
+ const balance = balances[i];
769
+ const code = this.safeCurrencyCode(this.safeString(balance, 'asset'));
770
+ const account = this.account();
771
+ account['free'] = this.safeString(balance, 'availableBalance');
772
+ account['total'] = this.safeString(balance, 'totalBalance');
773
+ const debt = this.safeString(balance, 'borrowed');
774
+ const interest = this.safeString(balance, 'interest');
775
+ account['debt'] = Precise["default"].stringAdd(debt, interest);
776
+ result[code] = account;
777
+ }
778
+ return this.safeBalance(result);
779
+ }
780
+ parseSwapBalance(response) {
781
+ const timestamp = this.milliseconds();
782
+ const result = {
783
+ 'info': response,
784
+ 'timestamp': timestamp,
785
+ 'datetime': this.iso8601(timestamp),
786
+ };
787
+ const data = this.safeValue(response, 'data', {});
788
+ const collaterals = this.safeValue(data, 'collaterals', []);
789
+ for (let i = 0; i < collaterals.length; i++) {
790
+ const balance = collaterals[i];
791
+ const code = this.safeCurrencyCode(this.safeString(balance, 'asset'));
792
+ const account = this.account();
793
+ account['total'] = this.safeString(balance, 'balance');
794
+ result[code] = account;
795
+ }
796
+ return this.safeBalance(result);
797
+ }
798
+ async fetchBalance(params = {}) {
799
+ /**
800
+ * @method
801
+ * @name ascendex#fetchBalance
802
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
803
+ * @see https://ascendex.github.io/ascendex-pro-api/#cash-account-balance
804
+ * @see https://ascendex.github.io/ascendex-pro-api/#margin-account-balance
805
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#position
806
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
807
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
808
+ */
809
+ await this.loadMarkets();
810
+ await this.loadAccounts();
811
+ let query = undefined;
812
+ let marketType = undefined;
813
+ [marketType, query] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
814
+ const isMargin = this.safeValue(params, 'margin', false);
815
+ marketType = isMargin ? 'margin' : marketType;
816
+ query = this.omit(query, 'margin');
817
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
818
+ const accountCategory = this.safeString(accountsByType, marketType, 'cash');
819
+ const account = this.safeValue(this.accounts, 0, {});
820
+ const accountGroup = this.safeString(account, 'id');
821
+ const request = {
822
+ 'account-group': accountGroup,
823
+ };
824
+ if ((accountCategory === 'cash') || (accountCategory === 'margin')) {
825
+ request['account-category'] = accountCategory;
826
+ }
827
+ let response = undefined;
828
+ if ((marketType === 'spot') || (marketType === 'margin')) {
829
+ response = await this.v1PrivateAccountCategoryGetBalance(this.extend(request, query));
830
+ }
831
+ else if (marketType === 'swap') {
832
+ response = await this.v2PrivateAccountGroupGetFuturesPosition(this.extend(request, query));
833
+ }
834
+ else {
835
+ throw new errors.NotSupported(this.id + ' fetchBalance() is not currently supported for ' + marketType + ' markets');
836
+ }
837
+ //
838
+ // cash
839
+ //
840
+ // {
841
+ // "code": 0,
842
+ // "data": [
843
+ // {
844
+ // "asset": "BCHSV",
845
+ // "totalBalance": "64.298000048",
846
+ // "availableBalance": "64.298000048",
847
+ // },
848
+ // ]
849
+ // }
850
+ //
851
+ // margin
852
+ //
853
+ // {
854
+ // "code": 0,
855
+ // "data": [
856
+ // {
857
+ // "asset": "BCHSV",
858
+ // "totalBalance": "64.298000048",
859
+ // "availableBalance": "64.298000048",
860
+ // "borrowed": "0",
861
+ // "interest": "0",
862
+ // },
863
+ // ]
864
+ // }
865
+ //
866
+ // swap
867
+ //
868
+ // {
869
+ // "code": 0,
870
+ // "data": {
871
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
872
+ // "ac": "FUTURES",
873
+ // "collaterals": [
874
+ // {"asset":"ADA","balance":"0.355803","referencePrice":"1.05095","discountFactor":"0.9"},
875
+ // {"asset":"USDT","balance":"0.000014519","referencePrice":"1","discountFactor":"1"}
876
+ // ],
877
+ // }j
878
+ // }
879
+ //
880
+ if (marketType === 'swap') {
881
+ return this.parseSwapBalance(response);
882
+ }
883
+ else if (marketType === 'margin') {
884
+ return this.parseMarginBalance(response);
885
+ }
886
+ else {
887
+ return this.parseBalance(response);
888
+ }
889
+ }
890
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
891
+ /**
892
+ * @method
893
+ * @name ascendex#fetchOrderBook
894
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
895
+ * @param {string} symbol unified symbol of the market to fetch the order book for
896
+ * @param {int} [limit] the maximum amount of order book entries to return
897
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
898
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
899
+ */
900
+ await this.loadMarkets();
901
+ const market = this.market(symbol);
902
+ const request = {
903
+ 'symbol': market['id'],
904
+ };
905
+ const response = await this.v1PublicGetDepth(this.extend(request, params));
906
+ //
907
+ // {
908
+ // "code":0,
909
+ // "data":{
910
+ // "m":"depth-snapshot",
911
+ // "symbol":"BTC-PERP",
912
+ // "data":{
913
+ // "ts":1590223998202,
914
+ // "seqnum":115444921,
915
+ // "asks":[
916
+ // ["9207.5","18.2383"],
917
+ // ["9207.75","18.8235"],
918
+ // ["9208","10.7873"],
919
+ // ],
920
+ // "bids":[
921
+ // ["9207.25","0.4009"],
922
+ // ["9207","0.003"],
923
+ // ["9206.5","0.003"],
924
+ // ]
925
+ // }
926
+ // }
927
+ // }
928
+ //
929
+ const data = this.safeValue(response, 'data', {});
930
+ const orderbook = this.safeValue(data, 'data', {});
931
+ const timestamp = this.safeInteger(orderbook, 'ts');
932
+ const result = this.parseOrderBook(orderbook, symbol, timestamp);
933
+ result['nonce'] = this.safeInteger(orderbook, 'seqnum');
934
+ return result;
935
+ }
936
+ parseTicker(ticker, market = undefined) {
937
+ //
938
+ // {
939
+ // "symbol":"QTUM/BTC",
940
+ // "open":"0.00016537",
941
+ // "close":"0.00019077",
942
+ // "high":"0.000192",
943
+ // "low":"0.00016537",
944
+ // "volume":"846.6",
945
+ // "ask":["0.00018698","26.2"],
946
+ // "bid":["0.00018408","503.7"],
947
+ // "type":"spot"
948
+ // }
949
+ //
950
+ const timestamp = undefined;
951
+ const marketId = this.safeString(ticker, 'symbol');
952
+ const type = this.safeString(ticker, 'type');
953
+ const delimiter = (type === 'spot') ? '/' : undefined;
954
+ const symbol = this.safeSymbol(marketId, market, delimiter);
955
+ const close = this.safeString(ticker, 'close');
956
+ const bid = this.safeValue(ticker, 'bid', []);
957
+ const ask = this.safeValue(ticker, 'ask', []);
958
+ const open = this.safeString(ticker, 'open');
959
+ return this.safeTicker({
960
+ 'symbol': symbol,
961
+ 'timestamp': timestamp,
962
+ 'datetime': undefined,
963
+ 'high': this.safeString(ticker, 'high'),
964
+ 'low': this.safeString(ticker, 'low'),
965
+ 'bid': this.safeString(bid, 0),
966
+ 'bidVolume': this.safeString(bid, 1),
967
+ 'ask': this.safeString(ask, 0),
968
+ 'askVolume': this.safeString(ask, 1),
969
+ 'vwap': undefined,
970
+ 'open': open,
971
+ 'close': close,
972
+ 'last': close,
973
+ 'previousClose': undefined,
974
+ 'change': undefined,
975
+ 'percentage': undefined,
976
+ 'average': undefined,
977
+ 'baseVolume': this.safeString(ticker, 'volume'),
978
+ 'quoteVolume': undefined,
979
+ 'info': ticker,
980
+ }, market);
981
+ }
982
+ async fetchTicker(symbol, params = {}) {
983
+ /**
984
+ * @method
985
+ * @name ascendex#fetchTicker
986
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
987
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
988
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
989
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
990
+ */
991
+ await this.loadMarkets();
992
+ const market = this.market(symbol);
993
+ const request = {
994
+ 'symbol': market['id'],
995
+ };
996
+ const response = await this.v1PublicGetTicker(this.extend(request, params));
997
+ //
998
+ // {
999
+ // "code":0,
1000
+ // "data":{
1001
+ // "symbol":"BTC-PERP", // or "BTC/USDT"
1002
+ // "open":"9073",
1003
+ // "close":"9185.75",
1004
+ // "high":"9185.75",
1005
+ // "low":"9185.75",
1006
+ // "volume":"576.8334",
1007
+ // "ask":["9185.75","15.5863"],
1008
+ // "bid":["9185.5","0.003"],
1009
+ // "type":"derivatives", // or "spot"
1010
+ // }
1011
+ // }
1012
+ //
1013
+ const data = this.safeValue(response, 'data', {});
1014
+ return this.parseTicker(data, market);
1015
+ }
1016
+ async fetchTickers(symbols = undefined, params = {}) {
1017
+ /**
1018
+ * @method
1019
+ * @name ascendex#fetchTickers
1020
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1021
+ * @see https://ascendex.github.io/ascendex-pro-api/#ticker
1022
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#ticker
1023
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1024
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1025
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1026
+ */
1027
+ await this.loadMarkets();
1028
+ const request = {};
1029
+ let market = undefined;
1030
+ if (symbols !== undefined) {
1031
+ const symbol = this.safeValue(symbols, 0);
1032
+ market = this.market(symbol);
1033
+ const marketIds = this.marketIds(symbols);
1034
+ request['symbol'] = marketIds.join(',');
1035
+ }
1036
+ let type = undefined;
1037
+ [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
1038
+ let response = undefined;
1039
+ if (type === 'spot') {
1040
+ response = await this.v1PublicGetTicker(this.extend(request, params));
1041
+ }
1042
+ else {
1043
+ response = await this.v2PublicGetFuturesTicker(this.extend(request, params));
1044
+ }
1045
+ //
1046
+ // {
1047
+ // "code":0,
1048
+ // "data":[
1049
+ // {
1050
+ // "symbol":"QTUM/BTC",
1051
+ // "open":"0.00016537",
1052
+ // "close":"0.00019077",
1053
+ // "high":"0.000192",
1054
+ // "low":"0.00016537",
1055
+ // "volume":"846.6",
1056
+ // "ask":["0.00018698","26.2"],
1057
+ // "bid":["0.00018408","503.7"],
1058
+ // "type":"spot"
1059
+ // }
1060
+ // ]
1061
+ // }
1062
+ //
1063
+ const data = this.safeValue(response, 'data', []);
1064
+ if (!Array.isArray(data)) {
1065
+ return this.parseTickers([data], symbols);
1066
+ }
1067
+ return this.parseTickers(data, symbols);
1068
+ }
1069
+ parseOHLCV(ohlcv, market = undefined) {
1070
+ //
1071
+ // {
1072
+ // "m":"bar",
1073
+ // "s":"BTC/USDT",
1074
+ // "data":{
1075
+ // "i":"1",
1076
+ // "ts":1590228000000,
1077
+ // "o":"9139.59",
1078
+ // "c":"9131.94",
1079
+ // "h":"9139.99",
1080
+ // "l":"9121.71",
1081
+ // "v":"25.20648"
1082
+ // }
1083
+ // }
1084
+ //
1085
+ const data = this.safeValue(ohlcv, 'data', {});
1086
+ return [
1087
+ this.safeInteger(data, 'ts'),
1088
+ this.safeNumber(data, 'o'),
1089
+ this.safeNumber(data, 'h'),
1090
+ this.safeNumber(data, 'l'),
1091
+ this.safeNumber(data, 'c'),
1092
+ this.safeNumber(data, 'v'),
1093
+ ];
1094
+ }
1095
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
1096
+ /**
1097
+ * @method
1098
+ * @name ascendex#fetchOHLCV
1099
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1100
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1101
+ * @param {string} timeframe the length of time each candle represents
1102
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
1103
+ * @param {int} [limit] the maximum amount of candles to fetch
1104
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1105
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1106
+ */
1107
+ await this.loadMarkets();
1108
+ const market = this.market(symbol);
1109
+ const request = {
1110
+ 'symbol': market['id'],
1111
+ 'interval': this.safeString(this.timeframes, timeframe, timeframe),
1112
+ };
1113
+ // if since and limit are not specified
1114
+ // the exchange will return just 1 last candle by default
1115
+ const duration = this.parseTimeframe(timeframe);
1116
+ const options = this.safeValue(this.options, 'fetchOHLCV', {});
1117
+ const defaultLimit = this.safeInteger(options, 'limit', 500);
1118
+ if (since !== undefined) {
1119
+ request['from'] = since;
1120
+ if (limit === undefined) {
1121
+ limit = defaultLimit;
1122
+ }
1123
+ else {
1124
+ limit = Math.min(limit, defaultLimit);
1125
+ }
1126
+ request['to'] = this.sum(since, limit * duration * 1000, 1);
1127
+ }
1128
+ else if (limit !== undefined) {
1129
+ request['n'] = limit; // max 500
1130
+ }
1131
+ const response = await this.v1PublicGetBarhist(this.extend(request, params));
1132
+ //
1133
+ // {
1134
+ // "code":0,
1135
+ // "data":[
1136
+ // {
1137
+ // "m":"bar",
1138
+ // "s":"BTC/USDT",
1139
+ // "data":{
1140
+ // "i":"1",
1141
+ // "ts":1590228000000,
1142
+ // "o":"9139.59",
1143
+ // "c":"9131.94",
1144
+ // "h":"9139.99",
1145
+ // "l":"9121.71",
1146
+ // "v":"25.20648"
1147
+ // }
1148
+ // }
1149
+ // ]
1150
+ // }
1151
+ //
1152
+ const data = this.safeValue(response, 'data', []);
1153
+ return this.parseOHLCVs(data, market, timeframe, since, limit);
1154
+ }
1155
+ parseTrade(trade, market = undefined) {
1156
+ //
1157
+ // public fetchTrades
1158
+ //
1159
+ // {
1160
+ // "p":"9128.5", // price
1161
+ // "q":"0.0030", // quantity
1162
+ // "ts":1590229002385, // timestamp
1163
+ // "bm":false, // if true, the buyer is the market maker, we only use this field to "define the side" of a public trade
1164
+ // "seqnum":180143985289898554
1165
+ // }
1166
+ //
1167
+ const timestamp = this.safeInteger(trade, 'ts');
1168
+ const priceString = this.safeString2(trade, 'price', 'p');
1169
+ const amountString = this.safeString(trade, 'q');
1170
+ const buyerIsMaker = this.safeValue(trade, 'bm', false);
1171
+ const side = buyerIsMaker ? 'sell' : 'buy';
1172
+ market = this.safeMarket(undefined, market);
1173
+ return this.safeTrade({
1174
+ 'info': trade,
1175
+ 'timestamp': timestamp,
1176
+ 'datetime': this.iso8601(timestamp),
1177
+ 'symbol': market['symbol'],
1178
+ 'id': undefined,
1179
+ 'order': undefined,
1180
+ 'type': undefined,
1181
+ 'takerOrMaker': undefined,
1182
+ 'side': side,
1183
+ 'price': priceString,
1184
+ 'amount': amountString,
1185
+ 'cost': undefined,
1186
+ 'fee': undefined,
1187
+ }, market);
1188
+ }
1189
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
1190
+ /**
1191
+ * @method
1192
+ * @name ascendex#fetchTrades
1193
+ * @description get the list of most recent trades for a particular symbol
1194
+ * @see https://ascendex.github.io/ascendex-pro-api/#market-trades
1195
+ * @param {string} symbol unified symbol of the market to fetch trades for
1196
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
1197
+ * @param {int} [limit] the maximum amount of trades to fetch
1198
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1199
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1200
+ */
1201
+ await this.loadMarkets();
1202
+ const market = this.market(symbol);
1203
+ const request = {
1204
+ 'symbol': market['id'],
1205
+ };
1206
+ if (limit !== undefined) {
1207
+ request['n'] = limit; // max 100
1208
+ }
1209
+ const response = await this.v1PublicGetTrades(this.extend(request, params));
1210
+ //
1211
+ // {
1212
+ // "code":0,
1213
+ // "data":{
1214
+ // "m":"trades",
1215
+ // "symbol":"BTC-PERP",
1216
+ // "data":[
1217
+ // {"p":"9128.5","q":"0.0030","ts":1590229002385,"bm":false,"seqnum":180143985289898554},
1218
+ // {"p":"9129","q":"0.0030","ts":1590229002642,"bm":false,"seqnum":180143985289898587},
1219
+ // {"p":"9129.5","q":"0.0030","ts":1590229021306,"bm":false,"seqnum":180143985289899043}
1220
+ // ]
1221
+ // }
1222
+ // }
1223
+ //
1224
+ const records = this.safeValue(response, 'data', []);
1225
+ const trades = this.safeValue(records, 'data', []);
1226
+ return this.parseTrades(trades, market, since, limit);
1227
+ }
1228
+ parseOrderStatus(status) {
1229
+ const statuses = {
1230
+ 'PendingNew': 'open',
1231
+ 'New': 'open',
1232
+ 'PartiallyFilled': 'open',
1233
+ 'Filled': 'closed',
1234
+ 'Canceled': 'canceled',
1235
+ 'Rejected': 'rejected',
1236
+ };
1237
+ return this.safeString(statuses, status, status);
1238
+ }
1239
+ parseOrder(order, market = undefined) {
1240
+ //
1241
+ // createOrder
1242
+ //
1243
+ // {
1244
+ // "id": "16e607e2b83a8bXHbAwwoqDo55c166fa",
1245
+ // "orderId": "16e85b4d9b9a8bXHbAwwoqDoc3d66830",
1246
+ // "orderType": "Market",
1247
+ // "symbol": "BTC/USDT",
1248
+ // "timestamp": 1573576916201
1249
+ // }
1250
+ //
1251
+ // {
1252
+ // "ac": "FUTURES",
1253
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
1254
+ // "time": 1640819389454,
1255
+ // "orderId": "a17e0874ecbdU0711043490bbtcpDU5X",
1256
+ // "seqNum": -1,
1257
+ // "orderType": "Limit",
1258
+ // "execInst": "NULL_VAL",
1259
+ // "side": "Buy",
1260
+ // "symbol": "BTC-PERP",
1261
+ // "price": "30000",
1262
+ // "orderQty": "0.002",
1263
+ // "stopPrice": "0",
1264
+ // "stopBy": "ref-px",
1265
+ // "status": "Ack",
1266
+ // "lastExecTime": 1640819389454,
1267
+ // "lastQty": "0",
1268
+ // "lastPx": "0",
1269
+ // "avgFilledPx": "0",
1270
+ // "cumFilledQty": "0",
1271
+ // "fee": "0",
1272
+ // "cumFee": "0",
1273
+ // "feeAsset": "",
1274
+ // "errorCode": "",
1275
+ // "posStopLossPrice": "0",
1276
+ // "posStopLossTrigger": "market",
1277
+ // "posTakeProfitPrice": "0",
1278
+ // "posTakeProfitTrigger": "market",
1279
+ // "liquidityInd": "n"
1280
+ // }
1281
+ //
1282
+ // fetchOrder, fetchOpenOrders, fetchClosedOrders
1283
+ //
1284
+ // {
1285
+ // "symbol": "BTC/USDT",
1286
+ // "price": "8131.22",
1287
+ // "orderQty": "0.00082",
1288
+ // "orderType": "Market",
1289
+ // "avgPx": "7392.02",
1290
+ // "cumFee": "0.005152238",
1291
+ // "cumFilledQty": "0.00082",
1292
+ // "errorCode": "",
1293
+ // "feeAsset": "USDT",
1294
+ // "lastExecTime": 1575953151764,
1295
+ // "orderId": "a16eee20b6750866943712zWEDdAjt3",
1296
+ // "seqNum": 2623469,
1297
+ // "side": "Buy",
1298
+ // "status": "Filled",
1299
+ // "stopPrice": "",
1300
+ // "execInst": "NULL_VAL" // "Post" (for postOnly orders), "reduceOnly" (for reduceOnly orders)
1301
+ // }
1302
+ //
1303
+ // {
1304
+ // "orderId": "a173ad938fc3U22666567717788c3b66", // orderId
1305
+ // "seqNum": 18777366360, // sequence number
1306
+ // "accountId": "cshwSjbpPjSwHmxPdz2CPQVU9mnbzPpt", // accountId
1307
+ // "symbol": "BTC/USDT", // symbol
1308
+ // "orderType": "Limit", // order type (Limit/Market/StopMarket/StopLimit)
1309
+ // "side": "Sell", // order side (Buy/Sell)
1310
+ // "price": "11346.77", // order price
1311
+ // "stopPrice": "0", // stop price (0 by default)
1312
+ // "orderQty": "0.01", // order quantity (in base asset)
1313
+ // "status": "Canceled", // order status (Filled/Canceled/Rejected)
1314
+ // "createTime": 1596344995793, // order creation time
1315
+ // "lastExecTime": 1596344996053, // last execution time
1316
+ // "avgFillPrice": "11346.77", // average filled price
1317
+ // "fillQty": "0.01", // filled quantity (in base asset)
1318
+ // "fee": "-0.004992579", // cummulative fee. if negative, this value is the commission charged; if possitive, this value is the rebate received.
1319
+ // "feeAsset": "USDT" // fee asset
1320
+ // }
1321
+ //
1322
+ // {
1323
+ // "ac": "FUTURES",
1324
+ // "accountId": "testabcdefg",
1325
+ // "avgPx": "0",
1326
+ // "cumFee": "0",
1327
+ // "cumQty": "0",
1328
+ // "errorCode": "NULL_VAL",
1329
+ // "execInst": "NULL_VAL",
1330
+ // "feeAsset": "USDT",
1331
+ // "lastExecTime": 1584072844085,
1332
+ // "orderId": "r170d21956dd5450276356bbtcpKa74",
1333
+ // "orderQty": "1.1499",
1334
+ // "orderType": "Limit",
1335
+ // "price": "4000",
1336
+ // "sendingTime": 1584072841033,
1337
+ // "seqNum": 24105338,
1338
+ // "side": "Buy",
1339
+ // "status": "Canceled",
1340
+ // "stopPrice": "",
1341
+ // "symbol": "BTC-PERP"
1342
+ // },
1343
+ //
1344
+ const status = this.parseOrderStatus(this.safeString(order, 'status'));
1345
+ const marketId = this.safeString(order, 'symbol');
1346
+ const symbol = this.safeSymbol(marketId, market, '/');
1347
+ let timestamp = this.safeInteger2(order, 'timestamp', 'sendingTime');
1348
+ const lastTradeTimestamp = this.safeInteger(order, 'lastExecTime');
1349
+ if (timestamp === undefined) {
1350
+ timestamp = lastTradeTimestamp;
1351
+ }
1352
+ const price = this.safeString(order, 'price');
1353
+ const amount = this.safeString(order, 'orderQty');
1354
+ const average = this.safeString(order, 'avgPx');
1355
+ const filled = this.safeStringN(order, ['cumFilledQty', 'cumQty', 'fillQty']);
1356
+ const id = this.safeString(order, 'orderId');
1357
+ let clientOrderId = this.safeString(order, 'id');
1358
+ if (clientOrderId !== undefined) {
1359
+ if (clientOrderId.length < 1) {
1360
+ clientOrderId = undefined;
1361
+ }
1362
+ }
1363
+ const rawTypeLower = this.safeStringLower(order, 'orderType');
1364
+ let type = rawTypeLower;
1365
+ if (rawTypeLower !== undefined) {
1366
+ if (rawTypeLower === 'stoplimit') {
1367
+ type = 'limit';
1368
+ }
1369
+ if (rawTypeLower === 'stopmarket') {
1370
+ type = 'market';
1371
+ }
1372
+ }
1373
+ const side = this.safeStringLower(order, 'side');
1374
+ const feeCost = this.safeNumber2(order, 'cumFee', 'fee');
1375
+ let fee = undefined;
1376
+ if (feeCost !== undefined) {
1377
+ const feeCurrencyId = this.safeString(order, 'feeAsset');
1378
+ const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
1379
+ fee = {
1380
+ 'cost': feeCost,
1381
+ 'currency': feeCurrencyCode,
1382
+ };
1383
+ }
1384
+ const stopPrice = this.safeNumber(order, 'stopPrice');
1385
+ let reduceOnly = undefined;
1386
+ const execInst = this.safeString(order, 'execInst');
1387
+ if (execInst === 'reduceOnly') {
1388
+ reduceOnly = true;
1389
+ }
1390
+ let postOnly = undefined;
1391
+ if (execInst === 'Post') {
1392
+ postOnly = true;
1393
+ }
1394
+ return this.safeOrder({
1395
+ 'info': order,
1396
+ 'id': id,
1397
+ 'clientOrderId': clientOrderId,
1398
+ 'timestamp': timestamp,
1399
+ 'datetime': this.iso8601(timestamp),
1400
+ 'lastTradeTimestamp': lastTradeTimestamp,
1401
+ 'symbol': symbol,
1402
+ 'type': type,
1403
+ 'timeInForce': undefined,
1404
+ 'postOnly': postOnly,
1405
+ 'reduceOnly': reduceOnly,
1406
+ 'side': side,
1407
+ 'price': price,
1408
+ 'stopPrice': stopPrice,
1409
+ 'triggerPrice': stopPrice,
1410
+ 'amount': amount,
1411
+ 'cost': undefined,
1412
+ 'average': average,
1413
+ 'filled': filled,
1414
+ 'remaining': undefined,
1415
+ 'status': status,
1416
+ 'fee': fee,
1417
+ 'trades': undefined,
1418
+ }, market);
1419
+ }
1420
+ async fetchTradingFees(params = {}) {
1421
+ /**
1422
+ * @method
1423
+ * @name ascendex#fetchTradingFees
1424
+ * @description fetch the trading fees for multiple markets
1425
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1426
+ * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
1427
+ */
1428
+ await this.loadMarkets();
1429
+ await this.loadAccounts();
1430
+ const account = this.safeValue(this.accounts, 0, {});
1431
+ const accountGroup = this.safeString(account, 'id');
1432
+ const request = {
1433
+ 'account-group': accountGroup,
1434
+ };
1435
+ const response = await this.v1PrivateAccountGroupGetSpotFee(this.extend(request, params));
1436
+ //
1437
+ // {
1438
+ // "code": "0",
1439
+ // "data": {
1440
+ // "domain": "spot",
1441
+ // "userUID": "U1479576458",
1442
+ // "vipLevel": "0",
1443
+ // "fees": [
1444
+ // { symbol: 'HT/USDT', fee: { taker: '0.001', maker: "0.001" } },
1445
+ // { symbol: 'LAMB/BTC', fee: { taker: '0.002', maker: "0.002" } },
1446
+ // { symbol: 'STOS/USDT', fee: { taker: '0.002', maker: "0.002" } },
1447
+ // ...
1448
+ // ]
1449
+ // }
1450
+ // }
1451
+ //
1452
+ const data = this.safeValue(response, 'data', {});
1453
+ const fees = this.safeValue(data, 'fees', []);
1454
+ const result = {};
1455
+ for (let i = 0; i < fees.length; i++) {
1456
+ const fee = fees[i];
1457
+ const marketId = this.safeString(fee, 'symbol');
1458
+ const symbol = this.safeSymbol(marketId, undefined, '/');
1459
+ const takerMaker = this.safeValue(fee, 'fee', {});
1460
+ result[symbol] = {
1461
+ 'info': fee,
1462
+ 'symbol': symbol,
1463
+ 'maker': this.safeNumber(takerMaker, 'maker'),
1464
+ 'taker': this.safeNumber(takerMaker, 'taker'),
1465
+ };
1466
+ }
1467
+ return result;
1468
+ }
1469
+ createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1470
+ /**
1471
+ * @method
1472
+ * @ignore
1473
+ * @name ascendex#createOrderRequest
1474
+ * @description helper function to build request
1475
+ * @param {string} symbol unified symbol of the market to create an order in
1476
+ * @param {string} type 'market' or 'limit'
1477
+ * @param {string} side 'buy' or 'sell'
1478
+ * @param {float} amount how much you want to trade in units of the base currency
1479
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1480
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1481
+ * @param {string} [params.timeInForce] "GTC", "IOC", "FOK", or "PO"
1482
+ * @param {bool} [params.postOnly] true or false
1483
+ * @param {float} [params.stopPrice] the price at which a trigger order is triggered at
1484
+ * @returns {object} request to be sent to the exchange
1485
+ */
1486
+ const market = this.market(symbol);
1487
+ let marginMode = undefined;
1488
+ let marketType = undefined;
1489
+ [marginMode, params] = this.handleMarginModeAndParams('createOrderRequest', params);
1490
+ [marketType, params] = this.handleMarketTypeAndParams('createOrderRequest', market, params);
1491
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
1492
+ let accountCategory = this.safeString(accountsByType, marketType, 'cash');
1493
+ if (marginMode !== undefined) {
1494
+ accountCategory = 'margin';
1495
+ }
1496
+ const account = this.safeValue(this.accounts, 0, {});
1497
+ const accountGroup = this.safeValue(account, 'id');
1498
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'id');
1499
+ const request = {
1500
+ 'account-group': accountGroup,
1501
+ 'account-category': accountCategory,
1502
+ 'symbol': market['id'],
1503
+ 'time': this.milliseconds(),
1504
+ 'orderQty': this.amountToPrecision(symbol, amount),
1505
+ 'orderType': type,
1506
+ 'side': side, // buy or sell,
1507
+ // 'execInst': // Post for postOnly, ReduceOnly for reduceOnly
1508
+ // 'respInst': 'ACK', // ACK, 'ACCEPT, DONE
1509
+ };
1510
+ const isMarketOrder = ((type === 'market') || (type === 'stop_market'));
1511
+ const isLimitOrder = ((type === 'limit') || (type === 'stop_limit'));
1512
+ const timeInForce = this.safeString(params, 'timeInForce');
1513
+ const postOnly = this.isPostOnly(isMarketOrder, false, params);
1514
+ const reduceOnly = this.safeValue(params, 'reduceOnly', false);
1515
+ const stopPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
1516
+ if (isLimitOrder) {
1517
+ request['orderPrice'] = this.priceToPrecision(symbol, price);
1518
+ }
1519
+ if (timeInForce === 'IOC') {
1520
+ request['timeInForce'] = 'IOC';
1521
+ }
1522
+ if (timeInForce === 'FOK') {
1523
+ request['timeInForce'] = 'FOK';
1524
+ }
1525
+ if (postOnly) {
1526
+ request['postOnly'] = true;
1527
+ }
1528
+ if (stopPrice !== undefined) {
1529
+ request['stopPrice'] = this.priceToPrecision(symbol, stopPrice);
1530
+ if (isLimitOrder) {
1531
+ request['orderType'] = 'stop_limit';
1532
+ }
1533
+ else if (isMarketOrder) {
1534
+ request['orderType'] = 'stop_market';
1535
+ }
1536
+ }
1537
+ if (clientOrderId !== undefined) {
1538
+ request['id'] = clientOrderId;
1539
+ }
1540
+ if (market['spot']) {
1541
+ if (accountCategory !== undefined) {
1542
+ request['category'] = accountCategory;
1543
+ }
1544
+ }
1545
+ else {
1546
+ request['account-category'] = accountCategory;
1547
+ if (reduceOnly) {
1548
+ request['execInst'] = 'ReduceOnly';
1549
+ }
1550
+ if (postOnly) {
1551
+ request['execInst'] = 'Post';
1552
+ }
1553
+ }
1554
+ params = this.omit(params, ['reduceOnly', 'triggerPrice']);
1555
+ return this.extend(request, params);
1556
+ }
1557
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1558
+ /**
1559
+ * @method
1560
+ * @name ascendex#createOrder
1561
+ * @description create a trade order on the exchange
1562
+ * @see https://ascendex.github.io/ascendex-pro-api/#place-order
1563
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#new-order
1564
+ * @param {string} symbol unified CCXT market symbol
1565
+ * @param {string} type "limit" or "market"
1566
+ * @param {string} side "buy" or "sell"
1567
+ * @param {float} amount the amount of currency to trade
1568
+ * @param {float} [price] *ignored in "market" orders* the price at which the order is to be fullfilled at in units of the quote currency
1569
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1570
+ * @param {string} [params.timeInForce] "GTC", "IOC", "FOK", or "PO"
1571
+ * @param {bool} [params.postOnly] true or false
1572
+ * @param {float} [params.stopPrice] the price at which a trigger order is triggered at
1573
+ * @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice that the attached take profit order will be triggered (perpetual swap markets only)
1574
+ * @param {float} [params.takeProfit.triggerPrice] *swap only* take profit trigger price
1575
+ * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice that the attached stop loss order will be triggered (perpetual swap markets only)
1576
+ * @param {float} [params.stopLoss.triggerPrice] *swap only* stop loss trigger price
1577
+ * @returns [An order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1578
+ */
1579
+ await this.loadMarkets();
1580
+ await this.loadAccounts();
1581
+ const market = this.market(symbol);
1582
+ const request = this.createOrderRequest(symbol, type, side, amount, price, params);
1583
+ let response = undefined;
1584
+ if (market['swap']) {
1585
+ response = await this.v2PrivateAccountGroupPostFuturesOrder(request);
1586
+ }
1587
+ else {
1588
+ response = await this.v1PrivateAccountCategoryPostOrder(request);
1589
+ }
1590
+ //
1591
+ // spot
1592
+ //
1593
+ // {
1594
+ // "code":0,
1595
+ // "data": {
1596
+ // "accountId":"cshwT8RKojkT1HoaA5UdeimR2SrmHG2I",
1597
+ // "ac":"CASH",
1598
+ // "action":"place-order",
1599
+ // "status":"Ack",
1600
+ // "info": {
1601
+ // "symbol":"TRX/USDT",
1602
+ // "orderType":"StopLimit",
1603
+ // "timestamp":1654290662172,
1604
+ // "id":"",
1605
+ // "orderId":"a1812b6840ddU8191168955av0k6Eyhj"
1606
+ // }
1607
+ // }
1608
+ // }
1609
+ //
1610
+ // swap
1611
+ //
1612
+ // {
1613
+ // "code":0,
1614
+ // "data": {
1615
+ // "meta": {
1616
+ // "id":"",
1617
+ // "action":"place-order",
1618
+ // "respInst":"ACK"
1619
+ // },
1620
+ // "order": {
1621
+ // "ac":"FUTURES",
1622
+ // "accountId":"futwT8RKojkT1HoaA5UdeimR2SrmHG2I",
1623
+ // "time":1654290969965,
1624
+ // "orderId":"a1812b6cf322U8191168955oJamfTh7b",
1625
+ // "seqNum":-1,
1626
+ // "orderType":"StopLimit",
1627
+ // "execInst":"NULL_VAL",
1628
+ // "side":"Buy",
1629
+ // "symbol":"TRX-PERP",
1630
+ // "price":"0.083",
1631
+ // "orderQty":"1",
1632
+ // "stopPrice":"0.082",
1633
+ // "stopBy":"ref-px",
1634
+ // "status":"Ack",
1635
+ // "lastExecTime":1654290969965,
1636
+ // "lastQty":"0",
1637
+ // "lastPx":"0",
1638
+ // "avgFilledPx":"0",
1639
+ // "cumFilledQty":"0",
1640
+ // "fee":"0",
1641
+ // "cumFee":"0",
1642
+ // "feeAsset":"",
1643
+ // "errorCode":"",
1644
+ // "posStopLossPrice":"0",
1645
+ // "posStopLossTrigger":"market",
1646
+ // "posTakeProfitPrice":"0",
1647
+ // "posTakeProfitTrigger":"market",
1648
+ // "liquidityInd":"n"
1649
+ // }
1650
+ // }
1651
+ // }
1652
+ //
1653
+ const data = this.safeValue(response, 'data', {});
1654
+ const order = this.safeValue2(data, 'order', 'info', {});
1655
+ return this.parseOrder(order, market);
1656
+ }
1657
+ async createOrders(orders, params = {}) {
1658
+ /**
1659
+ * @method
1660
+ * @name ascendex#createOrders
1661
+ * @description create a list of trade orders
1662
+ * @see https://ascendex.github.io/ascendex-pro-api/#place-batch-orders
1663
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#place-batch-orders
1664
+ * @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
1665
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1666
+ * @param {string} [params.timeInForce] "GTC", "IOC", "FOK", or "PO"
1667
+ * @param {bool} [params.postOnly] true or false
1668
+ * @param {float} [params.stopPrice] the price at which a trigger order is triggered at
1669
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1670
+ */
1671
+ await this.loadMarkets();
1672
+ await this.loadAccounts();
1673
+ const ordersRequests = [];
1674
+ let symbol = undefined;
1675
+ let marginMode = undefined;
1676
+ for (let i = 0; i < orders.length; i++) {
1677
+ const rawOrder = orders[i];
1678
+ const marketId = this.safeString(rawOrder, 'symbol');
1679
+ if (symbol === undefined) {
1680
+ symbol = marketId;
1681
+ }
1682
+ else {
1683
+ if (symbol !== marketId) {
1684
+ throw new errors.BadRequest(this.id + ' createOrders() requires all orders to have the same symbol');
1685
+ }
1686
+ }
1687
+ const type = this.safeString(rawOrder, 'type');
1688
+ const side = this.safeString(rawOrder, 'side');
1689
+ const amount = this.safeValue(rawOrder, 'amount');
1690
+ const price = this.safeValue(rawOrder, 'price');
1691
+ const orderParams = this.safeValue(rawOrder, 'params', {});
1692
+ const marginResult = this.handleMarginModeAndParams('createOrders', orderParams);
1693
+ const currentMarginMode = marginResult[0];
1694
+ if (currentMarginMode !== undefined) {
1695
+ if (marginMode === undefined) {
1696
+ marginMode = currentMarginMode;
1697
+ }
1698
+ else {
1699
+ if (marginMode !== currentMarginMode) {
1700
+ throw new errors.BadRequest(this.id + ' createOrders() requires all orders to have the same margin mode (isolated or cross)');
1701
+ }
1702
+ }
1703
+ }
1704
+ const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
1705
+ ordersRequests.push(orderRequest);
1706
+ }
1707
+ const market = this.market(symbol);
1708
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
1709
+ let accountCategory = this.safeString(accountsByType, market['type'], 'cash');
1710
+ if (marginMode !== undefined) {
1711
+ accountCategory = 'margin';
1712
+ }
1713
+ const account = this.safeValue(this.accounts, 0, {});
1714
+ const accountGroup = this.safeValue(account, 'id');
1715
+ const request = {};
1716
+ let response = undefined;
1717
+ if (market['swap']) {
1718
+ throw new errors.NotSupported(this.id + ' createOrders() is not currently supported for swap markets on ascendex');
1719
+ // request['account-group'] = accountGroup;
1720
+ // request['category'] = accountCategory;
1721
+ // request['orders'] = ordersRequests;
1722
+ // response = await this.v2PrivateAccountGroupPostFuturesOrderBatch (request);
1723
+ }
1724
+ else {
1725
+ request['account-group'] = accountGroup;
1726
+ request['account-category'] = accountCategory;
1727
+ request['orders'] = ordersRequests;
1728
+ response = await this.v1PrivateAccountCategoryPostOrderBatch(request);
1729
+ }
1730
+ //
1731
+ // spot
1732
+ //
1733
+ // {
1734
+ // "code": 0,
1735
+ // "data": {
1736
+ // "accountId": "cshdAKBO43TKIh2kJtq7FVVb42KIePyS",
1737
+ // "ac": "CASH",
1738
+ // "action": "batch-place-order",
1739
+ // "status": "Ack",
1740
+ // "info": [
1741
+ // {
1742
+ // "symbol": "BTC/USDT",
1743
+ // "orderType": "Limit",
1744
+ // "timestamp": 1699326589344,
1745
+ // "id": "",
1746
+ // "orderId": "a18ba7c1f6efU0711043490p3HvjjN5x"
1747
+ // }
1748
+ // ]
1749
+ // }
1750
+ // }
1751
+ //
1752
+ const data = this.safeValue(response, 'data', {});
1753
+ const info = this.safeValue(data, 'info', []);
1754
+ return this.parseOrders(info, market);
1755
+ }
1756
+ async fetchOrder(id, symbol = undefined, params = {}) {
1757
+ /**
1758
+ * @method
1759
+ * @name ascendex#fetchOrder
1760
+ * @description fetches information on an order made by the user
1761
+ * @see https://ascendex.github.io/ascendex-pro-api/#query-order
1762
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#query-order-by-id
1763
+ * @param {string} symbol unified symbol of the market the order was made in
1764
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1765
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1766
+ */
1767
+ await this.loadMarkets();
1768
+ await this.loadAccounts();
1769
+ let market = undefined;
1770
+ if (symbol !== undefined) {
1771
+ market = this.market(symbol);
1772
+ }
1773
+ const [type, query] = this.handleMarketTypeAndParams('fetchOrder', market, params);
1774
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
1775
+ const accountCategory = this.safeString(accountsByType, type, 'cash');
1776
+ const account = this.safeValue(this.accounts, 0, {});
1777
+ const accountGroup = this.safeValue(account, 'id');
1778
+ const request = {
1779
+ 'account-group': accountGroup,
1780
+ 'account-category': accountCategory,
1781
+ 'orderId': id,
1782
+ };
1783
+ let response = undefined;
1784
+ if ((type === 'spot') || (type === 'margin')) {
1785
+ response = await this.v1PrivateAccountCategoryGetOrderStatus(this.extend(request, query));
1786
+ }
1787
+ else if (type === 'swap') {
1788
+ request['account-category'] = accountCategory;
1789
+ response = await this.v2PrivateAccountGroupGetFuturesOrderStatus(this.extend(request, query));
1790
+ }
1791
+ else {
1792
+ throw new errors.NotSupported(this.id + ' fetchOrder() is not currently supported for ' + type + ' markets');
1793
+ }
1794
+ //
1795
+ // AccountCategoryGetOrderStatus
1796
+ //
1797
+ // {
1798
+ // "code": 0,
1799
+ // "accountCategory": "CASH",
1800
+ // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo",
1801
+ // "data": [
1802
+ // {
1803
+ // "symbol": "BTC/USDT",
1804
+ // "price": "8131.22",
1805
+ // "orderQty": "0.00082",
1806
+ // "orderType": "Market",
1807
+ // "avgPx": "7392.02",
1808
+ // "cumFee": "0.005152238",
1809
+ // "cumFilledQty": "0.00082",
1810
+ // "errorCode": "",
1811
+ // "feeAsset": "USDT",
1812
+ // "lastExecTime": 1575953151764,
1813
+ // "orderId": "a16eee20b6750866943712zWEDdAjt3",
1814
+ // "seqNum": 2623469,
1815
+ // "side": "Buy",
1816
+ // "status": "Filled",
1817
+ // "stopPrice": "",
1818
+ // "execInst": "NULL_VAL"
1819
+ // }
1820
+ // ]
1821
+ // }
1822
+ //
1823
+ // AccountGroupGetFuturesOrderStatus
1824
+ //
1825
+ // {
1826
+ // "code": 0,
1827
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
1828
+ // "ac": "FUTURES",
1829
+ // "data": {
1830
+ // "ac": "FUTURES",
1831
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
1832
+ // "time": 1640247020217,
1833
+ // "orderId": "r17de65747aeU0711043490bbtcp0cmt",
1834
+ // "seqNum": 28796162908,
1835
+ // "orderType": "Limit",
1836
+ // "execInst": "NULL_VAL",
1837
+ // "side": "Buy",
1838
+ // "symbol": "BTC-PERP",
1839
+ // "price": "30000",
1840
+ // "orderQty": "0.0021",
1841
+ // "stopPrice": "0",
1842
+ // "stopBy": "market",
1843
+ // "status": "New",
1844
+ // "lastExecTime": 1640247020232,
1845
+ // "lastQty": "0",
1846
+ // "lastPx": "0",
1847
+ // "avgFilledPx": "0",
1848
+ // "cumFilledQty": "0",
1849
+ // "fee": "0",
1850
+ // "cumFee": "0",
1851
+ // "feeAsset": "USDT",
1852
+ // "errorCode": "",
1853
+ // "posStopLossPrice": "0",
1854
+ // "posStopLossTrigger": "market",
1855
+ // "posTakeProfitPrice": "0",
1856
+ // "posTakeProfitTrigger": "market",
1857
+ // "liquidityInd": "n"
1858
+ // }
1859
+ // }
1860
+ //
1861
+ const data = this.safeValue(response, 'data', {});
1862
+ return this.parseOrder(data, market);
1863
+ }
1864
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1865
+ /**
1866
+ * @method
1867
+ * @name ascendex#fetchOpenOrders
1868
+ * @description fetch all unfilled currently open orders
1869
+ * @see https://ascendex.github.io/ascendex-pro-api/#list-open-orders
1870
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#list-open-orders
1871
+ * @param {string} symbol unified market symbol
1872
+ * @param {int} [since] the earliest time in ms to fetch open orders for
1873
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
1874
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1875
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1876
+ */
1877
+ await this.loadMarkets();
1878
+ await this.loadAccounts();
1879
+ let market = undefined;
1880
+ if (symbol !== undefined) {
1881
+ market = this.market(symbol);
1882
+ symbol = market['symbol'];
1883
+ }
1884
+ const account = this.safeValue(this.accounts, 0, {});
1885
+ const accountGroup = this.safeValue(account, 'id');
1886
+ const [type, query] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
1887
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
1888
+ const accountCategory = this.safeString(accountsByType, type, 'cash');
1889
+ const request = {
1890
+ 'account-group': accountGroup,
1891
+ 'account-category': accountCategory,
1892
+ };
1893
+ let response = undefined;
1894
+ if ((type === 'spot') || (type === 'margin')) {
1895
+ response = await this.v1PrivateAccountCategoryGetOrderOpen(this.extend(request, query));
1896
+ }
1897
+ else if (type === 'swap') {
1898
+ request['account-category'] = accountCategory;
1899
+ response = await this.v2PrivateAccountGroupGetFuturesOrderOpen(this.extend(request, query));
1900
+ }
1901
+ else {
1902
+ throw new errors.NotSupported(this.id + ' fetchOpenOrders() is not currently supported for ' + type + ' markets');
1903
+ }
1904
+ //
1905
+ // AccountCategoryGetOrderOpen
1906
+ //
1907
+ // {
1908
+ // "ac": "CASH",
1909
+ // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo",
1910
+ // "code": 0,
1911
+ // "data": [
1912
+ // {
1913
+ // "avgPx": "0", // Average filled price of the order
1914
+ // "cumFee": "0", // cumulative fee paid for this order
1915
+ // "cumFilledQty": "0", // cumulative filled quantity
1916
+ // "errorCode": "", // error code; could be empty
1917
+ // "feeAsset": "USDT", // fee asset
1918
+ // "lastExecTime": 1576019723550, // The last execution time of the order
1919
+ // "orderId": "s16ef21882ea0866943712034f36d83", // server provided orderId
1920
+ // "orderQty": "0.0083", // order quantity
1921
+ // "orderType": "Limit", // order type
1922
+ // "price": "7105", // order price
1923
+ // "seqNum": 8193258, // sequence number
1924
+ // "side": "Buy", // order side
1925
+ // "status": "New", // order status on matching engine
1926
+ // "stopPrice": "", // only available for stop market and stop limit orders; otherwise empty
1927
+ // "symbol": "BTC/USDT",
1928
+ // "execInst": "NULL_VAL" // execution instruction
1929
+ // },
1930
+ // ]
1931
+ // }
1932
+ //
1933
+ // AccountGroupGetFuturesOrderOpen
1934
+ //
1935
+ // {
1936
+ // "code": 0,
1937
+ // "data": [
1938
+ // {
1939
+ // "ac": "FUTURES",
1940
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
1941
+ // "time": 1640247020217,
1942
+ // "orderId": "r17de65747aeU0711043490bbtcp0cmt",
1943
+ // "seqNum": 28796162908,
1944
+ // "orderType": "Limit",
1945
+ // "execInst": "NULL_VAL",
1946
+ // "side": "Buy",
1947
+ // "symbol": "BTC-PERP",
1948
+ // "price": "30000",
1949
+ // "orderQty": "0.0021",
1950
+ // "stopPrice": "0",
1951
+ // "stopBy": "market",
1952
+ // "status": "New",
1953
+ // "lastExecTime": 1640247020232,
1954
+ // "lastQty": "0",
1955
+ // "lastPx": "0",
1956
+ // "avgFilledPx": "0",
1957
+ // "cumFilledQty": "0",
1958
+ // "fee": "0",
1959
+ // "cumFee": "0",
1960
+ // "feeAsset": "USDT",
1961
+ // "errorCode": "",
1962
+ // "posStopLossPrice": "0",
1963
+ // "posStopLossTrigger": "market",
1964
+ // "posTakeProfitPrice": "0",
1965
+ // "posTakeProfitTrigger": "market",
1966
+ // "liquidityInd": "n"
1967
+ // }
1968
+ // ]
1969
+ // }
1970
+ //
1971
+ const data = this.safeValue(response, 'data', []);
1972
+ if (accountCategory === 'futures') {
1973
+ return this.parseOrders(data, market, since, limit);
1974
+ }
1975
+ // a workaround for https://github.com/ccxt/ccxt/issues/7187
1976
+ const orders = [];
1977
+ for (let i = 0; i < data.length; i++) {
1978
+ const order = this.parseOrder(data[i], market);
1979
+ orders.push(order);
1980
+ }
1981
+ return this.filterBySymbolSinceLimit(orders, symbol, since, limit);
1982
+ }
1983
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1984
+ /**
1985
+ * @method
1986
+ * @name ascendex#fetchClosedOrders
1987
+ * @description fetches information on multiple closed orders made by the user
1988
+ * @see https://ascendex.github.io/ascendex-pro-api/#list-history-orders-v2
1989
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#list-current-history-orders
1990
+ * @param {string} symbol unified market symbol of the market orders were made in
1991
+ * @param {int} [since] the earliest time in ms to fetch orders for
1992
+ * @param {int} [limit] the maximum number of order structures to retrieve
1993
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1994
+ * @param {int} [params.until] the latest time in ms to fetch orders for
1995
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1996
+ */
1997
+ await this.loadMarkets();
1998
+ await this.loadAccounts();
1999
+ const account = this.safeValue(this.accounts, 0, {});
2000
+ const accountGroup = this.safeValue(account, 'id');
2001
+ const request = {
2002
+ // 'category': accountCategory,
2003
+ // 'symbol': market['id'],
2004
+ // 'orderType': 'market', // optional, string
2005
+ // 'side': 'buy', // or 'sell', optional, case insensitive.
2006
+ // 'status': 'Filled', // "Filled", "Canceled", or "Rejected"
2007
+ // 'startTime': exchange.milliseconds (),
2008
+ // 'endTime': exchange.milliseconds (),
2009
+ // 'page': 1,
2010
+ // 'pageSize': 100,
2011
+ };
2012
+ let market = undefined;
2013
+ if (symbol !== undefined) {
2014
+ market = this.market(symbol);
2015
+ request['symbol'] = market['id'];
2016
+ }
2017
+ const [type, query] = this.handleMarketTypeAndParams('fetchClosedOrders', market, params);
2018
+ const options = this.safeValue(this.options, 'fetchClosedOrders', {});
2019
+ const defaultMethod = this.safeString(options, 'method', 'v2PrivateDataGetOrderHist');
2020
+ const method = this.getSupportedMapping(type, {
2021
+ 'spot': defaultMethod,
2022
+ 'margin': defaultMethod,
2023
+ 'swap': 'v2PrivateAccountGroupGetFuturesOrderHistCurrent',
2024
+ });
2025
+ if (since !== undefined) {
2026
+ request['startTime'] = since;
2027
+ }
2028
+ const until = this.safeString(params, 'until');
2029
+ if (until !== undefined) {
2030
+ request['endTime'] = until;
2031
+ }
2032
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
2033
+ const accountCategory = this.safeString(accountsByType, type, 'cash'); // margin, futures
2034
+ let response = undefined;
2035
+ if (method === 'v1PrivateAccountCategoryGetOrderHistCurrent') {
2036
+ request['account-group'] = accountGroup;
2037
+ request['account-category'] = accountCategory;
2038
+ if (limit !== undefined) {
2039
+ request['limit'] = limit;
2040
+ }
2041
+ response = await this.v1PrivateAccountCategoryGetOrderHistCurrent(this.extend(request, query));
2042
+ }
2043
+ else if (method === 'v2PrivateDataGetOrderHist') {
2044
+ request['account'] = accountCategory;
2045
+ if (limit !== undefined) {
2046
+ request['limit'] = limit;
2047
+ }
2048
+ response = await this.v2PrivateDataGetOrderHist(this.extend(request, query));
2049
+ }
2050
+ else if (method === 'v2PrivateAccountGroupGetFuturesOrderHistCurrent') {
2051
+ request['account-group'] = accountGroup;
2052
+ request['account-category'] = accountCategory;
2053
+ if (limit !== undefined) {
2054
+ request['pageSize'] = limit;
2055
+ }
2056
+ response = await this.v2PrivateAccountGroupGetFuturesOrderHistCurrent(this.extend(request, query));
2057
+ }
2058
+ else {
2059
+ throw new errors.NotSupported(this.id + ' fetchClosedOrders() is not currently supported for ' + type + ' markets');
2060
+ }
2061
+ //
2062
+ // accountCategoryGetOrderHistCurrent
2063
+ //
2064
+ // {
2065
+ // "code":0,
2066
+ // "accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda",
2067
+ // "ac":"CASH",
2068
+ // "data":[
2069
+ // {
2070
+ // "seqNum":15561826728,
2071
+ // "orderId":"a17294d305c0U6491137460bethu7kw9",
2072
+ // "symbol":"ETH/USDT",
2073
+ // "orderType":"Limit",
2074
+ // "lastExecTime":1591635618200,
2075
+ // "price":"200",
2076
+ // "orderQty":"0.1",
2077
+ // "side":"Buy",
2078
+ // "status":"Canceled",
2079
+ // "avgPx":"0",
2080
+ // "cumFilledQty":"0",
2081
+ // "stopPrice":"",
2082
+ // "errorCode":"",
2083
+ // "cumFee":"0",
2084
+ // "feeAsset":"USDT",
2085
+ // "execInst":"NULL_VAL"
2086
+ // }
2087
+ // ]
2088
+ // }
2089
+ //
2090
+ // {
2091
+ // "code": 0,
2092
+ // "data": [
2093
+ // {
2094
+ // "orderId" : "a173ad938fc3U22666567717788c3b66", // orderId
2095
+ // "seqNum" : 18777366360, // sequence number
2096
+ // "accountId" : "cshwSjbpPjSwHmxPdz2CPQVU9mnbzPpt", // accountId
2097
+ // "symbol" : "BTC/USDT", // symbol
2098
+ // "orderType" : "Limit", // order type (Limit/Market/StopMarket/StopLimit)
2099
+ // "side" : "Sell", // order side (Buy/Sell)
2100
+ // "price" : "11346.77", // order price
2101
+ // "stopPrice" : "0", // stop price (0 by default)
2102
+ // "orderQty" : "0.01", // order quantity (in base asset)
2103
+ // "status" : "Canceled", // order status (Filled/Canceled/Rejected)
2104
+ // "createTime" : 1596344995793, // order creation time
2105
+ // "lastExecTime": 1596344996053, // last execution time
2106
+ // "avgFillPrice": "11346.77", // average filled price
2107
+ // "fillQty" : "0.01", // filled quantity (in base asset)
2108
+ // "fee" : "-0.004992579", // cummulative fee. if negative, this value is the commission charged; if possitive, this value is the rebate received.
2109
+ // "feeAsset" : "USDT" // fee asset
2110
+ // }
2111
+ // ]
2112
+ // }
2113
+ //
2114
+ // accountGroupGetFuturesOrderHistCurrent
2115
+ //
2116
+ // {
2117
+ // "code": 0,
2118
+ // "data": [
2119
+ // {
2120
+ // "ac": "FUTURES",
2121
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
2122
+ // "time": 1640245777002,
2123
+ // "orderId": "r17de6444fa6U0711043490bbtcpJ2lI",
2124
+ // "seqNum": 28796124902,
2125
+ // "orderType": "Limit",
2126
+ // "execInst": "NULL_VAL",
2127
+ // "side": "Buy",
2128
+ // "symbol": "BTC-PERP",
2129
+ // "price": "30000",
2130
+ // "orderQty": "0.0021",
2131
+ // "stopPrice": "0",
2132
+ // "stopBy": "market",
2133
+ // "status": "Canceled",
2134
+ // "lastExecTime": 1640246574886,
2135
+ // "lastQty": "0",
2136
+ // "lastPx": "0",
2137
+ // "avgFilledPx": "0",
2138
+ // "cumFilledQty": "0",
2139
+ // "fee": "0",
2140
+ // "cumFee": "0",
2141
+ // "feeAsset": "USDT",
2142
+ // "errorCode": "",
2143
+ // "posStopLossPrice": "0",
2144
+ // "posStopLossTrigger": "market",
2145
+ // "posTakeProfitPrice": "0",
2146
+ // "posTakeProfitTrigger": "market",
2147
+ // "liquidityInd": "n"
2148
+ // }
2149
+ // ]
2150
+ // }
2151
+ //
2152
+ let data = this.safeValue(response, 'data');
2153
+ const isArray = Array.isArray(data);
2154
+ if (!isArray) {
2155
+ data = this.safeValue(data, 'data', []);
2156
+ }
2157
+ return this.parseOrders(data, market, since, limit);
2158
+ }
2159
+ async cancelOrder(id, symbol = undefined, params = {}) {
2160
+ /**
2161
+ * @method
2162
+ * @name ascendex#cancelOrder
2163
+ * @description cancels an open order
2164
+ * @see https://ascendex.github.io/ascendex-pro-api/#cancel-order
2165
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#cancel-order
2166
+ * @param {string} id order id
2167
+ * @param {string} symbol unified symbol of the market the order was made in
2168
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2169
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2170
+ */
2171
+ if (symbol === undefined) {
2172
+ throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
2173
+ }
2174
+ await this.loadMarkets();
2175
+ await this.loadAccounts();
2176
+ const market = this.market(symbol);
2177
+ const [type, query] = this.handleMarketTypeAndParams('cancelOrder', market, params);
2178
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
2179
+ const accountCategory = this.safeString(accountsByType, type, 'cash');
2180
+ const account = this.safeValue(this.accounts, 0, {});
2181
+ const accountGroup = this.safeValue(account, 'id');
2182
+ const request = {
2183
+ 'account-group': accountGroup,
2184
+ 'account-category': accountCategory,
2185
+ 'symbol': market['id'],
2186
+ 'time': this.milliseconds(),
2187
+ 'id': 'foobar',
2188
+ };
2189
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'id');
2190
+ if (clientOrderId === undefined) {
2191
+ request['orderId'] = id;
2192
+ }
2193
+ else {
2194
+ request['id'] = clientOrderId;
2195
+ params = this.omit(params, ['clientOrderId', 'id']);
2196
+ }
2197
+ let response = undefined;
2198
+ if ((type === 'spot') || (type === 'margin')) {
2199
+ response = await this.v1PrivateAccountCategoryDeleteOrder(this.extend(request, query));
2200
+ }
2201
+ else if (type === 'swap') {
2202
+ request['account-category'] = accountCategory;
2203
+ response = await this.v2PrivateAccountGroupDeleteFuturesOrder(this.extend(request, query));
2204
+ }
2205
+ else {
2206
+ throw new errors.NotSupported(this.id + ' cancelOrder() is not currently supported for ' + type + ' markets');
2207
+ }
2208
+ //
2209
+ // AccountCategoryDeleteOrder
2210
+ //
2211
+ // {
2212
+ // "code": 0,
2213
+ // "data": {
2214
+ // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo",
2215
+ // "ac": "CASH",
2216
+ // "action": "cancel-order",
2217
+ // "status": "Ack",
2218
+ // "info": {
2219
+ // "id": "wv8QGquoeamhssvQBeHOHGQCGlcBjj23",
2220
+ // "orderId": "16e6198afb4s8bXHbAwwoqDo2ebc19dc",
2221
+ // "orderType": "", // could be empty
2222
+ // "symbol": "ETH/USDT",
2223
+ // "timestamp": 1573594877822
2224
+ // }
2225
+ // }
2226
+ // }
2227
+ //
2228
+ // AccountGroupDeleteFuturesOrder
2229
+ //
2230
+ // {
2231
+ // "code": 0,
2232
+ // "data": {
2233
+ // "meta": {
2234
+ // "id": "foobar",
2235
+ // "action": "cancel-order",
2236
+ // "respInst": "ACK"
2237
+ // },
2238
+ // "order": {
2239
+ // "ac": "FUTURES",
2240
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
2241
+ // "time": 1640244480476,
2242
+ // "orderId": "r17de63086f4U0711043490bbtcpPUF4",
2243
+ // "seqNum": 28795959269,
2244
+ // "orderType": "Limit",
2245
+ // "execInst": "NULL_VAL",
2246
+ // "side": "Buy",
2247
+ // "symbol": "BTC-PERP",
2248
+ // "price": "30000",
2249
+ // "orderQty": "0.0021",
2250
+ // "stopPrice": "0",
2251
+ // "stopBy": "market",
2252
+ // "status": "New",
2253
+ // "lastExecTime": 1640244480491,
2254
+ // "lastQty": "0",
2255
+ // "lastPx": "0",
2256
+ // "avgFilledPx": "0",
2257
+ // "cumFilledQty": "0",
2258
+ // "fee": "0",
2259
+ // "cumFee": "0",
2260
+ // "feeAsset": "BTCPC",
2261
+ // "errorCode": "",
2262
+ // "posStopLossPrice": "0",
2263
+ // "posStopLossTrigger": "market",
2264
+ // "posTakeProfitPrice": "0",
2265
+ // "posTakeProfitTrigger": "market",
2266
+ // "liquidityInd": "n"
2267
+ // }
2268
+ // }
2269
+ // }
2270
+ //
2271
+ const data = this.safeValue(response, 'data', {});
2272
+ const order = this.safeValue2(data, 'order', 'info', {});
2273
+ return this.parseOrder(order, market);
2274
+ }
2275
+ async cancelAllOrders(symbol = undefined, params = {}) {
2276
+ /**
2277
+ * @method
2278
+ * @name ascendex#cancelAllOrders
2279
+ * @description cancel all open orders
2280
+ * @see https://ascendex.github.io/ascendex-pro-api/#cancel-all-orders
2281
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#cancel-all-open-orders
2282
+ * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
2283
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2284
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2285
+ */
2286
+ await this.loadMarkets();
2287
+ await this.loadAccounts();
2288
+ let market = undefined;
2289
+ if (symbol !== undefined) {
2290
+ market = this.market(symbol);
2291
+ }
2292
+ const [type, query] = this.handleMarketTypeAndParams('cancelAllOrders', market, params);
2293
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
2294
+ const accountCategory = this.safeString(accountsByType, type, 'cash');
2295
+ const account = this.safeValue(this.accounts, 0, {});
2296
+ const accountGroup = this.safeValue(account, 'id');
2297
+ const request = {
2298
+ 'account-group': accountGroup,
2299
+ 'account-category': accountCategory,
2300
+ 'time': this.milliseconds(),
2301
+ };
2302
+ if (symbol !== undefined) {
2303
+ request['symbol'] = market['id'];
2304
+ }
2305
+ let response = undefined;
2306
+ if ((type === 'spot') || (type === 'margin')) {
2307
+ response = await this.v1PrivateAccountCategoryDeleteOrderAll(this.extend(request, query));
2308
+ }
2309
+ else if (type === 'swap') {
2310
+ request['account-category'] = accountCategory;
2311
+ response = await this.v2PrivateAccountGroupDeleteFuturesOrderAll(this.extend(request, query));
2312
+ }
2313
+ else {
2314
+ throw new errors.NotSupported(this.id + ' cancelAllOrders() is not currently supported for ' + type + ' markets');
2315
+ }
2316
+ //
2317
+ // AccountCategoryDeleteOrderAll
2318
+ //
2319
+ // {
2320
+ // "code": 0,
2321
+ // "data": {
2322
+ // "ac": "CASH",
2323
+ // "accountId": "cshQtyfq8XLAA9kcf19h8bXHbAwwoqDo",
2324
+ // "action": "cancel-all",
2325
+ // "info": {
2326
+ // "id": "2bmYvi7lyTrneMzpcJcf2D7Pe9V1P9wy",
2327
+ // "orderId": "",
2328
+ // "orderType": "NULL_VAL",
2329
+ // "symbol": "",
2330
+ // "timestamp": 1574118495462
2331
+ // },
2332
+ // "status": "Ack"
2333
+ // }
2334
+ // }
2335
+ //
2336
+ // AccountGroupDeleteFuturesOrderAll
2337
+ //
2338
+ // {
2339
+ // "code": 0,
2340
+ // "data": {
2341
+ // "ac": "FUTURES",
2342
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
2343
+ // "action": "cancel-all",
2344
+ // "info": {
2345
+ // "symbol":"BTC-PERP"
2346
+ // }
2347
+ // }
2348
+ // }
2349
+ //
2350
+ return response;
2351
+ }
2352
+ parseDepositAddress(depositAddress, currency = undefined) {
2353
+ //
2354
+ // {
2355
+ // "address": "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722",
2356
+ // "destTag": "",
2357
+ // "tagType": "",
2358
+ // "tagId": "",
2359
+ // "chainName": "ERC20",
2360
+ // "numConfirmations": 20,
2361
+ // "withdrawalFee": 1,
2362
+ // "nativeScale": 4,
2363
+ // "tips": []
2364
+ // }
2365
+ //
2366
+ const address = this.safeString(depositAddress, 'address');
2367
+ const tagId = this.safeString(depositAddress, 'tagId');
2368
+ const tag = this.safeString(depositAddress, tagId);
2369
+ this.checkAddress(address);
2370
+ const code = (currency === undefined) ? undefined : currency['code'];
2371
+ const chainName = this.safeString(depositAddress, 'chainName');
2372
+ const network = this.safeNetwork(chainName);
2373
+ return {
2374
+ 'currency': code,
2375
+ 'address': address,
2376
+ 'tag': tag,
2377
+ 'network': network,
2378
+ 'info': depositAddress,
2379
+ };
2380
+ }
2381
+ safeNetwork(networkId) {
2382
+ const networksById = {
2383
+ 'TRC20': 'TRC20',
2384
+ 'ERC20': 'ERC20',
2385
+ 'GO20': 'GO20',
2386
+ 'BEP2': 'BEP2',
2387
+ 'BEP20 (BSC)': 'BEP20',
2388
+ 'Bitcoin': 'BTC',
2389
+ 'Bitcoin ABC': 'BCH',
2390
+ 'Litecoin': 'LTC',
2391
+ 'Matic Network': 'MATIC',
2392
+ 'Solana': 'SOL',
2393
+ 'xDai': 'STAKE',
2394
+ 'Akash': 'AKT',
2395
+ };
2396
+ return this.safeString(networksById, networkId, networkId);
2397
+ }
2398
+ async fetchDepositAddress(code, params = {}) {
2399
+ /**
2400
+ * @method
2401
+ * @name ascendex#fetchDepositAddress
2402
+ * @description fetch the deposit address for a currency associated with this account
2403
+ * @param {string} code unified currency code
2404
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2405
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
2406
+ */
2407
+ await this.loadMarkets();
2408
+ const currency = this.currency(code);
2409
+ const chainName = this.safeString(params, 'chainName');
2410
+ params = this.omit(params, 'chainName');
2411
+ const request = {
2412
+ 'asset': currency['id'],
2413
+ };
2414
+ const response = await this.v1PrivateGetWalletDepositAddress(this.extend(request, params));
2415
+ //
2416
+ // {
2417
+ // "code":0,
2418
+ // "data":{
2419
+ // "asset":"USDT",
2420
+ // "assetName":"Tether",
2421
+ // "address":[
2422
+ // {
2423
+ // "address":"1N22odLHXnLPCjC8kwBJPTayarr9RtPod6",
2424
+ // "destTag":"",
2425
+ // "tagType":"",
2426
+ // "tagId":"",
2427
+ // "chainName":"Omni",
2428
+ // "numConfirmations":3,
2429
+ // "withdrawalFee":4.7,
2430
+ // "nativeScale":4,
2431
+ // "tips":[]
2432
+ // },
2433
+ // {
2434
+ // "address":"0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722",
2435
+ // "destTag":"",
2436
+ // "tagType":"",
2437
+ // "tagId":"",
2438
+ // "chainName":"ERC20",
2439
+ // "numConfirmations":20,
2440
+ // "withdrawalFee":1.0,
2441
+ // "nativeScale":4,
2442
+ // "tips":[]
2443
+ // }
2444
+ // ]
2445
+ // }
2446
+ // }
2447
+ //
2448
+ const data = this.safeValue(response, 'data', {});
2449
+ const addresses = this.safeValue(data, 'address', []);
2450
+ const numAddresses = addresses.length;
2451
+ let address = undefined;
2452
+ if (numAddresses > 1) {
2453
+ const addressesByChainName = this.indexBy(addresses, 'chainName');
2454
+ if (chainName === undefined) {
2455
+ const chainNames = Object.keys(addressesByChainName);
2456
+ const chains = chainNames.join(', ');
2457
+ throw new errors.ArgumentsRequired(this.id + ' fetchDepositAddress() returned more than one address, a chainName parameter is required, one of ' + chains);
2458
+ }
2459
+ address = this.safeValue(addressesByChainName, chainName, {});
2460
+ }
2461
+ else {
2462
+ // first address
2463
+ address = this.safeValue(addresses, 0, {});
2464
+ }
2465
+ const result = this.parseDepositAddress(address, currency);
2466
+ return this.extend(result, {
2467
+ 'info': response,
2468
+ });
2469
+ }
2470
+ async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
2471
+ /**
2472
+ * @method
2473
+ * @name ascendex#fetchDeposits
2474
+ * @description fetch all deposits made to an account
2475
+ * @param {string} code unified currency code
2476
+ * @param {int} [since] the earliest time in ms to fetch deposits for
2477
+ * @param {int} [limit] the maximum number of deposits structures to retrieve
2478
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2479
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2480
+ */
2481
+ const request = {
2482
+ 'txType': 'deposit',
2483
+ };
2484
+ return await this.fetchTransactions(code, since, limit, this.extend(request, params));
2485
+ }
2486
+ async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
2487
+ /**
2488
+ * @method
2489
+ * @name ascendex#fetchWithdrawals
2490
+ * @description fetch all withdrawals made from an account
2491
+ * @param {string} code unified currency code
2492
+ * @param {int} [since] the earliest time in ms to fetch withdrawals for
2493
+ * @param {int} [limit] the maximum number of withdrawals structures to retrieve
2494
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2495
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2496
+ */
2497
+ const request = {
2498
+ 'txType': 'withdrawal',
2499
+ };
2500
+ return await this.fetchTransactions(code, since, limit, this.extend(request, params));
2501
+ }
2502
+ async fetchDepositsWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
2503
+ /**
2504
+ * @method
2505
+ * @name ascendex#fetchDepositsWithdrawals
2506
+ * @description fetch history of deposits and withdrawals
2507
+ * @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
2508
+ * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
2509
+ * @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
2510
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2511
+ * @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2512
+ */
2513
+ await this.loadMarkets();
2514
+ const request = {
2515
+ // 'asset': currency['id'],
2516
+ // 'page': 1,
2517
+ // 'pageSize': 20,
2518
+ // 'startTs': this.milliseconds (),
2519
+ // 'endTs': this.milliseconds (),
2520
+ // 'txType': undefned, // deposit, withdrawal
2521
+ };
2522
+ let currency = undefined;
2523
+ if (code !== undefined) {
2524
+ currency = this.currency(code);
2525
+ request['asset'] = currency['id'];
2526
+ }
2527
+ if (since !== undefined) {
2528
+ request['startTs'] = since;
2529
+ }
2530
+ if (limit !== undefined) {
2531
+ request['pageSize'] = limit;
2532
+ }
2533
+ const response = await this.v1PrivateGetWalletTransactions(this.extend(request, params));
2534
+ //
2535
+ // {
2536
+ // "code": 0,
2537
+ // "data": {
2538
+ // "data": [
2539
+ // {
2540
+ // "requestId": "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB",
2541
+ // "time": 1591606166000,
2542
+ // "asset": "USDT",
2543
+ // "transactionType": "deposit",
2544
+ // "amount": "25",
2545
+ // "commission": "0",
2546
+ // "networkTransactionId": "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce",
2547
+ // "status": "pending",
2548
+ // "numConfirmed": 8,
2549
+ // "numConfirmations": 20,
2550
+ // "destAddress": { address: "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722" }
2551
+ // }
2552
+ // ],
2553
+ // "page": 1,
2554
+ // "pageSize": 20,
2555
+ // "hasNext": false
2556
+ // }
2557
+ // }
2558
+ //
2559
+ const data = this.safeValue(response, 'data', {});
2560
+ const transactions = this.safeValue(data, 'data', []);
2561
+ return this.parseTransactions(transactions, currency, since, limit);
2562
+ }
2563
+ parseTransactionStatus(status) {
2564
+ const statuses = {
2565
+ 'reviewing': 'pending',
2566
+ 'pending': 'pending',
2567
+ 'confirmed': 'ok',
2568
+ 'rejected': 'rejected',
2569
+ };
2570
+ return this.safeString(statuses, status, status);
2571
+ }
2572
+ parseTransaction(transaction, currency = undefined) {
2573
+ //
2574
+ // {
2575
+ // "requestId": "wuzd1Ojsqtz4bCA3UXwtUnnJDmU8PiyB",
2576
+ // "time": 1591606166000,
2577
+ // "asset": "USDT",
2578
+ // "transactionType": "deposit",
2579
+ // "amount": "25",
2580
+ // "commission": "0",
2581
+ // "networkTransactionId": "0xbc4eabdce92f14dbcc01d799a5f8ca1f02f4a3a804b6350ea202be4d3c738fce",
2582
+ // "status": "pending",
2583
+ // "numConfirmed": 8,
2584
+ // "numConfirmations": 20,
2585
+ // "destAddress": {
2586
+ // "address": "0xe7c70b4e73b6b450ee46c3b5c0f5fb127ca55722",
2587
+ // "destTag": "..." // for currencies that have it
2588
+ // }
2589
+ // }
2590
+ //
2591
+ const destAddress = this.safeValue(transaction, 'destAddress', {});
2592
+ const address = this.safeString(destAddress, 'address');
2593
+ const tag = this.safeString(destAddress, 'destTag');
2594
+ const timestamp = this.safeInteger(transaction, 'time');
2595
+ const currencyId = this.safeString(transaction, 'asset');
2596
+ let amountString = this.safeString(transaction, 'amount');
2597
+ const feeCostString = this.safeString(transaction, 'commission');
2598
+ amountString = Precise["default"].stringSub(amountString, feeCostString);
2599
+ const code = this.safeCurrencyCode(currencyId, currency);
2600
+ return {
2601
+ 'info': transaction,
2602
+ 'id': this.safeString(transaction, 'requestId'),
2603
+ 'txid': this.safeString(transaction, 'networkTransactionId'),
2604
+ 'type': this.safeString(transaction, 'transactionType'),
2605
+ 'currency': code,
2606
+ 'network': undefined,
2607
+ 'amount': this.parseNumber(amountString),
2608
+ 'status': this.parseTransactionStatus(this.safeString(transaction, 'status')),
2609
+ 'timestamp': timestamp,
2610
+ 'datetime': this.iso8601(timestamp),
2611
+ 'address': address,
2612
+ 'addressFrom': undefined,
2613
+ 'addressTo': address,
2614
+ 'tag': tag,
2615
+ 'tagFrom': undefined,
2616
+ 'tagTo': tag,
2617
+ 'updated': undefined,
2618
+ 'comment': undefined,
2619
+ 'fee': {
2620
+ 'currency': code,
2621
+ 'cost': this.parseNumber(feeCostString),
2622
+ 'rate': undefined,
2623
+ },
2624
+ 'internal': false,
2625
+ };
2626
+ }
2627
+ async fetchPositions(symbols = undefined, params = {}) {
2628
+ /**
2629
+ * @method
2630
+ * @name ascendex#fetchPositions
2631
+ * @description fetch all open positions
2632
+ * @param {string[]|undefined} symbols list of unified market symbols
2633
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2634
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
2635
+ */
2636
+ await this.loadMarkets();
2637
+ await this.loadAccounts();
2638
+ const account = this.safeValue(this.accounts, 0, {});
2639
+ const accountGroup = this.safeString(account, 'id');
2640
+ const request = {
2641
+ 'account-group': accountGroup,
2642
+ };
2643
+ const response = await this.v2PrivateAccountGroupGetFuturesPosition(this.extend(request, params));
2644
+ //
2645
+ // {
2646
+ // "code": 0,
2647
+ // "data": {
2648
+ // "accountId": "fut2ODPhGiY71Pl4vtXnOZ00ssgD7QGn",
2649
+ // "ac": "FUTURES",
2650
+ // "collaterals": [
2651
+ // {
2652
+ // "asset": "USDT",
2653
+ // "balance": "44.570287262",
2654
+ // "referencePrice": "1",
2655
+ // "discountFactor": "1"
2656
+ // }
2657
+ // ],
2658
+ // "contracts": [
2659
+ // {
2660
+ // "symbol": "BTC-PERP",
2661
+ // "side": "LONG",
2662
+ // "position": "0.0001",
2663
+ // "referenceCost": "-3.12277254",
2664
+ // "unrealizedPnl": "-0.001700233",
2665
+ // "realizedPnl": "0",
2666
+ // "avgOpenPrice": "31209",
2667
+ // "marginType": "isolated",
2668
+ // "isolatedMargin": "1.654972977",
2669
+ // "leverage": "2",
2670
+ // "takeProfitPrice": "0",
2671
+ // "takeProfitTrigger": "market",
2672
+ // "stopLossPrice": "0",
2673
+ // "stopLossTrigger": "market",
2674
+ // "buyOpenOrderNotional": "0",
2675
+ // "sellOpenOrderNotional": "0",
2676
+ // "markPrice": "31210.723063672",
2677
+ // "indexPrice": "31223.148857925"
2678
+ // },
2679
+ // ]
2680
+ // }
2681
+ // }
2682
+ //
2683
+ const data = this.safeValue(response, 'data', {});
2684
+ const position = this.safeValue(data, 'contracts', []);
2685
+ const result = [];
2686
+ for (let i = 0; i < position.length; i++) {
2687
+ result.push(this.parsePosition(position[i]));
2688
+ }
2689
+ symbols = this.marketSymbols(symbols);
2690
+ return this.filterByArrayPositions(result, 'symbol', symbols, false);
2691
+ }
2692
+ parsePosition(position, market = undefined) {
2693
+ //
2694
+ // {
2695
+ // "symbol": "BTC-PERP",
2696
+ // "side": "LONG",
2697
+ // "position": "0.0001",
2698
+ // "referenceCost": "-3.12277254",
2699
+ // "unrealizedPnl": "-0.001700233",
2700
+ // "realizedPnl": "0",
2701
+ // "avgOpenPrice": "31209",
2702
+ // "marginType": "isolated",
2703
+ // "isolatedMargin": "1.654972977",
2704
+ // "leverage": "2",
2705
+ // "takeProfitPrice": "0",
2706
+ // "takeProfitTrigger": "market",
2707
+ // "stopLossPrice": "0",
2708
+ // "stopLossTrigger": "market",
2709
+ // "buyOpenOrderNotional": "0",
2710
+ // "sellOpenOrderNotional": "0",
2711
+ // "markPrice": "31210.723063672",
2712
+ // "indexPrice": "31223.148857925"
2713
+ // },
2714
+ //
2715
+ const marketId = this.safeString(position, 'symbol');
2716
+ market = this.safeMarket(marketId, market);
2717
+ let notional = this.safeString(position, 'buyOpenOrderNotional');
2718
+ if (Precise["default"].stringEq(notional, '0')) {
2719
+ notional = this.safeString(position, 'sellOpenOrderNotional');
2720
+ }
2721
+ const marginMode = this.safeString(position, 'marginType');
2722
+ let collateral = undefined;
2723
+ if (marginMode === 'isolated') {
2724
+ collateral = this.safeString(position, 'isolatedMargin');
2725
+ }
2726
+ return this.safePosition({
2727
+ 'info': position,
2728
+ 'id': undefined,
2729
+ 'symbol': market['symbol'],
2730
+ 'notional': this.parseNumber(notional),
2731
+ 'marginMode': marginMode,
2732
+ 'liquidationPrice': undefined,
2733
+ 'entryPrice': this.safeNumber(position, 'avgOpenPrice'),
2734
+ 'unrealizedPnl': this.safeNumber(position, 'unrealizedPnl'),
2735
+ 'percentage': undefined,
2736
+ 'contracts': this.safeNumber(position, 'position'),
2737
+ 'contractSize': this.safeNumber(market, 'contractSize'),
2738
+ 'markPrice': this.safeNumber(position, 'markPrice'),
2739
+ 'lastPrice': undefined,
2740
+ 'side': this.safeStringLower(position, 'side'),
2741
+ 'hedged': undefined,
2742
+ 'timestamp': undefined,
2743
+ 'datetime': undefined,
2744
+ 'lastUpdateTimestamp': undefined,
2745
+ 'maintenanceMargin': undefined,
2746
+ 'maintenanceMarginPercentage': undefined,
2747
+ 'collateral': collateral,
2748
+ 'initialMargin': undefined,
2749
+ 'initialMarginPercentage': undefined,
2750
+ 'leverage': this.safeInteger(position, 'leverage'),
2751
+ 'marginRatio': undefined,
2752
+ 'stopLossPrice': this.safeNumber(position, 'stopLossPrice'),
2753
+ 'takeProfitPrice': this.safeNumber(position, 'takeProfitPrice'),
2754
+ });
2755
+ }
2756
+ parseFundingRate(contract, market = undefined) {
2757
+ //
2758
+ // {
2759
+ // "time": 1640061364830,
2760
+ // "symbol": "EOS-PERP",
2761
+ // "markPrice": "3.353854865",
2762
+ // "indexPrice": "3.3542",
2763
+ // "openInterest": "14242",
2764
+ // "fundingRate": "-0.000073026",
2765
+ // "nextFundingTime": 1640073600000
2766
+ // }
2767
+ //
2768
+ const marketId = this.safeString(contract, 'symbol');
2769
+ const symbol = this.safeSymbol(marketId, market);
2770
+ const currentTime = this.safeInteger(contract, 'time');
2771
+ const nextFundingRate = this.safeNumber(contract, 'fundingRate');
2772
+ const nextFundingRateTimestamp = this.safeInteger(contract, 'nextFundingTime');
2773
+ return {
2774
+ 'info': contract,
2775
+ 'symbol': symbol,
2776
+ 'markPrice': this.safeNumber(contract, 'markPrice'),
2777
+ 'indexPrice': this.safeNumber(contract, 'indexPrice'),
2778
+ 'interestRate': this.parseNumber('0'),
2779
+ 'estimatedSettlePrice': undefined,
2780
+ 'timestamp': currentTime,
2781
+ 'datetime': this.iso8601(currentTime),
2782
+ 'previousFundingRate': undefined,
2783
+ 'nextFundingRate': undefined,
2784
+ 'previousFundingTimestamp': undefined,
2785
+ 'nextFundingTimestamp': undefined,
2786
+ 'previousFundingDatetime': undefined,
2787
+ 'nextFundingDatetime': undefined,
2788
+ 'fundingRate': nextFundingRate,
2789
+ 'fundingTimestamp': nextFundingRateTimestamp,
2790
+ 'fundingDatetime': this.iso8601(nextFundingRateTimestamp),
2791
+ };
2792
+ }
2793
+ async fetchFundingRates(symbols = undefined, params = {}) {
2794
+ /**
2795
+ * @method
2796
+ * @name ascendex#fetchFundingRates
2797
+ * @description fetch the funding rate for multiple markets
2798
+ * @param {string[]|undefined} symbols list of unified market symbols
2799
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2800
+ * @returns {object} a dictionary of [funding rates structures]{@link https://docs.ccxt.com/#/?id=funding-rates-structure}, indexe by market symbols
2801
+ */
2802
+ await this.loadMarkets();
2803
+ symbols = this.marketSymbols(symbols);
2804
+ const response = await this.v2PublicGetFuturesPricingData(params);
2805
+ //
2806
+ // {
2807
+ // "code": 0,
2808
+ // "data": {
2809
+ // "contracts": [
2810
+ // {
2811
+ // "time": 1640061364830,
2812
+ // "symbol": "EOS-PERP",
2813
+ // "markPrice": "3.353854865",
2814
+ // "indexPrice": "3.3542",
2815
+ // "openInterest": "14242",
2816
+ // "fundingRate": "-0.000073026",
2817
+ // "nextFundingTime": 1640073600000
2818
+ // },
2819
+ // ],
2820
+ // "collaterals": [
2821
+ // {
2822
+ // "asset": "USDTR",
2823
+ // "referencePrice": "1"
2824
+ // },
2825
+ // ]
2826
+ // }
2827
+ // }
2828
+ //
2829
+ const data = this.safeValue(response, 'data', {});
2830
+ const contracts = this.safeValue(data, 'contracts', []);
2831
+ const result = this.parseFundingRates(contracts);
2832
+ return this.filterByArray(result, 'symbol', symbols);
2833
+ }
2834
+ async modifyMarginHelper(symbol, amount, type, params = {}) {
2835
+ await this.loadMarkets();
2836
+ await this.loadAccounts();
2837
+ const market = this.market(symbol);
2838
+ const account = this.safeValue(this.accounts, 0, {});
2839
+ const accountGroup = this.safeString(account, 'id');
2840
+ amount = this.amountToPrecision(symbol, amount);
2841
+ const request = {
2842
+ 'account-group': accountGroup,
2843
+ 'symbol': market['id'],
2844
+ 'amount': amount, // positive value for adding margin, negative for reducing
2845
+ };
2846
+ const response = await this.v2PrivateAccountGroupPostFuturesIsolatedPositionMargin(this.extend(request, params));
2847
+ //
2848
+ // Can only change margin for perpetual futures isolated margin positions
2849
+ //
2850
+ // {
2851
+ // "code": 0
2852
+ // }
2853
+ //
2854
+ if (type === 'reduce') {
2855
+ amount = Precise["default"].stringAbs(amount);
2856
+ }
2857
+ return this.extend(this.parseMarginModification(response, market), {
2858
+ 'amount': this.parseNumber(amount),
2859
+ 'type': type,
2860
+ });
2861
+ }
2862
+ parseMarginModification(data, market = undefined) {
2863
+ const errorCode = this.safeString(data, 'code');
2864
+ const status = (errorCode === '0') ? 'ok' : 'failed';
2865
+ return {
2866
+ 'info': data,
2867
+ 'type': undefined,
2868
+ 'amount': undefined,
2869
+ 'code': market['quote'],
2870
+ 'symbol': market['symbol'],
2871
+ 'status': status,
2872
+ };
2873
+ }
2874
+ async reduceMargin(symbol, amount, params = {}) {
2875
+ /**
2876
+ * @method
2877
+ * @name ascendex#reduceMargin
2878
+ * @description remove margin from a position
2879
+ * @param {string} symbol unified market symbol
2880
+ * @param {float} amount the amount of margin to remove
2881
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2882
+ * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=reduce-margin-structure}
2883
+ */
2884
+ return await this.modifyMarginHelper(symbol, -amount, 'reduce', params);
2885
+ }
2886
+ async addMargin(symbol, amount, params = {}) {
2887
+ /**
2888
+ * @method
2889
+ * @name ascendex#addMargin
2890
+ * @description add margin
2891
+ * @param {string} symbol unified market symbol
2892
+ * @param {float} amount amount of margin to add
2893
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2894
+ * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=add-margin-structure}
2895
+ */
2896
+ return await this.modifyMarginHelper(symbol, amount, 'add', params);
2897
+ }
2898
+ async setLeverage(leverage, symbol = undefined, params = {}) {
2899
+ /**
2900
+ * @method
2901
+ * @name ascendex#setLeverage
2902
+ * @description set the level of leverage for a market
2903
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#change-contract-leverage
2904
+ * @param {float} leverage the rate of leverage
2905
+ * @param {string} symbol unified market symbol
2906
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2907
+ * @returns {object} response from the exchange
2908
+ */
2909
+ if (symbol === undefined) {
2910
+ throw new errors.ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
2911
+ }
2912
+ if ((leverage < 1) || (leverage > 100)) {
2913
+ throw new errors.BadRequest(this.id + ' leverage should be between 1 and 100');
2914
+ }
2915
+ await this.loadMarkets();
2916
+ await this.loadAccounts();
2917
+ const market = this.market(symbol);
2918
+ if (!market['swap']) {
2919
+ throw new errors.BadSymbol(this.id + ' setLeverage() supports swap contracts only');
2920
+ }
2921
+ const account = this.safeValue(this.accounts, 0, {});
2922
+ const accountGroup = this.safeString(account, 'id');
2923
+ const request = {
2924
+ 'account-group': accountGroup,
2925
+ 'symbol': market['id'],
2926
+ 'leverage': leverage,
2927
+ };
2928
+ return await this.v2PrivateAccountGroupPostFuturesLeverage(this.extend(request, params));
2929
+ }
2930
+ async setMarginMode(marginMode, symbol = undefined, params = {}) {
2931
+ /**
2932
+ * @method
2933
+ * @name ascendex#setMarginMode
2934
+ * @description set margin mode to 'cross' or 'isolated'
2935
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#change-margin-type
2936
+ * @param {string} marginMode 'cross' or 'isolated'
2937
+ * @param {string} symbol unified market symbol
2938
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2939
+ * @returns {object} response from the exchange
2940
+ */
2941
+ if (symbol === undefined) {
2942
+ throw new errors.ArgumentsRequired(this.id + ' setMarginMode() requires a symbol argument');
2943
+ }
2944
+ marginMode = marginMode.toLowerCase();
2945
+ if (marginMode === 'cross') {
2946
+ marginMode = 'crossed';
2947
+ }
2948
+ if (marginMode !== 'isolated' && marginMode !== 'crossed') {
2949
+ throw new errors.BadRequest(this.id + ' setMarginMode() marginMode argument should be isolated or cross');
2950
+ }
2951
+ await this.loadMarkets();
2952
+ await this.loadAccounts();
2953
+ const market = this.market(symbol);
2954
+ const account = this.safeValue(this.accounts, 0, {});
2955
+ const accountGroup = this.safeString(account, 'id');
2956
+ const request = {
2957
+ 'account-group': accountGroup,
2958
+ 'symbol': market['id'],
2959
+ 'marginType': marginMode,
2960
+ };
2961
+ if (!market['swap']) {
2962
+ throw new errors.BadSymbol(this.id + ' setMarginMode() supports swap contracts only');
2963
+ }
2964
+ return await this.v2PrivateAccountGroupPostFuturesMarginType(this.extend(request, params));
2965
+ }
2966
+ async fetchLeverageTiers(symbols = undefined, params = {}) {
2967
+ /**
2968
+ * @method
2969
+ * @name ascendex#fetchLeverageTiers
2970
+ * @description retrieve information on the maximum leverage, and maintenance margin for trades of varying trade sizes
2971
+ * @param {string[]|undefined} symbols list of unified market symbols
2972
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2973
+ * @returns {object} a dictionary of [leverage tiers structures]{@link https://docs.ccxt.com/#/?id=leverage-tiers-structure}, indexed by market symbols
2974
+ */
2975
+ await this.loadMarkets();
2976
+ const response = await this.v2PublicGetFuturesContract(params);
2977
+ //
2978
+ // {
2979
+ // "code":0,
2980
+ // "data":[
2981
+ // {
2982
+ // "symbol":"BTC-PERP",
2983
+ // "status":"Normal",
2984
+ // "displayName":"BTCUSDT",
2985
+ // "settlementAsset":"USDT",
2986
+ // "underlying":"BTC/USDT",
2987
+ // "tradingStartTime":1579701600000,
2988
+ // "priceFilter":{"minPrice":"1","maxPrice":"1000000","tickSize":"1"},
2989
+ // "lotSizeFilter":{"minQty":"0.0001","maxQty":"1000000000","lotSize":"0.0001"},
2990
+ // "commissionType":"Quote",
2991
+ // "commissionReserveRate":"0.001",
2992
+ // "marketOrderPriceMarkup":"0.03",
2993
+ // "marginRequirements":[
2994
+ // {"positionNotionalLowerBound":"0","positionNotionalUpperBound":"50000","initialMarginRate":"0.01","maintenanceMarginRate":"0.006"},
2995
+ // {"positionNotionalLowerBound":"50000","positionNotionalUpperBound":"200000","initialMarginRate":"0.02","maintenanceMarginRate":"0.012"},
2996
+ // {"positionNotionalLowerBound":"200000","positionNotionalUpperBound":"2000000","initialMarginRate":"0.04","maintenanceMarginRate":"0.024"},
2997
+ // {"positionNotionalLowerBound":"2000000","positionNotionalUpperBound":"20000000","initialMarginRate":"0.1","maintenanceMarginRate":"0.06"},
2998
+ // {"positionNotionalLowerBound":"20000000","positionNotionalUpperBound":"40000000","initialMarginRate":"0.2","maintenanceMarginRate":"0.12"},
2999
+ // {"positionNotionalLowerBound":"40000000","positionNotionalUpperBound":"1000000000","initialMarginRate":"0.333333","maintenanceMarginRate":"0.2"}
3000
+ // ]
3001
+ // }
3002
+ // ]
3003
+ // }
3004
+ //
3005
+ const data = this.safeValue(response, 'data');
3006
+ symbols = this.marketSymbols(symbols);
3007
+ return this.parseLeverageTiers(data, symbols, 'symbol');
3008
+ }
3009
+ parseMarketLeverageTiers(info, market = undefined) {
3010
+ /**
3011
+ * @param {object} info Exchange market response for 1 market
3012
+ * @param {object} market CCXT market
3013
+ */
3014
+ //
3015
+ // {
3016
+ // "symbol":"BTC-PERP",
3017
+ // "status":"Normal",
3018
+ // "displayName":"BTCUSDT",
3019
+ // "settlementAsset":"USDT",
3020
+ // "underlying":"BTC/USDT",
3021
+ // "tradingStartTime":1579701600000,
3022
+ // "priceFilter":{"minPrice":"1","maxPrice":"1000000","tickSize":"1"},
3023
+ // "lotSizeFilter":{"minQty":"0.0001","maxQty":"1000000000","lotSize":"0.0001"},
3024
+ // "commissionType":"Quote",
3025
+ // "commissionReserveRate":"0.001",
3026
+ // "marketOrderPriceMarkup":"0.03",
3027
+ // "marginRequirements":[
3028
+ // {"positionNotionalLowerBound":"0","positionNotionalUpperBound":"50000","initialMarginRate":"0.01","maintenanceMarginRate":"0.006"},
3029
+ // {"positionNotionalLowerBound":"50000","positionNotionalUpperBound":"200000","initialMarginRate":"0.02","maintenanceMarginRate":"0.012"},
3030
+ // {"positionNotionalLowerBound":"200000","positionNotionalUpperBound":"2000000","initialMarginRate":"0.04","maintenanceMarginRate":"0.024"},
3031
+ // {"positionNotionalLowerBound":"2000000","positionNotionalUpperBound":"20000000","initialMarginRate":"0.1","maintenanceMarginRate":"0.06"},
3032
+ // {"positionNotionalLowerBound":"20000000","positionNotionalUpperBound":"40000000","initialMarginRate":"0.2","maintenanceMarginRate":"0.12"},
3033
+ // {"positionNotionalLowerBound":"40000000","positionNotionalUpperBound":"1000000000","initialMarginRate":"0.333333","maintenanceMarginRate":"0.2"}
3034
+ // ]
3035
+ // }
3036
+ //
3037
+ const marginRequirements = this.safeValue(info, 'marginRequirements', []);
3038
+ const id = this.safeString(info, 'symbol');
3039
+ market = this.safeMarket(id, market);
3040
+ const tiers = [];
3041
+ for (let i = 0; i < marginRequirements.length; i++) {
3042
+ const tier = marginRequirements[i];
3043
+ const initialMarginRate = this.safeString(tier, 'initialMarginRate');
3044
+ tiers.push({
3045
+ 'tier': this.sum(i, 1),
3046
+ 'currency': market['quote'],
3047
+ 'minNotional': this.safeNumber(tier, 'positionNotionalLowerBound'),
3048
+ 'maxNotional': this.safeNumber(tier, 'positionNotionalUpperBound'),
3049
+ 'maintenanceMarginRate': this.safeNumber(tier, 'maintenanceMarginRate'),
3050
+ 'maxLeverage': this.parseNumber(Precise["default"].stringDiv('1', initialMarginRate)),
3051
+ 'info': tier,
3052
+ });
3053
+ }
3054
+ return tiers;
3055
+ }
3056
+ parseDepositWithdrawFee(fee, currency = undefined) {
3057
+ //
3058
+ // {
3059
+ // "assetCode": "USDT",
3060
+ // "assetName": "Tether",
3061
+ // "precisionScale": 9,
3062
+ // "nativeScale": 4,
3063
+ // "blockChain": [
3064
+ // {
3065
+ // "chainName": "Omni",
3066
+ // "withdrawFee": "30.0",
3067
+ // "allowDeposit": true,
3068
+ // "allowWithdraw": true,
3069
+ // "minDepositAmt": "0.0",
3070
+ // "minWithdrawal": "50.0",
3071
+ // "numConfirmations": 3
3072
+ // },
3073
+ // ]
3074
+ // }
3075
+ //
3076
+ const blockChains = this.safeValue(fee, 'blockChain', []);
3077
+ const blockChainsLength = blockChains.length;
3078
+ const result = {
3079
+ 'info': fee,
3080
+ 'withdraw': {
3081
+ 'fee': undefined,
3082
+ 'percentage': undefined,
3083
+ },
3084
+ 'deposit': {
3085
+ 'fee': undefined,
3086
+ 'percentage': undefined,
3087
+ },
3088
+ 'networks': {},
3089
+ };
3090
+ for (let i = 0; i < blockChainsLength; i++) {
3091
+ const blockChain = blockChains[i];
3092
+ const networkId = this.safeString(blockChain, 'chainName');
3093
+ const currencyCode = this.safeString(currency, 'code');
3094
+ const networkCode = this.networkIdToCode(networkId, currencyCode);
3095
+ result['networks'][networkCode] = {
3096
+ 'deposit': { 'fee': undefined, 'percentage': undefined },
3097
+ 'withdraw': { 'fee': this.safeNumber(blockChain, 'withdrawFee'), 'percentage': false },
3098
+ };
3099
+ if (blockChainsLength === 1) {
3100
+ result['withdraw']['fee'] = this.safeNumber(blockChain, 'withdrawFee');
3101
+ result['withdraw']['percentage'] = false;
3102
+ }
3103
+ }
3104
+ return result;
3105
+ }
3106
+ async fetchDepositWithdrawFees(codes = undefined, params = {}) {
3107
+ /**
3108
+ * @method
3109
+ * @name ascendex#fetchDepositWithdrawFees
3110
+ * @description fetch deposit and withdraw fees
3111
+ * @see https://ascendex.github.io/ascendex-pro-api/#list-all-assets
3112
+ * @param {string[]|undefined} codes list of unified currency codes
3113
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3114
+ * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
3115
+ */
3116
+ await this.loadMarkets();
3117
+ const response = await this.v2PublicGetAssets(params);
3118
+ const data = this.safeValue(response, 'data');
3119
+ return this.parseDepositWithdrawFees(data, codes, 'assetCode');
3120
+ }
3121
+ async transfer(code, amount, fromAccount, toAccount, params = {}) {
3122
+ /**
3123
+ * @method
3124
+ * @name ascendex#transfer
3125
+ * @description transfer currency internally between wallets on the same account
3126
+ * @param {string} code unified currency code
3127
+ * @param {float} amount amount to transfer
3128
+ * @param {string} fromAccount account to transfer from
3129
+ * @param {string} toAccount account to transfer to
3130
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3131
+ * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
3132
+ */
3133
+ await this.loadMarkets();
3134
+ await this.loadAccounts();
3135
+ const account = this.safeValue(this.accounts, 0, {});
3136
+ const accountGroup = this.safeString(account, 'id');
3137
+ const currency = this.currency(code);
3138
+ amount = this.currencyToPrecision(code, amount);
3139
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
3140
+ const fromId = this.safeString(accountsByType, fromAccount, fromAccount);
3141
+ const toId = this.safeString(accountsByType, toAccount, toAccount);
3142
+ if (fromId !== 'cash' && toId !== 'cash') {
3143
+ throw new errors.ExchangeError(this.id + ' transfer() only supports direct balance transfer between spot and swap, spot and margin');
3144
+ }
3145
+ const request = {
3146
+ 'account-group': accountGroup,
3147
+ 'amount': amount,
3148
+ 'asset': currency['id'],
3149
+ 'fromAccount': fromId,
3150
+ 'toAccount': toId,
3151
+ };
3152
+ const response = await this.v1PrivateAccountGroupPostTransfer(this.extend(request, params));
3153
+ //
3154
+ // { "code": "0" }
3155
+ //
3156
+ const transferOptions = this.safeValue(this.options, 'transfer', {});
3157
+ const fillResponseFromRequest = this.safeValue(transferOptions, 'fillResponseFromRequest', true);
3158
+ const transfer = this.parseTransfer(response, currency);
3159
+ if (fillResponseFromRequest) {
3160
+ transfer['fromAccount'] = fromAccount;
3161
+ transfer['toAccount'] = toAccount;
3162
+ transfer['amount'] = amount;
3163
+ transfer['currency'] = code;
3164
+ }
3165
+ return transfer;
3166
+ }
3167
+ parseTransfer(transfer, currency = undefined) {
3168
+ //
3169
+ // { "code": "0" }
3170
+ //
3171
+ const status = this.safeInteger(transfer, 'code');
3172
+ const currencyCode = this.safeCurrencyCode(undefined, currency);
3173
+ const timestamp = this.milliseconds();
3174
+ return {
3175
+ 'info': transfer,
3176
+ 'id': undefined,
3177
+ 'timestamp': timestamp,
3178
+ 'datetime': this.iso8601(timestamp),
3179
+ 'currency': currencyCode,
3180
+ 'amount': undefined,
3181
+ 'fromAccount': undefined,
3182
+ 'toAccount': undefined,
3183
+ 'status': this.parseTransferStatus(status),
3184
+ };
3185
+ }
3186
+ parseTransferStatus(status) {
3187
+ if (status === 0) {
3188
+ return 'ok';
3189
+ }
3190
+ return 'failed';
3191
+ }
3192
+ async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3193
+ /**
3194
+ * @method
3195
+ * @name ascendex#fetchFundingHistory
3196
+ * @description fetch the history of funding payments paid and received on this account
3197
+ * @see https://ascendex.github.io/ascendex-futures-pro-api-v2/#funding-payment-history
3198
+ * @param {string} [symbol] unified market symbol
3199
+ * @param {int} [since] the earliest time in ms to fetch funding history for
3200
+ * @param {int} [limit] the maximum number of funding history structures to retrieve
3201
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3202
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [available parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3203
+ * @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
3204
+ */
3205
+ await this.loadMarkets();
3206
+ await this.loadAccounts();
3207
+ let paginate = false;
3208
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingHistory', 'paginate');
3209
+ if (paginate) {
3210
+ return await this.fetchPaginatedCallIncremental('fetchFundingHistory', symbol, since, limit, params, 'page', 25);
3211
+ }
3212
+ const account = this.safeValue(this.accounts, 0, {});
3213
+ const accountGroup = this.safeString(account, 'id');
3214
+ const request = {
3215
+ 'account-group': accountGroup,
3216
+ };
3217
+ let market = undefined;
3218
+ if (symbol !== undefined) {
3219
+ market = this.market(symbol);
3220
+ request['symbol'] = market['id'];
3221
+ }
3222
+ if (limit !== undefined) {
3223
+ request['pageSize'] = limit;
3224
+ }
3225
+ const response = await this.v2PrivateAccountGroupGetFuturesFundingPayments(this.extend(request, params));
3226
+ //
3227
+ // {
3228
+ // "code": 0,
3229
+ // "data": {
3230
+ // "data": [
3231
+ // {
3232
+ // "timestamp": 1640476800000,
3233
+ // "symbol": "BTC-PERP",
3234
+ // "paymentInUSDT": "-0.013991178",
3235
+ // "fundingRate": "0.000173497"
3236
+ // },
3237
+ // ],
3238
+ // "page": 1,
3239
+ // "pageSize": 3,
3240
+ // "hasNext": true
3241
+ // }
3242
+ // }
3243
+ //
3244
+ const data = this.safeValue(response, 'data', {});
3245
+ const rows = this.safeValue(data, 'data', []);
3246
+ return this.parseIncomes(rows, market, since, limit);
3247
+ }
3248
+ parseIncome(income, market = undefined) {
3249
+ //
3250
+ // {
3251
+ // "timestamp": 1640476800000,
3252
+ // "symbol": "BTC-PERP",
3253
+ // "paymentInUSDT": "-0.013991178",
3254
+ // "fundingRate": "0.000173497"
3255
+ // }
3256
+ //
3257
+ const marketId = this.safeString(income, 'symbol');
3258
+ const timestamp = this.safeInteger(income, 'timestamp');
3259
+ return {
3260
+ 'info': income,
3261
+ 'symbol': this.safeSymbol(marketId, market, '-', 'swap'),
3262
+ 'code': 'USDT',
3263
+ 'timestamp': timestamp,
3264
+ 'datetime': this.iso8601(timestamp),
3265
+ 'id': undefined,
3266
+ 'amount': this.safeNumber(income, 'paymentInUSDT'),
3267
+ };
3268
+ }
3269
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3270
+ const version = api[0];
3271
+ const access = api[1];
3272
+ const type = this.safeString(api, 2);
3273
+ let url = '';
3274
+ const accountCategory = (type === 'accountCategory');
3275
+ if (accountCategory || (type === 'accountGroup')) {
3276
+ url += this.implodeParams('/{account-group}', params);
3277
+ params = this.omit(params, 'account-group');
3278
+ }
3279
+ let request = this.implodeParams(path, params);
3280
+ url += '/api/pro/';
3281
+ if (version === 'v2') {
3282
+ if (type === 'data') {
3283
+ request = 'data/' + version + '/' + request;
3284
+ }
3285
+ else {
3286
+ request = version + '/' + request;
3287
+ }
3288
+ }
3289
+ else {
3290
+ url += version + '/';
3291
+ }
3292
+ if (accountCategory) {
3293
+ url += this.implodeParams('{account-category}/', params);
3294
+ }
3295
+ params = this.omit(params, 'account-category');
3296
+ url += request;
3297
+ if ((version === 'v1') && (request === 'cash/balance') || (request === 'margin/balance')) {
3298
+ request = 'balance';
3299
+ }
3300
+ if ((version === 'v1') && (request === 'spot/fee')) {
3301
+ request = 'fee';
3302
+ }
3303
+ if (request.indexOf('subuser') >= 0) {
3304
+ const parts = request.split('/');
3305
+ request = parts[2];
3306
+ }
3307
+ params = this.omit(params, this.extractParams(path));
3308
+ if (access === 'public') {
3309
+ if (Object.keys(params).length) {
3310
+ url += '?' + this.urlencode(params);
3311
+ }
3312
+ }
3313
+ else {
3314
+ this.checkRequiredCredentials();
3315
+ const timestamp = this.milliseconds().toString();
3316
+ const payload = timestamp + '+' + request;
3317
+ const hmac = this.hmac(this.encode(payload), this.encode(this.secret), sha256.sha256, 'base64');
3318
+ headers = {
3319
+ 'x-auth-key': this.apiKey,
3320
+ 'x-auth-timestamp': timestamp,
3321
+ 'x-auth-signature': hmac,
3322
+ };
3323
+ if (method === 'GET') {
3324
+ if (Object.keys(params).length) {
3325
+ url += '?' + this.urlencode(params);
3326
+ }
3327
+ }
3328
+ else {
3329
+ headers['Content-Type'] = 'application/json';
3330
+ body = this.json(params);
3331
+ }
3332
+ }
3333
+ url = this.urls['api']['rest'] + url;
3334
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
3335
+ }
3336
+ handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3337
+ if (response === undefined) {
3338
+ return undefined; // fallback to default error handler
3339
+ }
3340
+ //
3341
+ // {"code": 6010, "message": "Not enough balance."}
3342
+ // {"code": 60060, "message": "The order is already filled or canceled."}
3343
+ // {"code":2100,"message":"ApiKeyFailure"}
3344
+ // {"code":300001,"message":"Price is too low from market price.","reason":"INVALID_PRICE","accountId":"cshrHKLZCjlZ2ejqkmvIHHtPmLYqdnda","ac":"CASH","action":"place-order","status":"Err","info":{"symbol":"BTC/USDT"}}
3345
+ //
3346
+ const code = this.safeString(response, 'code');
3347
+ const message = this.safeString(response, 'message');
3348
+ const error = (code !== undefined) && (code !== '0');
3349
+ if (error || (message !== undefined)) {
3350
+ const feedback = this.id + ' ' + body;
3351
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
3352
+ this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
3353
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
3354
+ throw new errors.ExchangeError(feedback); // unknown message
3355
+ }
3356
+ return undefined;
3357
+ }
3358
+ }
3359
+
3360
+ module.exports = ascendex;