ccxt 4.2.11 → 4.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (392) hide show
  1. package/README.md +5 -5
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +1347 -490
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/_virtual/agent.js +7 -0
  6. package/dist/cjs/_virtual/parse-proxy-response.js +7 -0
  7. package/dist/cjs/_virtual/promisify.js +7 -0
  8. package/dist/cjs/ccxt.js +1 -1
  9. package/dist/cjs/js/ccxt.js +474 -0
  10. package/dist/cjs/js/src/abstract/ace.js +9 -0
  11. package/dist/cjs/js/src/abstract/alpaca.js +9 -0
  12. package/dist/cjs/js/src/abstract/ascendex.js +9 -0
  13. package/dist/cjs/js/src/abstract/bigone.js +9 -0
  14. package/dist/cjs/js/src/abstract/binance.js +9 -0
  15. package/dist/cjs/js/src/abstract/bingx.js +9 -0
  16. package/dist/cjs/js/src/abstract/bit2c.js +9 -0
  17. package/dist/cjs/js/src/abstract/bitbank.js +9 -0
  18. package/dist/cjs/js/src/abstract/bitbns.js +9 -0
  19. package/dist/cjs/js/src/abstract/bitfinex.js +9 -0
  20. package/dist/cjs/js/src/abstract/bitfinex2.js +9 -0
  21. package/dist/cjs/js/src/abstract/bitflyer.js +9 -0
  22. package/dist/cjs/js/src/abstract/bitforex.js +9 -0
  23. package/dist/cjs/js/src/abstract/bitget.js +9 -0
  24. package/dist/cjs/js/src/abstract/bithumb.js +9 -0
  25. package/dist/cjs/js/src/abstract/bitmart.js +9 -0
  26. package/dist/cjs/js/src/abstract/bitmex.js +9 -0
  27. package/dist/cjs/js/src/abstract/bitopro.js +9 -0
  28. package/dist/cjs/js/src/abstract/bitpanda.js +9 -0
  29. package/dist/cjs/js/src/abstract/bitrue.js +9 -0
  30. package/dist/cjs/js/src/abstract/bitso.js +9 -0
  31. package/dist/cjs/js/src/abstract/bitstamp.js +9 -0
  32. package/dist/cjs/js/src/abstract/bitteam.js +9 -0
  33. package/dist/cjs/js/src/abstract/bitvavo.js +9 -0
  34. package/dist/cjs/js/src/abstract/bl3p.js +9 -0
  35. package/dist/cjs/js/src/abstract/blockchaincom.js +9 -0
  36. package/dist/cjs/js/src/abstract/btcalpha.js +9 -0
  37. package/dist/cjs/js/src/abstract/btcbox.js +9 -0
  38. package/dist/cjs/js/src/abstract/btcmarkets.js +9 -0
  39. package/dist/cjs/js/src/abstract/btcturk.js +9 -0
  40. package/dist/cjs/js/src/abstract/bybit.js +9 -0
  41. package/dist/cjs/js/src/abstract/cex.js +9 -0
  42. package/dist/cjs/js/src/abstract/coinbase.js +9 -0
  43. package/dist/cjs/js/src/abstract/coinbasepro.js +9 -0
  44. package/dist/cjs/js/src/abstract/coincheck.js +9 -0
  45. package/dist/cjs/js/src/abstract/coinex.js +9 -0
  46. package/dist/cjs/js/src/abstract/coinlist.js +9 -0
  47. package/dist/cjs/js/src/abstract/coinmate.js +9 -0
  48. package/dist/cjs/js/src/abstract/coinone.js +9 -0
  49. package/dist/cjs/js/src/abstract/coinsph.js +9 -0
  50. package/dist/cjs/js/src/abstract/coinspot.js +9 -0
  51. package/dist/cjs/js/src/abstract/cryptocom.js +9 -0
  52. package/dist/cjs/js/src/abstract/currencycom.js +9 -0
  53. package/dist/cjs/js/src/abstract/delta.js +9 -0
  54. package/dist/cjs/js/src/abstract/deribit.js +9 -0
  55. package/dist/cjs/js/src/abstract/digifinex.js +9 -0
  56. package/dist/cjs/js/src/abstract/exmo.js +9 -0
  57. package/dist/cjs/js/src/abstract/gate.js +9 -0
  58. package/dist/cjs/js/src/abstract/gemini.js +9 -0
  59. package/dist/cjs/js/src/abstract/hitbtc.js +9 -0
  60. package/dist/cjs/js/src/abstract/hollaex.js +9 -0
  61. package/dist/cjs/js/src/abstract/htx.js +9 -0
  62. package/dist/cjs/js/src/abstract/huobijp.js +9 -0
  63. package/dist/cjs/js/src/abstract/idex.js +9 -0
  64. package/dist/cjs/js/src/abstract/independentreserve.js +9 -0
  65. package/dist/cjs/js/src/abstract/indodax.js +9 -0
  66. package/dist/cjs/js/src/abstract/kraken.js +9 -0
  67. package/dist/cjs/js/src/abstract/krakenfutures.js +9 -0
  68. package/dist/cjs/js/src/abstract/kucoin.js +9 -0
  69. package/dist/cjs/js/src/abstract/kucoinfutures.js +9 -0
  70. package/dist/cjs/js/src/abstract/kuna.js +9 -0
  71. package/dist/cjs/js/src/abstract/latoken.js +9 -0
  72. package/dist/cjs/js/src/abstract/lbank.js +9 -0
  73. package/dist/cjs/js/src/abstract/luno.js +9 -0
  74. package/dist/cjs/js/src/abstract/lykke.js +9 -0
  75. package/dist/cjs/js/src/abstract/mercado.js +9 -0
  76. package/dist/cjs/js/src/abstract/mexc.js +9 -0
  77. package/dist/cjs/js/src/abstract/ndax.js +9 -0
  78. package/dist/cjs/js/src/abstract/novadax.js +9 -0
  79. package/dist/cjs/js/src/abstract/oceanex.js +9 -0
  80. package/dist/cjs/js/src/abstract/okcoin.js +9 -0
  81. package/dist/cjs/js/src/abstract/okx.js +9 -0
  82. package/dist/cjs/js/src/abstract/p2b.js +9 -0
  83. package/dist/cjs/js/src/abstract/paymium.js +9 -0
  84. package/dist/cjs/js/src/abstract/phemex.js +9 -0
  85. package/dist/cjs/js/src/abstract/poloniex.js +9 -0
  86. package/dist/cjs/js/src/abstract/poloniexfutures.js +9 -0
  87. package/dist/cjs/js/src/abstract/probit.js +9 -0
  88. package/dist/cjs/js/src/abstract/timex.js +9 -0
  89. package/dist/cjs/js/src/abstract/tokocrypto.js +9 -0
  90. package/dist/cjs/js/src/abstract/upbit.js +9 -0
  91. package/dist/cjs/js/src/abstract/wavesexchange.js +9 -0
  92. package/dist/cjs/js/src/abstract/wazirx.js +9 -0
  93. package/dist/cjs/js/src/abstract/whitebit.js +9 -0
  94. package/dist/cjs/js/src/abstract/woo.js +9 -0
  95. package/dist/cjs/js/src/abstract/yobit.js +9 -0
  96. package/dist/cjs/js/src/abstract/zaif.js +9 -0
  97. package/dist/cjs/js/src/abstract/zonda.js +9 -0
  98. package/dist/cjs/js/src/ace.js +1058 -0
  99. package/dist/cjs/js/src/alpaca.js +1125 -0
  100. package/dist/cjs/js/src/ascendex.js +3360 -0
  101. package/dist/cjs/js/src/base/Exchange.js +5110 -0
  102. package/dist/cjs/js/src/base/Precise.js +263 -0
  103. package/dist/cjs/js/src/base/errors.js +299 -0
  104. package/dist/cjs/js/src/base/functions/crypto.js +78 -0
  105. package/dist/cjs/js/src/base/functions/encode.js +44 -0
  106. package/dist/cjs/js/src/base/functions/generic.js +193 -0
  107. package/dist/cjs/js/src/base/functions/misc.js +96 -0
  108. package/dist/cjs/js/src/base/functions/number.js +297 -0
  109. package/dist/cjs/js/src/base/functions/platform.js +28 -0
  110. package/dist/cjs/js/src/base/functions/rsa.js +34 -0
  111. package/dist/cjs/js/src/base/functions/string.js +48 -0
  112. package/dist/cjs/js/src/base/functions/throttle.js +66 -0
  113. package/dist/cjs/js/src/base/functions/time.js +187 -0
  114. package/dist/cjs/js/src/base/functions/totp.js +24 -0
  115. package/dist/cjs/js/src/base/functions/type.js +162 -0
  116. package/dist/cjs/js/src/base/functions.js +157 -0
  117. package/dist/cjs/js/src/base/ws/Cache.js +254 -0
  118. package/dist/cjs/js/src/base/ws/Client.js +299 -0
  119. package/dist/cjs/js/src/base/ws/Future.js +34 -0
  120. package/dist/cjs/js/src/base/ws/OrderBook.js +107 -0
  121. package/dist/cjs/js/src/base/ws/OrderBookSide.js +281 -0
  122. package/dist/cjs/js/src/base/ws/WsClient.js +69 -0
  123. package/dist/cjs/js/src/bequant.js +33 -0
  124. package/dist/cjs/js/src/bigone.js +2209 -0
  125. package/dist/cjs/js/src/binance.js +9736 -0
  126. package/dist/cjs/js/src/binancecoinm.js +45 -0
  127. package/dist/cjs/js/src/binanceus.js +84 -0
  128. package/dist/cjs/js/src/binanceusdm.js +58 -0
  129. package/dist/cjs/js/src/bingx.js +3807 -0
  130. package/dist/cjs/js/src/bit2c.js +916 -0
  131. package/dist/cjs/js/src/bitbank.js +1000 -0
  132. package/dist/cjs/js/src/bitbay.js +17 -0
  133. package/dist/cjs/js/src/bitbns.js +1220 -0
  134. package/dist/cjs/js/src/bitcoincom.js +17 -0
  135. package/dist/cjs/js/src/bitfinex.js +1670 -0
  136. package/dist/cjs/js/src/bitfinex2.js +2990 -0
  137. package/dist/cjs/js/src/bitflyer.js +1045 -0
  138. package/dist/cjs/js/src/bitforex.js +852 -0
  139. package/dist/cjs/js/src/bitget.js +8291 -0
  140. package/dist/cjs/js/src/bithumb.js +1090 -0
  141. package/dist/cjs/js/src/bitmart.js +4454 -0
  142. package/dist/cjs/js/src/bitmex.js +2884 -0
  143. package/dist/cjs/js/src/bitopro.js +1724 -0
  144. package/dist/cjs/js/src/bitpanda.js +2002 -0
  145. package/dist/cjs/js/src/bitrue.js +3253 -0
  146. package/dist/cjs/js/src/bitso.js +1753 -0
  147. package/dist/cjs/js/src/bitstamp.js +2188 -0
  148. package/dist/cjs/js/src/bitteam.js +2309 -0
  149. package/dist/cjs/js/src/bitvavo.js +1968 -0
  150. package/dist/cjs/js/src/bl3p.js +447 -0
  151. package/dist/cjs/js/src/blockchaincom.js +1160 -0
  152. package/dist/cjs/js/src/btcalpha.js +929 -0
  153. package/dist/cjs/js/src/btcbox.js +565 -0
  154. package/dist/cjs/js/src/btcmarkets.js +1237 -0
  155. package/dist/cjs/js/src/btcturk.js +929 -0
  156. package/dist/cjs/js/src/bybit.js +7646 -0
  157. package/dist/cjs/js/src/cex.js +1693 -0
  158. package/dist/cjs/js/src/coinbase.js +3424 -0
  159. package/dist/cjs/js/src/coinbasepro.js +1866 -0
  160. package/dist/cjs/js/src/coincheck.js +843 -0
  161. package/dist/cjs/js/src/coinex.js +5414 -0
  162. package/dist/cjs/js/src/coinlist.js +2329 -0
  163. package/dist/cjs/js/src/coinmate.js +989 -0
  164. package/dist/cjs/js/src/coinone.js +1185 -0
  165. package/dist/cjs/js/src/coinsph.js +1933 -0
  166. package/dist/cjs/js/src/coinspot.js +548 -0
  167. package/dist/cjs/js/src/cryptocom.js +3007 -0
  168. package/dist/cjs/js/src/currencycom.js +2015 -0
  169. package/dist/cjs/js/src/delta.js +3256 -0
  170. package/dist/cjs/js/src/deribit.js +3306 -0
  171. package/dist/cjs/js/src/digifinex.js +4307 -0
  172. package/dist/cjs/js/src/exmo.js +2645 -0
  173. package/dist/cjs/js/src/fmfwio.js +34 -0
  174. package/dist/cjs/js/src/gate.js +7072 -0
  175. package/dist/cjs/js/src/gateio.js +16 -0
  176. package/dist/cjs/js/src/gemini.js +1801 -0
  177. package/dist/cjs/js/src/hitbtc.js +3660 -0
  178. package/dist/cjs/js/src/hitbtc3.js +19 -0
  179. package/dist/cjs/js/src/hollaex.js +1882 -0
  180. package/dist/cjs/js/src/htx.js +9049 -0
  181. package/dist/cjs/js/src/huobi.js +16 -0
  182. package/dist/cjs/js/src/huobijp.js +1918 -0
  183. package/dist/cjs/js/src/idex.js +1770 -0
  184. package/dist/cjs/js/src/independentreserve.js +761 -0
  185. package/dist/cjs/js/src/indodax.js +1069 -0
  186. package/dist/cjs/js/src/kraken.js +2857 -0
  187. package/dist/cjs/js/src/krakenfutures.js +2407 -0
  188. package/dist/cjs/js/src/kucoin.js +4489 -0
  189. package/dist/cjs/js/src/kucoinfutures.js +2475 -0
  190. package/dist/cjs/js/src/kuna.js +1949 -0
  191. package/dist/cjs/js/src/latoken.js +1729 -0
  192. package/dist/cjs/js/src/lbank.js +2851 -0
  193. package/dist/cjs/js/src/luno.js +1044 -0
  194. package/dist/cjs/js/src/lykke.js +1303 -0
  195. package/dist/cjs/js/src/mercado.js +897 -0
  196. package/dist/cjs/js/src/mexc.js +5407 -0
  197. package/dist/cjs/js/src/ndax.js +2450 -0
  198. package/dist/cjs/js/src/novadax.js +1556 -0
  199. package/dist/cjs/js/src/oceanex.js +964 -0
  200. package/dist/cjs/js/src/okcoin.js +3115 -0
  201. package/dist/cjs/js/src/okx.js +7330 -0
  202. package/dist/cjs/js/src/p2b.js +1243 -0
  203. package/dist/cjs/js/src/paymium.js +597 -0
  204. package/dist/cjs/js/src/phemex.js +4722 -0
  205. package/dist/cjs/js/src/poloniex.js +2356 -0
  206. package/dist/cjs/js/src/poloniexfutures.js +1794 -0
  207. package/dist/cjs/js/src/pro/alpaca.js +714 -0
  208. package/dist/cjs/js/src/pro/ascendex.js +957 -0
  209. package/dist/cjs/js/src/pro/bequant.js +33 -0
  210. package/dist/cjs/js/src/pro/binance.js +2796 -0
  211. package/dist/cjs/js/src/pro/binancecoinm.js +23 -0
  212. package/dist/cjs/js/src/pro/binanceus.js +51 -0
  213. package/dist/cjs/js/src/pro/binanceusdm.js +32 -0
  214. package/dist/cjs/js/src/pro/bingx.js +944 -0
  215. package/dist/cjs/js/src/pro/bitcoincom.js +29 -0
  216. package/dist/cjs/js/src/pro/bitfinex.js +672 -0
  217. package/dist/cjs/js/src/pro/bitfinex2.js +1159 -0
  218. package/dist/cjs/js/src/pro/bitget.js +1733 -0
  219. package/dist/cjs/js/src/pro/bitmart.js +1486 -0
  220. package/dist/cjs/js/src/pro/bitmex.js +1576 -0
  221. package/dist/cjs/js/src/pro/bitopro.js +327 -0
  222. package/dist/cjs/js/src/pro/bitpanda.js +1341 -0
  223. package/dist/cjs/js/src/pro/bitrue.js +462 -0
  224. package/dist/cjs/js/src/pro/bitstamp.js +547 -0
  225. package/dist/cjs/js/src/pro/bitvavo.js +704 -0
  226. package/dist/cjs/js/src/pro/blockchaincom.js +794 -0
  227. package/dist/cjs/js/src/pro/bybit.js +1843 -0
  228. package/dist/cjs/js/src/pro/cex.js +1510 -0
  229. package/dist/cjs/js/src/pro/coinbase.js +561 -0
  230. package/dist/cjs/js/src/pro/coinbasepro.js +968 -0
  231. package/dist/cjs/js/src/pro/coinex.js +1095 -0
  232. package/dist/cjs/js/src/pro/cryptocom.js +1020 -0
  233. package/dist/cjs/js/src/pro/currencycom.js +563 -0
  234. package/dist/cjs/js/src/pro/deribit.js +825 -0
  235. package/dist/cjs/js/src/pro/exmo.js +658 -0
  236. package/dist/cjs/js/src/pro/gate.js +1316 -0
  237. package/dist/cjs/js/src/pro/gateio.js +16 -0
  238. package/dist/cjs/js/src/pro/gemini.js +649 -0
  239. package/dist/cjs/js/src/pro/hitbtc.js +1293 -0
  240. package/dist/cjs/js/src/pro/hollaex.js +597 -0
  241. package/dist/cjs/js/src/pro/htx.js +2383 -0
  242. package/dist/cjs/js/src/pro/huobi.js +16 -0
  243. package/dist/cjs/js/src/pro/huobijp.js +606 -0
  244. package/dist/cjs/js/src/pro/idex.js +714 -0
  245. package/dist/cjs/js/src/pro/independentreserve.js +280 -0
  246. package/dist/cjs/js/src/pro/kraken.js +1364 -0
  247. package/dist/cjs/js/src/pro/krakenfutures.js +1500 -0
  248. package/dist/cjs/js/src/pro/kucoin.js +1052 -0
  249. package/dist/cjs/js/src/pro/kucoinfutures.js +981 -0
  250. package/dist/cjs/js/src/pro/luno.js +322 -0
  251. package/dist/cjs/js/src/pro/mexc.js +1170 -0
  252. package/dist/cjs/js/src/pro/ndax.js +545 -0
  253. package/dist/cjs/js/src/pro/okcoin.js +760 -0
  254. package/dist/cjs/js/src/pro/okx.js +1608 -0
  255. package/dist/cjs/js/src/pro/phemex.js +1511 -0
  256. package/dist/cjs/js/src/pro/poloniex.js +1253 -0
  257. package/dist/cjs/js/src/pro/poloniexfutures.js +1014 -0
  258. package/dist/cjs/js/src/pro/probit.js +586 -0
  259. package/dist/cjs/js/src/pro/upbit.js +234 -0
  260. package/dist/cjs/js/src/pro/wazirx.js +776 -0
  261. package/dist/cjs/js/src/pro/whitebit.js +927 -0
  262. package/dist/cjs/js/src/pro/woo.js +769 -0
  263. package/dist/cjs/js/src/probit.js +1867 -0
  264. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +401 -0
  265. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +195 -0
  266. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +308 -0
  267. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +554 -0
  268. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +94 -0
  269. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +70 -0
  270. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +91 -0
  271. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +16 -0
  272. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +1760 -0
  273. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +52 -0
  274. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +81 -0
  275. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +376 -0
  276. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +70 -0
  277. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +1580 -0
  278. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +74 -0
  279. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +24 -0
  280. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +158 -0
  281. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +429 -0
  282. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +176 -0
  283. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +324 -0
  284. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +163 -0
  285. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +245 -0
  286. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1018 -0
  287. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +383 -0
  288. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +258 -0
  289. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +53 -0
  290. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +120 -0
  291. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +69 -0
  292. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +7 -0
  293. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +83 -0
  294. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +240 -0
  295. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +91 -0
  296. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +130 -0
  297. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +214 -0
  298. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +239 -0
  299. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +93 -0
  300. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +354 -0
  301. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +16 -0
  302. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +20 -0
  303. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +30 -0
  304. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +239 -0
  305. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +372 -0
  306. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +273 -0
  307. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +139 -0
  308. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +14 -0
  309. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +16 -0
  310. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +81 -0
  311. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +292 -0
  312. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +103 -0
  313. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +140 -0
  314. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +175 -0
  315. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +95 -0
  316. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +7 -0
  317. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +383 -0
  318. package/dist/cjs/js/src/timex.js +1562 -0
  319. package/dist/cjs/js/src/tokocrypto.js +2542 -0
  320. package/dist/cjs/js/src/upbit.js +1844 -0
  321. package/dist/cjs/js/src/wavesexchange.js +2607 -0
  322. package/dist/cjs/js/src/wazirx.js +953 -0
  323. package/dist/cjs/js/src/whitebit.js +2309 -0
  324. package/dist/cjs/js/src/woo.js +2765 -0
  325. package/dist/cjs/js/src/yobit.js +1314 -0
  326. package/dist/cjs/js/src/zaif.js +736 -0
  327. package/dist/cjs/js/src/zonda.js +1883 -0
  328. package/js/ccxt.d.ts +1 -1
  329. package/js/ccxt.js +1 -1
  330. package/js/src/abstract/bigone.d.ts +18 -0
  331. package/js/src/abstract/binance.d.ts +2 -0
  332. package/js/src/abstract/binancecoinm.d.ts +2 -0
  333. package/js/src/abstract/binanceus.d.ts +2 -0
  334. package/js/src/abstract/binanceusdm.d.ts +2 -0
  335. package/js/src/abstract/bingx.d.ts +2 -0
  336. package/js/src/abstract/bybit.d.ts +1 -0
  337. package/js/src/abstract/gate.d.ts +11 -0
  338. package/js/src/abstract/gateio.d.ts +11 -0
  339. package/js/src/abstract/okx.d.ts +1 -0
  340. package/js/src/alpaca.js +18 -18
  341. package/js/src/base/Exchange.d.ts +5 -1
  342. package/js/src/base/Exchange.js +101 -12
  343. package/js/src/bigone.d.ts +3 -2
  344. package/js/src/bigone.js +429 -167
  345. package/js/src/binance.js +48 -34
  346. package/js/src/bingx.js +115 -38
  347. package/js/src/bitfinex.d.ts +2 -2
  348. package/js/src/bitfinex.js +2 -3
  349. package/js/src/bitget.js +33 -13
  350. package/js/src/bitmart.d.ts +2 -2
  351. package/js/src/bitmart.js +5 -5
  352. package/js/src/bitmex.js +1 -0
  353. package/js/src/bybit.js +2 -0
  354. package/js/src/coinbase.d.ts +26 -3
  355. package/js/src/coinbase.js +176 -26
  356. package/js/src/coinlist.js +3 -4
  357. package/js/src/coinone.js +1 -1
  358. package/js/src/coinsph.js +2 -3
  359. package/js/src/deribit.js +1 -0
  360. package/js/src/gate.d.ts +4 -4
  361. package/js/src/gate.js +96 -59
  362. package/js/src/gemini.js +1 -1
  363. package/js/src/hitbtc.d.ts +4 -4
  364. package/js/src/hitbtc.js +2 -3
  365. package/js/src/htx.d.ts +1 -0
  366. package/js/src/htx.js +29 -7
  367. package/js/src/huobijp.js +2 -3
  368. package/js/src/independentreserve.js +7 -5
  369. package/js/src/kraken.js +3 -6
  370. package/js/src/lbank.js +59 -33
  371. package/js/src/mexc.js +2 -1
  372. package/js/src/oceanex.js +1 -1
  373. package/js/src/okx.js +14 -3
  374. package/js/src/phemex.js +9 -2
  375. package/js/src/pro/binance.d.ts +2 -23
  376. package/js/src/pro/binance.js +58 -22
  377. package/js/src/pro/coinbase.d.ts +2 -2
  378. package/js/src/pro/coinbase.js +4 -1
  379. package/js/src/pro/coinbasepro.d.ts +2 -2
  380. package/js/src/pro/hitbtc.d.ts +2 -2
  381. package/js/src/pro/kraken.js +1 -1
  382. package/js/src/pro/okx.d.ts +1 -0
  383. package/js/src/pro/okx.js +52 -2
  384. package/js/src/pro/poloniex.d.ts +2 -2
  385. package/js/src/probit.js +4 -2
  386. package/js/src/upbit.d.ts +3 -101
  387. package/js/src/upbit.js +12 -12
  388. package/js/src/wavesexchange.js +1 -1
  389. package/js/src/woo.d.ts +2 -0
  390. package/js/src/woo.js +52 -0
  391. package/package.json +1 -1
  392. package/skip-tests.json +5 -0
