ccxt 4.2.17 → 4.2.19

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 (439) hide show
  1. package/README.md +9 -9
  2. package/dist/ccxt.browser.js +48992 -47725
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +12 -1
  5. package/dist/cjs/src/alpaca.js +18 -18
  6. package/dist/cjs/src/ascendex.js +13 -6
  7. package/dist/cjs/src/base/Exchange.js +266 -27
  8. package/dist/cjs/src/bigone.js +434 -168
  9. package/dist/cjs/src/binance.js +163 -34
  10. package/dist/cjs/src/binanceus.js +8 -0
  11. package/dist/cjs/src/bingx.js +183 -41
  12. package/dist/cjs/src/bitfinex.js +2 -3
  13. package/dist/cjs/src/bitget.js +59 -16
  14. package/dist/cjs/src/bitmart.js +5 -5
  15. package/dist/cjs/src/bitmex.js +4 -6
  16. package/dist/cjs/src/bitpanda.js +5 -1991
  17. package/dist/cjs/src/bitstamp.js +8 -0
  18. package/dist/cjs/src/bybit.js +27 -47
  19. package/dist/cjs/src/coinbase.js +176 -26
  20. package/dist/cjs/src/coincheck.js +1 -0
  21. package/dist/cjs/src/coinex.js +3 -0
  22. package/dist/cjs/src/coinlist.js +13 -6
  23. package/dist/cjs/src/coinone.js +2 -2
  24. package/dist/cjs/src/coinsph.js +4 -5
  25. package/dist/cjs/src/delta.js +7 -1
  26. package/dist/cjs/src/deribit.js +17 -4
  27. package/dist/cjs/src/gate.js +151 -169
  28. package/dist/cjs/src/gemini.js +1 -1
  29. package/dist/cjs/src/hitbtc.js +2 -3
  30. package/dist/cjs/src/htx.js +157 -7
  31. package/dist/cjs/src/huobijp.js +2 -3
  32. package/dist/cjs/src/independentreserve.js +7 -5
  33. package/dist/cjs/src/kraken.js +86 -54
  34. package/dist/cjs/src/kucoin.js +5 -0
  35. package/dist/cjs/src/kucoinfutures.js +131 -77
  36. package/dist/cjs/src/lbank.js +60 -33
  37. package/dist/cjs/src/luno.js +84 -2
  38. package/dist/cjs/src/mexc.js +3 -3
  39. package/dist/cjs/src/oceanex.js +1 -1
  40. package/dist/cjs/src/okx.js +23 -11
  41. package/dist/cjs/{js/src/bitpanda.js → src/onetrading.js} +39 -39
  42. package/dist/cjs/src/phemex.js +37 -27
  43. package/dist/cjs/src/poloniexfutures.js +1 -0
  44. package/dist/cjs/src/pro/binance.js +66 -25
  45. package/dist/cjs/src/pro/bitget.js +1 -1
  46. package/dist/cjs/src/pro/bitpanda.js +5 -1330
  47. package/dist/cjs/src/pro/coinbase.js +4 -1
  48. package/dist/cjs/src/pro/coincheck.js +208 -0
  49. package/dist/cjs/src/pro/hitbtc.js +5 -4
  50. package/dist/cjs/src/pro/htx.js +6 -1
  51. package/dist/cjs/src/pro/kraken.js +1 -1
  52. package/dist/cjs/src/pro/krakenfutures.js +7 -1
  53. package/dist/cjs/src/pro/kucoin.js +46 -36
  54. package/dist/cjs/src/pro/kucoinfutures.js +45 -37
  55. package/dist/cjs/src/pro/lbank.js +881 -0
  56. package/dist/cjs/src/pro/okx.js +52 -2
  57. package/dist/cjs/{js/src/pro/bitpanda.js → src/pro/onetrading.js} +4 -7
  58. package/dist/cjs/src/pro/poloniex.js +2 -2
  59. package/dist/cjs/src/pro/poloniexfutures.js +43 -35
  60. package/dist/cjs/src/pro/woo.js +126 -0
  61. package/dist/cjs/src/probit.js +4 -2
  62. package/dist/cjs/src/upbit.js +12 -12
  63. package/dist/cjs/src/wavesexchange.js +1 -1
  64. package/dist/cjs/src/whitebit.js +1 -0
  65. package/dist/cjs/src/woo.js +56 -0
  66. package/js/ccxt.d.ts +14 -2
  67. package/js/ccxt.js +10 -2
  68. package/js/src/abstract/bitpanda.d.ts +4 -4
  69. package/js/src/abstract/bitstamp.d.ts +8 -0
  70. package/js/src/abstract/gate.d.ts +1 -0
  71. package/js/src/abstract/gateio.d.ts +1 -0
  72. package/js/src/abstract/htx.d.ts +3 -0
  73. package/js/src/abstract/huobi.d.ts +3 -0
  74. package/js/src/abstract/luno.d.ts +1 -0
  75. package/js/src/abstract/onetrading.d.ts +38 -0
  76. package/js/src/ascendex.js +2 -0
  77. package/js/src/base/Exchange.d.ts +2 -3
  78. package/js/src/base/Exchange.js +5 -2
  79. package/js/src/binance.js +7 -1
  80. package/js/src/bingx.d.ts +1 -0
  81. package/js/src/bingx.js +26 -0
  82. package/js/src/bitget.js +22 -3
  83. package/js/src/bitpanda.d.ts +2 -72
  84. package/js/src/bitpanda.js +5 -1991
  85. package/js/src/bitstamp.js +8 -0
  86. package/js/src/bybit.js +21 -47
  87. package/js/src/coincheck.js +1 -0
  88. package/js/src/deribit.js +16 -4
  89. package/js/src/gate.d.ts +1 -0
  90. package/js/src/gate.js +50 -110
  91. package/js/src/htx.js +3 -0
  92. package/js/src/kraken.d.ts +1 -0
  93. package/js/src/kraken.js +40 -39
  94. package/js/src/lbank.js +1 -0
  95. package/js/src/luno.d.ts +3 -1
  96. package/js/src/luno.js +84 -2
  97. package/js/src/mexc.js +1 -2
  98. package/js/src/onetrading.d.ts +74 -0
  99. package/js/src/onetrading.js +2003 -0
  100. package/js/src/poloniexfutures.js +1 -0
  101. package/js/src/pro/binance.js +7 -2
  102. package/js/src/pro/bitget.js +1 -1
  103. package/js/src/pro/bitpanda.d.ts +2 -34
  104. package/js/src/pro/bitpanda.js +5 -1330
  105. package/js/src/pro/coincheck.d.ts +12 -0
  106. package/js/src/pro/coincheck.js +209 -0
  107. package/js/src/pro/kucoin.js +43 -35
  108. package/js/src/pro/kucoinfutures.js +45 -37
  109. package/js/src/pro/lbank.d.ts +29 -0
  110. package/js/src/pro/lbank.js +882 -0
  111. package/js/src/pro/onetrading.d.ts +36 -0
  112. package/js/src/pro/onetrading.js +1339 -0
  113. package/js/src/pro/poloniexfutures.js +43 -35
  114. package/js/src/whitebit.js +1 -0
  115. package/package.json +2 -2
  116. package/rollup.config.js +2 -0
  117. package/skip-tests.json +14 -2
  118. package/test-commonjs.cjs +25 -1
  119. package/dist/cjs/js/ccxt.js +0 -476
  120. package/dist/cjs/js/src/abstract/alpaca.js +0 -9
  121. package/dist/cjs/js/src/abstract/ascendex.js +0 -9
  122. package/dist/cjs/js/src/abstract/bigone.js +0 -9
  123. package/dist/cjs/js/src/abstract/binance.js +0 -9
  124. package/dist/cjs/js/src/abstract/bingx.js +0 -9
  125. package/dist/cjs/js/src/abstract/bit2c.js +0 -9
  126. package/dist/cjs/js/src/abstract/bitbank.js +0 -9
  127. package/dist/cjs/js/src/abstract/bitbns.js +0 -9
  128. package/dist/cjs/js/src/abstract/bitfinex.js +0 -9
  129. package/dist/cjs/js/src/abstract/bitfinex2.js +0 -9
  130. package/dist/cjs/js/src/abstract/bitflyer.js +0 -9
  131. package/dist/cjs/js/src/abstract/bitforex.js +0 -9
  132. package/dist/cjs/js/src/abstract/bitget.js +0 -9
  133. package/dist/cjs/js/src/abstract/bithumb.js +0 -9
  134. package/dist/cjs/js/src/abstract/bitmart.js +0 -9
  135. package/dist/cjs/js/src/abstract/bitmex.js +0 -9
  136. package/dist/cjs/js/src/abstract/bitopro.js +0 -9
  137. package/dist/cjs/js/src/abstract/bitpanda.js +0 -9
  138. package/dist/cjs/js/src/abstract/bitrue.js +0 -9
  139. package/dist/cjs/js/src/abstract/bitso.js +0 -9
  140. package/dist/cjs/js/src/abstract/bitstamp.js +0 -9
  141. package/dist/cjs/js/src/abstract/bitteam.js +0 -9
  142. package/dist/cjs/js/src/abstract/bitvavo.js +0 -9
  143. package/dist/cjs/js/src/abstract/bl3p.js +0 -9
  144. package/dist/cjs/js/src/abstract/blockchaincom.js +0 -9
  145. package/dist/cjs/js/src/abstract/btcalpha.js +0 -9
  146. package/dist/cjs/js/src/abstract/btcbox.js +0 -9
  147. package/dist/cjs/js/src/abstract/btcmarkets.js +0 -9
  148. package/dist/cjs/js/src/abstract/btcturk.js +0 -9
  149. package/dist/cjs/js/src/abstract/bybit.js +0 -9
  150. package/dist/cjs/js/src/abstract/cex.js +0 -9
  151. package/dist/cjs/js/src/abstract/coinbase.js +0 -9
  152. package/dist/cjs/js/src/abstract/coinbasepro.js +0 -9
  153. package/dist/cjs/js/src/abstract/coincheck.js +0 -9
  154. package/dist/cjs/js/src/abstract/coinex.js +0 -9
  155. package/dist/cjs/js/src/abstract/coinlist.js +0 -9
  156. package/dist/cjs/js/src/abstract/coinmate.js +0 -9
  157. package/dist/cjs/js/src/abstract/coinone.js +0 -9
  158. package/dist/cjs/js/src/abstract/coinsph.js +0 -9
  159. package/dist/cjs/js/src/abstract/coinspot.js +0 -9
  160. package/dist/cjs/js/src/abstract/cryptocom.js +0 -9
  161. package/dist/cjs/js/src/abstract/currencycom.js +0 -9
  162. package/dist/cjs/js/src/abstract/delta.js +0 -9
  163. package/dist/cjs/js/src/abstract/deribit.js +0 -9
  164. package/dist/cjs/js/src/abstract/digifinex.js +0 -9
  165. package/dist/cjs/js/src/abstract/exmo.js +0 -9
  166. package/dist/cjs/js/src/abstract/gate.js +0 -9
  167. package/dist/cjs/js/src/abstract/gemini.js +0 -9
  168. package/dist/cjs/js/src/abstract/hitbtc.js +0 -9
  169. package/dist/cjs/js/src/abstract/hollaex.js +0 -9
  170. package/dist/cjs/js/src/abstract/htx.js +0 -9
  171. package/dist/cjs/js/src/abstract/huobijp.js +0 -9
  172. package/dist/cjs/js/src/abstract/idex.js +0 -9
  173. package/dist/cjs/js/src/abstract/independentreserve.js +0 -9
  174. package/dist/cjs/js/src/abstract/indodax.js +0 -9
  175. package/dist/cjs/js/src/abstract/kraken.js +0 -9
  176. package/dist/cjs/js/src/abstract/krakenfutures.js +0 -9
  177. package/dist/cjs/js/src/abstract/kucoin.js +0 -9
  178. package/dist/cjs/js/src/abstract/kucoinfutures.js +0 -9
  179. package/dist/cjs/js/src/abstract/kuna.js +0 -9
  180. package/dist/cjs/js/src/abstract/latoken.js +0 -9
  181. package/dist/cjs/js/src/abstract/lbank.js +0 -9
  182. package/dist/cjs/js/src/abstract/luno.js +0 -9
  183. package/dist/cjs/js/src/abstract/lykke.js +0 -9
  184. package/dist/cjs/js/src/abstract/mercado.js +0 -9
  185. package/dist/cjs/js/src/abstract/mexc.js +0 -9
  186. package/dist/cjs/js/src/abstract/ndax.js +0 -9
  187. package/dist/cjs/js/src/abstract/novadax.js +0 -9
  188. package/dist/cjs/js/src/abstract/oceanex.js +0 -9
  189. package/dist/cjs/js/src/abstract/okcoin.js +0 -9
  190. package/dist/cjs/js/src/abstract/okx.js +0 -9
  191. package/dist/cjs/js/src/abstract/p2b.js +0 -9
  192. package/dist/cjs/js/src/abstract/paymium.js +0 -9
  193. package/dist/cjs/js/src/abstract/phemex.js +0 -9
  194. package/dist/cjs/js/src/abstract/poloniex.js +0 -9
  195. package/dist/cjs/js/src/abstract/poloniexfutures.js +0 -9
  196. package/dist/cjs/js/src/abstract/probit.js +0 -9
  197. package/dist/cjs/js/src/abstract/timex.js +0 -9
  198. package/dist/cjs/js/src/abstract/tokocrypto.js +0 -9
  199. package/dist/cjs/js/src/abstract/upbit.js +0 -9
  200. package/dist/cjs/js/src/abstract/wavesexchange.js +0 -9
  201. package/dist/cjs/js/src/abstract/wazirx.js +0 -9
  202. package/dist/cjs/js/src/abstract/whitebit.js +0 -9
  203. package/dist/cjs/js/src/abstract/woo.js +0 -9
  204. package/dist/cjs/js/src/abstract/yobit.js +0 -9
  205. package/dist/cjs/js/src/abstract/zaif.js +0 -9
  206. package/dist/cjs/js/src/abstract/zonda.js +0 -9
  207. package/dist/cjs/js/src/ace.js +0 -1058
  208. package/dist/cjs/js/src/alpaca.js +0 -1125
  209. package/dist/cjs/js/src/ascendex.js +0 -3365
  210. package/dist/cjs/js/src/base/Exchange.js +0 -5257
  211. package/dist/cjs/js/src/base/Precise.js +0 -263
  212. package/dist/cjs/js/src/base/errors.js +0 -299
  213. package/dist/cjs/js/src/base/functions/crypto.js +0 -78
  214. package/dist/cjs/js/src/base/functions/encode.js +0 -44
  215. package/dist/cjs/js/src/base/functions/generic.js +0 -193
  216. package/dist/cjs/js/src/base/functions/misc.js +0 -96
  217. package/dist/cjs/js/src/base/functions/number.js +0 -297
  218. package/dist/cjs/js/src/base/functions/platform.js +0 -28
  219. package/dist/cjs/js/src/base/functions/rsa.js +0 -34
  220. package/dist/cjs/js/src/base/functions/string.js +0 -48
  221. package/dist/cjs/js/src/base/functions/throttle.js +0 -66
  222. package/dist/cjs/js/src/base/functions/time.js +0 -187
  223. package/dist/cjs/js/src/base/functions/totp.js +0 -24
  224. package/dist/cjs/js/src/base/functions/type.js +0 -162
  225. package/dist/cjs/js/src/base/functions.js +0 -157
  226. package/dist/cjs/js/src/base/ws/Cache.js +0 -254
  227. package/dist/cjs/js/src/base/ws/Client.js +0 -299
  228. package/dist/cjs/js/src/base/ws/Future.js +0 -34
  229. package/dist/cjs/js/src/base/ws/OrderBook.js +0 -107
  230. package/dist/cjs/js/src/base/ws/OrderBookSide.js +0 -281
  231. package/dist/cjs/js/src/base/ws/WsClient.js +0 -69
  232. package/dist/cjs/js/src/bequant.js +0 -33
  233. package/dist/cjs/js/src/bigone.js +0 -2213
  234. package/dist/cjs/js/src/binance.js +0 -9845
  235. package/dist/cjs/js/src/binancecoinm.js +0 -45
  236. package/dist/cjs/js/src/binanceus.js +0 -92
  237. package/dist/cjs/js/src/binanceusdm.js +0 -58
  238. package/dist/cjs/js/src/bingx.js +0 -3846
  239. package/dist/cjs/js/src/bit2c.js +0 -916
  240. package/dist/cjs/js/src/bitbank.js +0 -1000
  241. package/dist/cjs/js/src/bitbay.js +0 -17
  242. package/dist/cjs/js/src/bitbns.js +0 -1220
  243. package/dist/cjs/js/src/bitcoincom.js +0 -17
  244. package/dist/cjs/js/src/bitfinex.js +0 -1670
  245. package/dist/cjs/js/src/bitfinex2.js +0 -2990
  246. package/dist/cjs/js/src/bitflyer.js +0 -1045
  247. package/dist/cjs/js/src/bitforex.js +0 -852
  248. package/dist/cjs/js/src/bitget.js +0 -8295
  249. package/dist/cjs/js/src/bithumb.js +0 -1090
  250. package/dist/cjs/js/src/bitmart.js +0 -4454
  251. package/dist/cjs/js/src/bitmex.js +0 -2881
  252. package/dist/cjs/js/src/bitopro.js +0 -1724
  253. package/dist/cjs/js/src/bitrue.js +0 -3253
  254. package/dist/cjs/js/src/bitso.js +0 -1753
  255. package/dist/cjs/js/src/bitstamp.js +0 -2188
  256. package/dist/cjs/js/src/bitteam.js +0 -2309
  257. package/dist/cjs/js/src/bitvavo.js +0 -1968
  258. package/dist/cjs/js/src/bl3p.js +0 -447
  259. package/dist/cjs/js/src/blockchaincom.js +0 -1160
  260. package/dist/cjs/js/src/btcalpha.js +0 -929
  261. package/dist/cjs/js/src/btcbox.js +0 -565
  262. package/dist/cjs/js/src/btcmarkets.js +0 -1237
  263. package/dist/cjs/js/src/btcturk.js +0 -929
  264. package/dist/cjs/js/src/bybit.js +0 -7650
  265. package/dist/cjs/js/src/cex.js +0 -1693
  266. package/dist/cjs/js/src/coinbase.js +0 -3424
  267. package/dist/cjs/js/src/coinbasepro.js +0 -1866
  268. package/dist/cjs/js/src/coincheck.js +0 -843
  269. package/dist/cjs/js/src/coinex.js +0 -5417
  270. package/dist/cjs/js/src/coinlist.js +0 -2337
  271. package/dist/cjs/js/src/coinmate.js +0 -989
  272. package/dist/cjs/js/src/coinone.js +0 -1185
  273. package/dist/cjs/js/src/coinsph.js +0 -1933
  274. package/dist/cjs/js/src/coinspot.js +0 -548
  275. package/dist/cjs/js/src/cryptocom.js +0 -3007
  276. package/dist/cjs/js/src/currencycom.js +0 -2015
  277. package/dist/cjs/js/src/delta.js +0 -3262
  278. package/dist/cjs/js/src/deribit.js +0 -3306
  279. package/dist/cjs/js/src/digifinex.js +0 -4307
  280. package/dist/cjs/js/src/exmo.js +0 -2645
  281. package/dist/cjs/js/src/fmfwio.js +0 -34
  282. package/dist/cjs/js/src/gate.js +0 -7077
  283. package/dist/cjs/js/src/gateio.js +0 -16
  284. package/dist/cjs/js/src/gemini.js +0 -1801
  285. package/dist/cjs/js/src/hitbtc.js +0 -3660
  286. package/dist/cjs/js/src/hitbtc3.js +0 -19
  287. package/dist/cjs/js/src/hollaex.js +0 -1882
  288. package/dist/cjs/js/src/htx.js +0 -9174
  289. package/dist/cjs/js/src/huobi.js +0 -16
  290. package/dist/cjs/js/src/huobijp.js +0 -1918
  291. package/dist/cjs/js/src/idex.js +0 -1770
  292. package/dist/cjs/js/src/independentreserve.js +0 -761
  293. package/dist/cjs/js/src/indodax.js +0 -1069
  294. package/dist/cjs/js/src/kraken.js +0 -2891
  295. package/dist/cjs/js/src/krakenfutures.js +0 -2407
  296. package/dist/cjs/js/src/kucoin.js +0 -4494
  297. package/dist/cjs/js/src/kucoinfutures.js +0 -2529
  298. package/dist/cjs/js/src/kuna.js +0 -1949
  299. package/dist/cjs/js/src/latoken.js +0 -1729
  300. package/dist/cjs/js/src/lbank.js +0 -2851
  301. package/dist/cjs/js/src/luno.js +0 -1044
  302. package/dist/cjs/js/src/lykke.js +0 -1303
  303. package/dist/cjs/js/src/mercado.js +0 -897
  304. package/dist/cjs/js/src/mexc.js +0 -5407
  305. package/dist/cjs/js/src/ndax.js +0 -2450
  306. package/dist/cjs/js/src/novadax.js +0 -1556
  307. package/dist/cjs/js/src/oceanex.js +0 -964
  308. package/dist/cjs/js/src/okcoin.js +0 -3115
  309. package/dist/cjs/js/src/okx.js +0 -7331
  310. package/dist/cjs/js/src/p2b.js +0 -1243
  311. package/dist/cjs/js/src/paymium.js +0 -597
  312. package/dist/cjs/js/src/phemex.js +0 -4725
  313. package/dist/cjs/js/src/poloniex.js +0 -2356
  314. package/dist/cjs/js/src/poloniexfutures.js +0 -1794
  315. package/dist/cjs/js/src/pro/alpaca.js +0 -714
  316. package/dist/cjs/js/src/pro/ascendex.js +0 -957
  317. package/dist/cjs/js/src/pro/bequant.js +0 -33
  318. package/dist/cjs/js/src/pro/binance.js +0 -2796
  319. package/dist/cjs/js/src/pro/binancecoinm.js +0 -23
  320. package/dist/cjs/js/src/pro/binanceus.js +0 -51
  321. package/dist/cjs/js/src/pro/binanceusdm.js +0 -32
  322. package/dist/cjs/js/src/pro/bingx.js +0 -944
  323. package/dist/cjs/js/src/pro/bitcoincom.js +0 -29
  324. package/dist/cjs/js/src/pro/bitfinex.js +0 -672
  325. package/dist/cjs/js/src/pro/bitfinex2.js +0 -1159
  326. package/dist/cjs/js/src/pro/bitget.js +0 -1733
  327. package/dist/cjs/js/src/pro/bitmart.js +0 -1486
  328. package/dist/cjs/js/src/pro/bitmex.js +0 -1576
  329. package/dist/cjs/js/src/pro/bitopro.js +0 -327
  330. package/dist/cjs/js/src/pro/bitrue.js +0 -462
  331. package/dist/cjs/js/src/pro/bitstamp.js +0 -547
  332. package/dist/cjs/js/src/pro/bitvavo.js +0 -704
  333. package/dist/cjs/js/src/pro/blockchaincom.js +0 -794
  334. package/dist/cjs/js/src/pro/bybit.js +0 -1843
  335. package/dist/cjs/js/src/pro/cex.js +0 -1510
  336. package/dist/cjs/js/src/pro/coinbase.js +0 -561
  337. package/dist/cjs/js/src/pro/coinbasepro.js +0 -968
  338. package/dist/cjs/js/src/pro/coinex.js +0 -1095
  339. package/dist/cjs/js/src/pro/cryptocom.js +0 -1020
  340. package/dist/cjs/js/src/pro/currencycom.js +0 -563
  341. package/dist/cjs/js/src/pro/deribit.js +0 -825
  342. package/dist/cjs/js/src/pro/exmo.js +0 -658
  343. package/dist/cjs/js/src/pro/gate.js +0 -1316
  344. package/dist/cjs/js/src/pro/gateio.js +0 -16
  345. package/dist/cjs/js/src/pro/gemini.js +0 -649
  346. package/dist/cjs/js/src/pro/hitbtc.js +0 -1294
  347. package/dist/cjs/js/src/pro/hollaex.js +0 -597
  348. package/dist/cjs/js/src/pro/htx.js +0 -2388
  349. package/dist/cjs/js/src/pro/huobi.js +0 -16
  350. package/dist/cjs/js/src/pro/huobijp.js +0 -606
  351. package/dist/cjs/js/src/pro/idex.js +0 -714
  352. package/dist/cjs/js/src/pro/independentreserve.js +0 -280
  353. package/dist/cjs/js/src/pro/kraken.js +0 -1364
  354. package/dist/cjs/js/src/pro/krakenfutures.js +0 -1506
  355. package/dist/cjs/js/src/pro/kucoin.js +0 -1054
  356. package/dist/cjs/js/src/pro/kucoinfutures.js +0 -981
  357. package/dist/cjs/js/src/pro/luno.js +0 -322
  358. package/dist/cjs/js/src/pro/mexc.js +0 -1170
  359. package/dist/cjs/js/src/pro/ndax.js +0 -545
  360. package/dist/cjs/js/src/pro/okcoin.js +0 -760
  361. package/dist/cjs/js/src/pro/okx.js +0 -1608
  362. package/dist/cjs/js/src/pro/phemex.js +0 -1511
  363. package/dist/cjs/js/src/pro/poloniex.js +0 -1253
  364. package/dist/cjs/js/src/pro/poloniexfutures.js +0 -1014
  365. package/dist/cjs/js/src/pro/probit.js +0 -586
  366. package/dist/cjs/js/src/pro/upbit.js +0 -234
  367. package/dist/cjs/js/src/pro/wazirx.js +0 -776
  368. package/dist/cjs/js/src/pro/whitebit.js +0 -927
  369. package/dist/cjs/js/src/pro/woo.js +0 -895
  370. package/dist/cjs/js/src/probit.js +0 -1867
  371. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +0 -401
  372. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -195
  373. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -308
  374. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +0 -554
  375. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -94
  376. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -70
  377. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -91
  378. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -16
  379. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +0 -1760
  380. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -52
  381. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +0 -81
  382. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +0 -376
  383. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -70
  384. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +0 -1580
  385. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -74
  386. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +0 -24
  387. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +0 -158
  388. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +0 -429
  389. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +0 -176
  390. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +0 -324
  391. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +0 -163
  392. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +0 -245
  393. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +0 -1018
  394. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +0 -383
  395. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +0 -258
  396. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +0 -53
  397. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +0 -120
  398. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +0 -69
  399. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +0 -7
  400. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +0 -83
  401. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +0 -240
  402. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +0 -91
  403. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +0 -130
  404. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +0 -214
  405. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +0 -239
  406. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +0 -93
  407. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +0 -354
  408. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +0 -16
  409. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +0 -20
  410. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +0 -30
  411. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +0 -239
  412. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +0 -372
  413. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +0 -273
  414. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +0 -139
  415. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +0 -14
  416. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +0 -16
  417. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +0 -81
  418. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +0 -292
  419. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +0 -103
  420. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +0 -140
  421. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +0 -175
  422. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +0 -95
  423. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +0 -7
  424. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +0 -383
  425. package/dist/cjs/js/src/timex.js +0 -1562
  426. package/dist/cjs/js/src/tokocrypto.js +0 -2542
  427. package/dist/cjs/js/src/upbit.js +0 -1844
  428. package/dist/cjs/js/src/wavesexchange.js +0 -2607
  429. package/dist/cjs/js/src/wazirx.js +0 -953
  430. package/dist/cjs/js/src/whitebit.js +0 -2309
  431. package/dist/cjs/js/src/woo.js +0 -2769
  432. package/dist/cjs/js/src/yobit.js +0 -1314
  433. package/dist/cjs/js/src/zaif.js +0 -736
  434. package/dist/cjs/js/src/zonda.js +0 -1883
  435. package/dist/cjs/src/abstract/bitpanda.js +0 -9
  436. package/test.ts +0 -0
  437. /package/dist/cjs/{js/src/abstract/ace.js → src/abstract/onetrading.js} +0 -0
  438. /package/dist/cjs/{js/src → src}/pro/coinone.js +0 -0
  439. /package/js/src/abstract/{bitpanda.js → onetrading.js} +0 -0
@@ -1,4494 +0,0 @@
1
- 'use strict';
2
-
3
- var kucoin$1 = require('./abstract/kucoin.js');
4
- var errors = require('./base/errors.js');
5
- var Precise = require('./base/Precise.js');
6
- var number = require('./base/functions/number.js');
7
- var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
-
9
- // ---------------------------------------------------------------------------
10
- // ---------------------------------------------------------------------------
11
- /**
12
- * @class kucoin
13
- * @augments Exchange
14
- */
15
- class kucoin extends kucoin$1 {
16
- describe() {
17
- return this.deepExtend(super.describe(), {
18
- 'id': 'kucoin',
19
- 'name': 'KuCoin',
20
- 'countries': ['SC'],
21
- 'rateLimit': 10,
22
- 'version': 'v2',
23
- 'certified': true,
24
- 'pro': true,
25
- 'comment': 'Platform 2.0',
26
- 'quoteJsonNumbers': false,
27
- 'has': {
28
- 'CORS': undefined,
29
- 'spot': true,
30
- 'margin': true,
31
- 'swap': false,
32
- 'future': false,
33
- 'option': false,
34
- 'borrowCrossMargin': true,
35
- 'borrowIsolatedMargin': true,
36
- 'cancelAllOrders': true,
37
- 'cancelOrder': true,
38
- 'closeAllPositions': false,
39
- 'closePosition': false,
40
- 'createDepositAddress': true,
41
- 'createMarketBuyOrderWithCost': true,
42
- 'createMarketOrderWithCost': true,
43
- 'createMarketSellOrderWithCost': true,
44
- 'createOrder': true,
45
- 'createOrders': true,
46
- 'createPostOnlyOrder': true,
47
- 'createStopLimitOrder': true,
48
- 'createStopMarketOrder': true,
49
- 'createStopOrder': true,
50
- 'createTriggerOrder': true,
51
- 'editOrder': true,
52
- 'fetchAccounts': true,
53
- 'fetchBalance': true,
54
- 'fetchBorrowInterest': true,
55
- 'fetchBorrowRateHistories': false,
56
- 'fetchBorrowRateHistory': false,
57
- 'fetchClosedOrders': true,
58
- 'fetchCrossBorrowRate': false,
59
- 'fetchCrossBorrowRates': false,
60
- 'fetchCurrencies': true,
61
- 'fetchDepositAddress': true,
62
- 'fetchDepositAddressesByNetwork': true,
63
- 'fetchDeposits': true,
64
- 'fetchDepositWithdrawFee': true,
65
- 'fetchDepositWithdrawFees': true,
66
- 'fetchFundingHistory': false,
67
- 'fetchFundingRate': false,
68
- 'fetchFundingRateHistory': false,
69
- 'fetchFundingRates': false,
70
- 'fetchIndexOHLCV': false,
71
- 'fetchIsolatedBorrowRate': false,
72
- 'fetchIsolatedBorrowRates': false,
73
- 'fetchL3OrderBook': true,
74
- 'fetchLedger': true,
75
- 'fetchLeverageTiers': false,
76
- 'fetchMarginMode': false,
77
- 'fetchMarketLeverageTiers': false,
78
- 'fetchMarkets': true,
79
- 'fetchMarkOHLCV': false,
80
- 'fetchMyTrades': true,
81
- 'fetchOHLCV': true,
82
- 'fetchOpenInterest': false,
83
- 'fetchOpenInterestHistory': false,
84
- 'fetchOpenOrders': true,
85
- 'fetchOrder': true,
86
- 'fetchOrderBook': true,
87
- 'fetchOrderBooks': false,
88
- 'fetchOrdersByStatus': true,
89
- 'fetchOrderTrades': true,
90
- 'fetchPositionMode': false,
91
- 'fetchPremiumIndexOHLCV': false,
92
- 'fetchStatus': true,
93
- 'fetchTicker': true,
94
- 'fetchTickers': true,
95
- 'fetchTime': true,
96
- 'fetchTrades': true,
97
- 'fetchTradingFee': true,
98
- 'fetchTradingFees': false,
99
- 'fetchTransactionFee': true,
100
- 'fetchTransfers': false,
101
- 'fetchWithdrawals': true,
102
- 'repayCrossMargin': true,
103
- 'repayIsolatedMargin': true,
104
- 'setLeverage': false,
105
- 'setMarginMode': false,
106
- 'setPositionMode': false,
107
- 'signIn': false,
108
- 'transfer': true,
109
- 'withdraw': true,
110
- },
111
- 'urls': {
112
- 'logo': 'https://user-images.githubusercontent.com/51840849/87295558-132aaf80-c50e-11ea-9801-a2fb0c57c799.jpg',
113
- 'referral': 'https://www.kucoin.com/ucenter/signup?rcode=E5wkqe',
114
- 'api': {
115
- 'public': 'https://api.kucoin.com',
116
- 'private': 'https://api.kucoin.com',
117
- 'futuresPrivate': 'https://api-futures.kucoin.com',
118
- 'futuresPublic': 'https://api-futures.kucoin.com',
119
- 'webExchange': 'https://kucoin.com/_api',
120
- },
121
- 'www': 'https://www.kucoin.com',
122
- 'doc': [
123
- 'https://docs.kucoin.com',
124
- ],
125
- },
126
- 'requiredCredentials': {
127
- 'apiKey': true,
128
- 'secret': true,
129
- 'password': true,
130
- },
131
- 'api': {
132
- // level VIP0
133
- // Spot => 3000/30s => 100/s
134
- // Weight = x => 100/(100/x) = x
135
- // Futures Management Public => 2000/30s => 200/3/s
136
- // Weight = x => 100/(200/3/x) = x*1.5
137
- 'public': {
138
- 'get': {
139
- // spot trading
140
- 'currencies': 4.5,
141
- 'currencies/{currency}': 4.5,
142
- 'symbols': 6,
143
- 'market/orderbook/level1': 3,
144
- 'market/allTickers': 22.5,
145
- 'market/stats': 22.5,
146
- 'markets': 4.5,
147
- 'market/orderbook/level{level}_{limit}': 6,
148
- 'market/orderbook/level2_20': 3,
149
- 'market/orderbook/level2_100': 6,
150
- 'market/histories': 4.5,
151
- 'market/candles': 4.5,
152
- 'prices': 4.5,
153
- 'timestamp': 4.5,
154
- 'status': 4.5,
155
- // margin trading
156
- 'mark-price/{symbol}/current': 3,
157
- 'margin/config': 25, // 25SW
158
- },
159
- 'post': {
160
- // ws
161
- 'bullet-public': 15, // 10PW
162
- },
163
- },
164
- 'private': {
165
- 'get': {
166
- // account
167
- 'user-info': 30,
168
- 'accounts': 7.5,
169
- 'accounts/{accountId}': 7.5,
170
- 'accounts/ledgers': 3,
171
- 'hf/accounts/ledgers': 2,
172
- 'hf/margin/account/ledgers': 2,
173
- 'transaction-history': 3,
174
- 'sub/user': 30,
175
- 'sub-accounts/{subUserId}': 22.5,
176
- 'sub-accounts': 30,
177
- 'sub/api-key': 30,
178
- // funding
179
- 'margin/account': 40,
180
- 'margin/accounts': 15,
181
- 'isolated/accounts': 15,
182
- 'deposit-addresses': 7.5,
183
- 'deposits': 7.5,
184
- 'hist-deposits': 7.5,
185
- 'withdrawals': 30,
186
- 'hist-withdrawals': 30,
187
- 'withdrawals/quotas': 30,
188
- 'accounts/transferable': 30,
189
- 'transfer-list': 30,
190
- 'base-fee': 3,
191
- 'trade-fees': 3,
192
- // spot trading
193
- 'market/orderbook/level{level}': 3,
194
- 'market/orderbook/level2': 3,
195
- 'market/orderbook/level3': 3,
196
- 'hf/orders/active': 2,
197
- 'hf/orders/active/symbols': 2,
198
- 'hf/orders/done': 2,
199
- 'hf/orders/{orderId}': 2,
200
- 'hf/orders/client-order/{clientOid}': 2,
201
- 'hf/orders/dead-cancel-all/query': 2,
202
- 'hf/fills': 2,
203
- 'orders': 2,
204
- 'limit/orders': 3,
205
- 'orders/{orderId}': 2,
206
- 'order/client-order/{clientOid}': 3,
207
- 'fills': 10,
208
- 'limit/fills': 20,
209
- 'stop-order': 8,
210
- 'stop-order/{orderId}': 3,
211
- 'stop-order/queryOrderByClientOid': 3,
212
- 'oco/order/{orderId}': 2,
213
- 'oco/order/details/{orderId}': 2,
214
- 'oco/client-order/{clientOid}': 2,
215
- 'oco/orders': 2,
216
- // margin trading
217
- 'hf/margin/orders/active': 4,
218
- 'hf/margin/orders/done': 10,
219
- 'hf/margin/orders/{orderId}': 4,
220
- 'hf/margin/orders/client-order/{clientOid}': 5,
221
- 'hf/margin/fills': 5,
222
- 'etf/info': 25,
223
- 'margin/currencies': 20,
224
- 'risk/limit/strategy': 20,
225
- 'isolated/symbols': 20,
226
- 'isolated/account/{symbol}': 50,
227
- 'margin/borrow': 15,
228
- 'margin/repay': 15,
229
- 'project/list': 10,
230
- 'project/marketInterestRate': 7.5,
231
- 'redeem/orders': 10,
232
- 'purchase/orders': 10, // 10SW
233
- },
234
- 'post': {
235
- // account
236
- 'sub/user/created': 22.5,
237
- 'sub/api-key': 30,
238
- 'sub/api-key/update': 45,
239
- // funding
240
- 'deposit-addresses': 30,
241
- 'withdrawals': 7.5,
242
- 'accounts/universal-transfer': 6,
243
- 'accounts/sub-transfer': 45,
244
- 'accounts/inner-transfer': 15,
245
- 'transfer-out': 30,
246
- 'transfer-in': 30,
247
- // spot trading
248
- 'hf/orders': 1,
249
- 'hf/orders/test': 1,
250
- 'hf/orders/sync': 1,
251
- 'hf/orders/multi': 1,
252
- 'hf/orders/multi/sync': 1,
253
- 'hf/orders/alter': 3,
254
- 'hf/orders/dead-cancel-all': 2,
255
- 'orders': 2,
256
- 'orders/test': 2,
257
- 'orders/multi': 3,
258
- 'stop-order': 2,
259
- 'oco/order': 2,
260
- // margin trading
261
- 'hf/margin/order': 5,
262
- 'hf/margin/order/test': 5,
263
- 'margin/order': 5,
264
- 'margin/order/test': 5,
265
- 'margin/borrow': 15,
266
- 'margin/repay': 10,
267
- 'purchase': 15,
268
- 'redeem': 15,
269
- 'lend/purchase/update': 10,
270
- // ws
271
- 'bullet-private': 10, // 10SW
272
- },
273
- 'delete': {
274
- // account
275
- 'sub/api-key': 45,
276
- // funding
277
- 'withdrawals/{withdrawalId}': 30,
278
- // spot trading
279
- 'hf/orders/{orderId}': 1,
280
- 'hf/orders/sync/{orderId}': 1,
281
- 'hf/orders/client-order/{clientOid}': 1,
282
- 'hf/orders/sync/client-order/{clientOid}': 1,
283
- 'hf/orders/cancel/{orderId}': 2,
284
- 'hf/orders': 2,
285
- 'hf/orders/cancelAll': 30,
286
- 'orders/{orderId}': 3,
287
- 'order/client-order/{clientOid}': 5,
288
- 'orders': 20,
289
- 'stop-order/{orderId}': 3,
290
- 'stop-order/cancelOrderByClientOid': 5,
291
- 'stop-order/cancel': 3,
292
- 'oco/order/{orderId}': 3,
293
- 'oco/client-order/{clientOid}': 3,
294
- 'oco/orders': 3,
295
- // margin trading
296
- 'hf/margin/orders/{orderId}': 5,
297
- 'hf/margin/orders/client-order/{clientOid}': 5,
298
- 'hf/margin/orders': 10, // 10SW
299
- },
300
- },
301
- 'futuresPublic': {
302
- 'get': {
303
- 'contracts/active': 4.5,
304
- 'contracts/{symbol}': 4.5,
305
- 'ticker': 3,
306
- 'level2/snapshot': 4.5,
307
- 'level2/depth20': 7.5,
308
- 'level2/depth100': 15,
309
- 'trade/history': 7.5,
310
- 'kline/query': 4.5,
311
- 'interest/query': 7.5,
312
- 'index/query': 3,
313
- 'mark-price/{symbol}/current': 4.5,
314
- 'premium/query': 4.5,
315
- 'trade-statistics': 4.5,
316
- 'funding-rate/{symbol}/current': 3,
317
- 'contract/funding-rates': 7.5,
318
- 'timestamp': 3,
319
- 'status': 6,
320
- // ?
321
- 'level2/message/query': 1.3953,
322
- },
323
- 'post': {
324
- // ws
325
- 'bullet-public': 15, // 10PW
326
- },
327
- },
328
- 'futuresPrivate': {
329
- 'get': {
330
- // account
331
- 'transaction-history': 3,
332
- // funding
333
- 'account-overview': 7.5,
334
- 'account-overview-all': 9,
335
- 'transfer-list': 30,
336
- // futures
337
- 'orders': 3,
338
- 'stopOrders': 9,
339
- 'recentDoneOrders': 7.5,
340
- 'orders/{orderId}': 7.5,
341
- 'orders/byClientOid': 7.5,
342
- 'fills': 7.5,
343
- 'recentFills': 4.5,
344
- 'openOrderStatistics': 15,
345
- 'position': 3,
346
- 'positions': 3,
347
- 'margin/maxWithdrawMargin': 15,
348
- 'contracts/risk-limit/{symbol}': 7.5,
349
- 'funding-history': 7.5, // 5FW
350
- },
351
- 'post': {
352
- // funding
353
- 'transfer-out': 30,
354
- 'transfer-in': 30,
355
- // futures
356
- 'orders': 3,
357
- 'orders/test': 3,
358
- 'orders/multi': 4.5,
359
- 'position/margin/auto-deposit-status': 6,
360
- 'margin/withdrawMargin': 15,
361
- 'position/margin/deposit-margin': 6,
362
- 'position/risk-limit-level/change': 6,
363
- // ws
364
- 'bullet-private': 15, // 10FW
365
- },
366
- 'delete': {
367
- 'orders/{orderId}': 1.5,
368
- 'orders/client-order/{clientOid}': 1.5,
369
- 'orders': 45,
370
- 'stopOrders': 22.5, // 15FW
371
- },
372
- },
373
- 'webExchange': {
374
- 'get': {
375
- 'currency/currency/chain-info': 1, // this is temporary from webApi
376
- },
377
- },
378
- },
379
- 'timeframes': {
380
- '1m': '1min',
381
- '3m': '3min',
382
- '5m': '5min',
383
- '15m': '15min',
384
- '30m': '30min',
385
- '1h': '1hour',
386
- '2h': '2hour',
387
- '4h': '4hour',
388
- '6h': '6hour',
389
- '8h': '8hour',
390
- '12h': '12hour',
391
- '1d': '1day',
392
- '1w': '1week',
393
- },
394
- 'precisionMode': number.TICK_SIZE,
395
- 'exceptions': {
396
- 'exact': {
397
- 'order not exist': errors.OrderNotFound,
398
- 'order not exist.': errors.OrderNotFound,
399
- 'order_not_exist': errors.OrderNotFound,
400
- 'order_not_exist_or_not_allow_to_cancel': errors.InvalidOrder,
401
- 'Order size below the minimum requirement.': errors.InvalidOrder,
402
- 'The withdrawal amount is below the minimum requirement.': errors.ExchangeError,
403
- 'Unsuccessful! Exceeded the max. funds out-transfer limit': errors.InsufficientFunds,
404
- '400': errors.BadRequest,
405
- '401': errors.AuthenticationError,
406
- '403': errors.NotSupported,
407
- '404': errors.NotSupported,
408
- '405': errors.NotSupported,
409
- '415': errors.NotSupported,
410
- '429': errors.RateLimitExceeded,
411
- '500': errors.ExchangeNotAvailable,
412
- '503': errors.ExchangeNotAvailable,
413
- '101030': errors.PermissionDenied,
414
- '103000': errors.InvalidOrder,
415
- '130101': errors.BadRequest,
416
- '130102': errors.ExchangeError,
417
- '130103': errors.OrderNotFound,
418
- '130104': errors.ExchangeError,
419
- '130105': errors.InsufficientFunds,
420
- '130106': errors.NotSupported,
421
- '130107': errors.ExchangeError,
422
- '130108': errors.OrderNotFound,
423
- '130201': errors.PermissionDenied,
424
- '130202': errors.ExchangeError,
425
- '130203': errors.InsufficientFunds,
426
- '130204': errors.BadRequest,
427
- '200004': errors.InsufficientFunds,
428
- '210014': errors.InvalidOrder,
429
- '210021': errors.InsufficientFunds,
430
- '230003': errors.InsufficientFunds,
431
- '260000': errors.InvalidAddress,
432
- '260100': errors.InsufficientFunds,
433
- '300000': errors.InvalidOrder,
434
- '400000': errors.BadSymbol,
435
- '400001': errors.AuthenticationError,
436
- '400002': errors.InvalidNonce,
437
- '400003': errors.AuthenticationError,
438
- '400004': errors.AuthenticationError,
439
- '400005': errors.AuthenticationError,
440
- '400006': errors.AuthenticationError,
441
- '400007': errors.AuthenticationError,
442
- '400008': errors.NotSupported,
443
- '400100': errors.BadRequest,
444
- '400200': errors.InvalidOrder,
445
- '400350': errors.InvalidOrder,
446
- '400370': errors.InvalidOrder,
447
- '400400': errors.BadRequest,
448
- '400500': errors.InvalidOrder,
449
- '400600': errors.BadSymbol,
450
- '400760': errors.InvalidOrder,
451
- '401000': errors.BadRequest,
452
- '411100': errors.AccountSuspended,
453
- '415000': errors.BadRequest,
454
- '400303': errors.PermissionDenied,
455
- '500000': errors.ExchangeNotAvailable,
456
- '260220': errors.InvalidAddress,
457
- '900014': errors.BadRequest, // {"code":"900014","msg":"Invalid chainId"}
458
- },
459
- 'broad': {
460
- 'Exceeded the access frequency': errors.RateLimitExceeded,
461
- 'require more permission': errors.PermissionDenied,
462
- },
463
- },
464
- 'fees': {
465
- 'trading': {
466
- 'tierBased': true,
467
- 'percentage': true,
468
- 'taker': this.parseNumber('0.001'),
469
- 'maker': this.parseNumber('0.001'),
470
- 'tiers': {
471
- 'taker': [
472
- [this.parseNumber('0'), this.parseNumber('0.001')],
473
- [this.parseNumber('50'), this.parseNumber('0.001')],
474
- [this.parseNumber('200'), this.parseNumber('0.0009')],
475
- [this.parseNumber('500'), this.parseNumber('0.0008')],
476
- [this.parseNumber('1000'), this.parseNumber('0.0007')],
477
- [this.parseNumber('2000'), this.parseNumber('0.0007')],
478
- [this.parseNumber('4000'), this.parseNumber('0.0006')],
479
- [this.parseNumber('8000'), this.parseNumber('0.0005')],
480
- [this.parseNumber('15000'), this.parseNumber('0.00045')],
481
- [this.parseNumber('25000'), this.parseNumber('0.0004')],
482
- [this.parseNumber('40000'), this.parseNumber('0.00035')],
483
- [this.parseNumber('60000'), this.parseNumber('0.0003')],
484
- [this.parseNumber('80000'), this.parseNumber('0.00025')],
485
- ],
486
- 'maker': [
487
- [this.parseNumber('0'), this.parseNumber('0.001')],
488
- [this.parseNumber('50'), this.parseNumber('0.0009')],
489
- [this.parseNumber('200'), this.parseNumber('0.0007')],
490
- [this.parseNumber('500'), this.parseNumber('0.0005')],
491
- [this.parseNumber('1000'), this.parseNumber('0.0003')],
492
- [this.parseNumber('2000'), this.parseNumber('0')],
493
- [this.parseNumber('4000'), this.parseNumber('0')],
494
- [this.parseNumber('8000'), this.parseNumber('0')],
495
- [this.parseNumber('15000'), this.parseNumber('-0.00005')],
496
- [this.parseNumber('25000'), this.parseNumber('-0.00005')],
497
- [this.parseNumber('40000'), this.parseNumber('-0.00005')],
498
- [this.parseNumber('60000'), this.parseNumber('-0.00005')],
499
- [this.parseNumber('80000'), this.parseNumber('-0.00005')],
500
- ],
501
- },
502
- },
503
- 'funding': {
504
- 'tierBased': false,
505
- 'percentage': false,
506
- 'withdraw': {},
507
- 'deposit': {},
508
- },
509
- },
510
- 'commonCurrencies': {
511
- 'BIFI': 'BIFIF',
512
- 'VAI': 'VAIOT',
513
- 'WAX': 'WAXP',
514
- },
515
- 'options': {
516
- 'version': 'v1',
517
- 'symbolSeparator': '-',
518
- 'fetchMyTradesMethod': 'private_get_fills',
519
- 'fetchCurrencies': {
520
- 'webApiEnable': true,
521
- 'webApiRetries': 1,
522
- 'webApiMuteFailure': true,
523
- },
524
- 'fetchMarkets': {
525
- 'fetchTickersFees': true,
526
- },
527
- 'withdraw': {
528
- 'includeFee': false,
529
- },
530
- // endpoint versions
531
- 'versions': {
532
- 'public': {
533
- 'GET': {
534
- // spot trading
535
- 'currencies': 'v3',
536
- 'currencies/{currency}': 'v3',
537
- 'symbols': 'v2',
538
- },
539
- },
540
- 'private': {
541
- 'GET': {
542
- // account
543
- 'user-info': 'v2',
544
- 'hf/margin/account/ledgers': 'v3',
545
- 'sub/user': 'v2',
546
- 'sub-accounts': 'v2',
547
- // funding
548
- 'margin/accounts': 'v3',
549
- 'isolated/accounts': 'v3',
550
- // 'deposit-addresses': 'v2',
551
- 'deposit-addresses': 'v1',
552
- // spot trading
553
- 'market/orderbook/level2': 'v3',
554
- 'market/orderbook/level3': 'v3',
555
- 'market/orderbook/level{level}': 'v3',
556
- 'oco/order/{orderId}': 'v3',
557
- 'oco/order/details/{orderId}': 'v3',
558
- 'oco/client-order/{clientOid}': 'v3',
559
- 'oco/orders': 'v3',
560
- // margin trading
561
- 'hf/margin/orders/active': 'v3',
562
- 'hf/margin/orders/done': 'v3',
563
- 'hf/margin/orders/{orderId}': 'v3',
564
- 'hf/margin/orders/client-order/{clientOid}': 'v3',
565
- 'hf/margin/fills': 'v3',
566
- 'etf/info': 'v3',
567
- 'margin/currencies': 'v3',
568
- 'margin/borrow': 'v3',
569
- 'margin/repay': 'v3',
570
- 'project/list': 'v3',
571
- 'project/marketInterestRate': 'v3',
572
- 'redeem/orders': 'v3',
573
- 'purchase/orders': 'v3',
574
- },
575
- 'POST': {
576
- // account
577
- 'sub/user/created': 'v2',
578
- // funding
579
- 'accounts/universal-transfer': 'v3',
580
- 'accounts/sub-transfer': 'v2',
581
- 'accounts/inner-transfer': 'v2',
582
- 'transfer-out': 'v3',
583
- // spot trading
584
- 'oco/order': 'v3',
585
- // margin trading
586
- 'hf/margin/order': 'v3',
587
- 'hf/margin/order/test': 'v3',
588
- 'margin/borrow': 'v3',
589
- 'margin/repay': 'v3',
590
- 'purchase': 'v3',
591
- 'redeem': 'v3',
592
- 'lend/purchase/update': 'v3',
593
- },
594
- 'DELETE': {
595
- // account
596
- // funding
597
- // spot trading
598
- 'hf/margin/orders/{orderId}': 'v3',
599
- 'hf/margin/orders/client-order/{clientOid}': 'v3',
600
- 'hf/margin/orders': 'v3',
601
- 'oco/order/{orderId}': 'v3',
602
- 'oco/client-order/{clientOid}': 'v3',
603
- 'oco/orders': 'v3',
604
- // margin trading
605
- },
606
- },
607
- 'futuresPrivate': {
608
- 'POST': {
609
- 'transfer-out': 'v3',
610
- },
611
- },
612
- },
613
- 'partner': {
614
- // the support for spot and future exchanges as separate settings
615
- 'spot': {
616
- 'id': 'ccxt',
617
- 'key': '9e58cc35-5b5e-4133-92ec-166e3f077cb8',
618
- },
619
- 'future': {
620
- 'id': 'ccxtfutures',
621
- 'key': '1b327198-f30c-4f14-a0ac-918871282f15',
622
- },
623
- // exchange-wide settings are also supported
624
- // 'id': 'ccxt'
625
- // 'key': '9e58cc35-5b5e-4133-92ec-166e3f077cb8',
626
- },
627
- 'accountsByType': {
628
- 'spot': 'trade',
629
- 'margin': 'margin',
630
- 'cross': 'margin',
631
- 'isolated': 'isolated',
632
- 'main': 'main',
633
- 'funding': 'main',
634
- 'future': 'contract',
635
- 'swap': 'contract',
636
- 'mining': 'pool',
637
- 'hf': 'trade_hf',
638
- },
639
- 'networks': {
640
- 'BTC': 'btc',
641
- 'BTCNATIVESEGWIT': 'bech32',
642
- 'ERC20': 'eth',
643
- 'TRC20': 'trx',
644
- 'HRC20': 'heco',
645
- 'MATIC': 'matic',
646
- 'KCC': 'kcc',
647
- 'SOL': 'sol',
648
- 'ALGO': 'algo',
649
- 'EOS': 'eos',
650
- 'BEP20': 'bsc',
651
- 'BEP2': 'bnb',
652
- 'ARBONE': 'arbitrum',
653
- 'AVAXX': 'avax',
654
- 'AVAXC': 'avaxc',
655
- 'TLOS': 'tlos',
656
- 'CFX': 'cfx',
657
- 'ACA': 'aca',
658
- 'OPTIMISM': 'optimism',
659
- 'ONT': 'ont',
660
- 'GLMR': 'glmr',
661
- 'CSPR': 'cspr',
662
- 'KLAY': 'klay',
663
- 'XRD': 'xrd',
664
- 'RVN': 'rvn',
665
- 'NEAR': 'near',
666
- 'APT': 'aptos',
667
- 'ETHW': 'ethw',
668
- 'TON': 'ton',
669
- 'BCH': 'bch',
670
- 'BSV': 'bchsv',
671
- 'BCHA': 'bchabc',
672
- 'OSMO': 'osmo',
673
- 'NANO': 'nano',
674
- 'XLM': 'xlm',
675
- 'VET': 'vet',
676
- 'IOST': 'iost',
677
- 'ZIL': 'zil',
678
- 'XRP': 'xrp',
679
- 'TOMO': 'tomo',
680
- 'XMR': 'xmr',
681
- 'COTI': 'coti',
682
- 'XTZ': 'xtz',
683
- 'ADA': 'ada',
684
- 'WAX': 'waxp',
685
- 'THETA': 'theta',
686
- 'ONE': 'one',
687
- 'IOTEX': 'iotx',
688
- 'NULS': 'nuls',
689
- 'KSM': 'ksm',
690
- 'LTC': 'ltc',
691
- 'WAVES': 'waves',
692
- 'DOT': 'dot',
693
- 'STEEM': 'steem',
694
- 'QTUM': 'qtum',
695
- 'DOGE': 'doge',
696
- 'FIL': 'fil',
697
- 'XYM': 'xym',
698
- 'FLUX': 'flux',
699
- 'ATOM': 'atom',
700
- 'XDC': 'xdc',
701
- 'KDA': 'kda',
702
- 'ICP': 'icp',
703
- 'CELO': 'celo',
704
- 'LSK': 'lsk',
705
- 'VSYS': 'vsys',
706
- 'KAR': 'kar',
707
- 'XCH': 'xch',
708
- 'FLOW': 'flow',
709
- 'BAND': 'band',
710
- 'EGLD': 'egld',
711
- 'HBAR': 'hbar',
712
- 'XPR': 'xpr',
713
- 'AR': 'ar',
714
- 'FTM': 'ftm',
715
- 'KAVA': 'kava',
716
- 'KMA': 'kma',
717
- 'XEC': 'xec',
718
- 'IOTA': 'iota',
719
- 'HNT': 'hnt',
720
- 'ASTR': 'astr',
721
- 'PDEX': 'pdex',
722
- 'METIS': 'metis',
723
- 'ZEC': 'zec',
724
- 'POKT': 'pokt',
725
- 'OASYS': 'oas',
726
- 'OASIS': 'oasis',
727
- 'ETC': 'etc',
728
- 'AKT': 'akt',
729
- 'FSN': 'fsn',
730
- 'SCRT': 'scrt',
731
- 'CFG': 'cfg',
732
- 'ICX': 'icx',
733
- 'KMD': 'kmd',
734
- 'NEM': 'NEM',
735
- 'STX': 'stx',
736
- 'DGB': 'dgb',
737
- 'DCR': 'dcr',
738
- 'CKB': 'ckb',
739
- 'ELA': 'ela',
740
- 'HYDRA': 'hydra',
741
- 'BTM': 'btm',
742
- 'KARDIA': 'kai',
743
- 'SXP': 'sxp',
744
- 'NEBL': 'nebl',
745
- 'ZEN': 'zen',
746
- 'SDN': 'sdn',
747
- 'LTO': 'lto',
748
- 'WEMIX': 'wemix',
749
- // 'BOBA': 'boba', // tbd
750
- 'EVER': 'ever',
751
- 'BNC': 'bnc',
752
- 'BNCDOT': 'bncdot',
753
- // 'CMP': 'cmp', // todo: after consensus
754
- 'AION': 'aion',
755
- 'GRIN': 'grin',
756
- 'LOKI': 'loki',
757
- 'QKC': 'qkc',
758
- 'TT': 'TT',
759
- 'PIVX': 'pivx',
760
- 'SERO': 'sero',
761
- 'METER': 'meter',
762
- 'STATEMINE': 'statemine',
763
- 'DVPN': 'dvpn',
764
- 'XPRT': 'xprt',
765
- 'MOVR': 'movr',
766
- 'ERGO': 'ergo',
767
- 'ABBC': 'abbc',
768
- 'DIVI': 'divi',
769
- 'PURA': 'pura',
770
- 'DFI': 'dfi',
771
- // 'NEO': 'neo', // tbd neo legacy
772
- 'NEON3': 'neon3',
773
- 'DOCK': 'dock',
774
- 'TRUE': 'true',
775
- 'CS': 'cs',
776
- 'ORAI': 'orai',
777
- // below will be uncommented after consensus
778
- // 'BITCOINDIAMON': 'bcd',
779
- // 'BITCOINGOLD': 'btg',
780
- // 'HTR': 'htr',
781
- // 'DEROHE': 'derohe',
782
- // 'NDAU': 'ndau',
783
- // 'HPB': 'hpb',
784
- // 'AXE': 'axe',
785
- // 'BITCOINPRIVATE': 'btcp',
786
- // 'EDGEWARE': 'edg',
787
- // 'JUPITER': 'jup',
788
- // 'VELAS': 'vlx', // vlxevm is different
789
- // // 'terra' luna lunc TBD
790
- // 'DIGITALBITS': 'xdb',
791
- // // fra is fra-emv on kucoin
792
- // 'PASTEL': 'psl',
793
- // // sysevm
794
- // 'CONCORDIUM': 'ccd',
795
- // 'AURORA': 'aurora',
796
- // 'PHA': 'pha', // a.k.a. khala
797
- // 'PAL': 'pal',
798
- // 'RSK': 'rbtc',
799
- // 'NIX': 'nix',
800
- // 'NIM': 'nim',
801
- // 'NRG': 'nrg',
802
- // 'RFOX': 'rfox',
803
- // 'PIONEER': 'neer',
804
- // 'PIXIE': 'pix',
805
- // 'ALEPHZERO': 'azero',
806
- // 'ACHAIN': 'act', // actevm is different
807
- // 'BOSCOIN': 'bos',
808
- // 'ELECTRONEUM': 'etn',
809
- // 'GOCHAIN': 'go',
810
- // 'SOPHIATX': 'sphtx',
811
- // 'WANCHAIN': 'wan',
812
- // 'ZEEPIN': 'zpt',
813
- // 'MATRIXAI': 'man',
814
- // 'METADIUM': 'meta',
815
- // 'METAHASH': 'mhc',
816
- // // eosc --"eosforce" tbd
817
- // 'IOTCHAIN': 'itc',
818
- // 'CONTENTOS': 'cos',
819
- // 'CPCHAIN': 'cpc',
820
- // 'INTCHAIN': 'int',
821
- // // 'DASH': 'dash', tbd digita-cash
822
- // 'WALTONCHAIN': 'wtc',
823
- // 'CONSTELLATION': 'dag',
824
- // 'ONELEDGER': 'olt',
825
- // 'AIRDAO': 'amb', // a.k.a. AMBROSUS
826
- // 'ENERGYWEB': 'ewt',
827
- // 'WAVESENTERPRISE': 'west',
828
- // 'HYPERCASH': 'hc',
829
- // 'ENECUUM': 'enq',
830
- // 'HAVEN': 'xhv',
831
- // 'CHAINX': 'pcx',
832
- // // 'FLUXOLD': 'zel', // zel seems old chain (with uppercase FLUX in kucoin UI and with id 'zel')
833
- // 'BUMO': 'bu',
834
- // 'DEEPONION': 'onion',
835
- // 'ULORD': 'ut',
836
- // 'ASCH': 'xas',
837
- // 'SOLARIS': 'xlr',
838
- // 'APOLLO': 'apl',
839
- // 'PIRATECHAIN': 'arrr',
840
- // 'ULTRA': 'uos',
841
- // 'EMONEY': 'ngm',
842
- // 'AURORACHAIN': 'aoa',
843
- // 'KLEVER': 'klv',
844
- // undetermined: xns(insolar), rhoc, luk (luniverse), kts (klimatas), bchn (bitcoin cash node), god (shallow entry), lit (litmus),
845
- },
846
- 'marginModes': {
847
- 'cross': 'MARGIN_TRADE',
848
- 'isolated': 'MARGIN_ISOLATED_TRADE',
849
- 'spot': 'TRADE',
850
- },
851
- },
852
- });
853
- }
854
- nonce() {
855
- return this.milliseconds();
856
- }
857
- async fetchTime(params = {}) {
858
- /**
859
- * @method
860
- * @name kucoin#fetchTime
861
- * @description fetches the current integer timestamp in milliseconds from the exchange server
862
- * @see https://docs.kucoin.com/#server-time
863
- * @param {object} [params] extra parameters specific to the exchange API endpoint
864
- * @returns {int} the current integer timestamp in milliseconds from the exchange server
865
- */
866
- const response = await this.publicGetTimestamp(params);
867
- //
868
- // {
869
- // "code":"200000",
870
- // "msg":"success",
871
- // "data":1546837113087
872
- // }
873
- //
874
- return this.safeInteger(response, 'data');
875
- }
876
- async fetchStatus(params = {}) {
877
- /**
878
- * @method
879
- * @name kucoin#fetchStatus
880
- * @description the latest known information on the availability of the exchange API
881
- * @see https://docs.kucoin.com/#service-status
882
- * @param {object} [params] extra parameters specific to the exchange API endpoint
883
- * @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
884
- */
885
- const response = await this.publicGetStatus(params);
886
- //
887
- // {
888
- // "code":"200000",
889
- // "data":{
890
- // "status":"open", //open, close, cancelonly
891
- // "msg":"upgrade match engine" //remark for operation
892
- // }
893
- // }
894
- //
895
- const data = this.safeValue(response, 'data', {});
896
- const status = this.safeString(data, 'status');
897
- return {
898
- 'status': (status === 'open') ? 'ok' : 'maintenance',
899
- 'updated': undefined,
900
- 'eta': undefined,
901
- 'url': undefined,
902
- 'info': response,
903
- };
904
- }
905
- async fetchMarkets(params = {}) {
906
- /**
907
- * @method
908
- * @name kucoin#fetchMarkets
909
- * @description retrieves data on all markets for kucoin
910
- * @see https://docs.kucoin.com/#get-symbols-list-deprecated
911
- * @see https://docs.kucoin.com/#get-all-tickers
912
- * @param {object} [params] extra parameters specific to the exchange API endpoint
913
- * @returns {object[]} an array of objects representing market data
914
- */
915
- const response = await this.publicGetSymbols(params);
916
- //
917
- // {
918
- // "code": "200000",
919
- // "data": [
920
- // {
921
- // "symbol": "XLM-USDT",
922
- // "name": "XLM-USDT",
923
- // "baseCurrency": "XLM",
924
- // "quoteCurrency": "USDT",
925
- // "feeCurrency": "USDT",
926
- // "market": "USDS",
927
- // "baseMinSize": "0.1",
928
- // "quoteMinSize": "0.01",
929
- // "baseMaxSize": "10000000000",
930
- // "quoteMaxSize": "99999999",
931
- // "baseIncrement": "0.0001",
932
- // "quoteIncrement": "0.000001",
933
- // "priceIncrement": "0.000001",
934
- // "priceLimitRate": "0.1",
935
- // "isMarginEnabled": true,
936
- // "enableTrading": true
937
- // },
938
- // ]
939
- // }
940
- //
941
- const data = this.safeValue(response, 'data');
942
- const options = this.safeValue(this.options, 'fetchMarkets', {});
943
- const fetchTickersFees = this.safeValue(options, 'fetchTickersFees', true);
944
- let tickersResponse = {};
945
- if (fetchTickersFees) {
946
- tickersResponse = await this.publicGetMarketAllTickers(params);
947
- }
948
- //
949
- // {
950
- // "code": "200000",
951
- // "data": {
952
- // "time":1602832092060,
953
- // "ticker":[
954
- // {
955
- // "symbol": "BTC-USDT", // symbol
956
- // "symbolName":"BTC-USDT", // Name of trading pairs, it would change after renaming
957
- // "buy": "11328.9", // bestAsk
958
- // "sell": "11329", // bestBid
959
- // "changeRate": "-0.0055", // 24h change rate
960
- // "changePrice": "-63.6", // 24h change price
961
- // "high": "11610", // 24h highest price
962
- // "low": "11200", // 24h lowest price
963
- // "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
964
- // "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
965
- // "last": "11328.9", // last price
966
- // "averagePrice": "11360.66065903", // 24h average transaction price yesterday
967
- // "takerFeeRate": "0.001", // Basic Taker Fee
968
- // "makerFeeRate": "0.001", // Basic Maker Fee
969
- // "takerCoefficient": "1", // Taker Fee Coefficient
970
- // "makerCoefficient": "1" // Maker Fee Coefficient
971
- // }
972
- // ]
973
- // }
974
- // }
975
- //
976
- const tickersData = this.safeValue(tickersResponse, 'data', {});
977
- const tickers = this.safeValue(tickersData, 'ticker', []);
978
- const tickersByMarketId = this.indexBy(tickers, 'symbol');
979
- const result = [];
980
- for (let i = 0; i < data.length; i++) {
981
- const market = data[i];
982
- const id = this.safeString(market, 'symbol');
983
- const [baseId, quoteId] = id.split('-');
984
- const base = this.safeCurrencyCode(baseId);
985
- const quote = this.safeCurrencyCode(quoteId);
986
- // const quoteIncrement = this.safeNumber (market, 'quoteIncrement');
987
- const ticker = this.safeValue(tickersByMarketId, id, {});
988
- const makerFeeRate = this.safeString(ticker, 'makerFeeRate');
989
- const takerFeeRate = this.safeString(ticker, 'takerFeeRate');
990
- const makerCoefficient = this.safeString(ticker, 'makerCoefficient');
991
- const takerCoefficient = this.safeString(ticker, 'takerCoefficient');
992
- result.push({
993
- 'id': id,
994
- 'symbol': base + '/' + quote,
995
- 'base': base,
996
- 'quote': quote,
997
- 'settle': undefined,
998
- 'baseId': baseId,
999
- 'quoteId': quoteId,
1000
- 'settleId': undefined,
1001
- 'type': 'spot',
1002
- 'spot': true,
1003
- 'margin': this.safeValue(market, 'isMarginEnabled'),
1004
- 'swap': false,
1005
- 'future': false,
1006
- 'option': false,
1007
- 'active': this.safeValue(market, 'enableTrading'),
1008
- 'contract': false,
1009
- 'linear': undefined,
1010
- 'inverse': undefined,
1011
- 'taker': this.parseNumber(Precise["default"].stringMul(takerFeeRate, takerCoefficient)),
1012
- 'maker': this.parseNumber(Precise["default"].stringMul(makerFeeRate, makerCoefficient)),
1013
- 'contractSize': undefined,
1014
- 'expiry': undefined,
1015
- 'expiryDatetime': undefined,
1016
- 'strike': undefined,
1017
- 'optionType': undefined,
1018
- 'precision': {
1019
- 'amount': this.safeNumber(market, 'baseIncrement'),
1020
- 'price': this.safeNumber(market, 'priceIncrement'),
1021
- },
1022
- 'limits': {
1023
- 'leverage': {
1024
- 'min': undefined,
1025
- 'max': undefined,
1026
- },
1027
- 'amount': {
1028
- 'min': this.safeNumber(market, 'baseMinSize'),
1029
- 'max': this.safeNumber(market, 'baseMaxSize'),
1030
- },
1031
- 'price': {
1032
- 'min': undefined,
1033
- 'max': undefined,
1034
- },
1035
- 'cost': {
1036
- 'min': this.safeNumber(market, 'quoteMinSize'),
1037
- 'max': this.safeNumber(market, 'quoteMaxSize'),
1038
- },
1039
- },
1040
- 'created': undefined,
1041
- 'info': market,
1042
- });
1043
- }
1044
- return result;
1045
- }
1046
- async fetchCurrencies(params = {}) {
1047
- /**
1048
- * @method
1049
- * @name kucoin#fetchCurrencies
1050
- * @description fetches all available currencies on an exchange
1051
- * @see https://docs.kucoin.com/#get-currencies
1052
- * @param {object} params extra parameters specific to the exchange API endpoint
1053
- * @returns {object} an associative dictionary of currencies
1054
- */
1055
- const promises = [];
1056
- promises.push(this.publicGetCurrencies(params));
1057
- //
1058
- // {
1059
- // "code":"200000",
1060
- // "data":[
1061
- // {
1062
- // "currency":"CSP",
1063
- // "name":"CSP",
1064
- // "fullName":"Caspian",
1065
- // "precision":8,
1066
- // "confirms":null,
1067
- // "contractAddress":null,
1068
- // "isMarginEnabled":false,
1069
- // "isDebitEnabled":false,
1070
- // "chains":[
1071
- // {
1072
- // "chainName":"ERC20",
1073
- // "chain":"eth",
1074
- // "withdrawalMinSize":"2999",
1075
- // "withdrawalMinFee":"2999",
1076
- // "isWithdrawEnabled":false,
1077
- // "isDepositEnabled":false,
1078
- // "confirms":12,
1079
- // "preConfirms":12,
1080
- // "contractAddress":"0xa6446d655a0c34bc4f05042ee88170d056cbaf45",
1081
- // "depositFeeRate": "0.001", // present for some currencies/networks
1082
- // }
1083
- // ]
1084
- // },
1085
- // }
1086
- //
1087
- promises.push(this.fetchWebEndpoint('fetchCurrencies', 'webExchangeGetCurrencyCurrencyChainInfo', true));
1088
- //
1089
- // {
1090
- // "success": true,
1091
- // "code": "200",
1092
- // "msg": "success",
1093
- // "retry": false,
1094
- // "data": [
1095
- // {
1096
- // "status": "enabled",
1097
- // "currency": "BTC",
1098
- // "isChainEnabled": "true",
1099
- // "chain": "btc",
1100
- // "chainName": "BTC",
1101
- // "chainFullName": "Bitcoin",
1102
- // "walletPrecision": "8",
1103
- // "isDepositEnabled": "true",
1104
- // "depositMinSize": "0.00005",
1105
- // "confirmationCount": "2",
1106
- // "isWithdrawEnabled": "true",
1107
- // "withdrawMinSize": "0.001",
1108
- // "withdrawMinFee": "0.0005",
1109
- // "withdrawFeeRate": "0",
1110
- // "depositDisabledTip": "Wallet Maintenance",
1111
- // "preDepositTipEnabled": "true",
1112
- // "preDepositTip": "Do not transfer from ETH network directly",
1113
- // "withdrawDisabledTip": "",
1114
- // "preWithdrawTipEnabled": "false",
1115
- // "preWithdrawTip": "",
1116
- // "orgAddress": "",
1117
- // "userAddressName": "Memo",
1118
- // },
1119
- // ]
1120
- // }
1121
- //
1122
- const responses = await Promise.all(promises);
1123
- const currenciesResponse = this.safeValue(responses, 0, {});
1124
- const currenciesData = this.safeValue(currenciesResponse, 'data', []);
1125
- const additionalResponse = this.safeValue(responses, 1, {});
1126
- const additionalData = this.safeValue(additionalResponse, 'data', []);
1127
- const additionalDataGrouped = this.groupBy(additionalData, 'currency');
1128
- const result = {};
1129
- for (let i = 0; i < currenciesData.length; i++) {
1130
- const entry = currenciesData[i];
1131
- const id = this.safeString(entry, 'currency');
1132
- const name = this.safeString(entry, 'fullName');
1133
- const code = this.safeCurrencyCode(id);
1134
- let isWithdrawEnabled = undefined;
1135
- let isDepositEnabled = undefined;
1136
- const networks = {};
1137
- const chains = this.safeValue(entry, 'chains', []);
1138
- const extraChainsData = this.indexBy(this.safeValue(additionalDataGrouped, id, []), 'chain');
1139
- const rawPrecision = this.safeString(entry, 'precision');
1140
- const precision = this.parseNumber(this.parsePrecision(rawPrecision));
1141
- const chainsLength = chains.length;
1142
- if (!chainsLength) {
1143
- // https://t.me/KuCoin_API/173118
1144
- isWithdrawEnabled = false;
1145
- isDepositEnabled = false;
1146
- }
1147
- for (let j = 0; j < chainsLength; j++) {
1148
- const chain = chains[j];
1149
- const chainId = this.safeString(chain, 'chainId');
1150
- const networkCode = this.networkIdToCode(chainId);
1151
- const chainWithdrawEnabled = this.safeValue(chain, 'isWithdrawEnabled', false);
1152
- if (isWithdrawEnabled === undefined) {
1153
- isWithdrawEnabled = chainWithdrawEnabled;
1154
- }
1155
- else {
1156
- isWithdrawEnabled = isWithdrawEnabled || chainWithdrawEnabled;
1157
- }
1158
- const chainDepositEnabled = this.safeValue(chain, 'isDepositEnabled', false);
1159
- if (isDepositEnabled === undefined) {
1160
- isDepositEnabled = chainDepositEnabled;
1161
- }
1162
- else {
1163
- isDepositEnabled = isDepositEnabled || chainDepositEnabled;
1164
- }
1165
- const chainExtraData = this.safeValue(extraChainsData, chainId, {});
1166
- networks[networkCode] = {
1167
- 'info': chain,
1168
- 'id': chainId,
1169
- 'name': this.safeString(chain, 'chainName'),
1170
- 'code': networkCode,
1171
- 'active': chainWithdrawEnabled && chainDepositEnabled,
1172
- 'fee': this.safeNumber(chain, 'withdrawalMinFee'),
1173
- 'deposit': chainDepositEnabled,
1174
- 'withdraw': chainWithdrawEnabled,
1175
- 'precision': this.parseNumber(this.parsePrecision(this.safeString(chainExtraData, 'walletPrecision'))),
1176
- 'limits': {
1177
- 'withdraw': {
1178
- 'min': this.safeNumber(chain, 'withdrawalMinSize'),
1179
- 'max': undefined,
1180
- },
1181
- 'deposit': {
1182
- 'min': this.safeNumber(chainExtraData, 'depositMinSize'),
1183
- 'max': undefined,
1184
- },
1185
- },
1186
- };
1187
- }
1188
- // kucoin has determined 'fiat' currencies with below logic
1189
- const isFiat = (rawPrecision === '2') && (chainsLength === 0);
1190
- result[code] = {
1191
- 'id': id,
1192
- 'name': name,
1193
- 'code': code,
1194
- 'type': isFiat ? 'fiat' : 'crypto',
1195
- 'precision': precision,
1196
- 'info': entry,
1197
- 'active': (isDepositEnabled || isWithdrawEnabled),
1198
- 'deposit': isDepositEnabled,
1199
- 'withdraw': isWithdrawEnabled,
1200
- 'fee': undefined,
1201
- 'limits': this.limits,
1202
- 'networks': networks,
1203
- };
1204
- }
1205
- return result;
1206
- }
1207
- async fetchAccounts(params = {}) {
1208
- /**
1209
- * @method
1210
- * @name kucoin#fetchAccounts
1211
- * @description fetch all the accounts associated with a profile
1212
- * @see https://docs.kucoin.com/#list-accounts
1213
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1214
- * @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
1215
- */
1216
- const response = await this.privateGetAccounts(params);
1217
- //
1218
- // {
1219
- // "code": "200000",
1220
- // "data": [
1221
- // {
1222
- // "balance": "0.00009788",
1223
- // "available": "0.00009788",
1224
- // "holds": "0",
1225
- // "currency": "BTC",
1226
- // "id": "5c6a4fd399a1d81c4f9cc4d0",
1227
- // "type": "trade"
1228
- // },
1229
- // {
1230
- // "balance": "0.00000001",
1231
- // "available": "0.00000001",
1232
- // "holds": "0",
1233
- // "currency": "ETH",
1234
- // "id": "5c6a49ec99a1d819392e8e9f",
1235
- // "type": "trade"
1236
- // }
1237
- // ]
1238
- // }
1239
- //
1240
- const data = this.safeValue(response, 'data', []);
1241
- const result = [];
1242
- for (let i = 0; i < data.length; i++) {
1243
- const account = data[i];
1244
- const accountId = this.safeString(account, 'id');
1245
- const currencyId = this.safeString(account, 'currency');
1246
- const code = this.safeCurrencyCode(currencyId);
1247
- const type = this.safeString(account, 'type'); // main or trade
1248
- result.push({
1249
- 'id': accountId,
1250
- 'type': type,
1251
- 'currency': code,
1252
- 'code': code,
1253
- 'info': account,
1254
- });
1255
- }
1256
- return result;
1257
- }
1258
- async fetchTransactionFee(code, params = {}) {
1259
- /**
1260
- * @method
1261
- * @name kucoin#fetchTransactionFee
1262
- * @description *DEPRECATED* please use fetchDepositWithdrawFee instead
1263
- * @see https://docs.kucoin.com/#get-withdrawal-quotas
1264
- * @param {string} code unified currency code
1265
- * @param {object} params extra parameters specific to the exchange API endpoint
1266
- * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
1267
- */
1268
- await this.loadMarkets();
1269
- const currency = this.currency(code);
1270
- const request = {
1271
- 'currency': currency['id'],
1272
- };
1273
- let networkCode = undefined;
1274
- [networkCode, params] = this.handleNetworkCodeAndParams(params);
1275
- if (networkCode !== undefined) {
1276
- request['chain'] = this.networkCodeToId(networkCode).toLowerCase();
1277
- }
1278
- const response = await this.privateGetWithdrawalsQuotas(this.extend(request, params));
1279
- const data = this.safeValue(response, 'data');
1280
- const withdrawFees = {};
1281
- withdrawFees[code] = this.safeNumber(data, 'withdrawMinFee');
1282
- return {
1283
- 'info': response,
1284
- 'withdraw': withdrawFees,
1285
- 'deposit': {},
1286
- };
1287
- }
1288
- async fetchDepositWithdrawFee(code, params = {}) {
1289
- /**
1290
- * @method
1291
- * @name kucoin#fetchDepositWithdrawFee
1292
- * @description fetch the fee for deposits and withdrawals
1293
- * @see https://docs.kucoin.com/#get-withdrawal-quotas
1294
- * @param {string} code unified currency code
1295
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1296
- * @param {string} [params.network] The chain of currency. This only apply for multi-chain currency, and there is no need for single chain currency; you can query the chain through the response of the GET /api/v2/currencies/{currency} interface
1297
- * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
1298
- */
1299
- await this.loadMarkets();
1300
- const currency = this.currency(code);
1301
- const request = {
1302
- 'currency': currency['id'],
1303
- };
1304
- let networkCode = undefined;
1305
- [networkCode, params] = this.handleNetworkCodeAndParams(params);
1306
- if (networkCode !== undefined) {
1307
- request['chain'] = this.networkCodeToId(networkCode).toLowerCase();
1308
- }
1309
- const response = await this.privateGetWithdrawalsQuotas(this.extend(request, params));
1310
- //
1311
- // {
1312
- // "code": "200000",
1313
- // "data": {
1314
- // "currency": "USDT",
1315
- // "limitBTCAmount": "1.00000000",
1316
- // "usedBTCAmount": "0.00000000",
1317
- // "remainAmount": "16548.072149",
1318
- // "availableAmount": "0",
1319
- // "withdrawMinFee": "25",
1320
- // "innerWithdrawMinFee": "0",
1321
- // "withdrawMinSize": "50",
1322
- // "isWithdrawEnabled": true,
1323
- // "precision": 6,
1324
- // "chain": "ERC20"
1325
- // }
1326
- // }
1327
- //
1328
- const data = this.safeValue(response, 'data');
1329
- return this.parseDepositWithdrawFee(data, currency);
1330
- }
1331
- parseDepositWithdrawFee(fee, currency = undefined) {
1332
- //
1333
- // {
1334
- // "currency": "USDT",
1335
- // "limitBTCAmount": "1.00000000",
1336
- // "usedBTCAmount": "0.00000000",
1337
- // "remainAmount": "16548.072149",
1338
- // "availableAmount": "0",
1339
- // "withdrawMinFee": "25",
1340
- // "innerWithdrawMinFee": "0",
1341
- // "withdrawMinSize": "50",
1342
- // "isWithdrawEnabled": true,
1343
- // "precision": 6,
1344
- // "chain": "ERC20"
1345
- // }
1346
- //
1347
- const result = {
1348
- 'info': fee,
1349
- 'withdraw': {
1350
- 'fee': undefined,
1351
- 'percentage': undefined,
1352
- },
1353
- 'deposit': {
1354
- 'fee': undefined,
1355
- 'percentage': undefined,
1356
- },
1357
- 'networks': {},
1358
- };
1359
- const isWithdrawEnabled = this.safeValue(fee, 'isWithdrawEnabled');
1360
- if (isWithdrawEnabled) {
1361
- result['withdraw']['fee'] = this.safeNumber2(fee, 'withdrawalMinFee', 'withdrawMinFee');
1362
- result['withdraw']['percentage'] = false;
1363
- const networkId = this.safeString(fee, 'chain');
1364
- if (networkId) {
1365
- const networkCode = this.networkIdToCode(networkId, this.safeString(currency, 'code'));
1366
- result['networks'][networkCode] = {
1367
- 'withdraw': result['withdraw'],
1368
- 'deposit': {
1369
- 'fee': undefined,
1370
- 'percentage': undefined,
1371
- },
1372
- };
1373
- }
1374
- }
1375
- return result;
1376
- }
1377
- isFuturesMethod(methodName, params) {
1378
- //
1379
- // Helper
1380
- // @methodName (string): The name of the method
1381
- // @params (dict): The parameters passed into {methodName}
1382
- // @return: true if the method used is meant for futures trading, false otherwise
1383
- //
1384
- const defaultType = this.safeString2(this.options, methodName, 'defaultType', 'trade');
1385
- const requestedType = this.safeString(params, 'type', defaultType);
1386
- const accountsByType = this.safeValue(this.options, 'accountsByType');
1387
- const type = this.safeString(accountsByType, requestedType);
1388
- if (type === undefined) {
1389
- const keys = Object.keys(accountsByType);
1390
- throw new errors.ExchangeError(this.id + ' isFuturesMethod() type must be one of ' + keys.join(', '));
1391
- }
1392
- params = this.omit(params, 'type');
1393
- return (type === 'contract') || (type === 'future') || (type === 'futures'); // * (type === 'futures') deprecated, use (type === 'future')
1394
- }
1395
- parseTicker(ticker, market = undefined) {
1396
- //
1397
- // {
1398
- // "symbol": "BTC-USDT", // symbol
1399
- // "symbolName":"BTC-USDT", // Name of trading pairs, it would change after renaming
1400
- // "buy": "11328.9", // bestAsk
1401
- // "sell": "11329", // bestBid
1402
- // "changeRate": "-0.0055", // 24h change rate
1403
- // "changePrice": "-63.6", // 24h change price
1404
- // "high": "11610", // 24h highest price
1405
- // "low": "11200", // 24h lowest price
1406
- // "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
1407
- // "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
1408
- // "last": "11328.9", // last price
1409
- // "averagePrice": "11360.66065903", // 24h average transaction price yesterday
1410
- // "takerFeeRate": "0.001", // Basic Taker Fee
1411
- // "makerFeeRate": "0.001", // Basic Maker Fee
1412
- // "takerCoefficient": "1", // Taker Fee Coefficient
1413
- // "makerCoefficient": "1" // Maker Fee Coefficient
1414
- // }
1415
- //
1416
- // {
1417
- // "trading": true,
1418
- // "symbol": "KCS-BTC",
1419
- // "buy": 0.00011,
1420
- // "sell": 0.00012,
1421
- // "sort": 100,
1422
- // "volValue": 3.13851792584, //total
1423
- // "baseCurrency": "KCS",
1424
- // "market": "BTC",
1425
- // "quoteCurrency": "BTC",
1426
- // "symbolCode": "KCS-BTC",
1427
- // "datetime": 1548388122031,
1428
- // "high": 0.00013,
1429
- // "vol": 27514.34842,
1430
- // "low": 0.0001,
1431
- // "changePrice": -1.0e-5,
1432
- // "changeRate": -0.0769,
1433
- // "lastTradedPrice": 0.00012,
1434
- // "board": 0,
1435
- // "mark": 0
1436
- // }
1437
- //
1438
- // market/ticker ws subscription
1439
- //
1440
- // {
1441
- // "bestAsk": "62258.9",
1442
- // "bestAskSize": "0.38579986",
1443
- // "bestBid": "62258.8",
1444
- // "bestBidSize": "0.0078381",
1445
- // "price": "62260.7",
1446
- // "sequence": "1621383297064",
1447
- // "size": "0.00002841",
1448
- // "time": 1634641777363
1449
- // }
1450
- //
1451
- let percentage = this.safeString(ticker, 'changeRate');
1452
- if (percentage !== undefined) {
1453
- percentage = Precise["default"].stringMul(percentage, '100');
1454
- }
1455
- let last = this.safeString2(ticker, 'last', 'lastTradedPrice');
1456
- last = this.safeString(ticker, 'price', last);
1457
- const marketId = this.safeString(ticker, 'symbol');
1458
- market = this.safeMarket(marketId, market, '-');
1459
- const symbol = market['symbol'];
1460
- const baseVolume = this.safeString(ticker, 'vol');
1461
- const quoteVolume = this.safeString(ticker, 'volValue');
1462
- const timestamp = this.safeInteger2(ticker, 'time', 'datetime');
1463
- return this.safeTicker({
1464
- 'symbol': symbol,
1465
- 'timestamp': timestamp,
1466
- 'datetime': this.iso8601(timestamp),
1467
- 'high': this.safeString(ticker, 'high'),
1468
- 'low': this.safeString(ticker, 'low'),
1469
- 'bid': this.safeString2(ticker, 'buy', 'bestBid'),
1470
- 'bidVolume': this.safeString(ticker, 'bestBidSize'),
1471
- 'ask': this.safeString2(ticker, 'sell', 'bestAsk'),
1472
- 'askVolume': this.safeString(ticker, 'bestAskSize'),
1473
- 'vwap': undefined,
1474
- 'open': this.safeString(ticker, 'open'),
1475
- 'close': last,
1476
- 'last': last,
1477
- 'previousClose': undefined,
1478
- 'change': this.safeString(ticker, 'changePrice'),
1479
- 'percentage': percentage,
1480
- 'average': this.safeString(ticker, 'averagePrice'),
1481
- 'baseVolume': baseVolume,
1482
- 'quoteVolume': quoteVolume,
1483
- 'info': ticker,
1484
- }, market);
1485
- }
1486
- async fetchTickers(symbols = undefined, params = {}) {
1487
- /**
1488
- * @method
1489
- * @name kucoin#fetchTickers
1490
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1491
- * @see https://docs.kucoin.com/#get-all-tickers
1492
- * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1493
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1494
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1495
- */
1496
- await this.loadMarkets();
1497
- symbols = this.marketSymbols(symbols);
1498
- const response = await this.publicGetMarketAllTickers(params);
1499
- //
1500
- // {
1501
- // "code": "200000",
1502
- // "data": {
1503
- // "time":1602832092060,
1504
- // "ticker":[
1505
- // {
1506
- // "symbol": "BTC-USDT", // symbol
1507
- // "symbolName":"BTC-USDT", // Name of trading pairs, it would change after renaming
1508
- // "buy": "11328.9", // bestAsk
1509
- // "sell": "11329", // bestBid
1510
- // "changeRate": "-0.0055", // 24h change rate
1511
- // "changePrice": "-63.6", // 24h change price
1512
- // "high": "11610", // 24h highest price
1513
- // "low": "11200", // 24h lowest price
1514
- // "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
1515
- // "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
1516
- // "last": "11328.9", // last price
1517
- // "averagePrice": "11360.66065903", // 24h average transaction price yesterday
1518
- // "takerFeeRate": "0.001", // Basic Taker Fee
1519
- // "makerFeeRate": "0.001", // Basic Maker Fee
1520
- // "takerCoefficient": "1", // Taker Fee Coefficient
1521
- // "makerCoefficient": "1" // Maker Fee Coefficient
1522
- // }
1523
- // ]
1524
- // }
1525
- // }
1526
- //
1527
- const data = this.safeValue(response, 'data', {});
1528
- const tickers = this.safeValue(data, 'ticker', []);
1529
- const time = this.safeInteger(data, 'time');
1530
- const result = {};
1531
- for (let i = 0; i < tickers.length; i++) {
1532
- tickers[i]['time'] = time;
1533
- const ticker = this.parseTicker(tickers[i]);
1534
- const symbol = this.safeString(ticker, 'symbol');
1535
- if (symbol !== undefined) {
1536
- result[symbol] = ticker;
1537
- }
1538
- }
1539
- return this.filterByArrayTickers(result, 'symbol', symbols);
1540
- }
1541
- async fetchTicker(symbol, params = {}) {
1542
- /**
1543
- * @method
1544
- * @name kucoin#fetchTicker
1545
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1546
- * @see https://docs.kucoin.com/#get-24hr-stats
1547
- * @param {string} symbol unified symbol of the market to fetch the ticker for
1548
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1549
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1550
- */
1551
- await this.loadMarkets();
1552
- const market = this.market(symbol);
1553
- const request = {
1554
- 'symbol': market['id'],
1555
- };
1556
- const response = await this.publicGetMarketStats(this.extend(request, params));
1557
- //
1558
- // {
1559
- // "code": "200000",
1560
- // "data": {
1561
- // "time": 1602832092060, // time
1562
- // "symbol": "BTC-USDT", // symbol
1563
- // "buy": "11328.9", // bestAsk
1564
- // "sell": "11329", // bestBid
1565
- // "changeRate": "-0.0055", // 24h change rate
1566
- // "changePrice": "-63.6", // 24h change price
1567
- // "high": "11610", // 24h highest price
1568
- // "low": "11200", // 24h lowest price
1569
- // "vol": "2282.70993217", // 24h volume,the aggregated trading volume in BTC
1570
- // "volValue": "25984946.157790431", // 24h total, the trading volume in quote currency of last 24 hours
1571
- // "last": "11328.9", // last price
1572
- // "averagePrice": "11360.66065903", // 24h average transaction price yesterday
1573
- // "takerFeeRate": "0.001", // Basic Taker Fee
1574
- // "makerFeeRate": "0.001", // Basic Maker Fee
1575
- // "takerCoefficient": "1", // Taker Fee Coefficient
1576
- // "makerCoefficient": "1" // Maker Fee Coefficient
1577
- // }
1578
- // }
1579
- //
1580
- return this.parseTicker(response['data'], market);
1581
- }
1582
- parseOHLCV(ohlcv, market = undefined) {
1583
- //
1584
- // [
1585
- // "1545904980", // Start time of the candle cycle
1586
- // "0.058", // opening price
1587
- // "0.049", // closing price
1588
- // "0.058", // highest price
1589
- // "0.049", // lowest price
1590
- // "0.018", // base volume
1591
- // "0.000945", // quote volume
1592
- // ]
1593
- //
1594
- return [
1595
- this.safeTimestamp(ohlcv, 0),
1596
- this.safeNumber(ohlcv, 1),
1597
- this.safeNumber(ohlcv, 3),
1598
- this.safeNumber(ohlcv, 4),
1599
- this.safeNumber(ohlcv, 2),
1600
- this.safeNumber(ohlcv, 5),
1601
- ];
1602
- }
1603
- async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
1604
- /**
1605
- * @method
1606
- * @name kucoin#fetchOHLCV
1607
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1608
- * @see https://docs.kucoin.com/#get-klines
1609
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1610
- * @param {string} timeframe the length of time each candle represents
1611
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
1612
- * @param {int} [limit] the maximum amount of candles to fetch
1613
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1614
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1615
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1616
- */
1617
- await this.loadMarkets();
1618
- let paginate = false;
1619
- [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate');
1620
- if (paginate) {
1621
- return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1500);
1622
- }
1623
- const market = this.market(symbol);
1624
- const marketId = market['id'];
1625
- const request = {
1626
- 'symbol': marketId,
1627
- 'type': this.safeString(this.timeframes, timeframe, timeframe),
1628
- };
1629
- const duration = this.parseTimeframe(timeframe) * 1000;
1630
- let endAt = this.milliseconds(); // required param
1631
- if (since !== undefined) {
1632
- request['startAt'] = this.parseToInt(Math.floor(since / 1000));
1633
- if (limit === undefined) {
1634
- // https://docs.kucoin.com/#get-klines
1635
- // https://docs.kucoin.com/#details
1636
- // For each query, the system would return at most 1500 pieces of data.
1637
- // To obtain more data, please page the data by time.
1638
- limit = this.safeInteger(this.options, 'fetchOHLCVLimit', 1500);
1639
- }
1640
- endAt = this.sum(since, limit * duration);
1641
- }
1642
- else if (limit !== undefined) {
1643
- since = endAt - limit * duration;
1644
- request['startAt'] = this.parseToInt(Math.floor(since / 1000));
1645
- }
1646
- request['endAt'] = this.parseToInt(Math.floor(endAt / 1000));
1647
- const response = await this.publicGetMarketCandles(this.extend(request, params));
1648
- //
1649
- // {
1650
- // "code":"200000",
1651
- // "data":[
1652
- // ["1591517700","0.025078","0.025069","0.025084","0.025064","18.9883256","0.4761861079404"],
1653
- // ["1591516800","0.025089","0.025079","0.025089","0.02506","99.4716622","2.494143499081"],
1654
- // ["1591515900","0.025079","0.02509","0.025091","0.025068","59.83701271","1.50060885172798"],
1655
- // ]
1656
- // }
1657
- //
1658
- const data = this.safeValue(response, 'data', []);
1659
- return this.parseOHLCVs(data, market, timeframe, since, limit);
1660
- }
1661
- async createDepositAddress(code, params = {}) {
1662
- /**
1663
- * @method
1664
- * @name kucoin#createDepositAddress
1665
- * @see https://docs.kucoin.com/#create-deposit-address
1666
- * @description create a currency deposit address
1667
- * @param {string} code unified currency code of the currency for the deposit address
1668
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1669
- * @param {string} [params.network] the blockchain network name
1670
- * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1671
- */
1672
- await this.loadMarkets();
1673
- const currency = this.currency(code);
1674
- const request = {
1675
- 'currency': currency['id'],
1676
- };
1677
- let networkCode = undefined;
1678
- [networkCode, params] = this.handleNetworkCodeAndParams(params);
1679
- if (networkCode !== undefined) {
1680
- request['chain'] = this.networkCodeToId(networkCode).toLowerCase();
1681
- }
1682
- const response = await this.privatePostDepositAddresses(this.extend(request, params));
1683
- // {"code":"260000","msg":"Deposit address already exists."}
1684
- // BCH {"code":"200000","data":{"address":"bitcoincash:qza3m4nj9rx7l9r0cdadfqxts6f92shvhvr5ls4q7z","memo":""}}
1685
- // BTC {"code":"200000","data":{"address":"36SjucKqQpQSvsak9A7h6qzFjrVXpRNZhE","memo":""}}
1686
- const data = this.safeValue(response, 'data', {});
1687
- return this.parseDepositAddress(data, currency);
1688
- }
1689
- async fetchDepositAddress(code, params = {}) {
1690
- /**
1691
- * @method
1692
- * @name kucoin#fetchDepositAddress
1693
- * @description fetch the deposit address for a currency associated with this account
1694
- * @see https://docs.kucoin.com/#get-deposit-addresses-v2
1695
- * @param {string} code unified currency code
1696
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1697
- * @param {string} [params.network] the blockchain network name
1698
- * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1699
- */
1700
- await this.loadMarkets();
1701
- const currency = this.currency(code);
1702
- const request = {
1703
- 'currency': currency['id'],
1704
- // for USDT - OMNI, ERC20, TRC20, default is ERC20
1705
- // for BTC - Native, Segwit, TRC20, the parameters are bech32, btc, trx, default is Native
1706
- // 'chain': 'ERC20', // optional
1707
- };
1708
- let networkCode = undefined;
1709
- [networkCode, params] = this.handleNetworkCodeAndParams(params);
1710
- if (networkCode !== undefined) {
1711
- request['chain'] = this.networkCodeToId(networkCode).toLowerCase();
1712
- }
1713
- const version = this.options['versions']['private']['GET']['deposit-addresses'];
1714
- this.options['versions']['private']['GET']['deposit-addresses'] = 'v1';
1715
- const response = await this.privateGetDepositAddresses(this.extend(request, params));
1716
- // BCH {"code":"200000","data":{"address":"bitcoincash:qza3m4nj9rx7l9r0cdadfqxts6f92shvhvr5ls4q7z","memo":""}}
1717
- // BTC {"code":"200000","data":{"address":"36SjucKqQpQSvsak9A7h6qzFjrVXpRNZhE","memo":""}}
1718
- this.options['versions']['private']['GET']['deposit-addresses'] = version;
1719
- const data = this.safeValue(response, 'data');
1720
- if (data === undefined) {
1721
- throw new errors.ExchangeError(this.id + ' fetchDepositAddress() returned an empty response, you might try to run createDepositAddress() first and try again');
1722
- }
1723
- return this.parseDepositAddress(data, currency);
1724
- }
1725
- parseDepositAddress(depositAddress, currency = undefined) {
1726
- let address = this.safeString(depositAddress, 'address');
1727
- // BCH/BSV is returned with a "bitcoincash:" prefix, which we cut off here and only keep the address
1728
- if (address !== undefined) {
1729
- address = address.replace('bitcoincash:', '');
1730
- }
1731
- let code = undefined;
1732
- if (currency !== undefined) {
1733
- code = currency['id'];
1734
- if (code !== 'NIM') {
1735
- // contains spaces
1736
- this.checkAddress(address);
1737
- }
1738
- }
1739
- return {
1740
- 'info': depositAddress,
1741
- 'currency': code,
1742
- 'address': address,
1743
- 'tag': this.safeString(depositAddress, 'memo'),
1744
- 'network': this.networkIdToCode(this.safeString(depositAddress, 'chain')),
1745
- };
1746
- }
1747
- async fetchDepositAddressesByNetwork(code, params = {}) {
1748
- /**
1749
- * @method
1750
- * @name kucoin#fetchDepositAddressesByNetwork
1751
- * @see https://docs.kucoin.com/#get-deposit-addresses-v2
1752
- * @description fetch the deposit address for a currency associated with this account
1753
- * @param {string} code unified currency code
1754
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1755
- * @returns {object} an array of [address structures]{@link https://docs.ccxt.com/#/?id=address-structure}
1756
- */
1757
- await this.loadMarkets();
1758
- const currency = this.currency(code);
1759
- const request = {
1760
- 'currency': currency['id'],
1761
- };
1762
- const version = this.options['versions']['private']['GET']['deposit-addresses'];
1763
- this.options['versions']['private']['GET']['deposit-addresses'] = 'v2';
1764
- const response = await this.privateGetDepositAddresses(this.extend(request, params));
1765
- //
1766
- // {
1767
- // "code": "200000",
1768
- // "data": [
1769
- // {
1770
- // "address": "fr1qvus7d4d5fgxj5e7zvqe6yhxd7txm95h2and69r",
1771
- // "memo": "",
1772
- // "chain": "BTC-Segwit",
1773
- // "contractAddress": ""
1774
- // },
1775
- // {"address":"37icNMEWbiF8ZkwUMxmfzMxi2A1MQ44bMn","memo":"","chain":"BTC","contractAddress":""},
1776
- // {"address":"Deposit temporarily blocked","memo":"","chain":"TRC20","contractAddress":""}
1777
- // ]
1778
- // }
1779
- //
1780
- this.options['versions']['private']['GET']['deposit-addresses'] = version;
1781
- const chains = this.safeValue(response, 'data', []);
1782
- const parsed = this.parseDepositAddresses(chains, [currency['code']], false, {
1783
- 'currency': currency['id'],
1784
- });
1785
- return this.indexBy(parsed, 'network');
1786
- }
1787
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
1788
- /**
1789
- * @method
1790
- * @name kucoin#fetchOrderBook
1791
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1792
- * @see https://www.kucoin.com/docs/rest/spot-trading/market-data/get-part-order-book-aggregated-
1793
- * @see https://www.kucoin.com/docs/rest/spot-trading/market-data/get-full-order-book-aggregated-
1794
- * @param {string} symbol unified symbol of the market to fetch the order book for
1795
- * @param {int} [limit] the maximum amount of order book entries to return
1796
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1797
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1798
- */
1799
- await this.loadMarkets();
1800
- const market = this.market(symbol);
1801
- const level = this.safeInteger(params, 'level', 2);
1802
- const request = { 'symbol': market['id'] };
1803
- const isAuthenticated = this.checkRequiredCredentials(false);
1804
- let response = undefined;
1805
- if (!isAuthenticated || limit !== undefined) {
1806
- if (level === 2) {
1807
- request['level'] = level;
1808
- if (limit !== undefined) {
1809
- if ((limit === 20) || (limit === 100)) {
1810
- request['limit'] = limit;
1811
- }
1812
- else {
1813
- throw new errors.ExchangeError(this.id + ' fetchOrderBook() limit argument must be 20 or 100');
1814
- }
1815
- }
1816
- request['limit'] = limit ? limit : 100;
1817
- }
1818
- response = await this.publicGetMarketOrderbookLevelLevelLimit(this.extend(request, params));
1819
- }
1820
- else {
1821
- response = await this.privateGetMarketOrderbookLevel2(this.extend(request, params));
1822
- }
1823
- //
1824
- // public (v1) market/orderbook/level2_20 and market/orderbook/level2_100
1825
- //
1826
- // {
1827
- // "sequence": "3262786978",
1828
- // "time": 1550653727731,
1829
- // "bids": [
1830
- // ["6500.12", "0.45054140"],
1831
- // ["6500.11", "0.45054140"],
1832
- // ],
1833
- // "asks": [
1834
- // ["6500.16", "0.57753524"],
1835
- // ["6500.15", "0.57753524"],
1836
- // ]
1837
- // }
1838
- //
1839
- // private (v3) market/orderbook/level2
1840
- //
1841
- // {
1842
- // "sequence": "3262786978",
1843
- // "time": 1550653727731,
1844
- // "bids": [
1845
- // ["6500.12", "0.45054140"],
1846
- // ["6500.11", "0.45054140"],
1847
- // ],
1848
- // "asks": [
1849
- // ["6500.16", "0.57753524"],
1850
- // ["6500.15", "0.57753524"],
1851
- // ]
1852
- // }
1853
- //
1854
- const data = this.safeValue(response, 'data', {});
1855
- const timestamp = this.safeInteger(data, 'time');
1856
- const orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', level - 2, level - 1);
1857
- orderbook['nonce'] = this.safeInteger(data, 'sequence');
1858
- return orderbook;
1859
- }
1860
- handleTriggerPrices(params) {
1861
- const triggerPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
1862
- const stopLossPrice = this.safeValue(params, 'stopLossPrice');
1863
- const takeProfitPrice = this.safeValue(params, 'takeProfitPrice');
1864
- const isStopLoss = stopLossPrice !== undefined;
1865
- const isTakeProfit = takeProfitPrice !== undefined;
1866
- if ((isStopLoss && isTakeProfit) || (triggerPrice && stopLossPrice) || (triggerPrice && isTakeProfit)) {
1867
- throw new errors.ExchangeError(this.id + ' createOrder() - you should use either triggerPrice or stopLossPrice or takeProfitPrice');
1868
- }
1869
- return [triggerPrice, stopLossPrice, takeProfitPrice];
1870
- }
1871
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1872
- /**
1873
- * @method
1874
- * @name kucoin#createOrder
1875
- * @description Create an order on the exchange
1876
- * @see https://docs.kucoin.com/spot#place-a-new-order
1877
- * @see https://docs.kucoin.com/spot#place-a-new-order-2
1878
- * @see https://docs.kucoin.com/spot#place-a-margin-order
1879
- * @see https://docs.kucoin.com/spot-hf/#place-hf-order
1880
- * @see https://www.kucoin.com/docs/rest/spot-trading/orders/place-order-test
1881
- * @see https://www.kucoin.com/docs/rest/margin-trading/orders/place-margin-order-test
1882
- * @param {string} symbol Unified CCXT market symbol
1883
- * @param {string} type 'limit' or 'market'
1884
- * @param {string} side 'buy' or 'sell'
1885
- * @param {float} amount the amount of currency to trade
1886
- * @param {float} [price] *ignored in "market" orders* the price at which the order is to be fullfilled at in units of the quote currency
1887
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1888
- * @param {float} [params.triggerPrice] The price at which a trigger order is triggered at
1889
- * @param {string} [params.marginMode] 'cross', // cross (cross mode) and isolated (isolated mode), set to cross by default, the isolated mode will be released soon, stay tuned
1890
- * @param {string} [params.timeInForce] GTC, GTT, IOC, or FOK, default is GTC, limit orders only
1891
- * @param {string} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK
1892
- *
1893
- * EXCHANGE SPECIFIC PARAMETERS
1894
- * @param {string} [params.clientOid] client order id, defaults to uuid if not passed
1895
- * @param {string} [params.remark] remark for the order, length cannot exceed 100 utf8 characters
1896
- * @param {string} [params.tradeType] 'TRADE', // TRADE, MARGIN_TRADE // not used with margin orders
1897
- * limit orders ---------------------------------------------------
1898
- * @param {float} [params.cancelAfter] long, // cancel after n seconds, requires timeInForce to be GTT
1899
- * @param {bool} [params.hidden] false, // Order will not be displayed in the order book
1900
- * @param {bool} [params.iceberg] false, // Only a portion of the order is displayed in the order book
1901
- * @param {string} [params.visibleSize] this.amountToPrecision (symbol, visibleSize), // The maximum visible size of an iceberg order
1902
- * market orders --------------------------------------------------
1903
- * @param {string} [params.funds] // Amount of quote currency to use
1904
- * stop orders ----------------------------------------------------
1905
- * @param {string} [params.stop] Either loss or entry, the default is loss. Requires stopPrice to be defined
1906
- * margin orders --------------------------------------------------
1907
- * @param {float} [params.leverage] Leverage size of the order
1908
- * @param {string} [params.stp] '', // self trade prevention, CN, CO, CB or DC
1909
- * @param {bool} [params.autoBorrow] false, // The system will first borrow you funds at the optimal interest rate and then place an order for you
1910
- * @param {bool} [params.hf] false, // true for hf order
1911
- * @param {bool} [params.test] set to true to test an order, no order will be created but the request will be validated
1912
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1913
- */
1914
- await this.loadMarkets();
1915
- const market = this.market(symbol);
1916
- const testOrder = this.safeValue(params, 'test', false);
1917
- params = this.omit(params, 'test');
1918
- const isHf = this.safeValue(params, 'hf', false);
1919
- const [triggerPrice, stopLossPrice, takeProfitPrice] = this.handleTriggerPrices(params);
1920
- const tradeType = this.safeString(params, 'tradeType'); // keep it for backward compatibility
1921
- const isTriggerOrder = (triggerPrice || stopLossPrice || takeProfitPrice);
1922
- const marginResult = this.handleMarginModeAndParams('createOrder', params);
1923
- const marginMode = this.safeString(marginResult, 0);
1924
- const isMarginOrder = tradeType === 'MARGIN_TRADE' || marginMode !== undefined;
1925
- // don't omit anything before calling createOrderRequest
1926
- const orderRequest = this.createOrderRequest(symbol, type, side, amount, price, params);
1927
- let response = undefined;
1928
- if (testOrder) {
1929
- if (isMarginOrder) {
1930
- response = await this.privatePostMarginOrderTest(orderRequest);
1931
- }
1932
- else {
1933
- response = await this.privatePostOrdersTest(orderRequest);
1934
- }
1935
- }
1936
- else if (isHf) {
1937
- response = await this.privatePostHfOrders(orderRequest);
1938
- }
1939
- else if (isTriggerOrder) {
1940
- response = await this.privatePostStopOrder(orderRequest);
1941
- }
1942
- else if (isMarginOrder) {
1943
- response = await this.privatePostMarginOrder(orderRequest);
1944
- }
1945
- else {
1946
- response = await this.privatePostOrders(orderRequest);
1947
- }
1948
- //
1949
- // {
1950
- // "code": "200000",
1951
- // "data": {
1952
- // "orderId": "5bd6e9286d99522a52e458de"
1953
- // }
1954
- // }
1955
- //
1956
- const data = this.safeValue(response, 'data', {});
1957
- return this.parseOrder(data, market);
1958
- }
1959
- async createMarketOrderWithCost(symbol, side, cost, params = {}) {
1960
- /**
1961
- * @method
1962
- * @name kucoin#createMarketOrderWithCost
1963
- * @description create a market order by providing the symbol, side and cost
1964
- * @see https://www.kucoin.com/docs/rest/spot-trading/orders/place-order
1965
- * @param {string} symbol unified symbol of the market to create an order in
1966
- * @param {string} side 'buy' or 'sell'
1967
- * @param {float} cost how much you want to trade in units of the quote currency
1968
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1969
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1970
- */
1971
- await this.loadMarkets();
1972
- params['cost'] = cost;
1973
- return await this.createOrder(symbol, 'market', side, cost, undefined, params);
1974
- }
1975
- async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1976
- /**
1977
- * @method
1978
- * @name kucoin#createMarketBuyOrderWithCost
1979
- * @description create a market buy order by providing the symbol and cost
1980
- * @see https://www.kucoin.com/docs/rest/spot-trading/orders/place-order
1981
- * @param {string} symbol unified symbol of the market to create an order in
1982
- * @param {float} cost how much you want to trade in units of the quote currency
1983
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1984
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1985
- */
1986
- await this.loadMarkets();
1987
- return await this.createMarketOrderWithCost(symbol, 'buy', cost, params);
1988
- }
1989
- async createMarketSellOrderWithCost(symbol, cost, params = {}) {
1990
- /**
1991
- * @method
1992
- * @name kucoin#createMarketSellOrderWithCost
1993
- * @description create a market sell order by providing the symbol and cost
1994
- * @see https://www.kucoin.com/docs/rest/spot-trading/orders/place-order
1995
- * @param {string} symbol unified symbol of the market to create an order in
1996
- * @param {float} cost how much you want to trade in units of the quote currency
1997
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1998
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1999
- */
2000
- await this.loadMarkets();
2001
- return await this.createMarketOrderWithCost(symbol, 'sell', cost, params);
2002
- }
2003
- async createOrders(orders, params = {}) {
2004
- /**
2005
- * @method
2006
- * @name kucoin#createOrders
2007
- * @description create a list of trade orders
2008
- * @see https://www.kucoin.com/docs/rest/spot-trading/orders/place-multiple-orders
2009
- * @see https://www.kucoin.com/docs/rest/spot-trading/spot-hf-trade-pro-account/place-multiple-hf-orders
2010
- * @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
2011
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2012
- * @param {bool} [params.hf] false, // true for hf orders
2013
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2014
- */
2015
- await this.loadMarkets();
2016
- const ordersRequests = [];
2017
- let symbol = undefined;
2018
- for (let i = 0; i < orders.length; i++) {
2019
- const rawOrder = orders[i];
2020
- const marketId = this.safeString(rawOrder, 'symbol');
2021
- if (symbol === undefined) {
2022
- symbol = marketId;
2023
- }
2024
- else {
2025
- if (symbol !== marketId) {
2026
- throw new errors.BadRequest(this.id + ' createOrders() requires all orders to have the same symbol');
2027
- }
2028
- }
2029
- const type = this.safeString(rawOrder, 'type');
2030
- if (type !== 'limit') {
2031
- throw new errors.BadRequest(this.id + ' createOrders() only supports limit orders');
2032
- }
2033
- const side = this.safeString(rawOrder, 'side');
2034
- const amount = this.safeValue(rawOrder, 'amount');
2035
- const price = this.safeValue(rawOrder, 'price');
2036
- const orderParams = this.safeValue(rawOrder, 'params', {});
2037
- const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
2038
- ordersRequests.push(orderRequest);
2039
- }
2040
- const market = this.market(symbol);
2041
- const request = {
2042
- 'symbol': market['id'],
2043
- 'orderList': ordersRequests,
2044
- };
2045
- const hf = this.safeValue(params, 'hf', false);
2046
- params = this.omit(params, 'hf');
2047
- let response = undefined;
2048
- if (hf) {
2049
- response = await this.privatePostHfOrdersMulti(this.extend(request, params));
2050
- }
2051
- else {
2052
- response = await this.privatePostOrdersMulti(this.extend(request, params));
2053
- }
2054
- //
2055
- // {
2056
- // "code": "200000",
2057
- // "data": {
2058
- // "data": [
2059
- // {
2060
- // "symbol": "LTC-USDT",
2061
- // "type": "limit",
2062
- // "side": "sell",
2063
- // "price": "90",
2064
- // "size": "0.1",
2065
- // "funds": null,
2066
- // "stp": "",
2067
- // "stop": "",
2068
- // "stopPrice": null,
2069
- // "timeInForce": "GTC",
2070
- // "cancelAfter": 0,
2071
- // "postOnly": false,
2072
- // "hidden": false,
2073
- // "iceberge": false,
2074
- // "iceberg": false,
2075
- // "visibleSize": null,
2076
- // "channel": "API",
2077
- // "id": "6539148443fcf500079d15e5",
2078
- // "status": "success",
2079
- // "failMsg": null,
2080
- // "clientOid": "5c4c5398-8ab2-4b4e-af8a-e2d90ad2488f"
2081
- // },
2082
- // }
2083
- //
2084
- let data = this.safeValue(response, 'data', {});
2085
- data = this.safeValue(data, 'data', []);
2086
- return this.parseOrders(data);
2087
- }
2088
- createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
2089
- const market = this.market(symbol);
2090
- // required param, cannot be used twice
2091
- const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId', this.uuid());
2092
- params = this.omit(params, ['clientOid', 'clientOrderId']);
2093
- const request = {
2094
- 'clientOid': clientOrderId,
2095
- 'side': side,
2096
- 'symbol': market['id'],
2097
- 'type': type, // limit or market
2098
- };
2099
- const quoteAmount = this.safeNumber2(params, 'cost', 'funds');
2100
- let amountString = undefined;
2101
- let costString = undefined;
2102
- let marginMode = undefined;
2103
- [marginMode, params] = this.handleMarginModeAndParams('createOrder', params);
2104
- if (type === 'market') {
2105
- if (quoteAmount !== undefined) {
2106
- params = this.omit(params, ['cost', 'funds']);
2107
- // kucoin uses base precision even for quote values
2108
- costString = this.amountToPrecision(symbol, quoteAmount);
2109
- request['funds'] = costString;
2110
- }
2111
- else {
2112
- amountString = this.amountToPrecision(symbol, amount);
2113
- request['size'] = this.amountToPrecision(symbol, amount);
2114
- }
2115
- }
2116
- else {
2117
- amountString = this.amountToPrecision(symbol, amount);
2118
- request['size'] = amountString;
2119
- request['price'] = this.priceToPrecision(symbol, price);
2120
- }
2121
- const tradeType = this.safeString(params, 'tradeType'); // keep it for backward compatibility
2122
- const [triggerPrice, stopLossPrice, takeProfitPrice] = this.handleTriggerPrices(params);
2123
- const isTriggerOrder = (triggerPrice || stopLossPrice || takeProfitPrice);
2124
- const isMarginOrder = tradeType === 'MARGIN_TRADE' || marginMode !== undefined;
2125
- params = this.omit(params, ['stopLossPrice', 'takeProfitPrice', 'triggerPrice', 'stopPrice']);
2126
- if (isTriggerOrder) {
2127
- if (triggerPrice) {
2128
- request['stopPrice'] = this.priceToPrecision(symbol, triggerPrice);
2129
- }
2130
- else if (stopLossPrice || takeProfitPrice) {
2131
- if (stopLossPrice) {
2132
- request['stop'] = (side === 'buy') ? 'entry' : 'loss';
2133
- request['stopPrice'] = this.priceToPrecision(symbol, stopLossPrice);
2134
- }
2135
- else {
2136
- request['stop'] = (side === 'buy') ? 'loss' : 'entry';
2137
- request['stopPrice'] = this.priceToPrecision(symbol, takeProfitPrice);
2138
- }
2139
- }
2140
- if (marginMode === 'isolated') {
2141
- throw new errors.BadRequest(this.id + ' createOrder does not support isolated margin for stop orders');
2142
- }
2143
- else if (marginMode === 'cross') {
2144
- request['tradeType'] = this.options['marginModes'][marginMode];
2145
- }
2146
- }
2147
- else if (isMarginOrder) {
2148
- if (marginMode === 'isolated') {
2149
- request['marginModel'] = 'isolated';
2150
- }
2151
- }
2152
- let postOnly = undefined;
2153
- [postOnly, params] = this.handlePostOnly(type === 'market', false, params);
2154
- if (postOnly) {
2155
- request['postOnly'] = true;
2156
- }
2157
- return this.extend(request, params);
2158
- }
2159
- async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
2160
- /**
2161
- * @method
2162
- * @name kucoin#editOrder
2163
- * @description edit an order, kucoin currently only supports the modification of HF orders
2164
- * @see https://docs.kucoin.com/spot-hf/#modify-order
2165
- * @param {string} id order id
2166
- * @param {string} symbol unified symbol of the market to create an order in
2167
- * @param {string} type not used
2168
- * @param {string} side not used
2169
- * @param {float} amount how much of the currency you want to trade in units of the base currency
2170
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the base currency, ignored in market orders
2171
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2172
- * @param {string} [params.clientOrderId] client order id, defaults to id if not passed
2173
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2174
- */
2175
- await this.loadMarkets();
2176
- const market = this.market(symbol);
2177
- const request = {
2178
- 'symbol': market['id'],
2179
- };
2180
- const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
2181
- if (clientOrderId !== undefined) {
2182
- request['clientOid'] = clientOrderId;
2183
- }
2184
- else {
2185
- request['orderId'] = id;
2186
- }
2187
- if (amount !== undefined) {
2188
- request['newSize'] = this.amountToPrecision(symbol, amount);
2189
- }
2190
- if (price !== undefined) {
2191
- request['newPrice'] = this.priceToPrecision(symbol, price);
2192
- }
2193
- const response = await this.privatePostHfOrdersAlter(this.extend(request, params));
2194
- //
2195
- // {
2196
- // "code":"200000",
2197
- // "data":{
2198
- // "newOrderId":"6478d7a6c883280001e92d8b"
2199
- // }
2200
- // }
2201
- //
2202
- const data = this.safeValue(response, 'data', {});
2203
- return this.parseOrder(data, market);
2204
- }
2205
- async cancelOrder(id, symbol = undefined, params = {}) {
2206
- /**
2207
- * @method
2208
- * @name kucoin#cancelOrder
2209
- * @description cancels an open order
2210
- * @see https://docs.kucoin.com/spot#cancel-an-order
2211
- * @see https://docs.kucoin.com/spot#cancel-an-order-2
2212
- * @see https://docs.kucoin.com/spot#cancel-single-order-by-clientoid
2213
- * @see https://docs.kucoin.com/spot#cancel-single-order-by-clientoid-2
2214
- * @see https://docs.kucoin.com/spot-hf/#cancel-orders-by-orderid
2215
- * @see https://docs.kucoin.com/spot-hf/#cancel-order-by-clientoid
2216
- * @param {string} id order id
2217
- * @param {string} symbol unified symbol of the market the order was made in
2218
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2219
- * @param {bool} [params.stop] True if cancelling a stop order
2220
- * @param {bool} [params.hf] false, // true for hf order
2221
- * @returns Response from the exchange
2222
- */
2223
- await this.loadMarkets();
2224
- const request = {};
2225
- const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
2226
- const stop = this.safeValue2(params, 'stop', 'trigger', false);
2227
- const hf = this.safeValue(params, 'hf', false);
2228
- if (hf) {
2229
- if (symbol === undefined) {
2230
- throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol parameter for hf orders');
2231
- }
2232
- const market = this.market(symbol);
2233
- request['symbol'] = market['id'];
2234
- }
2235
- let response = undefined;
2236
- params = this.omit(params, ['clientOid', 'clientOrderId', 'stop', 'hf', 'trigger']);
2237
- if (clientOrderId !== undefined) {
2238
- request['clientOid'] = clientOrderId;
2239
- if (stop) {
2240
- response = await this.privateDeleteStopOrderCancelOrderByClientOid(this.extend(request, params));
2241
- }
2242
- else if (hf) {
2243
- response = await this.privateDeleteHfOrdersClientOrderClientOid(this.extend(request, params));
2244
- }
2245
- else {
2246
- response = await this.privateDeleteOrderClientOrderClientOid(this.extend(request, params));
2247
- }
2248
- }
2249
- else {
2250
- request['orderId'] = id;
2251
- if (stop) {
2252
- response = await this.privateDeleteStopOrderOrderId(this.extend(request, params));
2253
- }
2254
- else if (hf) {
2255
- response = await this.privateDeleteHfOrdersOrderId(this.extend(request, params));
2256
- }
2257
- else {
2258
- response = await this.privateDeleteOrdersOrderId(this.extend(request, params));
2259
- }
2260
- }
2261
- return response;
2262
- }
2263
- async cancelAllOrders(symbol = undefined, params = {}) {
2264
- /**
2265
- * @method
2266
- * @name kucoin#cancelAllOrders
2267
- * @description cancel all open orders
2268
- * @see https://docs.kucoin.com/spot#cancel-all-orders
2269
- * @see https://docs.kucoin.com/spot#cancel-orders
2270
- * @see https://docs.kucoin.com/spot-hf/#cancel-all-hf-orders-by-symbol
2271
- * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
2272
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2273
- * @param {bool} [params.stop] *invalid for isolated margin* true if cancelling all stop orders
2274
- * @param {string} [params.marginMode] 'cross' or 'isolated'
2275
- * @param {string} [params.orderIds] *stop orders only* Comma seperated order IDs
2276
- * @param {bool} [params.stop] True if cancelling a stop order
2277
- * @param {bool} [params.hf] false, // true for hf order
2278
- * @returns Response from the exchange
2279
- */
2280
- await this.loadMarkets();
2281
- const request = {};
2282
- const stop = this.safeValue(params, 'stop', false);
2283
- const hf = this.safeValue(params, 'hf', false);
2284
- params = this.omit(params, ['stop', 'hf']);
2285
- const [marginMode, query] = this.handleMarginModeAndParams('cancelAllOrders', params);
2286
- if (symbol !== undefined) {
2287
- request['symbol'] = this.marketId(symbol);
2288
- }
2289
- if (marginMode !== undefined) {
2290
- request['tradeType'] = this.options['marginModes'][marginMode];
2291
- if (marginMode === 'isolated' && stop) {
2292
- throw new errors.BadRequest(this.id + ' cancelAllOrders does not support isolated margin for stop orders');
2293
- }
2294
- }
2295
- let response = undefined;
2296
- if (stop) {
2297
- response = await this.privateDeleteStopOrderCancel(this.extend(request, query));
2298
- }
2299
- else if (hf) {
2300
- if (symbol === undefined) {
2301
- response = await this.privateDeleteHfOrdersCancelAll(this.extend(request, query));
2302
- }
2303
- else {
2304
- response = await this.privateDeleteHfOrders(this.extend(request, query));
2305
- }
2306
- }
2307
- else {
2308
- response = await this.privateDeleteOrders(this.extend(request, query));
2309
- }
2310
- return response;
2311
- }
2312
- async fetchOrdersByStatus(status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2313
- /**
2314
- * @method
2315
- * @name kucoin#fetchOrdersByStatus
2316
- * @description fetch a list of orders
2317
- * @see https://docs.kucoin.com/spot#list-orders
2318
- * @see https://docs.kucoin.com/spot#list-stop-orders
2319
- * @see https://docs.kucoin.com/spot-hf/#obtain-list-of-active-hf-orders
2320
- * @see https://docs.kucoin.com/spot-hf/#obtain-list-of-filled-hf-orders
2321
- * @param {string} status *not used for stop orders* 'open' or 'closed'
2322
- * @param {string} symbol unified market symbol
2323
- * @param {int} [since] timestamp in ms of the earliest order
2324
- * @param {int} [limit] max number of orders to return
2325
- * @param {object} [params] exchange specific params
2326
- * @param {int} [params.until] end time in ms
2327
- * @param {bool} [params.stop] true if fetching stop orders
2328
- * @param {string} [params.side] buy or sell
2329
- * @param {string} [params.type] limit, market, limit_stop or market_stop
2330
- * @param {string} [params.tradeType] TRADE for spot trading, MARGIN_TRADE for Margin Trading
2331
- * @param {int} [params.currentPage] *stop orders only* current page
2332
- * @param {string} [params.orderIds] *stop orders only* comma seperated order ID list
2333
- * @param {bool} [params.stop] True if fetching a stop order
2334
- * @param {bool} [params.hf] false, // true for hf order
2335
- * @returns An [array of order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2336
- */
2337
- await this.loadMarkets();
2338
- let lowercaseStatus = status.toLowerCase();
2339
- const until = this.safeInteger2(params, 'until', 'till');
2340
- const stop = this.safeValue(params, 'stop', false);
2341
- const hf = this.safeValue(params, 'hf', false);
2342
- params = this.omit(params, ['stop', 'hf', 'till', 'until']);
2343
- const [marginMode, query] = this.handleMarginModeAndParams('fetchOrdersByStatus', params);
2344
- if (lowercaseStatus === 'open') {
2345
- lowercaseStatus = 'active';
2346
- }
2347
- else if (lowercaseStatus === 'closed') {
2348
- lowercaseStatus = 'done';
2349
- }
2350
- const request = {
2351
- 'status': lowercaseStatus,
2352
- };
2353
- let market = undefined;
2354
- if (symbol !== undefined) {
2355
- market = this.market(symbol);
2356
- request['symbol'] = market['id'];
2357
- }
2358
- if (since !== undefined) {
2359
- request['startAt'] = since;
2360
- }
2361
- if (limit !== undefined) {
2362
- request['pageSize'] = limit;
2363
- }
2364
- if (until) {
2365
- request['endAt'] = until;
2366
- }
2367
- request['tradeType'] = this.safeString(this.options['marginModes'], marginMode, 'TRADE');
2368
- let response = undefined;
2369
- if (stop) {
2370
- response = await this.privateGetStopOrder(this.extend(request, query));
2371
- }
2372
- else if (hf) {
2373
- if (lowercaseStatus === 'active') {
2374
- response = await this.privateGetHfOrdersActive(this.extend(request, query));
2375
- }
2376
- else if (lowercaseStatus === 'done') {
2377
- response = await this.privateGetHfOrdersDone(this.extend(request, query));
2378
- }
2379
- }
2380
- else {
2381
- response = await this.privateGetOrders(this.extend(request, query));
2382
- }
2383
- //
2384
- // {
2385
- // "code": "200000",
2386
- // "data": {
2387
- // "currentPage": 1,
2388
- // "pageSize": 1,
2389
- // "totalNum": 153408,
2390
- // "totalPage": 153408,
2391
- // "items": [
2392
- // {
2393
- // "id": "5c35c02703aa673ceec2a168", //orderid
2394
- // "symbol": "BTC-USDT", //symbol
2395
- // "opType": "DEAL", // operation type,deal is pending order,cancel is cancel order
2396
- // "type": "limit", // order type,e.g. limit,markrt,stop_limit.
2397
- // "side": "buy", // transaction direction,include buy and sell
2398
- // "price": "10", // order price
2399
- // "size": "2", // order quantity
2400
- // "funds": "0", // order funds
2401
- // "dealFunds": "0.166", // deal funds
2402
- // "dealSize": "2", // deal quantity
2403
- // "fee": "0", // fee
2404
- // "feeCurrency": "USDT", // charge fee currency
2405
- // "stp": "", // self trade prevention,include CN,CO,DC,CB
2406
- // "stop": "", // stop type
2407
- // "stopTriggered": false, // stop order is triggered
2408
- // "stopPrice": "0", // stop price
2409
- // "timeInForce": "GTC", // time InForce,include GTC,GTT,IOC,FOK
2410
- // "postOnly": false, // postOnly
2411
- // "hidden": false, // hidden order
2412
- // "iceberg": false, // iceberg order
2413
- // "visibleSize": "0", // display quantity for iceberg order
2414
- // "cancelAfter": 0, // cancel orders time,requires timeInForce to be GTT
2415
- // "channel": "IOS", // order source
2416
- // "clientOid": "", // user-entered order unique mark
2417
- // "remark": "", // remark
2418
- // "tags": "", // tag order source
2419
- // "isActive": false, // status before unfilled or uncancelled
2420
- // "cancelExist": false, // order cancellation transaction record
2421
- // "createdAt": 1547026471000 // time
2422
- // },
2423
- // ]
2424
- // }
2425
- // }
2426
- const responseData = this.safeValue(response, 'data', {});
2427
- const orders = this.safeValue(responseData, 'items', responseData);
2428
- return this.parseOrders(orders, market, since, limit);
2429
- }
2430
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2431
- /**
2432
- * @method
2433
- * @name kucoin#fetchClosedOrders
2434
- * @description fetches information on multiple closed orders made by the user
2435
- * @see https://docs.kucoin.com/spot#list-orders
2436
- * @see https://docs.kucoin.com/spot#list-stop-orders
2437
- * @see https://docs.kucoin.com/spot-hf/#obtain-list-of-active-hf-orders
2438
- * @see https://docs.kucoin.com/spot-hf/#obtain-list-of-filled-hf-orders
2439
- * @param {string} symbol unified market symbol of the market orders were made in
2440
- * @param {int} [since] the earliest time in ms to fetch orders for
2441
- * @param {int} [limit] the maximum number of order structures to retrieve
2442
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2443
- * @param {int} [params.till] end time in ms
2444
- * @param {string} [params.side] buy or sell
2445
- * @param {string} [params.type] limit, market, limit_stop or market_stop
2446
- * @param {string} [params.tradeType] TRADE for spot trading, MARGIN_TRADE for Margin Trading
2447
- * @param {bool} [params.stop] True if fetching a stop order
2448
- * @param {bool} [params.hf] false, // true for hf order
2449
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2450
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2451
- */
2452
- await this.loadMarkets();
2453
- let paginate = false;
2454
- [paginate, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'paginate');
2455
- if (paginate) {
2456
- return await this.fetchPaginatedCallDynamic('fetchClosedOrders', symbol, since, limit, params);
2457
- }
2458
- return await this.fetchOrdersByStatus('done', symbol, since, limit, params);
2459
- }
2460
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2461
- /**
2462
- * @method
2463
- * @name kucoin#fetchOpenOrders
2464
- * @description fetch all unfilled currently open orders
2465
- * @see https://docs.kucoin.com/spot#list-orders
2466
- * @see https://docs.kucoin.com/spot#list-stop-orders
2467
- * @see https://docs.kucoin.com/spot-hf/#obtain-list-of-active-hf-orders
2468
- * @see https://docs.kucoin.com/spot-hf/#obtain-list-of-filled-hf-orders
2469
- * @param {string} symbol unified market symbol
2470
- * @param {int} [since] the earliest time in ms to fetch open orders for
2471
- * @param {int} [limit] the maximum number of open orders structures to retrieve
2472
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2473
- * @param {int} [params.till] end time in ms
2474
- * @param {bool} [params.stop] true if fetching stop orders
2475
- * @param {string} [params.side] buy or sell
2476
- * @param {string} [params.type] limit, market, limit_stop or market_stop
2477
- * @param {string} [params.tradeType] TRADE for spot trading, MARGIN_TRADE for Margin Trading
2478
- * @param {int} [params.currentPage] *stop orders only* current page
2479
- * @param {string} [params.orderIds] *stop orders only* comma seperated order ID list
2480
- * @param {bool} [params.stop] True if fetching a stop order
2481
- * @param {bool} [params.hf] false, // true for hf order
2482
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2483
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2484
- */
2485
- await this.loadMarkets();
2486
- let paginate = false;
2487
- [paginate, params] = this.handleOptionAndParams(params, 'fetchOpenOrders', 'paginate');
2488
- if (paginate) {
2489
- return await this.fetchPaginatedCallDynamic('fetchOpenOrders', symbol, since, limit, params);
2490
- }
2491
- return await this.fetchOrdersByStatus('active', symbol, since, limit, params);
2492
- }
2493
- async fetchOrder(id, symbol = undefined, params = {}) {
2494
- /**
2495
- * @method
2496
- * @name kucoin#fetchOrder
2497
- * @description fetch an order
2498
- * @see https://docs.kucoin.com/spot#get-an-order
2499
- * @see https://docs.kucoin.com/spot#get-single-active-order-by-clientoid
2500
- * @see https://docs.kucoin.com/spot#get-single-order-info
2501
- * @see https://docs.kucoin.com/spot#get-single-order-by-clientoid
2502
- * @see https://docs.kucoin.com/spot-hf/#details-of-a-single-hf-order
2503
- * @see https://docs.kucoin.com/spot-hf/#obtain-details-of-a-single-hf-order-using-clientoid
2504
- * @param {string} id Order id
2505
- * @param {string} symbol not sent to exchange except for stop orders with clientOid, but used internally by CCXT to filter
2506
- * @param {object} [params] exchange specific parameters
2507
- * @param {bool} [params.stop] true if fetching a stop order
2508
- * @param {bool} [params.hf] false, // true for hf order
2509
- * @param {bool} [params.clientOid] unique order id created by users to identify their orders
2510
- * @returns An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2511
- */
2512
- await this.loadMarkets();
2513
- const request = {};
2514
- const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
2515
- const stop = this.safeValue(params, 'stop', false);
2516
- const hf = this.safeValue(params, 'hf', false);
2517
- let market = undefined;
2518
- if (symbol !== undefined) {
2519
- market = this.market(symbol);
2520
- }
2521
- if (hf) {
2522
- if (symbol === undefined) {
2523
- throw new errors.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol parameter for hf orders');
2524
- }
2525
- request['symbol'] = market['id'];
2526
- }
2527
- params = this.omit(params, ['stop', 'hf', 'clientOid', 'clientOrderId']);
2528
- let response = undefined;
2529
- if (clientOrderId !== undefined) {
2530
- request['clientOid'] = clientOrderId;
2531
- if (stop) {
2532
- if (symbol !== undefined) {
2533
- request['symbol'] = market['id'];
2534
- }
2535
- response = await this.privateGetStopOrderQueryOrderByClientOid(this.extend(request, params));
2536
- }
2537
- else if (hf) {
2538
- response = await this.privateGetHfOrdersClientOrderClientOid(this.extend(request, params));
2539
- }
2540
- else {
2541
- response = await this.privateGetOrderClientOrderClientOid(this.extend(request, params));
2542
- }
2543
- }
2544
- else {
2545
- // a special case for undefined ids
2546
- // otherwise a wrong endpoint for all orders will be triggered
2547
- // https://github.com/ccxt/ccxt/issues/7234
2548
- if (id === undefined) {
2549
- throw new errors.InvalidOrder(this.id + ' fetchOrder() requires an order id');
2550
- }
2551
- request['orderId'] = id;
2552
- if (stop) {
2553
- response = await this.privateGetStopOrderOrderId(this.extend(request, params));
2554
- }
2555
- else if (hf) {
2556
- response = await this.privateGetHfOrdersOrderId(this.extend(request, params));
2557
- }
2558
- else {
2559
- response = await this.privateGetOrdersOrderId(this.extend(request, params));
2560
- }
2561
- }
2562
- let responseData = this.safeValue(response, 'data', {});
2563
- if (Array.isArray(responseData)) {
2564
- responseData = this.safeValue(responseData, 0);
2565
- }
2566
- return this.parseOrder(responseData, market);
2567
- }
2568
- parseOrder(order, market = undefined) {
2569
- //
2570
- // createOrder
2571
- //
2572
- // {
2573
- // "orderId": "63c97e47d686c5000159a656"
2574
- // }
2575
- //
2576
- // cancelOrder
2577
- //
2578
- // {
2579
- // "cancelledOrderIds": [ "63c97e47d686c5000159a656" ]
2580
- // }
2581
- //
2582
- // fetchOpenOrders, fetchClosedOrders
2583
- //
2584
- // {
2585
- // "id": "63c97ce8d686c500015793bb",
2586
- // "symbol": "USDC-USDT",
2587
- // "opType": "DEAL",
2588
- // "type": "limit",
2589
- // "side": "sell",
2590
- // "price": "1.05",
2591
- // "size": "1",
2592
- // "funds": "0",
2593
- // "dealFunds": "0",
2594
- // "dealSize": "0",
2595
- // "fee": "0",
2596
- // "feeCurrency": "USDT",
2597
- // "stp": "",
2598
- // "stop": "",
2599
- // "stopTriggered": false,
2600
- // "stopPrice": "0",
2601
- // "timeInForce": "GTC",
2602
- // "postOnly": false,
2603
- // "hidden": false,
2604
- // "iceberg": false,
2605
- // "visibleSize": "0",
2606
- // "cancelAfter": 0,
2607
- // "channel": "API",
2608
- // "clientOid": "d602d73f-5424-4751-bef0-8debce8f0a82",
2609
- // "remark": null,
2610
- // "tags": "partner:ccxt",
2611
- // "isActive": true,
2612
- // "cancelExist": false,
2613
- // "createdAt": 1674149096927,
2614
- // "tradeType": "TRADE"
2615
- // }
2616
- //
2617
- // stop orders (fetchOpenOrders, fetchClosedOrders)
2618
- //
2619
- // {
2620
- // "id": "vs9f6ou9e864rgq8000t4qnm",
2621
- // "symbol": "USDC-USDT",
2622
- // "userId": "613a896885d8660006151f01",
2623
- // "status": "NEW",
2624
- // "type": "market",
2625
- // "side": "sell",
2626
- // "price": null,
2627
- // "size": "1.00000000000000000000",
2628
- // "funds": null,
2629
- // "stp": null,
2630
- // "timeInForce": "GTC",
2631
- // "cancelAfter": -1,
2632
- // "postOnly": false,
2633
- // "hidden": false,
2634
- // "iceberg": false,
2635
- // "visibleSize": null,
2636
- // "channel": "API",
2637
- // "clientOid": "5d3fd727-6456-438d-9550-40d9d85eee0b",
2638
- // "remark": null,
2639
- // "tags": "partner:ccxt",
2640
- // "relatedNo": null,
2641
- // "orderTime": 1674146316994000028,
2642
- // "domainId": "kucoin",
2643
- // "tradeSource": "USER",
2644
- // "tradeType": "MARGIN_TRADE",
2645
- // "feeCurrency": "USDT",
2646
- // "takerFeeRate": "0.00100000000000000000",
2647
- // "makerFeeRate": "0.00100000000000000000",
2648
- // "createdAt": 1674146316994,
2649
- // "stop": "loss",
2650
- // "stopTriggerTime": null,
2651
- // "stopPrice": "0.97000000000000000000"
2652
- // }
2653
- // hf order
2654
- // {
2655
- // "id":"6478cf1439bdfc0001528a1d",
2656
- // "symbol":"LTC-USDT",
2657
- // "opType":"DEAL",
2658
- // "type":"limit",
2659
- // "side":"buy",
2660
- // "price":"50",
2661
- // "size":"0.1",
2662
- // "funds":"5",
2663
- // "dealSize":"0",
2664
- // "dealFunds":"0",
2665
- // "fee":"0",
2666
- // "feeCurrency":"USDT",
2667
- // "stp":null,
2668
- // "timeInForce":"GTC",
2669
- // "postOnly":false,
2670
- // "hidden":false,
2671
- // "iceberg":false,
2672
- // "visibleSize":"0",
2673
- // "cancelAfter":0,
2674
- // "channel":"API",
2675
- // "clientOid":"d4d2016b-8e3a-445c-aa5d-dc6df5d1678d",
2676
- // "remark":null,
2677
- // "tags":"partner:ccxt",
2678
- // "cancelExist":false,
2679
- // "createdAt":1685638932074,
2680
- // "lastUpdatedAt":1685639013735,
2681
- // "tradeType":"TRADE",
2682
- // "inOrderBook":true,
2683
- // "cancelledSize":"0",
2684
- // "cancelledFunds":"0",
2685
- // "remainSize":"0.1",
2686
- // "remainFunds":"5",
2687
- // "active":true
2688
- // }
2689
- //
2690
- const marketId = this.safeString(order, 'symbol');
2691
- const timestamp = this.safeInteger(order, 'createdAt');
2692
- const feeCurrencyId = this.safeString(order, 'feeCurrency');
2693
- const cancelExist = this.safeValue(order, 'cancelExist', false);
2694
- const responseStop = this.safeString(order, 'stop');
2695
- const stop = responseStop !== undefined;
2696
- const stopTriggered = this.safeValue(order, 'stopTriggered', false);
2697
- const isActive = this.safeValue2(order, 'isActive', 'active');
2698
- const responseStatus = this.safeString(order, 'status');
2699
- let status = undefined;
2700
- if (isActive !== undefined) {
2701
- if (isActive === true) {
2702
- status = 'open';
2703
- }
2704
- else {
2705
- status = 'closed';
2706
- }
2707
- }
2708
- if (stop) {
2709
- if (responseStatus === 'NEW') {
2710
- status = 'open';
2711
- }
2712
- else if (!isActive && !stopTriggered) {
2713
- status = 'cancelled';
2714
- }
2715
- }
2716
- if (cancelExist) {
2717
- status = 'canceled';
2718
- }
2719
- if (responseStatus === 'fail') {
2720
- status = 'rejected';
2721
- }
2722
- const stopPrice = this.safeNumber(order, 'stopPrice');
2723
- return this.safeOrder({
2724
- 'info': order,
2725
- 'id': this.safeStringN(order, ['id', 'orderId', 'newOrderId']),
2726
- 'clientOrderId': this.safeString(order, 'clientOid'),
2727
- 'symbol': this.safeSymbol(marketId, market, '-'),
2728
- 'type': this.safeString(order, 'type'),
2729
- 'timeInForce': this.safeString(order, 'timeInForce'),
2730
- 'postOnly': this.safeValue(order, 'postOnly'),
2731
- 'side': this.safeString(order, 'side'),
2732
- 'amount': this.safeString(order, 'size'),
2733
- 'price': this.safeString(order, 'price'),
2734
- 'stopPrice': stopPrice,
2735
- 'triggerPrice': stopPrice,
2736
- 'cost': this.safeString(order, 'dealFunds'),
2737
- 'filled': this.safeString(order, 'dealSize'),
2738
- 'remaining': undefined,
2739
- 'timestamp': timestamp,
2740
- 'datetime': this.iso8601(timestamp),
2741
- 'fee': {
2742
- 'currency': this.safeCurrencyCode(feeCurrencyId),
2743
- 'cost': this.safeNumber(order, 'fee'),
2744
- },
2745
- 'status': status,
2746
- 'lastTradeTimestamp': undefined,
2747
- 'average': undefined,
2748
- 'trades': undefined,
2749
- }, market);
2750
- }
2751
- async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2752
- /**
2753
- * @method
2754
- * @name kucoin#fetchOrderTrades
2755
- * @description fetch all the trades made from a single order
2756
- * @see https://docs.kucoin.com/#list-fills
2757
- * @see https://docs.kucoin.com/spot-hf/#transaction-details
2758
- * @param {string} id order id
2759
- * @param {string} symbol unified market symbol
2760
- * @param {int} [since] the earliest time in ms to fetch trades for
2761
- * @param {int} [limit] the maximum number of trades to retrieve
2762
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2763
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2764
- */
2765
- const request = {
2766
- 'orderId': id,
2767
- };
2768
- return await this.fetchMyTrades(symbol, since, limit, this.extend(request, params));
2769
- }
2770
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2771
- /**
2772
- * @method
2773
- * @name kucoin#fetchMyTrades
2774
- * @see https://docs.kucoin.com/#list-fills
2775
- * @see https://docs.kucoin.com/spot-hf/#transaction-details
2776
- * @description fetch all trades made by the user
2777
- * @param {string} symbol unified market symbol
2778
- * @param {int} [since] the earliest time in ms to fetch trades for
2779
- * @param {int} [limit] the maximum number of trades structures to retrieve
2780
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2781
- * @param {int} [params.until] the latest time in ms to fetch entries for
2782
- * @param {bool} [params.hf] false, // true for hf order
2783
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2784
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
2785
- */
2786
- await this.loadMarkets();
2787
- let paginate = false;
2788
- [paginate, params] = this.handleOptionAndParams(params, 'fetchMyTrades', 'paginate');
2789
- if (paginate) {
2790
- return await this.fetchPaginatedCallDynamic('fetchMyTrades', symbol, since, limit, params);
2791
- }
2792
- let request = {};
2793
- const hf = this.safeValue(params, 'hf', false);
2794
- if (hf && symbol === undefined) {
2795
- throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol parameter for hf orders');
2796
- }
2797
- let market = undefined;
2798
- if (symbol !== undefined) {
2799
- market = this.market(symbol);
2800
- request['symbol'] = market['id'];
2801
- }
2802
- if (limit !== undefined) {
2803
- request['pageSize'] = limit;
2804
- }
2805
- const method = this.options['fetchMyTradesMethod'];
2806
- let parseResponseData = false;
2807
- let response = undefined;
2808
- [request, params] = this.handleUntilOption('endAt', request, params);
2809
- if (hf) {
2810
- response = await this.privateGetHfFills(this.extend(request, params));
2811
- }
2812
- else if (method === 'private_get_fills') {
2813
- // does not return trades earlier than 2019-02-18T00:00:00Z
2814
- if (since !== undefined) {
2815
- // only returns trades up to one week after the since param
2816
- request['startAt'] = since;
2817
- }
2818
- response = await this.privateGetFills(this.extend(request, params));
2819
- }
2820
- else if (method === 'private_get_limit_fills') {
2821
- // does not return trades earlier than 2019-02-18T00:00:00Z
2822
- // takes no params
2823
- // only returns first 1000 trades (not only "in the last 24 hours" as stated in the docs)
2824
- parseResponseData = true;
2825
- response = await this.privateGetLimitFills(this.extend(request, params));
2826
- }
2827
- else {
2828
- throw new errors.ExchangeError(this.id + ' fetchMyTradesMethod() invalid method');
2829
- }
2830
- //
2831
- // {
2832
- // "currentPage": 1,
2833
- // "pageSize": 50,
2834
- // "totalNum": 1,
2835
- // "totalPage": 1,
2836
- // "items": [
2837
- // {
2838
- // "symbol":"BTC-USDT", // symbol
2839
- // "tradeId":"5c35c02709e4f67d5266954e", // trade id
2840
- // "orderId":"5c35c02703aa673ceec2a168", // order id
2841
- // "counterOrderId":"5c1ab46003aa676e487fa8e3", // counter order id
2842
- // "side":"buy", // transaction direction,include buy and sell
2843
- // "liquidity":"taker", // include taker and maker
2844
- // "forceTaker":true, // forced to become taker
2845
- // "price":"0.083", // order price
2846
- // "size":"0.8424304", // order quantity
2847
- // "funds":"0.0699217232", // order funds
2848
- // "fee":"0", // fee
2849
- // "feeRate":"0", // fee rate
2850
- // "feeCurrency":"USDT", // charge fee currency
2851
- // "stop":"", // stop type
2852
- // "type":"limit", // order type, e.g. limit, market, stop_limit.
2853
- // "createdAt":1547026472000 // time
2854
- // },
2855
- // //------------------------------------------------------
2856
- // // v1 (historical) trade response structure
2857
- // {
2858
- // "symbol": "SNOV-ETH",
2859
- // "dealPrice": "0.0000246",
2860
- // "dealValue": "0.018942",
2861
- // "amount": "770",
2862
- // "fee": "0.00001137",
2863
- // "side": "sell",
2864
- // "createdAt": 1540080199
2865
- // "id":"5c4d389e4c8c60413f78e2e5",
2866
- // }
2867
- // ]
2868
- // }
2869
- //
2870
- const data = this.safeValue(response, 'data', {});
2871
- let trades = undefined;
2872
- if (parseResponseData) {
2873
- trades = data;
2874
- }
2875
- else {
2876
- trades = this.safeValue(data, 'items', []);
2877
- }
2878
- return this.parseTrades(trades, market, since, limit);
2879
- }
2880
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
2881
- /**
2882
- * @method
2883
- * @name kucoin#fetchTrades
2884
- * @description get the list of most recent trades for a particular symbol
2885
- * @see https://docs.kucoin.com/#get-trade-histories
2886
- * @param {string} symbol unified symbol of the market to fetch trades for
2887
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
2888
- * @param {int} [limit] the maximum amount of trades to fetch
2889
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2890
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
2891
- */
2892
- await this.loadMarkets();
2893
- const market = this.market(symbol);
2894
- const request = {
2895
- 'symbol': market['id'],
2896
- };
2897
- // pagination is not supported on the exchange side anymore
2898
- // if (since !== undefined) {
2899
- // request['startAt'] = Math.floor (since / 1000);
2900
- // }
2901
- // if (limit !== undefined) {
2902
- // request['pageSize'] = limit;
2903
- // }
2904
- const response = await this.publicGetMarketHistories(this.extend(request, params));
2905
- //
2906
- // {
2907
- // "code": "200000",
2908
- // "data": [
2909
- // {
2910
- // "sequence": "1548764654235",
2911
- // "side": "sell",
2912
- // "size":"0.6841354",
2913
- // "price":"0.03202",
2914
- // "time":1548848575203567174
2915
- // }
2916
- // ]
2917
- // }
2918
- //
2919
- const trades = this.safeValue(response, 'data', []);
2920
- return this.parseTrades(trades, market, since, limit);
2921
- }
2922
- parseTrade(trade, market = undefined) {
2923
- //
2924
- // fetchTrades (public)
2925
- //
2926
- // {
2927
- // "sequence": "1548764654235",
2928
- // "side": "sell",
2929
- // "size":"0.6841354",
2930
- // "price":"0.03202",
2931
- // "time":1548848575203567174
2932
- // }
2933
- //
2934
- // {
2935
- // "sequence": "1568787654360",
2936
- // "symbol": "BTC-USDT",
2937
- // "side": "buy",
2938
- // "size": "0.00536577",
2939
- // "price": "9345",
2940
- // "takerOrderId": "5e356c4a9f1a790008f8d921",
2941
- // "time": "1580559434436443257",
2942
- // "type": "match",
2943
- // "makerOrderId": "5e356bffedf0010008fa5d7f",
2944
- // "tradeId": "5e356c4aeefabd62c62a1ece"
2945
- // }
2946
- //
2947
- // fetchMyTrades (private) v2
2948
- //
2949
- // {
2950
- // "symbol":"BTC-USDT",
2951
- // "tradeId":"5c35c02709e4f67d5266954e",
2952
- // "orderId":"5c35c02703aa673ceec2a168",
2953
- // "counterOrderId":"5c1ab46003aa676e487fa8e3",
2954
- // "side":"buy",
2955
- // "liquidity":"taker",
2956
- // "forceTaker":true,
2957
- // "price":"0.083",
2958
- // "size":"0.8424304",
2959
- // "funds":"0.0699217232",
2960
- // "fee":"0",
2961
- // "feeRate":"0",
2962
- // "feeCurrency":"USDT",
2963
- // "stop":"",
2964
- // "type":"limit",
2965
- // "createdAt":1547026472000
2966
- // }
2967
- //
2968
- // fetchMyTrades v2 alternative format since 2019-05-21 https://github.com/ccxt/ccxt/pull/5162
2969
- //
2970
- // {
2971
- // "symbol": "OPEN-BTC",
2972
- // "forceTaker": false,
2973
- // "orderId": "5ce36420054b4663b1fff2c9",
2974
- // "fee": "0",
2975
- // "feeCurrency": "",
2976
- // "type": "",
2977
- // "feeRate": "0",
2978
- // "createdAt": 1558417615000,
2979
- // "size": "12.8206",
2980
- // "stop": "",
2981
- // "price": "0",
2982
- // "funds": "0",
2983
- // "tradeId": "5ce390cf6e0db23b861c6e80"
2984
- // }
2985
- //
2986
- // fetchMyTrades (private) v1 (historical)
2987
- //
2988
- // {
2989
- // "symbol": "SNOV-ETH",
2990
- // "dealPrice": "0.0000246",
2991
- // "dealValue": "0.018942",
2992
- // "amount": "770",
2993
- // "fee": "0.00001137",
2994
- // "side": "sell",
2995
- // "createdAt": 1540080199
2996
- // "id":"5c4d389e4c8c60413f78e2e5",
2997
- // }
2998
- //
2999
- const marketId = this.safeString(trade, 'symbol');
3000
- market = this.safeMarket(marketId, market, '-');
3001
- const id = this.safeString2(trade, 'tradeId', 'id');
3002
- const orderId = this.safeString(trade, 'orderId');
3003
- const takerOrMaker = this.safeString(trade, 'liquidity');
3004
- let timestamp = this.safeInteger(trade, 'time');
3005
- if (timestamp !== undefined) {
3006
- timestamp = this.parseToInt(timestamp / 1000000);
3007
- }
3008
- else {
3009
- timestamp = this.safeInteger(trade, 'createdAt');
3010
- // if it's a historical v1 trade, the exchange returns timestamp in seconds
3011
- if (('dealValue' in trade) && (timestamp !== undefined)) {
3012
- timestamp = timestamp * 1000;
3013
- }
3014
- }
3015
- const priceString = this.safeString2(trade, 'price', 'dealPrice');
3016
- const amountString = this.safeString2(trade, 'size', 'amount');
3017
- const side = this.safeString(trade, 'side');
3018
- let fee = undefined;
3019
- const feeCostString = this.safeString(trade, 'fee');
3020
- if (feeCostString !== undefined) {
3021
- const feeCurrencyId = this.safeString(trade, 'feeCurrency');
3022
- let feeCurrency = this.safeCurrencyCode(feeCurrencyId);
3023
- if (feeCurrency === undefined) {
3024
- feeCurrency = (side === 'sell') ? market['quote'] : market['base'];
3025
- }
3026
- fee = {
3027
- 'cost': feeCostString,
3028
- 'currency': feeCurrency,
3029
- 'rate': this.safeString(trade, 'feeRate'),
3030
- };
3031
- }
3032
- let type = this.safeString(trade, 'type');
3033
- if (type === 'match') {
3034
- type = undefined;
3035
- }
3036
- const costString = this.safeString2(trade, 'funds', 'dealValue');
3037
- return this.safeTrade({
3038
- 'info': trade,
3039
- 'id': id,
3040
- 'order': orderId,
3041
- 'timestamp': timestamp,
3042
- 'datetime': this.iso8601(timestamp),
3043
- 'symbol': market['symbol'],
3044
- 'type': type,
3045
- 'takerOrMaker': takerOrMaker,
3046
- 'side': side,
3047
- 'price': priceString,
3048
- 'amount': amountString,
3049
- 'cost': costString,
3050
- 'fee': fee,
3051
- }, market);
3052
- }
3053
- async fetchTradingFee(symbol, params = {}) {
3054
- /**
3055
- * @method
3056
- * @name kucoin#fetchTradingFee
3057
- * @description fetch the trading fees for a market
3058
- * @see https://docs.kucoin.com/#actual-fee-rate-of-the-trading-pair
3059
- * @param {string} symbol unified market symbol
3060
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3061
- * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
3062
- */
3063
- await this.loadMarkets();
3064
- const market = this.market(symbol);
3065
- const request = {
3066
- 'symbols': market['id'],
3067
- };
3068
- const response = await this.privateGetTradeFees(this.extend(request, params));
3069
- //
3070
- // {
3071
- // "code": "200000",
3072
- // "data": [
3073
- // {
3074
- // "symbol": "BTC-USDT",
3075
- // "takerFeeRate": "0.001",
3076
- // "makerFeeRate": "0.001"
3077
- // }
3078
- // ]
3079
- // }
3080
- //
3081
- const data = this.safeValue(response, 'data', []);
3082
- const first = this.safeValue(data, 0);
3083
- const marketId = this.safeString(first, 'symbol');
3084
- return {
3085
- 'info': response,
3086
- 'symbol': this.safeSymbol(marketId, market),
3087
- 'maker': this.safeNumber(first, 'makerFeeRate'),
3088
- 'taker': this.safeNumber(first, 'takerFeeRate'),
3089
- 'percentage': true,
3090
- 'tierBased': true,
3091
- };
3092
- }
3093
- async withdraw(code, amount, address, tag = undefined, params = {}) {
3094
- /**
3095
- * @method
3096
- * @name kucoin#withdraw
3097
- * @description make a withdrawal
3098
- * @see https://docs.kucoin.com/#apply-withdraw-2
3099
- * @param {string} code unified currency code
3100
- * @param {float} amount the amount to withdraw
3101
- * @param {string} address the address to withdraw to
3102
- * @param {string} tag
3103
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3104
- * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3105
- */
3106
- [tag, params] = this.handleWithdrawTagAndParams(tag, params);
3107
- await this.loadMarkets();
3108
- this.checkAddress(address);
3109
- const currency = this.currency(code);
3110
- const request = {
3111
- 'currency': currency['id'],
3112
- 'address': address,
3113
- 'amount': amount,
3114
- // 'memo': tag,
3115
- // 'isInner': false, // internal transfer or external withdrawal
3116
- // 'remark': 'optional',
3117
- // 'chain': 'OMNI', // 'ERC20', 'TRC20', default is ERC20, This only apply for multi-chain currency, and there is no need for single chain currency.
3118
- };
3119
- if (tag !== undefined) {
3120
- request['memo'] = tag;
3121
- }
3122
- let networkCode = undefined;
3123
- [networkCode, params] = this.handleNetworkCodeAndParams(params);
3124
- if (networkCode !== undefined) {
3125
- request['chain'] = this.networkCodeToId(networkCode).toLowerCase();
3126
- }
3127
- let includeFee = undefined;
3128
- [includeFee, params] = this.handleOptionAndParams(params, 'withdraw', 'includeFee', false);
3129
- if (includeFee) {
3130
- request['feeDeductType'] = 'INTERNAL';
3131
- }
3132
- const response = await this.privatePostWithdrawals(this.extend(request, params));
3133
- //
3134
- // https://github.com/ccxt/ccxt/issues/5558
3135
- //
3136
- // {
3137
- // "code": 200000,
3138
- // "data": {
3139
- // "withdrawalId": "5bffb63303aa675e8bbe18f9"
3140
- // }
3141
- // }
3142
- //
3143
- const data = this.safeValue(response, 'data', {});
3144
- return this.parseTransaction(data, currency);
3145
- }
3146
- parseTransactionStatus(status) {
3147
- const statuses = {
3148
- 'SUCCESS': 'ok',
3149
- 'PROCESSING': 'pending',
3150
- 'WALLET_PROCESSING': 'pending',
3151
- 'FAILURE': 'failed',
3152
- };
3153
- return this.safeString(statuses, status, status);
3154
- }
3155
- parseTransaction(transaction, currency = undefined) {
3156
- //
3157
- // fetchDeposits
3158
- //
3159
- // {
3160
- // "address": "0x5f047b29041bcfdbf0e4478cdfa753a336ba6989",
3161
- // "memo": "5c247c8a03aa677cea2a251d",
3162
- // "amount": 1,
3163
- // "fee": 0.0001,
3164
- // "currency": "KCS",
3165
- // "chain": "",
3166
- // "isInner": false,
3167
- // "walletTxId": "5bbb57386d99522d9f954c5a@test004",
3168
- // "status": "SUCCESS",
3169
- // "createdAt": 1544178843000,
3170
- // "updatedAt": 1544178891000
3171
- // "remark":"foobar"
3172
- // }
3173
- //
3174
- // fetchWithdrawals
3175
- //
3176
- // {
3177
- // "id": "5c2dc64e03aa675aa263f1ac",
3178
- // "address": "0x5bedb060b8eb8d823e2414d82acce78d38be7fe9",
3179
- // "memo": "",
3180
- // "currency": "ETH",
3181
- // "chain": "",
3182
- // "amount": 1.0000000,
3183
- // "fee": 0.0100000,
3184
- // "walletTxId": "3e2414d82acce78d38be7fe9",
3185
- // "isInner": false,
3186
- // "status": "FAILURE",
3187
- // "createdAt": 1546503758000,
3188
- // "updatedAt": 1546504603000
3189
- // "remark":"foobar"
3190
- // }
3191
- //
3192
- // withdraw
3193
- //
3194
- // {
3195
- // "withdrawalId": "5bffb63303aa675e8bbe18f9"
3196
- // }
3197
- //
3198
- const currencyId = this.safeString(transaction, 'currency');
3199
- const code = this.safeCurrencyCode(currencyId, currency);
3200
- let address = this.safeString(transaction, 'address');
3201
- const amount = this.safeString(transaction, 'amount');
3202
- let txid = this.safeString(transaction, 'walletTxId');
3203
- if (txid !== undefined) {
3204
- const txidParts = txid.split('@');
3205
- const numTxidParts = txidParts.length;
3206
- if (numTxidParts > 1) {
3207
- if (address === undefined) {
3208
- if (txidParts[1].length > 1) {
3209
- address = txidParts[1];
3210
- }
3211
- }
3212
- }
3213
- txid = txidParts[0];
3214
- }
3215
- let type = (txid === undefined) ? 'withdrawal' : 'deposit';
3216
- const rawStatus = this.safeString(transaction, 'status');
3217
- let fee = undefined;
3218
- const feeCost = this.safeString(transaction, 'fee');
3219
- if (feeCost !== undefined) {
3220
- let rate = undefined;
3221
- if (amount !== undefined) {
3222
- rate = Precise["default"].stringDiv(feeCost, amount);
3223
- }
3224
- fee = {
3225
- 'cost': this.parseNumber(feeCost),
3226
- 'rate': this.parseNumber(rate),
3227
- 'currency': code,
3228
- };
3229
- }
3230
- let timestamp = this.safeInteger2(transaction, 'createdAt', 'createAt');
3231
- let updated = this.safeInteger(transaction, 'updatedAt');
3232
- const isV1 = !('createdAt' in transaction);
3233
- // if it's a v1 structure
3234
- if (isV1) {
3235
- type = ('address' in transaction) ? 'withdrawal' : 'deposit';
3236
- if (timestamp !== undefined) {
3237
- timestamp = timestamp * 1000;
3238
- }
3239
- if (updated !== undefined) {
3240
- updated = updated * 1000;
3241
- }
3242
- }
3243
- const internal = this.safeValue(transaction, 'isInner');
3244
- const tag = this.safeString(transaction, 'memo');
3245
- return {
3246
- 'info': transaction,
3247
- 'id': this.safeString2(transaction, 'id', 'withdrawalId'),
3248
- 'timestamp': timestamp,
3249
- 'datetime': this.iso8601(timestamp),
3250
- 'network': this.networkIdToCode(this.safeString(transaction, 'chain')),
3251
- 'address': address,
3252
- 'addressTo': address,
3253
- 'addressFrom': undefined,
3254
- 'tag': tag,
3255
- 'tagTo': tag,
3256
- 'tagFrom': undefined,
3257
- 'currency': code,
3258
- 'amount': this.parseNumber(amount),
3259
- 'txid': txid,
3260
- 'type': type,
3261
- 'status': this.parseTransactionStatus(rawStatus),
3262
- 'comment': this.safeString(transaction, 'remark'),
3263
- 'internal': internal,
3264
- 'fee': fee,
3265
- 'updated': updated,
3266
- };
3267
- }
3268
- async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
3269
- /**
3270
- * @method
3271
- * @name kucoin#fetchDeposits
3272
- * @description fetch all deposits made to an account
3273
- * @see https://docs.kucoin.com/#get-deposit-list
3274
- * @see https://docs.kucoin.com/#get-v1-historical-deposits-list
3275
- * @param {string} code unified currency code
3276
- * @param {int} [since] the earliest time in ms to fetch deposits for
3277
- * @param {int} [limit] the maximum number of deposits structures to retrieve
3278
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3279
- * @param {int} [params.until] the latest time in ms to fetch entries for
3280
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3281
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3282
- */
3283
- await this.loadMarkets();
3284
- let paginate = false;
3285
- [paginate, params] = this.handleOptionAndParams(params, 'fetchDeposits', 'paginate');
3286
- if (paginate) {
3287
- return await this.fetchPaginatedCallDynamic('fetchDeposits', code, since, limit, params);
3288
- }
3289
- let request = {};
3290
- let currency = undefined;
3291
- if (code !== undefined) {
3292
- currency = this.currency(code);
3293
- request['currency'] = currency['id'];
3294
- }
3295
- if (limit !== undefined) {
3296
- request['pageSize'] = limit;
3297
- }
3298
- [request, params] = this.handleUntilOption('endAt', request, params);
3299
- let response = undefined;
3300
- if (since !== undefined && since < 1550448000000) {
3301
- // if since is earlier than 2019-02-18T00:00:00Z
3302
- request['startAt'] = this.parseToInt(since / 1000);
3303
- response = await this.privateGetHistDeposits(this.extend(request, params));
3304
- }
3305
- else {
3306
- if (since !== undefined) {
3307
- request['startAt'] = since;
3308
- }
3309
- response = await this.privateGetDeposits(this.extend(request, params));
3310
- }
3311
- //
3312
- // {
3313
- // "code": "200000",
3314
- // "data": {
3315
- // "currentPage": 1,
3316
- // "pageSize": 5,
3317
- // "totalNum": 2,
3318
- // "totalPage": 1,
3319
- // "items": [
3320
- // //--------------------------------------------------
3321
- // // version 2 deposit response structure
3322
- // {
3323
- // "address": "0x5f047b29041bcfdbf0e4478cdfa753a336ba6989",
3324
- // "memo": "5c247c8a03aa677cea2a251d",
3325
- // "amount": 1,
3326
- // "fee": 0.0001,
3327
- // "currency": "KCS",
3328
- // "isInner": false,
3329
- // "walletTxId": "5bbb57386d99522d9f954c5a@test004",
3330
- // "status": "SUCCESS",
3331
- // "createdAt": 1544178843000,
3332
- // "updatedAt": 1544178891000
3333
- // "remark":"foobar"
3334
- // },
3335
- // //--------------------------------------------------
3336
- // // version 1 (historical) deposit response structure
3337
- // {
3338
- // "currency": "BTC",
3339
- // "createAt": 1528536998,
3340
- // "amount": "0.03266638",
3341
- // "walletTxId": "55c643bc2c68d6f17266383ac1be9e454038864b929ae7cee0bc408cc5c869e8@12ffGWmMMD1zA1WbFm7Ho3JZ1w6NYXjpFk@234",
3342
- // "isInner": false,
3343
- // "status": "SUCCESS",
3344
- // }
3345
- // ]
3346
- // }
3347
- // }
3348
- //
3349
- const responseData = response['data']['items'];
3350
- return this.parseTransactions(responseData, currency, since, limit, { 'type': 'deposit' });
3351
- }
3352
- async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
3353
- /**
3354
- * @method
3355
- * @name kucoin#fetchWithdrawals
3356
- * @description fetch all withdrawals made from an account
3357
- * @see https://docs.kucoin.com/#get-withdrawals-list
3358
- * @see https://docs.kucoin.com/#get-v1-historical-withdrawals-list
3359
- * @param {string} code unified currency code
3360
- * @param {int} [since] the earliest time in ms to fetch withdrawals for
3361
- * @param {int} [limit] the maximum number of withdrawals structures to retrieve
3362
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3363
- * @param {int} [params.until] the latest time in ms to fetch entries for
3364
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3365
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3366
- */
3367
- await this.loadMarkets();
3368
- let paginate = false;
3369
- [paginate, params] = this.handleOptionAndParams(params, 'fetchWithdrawals', 'paginate');
3370
- if (paginate) {
3371
- return await this.fetchPaginatedCallDynamic('fetchWithdrawals', code, since, limit, params);
3372
- }
3373
- let request = {};
3374
- let currency = undefined;
3375
- if (code !== undefined) {
3376
- currency = this.currency(code);
3377
- request['currency'] = currency['id'];
3378
- }
3379
- if (limit !== undefined) {
3380
- request['pageSize'] = limit;
3381
- }
3382
- [request, params] = this.handleUntilOption('endAt', request, params);
3383
- let response = undefined;
3384
- if (since !== undefined && since < 1550448000000) {
3385
- // if since is earlier than 2019-02-18T00:00:00Z
3386
- request['startAt'] = this.parseToInt(since / 1000);
3387
- response = await this.privateGetHistWithdrawals(this.extend(request, params));
3388
- }
3389
- else {
3390
- if (since !== undefined) {
3391
- request['startAt'] = since;
3392
- }
3393
- response = await this.privateGetWithdrawals(this.extend(request, params));
3394
- }
3395
- //
3396
- // {
3397
- // "code": "200000",
3398
- // "data": {
3399
- // "currentPage": 1,
3400
- // "pageSize": 5,
3401
- // "totalNum": 2,
3402
- // "totalPage": 1,
3403
- // "items": [
3404
- // //--------------------------------------------------
3405
- // // version 2 withdrawal response structure
3406
- // {
3407
- // "id": "5c2dc64e03aa675aa263f1ac",
3408
- // "address": "0x5bedb060b8eb8d823e2414d82acce78d38be7fe9",
3409
- // "memo": "",
3410
- // "currency": "ETH",
3411
- // "amount": 1.0000000,
3412
- // "fee": 0.0100000,
3413
- // "walletTxId": "3e2414d82acce78d38be7fe9",
3414
- // "isInner": false,
3415
- // "status": "FAILURE",
3416
- // "createdAt": 1546503758000,
3417
- // "updatedAt": 1546504603000
3418
- // },
3419
- // //--------------------------------------------------
3420
- // // version 1 (historical) withdrawal response structure
3421
- // {
3422
- // "currency": "BTC",
3423
- // "createAt": 1526723468,
3424
- // "amount": "0.534",
3425
- // "address": "33xW37ZSW4tQvg443Pc7NLCAs167Yc2XUV",
3426
- // "walletTxId": "aeacea864c020acf58e51606169240e96774838dcd4f7ce48acf38e3651323f4",
3427
- // "isInner": false,
3428
- // "status": "SUCCESS"
3429
- // }
3430
- // ]
3431
- // }
3432
- // }
3433
- //
3434
- const responseData = response['data']['items'];
3435
- return this.parseTransactions(responseData, currency, since, limit, { 'type': 'withdrawal' });
3436
- }
3437
- parseBalanceHelper(entry) {
3438
- const account = this.account();
3439
- account['used'] = this.safeString(entry, 'holdBalance');
3440
- account['free'] = this.safeString(entry, 'availableBalance');
3441
- account['total'] = this.safeString(entry, 'totalBalance');
3442
- const debt = this.safeString(entry, 'liability');
3443
- const interest = this.safeString(entry, 'interest');
3444
- account['debt'] = Precise["default"].stringAdd(debt, interest);
3445
- return account;
3446
- }
3447
- async fetchBalance(params = {}) {
3448
- /**
3449
- * @method
3450
- * @name kucoin#fetchBalance
3451
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
3452
- * @see https://docs.kucoin.com/#list-accounts
3453
- * @see https://www.kucoin.com/docs/rest/account/basic-info/get-account-list-spot-margin-trade_hf
3454
- * @see https://docs.kucoin.com/#query-isolated-margin-account-info
3455
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3456
- * @param {object} [params.marginMode] 'cross' or 'isolated', margin type for fetching margin balance
3457
- * @param {object} [params.type] extra parameters specific to the exchange API endpoint
3458
- * @param {object} [params.hf] *default if false* if true, the result includes the balance of the high frequency account
3459
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
3460
- */
3461
- await this.loadMarkets();
3462
- const code = this.safeString(params, 'code');
3463
- let currency = undefined;
3464
- if (code !== undefined) {
3465
- currency = this.currency(code);
3466
- }
3467
- const defaultType = this.safeString2(this.options, 'fetchBalance', 'defaultType', 'spot');
3468
- const requestedType = this.safeString(params, 'type', defaultType);
3469
- const accountsByType = this.safeValue(this.options, 'accountsByType');
3470
- let type = this.safeString(accountsByType, requestedType, requestedType);
3471
- params = this.omit(params, 'type');
3472
- const isHf = this.safeValue(params, 'hf', false);
3473
- if (isHf) {
3474
- type = 'trade_hf';
3475
- }
3476
- params = this.omit(params, 'hf');
3477
- const [marginMode, query] = this.handleMarginModeAndParams('fetchBalance', params);
3478
- let response = undefined;
3479
- const request = {};
3480
- const isolated = (marginMode === 'isolated') || (type === 'isolated');
3481
- const cross = (marginMode === 'cross') || (type === 'cross');
3482
- if (isolated) {
3483
- if (currency !== undefined) {
3484
- request['balanceCurrency'] = currency['id'];
3485
- }
3486
- response = await this.privateGetIsolatedAccounts(this.extend(request, query));
3487
- }
3488
- else if (cross) {
3489
- response = await this.privateGetMarginAccount(this.extend(request, query));
3490
- }
3491
- else {
3492
- if (currency !== undefined) {
3493
- request['currency'] = currency['id'];
3494
- }
3495
- request['type'] = type;
3496
- response = await this.privateGetAccounts(this.extend(request, query));
3497
- }
3498
- //
3499
- // Spot and Cross
3500
- //
3501
- // {
3502
- // "code": "200000",
3503
- // "data": [
3504
- // {
3505
- // "balance": "0.00009788",
3506
- // "available": "0.00009788",
3507
- // "holds": "0",
3508
- // "currency": "BTC",
3509
- // "id": "5c6a4fd399a1d81c4f9cc4d0",
3510
- // "type": "trade",
3511
- // },
3512
- // ]
3513
- // }
3514
- //
3515
- // Isolated
3516
- //
3517
- // {
3518
- // "code": "200000",
3519
- // "data": {
3520
- // "totalConversionBalance": "0",
3521
- // "liabilityConversionBalance": "0",
3522
- // "assets": [
3523
- // {
3524
- // "symbol": "MANA-USDT",
3525
- // "status": "CLEAR",
3526
- // "debtRatio": "0",
3527
- // "baseAsset": {
3528
- // "currency": "MANA",
3529
- // "totalBalance": "0",
3530
- // "holdBalance": "0",
3531
- // "availableBalance": "0",
3532
- // "liability": "0",
3533
- // "interest": "0",
3534
- // "borrowableAmount": "0"
3535
- // },
3536
- // "quoteAsset": {
3537
- // "currency": "USDT",
3538
- // "totalBalance": "0",
3539
- // "holdBalance": "0",
3540
- // "availableBalance": "0",
3541
- // "liability": "0",
3542
- // "interest": "0",
3543
- // "borrowableAmount": "0"
3544
- // }
3545
- // },
3546
- // ...
3547
- // ]
3548
- // }
3549
- // }
3550
- //
3551
- const data = this.safeValue(response, 'data', []);
3552
- const result = {
3553
- 'info': response,
3554
- 'timestamp': undefined,
3555
- 'datetime': undefined,
3556
- };
3557
- if (isolated) {
3558
- const assets = this.safeValue(data, 'assets', data);
3559
- for (let i = 0; i < assets.length; i++) {
3560
- const entry = assets[i];
3561
- const marketId = this.safeString(entry, 'symbol');
3562
- const symbol = this.safeSymbol(marketId, undefined, '_');
3563
- const base = this.safeValue(entry, 'baseAsset', {});
3564
- const quote = this.safeValue(entry, 'quoteAsset', {});
3565
- const baseCode = this.safeCurrencyCode(this.safeString(base, 'currency'));
3566
- const quoteCode = this.safeCurrencyCode(this.safeString(quote, 'currency'));
3567
- const subResult = {};
3568
- subResult[baseCode] = this.parseBalanceHelper(base);
3569
- subResult[quoteCode] = this.parseBalanceHelper(quote);
3570
- result[symbol] = this.safeBalance(subResult);
3571
- }
3572
- }
3573
- else if (cross) {
3574
- const accounts = this.safeValue(data, 'accounts', []);
3575
- for (let i = 0; i < accounts.length; i++) {
3576
- const balance = accounts[i];
3577
- const currencyId = this.safeString(balance, 'currency');
3578
- const codeInner = this.safeCurrencyCode(currencyId);
3579
- result[codeInner] = this.parseBalanceHelper(balance);
3580
- }
3581
- }
3582
- else {
3583
- for (let i = 0; i < data.length; i++) {
3584
- const balance = data[i];
3585
- const balanceType = this.safeString(balance, 'type');
3586
- if (balanceType === type) {
3587
- const currencyId = this.safeString(balance, 'currency');
3588
- const codeInner2 = this.safeCurrencyCode(currencyId);
3589
- const account = this.account();
3590
- account['total'] = this.safeString(balance, 'balance');
3591
- account['free'] = this.safeString(balance, 'available');
3592
- account['used'] = this.safeString(balance, 'holds');
3593
- result[codeInner2] = account;
3594
- }
3595
- }
3596
- }
3597
- const returnType = isolated ? result : this.safeBalance(result);
3598
- return returnType;
3599
- }
3600
- async transfer(code, amount, fromAccount, toAccount, params = {}) {
3601
- /**
3602
- * @method
3603
- * @name kucoin#transfer
3604
- * @description transfer currency internally between wallets on the same account
3605
- * @see https://docs.kucoin.com/#inner-transfer
3606
- * @see https://docs.kucoin.com/futures/#transfer-funds-to-kucoin-main-account-2
3607
- * @see https://docs.kucoin.com/spot-hf/#internal-funds-transfers-in-high-frequency-trading-accounts
3608
- * @param {string} code unified currency code
3609
- * @param {float} amount amount to transfer
3610
- * @param {string} fromAccount account to transfer from
3611
- * @param {string} toAccount account to transfer to
3612
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3613
- * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
3614
- */
3615
- await this.loadMarkets();
3616
- const currency = this.currency(code);
3617
- const requestedAmount = this.currencyToPrecision(code, amount);
3618
- let fromId = this.convertTypeToAccount(fromAccount);
3619
- let toId = this.convertTypeToAccount(toAccount);
3620
- const fromIsolated = this.inArray(fromId, this.ids);
3621
- const toIsolated = this.inArray(toId, this.ids);
3622
- if (fromId === 'contract') {
3623
- if (toId !== 'main') {
3624
- throw new errors.ExchangeError(this.id + ' transfer() only supports transferring from futures account to main account');
3625
- }
3626
- const request = {
3627
- 'currency': currency['id'],
3628
- 'amount': requestedAmount,
3629
- };
3630
- if (!('bizNo' in params)) {
3631
- // it doesn't like more than 24 characters
3632
- request['bizNo'] = this.uuid22();
3633
- }
3634
- const response = await this.futuresPrivatePostTransferOut(this.extend(request, params));
3635
- //
3636
- // {
3637
- // "code": "200000",
3638
- // "data": {
3639
- // "applyId": "605a87217dff1500063d485d",
3640
- // "bizNo": "bcd6e5e1291f4905af84dc",
3641
- // "payAccountType": "CONTRACT",
3642
- // "payTag": "DEFAULT",
3643
- // "remark": '',
3644
- // "recAccountType": "MAIN",
3645
- // "recTag": "DEFAULT",
3646
- // "recRemark": '',
3647
- // "recSystem": "KUCOIN",
3648
- // "status": "PROCESSING",
3649
- // "currency": "XBT",
3650
- // "amount": "0.00001",
3651
- // "fee": "0",
3652
- // "sn": "573688685663948",
3653
- // "reason": '',
3654
- // "createdAt": 1616545569000,
3655
- // "updatedAt": 1616545569000
3656
- // }
3657
- // }
3658
- //
3659
- const data = this.safeValue(response, 'data');
3660
- return this.parseTransfer(data, currency);
3661
- }
3662
- else {
3663
- const request = {
3664
- 'currency': currency['id'],
3665
- 'amount': requestedAmount,
3666
- };
3667
- if (fromIsolated || toIsolated) {
3668
- if (this.inArray(fromId, this.ids)) {
3669
- request['fromTag'] = fromId;
3670
- fromId = 'isolated';
3671
- }
3672
- if (this.inArray(toId, this.ids)) {
3673
- request['toTag'] = toId;
3674
- toId = 'isolated';
3675
- }
3676
- }
3677
- request['from'] = fromId;
3678
- request['to'] = toId;
3679
- if (!('clientOid' in params)) {
3680
- request['clientOid'] = this.uuid();
3681
- }
3682
- const response = await this.privatePostAccountsInnerTransfer(this.extend(request, params));
3683
- //
3684
- // {
3685
- // "code": "200000",
3686
- // "data": {
3687
- // "orderId": "605a6211e657f00006ad0ad6"
3688
- // }
3689
- // }
3690
- //
3691
- const data = this.safeValue(response, 'data');
3692
- return this.parseTransfer(data, currency);
3693
- }
3694
- }
3695
- parseTransfer(transfer, currency = undefined) {
3696
- //
3697
- // transfer (spot)
3698
- //
3699
- // {
3700
- // "orderId": "605a6211e657f00006ad0ad6"
3701
- // }
3702
- //
3703
- // {
3704
- // "code": "200000",
3705
- // "msg": "Failed to transfer out. The amount exceeds the upper limit"
3706
- // }
3707
- //
3708
- // transfer (futures)
3709
- //
3710
- // {
3711
- // "applyId": "605a87217dff1500063d485d",
3712
- // "bizNo": "bcd6e5e1291f4905af84dc",
3713
- // "payAccountType": "CONTRACT",
3714
- // "payTag": "DEFAULT",
3715
- // "remark": '',
3716
- // "recAccountType": "MAIN",
3717
- // "recTag": "DEFAULT",
3718
- // "recRemark": '',
3719
- // "recSystem": "KUCOIN",
3720
- // "status": "PROCESSING",
3721
- // "currency": "XBT",
3722
- // "amount": "0.00001",
3723
- // "fee": "0",
3724
- // "sn": "573688685663948",
3725
- // "reason": '',
3726
- // "createdAt": 1616545569000,
3727
- // "updatedAt": 1616545569000
3728
- // }
3729
- //
3730
- const timestamp = this.safeInteger(transfer, 'createdAt');
3731
- const currencyId = this.safeString(transfer, 'currency');
3732
- const rawStatus = this.safeString(transfer, 'status');
3733
- const accountFromRaw = this.safeStringLower(transfer, 'payAccountType');
3734
- const accountToRaw = this.safeStringLower(transfer, 'recAccountType');
3735
- const accountsByType = this.safeValue(this.options, 'accountsByType');
3736
- const accountFrom = this.safeString(accountsByType, accountFromRaw, accountFromRaw);
3737
- const accountTo = this.safeString(accountsByType, accountToRaw, accountToRaw);
3738
- return {
3739
- 'id': this.safeString2(transfer, 'applyId', 'orderId'),
3740
- 'currency': this.safeCurrencyCode(currencyId, currency),
3741
- 'timestamp': timestamp,
3742
- 'datetime': this.iso8601(timestamp),
3743
- 'amount': this.safeNumber(transfer, 'amount'),
3744
- 'fromAccount': accountFrom,
3745
- 'toAccount': accountTo,
3746
- 'status': this.parseTransferStatus(rawStatus),
3747
- 'info': transfer,
3748
- };
3749
- }
3750
- parseTransferStatus(status) {
3751
- const statuses = {
3752
- 'PROCESSING': 'pending',
3753
- };
3754
- return this.safeString(statuses, status, status);
3755
- }
3756
- parseLedgerEntryType(type) {
3757
- const types = {
3758
- 'Assets Transferred in After Upgrading': 'transfer',
3759
- 'Deposit': 'transaction',
3760
- 'Withdrawal': 'transaction',
3761
- 'Transfer': 'transfer',
3762
- 'Trade_Exchange': 'trade',
3763
- // 'Vote for Coin': 'Vote for Coin', // Vote for Coin
3764
- 'KuCoin Bonus': 'bonus',
3765
- 'Referral Bonus': 'referral',
3766
- 'Rewards': 'bonus',
3767
- // 'Distribution': 'Distribution', // Distribution, such as get GAS by holding NEO
3768
- 'Airdrop/Fork': 'airdrop',
3769
- 'Other rewards': 'bonus',
3770
- 'Fee Rebate': 'rebate',
3771
- 'Buy Crypto': 'trade',
3772
- 'Sell Crypto': 'sell',
3773
- 'Public Offering Purchase': 'trade',
3774
- // 'Send red envelope': 'Send red envelope', // Send red envelope
3775
- // 'Open red envelope': 'Open red envelope', // Open red envelope
3776
- // 'Staking': 'Staking', // Staking
3777
- // 'LockDrop Vesting': 'LockDrop Vesting', // LockDrop Vesting
3778
- // 'Staking Profits': 'Staking Profits', // Staking Profits
3779
- // 'Redemption': 'Redemption', // Redemption
3780
- 'Refunded Fees': 'fee',
3781
- 'KCS Pay Fees': 'fee',
3782
- 'Margin Trade': 'trade',
3783
- 'Loans': 'Loans',
3784
- // 'Borrowings': 'Borrowings', // Borrowings
3785
- // 'Debt Repayment': 'Debt Repayment', // Debt Repayment
3786
- // 'Loans Repaid': 'Loans Repaid', // Loans Repaid
3787
- // 'Lendings': 'Lendings', // Lendings
3788
- // 'Pool transactions': 'Pool transactions', // Pool-X transactions
3789
- 'Instant Exchange': 'trade',
3790
- 'Sub-account transfer': 'transfer',
3791
- 'Liquidation Fees': 'fee', // Liquidation Fees
3792
- // 'Soft Staking Profits': 'Soft Staking Profits', // Soft Staking Profits
3793
- // 'Voting Earnings': 'Voting Earnings', // Voting Earnings on Pool-X
3794
- // 'Redemption of Voting': 'Redemption of Voting', // Redemption of Voting on Pool-X
3795
- // 'Voting': 'Voting', // Voting on Pool-X
3796
- // 'Convert to KCS': 'Convert to KCS', // Convert to KCS
3797
- };
3798
- return this.safeString(types, type, type);
3799
- }
3800
- parseLedgerEntry(item, currency = undefined) {
3801
- //
3802
- // {
3803
- // "id": "611a1e7c6a053300067a88d9", //unique key for each ledger entry
3804
- // "currency": "USDT", //Currency
3805
- // "amount": "10.00059547", //The total amount of assets (fees included) involved in assets changes such as transaction, withdrawal and bonus distribution.
3806
- // "fee": "0", //Deposit or withdrawal fee
3807
- // "balance": "0", //Total assets of a currency remaining funds after transaction
3808
- // "accountType": "MAIN", //Account Type
3809
- // "bizType": "Loans Repaid", //business type
3810
- // "direction": "in", //side, in or out
3811
- // "createdAt": 1629101692950, //Creation time
3812
- // "context": "{\"borrowerUserId\":\"601ad03e50dc810006d242ea\",\"loanRepayDetailNo\":\"611a1e7cc913d000066cf7ec\"}" //Business core parameters
3813
- // }
3814
- //
3815
- const id = this.safeString(item, 'id');
3816
- const currencyId = this.safeString(item, 'currency');
3817
- const code = this.safeCurrencyCode(currencyId, currency);
3818
- const amount = this.safeNumber(item, 'amount');
3819
- const balanceAfter = undefined;
3820
- // const balanceAfter = this.safeNumber (item, 'balance'); only returns zero string
3821
- const bizType = this.safeString(item, 'bizType');
3822
- const type = this.parseLedgerEntryType(bizType);
3823
- const direction = this.safeString(item, 'direction');
3824
- const timestamp = this.safeInteger(item, 'createdAt');
3825
- const datetime = this.iso8601(timestamp);
3826
- const account = this.safeString(item, 'accountType'); // MAIN, TRADE, MARGIN, or CONTRACT
3827
- const context = this.safeString(item, 'context'); // contains other information about the ledger entry
3828
- //
3829
- // withdrawal transaction
3830
- //
3831
- // "{\"orderId\":\"617bb2d09e7b3b000196dac8\",\"txId\":\"0x79bb9855f86b351a45cab4dc69d78ca09586a94c45dde49475722b98f401b054\"}"
3832
- //
3833
- // deposit to MAIN, trade via MAIN
3834
- //
3835
- // "{\"orderId\":\"617ab9949e7b3b0001948081\",\"txId\":\"0x7a06b16bbd6b03dbc3d96df5683b15229fc35e7184fd7179a5f3a310bd67d1fa@default@0\"}"
3836
- //
3837
- // sell trade
3838
- //
3839
- // "{\"symbol\":\"ETH-USDT\",\"orderId\":\"617adcd1eb3fa20001dd29a1\",\"tradeId\":\"617adcd12e113d2b91222ff9\"}"
3840
- //
3841
- let referenceId = undefined;
3842
- if (context !== undefined && context !== '') {
3843
- try {
3844
- const parsed = JSON.parse(context);
3845
- const orderId = this.safeString(parsed, 'orderId');
3846
- const tradeId = this.safeString(parsed, 'tradeId');
3847
- // transactions only have an orderId but for trades we wish to use tradeId
3848
- if (tradeId !== undefined) {
3849
- referenceId = tradeId;
3850
- }
3851
- else {
3852
- referenceId = orderId;
3853
- }
3854
- }
3855
- catch (exc) {
3856
- referenceId = context;
3857
- }
3858
- }
3859
- let fee = undefined;
3860
- const feeCost = this.safeNumber(item, 'fee');
3861
- let feeCurrency = undefined;
3862
- if (feeCost !== 0) {
3863
- feeCurrency = code;
3864
- fee = { 'cost': feeCost, 'currency': feeCurrency };
3865
- }
3866
- return {
3867
- 'id': id,
3868
- 'direction': direction,
3869
- 'account': account,
3870
- 'referenceId': referenceId,
3871
- 'referenceAccount': account,
3872
- 'type': type,
3873
- 'currency': code,
3874
- 'amount': amount,
3875
- 'timestamp': timestamp,
3876
- 'datetime': datetime,
3877
- 'before': undefined,
3878
- 'after': balanceAfter,
3879
- 'status': undefined,
3880
- 'fee': fee,
3881
- 'info': item,
3882
- };
3883
- }
3884
- async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
3885
- /**
3886
- * @method
3887
- * @name kucoin#fetchLedger
3888
- * @see https://docs.kucoin.com/#get-account-ledgers
3889
- * @see https://www.kucoin.com/docs/rest/account/basic-info/get-account-ledgers-trade_hf
3890
- * @see https://www.kucoin.com/docs/rest/account/basic-info/get-account-ledgers-margin_hf
3891
- * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
3892
- * @param {string} code unified currency code, default is undefined
3893
- * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
3894
- * @param {int} [limit] max number of ledger entrys to return, default is undefined
3895
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3896
- * @param {boolean} [params.hf] default false, when true will fetch ledger entries for the high frequency trading account
3897
- * @param {int} [params.until] the latest time in ms to fetch entries for
3898
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
3899
- * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
3900
- */
3901
- await this.loadMarkets();
3902
- await this.loadAccounts();
3903
- let paginate = false;
3904
- [paginate, params] = this.handleOptionAndParams(params, 'fetchLedger', 'paginate');
3905
- const isHf = this.safeValue(params, 'hf');
3906
- params = this.omit(params, 'hf');
3907
- if (paginate) {
3908
- return await this.fetchPaginatedCallDynamic('fetchLedger', code, since, limit, params);
3909
- }
3910
- let request = {
3911
- // 'currency': currency['id'], // can choose up to 10, if not provided returns for all currencies by default
3912
- // 'direction': 'in', // 'out'
3913
- // 'bizType': 'DEPOSIT', // DEPOSIT, WITHDRAW, TRANSFER, SUB_TRANSFER,TRADE_EXCHANGE, MARGIN_EXCHANGE, KUCOIN_BONUS (optional)
3914
- // 'startAt': since,
3915
- // 'endAt': exchange.milliseconds (),
3916
- };
3917
- if (since !== undefined) {
3918
- request['startAt'] = since;
3919
- }
3920
- // atm only single currency retrieval is supported
3921
- let currency = undefined;
3922
- if (code !== undefined) {
3923
- currency = this.currency(code);
3924
- request['currency'] = currency['id'];
3925
- }
3926
- [request, params] = this.handleUntilOption('endAt', request, params);
3927
- let marginMode = undefined;
3928
- [marginMode, params] = this.handleMarginModeAndParams('fetchLedger', params);
3929
- let response = undefined;
3930
- if (isHf) {
3931
- if (marginMode !== undefined) {
3932
- response = await this.privateGetHfMarginAccountLedgers(this.extend(request, params));
3933
- }
3934
- else {
3935
- response = await this.privateGetHfAccountsLedgers(this.extend(request, params));
3936
- }
3937
- }
3938
- else {
3939
- response = await this.privateGetAccountsLedgers(this.extend(request, params));
3940
- }
3941
- //
3942
- // {
3943
- // "code":"200000",
3944
- // "data":{
3945
- // "currentPage":1,
3946
- // "pageSize":50,
3947
- // "totalNum":1,
3948
- // "totalPage":1,
3949
- // "items":[
3950
- // {
3951
- // "id":"617cc528729f5f0001c03ceb",
3952
- // "currency":"GAS",
3953
- // "amount":"0.00000339",
3954
- // "fee":"0",
3955
- // "balance":"0",
3956
- // "accountType":"MAIN",
3957
- // "bizType":"Distribution",
3958
- // "direction":"in",
3959
- // "createdAt":1635566888183,
3960
- // "context":"{\"orderId\":\"617cc47a1c47ed0001ce3606\",\"description\":\"Holding NEO,distribute GAS(2021/10/30)\"}"
3961
- // }
3962
- // {
3963
- // "id": "611a1e7c6a053300067a88d9",//unique key
3964
- // "currency": "USDT", //Currency
3965
- // "amount": "10.00059547", //Change amount of the funds
3966
- // "fee": "0", //Deposit or withdrawal fee
3967
- // "balance": "0", //Total assets of a currency
3968
- // "accountType": "MAIN", //Account Type
3969
- // "bizType": "Loans Repaid", //business type
3970
- // "direction": "in", //side, in or out
3971
- // "createdAt": 1629101692950, //Creation time
3972
- // "context": "{\"borrowerUserId\":\"601ad03e50dc810006d242ea\",\"loanRepayDetailNo\":\"611a1e7cc913d000066cf7ec\"}"
3973
- // },
3974
- // ]
3975
- // }
3976
- // }
3977
- //
3978
- const data = this.safeValue(response, 'data');
3979
- const items = this.safeValue(data, 'items', data);
3980
- return this.parseLedger(items, currency, since, limit);
3981
- }
3982
- calculateRateLimiterCost(api, method, path, params, config = {}) {
3983
- const versions = this.safeValue(this.options, 'versions', {});
3984
- const apiVersions = this.safeValue(versions, api, {});
3985
- const methodVersions = this.safeValue(apiVersions, method, {});
3986
- const defaultVersion = this.safeString(methodVersions, path, this.options['version']);
3987
- const version = this.safeString(params, 'version', defaultVersion);
3988
- if (version === 'v3' && ('v3' in config)) {
3989
- return config['v3'];
3990
- }
3991
- else if (version === 'v2' && ('v2' in config)) {
3992
- return config['v2'];
3993
- }
3994
- else if (version === 'v1' && ('v1' in config)) {
3995
- return config['v1'];
3996
- }
3997
- return this.safeValue(config, 'cost', 1);
3998
- }
3999
- parseBorrowRateHistory(response, code, since, limit) {
4000
- const result = [];
4001
- for (let i = 0; i < response.length; i++) {
4002
- const item = response[i];
4003
- const borrowRate = this.parseBorrowRate(item);
4004
- result.push(borrowRate);
4005
- }
4006
- const sorted = this.sortBy(result, 'timestamp');
4007
- return this.filterByCurrencySinceLimit(sorted, code, since, limit);
4008
- }
4009
- parseBorrowRate(info, currency = undefined) {
4010
- //
4011
- // {
4012
- // "tradeId": "62db2dcaff219600012b56cd",
4013
- // "currency": "USDT",
4014
- // "size": "10",
4015
- // "dailyIntRate": "0.00003",
4016
- // "term": 7,
4017
- // "timestamp": 1658531274508488480
4018
- // },
4019
- //
4020
- const timestampId = this.safeString(info, 'timestamp');
4021
- const timestamp = Precise["default"].stringMul(timestampId, '0.000001');
4022
- const currencyId = this.safeString(info, 'currency');
4023
- return {
4024
- 'currency': this.safeCurrencyCode(currencyId, currency),
4025
- 'rate': this.safeNumber(info, 'dailyIntRate'),
4026
- 'period': 86400000,
4027
- 'timestamp': timestamp,
4028
- 'datetime': this.iso8601(timestamp),
4029
- 'info': info,
4030
- };
4031
- }
4032
- async fetchBorrowInterest(code = undefined, symbol = undefined, since = undefined, limit = undefined, params = {}) {
4033
- /**
4034
- * @method
4035
- * @name kucoin#fetchBorrowInterest
4036
- * @description fetch the interest owed by the user for borrowing currency for margin trading
4037
- * @see https://docs.kucoin.com/#get-repay-record
4038
- * @see https://docs.kucoin.com/#query-isolated-margin-account-info
4039
- * @param {string} code unified currency code
4040
- * @param {string} symbol unified market symbol, required for isolated margin
4041
- * @param {int} [since] the earliest time in ms to fetch borrrow interest for
4042
- * @param {int} [limit] the maximum number of structures to retrieve
4043
- * @param {object} [params] extra parameters specific to the exchange API endpoint
4044
- * @param {string} [params.marginMode] 'cross' or 'isolated' default is 'cross'
4045
- * @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/#/?id=borrow-interest-structure}
4046
- */
4047
- await this.loadMarkets();
4048
- let marginMode = undefined;
4049
- [marginMode, params] = this.handleMarginModeAndParams('fetchBorrowInterest', params);
4050
- if (marginMode === undefined) {
4051
- marginMode = 'cross'; // cross as default marginMode
4052
- }
4053
- const request = {};
4054
- let response = undefined;
4055
- if (code !== undefined) {
4056
- const currency = this.currency(code);
4057
- request['quoteCurrency'] = currency['id'];
4058
- }
4059
- if (marginMode === 'isolated') {
4060
- response = await this.privateGetIsolatedAccounts(this.extend(request, params));
4061
- }
4062
- else {
4063
- response = await this.privateGetMarginAccounts(this.extend(request, params));
4064
- }
4065
- //
4066
- // Cross
4067
- //
4068
- // {
4069
- // "code": "200000",
4070
- // "data": {
4071
- // "totalAssetOfQuoteCurrency": "0",
4072
- // "totalLiabilityOfQuoteCurrency": "0",
4073
- // "debtRatio": "0",
4074
- // "status": "EFFECTIVE",
4075
- // "accounts": [
4076
- // {
4077
- // "currency": "1INCH",
4078
- // "total": "0",
4079
- // "available": "0",
4080
- // "hold": "0",
4081
- // "liability": "0",
4082
- // "maxBorrowSize": "0",
4083
- // "borrowEnabled": true,
4084
- // "transferInEnabled": true
4085
- // }
4086
- // ]
4087
- // }
4088
- // }
4089
- //
4090
- // Isolated
4091
- //
4092
- // {
4093
- // "code": "200000",
4094
- // "data": {
4095
- // "totalConversionBalance": "0.02138647",
4096
- // "liabilityConversionBalance": "0.01480001",
4097
- // "assets": [
4098
- // {
4099
- // "symbol": "MANA-USDT",
4100
- // "debtRatio": "0",
4101
- // "status": "BORROW",
4102
- // "baseAsset": {
4103
- // "currency": "MANA",
4104
- // "borrowEnabled": true,
4105
- // "repayEnabled": true,
4106
- // "transferEnabled": true,
4107
- // "borrowed": "0",
4108
- // "totalAsset": "0",
4109
- // "available": "0",
4110
- // "hold": "0",
4111
- // "maxBorrowSize": "1000"
4112
- // },
4113
- // "quoteAsset": {
4114
- // "currency": "USDT",
4115
- // "borrowEnabled": true,
4116
- // "repayEnabled": true,
4117
- // "transferEnabled": true,
4118
- // "borrowed": "0",
4119
- // "totalAsset": "0",
4120
- // "available": "0",
4121
- // "hold": "0",
4122
- // "maxBorrowSize": "50000"
4123
- // }
4124
- // }
4125
- // ]
4126
- // }
4127
- // }
4128
- //
4129
- const data = this.safeValue(response, 'data', {});
4130
- const assets = (marginMode === 'isolated') ? this.safeValue(data, 'assets', []) : this.safeValue(data, 'accounts', []);
4131
- return this.parseBorrowInterests(assets, undefined);
4132
- }
4133
- parseBorrowInterest(info, market = undefined) {
4134
- //
4135
- // Cross
4136
- //
4137
- // {
4138
- // "currency": "1INCH",
4139
- // "total": "0",
4140
- // "available": "0",
4141
- // "hold": "0",
4142
- // "liability": "0",
4143
- // "maxBorrowSize": "0",
4144
- // "borrowEnabled": true,
4145
- // "transferInEnabled": true
4146
- // }
4147
- //
4148
- // Isolated
4149
- //
4150
- // {
4151
- // "symbol": "MANA-USDT",
4152
- // "debtRatio": "0",
4153
- // "status": "BORROW",
4154
- // "baseAsset": {
4155
- // "currency": "MANA",
4156
- // "borrowEnabled": true,
4157
- // "repayEnabled": true,
4158
- // "transferEnabled": true,
4159
- // "borrowed": "0",
4160
- // "totalAsset": "0",
4161
- // "available": "0",
4162
- // "hold": "0",
4163
- // "maxBorrowSize": "1000"
4164
- // },
4165
- // "quoteAsset": {
4166
- // "currency": "USDT",
4167
- // "borrowEnabled": true,
4168
- // "repayEnabled": true,
4169
- // "transferEnabled": true,
4170
- // "borrowed": "0",
4171
- // "totalAsset": "0",
4172
- // "available": "0",
4173
- // "hold": "0",
4174
- // "maxBorrowSize": "50000"
4175
- // }
4176
- // }
4177
- //
4178
- const marketId = this.safeString(info, 'symbol');
4179
- const marginMode = (marketId === undefined) ? 'cross' : 'isolated';
4180
- market = this.safeMarket(marketId, market);
4181
- const symbol = this.safeString(market, 'symbol');
4182
- const timestamp = this.safeInteger(info, 'createdAt');
4183
- const isolatedBase = this.safeValue(info, 'baseAsset', {});
4184
- let amountBorrowed = undefined;
4185
- let interest = undefined;
4186
- let currencyId = undefined;
4187
- if (marginMode === 'isolated') {
4188
- amountBorrowed = this.safeNumber(isolatedBase, 'liability');
4189
- interest = this.safeNumber(isolatedBase, 'interest');
4190
- currencyId = this.safeString(isolatedBase, 'currency');
4191
- }
4192
- else {
4193
- amountBorrowed = this.safeNumber(info, 'liability');
4194
- interest = this.safeNumber(info, 'accruedInterest');
4195
- currencyId = this.safeString(info, 'currency');
4196
- }
4197
- return {
4198
- 'symbol': symbol,
4199
- 'marginMode': marginMode,
4200
- 'currency': this.safeCurrencyCode(currencyId),
4201
- 'interest': interest,
4202
- 'interestRate': this.safeNumber(info, 'dailyIntRate'),
4203
- 'amountBorrowed': amountBorrowed,
4204
- 'timestamp': timestamp,
4205
- 'datetime': this.iso8601(timestamp),
4206
- 'info': info,
4207
- };
4208
- }
4209
- async borrowCrossMargin(code, amount, params = {}) {
4210
- /**
4211
- * @method
4212
- * @name kucoin#borrowCrossMargin
4213
- * @description create a loan to borrow margin
4214
- * @see https://docs.kucoin.com/#1-margin-borrowing
4215
- * @param {string} code unified currency code of the currency to borrow
4216
- * @param {float} amount the amount to borrow
4217
- * @param {object} [params] extra parameters specific to the exchange API endpoints
4218
- * @param {string} [params.timeInForce] either IOC or FOK
4219
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
4220
- */
4221
- await this.loadMarkets();
4222
- const currency = this.currency(code);
4223
- const request = {
4224
- 'currency': currency['id'],
4225
- 'size': this.currencyToPrecision(code, amount),
4226
- 'timeInForce': 'FOK',
4227
- };
4228
- const response = await this.privatePostMarginBorrow(this.extend(request, params));
4229
- //
4230
- // {
4231
- // "success": true,
4232
- // "code": "200",
4233
- // "msg": "success",
4234
- // "retry": false,
4235
- // "data": {
4236
- // "orderNo": "5da6dba0f943c0c81f5d5db5",
4237
- // "actualSize": 10
4238
- // }
4239
- // }
4240
- //
4241
- const data = this.safeValue(response, 'data', {});
4242
- return this.parseMarginLoan(data, currency);
4243
- }
4244
- async borrowIsolatedMargin(symbol, code, amount, params = {}) {
4245
- /**
4246
- * @method
4247
- * @name kucoin#borrowIsolatedMargin
4248
- * @description create a loan to borrow margin
4249
- * @see https://docs.kucoin.com/#1-margin-borrowing
4250
- * @param {string} symbol unified market symbol, required for isolated margin
4251
- * @param {string} code unified currency code of the currency to borrow
4252
- * @param {float} amount the amount to borrow
4253
- * @param {object} [params] extra parameters specific to the exchange API endpoints
4254
- * @param {string} [params.timeInForce] either IOC or FOK
4255
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
4256
- */
4257
- await this.loadMarkets();
4258
- const market = this.market(symbol);
4259
- const currency = this.currency(code);
4260
- const request = {
4261
- 'currency': currency['id'],
4262
- 'size': this.currencyToPrecision(code, amount),
4263
- 'symbol': market['id'],
4264
- 'timeInForce': 'FOK',
4265
- 'isIsolated': true,
4266
- };
4267
- const response = await this.privatePostMarginBorrow(this.extend(request, params));
4268
- //
4269
- // {
4270
- // "success": true,
4271
- // "code": "200",
4272
- // "msg": "success",
4273
- // "retry": false,
4274
- // "data": {
4275
- // "orderNo": "5da6dba0f943c0c81f5d5db5",
4276
- // "actualSize": 10
4277
- // }
4278
- // }
4279
- //
4280
- const data = this.safeValue(response, 'data', {});
4281
- return this.parseMarginLoan(data, currency);
4282
- }
4283
- async repayCrossMargin(code, amount, params = {}) {
4284
- /**
4285
- * @method
4286
- * @name kucoin#repayCrossMargin
4287
- * @description repay borrowed margin and interest
4288
- * @see https://docs.kucoin.com/#2-repayment
4289
- * @param {string} code unified currency code of the currency to repay
4290
- * @param {float} amount the amount to repay
4291
- * @param {object} [params] extra parameters specific to the exchange API endpoints
4292
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
4293
- */
4294
- await this.loadMarkets();
4295
- const currency = this.currency(code);
4296
- const request = {
4297
- 'currency': currency['id'],
4298
- 'size': this.currencyToPrecision(code, amount),
4299
- };
4300
- const response = await this.privatePostMarginRepay(this.extend(request, params));
4301
- //
4302
- // {
4303
- // "success": true,
4304
- // "code": "200",
4305
- // "msg": "success",
4306
- // "retry": false,
4307
- // "data": {
4308
- // "orderNo": "5da6dba0f943c0c81f5d5db5",
4309
- // "actualSize": 10
4310
- // }
4311
- // }
4312
- //
4313
- const data = this.safeValue(response, 'data', {});
4314
- return this.parseMarginLoan(data, currency);
4315
- }
4316
- async repayIsolatedMargin(symbol, code, amount, params = {}) {
4317
- /**
4318
- * @method
4319
- * @name kucoin#repayIsolatedMargin
4320
- * @description repay borrowed margin and interest
4321
- * @see https://docs.kucoin.com/#2-repayment
4322
- * @param {string} symbol unified market symbol
4323
- * @param {string} code unified currency code of the currency to repay
4324
- * @param {float} amount the amount to repay
4325
- * @param {object} [params] extra parameters specific to the exchange API endpoints
4326
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
4327
- */
4328
- await this.loadMarkets();
4329
- const market = this.market(symbol);
4330
- const currency = this.currency(code);
4331
- const request = {
4332
- 'currency': currency['id'],
4333
- 'size': this.currencyToPrecision(code, amount),
4334
- 'symbol': market['id'],
4335
- 'isIsolated': true,
4336
- };
4337
- const response = await this.privatePostMarginRepay(this.extend(request, params));
4338
- //
4339
- // {
4340
- // "success": true,
4341
- // "code": "200",
4342
- // "msg": "success",
4343
- // "retry": false,
4344
- // "data": {
4345
- // "orderNo": "5da6dba0f943c0c81f5d5db5",
4346
- // "actualSize": 10
4347
- // }
4348
- // }
4349
- //
4350
- const data = this.safeValue(response, 'data', {});
4351
- return this.parseMarginLoan(data, currency);
4352
- }
4353
- parseMarginLoan(info, currency = undefined) {
4354
- //
4355
- // {
4356
- // "orderNo": "5da6dba0f943c0c81f5d5db5",
4357
- // "actualSize": 10
4358
- // }
4359
- //
4360
- const timestamp = this.milliseconds();
4361
- const currencyId = this.safeString(info, 'currency');
4362
- return {
4363
- 'id': this.safeString(info, 'orderNo'),
4364
- 'currency': this.safeCurrencyCode(currencyId, currency),
4365
- 'amount': this.safeNumber(info, 'actualSize'),
4366
- 'symbol': undefined,
4367
- 'timestamp': timestamp,
4368
- 'datetime': this.iso8601(timestamp),
4369
- 'info': info,
4370
- };
4371
- }
4372
- async fetchDepositWithdrawFees(codes = undefined, params = {}) {
4373
- /**
4374
- * @method
4375
- * @name kucoin#fetchDepositWithdrawFees
4376
- * @description fetch deposit and withdraw fees - *IMPORTANT* use fetchDepositWithdrawFee to get more in-depth info
4377
- * @see https://docs.kucoin.com/#get-currencies
4378
- * @param {string[]|undefined} codes list of unified currency codes
4379
- * @param {object} [params] extra parameters specific to the exchange API endpoint
4380
- * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
4381
- */
4382
- await this.loadMarkets();
4383
- const response = await this.publicGetCurrencies(params);
4384
- //
4385
- // [
4386
- // {
4387
- // "currency": "CSP",
4388
- // "name": "CSP",
4389
- // "fullName": "Caspian",
4390
- // "precision": 8,
4391
- // "confirms": 12,
4392
- // "contractAddress": "0xa6446d655a0c34bc4f05042ee88170d056cbaf45",
4393
- // "withdrawalMinSize": "2000",
4394
- // "withdrawalMinFee": "1000",
4395
- // "isWithdrawEnabled": true,
4396
- // "isDepositEnabled": true,
4397
- // "isMarginEnabled": false,
4398
- // "isDebitEnabled": false
4399
- // },
4400
- // ]
4401
- //
4402
- const data = this.safeValue(response, 'data', []);
4403
- return this.parseDepositWithdrawFees(data, codes, 'currency');
4404
- }
4405
- sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
4406
- //
4407
- // the v2 URL is https://openapi-v2.kucoin.com/api/v1/endpoint
4408
- // ↑ ↑
4409
- // ↑ ↑
4410
- //
4411
- const versions = this.safeValue(this.options, 'versions', {});
4412
- const apiVersions = this.safeValue(versions, api, {});
4413
- const methodVersions = this.safeValue(apiVersions, method, {});
4414
- const defaultVersion = this.safeString(methodVersions, path, this.options['version']);
4415
- const version = this.safeString(params, 'version', defaultVersion);
4416
- params = this.omit(params, 'version');
4417
- let endpoint = '/api/' + version + '/' + this.implodeParams(path, params);
4418
- if (api === 'webExchange') {
4419
- endpoint = '/' + this.implodeParams(path, params);
4420
- }
4421
- const query = this.omit(params, this.extractParams(path));
4422
- let endpart = '';
4423
- headers = (headers !== undefined) ? headers : {};
4424
- let url = this.urls['api'][api];
4425
- if (Object.keys(query).length) {
4426
- if ((method === 'GET') || (method === 'DELETE')) {
4427
- endpoint += '?' + this.rawencode(query);
4428
- }
4429
- else {
4430
- body = this.json(query);
4431
- endpart = body;
4432
- headers['Content-Type'] = 'application/json';
4433
- }
4434
- }
4435
- url = url + endpoint;
4436
- const isFuturePrivate = (api === 'futuresPrivate');
4437
- const isPrivate = (api === 'private');
4438
- if (isPrivate || isFuturePrivate) {
4439
- this.checkRequiredCredentials();
4440
- const timestamp = this.nonce().toString();
4441
- headers = this.extend({
4442
- 'KC-API-KEY-VERSION': '2',
4443
- 'KC-API-KEY': this.apiKey,
4444
- 'KC-API-TIMESTAMP': timestamp,
4445
- }, headers);
4446
- const apiKeyVersion = this.safeString(headers, 'KC-API-KEY-VERSION');
4447
- if (apiKeyVersion === '2') {
4448
- const passphrase = this.hmac(this.encode(this.password), this.encode(this.secret), sha256.sha256, 'base64');
4449
- headers['KC-API-PASSPHRASE'] = passphrase;
4450
- }
4451
- else {
4452
- headers['KC-API-PASSPHRASE'] = this.password;
4453
- }
4454
- const payload = timestamp + method + endpoint + endpart;
4455
- const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256.sha256, 'base64');
4456
- headers['KC-API-SIGN'] = signature;
4457
- let partner = this.safeValue(this.options, 'partner', {});
4458
- partner = isFuturePrivate ? this.safeValue(partner, 'future', partner) : this.safeValue(partner, 'spot', partner);
4459
- const partnerId = this.safeString(partner, 'id');
4460
- const partnerSecret = this.safeString2(partner, 'secret', 'key');
4461
- if ((partnerId !== undefined) && (partnerSecret !== undefined)) {
4462
- const partnerPayload = timestamp + partnerId + this.apiKey;
4463
- const partnerSignature = this.hmac(this.encode(partnerPayload), this.encode(partnerSecret), sha256.sha256, 'base64');
4464
- headers['KC-API-PARTNER-SIGN'] = partnerSignature;
4465
- headers['KC-API-PARTNER'] = partnerId;
4466
- }
4467
- }
4468
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
4469
- }
4470
- handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
4471
- if (!response) {
4472
- this.throwBroadlyMatchedException(this.exceptions['broad'], body, body);
4473
- return undefined;
4474
- }
4475
- //
4476
- // bad
4477
- // { "code": "400100", "msg": "validation.createOrder.clientOidIsRequired" }
4478
- // good
4479
- // { code: '200000', data: { ... }}
4480
- //
4481
- const errorCode = this.safeString(response, 'code');
4482
- const message = this.safeString2(response, 'msg', 'data', '');
4483
- const feedback = this.id + ' ' + message;
4484
- this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
4485
- this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
4486
- this.throwBroadlyMatchedException(this.exceptions['broad'], body, feedback);
4487
- if (errorCode !== '200000' && errorCode !== '200') {
4488
- throw new errors.ExchangeError(feedback);
4489
- }
4490
- return undefined;
4491
- }
4492
- }
4493
-
4494
- module.exports = kucoin;