@@ -0,0 +1,2450 @@
1
+ 'use strict';
2
+
3
+ var ndax$1 = require('./abstract/ndax.js');
4
+ var errors = require('./base/errors.js');
5
+ var number = require('./base/functions/number.js');
6
+ var Precise = require('./base/Precise.js');
7
+ var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
+ var totp = require('./base/functions/totp.js');
9
+
10
+ // ---------------------------------------------------------------------------
11
+ // ---------------------------------------------------------------------------
12
+ /**
13
+ * @class ndax
14
+ * @augments Exchange
15
+ */
16
+ class ndax extends ndax$1 {
17
+ describe() {
18
+ return this.deepExtend(super.describe(), {
19
+ 'id': 'ndax',
20
+ 'name': 'NDAX',
21
+ 'countries': ['CA'],
22
+ 'rateLimit': 1000,
23
+ 'pro': true,
24
+ 'has': {
25
+ 'CORS': undefined,
26
+ 'spot': true,
27
+ 'margin': false,
28
+ 'swap': false,
29
+ 'future': false,
30
+ 'option': false,
31
+ 'addMargin': false,
32
+ 'cancelAllOrders': true,
33
+ 'cancelOrder': true,
34
+ 'closeAllPositions': false,
35
+ 'closePosition': false,
36
+ 'createDepositAddress': true,
37
+ 'createOrder': true,
38
+ 'createReduceOnlyOrder': false,
39
+ 'createStopLimitOrder': true,
40
+ 'createStopMarketOrder': true,
41
+ 'createStopOrder': true,
42
+ 'editOrder': true,
43
+ 'fetchAccounts': true,
44
+ 'fetchBalance': true,
45
+ 'fetchBorrowRateHistories': false,
46
+ 'fetchBorrowRateHistory': false,
47
+ 'fetchCrossBorrowRate': false,
48
+ 'fetchCrossBorrowRates': false,
49
+ 'fetchCurrencies': true,
50
+ 'fetchDepositAddress': true,
51
+ 'fetchDeposits': true,
52
+ 'fetchFundingHistory': false,
53
+ 'fetchFundingRate': false,
54
+ 'fetchFundingRateHistory': false,
55
+ 'fetchFundingRates': false,
56
+ 'fetchIndexOHLCV': false,
57
+ 'fetchIsolatedBorrowRate': false,
58
+ 'fetchIsolatedBorrowRates': false,
59
+ 'fetchLedger': true,
60
+ 'fetchLeverage': false,
61
+ 'fetchLeverageTiers': false,
62
+ 'fetchMarkets': true,
63
+ 'fetchMarkOHLCV': false,
64
+ 'fetchMyTrades': true,
65
+ 'fetchOHLCV': true,
66
+ 'fetchOpenInterestHistory': false,
67
+ 'fetchOpenOrders': true,
68
+ 'fetchOrder': true,
69
+ 'fetchOrderBook': true,
70
+ 'fetchOrders': true,
71
+ 'fetchOrderTrades': true,
72
+ 'fetchPosition': false,
73
+ 'fetchPositions': false,
74
+ 'fetchPositionsRisk': false,
75
+ 'fetchPremiumIndexOHLCV': false,
76
+ 'fetchTicker': true,
77
+ 'fetchTickers': false,
78
+ 'fetchTime': false,
79
+ 'fetchTrades': true,
80
+ 'fetchTradingFee': false,
81
+ 'fetchTradingFees': false,
82
+ 'fetchWithdrawals': true,
83
+ 'reduceMargin': false,
84
+ 'setLeverage': false,
85
+ 'setMarginMode': false,
86
+ 'setPositionMode': false,
87
+ 'signIn': true,
88
+ 'transfer': false,
89
+ 'withdraw': true,
90
+ },
91
+ 'timeframes': {
92
+ '1m': '60',
93
+ '5m': '300',
94
+ '15m': '900',
95
+ '30m': '1800',
96
+ '1h': '3600',
97
+ '2h': '7200',
98
+ '4h': '14400',
99
+ '6h': '21600',
100
+ '12h': '43200',
101
+ '1d': '86400',
102
+ '1w': '604800',
103
+ '1M': '2419200',
104
+ '4M': '9676800',
105
+ },
106
+ 'urls': {
107
+ 'logo': 'https://user-images.githubusercontent.com/1294454/108623144-67a3ef00-744e-11eb-8140-75c6b851e945.jpg',
108
+ 'test': {
109
+ 'public': 'https://ndaxmarginstaging.cdnhop.net:8443/AP',
110
+ 'private': 'https://ndaxmarginstaging.cdnhop.net:8443/AP',
111
+ },
112
+ 'api': {
113
+ 'public': 'https://api.ndax.io:8443/AP',
114
+ 'private': 'https://api.ndax.io:8443/AP',
115
+ },
116
+ 'www': 'https://ndax.io',
117
+ 'doc': [
118
+ 'https://apidoc.ndax.io/',
119
+ ],
120
+ 'fees': 'https://ndax.io/fees',
121
+ 'referral': 'https://one.ndax.io/bfQiSL',
122
+ },
123
+ 'api': {
124
+ 'public': {
125
+ 'get': {
126
+ 'Activate2FA': 1,
127
+ 'Authenticate2FA': 1,
128
+ 'AuthenticateUser': 1,
129
+ 'GetL2Snapshot': 1,
130
+ 'GetLevel1': 1,
131
+ 'GetValidate2FARequiredEndpoints': 1,
132
+ 'LogOut': 1,
133
+ 'GetTickerHistory': 1,
134
+ 'GetProduct': 1,
135
+ 'GetProducts': 1,
136
+ 'GetInstrument': 1,
137
+ 'GetInstruments': 1,
138
+ 'Ping': 1,
139
+ 'trades': 1,
140
+ 'GetLastTrades': 1,
141
+ 'SubscribeLevel1': 1,
142
+ 'SubscribeLevel2': 1,
143
+ 'SubscribeTicker': 1,
144
+ 'SubscribeTrades': 1,
145
+ 'SubscribeBlockTrades': 1,
146
+ 'UnsubscribeBlockTrades': 1,
147
+ 'UnsubscribeLevel1': 1,
148
+ 'UnsubscribeLevel2': 1,
149
+ 'UnsubscribeTicker': 1,
150
+ 'UnsubscribeTrades': 1,
151
+ 'Authenticate': 1, // undocumented
152
+ },
153
+ },
154
+ 'private': {
155
+ 'get': {
156
+ 'GetUserAccountInfos': 1,
157
+ 'GetUserAccounts': 1,
158
+ 'GetUserAffiliateCount': 1,
159
+ 'GetUserAffiliateTag': 1,
160
+ 'GetUserConfig': 1,
161
+ 'GetAllUnredactedUserConfigsForUser': 1,
162
+ 'GetUnredactedUserConfigByKey': 1,
163
+ 'GetUserDevices': 1,
164
+ 'GetUserReportTickets': 1,
165
+ 'GetUserReportWriterResultRecords': 1,
166
+ 'GetAccountInfo': 1,
167
+ 'GetAccountPositions': 1,
168
+ 'GetAllAccountConfigs': 1,
169
+ 'GetTreasuryProductsForAccount': 1,
170
+ 'GetAccountTrades': 1,
171
+ 'GetAccountTransactions': 1,
172
+ 'GetOpenTradeReports': 1,
173
+ 'GetAllOpenTradeReports': 1,
174
+ 'GetTradesHistory': 1,
175
+ 'GetOpenOrders': 1,
176
+ 'GetOpenQuotes': 1,
177
+ 'GetOrderFee': 1,
178
+ 'GetOrderHistory': 1,
179
+ 'GetOrdersHistory': 1,
180
+ 'GetOrderStatus': 1,
181
+ 'GetOmsFeeTiers': 1,
182
+ 'GetAccountDepositTransactions': 1,
183
+ 'GetAccountWithdrawTransactions': 1,
184
+ 'GetAllDepositRequestInfoTemplates': 1,
185
+ 'GetDepositInfo': 1,
186
+ 'GetDepositRequestInfoTemplate': 1,
187
+ 'GetDeposits': 1,
188
+ 'GetDepositTicket': 1,
189
+ 'GetDepositTickets': 1,
190
+ 'GetOMSWithdrawFees': 1,
191
+ 'GetWithdrawFee': 1,
192
+ 'GetWithdraws': 1,
193
+ 'GetWithdrawTemplate': 1,
194
+ 'GetWithdrawTemplateTypes': 1,
195
+ 'GetWithdrawTicket': 1,
196
+ 'GetWithdrawTickets': 1,
197
+ },
198
+ 'post': {
199
+ 'AddUserAffiliateTag': 1,
200
+ 'CancelUserReport': 1,
201
+ 'RegisterNewDevice': 1,
202
+ 'SubscribeAccountEvents': 1,
203
+ 'UpdateUserAffiliateTag': 1,
204
+ 'GenerateTradeActivityReport': 1,
205
+ 'GenerateTransactionActivityReport': 1,
206
+ 'GenerateTreasuryActivityReport': 1,
207
+ 'ScheduleTradeActivityReport': 1,
208
+ 'ScheduleTransactionActivityReport': 1,
209
+ 'ScheduleTreasuryActivityReport': 1,
210
+ 'CancelAllOrders': 1,
211
+ 'CancelOrder': 1,
212
+ 'CancelQuote': 1,
213
+ 'CancelReplaceOrder': 1,
214
+ 'CreateQuote': 1,
215
+ 'ModifyOrder': 1,
216
+ 'SendOrder': 1,
217
+ 'SubmitBlockTrade': 1,
218
+ 'UpdateQuote': 1,
219
+ 'CancelWithdraw': 1,
220
+ 'CreateDepositTicket': 1,
221
+ 'CreateWithdrawTicket': 1,
222
+ 'SubmitDepositTicketComment': 1,
223
+ 'SubmitWithdrawTicketComment': 1,
224
+ 'GetOrderHistoryByOrderId': 1,
225
+ },
226
+ },
227
+ },
228
+ 'fees': {
229
+ 'trading': {
230
+ 'tierBased': false,
231
+ 'percentage': true,
232
+ 'maker': this.parseNumber('0.002'),
233
+ 'taker': this.parseNumber('0.0025'),
234
+ },
235
+ },
236
+ 'requiredCredentials': {
237
+ 'apiKey': true,
238
+ 'secret': true,
239
+ 'uid': true,
240
+ // these credentials are required for signIn() and withdraw()
241
+ 'login': true,
242
+ 'password': true,
243
+ // 'twofa': true,
244
+ },
245
+ 'precisionMode': number.TICK_SIZE,
246
+ 'exceptions': {
247
+ 'exact': {
248
+ 'Not_Enough_Funds': errors.InsufficientFunds,
249
+ 'Server Error': errors.ExchangeError,
250
+ 'Resource Not Found': errors.OrderNotFound, // {"result":false,"errormsg":"Resource Not Found","errorcode":104,"detail":null}
251
+ },
252
+ 'broad': {
253
+ 'Invalid InstrumentId': errors.BadSymbol,
254
+ 'This endpoint requires 2FACode along with the payload': errors.AuthenticationError,
255
+ },
256
+ },
257
+ 'options': {
258
+ 'omsId': 1,
259
+ 'orderTypes': {
260
+ 'Market': 1,
261
+ 'Limit': 2,
262
+ 'StopMarket': 3,
263
+ 'StopLimit': 4,
264
+ 'TrailingStopMarket': 5,
265
+ 'TrailingStopLimit': 6,
266
+ 'BlockTrade': 7,
267
+ '1': 1,
268
+ '2': 2,
269
+ '3': 3,
270
+ '4': 4,
271
+ '5': 5,
272
+ '6': 6,
273
+ '7': 7,
274
+ },
275
+ },
276
+ });
277
+ }
278
+ async signIn(params = {}) {
279
+ /**
280
+ * @method
281
+ * @name ndax#signIn
282
+ * @description sign in, must be called prior to using other authenticated methods
283
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
284
+ * @returns response from exchange
285
+ */
286
+ this.checkRequiredCredentials();
287
+ if (this.login === undefined || this.password === undefined) {
288
+ throw new errors.AuthenticationError(this.id + ' signIn() requires exchange.login, exchange.password');
289
+ }
290
+ let request = {
291
+ 'grant_type': 'client_credentials', // the only supported value
292
+ };
293
+ const response = await this.publicGetAuthenticate(this.extend(request, params));
294
+ //
295
+ // {
296
+ // "Authenticated":true,
297
+ // "Requires2FA":true,
298
+ // "AuthType":"Google",
299
+ // "AddtlInfo":"",
300
+ // "Pending2FaToken": "6f5c4e66-f3ee-493e-9227-31cc0583b55f"
301
+ // }
302
+ //
303
+ let sessionToken = this.safeString(response, 'SessionToken');
304
+ if (sessionToken !== undefined) {
305
+ this.options['sessionToken'] = sessionToken;
306
+ return response;
307
+ }
308
+ const pending2faToken = this.safeString(response, 'Pending2FaToken');
309
+ if (pending2faToken !== undefined) {
310
+ if (this.twofa === undefined) {
311
+ throw new errors.AuthenticationError(this.id + ' signIn() requires exchange.twofa credentials');
312
+ }
313
+ this.options['pending2faToken'] = pending2faToken;
314
+ request = {
315
+ 'Code': totp.totp(this.twofa),
316
+ };
317
+ const responseInner = await this.publicGetAuthenticate2FA(this.extend(request, params));
318
+ //
319
+ // {
320
+ // "Authenticated": true,
321
+ // "UserId":57765,
322
+ // "SessionToken":"4a2a5857-c4e5-4fac-b09e-2c4c30b591a0"
323
+ // }
324
+ //
325
+ sessionToken = this.safeString(responseInner, 'SessionToken');
326
+ this.options['sessionToken'] = sessionToken;
327
+ return responseInner;
328
+ }
329
+ return response;
330
+ }
331
+ async fetchCurrencies(params = {}) {
332
+ /**
333
+ * @method
334
+ * @name ndax#fetchCurrencies
335
+ * @description fetches all available currencies on an exchange
336
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
337
+ * @returns {object} an associative dictionary of currencies
338
+ */
339
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
340
+ const request = {
341
+ 'omsId': omsId,
342
+ };
343
+ const response = await this.publicGetGetProducts(this.extend(request, params));
344
+ //
345
+ // [
346
+ // {
347
+ // "OMSId":1,
348
+ // "ProductId":1,
349
+ // "Product":"BTC",
350
+ // "ProductFullName":"Bitcoin",
351
+ // "ProductType":"CryptoCurrency",
352
+ // "DecimalPlaces":8,
353
+ // "TickSize":0.0000000100000000000000000000,
354
+ // "NoFees":false,
355
+ // "IsDisabled":false,
356
+ // "MarginEnabled":false
357
+ // },
358
+ // ]
359
+ //
360
+ const result = {};
361
+ for (let i = 0; i < response.length; i++) {
362
+ const currency = response[i];
363
+ const id = this.safeString(currency, 'ProductId');
364
+ const name = this.safeString(currency, 'ProductFullName');
365
+ const ProductType = this.safeString(currency, 'ProductType');
366
+ let type = (ProductType === 'NationalCurrency') ? 'fiat' : 'crypto';
367
+ if (ProductType === 'Unknown') {
368
+ // such currency is just a blanket entry
369
+ type = 'other';
370
+ }
371
+ const code = this.safeCurrencyCode(this.safeString(currency, 'Product'));
372
+ const isDisabled = this.safeValue(currency, 'IsDisabled');
373
+ const active = !isDisabled;
374
+ result[code] = {
375
+ 'id': id,
376
+ 'name': name,
377
+ 'code': code,
378
+ 'type': type,
379
+ 'precision': this.safeNumber(currency, 'TickSize'),
380
+ 'info': currency,
381
+ 'active': active,
382
+ 'deposit': undefined,
383
+ 'withdraw': undefined,
384
+ 'fee': undefined,
385
+ 'limits': {
386
+ 'amount': {
387
+ 'min': undefined,
388
+ 'max': undefined,
389
+ },
390
+ 'withdraw': {
391
+ 'min': undefined,
392
+ 'max': undefined,
393
+ },
394
+ },
395
+ 'networks': {},
396
+ };
397
+ }
398
+ return result;
399
+ }
400
+ async fetchMarkets(params = {}) {
401
+ /**
402
+ * @method
403
+ * @name ndax#fetchMarkets
404
+ * @description retrieves data on all markets for ndax
405
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
406
+ * @returns {object[]} an array of objects representing market data
407
+ */
408
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
409
+ const request = {
410
+ 'omsId': omsId,
411
+ };
412
+ const response = await this.publicGetGetInstruments(this.extend(request, params));
413
+ //
414
+ // [
415
+ // {
416
+ // "OMSId":1,
417
+ // "InstrumentId":3,
418
+ // "Symbol":"LTCBTC",
419
+ // "Product1":3,
420
+ // "Product1Symbol":"LTC",
421
+ // "Product2":1,
422
+ // "Product2Symbol":"BTC",
423
+ // "InstrumentType":"Standard",
424
+ // "VenueInstrumentId":3,
425
+ // "VenueId":1,
426
+ // "SortIndex":0,
427
+ // "SessionStatus":"Running",
428
+ // "PreviousSessionStatus":"Stopped",
429
+ // "SessionStatusDateTime":"2020-11-25T19:42:15.245Z",
430
+ // "SelfTradePrevention":true,
431
+ // "QuantityIncrement":0.0000000100000000000000000000,
432
+ // "PriceIncrement":0.0000000100000000000000000000,
433
+ // "MinimumQuantity":0.0100000000000000000000000000,
434
+ // "MinimumPrice":0.0000010000000000000000000000,
435
+ // "VenueSymbol":"LTCBTC",
436
+ // "IsDisable":false,
437
+ // "MasterDataId":0,
438
+ // "PriceCollarThreshold":0.0000000000000000000000000000,
439
+ // "PriceCollarPercent":0.0000000000000000000000000000,
440
+ // "PriceCollarEnabled":false,
441
+ // "PriceFloorLimit":0.0000000000000000000000000000,
442
+ // "PriceFloorLimitEnabled":false,
443
+ // "PriceCeilingLimit":0.0000000000000000000000000000,
444
+ // "PriceCeilingLimitEnabled":false,
445
+ // "CreateWithMarketRunning":true,
446
+ // "AllowOnlyMarketMakerCounterParty":false,
447
+ // "PriceCollarIndexDifference":0.0000000000000000000000000000,
448
+ // "PriceCollarConvertToOtcEnabled":false,
449
+ // "PriceCollarConvertToOtcClientUserId":0,
450
+ // "PriceCollarConvertToOtcAccountId":0,
451
+ // "PriceCollarConvertToOtcThreshold":0.0000000000000000000000000000,
452
+ // "OtcConvertSizeThreshold":0.0000000000000000000000000000,
453
+ // "OtcConvertSizeEnabled":false,
454
+ // "OtcTradesPublic":true,
455
+ // "PriceTier":0
456
+ // },
457
+ // ]
458
+ //
459
+ return this.parseMarkets(response);
460
+ }
461
+ parseMarket(market) {
462
+ const id = this.safeString(market, 'InstrumentId');
463
+ // const lowercaseId = this.safeStringLower (market, 'symbol');
464
+ const baseId = this.safeString(market, 'Product1');
465
+ const quoteId = this.safeString(market, 'Product2');
466
+ const base = this.safeCurrencyCode(this.safeString(market, 'Product1Symbol'));
467
+ const quote = this.safeCurrencyCode(this.safeString(market, 'Product2Symbol'));
468
+ const sessionStatus = this.safeString(market, 'SessionStatus');
469
+ const isDisable = this.safeValue(market, 'IsDisable');
470
+ const sessionRunning = (sessionStatus === 'Running');
471
+ return {
472
+ 'id': id,
473
+ 'symbol': base + '/' + quote,
474
+ 'base': base,
475
+ 'quote': quote,
476
+ 'settle': undefined,
477
+ 'baseId': baseId,
478
+ 'quoteId': quoteId,
479
+ 'settleId': undefined,
480
+ 'type': 'spot',
481
+ 'spot': true,
482
+ 'margin': false,
483
+ 'swap': false,
484
+ 'future': false,
485
+ 'option': false,
486
+ 'active': (sessionRunning && !isDisable),
487
+ 'contract': false,
488
+ 'linear': undefined,
489
+ 'inverse': undefined,
490
+ 'contractSize': undefined,
491
+ 'expiry': undefined,
492
+ 'expiryDatetime': undefined,
493
+ 'strike': undefined,
494
+ 'optionType': undefined,
495
+ 'precision': {
496
+ 'amount': this.safeNumber(market, 'QuantityIncrement'),
497
+ 'price': this.safeNumber(market, 'PriceIncrement'),
498
+ },
499
+ 'limits': {
500
+ 'leverage': {
501
+ 'min': undefined,
502
+ 'max': undefined,
503
+ },
504
+ 'amount': {
505
+ 'min': this.safeNumber(market, 'MinimumQuantity'),
506
+ 'max': undefined,
507
+ },
508
+ 'price': {
509
+ 'min': this.safeNumber(market, 'MinimumPrice'),
510
+ 'max': undefined,
511
+ },
512
+ 'cost': {
513
+ 'min': undefined,
514
+ 'max': undefined,
515
+ },
516
+ },
517
+ 'created': undefined,
518
+ 'info': market,
519
+ };
520
+ }
521
+ parseOrderBook(orderbook, symbol, timestamp = undefined, bidsKey = 'bids', asksKey = 'asks', priceKey = 6, amountKey = 8, countOrIdKey = 2) {
522
+ let nonce = undefined;
523
+ const result = {
524
+ 'symbol': symbol,
525
+ 'bids': [],
526
+ 'asks': [],
527
+ 'timestamp': undefined,
528
+ 'datetime': undefined,
529
+ 'nonce': undefined,
530
+ };
531
+ for (let i = 0; i < orderbook.length; i++) {
532
+ const level = orderbook[i];
533
+ if (timestamp === undefined) {
534
+ timestamp = this.safeInteger(level, 2);
535
+ }
536
+ else {
537
+ const newTimestamp = this.safeInteger(level, 2);
538
+ timestamp = Math.max(timestamp, newTimestamp);
539
+ }
540
+ if (nonce === undefined) {
541
+ nonce = this.safeInteger(level, 0);
542
+ }
543
+ else {
544
+ const newNonce = this.safeInteger(level, 0);
545
+ nonce = Math.max(nonce, newNonce);
546
+ }
547
+ const bidask = this.parseBidAsk(level, priceKey, amountKey);
548
+ const levelSide = this.safeInteger(level, 9);
549
+ const side = levelSide ? asksKey : bidsKey;
550
+ result[side].push(bidask);
551
+ }
552
+ result['bids'] = this.sortBy(result['bids'], 0, true);
553
+ result['asks'] = this.sortBy(result['asks'], 0);
554
+ result['timestamp'] = timestamp;
555
+ result['datetime'] = this.iso8601(timestamp);
556
+ result['nonce'] = nonce;
557
+ return result;
558
+ }
559
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
560
+ /**
561
+ * @method
562
+ * @name ndax#fetchOrderBook
563
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
564
+ * @param {string} symbol unified symbol of the market to fetch the order book for
565
+ * @param {int} [limit] the maximum amount of order book entries to return
566
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
567
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
568
+ */
569
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
570
+ await this.loadMarkets();
571
+ const market = this.market(symbol);
572
+ limit = (limit === undefined) ? 100 : limit; // default 100
573
+ const request = {
574
+ 'omsId': omsId,
575
+ 'InstrumentId': market['id'],
576
+ 'Depth': limit, // default 100
577
+ };
578
+ const response = await this.publicGetGetL2Snapshot(this.extend(request, params));
579
+ //
580
+ // [
581
+ // [
582
+ // 0, // 0 MDUpdateId
583
+ // 1, // 1 Number of Unique Accounts
584
+ // 123, // 2 ActionDateTime in Posix format X 1000
585
+ // 0, // 3 ActionType 0 (New), 1 (Update), 2(Delete)
586
+ // 0.0, // 4 LastTradePrice
587
+ // 0, // 5 Number of Orders
588
+ // 0.0, // 6 Price
589
+ // 0, // 7 ProductPairCode
590
+ // 0.0, // 8 Quantity
591
+ // 0, // 9 Side
592
+ // ],
593
+ // [97244115,1,1607456142963,0,19069.32,1,19069.31,8,0.140095,0],
594
+ // [97244115,0,1607456142963,0,19069.32,1,19068.64,8,0.0055,0],
595
+ // [97244115,0,1607456142963,0,19069.32,1,19068.26,8,0.021291,0],
596
+ // [97244115,1,1607456142964,0,19069.32,1,19069.32,8,0.099636,1],
597
+ // [97244115,0,1607456142964,0,19069.32,1,19069.98,8,0.1,1],
598
+ // [97244115,0,1607456142964,0,19069.32,1,19069.99,8,0.141604,1],
599
+ // ]
600
+ //
601
+ return this.parseOrderBook(response, symbol);
602
+ }
603
+ parseTicker(ticker, market = undefined) {
604
+ //
605
+ // fetchTicker
606
+ //
607
+ // {
608
+ // "OMSId":1,
609
+ // "InstrumentId":8,
610
+ // "BestBid":19069.31,
611
+ // "BestOffer":19069.32,
612
+ // "LastTradedPx":19069.32,
613
+ // "LastTradedQty":0.0001,
614
+ // "LastTradeTime":1607040406424,
615
+ // "SessionOpen":19069.32,
616
+ // "SessionHigh":19069.32,
617
+ // "SessionLow":19069.32,
618
+ // "SessionClose":19069.32,
619
+ // "Volume":0.0001,
620
+ // "CurrentDayVolume":0.0001,
621
+ // "CurrentDayNotional":1.906932,
622
+ // "CurrentDayNumTrades":1,
623
+ // "CurrentDayPxChange":0.00,
624
+ // "Rolling24HrVolume":0.000000000000000000000000000,
625
+ // "Rolling24HrNotional":0.00000000000000000000000,
626
+ // "Rolling24NumTrades":0,
627
+ // "Rolling24HrPxChange":0,
628
+ // "TimeStamp":"1607040406425",
629
+ // "BidQty":0,
630
+ // "AskQty":0,
631
+ // "BidOrderCt":0,
632
+ // "AskOrderCt":0,
633
+ // "Rolling24HrPxChangePercent":0,
634
+ // }
635
+ //
636
+ const timestamp = this.safeInteger(ticker, 'TimeStamp');
637
+ const marketId = this.safeString(ticker, 'InstrumentId');
638
+ market = this.safeMarket(marketId, market);
639
+ const symbol = this.safeSymbol(marketId, market);
640
+ const last = this.safeString(ticker, 'LastTradedPx');
641
+ const percentage = this.safeString(ticker, 'Rolling24HrPxChangePercent');
642
+ const change = this.safeString(ticker, 'Rolling24HrPxChange');
643
+ const open = this.safeString(ticker, 'SessionOpen');
644
+ const baseVolume = this.safeString(ticker, 'Rolling24HrVolume');
645
+ const quoteVolume = this.safeString(ticker, 'Rolling24HrNotional');
646
+ return this.safeTicker({
647
+ 'symbol': symbol,
648
+ 'timestamp': timestamp,
649
+ 'datetime': this.iso8601(timestamp),
650
+ 'high': this.safeString(ticker, 'SessionHigh'),
651
+ 'low': this.safeString(ticker, 'SessionLow'),
652
+ 'bid': this.safeString(ticker, 'BestBid'),
653
+ 'bidVolume': undefined,
654
+ 'ask': this.safeString(ticker, 'BestOffer'),
655
+ 'askVolume': undefined,
656
+ 'vwap': undefined,
657
+ 'open': open,
658
+ 'close': last,
659
+ 'last': last,
660
+ 'previousClose': undefined,
661
+ 'change': change,
662
+ 'percentage': percentage,
663
+ 'average': undefined,
664
+ 'baseVolume': baseVolume,
665
+ 'quoteVolume': quoteVolume,
666
+ 'info': ticker,
667
+ }, market);
668
+ }
669
+ async fetchTicker(symbol, params = {}) {
670
+ /**
671
+ * @method
672
+ * @name ndax#fetchTicker
673
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
674
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
675
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
676
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
677
+ */
678
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
679
+ await this.loadMarkets();
680
+ const market = this.market(symbol);
681
+ const request = {
682
+ 'omsId': omsId,
683
+ 'InstrumentId': market['id'],
684
+ };
685
+ const response = await this.publicGetGetLevel1(this.extend(request, params));
686
+ //
687
+ // {
688
+ // "OMSId":1,
689
+ // "InstrumentId":8,
690
+ // "BestBid":19069.31,
691
+ // "BestOffer":19069.32,
692
+ // "LastTradedPx":19069.32,
693
+ // "LastTradedQty":0.0001,
694
+ // "LastTradeTime":1607040406424,
695
+ // "SessionOpen":19069.32,
696
+ // "SessionHigh":19069.32,
697
+ // "SessionLow":19069.32,
698
+ // "SessionClose":19069.32,
699
+ // "Volume":0.0001,
700
+ // "CurrentDayVolume":0.0001,
701
+ // "CurrentDayNotional":1.906932,
702
+ // "CurrentDayNumTrades":1,
703
+ // "CurrentDayPxChange":0.00,
704
+ // "Rolling24HrVolume":0.000000000000000000000000000,
705
+ // "Rolling24HrNotional":0.00000000000000000000000,
706
+ // "Rolling24NumTrades":0,
707
+ // "Rolling24HrPxChange":0,
708
+ // "TimeStamp":"1607040406425",
709
+ // "BidQty":0,
710
+ // "AskQty":0,
711
+ // "BidOrderCt":0,
712
+ // "AskOrderCt":0,
713
+ // "Rolling24HrPxChangePercent":0,
714
+ // }
715
+ //
716
+ return this.parseTicker(response, market);
717
+ }
718
+ parseOHLCV(ohlcv, market = undefined) {
719
+ //
720
+ // [
721
+ // 1501603632000, // 0 DateTime
722
+ // 2700.33, // 1 High
723
+ // 2687.01, // 2 Low
724
+ // 2687.01, // 3 Open
725
+ // 2687.01, // 4 Close
726
+ // 24.86100992, // 5 Volume
727
+ // 0, // 6 Inside Bid Price
728
+ // 2870.95, // 7 Inside Ask Price
729
+ // 1 // 8 InstrumentId
730
+ // ]
731
+ //
732
+ return [
733
+ this.safeInteger(ohlcv, 0),
734
+ this.safeNumber(ohlcv, 3),
735
+ this.safeNumber(ohlcv, 1),
736
+ this.safeNumber(ohlcv, 2),
737
+ this.safeNumber(ohlcv, 4),
738
+ this.safeNumber(ohlcv, 5),
739
+ ];
740
+ }
741
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
742
+ /**
743
+ * @method
744
+ * @name ndax#fetchOHLCV
745
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
746
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
747
+ * @param {string} timeframe the length of time each candle represents
748
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
749
+ * @param {int} [limit] the maximum amount of candles to fetch
750
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
751
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
752
+ */
753
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
754
+ await this.loadMarkets();
755
+ const market = this.market(symbol);
756
+ const request = {
757
+ 'omsId': omsId,
758
+ 'InstrumentId': market['id'],
759
+ 'Interval': this.safeString(this.timeframes, timeframe, timeframe),
760
+ };
761
+ const duration = this.parseTimeframe(timeframe);
762
+ const now = this.milliseconds();
763
+ if (since === undefined) {
764
+ if (limit !== undefined) {
765
+ request['FromDate'] = this.ymdhms(now - duration * limit * 1000);
766
+ request['ToDate'] = this.ymdhms(now);
767
+ }
768
+ }
769
+ else {
770
+ request['FromDate'] = this.ymdhms(since);
771
+ if (limit === undefined) {
772
+ request['ToDate'] = this.ymdhms(now);
773
+ }
774
+ else {
775
+ request['ToDate'] = this.ymdhms(this.sum(since, duration * limit * 1000));
776
+ }
777
+ }
778
+ const response = await this.publicGetGetTickerHistory(this.extend(request, params));
779
+ //
780
+ // [
781
+ // [1607299260000,19069.32,19069.32,19069.32,19069.32,0,19069.31,19069.32,8,1607299200000],
782
+ // [1607299320000,19069.32,19069.32,19069.32,19069.32,0,19069.31,19069.32,8,1607299260000],
783
+ // [1607299380000,19069.32,19069.32,19069.32,19069.32,0,19069.31,19069.32,8,1607299320000],
784
+ // ]
785
+ //
786
+ return this.parseOHLCVs(response, market, timeframe, since, limit);
787
+ }
788
+ parseTrade(trade, market = undefined) {
789
+ //
790
+ // fetchTrades (public)
791
+ //
792
+ // [
793
+ // 6913253, // 0 TradeId
794
+ // 8, // 1 ProductPairCode
795
+ // 0.03340802, // 2 Quantity
796
+ // 19116.08, // 3 Price
797
+ // 2543425077, // 4 Order1
798
+ // 2543425482, // 5 Order2
799
+ // 1606935922416, // 6 Tradetime
800
+ // 0, // 7 Direction
801
+ // 1, // 8 TakerSide
802
+ // 0, // 9 BlockTrade
803
+ // 0, // 10 Either Order1ClientId or Order2ClientId
804
+ // ]
805
+ //
806
+ // fetchMyTrades (private)
807
+ //
808
+ // {
809
+ // "OMSId":1,
810
+ // "ExecutionId":16916567,
811
+ // "TradeId":14476351,
812
+ // "OrderId":2543565231,
813
+ // "AccountId":449,
814
+ // "AccountName":"igor@ccxt.trade",
815
+ // "SubAccountId":0,
816
+ // "ClientOrderId":0,
817
+ // "InstrumentId":8,
818
+ // "Side":"Sell",
819
+ // "OrderType":"Market",
820
+ // "Quantity":0.1230000000000000000000000000,
821
+ // "RemainingQuantity":0.0000000000000000000000000000,
822
+ // "Price":19069.310000000000000000000000,
823
+ // "Value":2345.5251300000000000000000000,
824
+ // "CounterParty":"7",
825
+ // "OrderTradeRevision":1,
826
+ // "Direction":"NoChange",
827
+ // "IsBlockTrade":false,
828
+ // "Fee":1.1727625650000000000000000000,
829
+ // "FeeProductId":8,
830
+ // "OrderOriginator":446,
831
+ // "UserName":"igor@ccxt.trade",
832
+ // "TradeTimeMS":1607565031569,
833
+ // "MakerTaker":"Taker",
834
+ // "AdapterTradeId":0,
835
+ // "InsideBid":19069.310000000000000000000000,
836
+ // "InsideBidSize":0.2400950000000000000000000000,
837
+ // "InsideAsk":19069.320000000000000000000000,
838
+ // "InsideAskSize":0.0997360000000000000000000000,
839
+ // "IsQuote":false,
840
+ // "CounterPartyClientUserId":1,
841
+ // "NotionalProductId":2,
842
+ // "NotionalRate":1.0000000000000000000000000000,
843
+ // "NotionalValue":2345.5251300000000000000000000,
844
+ // "NotionalHoldAmount":0,
845
+ // "TradeTime":637431618315686826
846
+ // }
847
+ //
848
+ // fetchOrderTrades
849
+ //
850
+ // {
851
+ // "Side":"Sell",
852
+ // "OrderId":2543565235,
853
+ // "Price":18600.000000000000000000000000,
854
+ // "Quantity":0.0000000000000000000000000000,
855
+ // "DisplayQuantity":0.0000000000000000000000000000,
856
+ // "Instrument":8,
857
+ // "Account":449,
858
+ // "AccountName":"igor@ccxt.trade",
859
+ // "OrderType":"Limit",
860
+ // "ClientOrderId":0,
861
+ // "OrderState":"FullyExecuted",
862
+ // "ReceiveTime":1607585844956,
863
+ // "ReceiveTimeTicks":637431826449564182,
864
+ // "LastUpdatedTime":1607585844959,
865
+ // "LastUpdatedTimeTicks":637431826449593893,
866
+ // "OrigQuantity":0.1230000000000000000000000000,
867
+ // "QuantityExecuted":0.1230000000000000000000000000,
868
+ // "GrossValueExecuted":2345.3947500000000000000000000,
869
+ // "ExecutableValue":0.0000000000000000000000000000,
870
+ // "AvgPrice":19068.250000000000000000000000,
871
+ // "CounterPartyId":0,
872
+ // "ChangeReason":"Trade",
873
+ // "OrigOrderId":2543565235,
874
+ // "OrigClOrdId":0,
875
+ // "EnteredBy":446,
876
+ // "UserName":"igor@ccxt.trade",
877
+ // "IsQuote":false,
878
+ // "InsideAsk":19069.320000000000000000000000,
879
+ // "InsideAskSize":0.0997360000000000000000000000,
880
+ // "InsideBid":19068.250000000000000000000000,
881
+ // "InsideBidSize":1.3300010000000000000000000000,
882
+ // "LastTradePrice":19068.250000000000000000000000,
883
+ // "RejectReason":"",
884
+ // "IsLockedIn":false,
885
+ // "CancelReason":"",
886
+ // "OrderFlag":"0",
887
+ // "UseMargin":false,
888
+ // "StopPrice":0.0000000000000000000000000000,
889
+ // "PegPriceType":"Unknown",
890
+ // "PegOffset":0.0000000000000000000000000000,
891
+ // "PegLimitOffset":0.0000000000000000000000000000,
892
+ // "IpAddress":"x.x.x.x",
893
+ // "ClientOrderIdUuid":null,
894
+ // "OMSId":1
895
+ // }
896
+ //
897
+ let priceString = undefined;
898
+ let amountString = undefined;
899
+ let costString = undefined;
900
+ let timestamp = undefined;
901
+ let id = undefined;
902
+ let marketId = undefined;
903
+ let side = undefined;
904
+ let orderId = undefined;
905
+ let takerOrMaker = undefined;
906
+ let fee = undefined;
907
+ let type = undefined;
908
+ if (Array.isArray(trade)) {
909
+ priceString = this.safeString(trade, 3);
910
+ amountString = this.safeString(trade, 2);
911
+ timestamp = this.safeInteger(trade, 6);
912
+ id = this.safeString(trade, 0);
913
+ marketId = this.safeString(trade, 1);
914
+ const takerSide = this.safeValue(trade, 8);
915
+ side = takerSide ? 'sell' : 'buy';
916
+ orderId = this.safeString(trade, 4);
917
+ }
918
+ else {
919
+ timestamp = this.safeInteger2(trade, 'TradeTimeMS', 'ReceiveTime');
920
+ id = this.safeString(trade, 'TradeId');
921
+ orderId = this.safeString2(trade, 'OrderId', 'OrigOrderId');
922
+ marketId = this.safeString2(trade, 'InstrumentId', 'Instrument');
923
+ priceString = this.safeString(trade, 'Price');
924
+ amountString = this.safeString(trade, 'Quantity');
925
+ costString = this.safeString2(trade, 'Value', 'GrossValueExecuted');
926
+ takerOrMaker = this.safeStringLower(trade, 'MakerTaker');
927
+ side = this.safeStringLower(trade, 'Side');
928
+ type = this.safeStringLower(trade, 'OrderType');
929
+ const feeCostString = this.safeString(trade, 'Fee');
930
+ if (feeCostString !== undefined) {
931
+ const feeCurrencyId = this.safeString(trade, 'FeeProductId');
932
+ const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
933
+ fee = {
934
+ 'cost': feeCostString,
935
+ 'currency': feeCurrencyCode,
936
+ };
937
+ }
938
+ }
939
+ const symbol = this.safeSymbol(marketId, market);
940
+ return this.safeTrade({
941
+ 'info': trade,
942
+ 'id': id,
943
+ 'symbol': symbol,
944
+ 'timestamp': timestamp,
945
+ 'datetime': this.iso8601(timestamp),
946
+ 'order': orderId,
947
+ 'type': type,
948
+ 'side': side,
949
+ 'takerOrMaker': takerOrMaker,
950
+ 'price': priceString,
951
+ 'amount': amountString,
952
+ 'cost': costString,
953
+ 'fee': fee,
954
+ }, market);
955
+ }
956
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
957
+ /**
958
+ * @method
959
+ * @name ndax#fetchTrades
960
+ * @description get the list of most recent trades for a particular symbol
961
+ * @param {string} symbol unified symbol of the market to fetch trades for
962
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
963
+ * @param {int} [limit] the maximum amount of trades to fetch
964
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
965
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
966
+ */
967
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
968
+ await this.loadMarkets();
969
+ const market = this.market(symbol);
970
+ const request = {
971
+ 'omsId': omsId,
972
+ 'InstrumentId': market['id'],
973
+ };
974
+ if (limit !== undefined) {
975
+ request['Count'] = limit;
976
+ }
977
+ const response = await this.publicGetGetLastTrades(this.extend(request, params));
978
+ //
979
+ // [
980
+ // [6913253,8,0.03340802,19116.08,2543425077,2543425482,1606935922416,0,1,0,0],
981
+ // [6913254,8,0.01391671,19117.42,2543427510,2543427811,1606935927998,1,1,0,0],
982
+ // [6913255,8,0.000006,19107.81,2543430495,2543430793,1606935933881,2,0,0,0],
983
+ // ]
984
+ //
985
+ return this.parseTrades(response, market, since, limit);
986
+ }
987
+ async fetchAccounts(params = {}) {
988
+ /**
989
+ * @method
990
+ * @name ndax#fetchAccounts
991
+ * @description fetch all the accounts associated with a profile
992
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
993
+ * @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
994
+ */
995
+ if (!this.login) {
996
+ throw new errors.AuthenticationError(this.id + ' fetchAccounts() requires exchange.login email credential');
997
+ }
998
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
999
+ this.checkRequiredCredentials();
1000
+ const request = {
1001
+ 'omsId': omsId,
1002
+ 'UserId': this.uid,
1003
+ 'UserName': this.login,
1004
+ };
1005
+ const response = await this.privateGetGetUserAccounts(this.extend(request, params));
1006
+ //
1007
+ // [ 449 ] // comma-separated list of account ids
1008
+ //
1009
+ const result = [];
1010
+ for (let i = 0; i < response.length; i++) {
1011
+ const accountId = this.safeString(response, i);
1012
+ result.push({
1013
+ 'id': accountId,
1014
+ 'type': undefined,
1015
+ 'currency': undefined,
1016
+ 'info': accountId,
1017
+ });
1018
+ }
1019
+ return result;
1020
+ }
1021
+ parseBalance(response) {
1022
+ const result = {
1023
+ 'info': response,
1024
+ 'timestamp': undefined,
1025
+ 'datetime': undefined,
1026
+ };
1027
+ for (let i = 0; i < response.length; i++) {
1028
+ const balance = response[i];
1029
+ const currencyId = this.safeString(balance, 'ProductId');
1030
+ if (currencyId in this.currencies_by_id) {
1031
+ const code = this.safeCurrencyCode(currencyId);
1032
+ const account = this.account();
1033
+ account['total'] = this.safeString(balance, 'Amount');
1034
+ account['used'] = this.safeString(balance, 'Hold');
1035
+ result[code] = account;
1036
+ }
1037
+ }
1038
+ return this.safeBalance(result);
1039
+ }
1040
+ async fetchBalance(params = {}) {
1041
+ /**
1042
+ * @method
1043
+ * @name ndax#fetchBalance
1044
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
1045
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1046
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1047
+ */
1048
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1049
+ await this.loadMarkets();
1050
+ await this.loadAccounts();
1051
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1052
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1053
+ params = this.omit(params, ['accountId', 'AccountId']);
1054
+ const request = {
1055
+ 'omsId': omsId,
1056
+ 'AccountId': accountId,
1057
+ };
1058
+ const response = await this.privateGetGetAccountPositions(this.extend(request, params));
1059
+ //
1060
+ // [
1061
+ // {
1062
+ // "OMSId":1,
1063
+ // "AccountId":449,
1064
+ // "ProductSymbol":"BTC",
1065
+ // "ProductId":1,
1066
+ // "Amount":10.000000000000000000000000000,
1067
+ // "Hold":0,
1068
+ // "PendingDeposits":0.0000000000000000000000000000,
1069
+ // "PendingWithdraws":0.0000000000000000000000000000,
1070
+ // "TotalDayDeposits":10.000000000000000000000000000,
1071
+ // "TotalMonthDeposits":10.000000000000000000000000000,
1072
+ // "TotalYearDeposits":10.000000000000000000000000000,
1073
+ // "TotalDayDepositNotional":10.000000000000000000000000000,
1074
+ // "TotalMonthDepositNotional":10.000000000000000000000000000,
1075
+ // "TotalYearDepositNotional":10.000000000000000000000000000,
1076
+ // "TotalDayWithdraws":0,
1077
+ // "TotalMonthWithdraws":0,
1078
+ // "TotalYearWithdraws":0,
1079
+ // "TotalDayWithdrawNotional":0,
1080
+ // "TotalMonthWithdrawNotional":0,
1081
+ // "TotalYearWithdrawNotional":0,
1082
+ // "NotionalProductId":8,
1083
+ // "NotionalProductSymbol":"USDT",
1084
+ // "NotionalValue":10.000000000000000000000000000,
1085
+ // "NotionalHoldAmount":0,
1086
+ // "NotionalRate":1
1087
+ // },
1088
+ // ]
1089
+ //
1090
+ return this.parseBalance(response);
1091
+ }
1092
+ parseLedgerEntryType(type) {
1093
+ const types = {
1094
+ 'Trade': 'trade',
1095
+ 'Deposit': 'transaction',
1096
+ 'Withdraw': 'transaction',
1097
+ 'Transfer': 'transfer',
1098
+ 'OrderHold': 'trade',
1099
+ 'WithdrawHold': 'transaction',
1100
+ 'DepositHold': 'transaction',
1101
+ 'MarginHold': 'trade',
1102
+ 'ManualHold': 'trade',
1103
+ 'ManualEntry': 'trade',
1104
+ 'MarginAcquisition': 'trade',
1105
+ 'MarginRelinquish': 'trade',
1106
+ 'MarginQuoteHold': 'trade',
1107
+ };
1108
+ return this.safeString(types, type, type);
1109
+ }
1110
+ parseLedgerEntry(item, currency = undefined) {
1111
+ //
1112
+ // {
1113
+ // "TransactionId": 2663709493,
1114
+ // "ReferenceId": 68,
1115
+ // "OMSId": 1,
1116
+ // "AccountId": 449,
1117
+ // "CR": 10.000000000000000000000000000,
1118
+ // "DR": 0.0000000000000000000000000000,
1119
+ // "Counterparty": 3,
1120
+ // "TransactionType": "Other",
1121
+ // "ReferenceType": "Deposit",
1122
+ // "ProductId": 1,
1123
+ // "Balance": 10.000000000000000000000000000,
1124
+ // "TimeStamp": 1607532331591
1125
+ // }
1126
+ //
1127
+ const currencyId = this.safeString(item, 'ProductId');
1128
+ const credit = this.safeString(item, 'CR');
1129
+ const debit = this.safeString(item, 'DR');
1130
+ let amount = undefined;
1131
+ let direction = undefined;
1132
+ if (Precise["default"].stringLt(credit, '0')) {
1133
+ amount = credit;
1134
+ direction = 'in';
1135
+ }
1136
+ else if (Precise["default"].stringLt(debit, '0')) {
1137
+ amount = debit;
1138
+ direction = 'out';
1139
+ }
1140
+ let before = undefined;
1141
+ const after = this.safeString(item, 'Balance');
1142
+ if (direction === 'out') {
1143
+ before = Precise["default"].stringAdd(after, amount);
1144
+ }
1145
+ else if (direction === 'in') {
1146
+ before = Precise["default"].stringMax('0', Precise["default"].stringSub(after, amount));
1147
+ }
1148
+ const timestamp = this.safeInteger(item, 'TimeStamp');
1149
+ return {
1150
+ 'info': item,
1151
+ 'id': this.safeString(item, 'TransactionId'),
1152
+ 'direction': direction,
1153
+ 'account': this.safeString(item, 'AccountId'),
1154
+ 'referenceId': this.safeString(item, 'ReferenceId'),
1155
+ 'referenceAccount': this.safeString(item, 'Counterparty'),
1156
+ 'type': this.parseLedgerEntryType(this.safeString(item, 'ReferenceType')),
1157
+ 'currency': this.safeCurrencyCode(currencyId, currency),
1158
+ 'amount': this.parseNumber(amount),
1159
+ 'before': this.parseNumber(before),
1160
+ 'after': this.parseNumber(after),
1161
+ 'status': 'ok',
1162
+ 'timestamp': timestamp,
1163
+ 'datetime': this.iso8601(timestamp),
1164
+ 'fee': undefined,
1165
+ };
1166
+ }
1167
+ async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
1168
+ /**
1169
+ * @method
1170
+ * @name ndax#fetchLedger
1171
+ * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
1172
+ * @param {string} code unified currency code, default is undefined
1173
+ * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
1174
+ * @param {int} [limit] max number of ledger entrys to return, default is undefined
1175
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1176
+ * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
1177
+ */
1178
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1179
+ await this.loadMarkets();
1180
+ await this.loadAccounts();
1181
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1182
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1183
+ params = this.omit(params, ['accountId', 'AccountId']);
1184
+ const request = {
1185
+ 'omsId': omsId,
1186
+ 'AccountId': accountId,
1187
+ };
1188
+ if (limit !== undefined) {
1189
+ request['Depth'] = limit;
1190
+ }
1191
+ const response = await this.privateGetGetAccountTransactions(this.extend(request, params));
1192
+ //
1193
+ // [
1194
+ // {
1195
+ // "TransactionId":2663709493,
1196
+ // "ReferenceId":68,
1197
+ // "OMSId":1,
1198
+ // "AccountId":449,
1199
+ // "CR":10.000000000000000000000000000,
1200
+ // "DR":0.0000000000000000000000000000,
1201
+ // "Counterparty":3,
1202
+ // "TransactionType":"Other",
1203
+ // "ReferenceType":"Deposit",
1204
+ // "ProductId":1,
1205
+ // "Balance":10.000000000000000000000000000,
1206
+ // "TimeStamp":1607532331591
1207
+ // },
1208
+ // ]
1209
+ //
1210
+ let currency = undefined;
1211
+ if (code !== undefined) {
1212
+ currency = this.currency(code);
1213
+ }
1214
+ return this.parseLedger(response, currency, since, limit);
1215
+ }
1216
+ parseOrderStatus(status) {
1217
+ const statuses = {
1218
+ 'Accepted': 'open',
1219
+ 'Rejected': 'rejected',
1220
+ 'Working': 'open',
1221
+ 'Canceled': 'canceled',
1222
+ 'Expired': 'expired',
1223
+ 'FullyExecuted': 'closed',
1224
+ };
1225
+ return this.safeString(statuses, status, status);
1226
+ }
1227
+ parseOrder(order, market = undefined) {
1228
+ //
1229
+ // createOrder
1230
+ //
1231
+ // {
1232
+ // "status":"Accepted",
1233
+ // "errormsg":"",
1234
+ // "OrderId": 2543565231
1235
+ // }
1236
+ //
1237
+ // editOrder
1238
+ //
1239
+ // {
1240
+ // "ReplacementOrderId": 1234,
1241
+ // "ReplacementClOrdId": 1561,
1242
+ // "OrigOrderId": 5678,
1243
+ // "OrigClOrdId": 91011,
1244
+ // }
1245
+ //
1246
+ // fetchOpenOrders, fetchClosedOrders
1247
+ //
1248
+ // {
1249
+ // "Side":"Buy",
1250
+ // "OrderId":2543565233,
1251
+ // "Price":19010,
1252
+ // "Quantity":0.345,
1253
+ // "DisplayQuantity":0.345,
1254
+ // "Instrument":8,
1255
+ // "Account":449,
1256
+ // "AccountName":"igor@ccxt.trade",
1257
+ // "OrderType":"Limit",
1258
+ // "ClientOrderId":0,
1259
+ // "OrderState":"Working",
1260
+ // "ReceiveTime":1607579326003,
1261
+ // "ReceiveTimeTicks":637431761260028981,
1262
+ // "LastUpdatedTime":1607579326005,
1263
+ // "LastUpdatedTimeTicks":637431761260054714,
1264
+ // "OrigQuantity":0.345,
1265
+ // "QuantityExecuted":0,
1266
+ // "GrossValueExecuted":0,
1267
+ // "ExecutableValue":0,
1268
+ // "AvgPrice":0,
1269
+ // "CounterPartyId":0,
1270
+ // "ChangeReason":"NewInputAccepted",
1271
+ // "OrigOrderId":2543565233,
1272
+ // "OrigClOrdId":0,
1273
+ // "EnteredBy":446,
1274
+ // "UserName":"igor@ccxt.trade",
1275
+ // "IsQuote":false,
1276
+ // "InsideAsk":19069.32,
1277
+ // "InsideAskSize":0.099736,
1278
+ // "InsideBid":19068.25,
1279
+ // "InsideBidSize":1.330001,
1280
+ // "LastTradePrice":19068.25,
1281
+ // "RejectReason":"",
1282
+ // "IsLockedIn":false,
1283
+ // "CancelReason":"",
1284
+ // "OrderFlag":"AddedToBook",
1285
+ // "UseMargin":false,
1286
+ // "StopPrice":0,
1287
+ // "PegPriceType":"Unknown",
1288
+ // "PegOffset":0,
1289
+ // "PegLimitOffset":0,
1290
+ // "IpAddress":null,
1291
+ // "ClientOrderIdUuid":null,
1292
+ // "OMSId":1
1293
+ // }
1294
+ //
1295
+ const timestamp = this.safeInteger(order, 'ReceiveTime');
1296
+ const marketId = this.safeString(order, 'Instrument');
1297
+ return this.safeOrder({
1298
+ 'id': this.safeString2(order, 'ReplacementOrderId', 'OrderId'),
1299
+ 'clientOrderId': this.safeString2(order, 'ReplacementClOrdId', 'ClientOrderId'),
1300
+ 'info': order,
1301
+ 'timestamp': timestamp,
1302
+ 'datetime': this.iso8601(timestamp),
1303
+ 'lastTradeTimestamp': this.safeInteger(order, 'LastUpdatedTime'),
1304
+ 'status': this.parseOrderStatus(this.safeString(order, 'OrderState')),
1305
+ 'symbol': this.safeSymbol(marketId, market),
1306
+ 'type': this.safeStringLower(order, 'OrderType'),
1307
+ 'timeInForce': undefined,
1308
+ 'postOnly': undefined,
1309
+ 'side': this.safeStringLower(order, 'Side'),
1310
+ 'price': this.safeString(order, 'Price'),
1311
+ 'stopPrice': this.parseNumber(this.omitZero(this.safeString(order, 'StopPrice'))),
1312
+ 'cost': this.safeString(order, 'GrossValueExecuted'),
1313
+ 'amount': this.safeString(order, 'OrigQuantity'),
1314
+ 'filled': this.safeString(order, 'QuantityExecuted'),
1315
+ 'average': this.safeString(order, 'AvgPrice'),
1316
+ 'remaining': undefined,
1317
+ 'fee': undefined,
1318
+ 'trades': undefined,
1319
+ }, market);
1320
+ }
1321
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1322
+ /**
1323
+ * @method
1324
+ * @name ndax#createOrder
1325
+ * @description create a trade order
1326
+ * @param {string} symbol unified symbol of the market to create an order in
1327
+ * @param {string} type 'market' or 'limit'
1328
+ * @param {string} side 'buy' or 'sell'
1329
+ * @param {float} amount how much of currency you want to trade in units of base currency
1330
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1331
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1332
+ * @param {float} [params.triggerPrice] the price at which a trigger order would be triggered
1333
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1334
+ */
1335
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1336
+ await this.loadMarkets();
1337
+ await this.loadAccounts();
1338
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1339
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1340
+ const clientOrderId = this.safeInteger2(params, 'ClientOrderId', 'clientOrderId');
1341
+ let orderType = this.safeInteger(this.options['orderTypes'], this.capitalize(type));
1342
+ const triggerPrice = this.safeString(params, 'triggerPrice');
1343
+ if (triggerPrice !== undefined) {
1344
+ if (type === 'market') {
1345
+ orderType = 3;
1346
+ }
1347
+ else if (type === 'limit') {
1348
+ orderType = 4;
1349
+ }
1350
+ }
1351
+ params = this.omit(params, ['accountId', 'AccountId', 'clientOrderId', 'ClientOrderId', 'triggerPrice']);
1352
+ const market = this.market(symbol);
1353
+ const orderSide = (side === 'buy') ? 0 : 1;
1354
+ const request = {
1355
+ 'InstrumentId': parseInt(market['id']),
1356
+ 'omsId': omsId,
1357
+ 'AccountId': accountId,
1358
+ 'TimeInForce': 1,
1359
+ // 'ClientOrderId': clientOrderId, // defaults to 0
1360
+ // If this order is order A, OrderIdOCO refers to the order ID of an order B (which is not the order being created by this call).
1361
+ // If order B executes, then order A created by this call is canceled.
1362
+ // You can also set up order B to watch order A in the same way, but that may require an update to order B to make it watch this one, which could have implications for priority in the order book.
1363
+ // See CancelReplaceOrder and ModifyOrder.
1364
+ // 'OrderIdOCO': 0, // The order ID if One Cancels the Other.
1365
+ // 'UseDisplayQuantity': false, // If you enter a Limit order with a reserve, you must set UseDisplayQuantity to true
1366
+ 'Side': orderSide,
1367
+ 'Quantity': parseFloat(this.amountToPrecision(symbol, amount)),
1368
+ 'OrderType': orderType, // 0 Unknown, 1 Market, 2 Limit, 3 StopMarket, 4 StopLimit, 5 TrailingStopMarket, 6 TrailingStopLimit, 7 BlockTrade
1369
+ // 'PegPriceType': 3, // 1 Last, 2 Bid, 3 Ask, 4 Midpoint
1370
+ // 'LimitPrice': parseFloat (this.priceToPrecision (symbol, price)),
1371
+ };
1372
+ // If OrderType=1 (Market), Side=0 (Buy), and LimitPrice is supplied, the Market order will execute up to the value specified
1373
+ if (price !== undefined) {
1374
+ request['LimitPrice'] = parseFloat(this.priceToPrecision(symbol, price));
1375
+ }
1376
+ if (clientOrderId !== undefined) {
1377
+ request['ClientOrderId'] = clientOrderId;
1378
+ }
1379
+ if (triggerPrice !== undefined) {
1380
+ request['StopPrice'] = triggerPrice;
1381
+ }
1382
+ const response = await this.privatePostSendOrder(this.extend(request, params));
1383
+ //
1384
+ // {
1385
+ // "status":"Accepted",
1386
+ // "errormsg":"",
1387
+ // "OrderId": 2543565231
1388
+ // }
1389
+ //
1390
+ return this.parseOrder(response, market);
1391
+ }
1392
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1393
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1394
+ await this.loadMarkets();
1395
+ await this.loadAccounts();
1396
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1397
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1398
+ const clientOrderId = this.safeInteger2(params, 'ClientOrderId', 'clientOrderId');
1399
+ params = this.omit(params, ['accountId', 'AccountId', 'clientOrderId', 'ClientOrderId']);
1400
+ const market = this.market(symbol);
1401
+ const orderSide = (side === 'buy') ? 0 : 1;
1402
+ const request = {
1403
+ 'OrderIdToReplace': parseInt(id),
1404
+ 'InstrumentId': parseInt(market['id']),
1405
+ 'omsId': omsId,
1406
+ 'AccountId': accountId,
1407
+ 'TimeInForce': 1,
1408
+ // 'ClientOrderId': clientOrderId, // defaults to 0
1409
+ // If this order is order A, OrderIdOCO refers to the order ID of an order B (which is not the order being created by this call).
1410
+ // If order B executes, then order A created by this call is canceled.
1411
+ // You can also set up order B to watch order A in the same way, but that may require an update to order B to make it watch this one, which could have implications for priority in the order book.
1412
+ // See CancelReplaceOrder and ModifyOrder.
1413
+ // 'OrderIdOCO': 0, // The order ID if One Cancels the Other.
1414
+ // 'UseDisplayQuantity': false, // If you enter a Limit order with a reserve, you must set UseDisplayQuantity to true
1415
+ 'Side': orderSide,
1416
+ 'Quantity': parseFloat(this.amountToPrecision(symbol, amount)),
1417
+ 'OrderType': this.safeInteger(this.options['orderTypes'], this.capitalize(type)), // 0 Unknown, 1 Market, 2 Limit, 3 StopMarket, 4 StopLimit, 5 TrailingStopMarket, 6 TrailingStopLimit, 7 BlockTrade
1418
+ // 'PegPriceType': 3, // 1 Last, 2 Bid, 3 Ask, 4 Midpoint
1419
+ // 'LimitPrice': parseFloat (this.priceToPrecision (symbol, price)),
1420
+ };
1421
+ // If OrderType=1 (Market), Side=0 (Buy), and LimitPrice is supplied, the Market order will execute up to the value specified
1422
+ if (price !== undefined) {
1423
+ request['LimitPrice'] = parseFloat(this.priceToPrecision(symbol, price));
1424
+ }
1425
+ if (clientOrderId !== undefined) {
1426
+ request['ClientOrderId'] = clientOrderId;
1427
+ }
1428
+ const response = await this.privatePostCancelReplaceOrder(this.extend(request, params));
1429
+ //
1430
+ // {
1431
+ // "replacementOrderId": 1234,
1432
+ // "replacementClOrdId": 1561,
1433
+ // "origOrderId": 5678,
1434
+ // "origClOrdId": 91011,
1435
+ // }
1436
+ //
1437
+ return this.parseOrder(response, market);
1438
+ }
1439
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1440
+ /**
1441
+ * @method
1442
+ * @name ndax#fetchMyTrades
1443
+ * @description fetch all trades made by the user
1444
+ * @param {string} symbol unified market symbol
1445
+ * @param {int} [since] the earliest time in ms to fetch trades for
1446
+ * @param {int} [limit] the maximum number of trades structures to retrieve
1447
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1448
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1449
+ */
1450
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1451
+ await this.loadMarkets();
1452
+ await this.loadAccounts();
1453
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1454
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1455
+ params = this.omit(params, ['accountId', 'AccountId']);
1456
+ const request = {
1457
+ 'omsId': omsId,
1458
+ 'AccountId': accountId,
1459
+ // 'InstrumentId': market['id'],
1460
+ // 'TradeId': 123, // If you specify TradeId, GetTradesHistory can return all states for a single trade
1461
+ // 'OrderId': 456, // If specified, the call returns all trades associated with the order
1462
+ // 'UserId': integer. The ID of the logged-in user. If not specified, the call returns trades associated with the users belonging to the default account for the logged-in user of this OMS.
1463
+ // 'StartTimeStamp': long integer. The historical date and time at which to begin the trade report, in POSIX format. If not specified, reverts to the start date of this account on the trading venue.
1464
+ // 'EndTimeStamp': long integer. Date at which to end the trade report, in POSIX format.
1465
+ // 'Depth': integer. In this case, the count of trades to return, counting from the StartIndex. If Depth is not specified, returns all trades between BeginTimeStamp and EndTimeStamp, beginning at StartIndex.
1466
+ // 'StartIndex': 0 // from the most recent trade 0 and moving backwards in time
1467
+ // 'ExecutionId': 123, // The ID of the individual buy or sell execution. If not specified, returns all.
1468
+ };
1469
+ let market = undefined;
1470
+ if (symbol !== undefined) {
1471
+ market = this.market(symbol);
1472
+ request['InstrumentId'] = market['id'];
1473
+ }
1474
+ if (since !== undefined) {
1475
+ request['StartTimeStamp'] = this.parseToInt(since / 1000);
1476
+ }
1477
+ if (limit !== undefined) {
1478
+ request['Depth'] = limit;
1479
+ }
1480
+ const response = await this.privateGetGetTradesHistory(this.extend(request, params));
1481
+ //
1482
+ // [
1483
+ // {
1484
+ // "OMSId":1,
1485
+ // "ExecutionId":16916567,
1486
+ // "TradeId":14476351,
1487
+ // "OrderId":2543565231,
1488
+ // "AccountId":449,
1489
+ // "AccountName":"igor@ccxt.trade",
1490
+ // "SubAccountId":0,
1491
+ // "ClientOrderId":0,
1492
+ // "InstrumentId":8,
1493
+ // "Side":"Sell",
1494
+ // "OrderType":"Market",
1495
+ // "Quantity":0.1230000000000000000000000000,
1496
+ // "RemainingQuantity":0.0000000000000000000000000000,
1497
+ // "Price":19069.310000000000000000000000,
1498
+ // "Value":2345.5251300000000000000000000,
1499
+ // "CounterParty":"7",
1500
+ // "OrderTradeRevision":1,
1501
+ // "Direction":"NoChange",
1502
+ // "IsBlockTrade":false,
1503
+ // "Fee":1.1727625650000000000000000000,
1504
+ // "FeeProductId":8,
1505
+ // "OrderOriginator":446,
1506
+ // "UserName":"igor@ccxt.trade",
1507
+ // "TradeTimeMS":1607565031569,
1508
+ // "MakerTaker":"Taker",
1509
+ // "AdapterTradeId":0,
1510
+ // "InsideBid":19069.310000000000000000000000,
1511
+ // "InsideBidSize":0.2400950000000000000000000000,
1512
+ // "InsideAsk":19069.320000000000000000000000,
1513
+ // "InsideAskSize":0.0997360000000000000000000000,
1514
+ // "IsQuote":false,
1515
+ // "CounterPartyClientUserId":1,
1516
+ // "NotionalProductId":2,
1517
+ // "NotionalRate":1.0000000000000000000000000000,
1518
+ // "NotionalValue":2345.5251300000000000000000000,
1519
+ // "NotionalHoldAmount":0,
1520
+ // "TradeTime":637431618315686826
1521
+ // }
1522
+ // ]
1523
+ //
1524
+ return this.parseTrades(response, market, since, limit);
1525
+ }
1526
+ async cancelAllOrders(symbol = undefined, params = {}) {
1527
+ /**
1528
+ * @method
1529
+ * @name ndax#cancelAllOrders
1530
+ * @description cancel all open orders
1531
+ * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1532
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1533
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1534
+ */
1535
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1536
+ await this.loadMarkets();
1537
+ await this.loadAccounts();
1538
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1539
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1540
+ params = this.omit(params, ['accountId', 'AccountId']);
1541
+ const request = {
1542
+ 'omsId': omsId,
1543
+ 'AccountId': accountId,
1544
+ };
1545
+ if (symbol !== undefined) {
1546
+ const market = this.market(symbol);
1547
+ request['IntrumentId'] = market['id'];
1548
+ }
1549
+ const response = await this.privatePostCancelAllOrders(this.extend(request, params));
1550
+ //
1551
+ // {
1552
+ // "result":true,
1553
+ // "errormsg":null,
1554
+ // "errorcode":0,
1555
+ // "detail":null
1556
+ // }
1557
+ //
1558
+ return response;
1559
+ }
1560
+ async cancelOrder(id, symbol = undefined, params = {}) {
1561
+ /**
1562
+ * @method
1563
+ * @name ndax#cancelOrder
1564
+ * @description cancels an open order
1565
+ * @param {string} id order id
1566
+ * @param {string} symbol unified symbol of the market the order was made in
1567
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1568
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1569
+ */
1570
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1571
+ await this.loadMarkets();
1572
+ await this.loadAccounts();
1573
+ // const defaultAccountId = this.safeInteger2 (this.options, 'accountId', 'AccountId', parseInt (this.accounts[0]['id']));
1574
+ // const accountId = this.safeInteger2 (params, 'accountId', 'AccountId', defaultAccountId);
1575
+ // params = this.omit (params, [ 'accountId', 'AccountId' ]);
1576
+ let market = undefined;
1577
+ if (symbol !== undefined) {
1578
+ market = this.market(symbol);
1579
+ }
1580
+ const request = {
1581
+ 'omsId': omsId,
1582
+ // 'AccountId': accountId,
1583
+ };
1584
+ const clientOrderId = this.safeInteger2(params, 'clientOrderId', 'ClOrderId');
1585
+ if (clientOrderId !== undefined) {
1586
+ request['ClOrderId'] = clientOrderId;
1587
+ }
1588
+ else {
1589
+ request['OrderId'] = parseInt(id);
1590
+ }
1591
+ params = this.omit(params, ['clientOrderId', 'ClOrderId']);
1592
+ const response = await this.privatePostCancelOrder(this.extend(request, params));
1593
+ const order = this.parseOrder(response, market);
1594
+ return this.extend(order, {
1595
+ 'id': id,
1596
+ 'clientOrderId': clientOrderId,
1597
+ });
1598
+ }
1599
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1600
+ /**
1601
+ * @method
1602
+ * @name ndax#fetchOpenOrders
1603
+ * @description fetch all unfilled currently open orders
1604
+ * @param {string} symbol unified market symbol
1605
+ * @param {int} [since] the earliest time in ms to fetch open orders for
1606
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
1607
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1608
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1609
+ */
1610
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1611
+ await this.loadMarkets();
1612
+ await this.loadAccounts();
1613
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1614
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1615
+ params = this.omit(params, ['accountId', 'AccountId']);
1616
+ let market = undefined;
1617
+ if (symbol !== undefined) {
1618
+ market = this.market(symbol);
1619
+ }
1620
+ const request = {
1621
+ 'omsId': omsId,
1622
+ 'AccountId': accountId,
1623
+ };
1624
+ const response = await this.privateGetGetOpenOrders(this.extend(request, params));
1625
+ //
1626
+ // [
1627
+ // {
1628
+ // "Side":"Buy",
1629
+ // "OrderId":2543565233,
1630
+ // "Price":19010,
1631
+ // "Quantity":0.345,
1632
+ // "DisplayQuantity":0.345,
1633
+ // "Instrument":8,
1634
+ // "Account":449,
1635
+ // "AccountName":"igor@ccxt.trade",
1636
+ // "OrderType":"Limit",
1637
+ // "ClientOrderId":0,
1638
+ // "OrderState":"Working",
1639
+ // "ReceiveTime":1607579326003,
1640
+ // "ReceiveTimeTicks":637431761260028981,
1641
+ // "LastUpdatedTime":1607579326005,
1642
+ // "LastUpdatedTimeTicks":637431761260054714,
1643
+ // "OrigQuantity":0.345,
1644
+ // "QuantityExecuted":0,
1645
+ // "GrossValueExecuted":0,
1646
+ // "ExecutableValue":0,
1647
+ // "AvgPrice":0,
1648
+ // "CounterPartyId":0,
1649
+ // "ChangeReason":"NewInputAccepted",
1650
+ // "OrigOrderId":2543565233,
1651
+ // "OrigClOrdId":0,
1652
+ // "EnteredBy":446,
1653
+ // "UserName":"igor@ccxt.trade",
1654
+ // "IsQuote":false,
1655
+ // "InsideAsk":19069.32,
1656
+ // "InsideAskSize":0.099736,
1657
+ // "InsideBid":19068.25,
1658
+ // "InsideBidSize":1.330001,
1659
+ // "LastTradePrice":19068.25,
1660
+ // "RejectReason":"",
1661
+ // "IsLockedIn":false,
1662
+ // "CancelReason":"",
1663
+ // "OrderFlag":"AddedToBook",
1664
+ // "UseMargin":false,
1665
+ // "StopPrice":0,
1666
+ // "PegPriceType":"Unknown",
1667
+ // "PegOffset":0,
1668
+ // "PegLimitOffset":0,
1669
+ // "IpAddress":null,
1670
+ // "ClientOrderIdUuid":null,
1671
+ // "OMSId":1
1672
+ // }
1673
+ // ]
1674
+ //
1675
+ return this.parseOrders(response, market, since, limit);
1676
+ }
1677
+ async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1678
+ /**
1679
+ * @method
1680
+ * @name ndax#fetchOrders
1681
+ * @description fetches information on multiple orders made by the user
1682
+ * @param {string} symbol unified market symbol of the market orders were made in
1683
+ * @param {int} [since] the earliest time in ms to fetch orders for
1684
+ * @param {int} [limit] the maximum number of order structures to retrieve
1685
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1686
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1687
+ */
1688
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1689
+ await this.loadMarkets();
1690
+ await this.loadAccounts();
1691
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1692
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1693
+ params = this.omit(params, ['accountId', 'AccountId']);
1694
+ const request = {
1695
+ 'omsId': omsId,
1696
+ 'AccountId': accountId,
1697
+ // 'ClientOrderId': clientOrderId,
1698
+ // 'OriginalOrderId': id,
1699
+ // 'OriginalClientOrderId': long integer,
1700
+ // 'UserId': integer,
1701
+ // 'InstrumentId': market['id'],
1702
+ // 'StartTimestamp': since,
1703
+ // 'EndTimestamp': this.milliseconds (),
1704
+ // 'Depth': limit,
1705
+ // 'StartIndex': 0,
1706
+ };
1707
+ let market = undefined;
1708
+ if (symbol !== undefined) {
1709
+ market = this.market(symbol);
1710
+ request['InstrumentId'] = market['id'];
1711
+ }
1712
+ if (since !== undefined) {
1713
+ request['StartTimeStamp'] = this.parseToInt(since / 1000);
1714
+ }
1715
+ if (limit !== undefined) {
1716
+ request['Depth'] = limit;
1717
+ }
1718
+ const response = await this.privateGetGetOrdersHistory(this.extend(request, params));
1719
+ //
1720
+ // [
1721
+ // {
1722
+ // "Side":"Buy",
1723
+ // "OrderId":2543565233,
1724
+ // "Price":19010.000000000000000000000000,
1725
+ // "Quantity":0.0000000000000000000000000000,
1726
+ // "DisplayQuantity":0.3450000000000000000000000000,
1727
+ // "Instrument":8,
1728
+ // "Account":449,
1729
+ // "AccountName":"igor@ccxt.trade",
1730
+ // "OrderType":"Limit",
1731
+ // "ClientOrderId":0,
1732
+ // "OrderState":"Canceled",
1733
+ // "ReceiveTime":1607579326003,
1734
+ // "ReceiveTimeTicks":637431761260028981,
1735
+ // "LastUpdatedTime":1607580965346,
1736
+ // "LastUpdatedTimeTicks":637431777653463754,
1737
+ // "OrigQuantity":0.3450000000000000000000000000,
1738
+ // "QuantityExecuted":0.0000000000000000000000000000,
1739
+ // "GrossValueExecuted":0.0000000000000000000000000000,
1740
+ // "ExecutableValue":0.0000000000000000000000000000,
1741
+ // "AvgPrice":0.0000000000000000000000000000,
1742
+ // "CounterPartyId":0,
1743
+ // "ChangeReason":"UserModified",
1744
+ // "OrigOrderId":2543565233,
1745
+ // "OrigClOrdId":0,
1746
+ // "EnteredBy":446,
1747
+ // "UserName":"igor@ccxt.trade",
1748
+ // "IsQuote":false,
1749
+ // "InsideAsk":19069.320000000000000000000000,
1750
+ // "InsideAskSize":0.0997360000000000000000000000,
1751
+ // "InsideBid":19068.250000000000000000000000,
1752
+ // "InsideBidSize":1.3300010000000000000000000000,
1753
+ // "LastTradePrice":19068.250000000000000000000000,
1754
+ // "RejectReason":"",
1755
+ // "IsLockedIn":false,
1756
+ // "CancelReason":"UserModified",
1757
+ // "OrderFlag":"AddedToBook, RemovedFromBook",
1758
+ // "UseMargin":false,
1759
+ // "StopPrice":0.0000000000000000000000000000,
1760
+ // "PegPriceType":"Unknown",
1761
+ // "PegOffset":0.0000000000000000000000000000,
1762
+ // "PegLimitOffset":0.0000000000000000000000000000,
1763
+ // "IpAddress":"x.x.x.x",
1764
+ // "ClientOrderIdUuid":null,
1765
+ // "OMSId":1
1766
+ // },
1767
+ // ]
1768
+ //
1769
+ return this.parseOrders(response, market, since, limit);
1770
+ }
1771
+ async fetchOrder(id, symbol = undefined, params = {}) {
1772
+ /**
1773
+ * @method
1774
+ * @name ndax#fetchOrder
1775
+ * @description fetches information on an order made by the user
1776
+ * @param {string} symbol unified symbol of the market the order was made in
1777
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1778
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1779
+ */
1780
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1781
+ await this.loadMarkets();
1782
+ await this.loadAccounts();
1783
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1784
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1785
+ params = this.omit(params, ['accountId', 'AccountId']);
1786
+ let market = undefined;
1787
+ if (symbol !== undefined) {
1788
+ market = this.market(symbol);
1789
+ }
1790
+ const request = {
1791
+ 'omsId': omsId,
1792
+ 'AccountId': accountId,
1793
+ 'OrderId': parseInt(id),
1794
+ };
1795
+ const response = await this.privateGetGetOrderStatus(this.extend(request, params));
1796
+ //
1797
+ // {
1798
+ // "Side":"Sell",
1799
+ // "OrderId":2543565232,
1800
+ // "Price":0.0000000000000000000000000000,
1801
+ // "Quantity":0.0000000000000000000000000000,
1802
+ // "DisplayQuantity":0.0000000000000000000000000000,
1803
+ // "Instrument":8,
1804
+ // "Account":449,
1805
+ // "AccountName":"igor@ccxt.trade",
1806
+ // "OrderType":"Market",
1807
+ // "ClientOrderId":0,
1808
+ // "OrderState":"FullyExecuted",
1809
+ // "ReceiveTime":1607569475591,
1810
+ // "ReceiveTimeTicks":637431662755912377,
1811
+ // "LastUpdatedTime":1607569475596,
1812
+ // "LastUpdatedTimeTicks":637431662755960902,
1813
+ // "OrigQuantity":1.0000000000000000000000000000,
1814
+ // "QuantityExecuted":1.0000000000000000000000000000,
1815
+ // "GrossValueExecuted":19068.270478610000000000000000,
1816
+ // "ExecutableValue":0.0000000000000000000000000000,
1817
+ // "AvgPrice":19068.270478610000000000000000,
1818
+ // "CounterPartyId":0,
1819
+ // "ChangeReason":"Trade",
1820
+ // "OrigOrderId":2543565232,
1821
+ // "OrigClOrdId":0,
1822
+ // "EnteredBy":446,
1823
+ // "UserName":"igor@ccxt.trade",
1824
+ // "IsQuote":false,
1825
+ // "InsideAsk":19069.320000000000000000000000,
1826
+ // "InsideAskSize":0.0997360000000000000000000000,
1827
+ // "InsideBid":19069.310000000000000000000000,
1828
+ // "InsideBidSize":0.2400950000000000000000000000,
1829
+ // "LastTradePrice":19069.310000000000000000000000,
1830
+ // "RejectReason":"",
1831
+ // "IsLockedIn":false,
1832
+ // "CancelReason":"",
1833
+ // "OrderFlag":"0",
1834
+ // "UseMargin":false,
1835
+ // "StopPrice":0.0000000000000000000000000000,
1836
+ // "PegPriceType":"Unknown",
1837
+ // "PegOffset":0.0000000000000000000000000000,
1838
+ // "PegLimitOffset":0.0000000000000000000000000000,
1839
+ // "IpAddress":"x.x.x.x",
1840
+ // "ClientOrderIdUuid":null,
1841
+ // "OMSId":1
1842
+ // }
1843
+ //
1844
+ return this.parseOrder(response, market);
1845
+ }
1846
+ async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
1847
+ /**
1848
+ * @method
1849
+ * @name ndax#fetchOrderTrades
1850
+ * @description fetch all the trades made from a single order
1851
+ * @param {string} id order id
1852
+ * @param {string} symbol unified market symbol
1853
+ * @param {int} [since] the earliest time in ms to fetch trades for
1854
+ * @param {int} [limit] the maximum number of trades to retrieve
1855
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1856
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1857
+ */
1858
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1859
+ await this.loadMarkets();
1860
+ await this.loadAccounts();
1861
+ // const defaultAccountId = this.safeInteger2 (this.options, 'accountId', 'AccountId', parseInt (this.accounts[0]['id']));
1862
+ // const accountId = this.safeInteger2 (params, 'accountId', 'AccountId', defaultAccountId);
1863
+ // params = this.omit (params, [ 'accountId', 'AccountId' ]);
1864
+ let market = undefined;
1865
+ if (symbol !== undefined) {
1866
+ market = this.market(symbol);
1867
+ }
1868
+ const request = {
1869
+ 'OMSId': this.parseToInt(omsId),
1870
+ // 'AccountId': accountId,
1871
+ 'OrderId': parseInt(id),
1872
+ };
1873
+ const response = await this.privatePostGetOrderHistoryByOrderId(this.extend(request, params));
1874
+ //
1875
+ // [
1876
+ // {
1877
+ // "Side":"Sell",
1878
+ // "OrderId":2543565235,
1879
+ // "Price":18600.000000000000000000000000,
1880
+ // "Quantity":0.0000000000000000000000000000,
1881
+ // "DisplayQuantity":0.0000000000000000000000000000,
1882
+ // "Instrument":8,
1883
+ // "Account":449,
1884
+ // "AccountName":"igor@ccxt.trade",
1885
+ // "OrderType":"Limit",
1886
+ // "ClientOrderId":0,
1887
+ // "OrderState":"FullyExecuted",
1888
+ // "ReceiveTime":1607585844956,
1889
+ // "ReceiveTimeTicks":637431826449564182,
1890
+ // "LastUpdatedTime":1607585844959,
1891
+ // "LastUpdatedTimeTicks":637431826449593893,
1892
+ // "OrigQuantity":0.1230000000000000000000000000,
1893
+ // "QuantityExecuted":0.1230000000000000000000000000,
1894
+ // "GrossValueExecuted":2345.3947500000000000000000000,
1895
+ // "ExecutableValue":0.0000000000000000000000000000,
1896
+ // "AvgPrice":19068.250000000000000000000000,
1897
+ // "CounterPartyId":0,
1898
+ // "ChangeReason":"Trade",
1899
+ // "OrigOrderId":2543565235,
1900
+ // "OrigClOrdId":0,
1901
+ // "EnteredBy":446,
1902
+ // "UserName":"igor@ccxt.trade",
1903
+ // "IsQuote":false,
1904
+ // "InsideAsk":19069.320000000000000000000000,
1905
+ // "InsideAskSize":0.0997360000000000000000000000,
1906
+ // "InsideBid":19068.250000000000000000000000,
1907
+ // "InsideBidSize":1.3300010000000000000000000000,
1908
+ // "LastTradePrice":19068.250000000000000000000000,
1909
+ // "RejectReason":"",
1910
+ // "IsLockedIn":false,
1911
+ // "CancelReason":"",
1912
+ // "OrderFlag":"0",
1913
+ // "UseMargin":false,
1914
+ // "StopPrice":0.0000000000000000000000000000,
1915
+ // "PegPriceType":"Unknown",
1916
+ // "PegOffset":0.0000000000000000000000000000,
1917
+ // "PegLimitOffset":0.0000000000000000000000000000,
1918
+ // "IpAddress":"x.x.x.x",
1919
+ // "ClientOrderIdUuid":null,
1920
+ // "OMSId":1
1921
+ // },
1922
+ // ]
1923
+ //
1924
+ const grouped = this.groupBy(response, 'ChangeReason');
1925
+ const trades = this.safeValue(grouped, 'Trade', []);
1926
+ return this.parseTrades(trades, market, since, limit);
1927
+ }
1928
+ async fetchDepositAddress(code, params = {}) {
1929
+ /**
1930
+ * @method
1931
+ * @name ndax#fetchDepositAddress
1932
+ * @description fetch the deposit address for a currency associated with this account
1933
+ * @param {string} code unified currency code
1934
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1935
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1936
+ */
1937
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
1938
+ await this.loadMarkets();
1939
+ await this.loadAccounts();
1940
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
1941
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
1942
+ params = this.omit(params, ['accountId', 'AccountId']);
1943
+ const currency = this.currency(code);
1944
+ const request = {
1945
+ 'omsId': omsId,
1946
+ 'AccountId': accountId,
1947
+ 'ProductId': currency['id'],
1948
+ 'GenerateNewKey': false,
1949
+ };
1950
+ const response = await this.privateGetGetDepositInfo(this.extend(request, params));
1951
+ //
1952
+ // {
1953
+ // "result":true,
1954
+ // "errormsg":null,
1955
+ // "statuscode":0,
1956
+ // "AssetManagerId":1,
1957
+ // "AccountId":57922,
1958
+ // "AssetId":16,
1959
+ // "ProviderId":23,
1960
+ // "DepositInfo":"[\"0x8A27564b5c30b91C93B1591821642420F323a210\"]"
1961
+ // }
1962
+ //
1963
+ return this.parseDepositAddress(response, currency);
1964
+ }
1965
+ parseDepositAddress(depositAddress, currency = undefined) {
1966
+ //
1967
+ // fetchDepositAddress, createDepositAddress
1968
+ //
1969
+ // {
1970
+ // "result":true,
1971
+ // "errormsg":null,
1972
+ // "statuscode":0,
1973
+ // "AssetManagerId":1,
1974
+ // "AccountId":449,
1975
+ // "AssetId":1,
1976
+ // "ProviderId":1,
1977
+ // "DepositInfo":"[\"r3e95RwVsLH7yCbnMfyh7SA8FdwUJCB4S2?memo=241452010\"]"
1978
+ // }
1979
+ //
1980
+ const depositInfoString = this.safeString(depositAddress, 'DepositInfo');
1981
+ const depositInfo = JSON.parse(depositInfoString);
1982
+ const depositInfoLength = depositInfo.length;
1983
+ const lastString = this.safeString(depositInfo, depositInfoLength - 1);
1984
+ const parts = lastString.split('?memo=');
1985
+ const address = this.safeString(parts, 0);
1986
+ const tag = this.safeString(parts, 1);
1987
+ let code = undefined;
1988
+ if (currency !== undefined) {
1989
+ code = currency['code'];
1990
+ }
1991
+ this.checkAddress(address);
1992
+ return {
1993
+ 'currency': code,
1994
+ 'address': address,
1995
+ 'tag': tag,
1996
+ 'network': undefined,
1997
+ 'info': depositAddress,
1998
+ };
1999
+ }
2000
+ async createDepositAddress(code, params = {}) {
2001
+ /**
2002
+ * @method
2003
+ * @name ndax#createDepositAddress
2004
+ * @description create a currency deposit address
2005
+ * @param {string} code unified currency code of the currency for the deposit address
2006
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2007
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
2008
+ */
2009
+ const request = {
2010
+ 'GenerateNewKey': true,
2011
+ };
2012
+ return await this.fetchDepositAddress(code, this.extend(request, params));
2013
+ }
2014
+ async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
2015
+ /**
2016
+ * @method
2017
+ * @name ndax#fetchDeposits
2018
+ * @description fetch all deposits made to an account
2019
+ * @see https://apidoc.ndax.io/#getdeposits
2020
+ * @param {string} code unified currency code
2021
+ * @param {int} [since] not used by ndax fetchDeposits
2022
+ * @param {int} [limit] the maximum number of deposits structures to retrieve
2023
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2024
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2025
+ */
2026
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
2027
+ await this.loadMarkets();
2028
+ await this.loadAccounts();
2029
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
2030
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
2031
+ params = this.omit(params, ['accountId', 'AccountId']);
2032
+ let currency = undefined;
2033
+ if (code !== undefined) {
2034
+ currency = this.currency(code);
2035
+ }
2036
+ const request = {
2037
+ 'omsId': omsId,
2038
+ 'AccountId': accountId,
2039
+ };
2040
+ const response = await this.privateGetGetDeposits(this.extend(request, params));
2041
+ //
2042
+ // "[
2043
+ // {
2044
+ // "OMSId": 1,
2045
+ // "DepositId": 44,
2046
+ // "AccountId": 449,
2047
+ // "SubAccountId": 0,
2048
+ // "ProductId": 4,
2049
+ // "Amount": 200.00000000000000000000000000,
2050
+ // "LastUpdateTimeStamp": 637431291261187806,
2051
+ // "ProductType": "CryptoCurrency",
2052
+ // "TicketStatus": "FullyProcessed",
2053
+ // "DepositInfo": "{
2054
+ // "AccountProviderId":42,
2055
+ // "AccountProviderName":"USDT_BSC",
2056
+ // "TXId":"0x3879b02632c69482646409e991149290bc9a58e4603be63c7c2c90a843f45d2b",
2057
+ // "FromAddress":"0x8894E0a0c962CB723c1976a4421c95949bE2D4E3",
2058
+ // "ToAddress":"0x5428EcEB1F7Ee058f64158589e27D087149230CB"
2059
+ // },",
2060
+ // "DepositCode": "ab0e23d5-a9ce-4d94-865f-9ab464fb1de3",
2061
+ // "TicketNumber": 71,
2062
+ // "NotionalProductId": 13,
2063
+ // "NotionalValue": 200.00000000000000000000000000,
2064
+ // "FeeAmount": 0.0000000000000000000000000000,
2065
+ // },
2066
+ // ...
2067
+ // ]"
2068
+ //
2069
+ if (typeof response === 'string') {
2070
+ return this.parseTransactions(JSON.parse(response), currency, since, limit);
2071
+ }
2072
+ return this.parseTransactions(response, currency, since, limit);
2073
+ }
2074
+ async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
2075
+ /**
2076
+ * @method
2077
+ * @name ndax#fetchWithdrawals
2078
+ * @description fetch all withdrawals made from an account
2079
+ * @param {string} code unified currency code
2080
+ * @param {int} [since] the earliest time in ms to fetch withdrawals for
2081
+ * @param {int} [limit] the maximum number of withdrawals structures to retrieve
2082
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2083
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2084
+ */
2085
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
2086
+ await this.loadMarkets();
2087
+ await this.loadAccounts();
2088
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
2089
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
2090
+ params = this.omit(params, ['accountId', 'AccountId']);
2091
+ let currency = undefined;
2092
+ if (code !== undefined) {
2093
+ currency = this.currency(code);
2094
+ }
2095
+ const request = {
2096
+ 'omsId': omsId,
2097
+ 'AccountId': accountId,
2098
+ };
2099
+ const response = await this.privateGetGetWithdraws(this.extend(request, params));
2100
+ //
2101
+ // [
2102
+ // {
2103
+ // "Amount": 0.0,
2104
+ // "FeeAmount": 0.0,
2105
+ // "NotionalValue": 0.0,
2106
+ // "WithdrawId": 0,
2107
+ // "AssetManagerId": 0,
2108
+ // "AccountId": 0,
2109
+ // "AssetId": 0,
2110
+ // "TemplateForm": "{\"TemplateType\": \"TetherRPCWithdraw\",\"Comment\": \"TestWithdraw\",\"ExternalAddress\": \"ms6C3pKAAr8gRCcnVebs8VRkVrjcvqNYv3\"}",
2111
+ // "TemplateFormType": "TetherRPCWithdraw",
2112
+ // "omsId": 0,
2113
+ // "TicketStatus": 0,
2114
+ // "TicketNumber": 0,
2115
+ // "WithdrawTransactionDetails": "",
2116
+ // "WithdrawType": "",
2117
+ // "WithdrawCode": "490b4fa3-53fc-44f4-bd29-7e16be86fba3",
2118
+ // "AssetType": 0,
2119
+ // "Reaccepted": true,
2120
+ // "NotionalProductId": 0
2121
+ // },
2122
+ // ]
2123
+ //
2124
+ return this.parseTransactions(response, currency, since, limit);
2125
+ }
2126
+ parseTransactionStatusByType(status, type = undefined) {
2127
+ const statusesByType = {
2128
+ 'deposit': {
2129
+ 'New': 'pending',
2130
+ 'AdminProcessing': 'pending',
2131
+ 'Accepted': 'pending',
2132
+ 'Rejected': 'rejected',
2133
+ 'SystemProcessing': 'pending',
2134
+ 'FullyProcessed': 'ok',
2135
+ 'Failed': 'failed',
2136
+ 'Pending': 'pending',
2137
+ 'Confirmed': 'pending',
2138
+ 'AmlProcessing': 'pending',
2139
+ 'AmlAccepted': 'pending',
2140
+ 'AmlRejected': 'rejected',
2141
+ 'AmlFailed': 'failed',
2142
+ 'LimitsAccepted': 'pending',
2143
+ 'LimitsRejected': 'rejected', // deposit does not meet limits for fiat or crypto asset
2144
+ },
2145
+ 'withdrawal': {
2146
+ 'New': 'pending',
2147
+ 'AdminProcessing': 'pending',
2148
+ 'Accepted': 'pending',
2149
+ 'Rejected': 'rejected',
2150
+ 'SystemProcessing': 'pending',
2151
+ 'FullyProcessed': 'ok',
2152
+ 'Failed': 'failed',
2153
+ 'Pending': 'pending',
2154
+ 'Pending2Fa': 'pending',
2155
+ 'AutoAccepted': 'pending',
2156
+ 'Delayed': 'pending',
2157
+ 'UserCanceled': 'canceled',
2158
+ 'AdminCanceled': 'canceled',
2159
+ 'AmlProcessing': 'pending',
2160
+ 'AmlAccepted': 'pending',
2161
+ 'AmlRejected': 'rejected',
2162
+ 'AmlFailed': 'failed',
2163
+ 'LimitsAccepted': 'pending',
2164
+ 'LimitsRejected': 'rejected',
2165
+ 'Submitted': 'pending',
2166
+ 'Confirmed': 'pending',
2167
+ 'ManuallyConfirmed': 'pending',
2168
+ 'Confirmed2Fa': 'pending', // user has confirmed withdraw via 2-factor authentication.
2169
+ },
2170
+ };
2171
+ const statuses = this.safeValue(statusesByType, type, {});
2172
+ return this.safeString(statuses, status, status);
2173
+ }
2174
+ parseTransaction(transaction, currency = undefined) {
2175
+ //
2176
+ // fetchDeposits
2177
+ //
2178
+ // {
2179
+ // "OMSId": 1,
2180
+ // "DepositId": 44,
2181
+ // "AccountId": 449,
2182
+ // "SubAccountId": 0,
2183
+ // "ProductId": 4,
2184
+ // "Amount": 200.00000000000000000000000000,
2185
+ // "LastUpdateTimeStamp": 637431291261187806,
2186
+ // "ProductType": "CryptoCurrency",
2187
+ // "TicketStatus": "FullyProcessed",
2188
+ // "DepositInfo": "{
2189
+ // "AccountProviderId":42,
2190
+ // "AccountProviderName":"USDT_BSC",
2191
+ // "TXId":"0x3879b02632c69482646409e991149290bc9a58e4603be63c7c2c90a843f45d2b",
2192
+ // "FromAddress":"0x8894E0a0c962CB723c1976a4421c95949bE2D4E3",
2193
+ // "ToAddress":"0x5428EcEB1F7Ee058f64158589e27D087149230CB"
2194
+ // }",
2195
+ // "DepositCode": "ab0e23d5-a9ce-4d94-865f-9ab464fb1de3",
2196
+ // "TicketNumber": 71,
2197
+ // "NotionalProductId": 13,
2198
+ // "NotionalValue": 200.00000000000000000000000000,
2199
+ // "FeeAmount": 0.0000000000000000000000000000,
2200
+ // }
2201
+ //
2202
+ // fetchWithdrawals
2203
+ //
2204
+ // {
2205
+ // "Amount": 0.0,
2206
+ // "FeeAmount": 0.0,
2207
+ // "NotionalValue": 0.0,
2208
+ // "WithdrawId": 0,
2209
+ // "AssetManagerId": 0,
2210
+ // "AccountId": 0,
2211
+ // "AssetId": 0,
2212
+ // "TemplateForm": "{\"TemplateType\": \"TetherRPCWithdraw\",\"Comment\": \"TestWithdraw\",\"ExternalAddress\": \"ms6C3pKAAr8gRCcnVebs8VRkVrjcvqNYv3\"}",
2213
+ // "TemplateFormType": "TetherRPCWithdraw",
2214
+ // "omsId": 0,
2215
+ // "TicketStatus": 0,
2216
+ // "TicketNumber": 0,
2217
+ // "WithdrawTransactionDetails": "",
2218
+ // "WithdrawType": "",
2219
+ // "WithdrawCode": "490b4fa3-53fc-44f4-bd29-7e16be86fba3",
2220
+ // "AssetType": 0,
2221
+ // "Reaccepted": true,
2222
+ // "NotionalProductId": 0
2223
+ // }
2224
+ //
2225
+ let id = undefined;
2226
+ const currencyId = this.safeString(transaction, 'ProductId');
2227
+ const code = this.safeCurrencyCode(currencyId, currency);
2228
+ let type = undefined;
2229
+ if ('DepositId' in transaction) {
2230
+ id = this.safeString(transaction, 'DepositId');
2231
+ type = 'deposit';
2232
+ }
2233
+ else if ('WithdrawId' in transaction) {
2234
+ id = this.safeString(transaction, 'WithdrawId');
2235
+ type = 'withdrawal';
2236
+ }
2237
+ const templateForm = this.parseJson(this.safeValue2(transaction, 'TemplateForm', 'DepositInfo'));
2238
+ let updated = this.safeInteger(transaction, 'LastUpdateTimeStamp');
2239
+ if (templateForm !== undefined) {
2240
+ updated = this.safeInteger(templateForm, 'LastUpdated', updated);
2241
+ }
2242
+ const address = this.safeString2(templateForm, 'ExternalAddress', 'ToAddress');
2243
+ const timestamp = this.safeInteger(templateForm, 'TimeSubmitted');
2244
+ const feeCost = this.safeNumber(transaction, 'FeeAmount');
2245
+ const transactionStatus = this.safeString(transaction, 'TicketStatus');
2246
+ let fee = undefined;
2247
+ if (feeCost !== undefined) {
2248
+ fee = { 'currency': code, 'cost': feeCost };
2249
+ }
2250
+ return {
2251
+ 'info': transaction,
2252
+ 'id': id,
2253
+ 'txid': this.safeString2(templateForm, 'TxId', 'TXId'),
2254
+ 'timestamp': timestamp,
2255
+ 'datetime': this.iso8601(timestamp),
2256
+ 'address': address,
2257
+ 'addressTo': address,
2258
+ 'addressFrom': this.safeString(templateForm, 'FromAddress'),
2259
+ 'tag': undefined,
2260
+ 'tagTo': undefined,
2261
+ 'tagFrom': undefined,
2262
+ 'type': type,
2263
+ 'amount': this.safeNumber(transaction, 'Amount'),
2264
+ 'currency': code,
2265
+ 'status': this.parseTransactionStatusByType(transactionStatus, type),
2266
+ 'updated': updated,
2267
+ 'fee': fee,
2268
+ 'internal': undefined,
2269
+ 'comment': undefined,
2270
+ 'network': undefined,
2271
+ };
2272
+ }
2273
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
2274
+ /**
2275
+ * @method
2276
+ * @name ndax#withdraw
2277
+ * @description make a withdrawal
2278
+ * @param {string} code unified currency code
2279
+ * @param {float} amount the amount to withdraw
2280
+ * @param {string} address the address to withdraw to
2281
+ * @param {string} tag
2282
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2283
+ * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2284
+ */
2285
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
2286
+ // this method required login, password and twofa key
2287
+ const sessionToken = this.safeString(this.options, 'sessionToken');
2288
+ if (sessionToken === undefined) {
2289
+ throw new errors.AuthenticationError(this.id + ' call signIn() method to obtain a session token');
2290
+ }
2291
+ if (this.twofa === undefined) {
2292
+ throw new errors.AuthenticationError(this.id + ' withdraw() requires exchange.twofa credentials');
2293
+ }
2294
+ this.checkAddress(address);
2295
+ const omsId = this.safeInteger(this.options, 'omsId', 1);
2296
+ await this.loadMarkets();
2297
+ await this.loadAccounts();
2298
+ const defaultAccountId = this.safeInteger2(this.options, 'accountId', 'AccountId', parseInt(this.accounts[0]['id']));
2299
+ const accountId = this.safeInteger2(params, 'accountId', 'AccountId', defaultAccountId);
2300
+ params = this.omit(params, ['accountId', 'AccountId']);
2301
+ const currency = this.currency(code);
2302
+ const withdrawTemplateTypesRequest = {
2303
+ 'omsId': omsId,
2304
+ 'AccountId': accountId,
2305
+ 'ProductId': currency['id'],
2306
+ };
2307
+ const withdrawTemplateTypesResponse = await this.privateGetGetWithdrawTemplateTypes(withdrawTemplateTypesRequest);
2308
+ //
2309
+ // {
2310
+ // "result": true,
2311
+ // "errormsg": null,
2312
+ // "statuscode": "0",
2313
+ // "TemplateTypes": [
2314
+ // { AccountProviderId: "14", TemplateName: "ToExternalBitcoinAddress", AccountProviderName: "BitgoRPC-BTC" },
2315
+ // { AccountProviderId: "20", TemplateName: "ToExternalBitcoinAddress", AccountProviderName: "TrezorBTC" },
2316
+ // { AccountProviderId: "31", TemplateName: "BTC", AccountProviderName: "BTC Fireblocks 1" }
2317
+ // ]
2318
+ // }
2319
+ //
2320
+ const templateTypes = this.safeValue(withdrawTemplateTypesResponse, 'TemplateTypes', []);
2321
+ const firstTemplateType = this.safeValue(templateTypes, 0);
2322
+ if (firstTemplateType === undefined) {
2323
+ throw new errors.ExchangeError(this.id + ' withdraw() could not find a withdraw template type for ' + currency['code']);
2324
+ }
2325
+ const templateName = this.safeString(firstTemplateType, 'TemplateName');
2326
+ const withdrawTemplateRequest = {
2327
+ 'omsId': omsId,
2328
+ 'AccountId': accountId,
2329
+ 'ProductId': currency['id'],
2330
+ 'TemplateType': templateName,
2331
+ 'AccountProviderId': firstTemplateType['AccountProviderId'],
2332
+ };
2333
+ const withdrawTemplateResponse = await this.privateGetGetWithdrawTemplate(withdrawTemplateRequest);
2334
+ //
2335
+ // {
2336
+ // "result": true,
2337
+ // "errormsg": null,
2338
+ // "statuscode": "0",
2339
+ // "Template": "{\"TemplateType\":\"ToExternalBitcoinAddress\",\"Comment\":\"\",\"ExternalAddress\":\"\"}"
2340
+ // }
2341
+ //
2342
+ const template = this.safeString(withdrawTemplateResponse, 'Template');
2343
+ if (template === undefined) {
2344
+ throw new errors.ExchangeError(this.id + ' withdraw() could not find a withdraw template for ' + currency['code']);
2345
+ }
2346
+ const withdrawTemplate = JSON.parse(template);
2347
+ withdrawTemplate['ExternalAddress'] = address;
2348
+ if (tag !== undefined) {
2349
+ if ('Memo' in withdrawTemplate) {
2350
+ withdrawTemplate['Memo'] = tag;
2351
+ }
2352
+ }
2353
+ const withdrawPayload = {
2354
+ 'omsId': omsId,
2355
+ 'AccountId': accountId,
2356
+ 'ProductId': currency['id'],
2357
+ 'TemplateForm': this.json(withdrawTemplate),
2358
+ 'TemplateType': templateName,
2359
+ };
2360
+ const withdrawRequest = {
2361
+ 'TfaType': 'Google',
2362
+ 'TFaCode': totp.totp(this.twofa),
2363
+ 'Payload': this.json(withdrawPayload),
2364
+ };
2365
+ const response = await this.privatePostCreateWithdrawTicket(this.deepExtend(withdrawRequest, params));
2366
+ return this.parseTransaction(response, currency);
2367
+ }
2368
+ nonce() {
2369
+ return this.milliseconds();
2370
+ }
2371
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
2372
+ let url = this.urls['api'][api] + '/' + this.implodeParams(path, params);
2373
+ let query = this.omit(params, this.extractParams(path));
2374
+ if (api === 'public') {
2375
+ if (path === 'Authenticate') {
2376
+ const auth = this.login + ':' + this.password;
2377
+ const auth64 = this.stringToBase64(auth);
2378
+ headers = {
2379
+ 'Authorization': 'Basic ' + auth64,
2380
+ // 'Content-Type': 'application/json',
2381
+ };
2382
+ }
2383
+ else if (path === 'Authenticate2FA') {
2384
+ const pending2faToken = this.safeString(this.options, 'pending2faToken');
2385
+ if (pending2faToken !== undefined) {
2386
+ headers = {
2387
+ 'Pending2FaToken': pending2faToken,
2388
+ // 'Content-Type': 'application/json',
2389
+ };
2390
+ query = this.omit(query, 'pending2faToken');
2391
+ }
2392
+ }
2393
+ if (Object.keys(query).length) {
2394
+ url += '?' + this.urlencode(query);
2395
+ }
2396
+ }
2397
+ else if (api === 'private') {
2398
+ this.checkRequiredCredentials();
2399
+ const sessionToken = this.safeString(this.options, 'sessionToken');
2400
+ if (sessionToken === undefined) {
2401
+ const nonce = this.nonce().toString();
2402
+ const auth = nonce + this.uid + this.apiKey;
2403
+ const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
2404
+ headers = {
2405
+ 'Nonce': nonce,
2406
+ 'APIKey': this.apiKey,
2407
+ 'Signature': signature,
2408
+ 'UserId': this.uid,
2409
+ };
2410
+ }
2411
+ else {
2412
+ headers = {
2413
+ 'APToken': sessionToken,
2414
+ };
2415
+ }
2416
+ if (method === 'POST') {
2417
+ headers['Content-Type'] = 'application/json';
2418
+ body = this.json(query);
2419
+ }
2420
+ else {
2421
+ if (Object.keys(query).length) {
2422
+ url += '?' + this.urlencode(query);
2423
+ }
2424
+ }
2425
+ }
2426
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
2427
+ }
2428
+ handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2429
+ if (code === 404) {
2430
+ throw new errors.AuthenticationError(this.id + ' ' + body);
2431
+ }
2432
+ if (response === undefined) {
2433
+ return undefined;
2434
+ }
2435
+ //
2436
+ // {"status":"Rejected","errormsg":"Not_Enough_Funds","errorcode":101}
2437
+ // {"result":false,"errormsg":"Server Error","errorcode":102,"detail":null}
2438
+ //
2439
+ const message = this.safeString(response, 'errormsg');
2440
+ if ((message !== undefined) && (message !== '')) {
2441
+ const feedback = this.id + ' ' + body;
2442
+ this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
2443
+ this.throwBroadlyMatchedException(this.exceptions['broad'], body, feedback);
2444
+ throw new errors.ExchangeError(feedback);
2445
+ }
2446
+ return undefined;
2447
+ }
2448
+ }
2449
+
2450
+ module.exports = ndax;