ccxt 4.2.18 → 4.2.20

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 (446) hide show
  1. package/README.md +100 -100
  2. package/dist/ccxt.browser.js +34240 -33297
  3. package/dist/ccxt.browser.min.js +2 -2
  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 +276 -27
  8. package/dist/cjs/src/bigone.js +434 -168
  9. package/dist/cjs/src/binance.js +165 -35
  10. package/dist/cjs/src/binanceus.js +25 -0
  11. package/dist/cjs/src/bingx.js +185 -42
  12. package/dist/cjs/src/bitfinex.js +2 -3
  13. package/dist/cjs/src/bitget.js +84 -47
  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/bitteam.js +1 -1
  19. package/dist/cjs/src/bybit.js +27 -75
  20. package/dist/cjs/src/coinbase.js +176 -26
  21. package/dist/cjs/src/coincheck.js +1 -0
  22. package/dist/cjs/src/coinex.js +3 -0
  23. package/dist/cjs/src/coinlist.js +13 -6
  24. package/dist/cjs/src/coinone.js +2 -2
  25. package/dist/cjs/src/coinsph.js +4 -5
  26. package/dist/cjs/src/delta.js +7 -19
  27. package/dist/cjs/src/deribit.js +17 -4
  28. package/dist/cjs/src/gate.js +151 -194
  29. package/dist/cjs/src/gemini.js +1 -1
  30. package/dist/cjs/src/hitbtc.js +2 -3
  31. package/dist/cjs/src/htx.js +157 -7
  32. package/dist/cjs/src/huobijp.js +2 -3
  33. package/dist/cjs/src/independentreserve.js +7 -5
  34. package/dist/cjs/src/kraken.js +86 -54
  35. package/dist/cjs/src/kucoin.js +5 -0
  36. package/dist/cjs/src/kucoinfutures.js +140 -86
  37. package/dist/cjs/src/lbank.js +60 -33
  38. package/dist/cjs/src/luno.js +84 -2
  39. package/dist/cjs/src/mexc.js +3 -3
  40. package/dist/cjs/src/oceanex.js +1 -1
  41. package/dist/cjs/src/okx.js +23 -29
  42. package/dist/cjs/{js/src/bitpanda.js → src/onetrading.js} +39 -39
  43. package/dist/cjs/src/phemex.js +37 -27
  44. package/dist/cjs/src/poloniexfutures.js +1 -0
  45. package/dist/cjs/src/pro/binance.js +66 -25
  46. package/dist/cjs/src/pro/bitget.js +1 -1
  47. package/dist/cjs/src/pro/bitpanda.js +5 -1330
  48. package/dist/cjs/src/pro/coinbase.js +4 -1
  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 +11 -2
  67. package/js/ccxt.js +8 -2
  68. package/js/src/abstract/binance.d.ts +1 -0
  69. package/js/src/abstract/binancecoinm.d.ts +1 -0
  70. package/js/src/abstract/binanceus.d.ts +1 -0
  71. package/js/src/abstract/binanceusdm.d.ts +1 -0
  72. package/js/src/abstract/bitpanda.d.ts +4 -4
  73. package/js/src/abstract/bitpanda.js +3 -3
  74. package/js/src/abstract/bitstamp.d.ts +8 -0
  75. package/js/src/abstract/gate.d.ts +1 -0
  76. package/js/src/abstract/gateio.d.ts +1 -0
  77. package/js/src/abstract/htx.d.ts +3 -0
  78. package/js/src/abstract/huobi.d.ts +3 -0
  79. package/js/src/abstract/luno.d.ts +1 -0
  80. package/js/src/abstract/onetrading.d.ts +38 -0
  81. package/js/src/abstract/onetrading.js +11 -0
  82. package/js/src/ascendex.js +2 -0
  83. package/js/src/base/Exchange.d.ts +3 -0
  84. package/js/src/base/Exchange.js +10 -0
  85. package/js/src/binance.js +2 -1
  86. package/js/src/binanceus.js +17 -0
  87. package/js/src/bingx.js +3 -2
  88. package/js/src/bitget.d.ts +1 -1
  89. package/js/src/bitget.js +47 -34
  90. package/js/src/bitpanda.d.ts +2 -72
  91. package/js/src/bitpanda.js +5 -1991
  92. package/js/src/bitstamp.js +8 -0
  93. package/js/src/bitteam.js +1 -1
  94. package/js/src/bybit.d.ts +0 -1
  95. package/js/src/bybit.js +1 -29
  96. package/js/src/delta.d.ts +0 -1
  97. package/js/src/delta.js +0 -18
  98. package/js/src/deribit.js +11 -3
  99. package/js/src/gate.d.ts +1 -1
  100. package/js/src/gate.js +50 -135
  101. package/js/src/htx.js +3 -0
  102. package/js/src/kraken.d.ts +1 -0
  103. package/js/src/kraken.js +39 -38
  104. package/js/src/kucoinfutures.d.ts +6 -6
  105. package/js/src/kucoinfutures.js +9 -9
  106. package/js/src/lbank.js +1 -0
  107. package/js/src/luno.d.ts +3 -1
  108. package/js/src/luno.js +84 -2
  109. package/js/src/mexc.js +1 -2
  110. package/js/src/okx.d.ts +0 -1
  111. package/js/src/okx.js +0 -18
  112. package/js/src/onetrading.d.ts +74 -0
  113. package/js/src/onetrading.js +2003 -0
  114. package/js/src/poloniexfutures.js +1 -0
  115. package/js/src/pro/binance.js +6 -1
  116. package/js/src/pro/bitpanda.d.ts +2 -34
  117. package/js/src/pro/bitpanda.js +5 -1330
  118. package/js/src/pro/lbank.d.ts +29 -0
  119. package/js/src/pro/lbank.js +882 -0
  120. package/js/src/pro/onetrading.d.ts +36 -0
  121. package/js/src/pro/onetrading.js +1339 -0
  122. package/package.json +2 -2
  123. package/rollup.config.js +2 -0
  124. package/skip-tests.json +4 -2
  125. package/test-commonjs.cjs +25 -1
  126. package/dist/cjs/js/ccxt.js +0 -478
  127. package/dist/cjs/js/src/abstract/alpaca.js +0 -9
  128. package/dist/cjs/js/src/abstract/ascendex.js +0 -9
  129. package/dist/cjs/js/src/abstract/bigone.js +0 -9
  130. package/dist/cjs/js/src/abstract/binance.js +0 -9
  131. package/dist/cjs/js/src/abstract/bingx.js +0 -9
  132. package/dist/cjs/js/src/abstract/bit2c.js +0 -9
  133. package/dist/cjs/js/src/abstract/bitbank.js +0 -9
  134. package/dist/cjs/js/src/abstract/bitbns.js +0 -9
  135. package/dist/cjs/js/src/abstract/bitfinex.js +0 -9
  136. package/dist/cjs/js/src/abstract/bitfinex2.js +0 -9
  137. package/dist/cjs/js/src/abstract/bitflyer.js +0 -9
  138. package/dist/cjs/js/src/abstract/bitforex.js +0 -9
  139. package/dist/cjs/js/src/abstract/bitget.js +0 -9
  140. package/dist/cjs/js/src/abstract/bithumb.js +0 -9
  141. package/dist/cjs/js/src/abstract/bitmart.js +0 -9
  142. package/dist/cjs/js/src/abstract/bitmex.js +0 -9
  143. package/dist/cjs/js/src/abstract/bitopro.js +0 -9
  144. package/dist/cjs/js/src/abstract/bitpanda.js +0 -9
  145. package/dist/cjs/js/src/abstract/bitrue.js +0 -9
  146. package/dist/cjs/js/src/abstract/bitso.js +0 -9
  147. package/dist/cjs/js/src/abstract/bitstamp.js +0 -9
  148. package/dist/cjs/js/src/abstract/bitteam.js +0 -9
  149. package/dist/cjs/js/src/abstract/bitvavo.js +0 -9
  150. package/dist/cjs/js/src/abstract/bl3p.js +0 -9
  151. package/dist/cjs/js/src/abstract/blockchaincom.js +0 -9
  152. package/dist/cjs/js/src/abstract/btcalpha.js +0 -9
  153. package/dist/cjs/js/src/abstract/btcbox.js +0 -9
  154. package/dist/cjs/js/src/abstract/btcmarkets.js +0 -9
  155. package/dist/cjs/js/src/abstract/btcturk.js +0 -9
  156. package/dist/cjs/js/src/abstract/bybit.js +0 -9
  157. package/dist/cjs/js/src/abstract/cex.js +0 -9
  158. package/dist/cjs/js/src/abstract/coinbase.js +0 -9
  159. package/dist/cjs/js/src/abstract/coinbasepro.js +0 -9
  160. package/dist/cjs/js/src/abstract/coincheck.js +0 -9
  161. package/dist/cjs/js/src/abstract/coinex.js +0 -9
  162. package/dist/cjs/js/src/abstract/coinlist.js +0 -9
  163. package/dist/cjs/js/src/abstract/coinmate.js +0 -9
  164. package/dist/cjs/js/src/abstract/coinone.js +0 -9
  165. package/dist/cjs/js/src/abstract/coinsph.js +0 -9
  166. package/dist/cjs/js/src/abstract/coinspot.js +0 -9
  167. package/dist/cjs/js/src/abstract/cryptocom.js +0 -9
  168. package/dist/cjs/js/src/abstract/currencycom.js +0 -9
  169. package/dist/cjs/js/src/abstract/delta.js +0 -9
  170. package/dist/cjs/js/src/abstract/deribit.js +0 -9
  171. package/dist/cjs/js/src/abstract/digifinex.js +0 -9
  172. package/dist/cjs/js/src/abstract/exmo.js +0 -9
  173. package/dist/cjs/js/src/abstract/gate.js +0 -9
  174. package/dist/cjs/js/src/abstract/gemini.js +0 -9
  175. package/dist/cjs/js/src/abstract/hitbtc.js +0 -9
  176. package/dist/cjs/js/src/abstract/hollaex.js +0 -9
  177. package/dist/cjs/js/src/abstract/htx.js +0 -9
  178. package/dist/cjs/js/src/abstract/huobijp.js +0 -9
  179. package/dist/cjs/js/src/abstract/idex.js +0 -9
  180. package/dist/cjs/js/src/abstract/independentreserve.js +0 -9
  181. package/dist/cjs/js/src/abstract/indodax.js +0 -9
  182. package/dist/cjs/js/src/abstract/kraken.js +0 -9
  183. package/dist/cjs/js/src/abstract/krakenfutures.js +0 -9
  184. package/dist/cjs/js/src/abstract/kucoin.js +0 -9
  185. package/dist/cjs/js/src/abstract/kucoinfutures.js +0 -9
  186. package/dist/cjs/js/src/abstract/kuna.js +0 -9
  187. package/dist/cjs/js/src/abstract/latoken.js +0 -9
  188. package/dist/cjs/js/src/abstract/lbank.js +0 -9
  189. package/dist/cjs/js/src/abstract/luno.js +0 -9
  190. package/dist/cjs/js/src/abstract/lykke.js +0 -9
  191. package/dist/cjs/js/src/abstract/mercado.js +0 -9
  192. package/dist/cjs/js/src/abstract/mexc.js +0 -9
  193. package/dist/cjs/js/src/abstract/ndax.js +0 -9
  194. package/dist/cjs/js/src/abstract/novadax.js +0 -9
  195. package/dist/cjs/js/src/abstract/oceanex.js +0 -9
  196. package/dist/cjs/js/src/abstract/okcoin.js +0 -9
  197. package/dist/cjs/js/src/abstract/okx.js +0 -9
  198. package/dist/cjs/js/src/abstract/p2b.js +0 -9
  199. package/dist/cjs/js/src/abstract/paymium.js +0 -9
  200. package/dist/cjs/js/src/abstract/phemex.js +0 -9
  201. package/dist/cjs/js/src/abstract/poloniex.js +0 -9
  202. package/dist/cjs/js/src/abstract/poloniexfutures.js +0 -9
  203. package/dist/cjs/js/src/abstract/probit.js +0 -9
  204. package/dist/cjs/js/src/abstract/timex.js +0 -9
  205. package/dist/cjs/js/src/abstract/tokocrypto.js +0 -9
  206. package/dist/cjs/js/src/abstract/upbit.js +0 -9
  207. package/dist/cjs/js/src/abstract/wavesexchange.js +0 -9
  208. package/dist/cjs/js/src/abstract/wazirx.js +0 -9
  209. package/dist/cjs/js/src/abstract/whitebit.js +0 -9
  210. package/dist/cjs/js/src/abstract/woo.js +0 -9
  211. package/dist/cjs/js/src/abstract/yobit.js +0 -9
  212. package/dist/cjs/js/src/abstract/zaif.js +0 -9
  213. package/dist/cjs/js/src/abstract/zonda.js +0 -9
  214. package/dist/cjs/js/src/ace.js +0 -1058
  215. package/dist/cjs/js/src/alpaca.js +0 -1125
  216. package/dist/cjs/js/src/ascendex.js +0 -3365
  217. package/dist/cjs/js/src/base/Exchange.js +0 -5260
  218. package/dist/cjs/js/src/base/Precise.js +0 -263
  219. package/dist/cjs/js/src/base/errors.js +0 -299
  220. package/dist/cjs/js/src/base/functions/crypto.js +0 -78
  221. package/dist/cjs/js/src/base/functions/encode.js +0 -44
  222. package/dist/cjs/js/src/base/functions/generic.js +0 -193
  223. package/dist/cjs/js/src/base/functions/misc.js +0 -96
  224. package/dist/cjs/js/src/base/functions/number.js +0 -297
  225. package/dist/cjs/js/src/base/functions/platform.js +0 -28
  226. package/dist/cjs/js/src/base/functions/rsa.js +0 -34
  227. package/dist/cjs/js/src/base/functions/string.js +0 -48
  228. package/dist/cjs/js/src/base/functions/throttle.js +0 -66
  229. package/dist/cjs/js/src/base/functions/time.js +0 -187
  230. package/dist/cjs/js/src/base/functions/totp.js +0 -24
  231. package/dist/cjs/js/src/base/functions/type.js +0 -162
  232. package/dist/cjs/js/src/base/functions.js +0 -157
  233. package/dist/cjs/js/src/base/ws/Cache.js +0 -254
  234. package/dist/cjs/js/src/base/ws/Client.js +0 -299
  235. package/dist/cjs/js/src/base/ws/Future.js +0 -34
  236. package/dist/cjs/js/src/base/ws/OrderBook.js +0 -107
  237. package/dist/cjs/js/src/base/ws/OrderBookSide.js +0 -281
  238. package/dist/cjs/js/src/base/ws/WsClient.js +0 -69
  239. package/dist/cjs/js/src/bequant.js +0 -33
  240. package/dist/cjs/js/src/bigone.js +0 -2213
  241. package/dist/cjs/js/src/binance.js +0 -9851
  242. package/dist/cjs/js/src/binancecoinm.js +0 -45
  243. package/dist/cjs/js/src/binanceus.js +0 -92
  244. package/dist/cjs/js/src/binanceusdm.js +0 -58
  245. package/dist/cjs/js/src/bingx.js +0 -3872
  246. package/dist/cjs/js/src/bit2c.js +0 -916
  247. package/dist/cjs/js/src/bitbank.js +0 -1000
  248. package/dist/cjs/js/src/bitbay.js +0 -17
  249. package/dist/cjs/js/src/bitbns.js +0 -1220
  250. package/dist/cjs/js/src/bitcoincom.js +0 -17
  251. package/dist/cjs/js/src/bitfinex.js +0 -1670
  252. package/dist/cjs/js/src/bitfinex2.js +0 -2990
  253. package/dist/cjs/js/src/bitflyer.js +0 -1045
  254. package/dist/cjs/js/src/bitforex.js +0 -852
  255. package/dist/cjs/js/src/bitget.js +0 -8295
  256. package/dist/cjs/js/src/bithumb.js +0 -1090
  257. package/dist/cjs/js/src/bitmart.js +0 -4454
  258. package/dist/cjs/js/src/bitmex.js +0 -2881
  259. package/dist/cjs/js/src/bitopro.js +0 -1724
  260. package/dist/cjs/js/src/bitrue.js +0 -3253
  261. package/dist/cjs/js/src/bitso.js +0 -1753
  262. package/dist/cjs/js/src/bitstamp.js +0 -2188
  263. package/dist/cjs/js/src/bitteam.js +0 -2309
  264. package/dist/cjs/js/src/bitvavo.js +0 -1968
  265. package/dist/cjs/js/src/bl3p.js +0 -447
  266. package/dist/cjs/js/src/blockchaincom.js +0 -1160
  267. package/dist/cjs/js/src/btcalpha.js +0 -929
  268. package/dist/cjs/js/src/btcbox.js +0 -565
  269. package/dist/cjs/js/src/btcmarkets.js +0 -1237
  270. package/dist/cjs/js/src/btcturk.js +0 -929
  271. package/dist/cjs/js/src/bybit.js +0 -7624
  272. package/dist/cjs/js/src/cex.js +0 -1693
  273. package/dist/cjs/js/src/coinbase.js +0 -3424
  274. package/dist/cjs/js/src/coinbasepro.js +0 -1866
  275. package/dist/cjs/js/src/coincheck.js +0 -844
  276. package/dist/cjs/js/src/coinex.js +0 -5417
  277. package/dist/cjs/js/src/coinlist.js +0 -2337
  278. package/dist/cjs/js/src/coinmate.js +0 -989
  279. package/dist/cjs/js/src/coinone.js +0 -1185
  280. package/dist/cjs/js/src/coinsph.js +0 -1933
  281. package/dist/cjs/js/src/coinspot.js +0 -548
  282. package/dist/cjs/js/src/cryptocom.js +0 -3007
  283. package/dist/cjs/js/src/currencycom.js +0 -2015
  284. package/dist/cjs/js/src/delta.js +0 -3262
  285. package/dist/cjs/js/src/deribit.js +0 -3310
  286. package/dist/cjs/js/src/digifinex.js +0 -4307
  287. package/dist/cjs/js/src/exmo.js +0 -2645
  288. package/dist/cjs/js/src/fmfwio.js +0 -34
  289. package/dist/cjs/js/src/gate.js +0 -7077
  290. package/dist/cjs/js/src/gateio.js +0 -16
  291. package/dist/cjs/js/src/gemini.js +0 -1801
  292. package/dist/cjs/js/src/hitbtc.js +0 -3660
  293. package/dist/cjs/js/src/hitbtc3.js +0 -19
  294. package/dist/cjs/js/src/hollaex.js +0 -1882
  295. package/dist/cjs/js/src/htx.js +0 -9174
  296. package/dist/cjs/js/src/huobi.js +0 -16
  297. package/dist/cjs/js/src/huobijp.js +0 -1918
  298. package/dist/cjs/js/src/idex.js +0 -1770
  299. package/dist/cjs/js/src/independentreserve.js +0 -761
  300. package/dist/cjs/js/src/indodax.js +0 -1069
  301. package/dist/cjs/js/src/kraken.js +0 -2891
  302. package/dist/cjs/js/src/krakenfutures.js +0 -2407
  303. package/dist/cjs/js/src/kucoin.js +0 -4494
  304. package/dist/cjs/js/src/kucoinfutures.js +0 -2529
  305. package/dist/cjs/js/src/kuna.js +0 -1949
  306. package/dist/cjs/js/src/latoken.js +0 -1729
  307. package/dist/cjs/js/src/lbank.js +0 -2851
  308. package/dist/cjs/js/src/luno.js +0 -1044
  309. package/dist/cjs/js/src/lykke.js +0 -1303
  310. package/dist/cjs/js/src/mercado.js +0 -897
  311. package/dist/cjs/js/src/mexc.js +0 -5407
  312. package/dist/cjs/js/src/ndax.js +0 -2450
  313. package/dist/cjs/js/src/novadax.js +0 -1556
  314. package/dist/cjs/js/src/oceanex.js +0 -964
  315. package/dist/cjs/js/src/okcoin.js +0 -3115
  316. package/dist/cjs/js/src/okx.js +0 -7331
  317. package/dist/cjs/js/src/p2b.js +0 -1243
  318. package/dist/cjs/js/src/paymium.js +0 -597
  319. package/dist/cjs/js/src/phemex.js +0 -4725
  320. package/dist/cjs/js/src/poloniex.js +0 -2356
  321. package/dist/cjs/js/src/poloniexfutures.js +0 -1794
  322. package/dist/cjs/js/src/pro/alpaca.js +0 -714
  323. package/dist/cjs/js/src/pro/ascendex.js +0 -957
  324. package/dist/cjs/js/src/pro/bequant.js +0 -33
  325. package/dist/cjs/js/src/pro/binance.js +0 -2796
  326. package/dist/cjs/js/src/pro/binancecoinm.js +0 -23
  327. package/dist/cjs/js/src/pro/binanceus.js +0 -51
  328. package/dist/cjs/js/src/pro/binanceusdm.js +0 -32
  329. package/dist/cjs/js/src/pro/bingx.js +0 -944
  330. package/dist/cjs/js/src/pro/bitcoincom.js +0 -29
  331. package/dist/cjs/js/src/pro/bitfinex.js +0 -672
  332. package/dist/cjs/js/src/pro/bitfinex2.js +0 -1159
  333. package/dist/cjs/js/src/pro/bitget.js +0 -1733
  334. package/dist/cjs/js/src/pro/bitmart.js +0 -1486
  335. package/dist/cjs/js/src/pro/bitmex.js +0 -1576
  336. package/dist/cjs/js/src/pro/bitopro.js +0 -327
  337. package/dist/cjs/js/src/pro/bitrue.js +0 -462
  338. package/dist/cjs/js/src/pro/bitstamp.js +0 -547
  339. package/dist/cjs/js/src/pro/bitvavo.js +0 -704
  340. package/dist/cjs/js/src/pro/blockchaincom.js +0 -794
  341. package/dist/cjs/js/src/pro/bybit.js +0 -1843
  342. package/dist/cjs/js/src/pro/cex.js +0 -1510
  343. package/dist/cjs/js/src/pro/coinbase.js +0 -561
  344. package/dist/cjs/js/src/pro/coinbasepro.js +0 -968
  345. package/dist/cjs/js/src/pro/coinex.js +0 -1095
  346. package/dist/cjs/js/src/pro/cryptocom.js +0 -1020
  347. package/dist/cjs/js/src/pro/currencycom.js +0 -563
  348. package/dist/cjs/js/src/pro/deribit.js +0 -825
  349. package/dist/cjs/js/src/pro/exmo.js +0 -658
  350. package/dist/cjs/js/src/pro/gate.js +0 -1316
  351. package/dist/cjs/js/src/pro/gateio.js +0 -16
  352. package/dist/cjs/js/src/pro/gemini.js +0 -649
  353. package/dist/cjs/js/src/pro/hitbtc.js +0 -1294
  354. package/dist/cjs/js/src/pro/hollaex.js +0 -597
  355. package/dist/cjs/js/src/pro/htx.js +0 -2388
  356. package/dist/cjs/js/src/pro/huobi.js +0 -16
  357. package/dist/cjs/js/src/pro/huobijp.js +0 -606
  358. package/dist/cjs/js/src/pro/idex.js +0 -714
  359. package/dist/cjs/js/src/pro/independentreserve.js +0 -280
  360. package/dist/cjs/js/src/pro/kraken.js +0 -1364
  361. package/dist/cjs/js/src/pro/krakenfutures.js +0 -1506
  362. package/dist/cjs/js/src/pro/kucoin.js +0 -1062
  363. package/dist/cjs/js/src/pro/kucoinfutures.js +0 -989
  364. package/dist/cjs/js/src/pro/luno.js +0 -322
  365. package/dist/cjs/js/src/pro/mexc.js +0 -1170
  366. package/dist/cjs/js/src/pro/ndax.js +0 -545
  367. package/dist/cjs/js/src/pro/okcoin.js +0 -760
  368. package/dist/cjs/js/src/pro/okx.js +0 -1608
  369. package/dist/cjs/js/src/pro/phemex.js +0 -1511
  370. package/dist/cjs/js/src/pro/poloniex.js +0 -1253
  371. package/dist/cjs/js/src/pro/poloniexfutures.js +0 -1022
  372. package/dist/cjs/js/src/pro/probit.js +0 -586
  373. package/dist/cjs/js/src/pro/upbit.js +0 -234
  374. package/dist/cjs/js/src/pro/wazirx.js +0 -776
  375. package/dist/cjs/js/src/pro/whitebit.js +0 -927
  376. package/dist/cjs/js/src/pro/woo.js +0 -895
  377. package/dist/cjs/js/src/probit.js +0 -1867
  378. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +0 -401
  379. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -195
  380. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -308
  381. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +0 -554
  382. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -94
  383. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -70
  384. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -91
  385. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -16
  386. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +0 -1760
  387. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -52
  388. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +0 -81
  389. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +0 -376
  390. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -70
  391. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +0 -1580
  392. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -74
  393. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +0 -24
  394. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +0 -158
  395. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +0 -429
  396. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +0 -176
  397. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +0 -324
  398. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +0 -163
  399. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +0 -245
  400. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +0 -1018
  401. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +0 -383
  402. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +0 -258
  403. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +0 -53
  404. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +0 -120
  405. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +0 -69
  406. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +0 -7
  407. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +0 -83
  408. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +0 -240
  409. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +0 -91
  410. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +0 -130
  411. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +0 -214
  412. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +0 -239
  413. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +0 -93
  414. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +0 -354
  415. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +0 -16
  416. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +0 -20
  417. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +0 -30
  418. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +0 -239
  419. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +0 -372
  420. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +0 -273
  421. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +0 -139
  422. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +0 -14
  423. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +0 -16
  424. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +0 -81
  425. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +0 -292
  426. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +0 -103
  427. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +0 -140
  428. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +0 -175
  429. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +0 -95
  430. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +0 -7
  431. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +0 -383
  432. package/dist/cjs/js/src/timex.js +0 -1562
  433. package/dist/cjs/js/src/tokocrypto.js +0 -2542
  434. package/dist/cjs/js/src/upbit.js +0 -1844
  435. package/dist/cjs/js/src/wavesexchange.js +0 -2607
  436. package/dist/cjs/js/src/wazirx.js +0 -953
  437. package/dist/cjs/js/src/whitebit.js +0 -2310
  438. package/dist/cjs/js/src/woo.js +0 -2769
  439. package/dist/cjs/js/src/yobit.js +0 -1314
  440. package/dist/cjs/js/src/zaif.js +0 -736
  441. package/dist/cjs/js/src/zonda.js +0 -1883
  442. package/dist/cjs/src/abstract/bitpanda.js +0 -9
  443. package/test.ts +0 -0
  444. /package/dist/cjs/{js/src/abstract/ace.js → src/abstract/onetrading.js} +0 -0
  445. /package/dist/cjs/{js/src → src}/pro/coincheck.js +0 -0
  446. /package/dist/cjs/{js/src → src}/pro/coinone.js +0 -0
@@ -1,4454 +0,0 @@
1
- 'use strict';
2
-
3
- var bitmart$1 = require('./abstract/bitmart.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 bitmart
13
- * @augments Exchange
14
- */
15
- class bitmart extends bitmart$1 {
16
- describe() {
17
- return this.deepExtend(super.describe(), {
18
- 'id': 'bitmart',
19
- 'name': 'BitMart',
20
- 'countries': ['US', 'CN', 'HK', 'KR'],
21
- // 150 per 5 seconds = 30 per second
22
- // rateLimit = 1000ms / 30 ~= 33.334
23
- 'rateLimit': 33.34,
24
- 'version': 'v2',
25
- 'certified': true,
26
- 'pro': true,
27
- 'has': {
28
- 'CORS': undefined,
29
- 'spot': true,
30
- 'margin': true,
31
- 'swap': true,
32
- 'future': false,
33
- 'option': false,
34
- 'borrowCrossMargin': false,
35
- 'borrowIsolatedMargin': true,
36
- 'cancelAllOrders': true,
37
- 'cancelOrder': true,
38
- 'cancelOrders': false,
39
- 'createMarketBuyOrderWithCost': true,
40
- 'createMarketOrderWithCost': false,
41
- 'createMarketSellOrderWithCost': false,
42
- 'createOrder': true,
43
- 'createPostOnlyOrder': true,
44
- 'createStopLimitOrder': false,
45
- 'createStopMarketOrder': false,
46
- 'createStopOrder': false,
47
- 'createTrailingPercentOrder': true,
48
- 'fetchBalance': true,
49
- 'fetchBorrowInterest': true,
50
- 'fetchBorrowRateHistories': false,
51
- 'fetchBorrowRateHistory': false,
52
- 'fetchCanceledOrders': true,
53
- 'fetchClosedOrders': true,
54
- 'fetchCrossBorrowRate': false,
55
- 'fetchCrossBorrowRates': false,
56
- 'fetchCurrencies': true,
57
- 'fetchDeposit': true,
58
- 'fetchDepositAddress': true,
59
- 'fetchDepositAddresses': false,
60
- 'fetchDepositAddressesByNetwork': false,
61
- 'fetchDeposits': true,
62
- 'fetchDepositWithdrawFee': true,
63
- 'fetchDepositWithdrawFees': false,
64
- 'fetchFundingHistory': undefined,
65
- 'fetchFundingRate': true,
66
- 'fetchFundingRateHistory': false,
67
- 'fetchFundingRates': false,
68
- 'fetchIsolatedBorrowRate': true,
69
- 'fetchIsolatedBorrowRates': true,
70
- 'fetchLiquidations': false,
71
- 'fetchMarginMode': false,
72
- 'fetchMarkets': true,
73
- 'fetchMyLiquidations': true,
74
- 'fetchMyTrades': true,
75
- 'fetchOHLCV': true,
76
- 'fetchOpenInterest': true,
77
- 'fetchOpenInterestHistory': false,
78
- 'fetchOpenOrders': true,
79
- 'fetchOrder': true,
80
- 'fetchOrderBook': true,
81
- 'fetchOrders': false,
82
- 'fetchOrderTrades': true,
83
- 'fetchPosition': true,
84
- 'fetchPositionMode': false,
85
- 'fetchPositions': true,
86
- 'fetchStatus': true,
87
- 'fetchTicker': true,
88
- 'fetchTickers': true,
89
- 'fetchTime': true,
90
- 'fetchTrades': true,
91
- 'fetchTradingFee': true,
92
- 'fetchTradingFees': false,
93
- 'fetchTransactionFee': true,
94
- 'fetchTransactionFees': false,
95
- 'fetchTransfer': false,
96
- 'fetchTransfers': true,
97
- 'fetchWithdrawAddressesByNetwork': false,
98
- 'fetchWithdrawal': true,
99
- 'fetchWithdrawals': true,
100
- 'reduceMargin': false,
101
- 'repayCrossMargin': false,
102
- 'repayIsolatedMargin': true,
103
- 'setLeverage': true,
104
- 'setMarginMode': false,
105
- 'transfer': true,
106
- 'withdraw': true,
107
- },
108
- 'hostname': 'bitmart.com',
109
- 'urls': {
110
- 'logo': 'https://user-images.githubusercontent.com/1294454/129991357-8f47464b-d0f4-41d6-8a82-34122f0d1398.jpg',
111
- 'api': {
112
- 'rest': 'https://api-cloud.{hostname}', // bitmart.info for Hong Kong users
113
- },
114
- 'www': 'https://www.bitmart.com/',
115
- 'doc': 'https://developer-pro.bitmart.com/',
116
- 'referral': {
117
- 'url': 'http://www.bitmart.com/?r=rQCFLh',
118
- 'discount': 0.3,
119
- },
120
- 'fees': 'https://www.bitmart.com/fee/en',
121
- },
122
- 'requiredCredentials': {
123
- 'apiKey': true,
124
- 'secret': true,
125
- 'uid': true,
126
- },
127
- 'api': {
128
- 'public': {
129
- 'get': {
130
- 'system/time': 3,
131
- 'system/service': 3,
132
- // spot markets
133
- 'spot/v1/currencies': 7.5,
134
- 'spot/v1/symbols': 7.5,
135
- 'spot/v1/symbols/details': 5,
136
- 'spot/quotation/v3/tickers': 6,
137
- 'spot/quotation/v3/ticker': 4,
138
- 'spot/quotation/v3/lite-klines': 5,
139
- 'spot/quotation/v3/klines': 7,
140
- 'spot/quotation/v3/books': 4,
141
- 'spot/quotation/v3/trades': 4,
142
- 'spot/v1/ticker': 5,
143
- 'spot/v2/ticker': 30,
144
- 'spot/v1/ticker_detail': 5,
145
- 'spot/v1/steps': 30,
146
- 'spot/v1/symbols/kline': 6,
147
- 'spot/v1/symbols/book': 5,
148
- 'spot/v1/symbols/trades': 5,
149
- // contract markets
150
- 'contract/v1/tickers': 15,
151
- 'contract/public/details': 5,
152
- 'contract/public/depth': 5,
153
- 'contract/public/open-interest': 30,
154
- 'contract/public/funding-rate': 30,
155
- 'contract/public/kline': 6,
156
- 'account/v1/currencies': 30,
157
- },
158
- },
159
- 'private': {
160
- 'get': {
161
- // sub-account
162
- 'account/sub-account/v1/transfer-list': 7.5,
163
- 'account/sub-account/v1/transfer-history': 7.5,
164
- 'account/sub-account/main/v1/wallet': 5,
165
- 'account/sub-account/main/v1/subaccount-list': 7.5,
166
- 'account/contract/sub-account/main/v1/wallet': 5,
167
- 'account/contract/sub-account/main/v1/transfer-list': 7.5,
168
- 'account/contract/sub-account/v1/transfer-history': 7.5,
169
- // account
170
- 'account/v1/wallet': 5,
171
- 'account/v1/currencies': 30,
172
- 'spot/v1/wallet': 5,
173
- 'account/v1/deposit/address': 30,
174
- 'account/v1/withdraw/charge': 32,
175
- 'account/v2/deposit-withdraw/history': 7.5,
176
- 'account/v1/deposit-withdraw/detail': 7.5,
177
- // order
178
- 'spot/v1/order_detail': 1,
179
- 'spot/v2/orders': 5,
180
- 'spot/v1/trades': 5,
181
- // newer order endpoint
182
- 'spot/v2/trades': 5,
183
- 'spot/v3/orders': 5,
184
- 'spot/v2/order_detail': 1,
185
- // margin
186
- 'spot/v1/margin/isolated/borrow_record': 1,
187
- 'spot/v1/margin/isolated/repay_record': 1,
188
- 'spot/v1/margin/isolated/pairs': 30,
189
- 'spot/v1/margin/isolated/account': 5,
190
- 'spot/v1/trade_fee': 30,
191
- 'spot/v1/user_fee': 30,
192
- // broker
193
- 'spot/v1/broker/rebate': 1,
194
- // contract
195
- 'contract/private/assets-detail': 5,
196
- 'contract/private/order': 1.2,
197
- 'contract/private/order-history': 10,
198
- 'contract/private/position': 10,
199
- 'contract/private/get-open-orders': 1.2,
200
- 'contract/private/current-plan-order': 1.2,
201
- 'contract/private/trades': 10,
202
- },
203
- 'post': {
204
- // sub-account endpoints
205
- 'account/sub-account/main/v1/sub-to-main': 30,
206
- 'account/sub-account/sub/v1/sub-to-main': 30,
207
- 'account/sub-account/main/v1/main-to-sub': 30,
208
- 'account/sub-account/sub/v1/sub-to-sub': 30,
209
- 'account/sub-account/main/v1/sub-to-sub': 30,
210
- 'account/contract/sub-account/main/v1/sub-to-main': 7.5,
211
- 'account/contract/sub-account/main/v1/main-to-sub': 7.5,
212
- 'account/contract/sub-account/sub/v1/sub-to-main': 7.5,
213
- // account
214
- 'account/v1/withdraw/apply': 7.5,
215
- // transaction and trading
216
- 'spot/v1/submit_order': 1,
217
- 'spot/v1/batch_orders': 1,
218
- 'spot/v2/cancel_order': 1,
219
- 'spot/v1/cancel_orders': 15,
220
- 'spot/v4/query/order': 1,
221
- 'spot/v4/query/client-order': 1,
222
- 'spot/v4/query/open-orders': 5,
223
- 'spot/v4/query/history-orders': 5,
224
- 'spot/v4/query/trades': 5,
225
- 'spot/v4/query/order-trades': 5,
226
- // newer endpoint
227
- 'spot/v3/cancel_order': 1,
228
- 'spot/v2/batch_orders': 1,
229
- 'spot/v2/submit_order': 1,
230
- // margin
231
- 'spot/v1/margin/submit_order': 1,
232
- 'spot/v1/margin/isolated/borrow': 30,
233
- 'spot/v1/margin/isolated/repay': 30,
234
- 'spot/v1/margin/isolated/transfer': 30,
235
- // contract
236
- 'account/v1/transfer-contract-list': 60,
237
- 'account/v1/transfer-contract': 60,
238
- 'contract/private/submit-order': 2.5,
239
- 'contract/private/cancel-order': 1.5,
240
- 'contract/private/cancel-orders': 30,
241
- 'contract/private/submit-plan-order': 2.5,
242
- 'contract/private/cancel-plan-order': 1.5,
243
- 'contract/private/submit-leverage': 2.5,
244
- },
245
- },
246
- },
247
- 'timeframes': {
248
- '1m': 1,
249
- '3m': 3,
250
- '5m': 5,
251
- '15m': 15,
252
- '30m': 30,
253
- '45m': 45,
254
- '1h': 60,
255
- '2h': 120,
256
- '3h': 180,
257
- '4h': 240,
258
- '1d': 1440,
259
- '1w': 10080,
260
- '1M': 43200,
261
- },
262
- 'fees': {
263
- 'trading': {
264
- 'tierBased': true,
265
- 'percentage': true,
266
- 'taker': this.parseNumber('0.0040'),
267
- 'maker': this.parseNumber('0.0035'),
268
- 'tiers': {
269
- 'taker': [
270
- [this.parseNumber('0'), this.parseNumber('0.0020')],
271
- [this.parseNumber('10'), this.parseNumber('0.18')],
272
- [this.parseNumber('50'), this.parseNumber('0.0016')],
273
- [this.parseNumber('250'), this.parseNumber('0.0014')],
274
- [this.parseNumber('1000'), this.parseNumber('0.0012')],
275
- [this.parseNumber('5000'), this.parseNumber('0.0010')],
276
- [this.parseNumber('25000'), this.parseNumber('0.0008')],
277
- [this.parseNumber('50000'), this.parseNumber('0.0006')],
278
- ],
279
- 'maker': [
280
- [this.parseNumber('0'), this.parseNumber('0.001')],
281
- [this.parseNumber('10'), this.parseNumber('0.0009')],
282
- [this.parseNumber('50'), this.parseNumber('0.0008')],
283
- [this.parseNumber('250'), this.parseNumber('0.0007')],
284
- [this.parseNumber('1000'), this.parseNumber('0.0006')],
285
- [this.parseNumber('5000'), this.parseNumber('0.0005')],
286
- [this.parseNumber('25000'), this.parseNumber('0.0004')],
287
- [this.parseNumber('50000'), this.parseNumber('0.0003')],
288
- ],
289
- },
290
- },
291
- },
292
- 'precisionMode': number.TICK_SIZE,
293
- 'exceptions': {
294
- 'exact': {
295
- // general errors
296
- '30000': errors.ExchangeError,
297
- '30001': errors.AuthenticationError,
298
- '30002': errors.AuthenticationError,
299
- '30003': errors.AccountSuspended,
300
- '30004': errors.AuthenticationError,
301
- '30005': errors.AuthenticationError,
302
- '30006': errors.AuthenticationError,
303
- '30007': errors.AuthenticationError,
304
- '30008': errors.AuthenticationError,
305
- '30010': errors.PermissionDenied,
306
- '30011': errors.AuthenticationError,
307
- '30012': errors.AuthenticationError,
308
- '30013': errors.RateLimitExceeded,
309
- '30014': errors.ExchangeNotAvailable,
310
- '30016': errors.OnMaintenance,
311
- '30017': errors.RateLimitExceeded,
312
- '30018': errors.BadRequest,
313
- '30019': errors.PermissionDenied,
314
- // funding account & sub account errors
315
- '60000': errors.BadRequest,
316
- '60001': errors.BadRequest,
317
- '60002': errors.BadRequest,
318
- '60003': errors.ExchangeError,
319
- '60004': errors.ExchangeError,
320
- '60005': errors.ExchangeError,
321
- '60006': errors.ExchangeError,
322
- '60007': errors.InvalidAddress,
323
- '60008': errors.InsufficientFunds,
324
- '60009': errors.ExchangeError,
325
- '60010': errors.ExchangeError,
326
- '60011': errors.InvalidAddress,
327
- '60012': errors.ExchangeError,
328
- '60020': errors.PermissionDenied,
329
- '60021': errors.PermissionDenied,
330
- '60022': errors.PermissionDenied,
331
- '60026': errors.PermissionDenied,
332
- '60027': errors.PermissionDenied,
333
- '60028': errors.AccountSuspended,
334
- '60029': errors.AccountSuspended,
335
- '60030': errors.BadRequest,
336
- '60031': errors.BadRequest,
337
- '60050': errors.ExchangeError,
338
- '60051': errors.ExchangeError,
339
- '61001': errors.InsufficientFunds,
340
- '61003': errors.BadRequest,
341
- '61004': errors.BadRequest,
342
- '61005': errors.BadRequest,
343
- '61006': errors.NotSupported,
344
- '61007': errors.ExchangeError,
345
- '61008': errors.ExchangeError,
346
- // spot public errors
347
- '70000': errors.ExchangeError,
348
- '70001': errors.BadRequest,
349
- '70002': errors.BadSymbol,
350
- '71001': errors.BadRequest,
351
- '71002': errors.BadRequest,
352
- '71003': errors.BadRequest,
353
- '71004': errors.BadRequest,
354
- '71005': errors.BadRequest,
355
- // spot & margin errors
356
- '50000': errors.BadRequest,
357
- '50001': errors.BadSymbol,
358
- '50002': errors.BadRequest,
359
- '50003': errors.BadRequest,
360
- '50004': errors.BadRequest,
361
- '50005': errors.OrderNotFound,
362
- '50006': errors.InvalidOrder,
363
- '50007': errors.InvalidOrder,
364
- '50008': errors.InvalidOrder,
365
- '50009': errors.InvalidOrder,
366
- '50010': errors.InvalidOrder,
367
- '50011': errors.InvalidOrder,
368
- '50012': errors.InvalidOrder,
369
- '50013': errors.InvalidOrder,
370
- '50014': errors.BadRequest,
371
- '50015': errors.BadRequest,
372
- '50016': errors.BadRequest,
373
- '50017': errors.BadRequest,
374
- '50018': errors.BadRequest,
375
- '50019': errors.ExchangeError,
376
- '50020': errors.InsufficientFunds,
377
- '50021': errors.BadRequest,
378
- '50022': errors.ExchangeNotAvailable,
379
- '50023': errors.BadSymbol,
380
- '50024': errors.BadRequest,
381
- '50025': errors.BadRequest,
382
- '50026': errors.BadRequest,
383
- '50027': errors.BadRequest,
384
- '50028': errors.BadRequest,
385
- '50029': errors.InvalidOrder,
386
- '50030': errors.OrderNotFound,
387
- '50031': errors.OrderNotFound,
388
- '50032': errors.OrderNotFound,
389
- '50033': errors.InvalidOrder,
390
- // below Error codes used interchangeably for both failed postOnly and IOC orders depending on market price and order side
391
- '50034': errors.InvalidOrder,
392
- '50035': errors.InvalidOrder,
393
- '50036': errors.ExchangeError,
394
- '50037': errors.BadRequest,
395
- '50038': errors.BadRequest,
396
- '50039': errors.BadRequest,
397
- '50040': errors.BadSymbol,
398
- '50041': errors.ExchangeError,
399
- '50042': errors.BadRequest,
400
- '51000': errors.BadSymbol,
401
- '51001': errors.ExchangeError,
402
- '51002': errors.ExchangeError,
403
- '51003': errors.ExchangeError,
404
- '51004': errors.InsufficientFunds,
405
- '51005': errors.InvalidOrder,
406
- '51006': errors.InvalidOrder,
407
- '51007': errors.BadRequest,
408
- '51008': errors.ExchangeError,
409
- '51009': errors.InvalidOrder,
410
- '51010': errors.InvalidOrder,
411
- '51011': errors.InvalidOrder,
412
- '51012': errors.InvalidOrder,
413
- '51013': errors.InvalidOrder,
414
- '51014': errors.InvalidOrder,
415
- '51015': errors.InvalidOrder,
416
- '52000': errors.BadRequest,
417
- '52001': errors.BadRequest,
418
- '52002': errors.BadRequest,
419
- '52003': errors.BadRequest,
420
- '52004': errors.BadRequest,
421
- '53000': errors.AccountSuspended,
422
- '53001': errors.AccountSuspended,
423
- '53002': errors.PermissionDenied,
424
- '53003': errors.PermissionDenied,
425
- '53005': errors.PermissionDenied,
426
- '53006': errors.PermissionDenied,
427
- '53007': errors.PermissionDenied,
428
- '53008': errors.PermissionDenied,
429
- '53009': errors.PermissionDenied,
430
- '53010': errors.PermissionDenied,
431
- '57001': errors.BadRequest,
432
- '58001': errors.BadRequest,
433
- '59001': errors.ExchangeError,
434
- '59002': errors.ExchangeError,
435
- '59003': errors.ExchangeError,
436
- '59004': errors.ExchangeError,
437
- '59005': errors.PermissionDenied,
438
- '59006': errors.ExchangeError,
439
- '59007': errors.ExchangeError,
440
- '59008': errors.ExchangeError,
441
- '59009': errors.ExchangeError,
442
- '59010': errors.InsufficientFunds,
443
- '59011': errors.ExchangeError,
444
- // contract errors
445
- '40001': errors.ExchangeError,
446
- '40002': errors.ExchangeError,
447
- '40003': errors.ExchangeError,
448
- '40004': errors.ExchangeError,
449
- '40005': errors.ExchangeError,
450
- '40006': errors.PermissionDenied,
451
- '40007': errors.BadRequest,
452
- '40008': errors.InvalidNonce,
453
- '40009': errors.BadRequest,
454
- '40010': errors.BadRequest,
455
- '40011': errors.BadRequest,
456
- '40012': errors.ExchangeError,
457
- '40013': errors.ExchangeError,
458
- '40014': errors.BadSymbol,
459
- '40015': errors.BadSymbol,
460
- '40016': errors.InvalidOrder,
461
- '40017': errors.InvalidOrder,
462
- '40018': errors.InvalidOrder,
463
- '40019': errors.ExchangeError,
464
- '40020': errors.InvalidOrder,
465
- '40021': errors.ExchangeError,
466
- '40022': errors.ExchangeError,
467
- '40023': errors.ExchangeError,
468
- '40024': errors.ExchangeError,
469
- '40025': errors.ExchangeError,
470
- '40026': errors.ExchangeError,
471
- '40027': errors.InsufficientFunds,
472
- '40028': errors.PermissionDenied,
473
- '40029': errors.InvalidOrder,
474
- '40030': errors.InvalidOrder,
475
- '40031': errors.InvalidOrder,
476
- '40032': errors.InvalidOrder,
477
- '40033': errors.InvalidOrder,
478
- '40034': errors.BadSymbol,
479
- '40035': errors.OrderNotFound,
480
- '40036': errors.InvalidOrder,
481
- '40037': errors.OrderNotFound,
482
- '40038': errors.BadRequest,
483
- '40039': errors.BadRequest,
484
- '40040': errors.InvalidOrder,
485
- '40041': errors.InvalidOrder,
486
- '40042': errors.InvalidOrder,
487
- '40043': errors.InvalidOrder,
488
- '40044': errors.InvalidOrder,
489
- '40045': errors.InvalidOrder,
490
- '40046': errors.PermissionDenied,
491
- '40047': errors.PermissionDenied,
492
- '40048': errors.BadRequest,
493
- '40049': errors.BadRequest,
494
- '40050': errors.InvalidOrder, // 403, Client OrderId duplicated with existing orders
495
- },
496
- 'broad': {},
497
- },
498
- 'commonCurrencies': {
499
- '$GM': 'GOLDMINER',
500
- '$HERO': 'Step Hero',
501
- '$PAC': 'PAC',
502
- 'BP': 'BEYOND',
503
- 'GDT': 'Gorilla Diamond',
504
- 'GLD': 'Goldario',
505
- 'MVP': 'MVP Coin',
506
- 'TRU': 'Truebit', // conflict with TrueFi
507
- },
508
- 'options': {
509
- 'defaultNetwork': 'ERC20',
510
- 'defaultNetworks': {
511
- 'USDT': 'ERC20',
512
- },
513
- 'networks': {
514
- 'ERC20': 'ERC20',
515
- 'BTC': 'BTC',
516
- 'TRC20': 'TRC20',
517
- // todo: should be TRX after unification
518
- // 'TRC20': [ 'TRC20', 'trc20', 'TRON' ], // todo: after unification i.e. TRON is returned from fetchDepositAddress
519
- // 'ERC20': [ 'ERC20', 'ERC-20', 'ERC20 ' ], // todo: after unification
520
- 'OMNI': 'OMNI',
521
- 'XLM': 'XLM',
522
- 'EOS': 'EOS',
523
- 'NEO': 'NEO',
524
- 'BTM': 'BTM',
525
- 'BCH': 'BCH',
526
- 'LTC': 'LTC',
527
- 'BSV': 'BSV',
528
- 'XRP': 'XRP',
529
- // 'VECHAIN': [ 'VET', 'Vechain' ], // todo: after unification
530
- 'PLEX': 'PLEX',
531
- 'XCH': 'XCH',
532
- // 'AVALANCHE_C': [ 'AVAX', 'AVAX-C' ], // todo: after unification
533
- 'NEAR': 'NEAR',
534
- 'FIO': 'FIO',
535
- 'SCRT': 'SCRT',
536
- 'IOTX': 'IOTX',
537
- 'SOL': 'SOL',
538
- 'ALGO': 'ALGO',
539
- 'ATOM': 'ATOM',
540
- 'DOT': 'DOT',
541
- 'ADA': 'ADA',
542
- 'DOGE': 'DOGE',
543
- 'XYM': 'XYM',
544
- 'GLMR': 'GLMR',
545
- 'MOVR': 'MOVR',
546
- 'ZIL': 'ZIL',
547
- 'INJ': 'INJ',
548
- 'KSM': 'KSM',
549
- 'ZEC': 'ZEC',
550
- 'NAS': 'NAS',
551
- // 'POLYGON': [ 'MATIC', 'Polygon', 'POLYGON' ], // todo: after unification
552
- 'HRC20': 'HECO',
553
- 'XDC': 'XDC',
554
- 'ONE': 'ONE',
555
- 'LAT': 'LAT',
556
- 'CSPR': 'Casper',
557
- 'ICP': 'Computer',
558
- 'XTZ': 'XTZ',
559
- 'MINA': 'MINA',
560
- // 'BEP20': [ 'BEP20', 'BSC_BNB', 'bep20' ], // todo: after unification
561
- 'THETA': 'THETA',
562
- 'AKT': 'AKT',
563
- 'AR': 'AR',
564
- 'CELO': 'CELO',
565
- 'FIL': 'FIL',
566
- 'NULS': 'NULS',
567
- 'ETC': 'ETC',
568
- 'DASH': 'DASH',
569
- 'DGB': 'DGB',
570
- 'BEP2': 'BEP2',
571
- 'GRIN': 'GRIN',
572
- 'WAVES': 'WAVES',
573
- 'ABBC': 'ABBC',
574
- 'ACA': 'ACA',
575
- 'QTUM': 'QTUM',
576
- 'PAC': 'PAC',
577
- // 'TERRACLASSIC': 'LUNC', // TBD
578
- // 'TERRA': 'Terra', // TBD
579
- // 'HEDERA': [ 'HBAR', 'Hedera', 'Hedera Mainnet' ], // todo: after unification
580
- 'TLOS': 'TLOS',
581
- 'KARDIA': 'KardiaChain',
582
- 'FUSE': 'FUSE',
583
- 'TRC10': 'TRC10',
584
- 'FIRO': 'FIRO',
585
- 'FTM': 'Fantom',
586
- // 'KLAYTN': [ 'klaytn', 'KLAY', 'Klaytn' ], // todo: after unification
587
- // 'ELROND': [ 'EGLD', 'Elrond eGold', 'MultiversX' ], // todo: after unification
588
- 'EVER': 'EVER',
589
- 'KAVA': 'KAVA',
590
- 'HYDRA': 'HYDRA',
591
- 'PLCU': 'PLCU',
592
- 'BRISE': 'BRISE',
593
- // 'CRC20': [ 'CRO', 'CRO_Chain' ], // todo: after unification
594
- // 'CONFLUX': [ 'CFX eSpace', 'CFX' ], // todo: after unification
595
- 'OPTIMISM': 'OPTIMISM',
596
- 'REEF': 'REEF',
597
- 'SYS': 'SYS',
598
- 'VITE': 'VITE',
599
- 'STX': 'STX',
600
- 'SXP': 'SXP',
601
- 'BITCI': 'BITCI',
602
- // 'ARBITRUM': [ 'ARBI', 'Arbitrum' ], // todo: after unification
603
- 'XRD': 'XRD',
604
- 'ASTR': 'ASTAR',
605
- 'ZEN': 'HORIZEN',
606
- 'LTO': 'LTO',
607
- 'ETHW': 'ETHW',
608
- 'ETHF': 'ETHF',
609
- 'IOST': 'IOST',
610
- // 'CHILIZ': [ 'CHZ', 'CHILIZ' ], // todo: after unification
611
- 'APT': 'APT',
612
- // 'FLOW': [ 'FLOW', 'Flow' ], // todo: after unification
613
- 'ONT': 'ONT',
614
- 'EVMOS': 'EVMOS',
615
- 'XMR': 'XMR',
616
- 'OASYS': 'OAS',
617
- 'OSMO': 'OSMO',
618
- 'OMAX': 'OMAX Chain',
619
- 'DESO': 'DESO',
620
- 'BFIC': 'BFIC',
621
- 'OHO': 'OHO',
622
- 'CS': 'CS',
623
- 'CHEQ': 'CHEQ',
624
- 'NODL': 'NODL',
625
- 'NEM': 'XEM',
626
- 'FRA': 'FRA',
627
- 'ERGO': 'ERG',
628
- // todo: below will be uncommented after unification
629
- // 'BITCOINHD': 'BHD',
630
- // 'CRUST': 'CRU',
631
- // 'MINTME': 'MINTME',
632
- // 'ZENITH': 'ZENITH',
633
- // 'ZENIQ': 'ZENIQ', // "ZEN-20" is different
634
- // 'BITCOINVAULT': 'BTCV',
635
- // 'MOBILECOIN': 'MBX',
636
- // 'PINETWORK': 'PI',
637
- // 'PI': 'PI',
638
- // 'REBUS': 'REBUS',
639
- // 'XODEX': 'XODEX',
640
- // 'ULTRONGLOW': 'UTG'
641
- // 'QIBLOCKCHAIN': 'QIE',
642
- // 'XIDEN': 'XDEN',
643
- // 'PHAETON': 'PHAE',
644
- // 'REDLIGHT': 'REDLC',
645
- // 'VERITISE': 'VTS',
646
- // 'VERIBLOCK': 'VBK',
647
- // 'RAMESTTA': 'RAMA',
648
- // 'BITICA': 'BDCC',
649
- // 'CROWNSOVEREIGN': 'CSOV',
650
- // 'DRAC': 'DRC20',
651
- // 'QCHAIN': 'QDT',
652
- // 'KINGARU': 'KRU',
653
- // 'PROOFOFMEMES': 'POM',
654
- // 'CUBE': 'CUBE',
655
- // 'CADUCEUS': 'CMP',
656
- // 'VEIL': 'VEIL',
657
- // 'ENERGYWEB': 'EWT',
658
- // 'CYPHERIUM': 'CPH',
659
- // 'LBRY': 'LBC',
660
- // 'ETHERCOIN': 'ETE',
661
- // undetermined chains:
662
- // LEX (for LexThum), TAYCAN (for TRICE), SFL (probably TAYCAN), OMNIA (for APEX), NAC (for NAC), KAG (Kinesis), CEM (crypto emergency), XVM (for Venidium), NEVM (for NEVM), IGT20 (for IGNITE), FILM (FILMCredits), CC (CloudCoin), MERGE (MERGE), LTNM (Bitcoin latinum), PLUGCN ( PlugChain), DINGO (dingo), LED (LEDGIS), AVAT (AVAT), VSOL (Vsolidus), EPIC (EPIC cash), NFC (netflowcoin), mrx (Metrix Coin), Idena (idena network), PKT (PKT Cash), BondDex (BondDex), XBN (XBN), KALAM (Kalamint), REV (RChain), KRC20 (MyDeFiPet), ARC20 (Hurricane Token), GMD (Coop network), BERS (Berith), ZEBI (Zebi), BRC (Baer Chain), DAPS (DAPS Coin), APL (Gold Secured Currency), NDAU (NDAU), WICC (WICC), UPG (Unipay God), TSL (TreasureSL), MXW (Maxonrow), CLC (Cifculation), SMH (SMH Coin), XIN (CPCoin), RDD (ReddCoin), OK (Okcash), KAR (KAR), CCX (ConcealNetwork),
663
- },
664
- 'defaultType': 'spot',
665
- 'fetchBalance': {
666
- 'type': 'spot', // 'spot', 'swap', 'account'
667
- },
668
- 'accountsByType': {
669
- 'spot': 'spot',
670
- 'swap': 'swap',
671
- },
672
- 'createMarketBuyOrderRequiresPrice': true,
673
- 'brokerId': 'CCXTxBitmart000',
674
- },
675
- });
676
- }
677
- async fetchTime(params = {}) {
678
- /**
679
- * @method
680
- * @name bitmart#fetchTime
681
- * @description fetches the current integer timestamp in milliseconds from the exchange server
682
- * @param {object} [params] extra parameters specific to the exchange API endpoint
683
- * @returns {int} the current integer timestamp in milliseconds from the exchange server
684
- */
685
- const response = await this.publicGetSystemTime(params);
686
- //
687
- // {
688
- // "message":"OK",
689
- // "code":1000,
690
- // "trace":"c4e5e5b7-fe9f-4191-89f7-53f6c5bf9030",
691
- // "data":{
692
- // "server_time":1599843709578
693
- // }
694
- // }
695
- //
696
- const data = this.safeValue(response, 'data', {});
697
- return this.safeInteger(data, 'server_time');
698
- }
699
- async fetchStatus(params = {}) {
700
- /**
701
- * @method
702
- * @name bitmart#fetchStatus
703
- * @description the latest known information on the availability of the exchange API
704
- * @param {object} [params] extra parameters specific to the exchange API endpoint
705
- * @returns {object} a [status structure]{@link https://docs.ccxt.com/#/?id=exchange-status-structure}
706
- */
707
- const options = this.safeValue(this.options, 'fetchStatus', {});
708
- const defaultType = this.safeString(this.options, 'defaultType');
709
- let type = this.safeString(options, 'type', defaultType);
710
- type = this.safeString(params, 'type', type);
711
- params = this.omit(params, 'type');
712
- const response = await this.publicGetSystemService(params);
713
- //
714
- // {
715
- // "message": "OK",
716
- // "code": 1000,
717
- // "trace": "1d3f28b0-763e-4f78-90c4-5e3ad19dc595",
718
- // "data": {
719
- // "service": [
720
- // {
721
- // "title": "Spot API Stop",
722
- // "service_type": "spot",
723
- // "status": 2,
724
- // "start_time": 1648639069125,
725
- // "end_time": 1648639069125
726
- // },
727
- // {
728
- // "title": "Contract API Stop",
729
- // "service_type": "contract",
730
- // "status": 2,
731
- // "start_time": 1648639069125,
732
- // "end_time": 1648639069125
733
- // }
734
- // ]
735
- // }
736
- // }
737
- //
738
- const data = this.safeValue(response, 'data', {});
739
- const services = this.safeValue(data, 'service', []);
740
- const servicesByType = this.indexBy(services, 'service_type');
741
- if (type === 'swap') {
742
- type = 'contract';
743
- }
744
- const service = this.safeValue(servicesByType, type);
745
- let status = undefined;
746
- let eta = undefined;
747
- if (service !== undefined) {
748
- const statusCode = this.safeInteger(service, 'status');
749
- if (statusCode === 2) {
750
- status = 'ok';
751
- }
752
- else {
753
- status = 'maintenance';
754
- eta = this.safeInteger(service, 'end_time');
755
- }
756
- }
757
- return {
758
- 'status': status,
759
- 'updated': undefined,
760
- 'eta': eta,
761
- 'url': undefined,
762
- 'info': response,
763
- };
764
- }
765
- async fetchSpotMarkets(params = {}) {
766
- const response = await this.publicGetSpotV1SymbolsDetails(params);
767
- //
768
- // {
769
- // "message":"OK",
770
- // "code":1000,
771
- // "trace":"a67c9146-086d-4d3f-9897-5636a9bb26e1",
772
- // "data":{
773
- // "symbols":[
774
- // {
775
- // "symbol": "BTC_USDT",
776
- // "symbol_id": 53,
777
- // "base_currency": "BTC",
778
- // "quote_currency": "USDT",
779
- // "base_min_size": "0.000010000000000000000000000000",
780
- // "base_max_size": "100000000.000000000000000000000000000000",
781
- // "price_min_precision": -1,
782
- // "price_max_precision": 2,
783
- // "quote_increment": "0.00001", // Api docs says "The minimum order quantity is also the minimum order quantity increment", however I think they mistakenly use the term 'order quantity'
784
- // "expiration": "NA",
785
- // "min_buy_amount": "5.000000000000000000000000000000",
786
- // "min_sell_amount": "5.000000000000000000000000000000",
787
- // "trade_status": "trading"
788
- // },
789
- // ]
790
- // }
791
- // }
792
- //
793
- const data = this.safeValue(response, 'data', {});
794
- const symbols = this.safeValue(data, 'symbols', []);
795
- const result = [];
796
- for (let i = 0; i < symbols.length; i++) {
797
- const market = symbols[i];
798
- const id = this.safeString(market, 'symbol');
799
- const numericId = this.safeInteger(market, 'symbol_id');
800
- const baseId = this.safeString(market, 'base_currency');
801
- const quoteId = this.safeString(market, 'quote_currency');
802
- const base = this.safeCurrencyCode(baseId);
803
- const quote = this.safeCurrencyCode(quoteId);
804
- const symbol = base + '/' + quote;
805
- const minBuyCost = this.safeString(market, 'min_buy_amount');
806
- const minSellCost = this.safeString(market, 'min_sell_amount');
807
- const minCost = Precise["default"].stringMax(minBuyCost, minSellCost);
808
- const baseMinSize = this.safeNumber(market, 'base_min_size');
809
- result.push({
810
- 'id': id,
811
- 'numericId': numericId,
812
- 'symbol': symbol,
813
- 'base': base,
814
- 'quote': quote,
815
- 'settle': undefined,
816
- 'baseId': baseId,
817
- 'quoteId': quoteId,
818
- 'settleId': undefined,
819
- 'type': 'spot',
820
- 'spot': true,
821
- 'margin': false,
822
- 'swap': false,
823
- 'future': false,
824
- 'option': false,
825
- 'active': true,
826
- 'contract': false,
827
- 'linear': undefined,
828
- 'inverse': undefined,
829
- 'contractSize': undefined,
830
- 'expiry': undefined,
831
- 'expiryDatetime': undefined,
832
- 'strike': undefined,
833
- 'optionType': undefined,
834
- 'precision': {
835
- 'amount': baseMinSize,
836
- 'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'price_max_precision'))),
837
- },
838
- 'limits': {
839
- 'leverage': {
840
- 'min': undefined,
841
- 'max': undefined,
842
- },
843
- 'amount': {
844
- 'min': baseMinSize,
845
- 'max': this.safeNumber(market, 'base_max_size'),
846
- },
847
- 'price': {
848
- 'min': undefined,
849
- 'max': undefined,
850
- },
851
- 'cost': {
852
- 'min': this.parseNumber(minCost),
853
- 'max': undefined,
854
- },
855
- },
856
- 'created': undefined,
857
- 'info': market,
858
- });
859
- }
860
- return result;
861
- }
862
- async fetchContractMarkets(params = {}) {
863
- const response = await this.publicGetContractPublicDetails(params);
864
- //
865
- // {
866
- // "code": 1000,
867
- // "message": "Ok",
868
- // "trace": "9b92a999-9463-4c96-91a4-93ad1cad0d72",
869
- // "data": {
870
- // "symbols": [{
871
- // "symbol": "BTCUSDT",
872
- // "product_type": 1,
873
- // "open_timestamp": 1594080000,
874
- // "expire_timestamp": 0,
875
- // "settle_timestamp": 0,
876
- // "base_currency": "BTC",
877
- // "quote_currency": "USDT",
878
- // "last_price": "23920",
879
- // "volume_24h": "18969368",
880
- // "turnover_24h": "458933659.7858",
881
- // "index_price": "23945.25191635",
882
- // "index_name": "BTCUSDT",
883
- // "contract_size": "0.001",
884
- // "min_leverage": "1",
885
- // "max_leverage": "100",
886
- // "price_precision": "0.1",
887
- // "vol_precision": "1",
888
- // "max_volume": "500000",
889
- // "min_volume": "1"
890
- // },
891
- // ...
892
- // ]
893
- // }
894
- // }
895
- //
896
- const data = this.safeValue(response, 'data', {});
897
- const symbols = this.safeValue(data, 'symbols', []);
898
- const result = [];
899
- for (let i = 0; i < symbols.length; i++) {
900
- const market = symbols[i];
901
- const id = this.safeString(market, 'symbol');
902
- const baseId = this.safeString(market, 'base_currency');
903
- const quoteId = this.safeString(market, 'quote_currency');
904
- const base = this.safeCurrencyCode(baseId);
905
- const quote = this.safeCurrencyCode(quoteId);
906
- const settleId = 'USDT'; // this is bitmart's ID for usdt
907
- const settle = this.safeCurrencyCode(settleId);
908
- const symbol = base + '/' + quote + ':' + settle;
909
- const productType = this.safeInteger(market, 'product_type');
910
- const isSwap = (productType === 1);
911
- const isFutures = (productType === 2);
912
- let expiry = this.safeInteger(market, 'expire_timestamp');
913
- if (!isFutures && (expiry === 0)) {
914
- expiry = undefined;
915
- }
916
- result.push({
917
- 'id': id,
918
- 'numericId': undefined,
919
- 'symbol': symbol,
920
- 'base': base,
921
- 'quote': quote,
922
- 'settle': settle,
923
- 'baseId': baseId,
924
- 'quoteId': quoteId,
925
- 'settleId': settleId,
926
- 'type': isSwap ? 'swap' : 'future',
927
- 'spot': false,
928
- 'margin': false,
929
- 'swap': isSwap,
930
- 'future': isFutures,
931
- 'option': false,
932
- 'active': true,
933
- 'contract': true,
934
- 'linear': true,
935
- 'inverse': false,
936
- 'contractSize': this.safeNumber(market, 'contract_size'),
937
- 'expiry': expiry,
938
- 'expiryDatetime': this.iso8601(expiry),
939
- 'strike': undefined,
940
- 'optionType': undefined,
941
- 'precision': {
942
- 'amount': this.safeNumber(market, 'vol_precision'),
943
- 'price': this.safeNumber(market, 'price_precision'),
944
- },
945
- 'limits': {
946
- 'leverage': {
947
- 'min': this.safeNumber(market, 'min_leverage'),
948
- 'max': this.safeNumber(market, 'max_leverage'),
949
- },
950
- 'amount': {
951
- 'min': this.safeNumber(market, 'min_volume'),
952
- 'max': this.safeNumber(market, 'max_volume'),
953
- },
954
- 'price': {
955
- 'min': undefined,
956
- 'max': undefined,
957
- },
958
- 'cost': {
959
- 'min': undefined,
960
- 'max': undefined,
961
- },
962
- },
963
- 'created': this.safeInteger(market, 'open_timestamp'),
964
- 'info': market,
965
- });
966
- }
967
- return result;
968
- }
969
- async fetchMarkets(params = {}) {
970
- /**
971
- * @method
972
- * @name bitmart#fetchMarkets
973
- * @description retrieves data on all markets for bitmart
974
- * @param {object} [params] extra parameters specific to the exchange API endpoint
975
- * @returns {object[]} an array of objects representing market data
976
- */
977
- const spot = await this.fetchSpotMarkets(params);
978
- const contract = await this.fetchContractMarkets(params);
979
- return this.arrayConcat(spot, contract);
980
- }
981
- async fetchCurrencies(params = {}) {
982
- /**
983
- * @method
984
- * @name bitmart#fetchCurrencies
985
- * @description fetches all available currencies on an exchange
986
- * @param {object} [params] extra parameters specific to the exchange API endpoint
987
- * @returns {object} an associative dictionary of currencies
988
- */
989
- const response = await this.publicGetSpotV1Currencies(params);
990
- //
991
- // {
992
- // "message":"OK",
993
- // "code":1000,
994
- // "trace":"8c768b3c-025f-413f-bec5-6d6411d46883",
995
- // "data":{
996
- // "currencies":[
997
- // {"currency":"MATIC","name":"Matic Network","withdraw_enabled":true,"deposit_enabled":true},
998
- // {"currency":"KTN","name":"Kasoutuuka News","withdraw_enabled":true,"deposit_enabled":false},
999
- // {"currency":"BRT","name":"Berith","withdraw_enabled":true,"deposit_enabled":true},
1000
- // ]
1001
- // }
1002
- // }
1003
- //
1004
- const data = this.safeValue(response, 'data', {});
1005
- const currencies = this.safeValue(data, 'currencies', []);
1006
- const result = {};
1007
- for (let i = 0; i < currencies.length; i++) {
1008
- const currency = currencies[i];
1009
- const id = this.safeString(currency, 'id');
1010
- const code = this.safeCurrencyCode(id);
1011
- const name = this.safeString(currency, 'name');
1012
- const withdrawEnabled = this.safeValue(currency, 'withdraw_enabled');
1013
- const depositEnabled = this.safeValue(currency, 'deposit_enabled');
1014
- const active = withdrawEnabled && depositEnabled;
1015
- result[code] = {
1016
- 'id': id,
1017
- 'code': code,
1018
- 'name': name,
1019
- 'info': currency,
1020
- 'active': active,
1021
- 'deposit': depositEnabled,
1022
- 'withdraw': withdrawEnabled,
1023
- 'fee': undefined,
1024
- 'precision': undefined,
1025
- 'limits': {
1026
- 'amount': { 'min': undefined, 'max': undefined },
1027
- 'withdraw': { 'min': undefined, 'max': undefined },
1028
- },
1029
- };
1030
- }
1031
- return result;
1032
- }
1033
- async fetchTransactionFee(code, params = {}) {
1034
- /**
1035
- * @method
1036
- * @name bitmart#fetchTransactionFee
1037
- * @deprecated
1038
- * @description please use fetchDepositWithdrawFee instead
1039
- * @param {string} code unified currency code
1040
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1041
- * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
1042
- */
1043
- await this.loadMarkets();
1044
- const currency = this.currency(code);
1045
- const request = {
1046
- 'currency': currency['id'],
1047
- };
1048
- const response = await this.privateGetAccountV1WithdrawCharge(this.extend(request, params));
1049
- //
1050
- // {
1051
- // "message": "OK",
1052
- // "code": "1000",
1053
- // "trace": "3ecc0adf-91bd-4de7-aca1-886c1122f54f",
1054
- // "data": {
1055
- // "today_available_withdraw_BTC": "100.0000",
1056
- // "min_withdraw": "0.005",
1057
- // "withdraw_precision": "8",
1058
- // "withdraw_fee": "0.000500000000000000000000000000"
1059
- // }
1060
- // }
1061
- //
1062
- const data = response['data'];
1063
- const withdrawFees = {};
1064
- withdrawFees[code] = this.safeNumber(data, 'withdraw_fee');
1065
- return {
1066
- 'info': response,
1067
- 'withdraw': withdrawFees,
1068
- 'deposit': {},
1069
- };
1070
- }
1071
- parseDepositWithdrawFee(fee, currency = undefined) {
1072
- //
1073
- // {
1074
- // "today_available_withdraw_BTC": "100.0000",
1075
- // "min_withdraw": "0.005",
1076
- // "withdraw_precision": "8",
1077
- // "withdraw_fee": "0.000500000000000000000000000000"
1078
- // }
1079
- //
1080
- return {
1081
- 'info': fee,
1082
- 'withdraw': {
1083
- 'fee': this.safeNumber(fee, 'withdraw_fee'),
1084
- 'percentage': undefined,
1085
- },
1086
- 'deposit': {
1087
- 'fee': undefined,
1088
- 'percentage': undefined,
1089
- },
1090
- 'networks': {},
1091
- };
1092
- }
1093
- async fetchDepositWithdrawFee(code, params = {}) {
1094
- /**
1095
- * @method
1096
- * @name bitmart#fetchDepositWithdrawFee
1097
- * @description fetch the fee for deposits and withdrawals
1098
- * @param {string} code unified currency code
1099
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1100
- * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
1101
- */
1102
- await this.loadMarkets();
1103
- const currency = this.currency(code);
1104
- const request = {
1105
- 'currency': currency['id'],
1106
- };
1107
- const response = await this.privateGetAccountV1WithdrawCharge(this.extend(request, params));
1108
- //
1109
- // {
1110
- // "message": "OK",
1111
- // "code": "1000",
1112
- // "trace": "3ecc0adf-91bd-4de7-aca1-886c1122f54f",
1113
- // "data": {
1114
- // "today_available_withdraw_BTC": "100.0000",
1115
- // "min_withdraw": "0.005",
1116
- // "withdraw_precision": "8",
1117
- // "withdraw_fee": "0.000500000000000000000000000000"
1118
- // }
1119
- // }
1120
- //
1121
- const data = response['data'];
1122
- return this.parseDepositWithdrawFee(data);
1123
- }
1124
- parseTicker(ticker, market = undefined) {
1125
- //
1126
- // spot
1127
- //
1128
- // {
1129
- // "symbol": "SOLAR_USDT",
1130
- // "last_price": "0.020342",
1131
- // "quote_volume_24h": "56817.811802",
1132
- // "base_volume_24h": "2172060",
1133
- // "high_24h": "0.256000",
1134
- // "low_24h": "0.016980",
1135
- // "open_24h": "0.022309",
1136
- // "close_24h": "0.020342",
1137
- // "best_ask": "0.020389",
1138
- // "best_ask_size": "339.000000000000000000000000000000",
1139
- // "best_bid": "0.020342",
1140
- // "best_bid_size": "3369.000000000000000000000000000000",
1141
- // "fluctuation": "-0.0882",
1142
- // "url": "https://www.bitmart.com/trade?symbol=SOLAR_USDT",
1143
- // "timestamp": 1667403439367
1144
- // }
1145
- //
1146
- // swap
1147
- //
1148
- // {
1149
- // "contract_symbol":"DOGEUSDT",
1150
- // "last_price":"0.130340",
1151
- // "index_price":"0.13048245",
1152
- // "last_funding_rate":"0.00002287",
1153
- // "price_change_percent_24h":"-2.074",
1154
- // "volume_24h":"113705028.59482228",
1155
- // "url":"https://futures.bitmart.com/en?symbol=DOGEUSDT",
1156
- // "high_price":"0.134520",
1157
- // "low_price":"0.128570",
1158
- // "legal_coin_price":"0.1302699"
1159
- // }
1160
- //
1161
- const timestamp = this.safeInteger(ticker, 'timestamp');
1162
- const marketId = this.safeString2(ticker, 'symbol', 'contract_symbol');
1163
- market = this.safeMarket(marketId, market);
1164
- const symbol = market['symbol'];
1165
- const last = this.safeString2(ticker, 'close_24h', 'last_price');
1166
- let percentage = this.safeString(ticker, 'price_change_percent_24h');
1167
- if (percentage === undefined) {
1168
- const percentageRaw = this.safeString(ticker, 'fluctuation');
1169
- if ((percentageRaw !== undefined) && (percentageRaw !== '0')) { // a few tickers show strictly '0' in fluctuation field
1170
- const direction = percentageRaw[0];
1171
- percentage = direction + Precise["default"].stringMul(percentageRaw.replace(direction, ''), '100');
1172
- }
1173
- else if (percentageRaw === '0') {
1174
- percentage = '0';
1175
- }
1176
- }
1177
- const baseVolume = this.safeString(ticker, 'base_volume_24h');
1178
- let quoteVolume = this.safeString(ticker, 'quote_volume_24h');
1179
- quoteVolume = this.safeString(ticker, 'volume_24h', quoteVolume);
1180
- const average = this.safeString2(ticker, 'avg_price', 'index_price');
1181
- const high = this.safeString2(ticker, 'high_24h', 'high_price');
1182
- const low = this.safeString2(ticker, 'low_24h', 'low_price');
1183
- return this.safeTicker({
1184
- 'symbol': symbol,
1185
- 'timestamp': timestamp,
1186
- 'datetime': this.iso8601(timestamp),
1187
- 'high': high,
1188
- 'low': low,
1189
- 'bid': this.safeString(ticker, 'best_bid'),
1190
- 'bidVolume': this.safeString(ticker, 'best_bid_size'),
1191
- 'ask': this.safeString(ticker, 'best_ask'),
1192
- 'askVolume': this.safeString(ticker, 'best_ask_size'),
1193
- 'vwap': undefined,
1194
- 'open': this.safeString(ticker, 'open_24h'),
1195
- 'close': last,
1196
- 'last': last,
1197
- 'previousClose': undefined,
1198
- 'change': undefined,
1199
- 'percentage': percentage,
1200
- 'average': average,
1201
- 'baseVolume': baseVolume,
1202
- 'quoteVolume': quoteVolume,
1203
- 'info': ticker,
1204
- }, market);
1205
- }
1206
- async fetchTicker(symbol, params = {}) {
1207
- /**
1208
- * @method
1209
- * @name bitmart#fetchTicker
1210
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1211
- * @param {string} symbol unified symbol of the market to fetch the ticker for
1212
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1213
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1214
- */
1215
- await this.loadMarkets();
1216
- const market = this.market(symbol);
1217
- const request = {};
1218
- let response = undefined;
1219
- if (market['swap']) {
1220
- request['contract_symbol'] = market['id'];
1221
- response = await this.publicGetContractV1Tickers(this.extend(request, params));
1222
- }
1223
- else if (market['spot']) {
1224
- request['symbol'] = market['id'];
1225
- response = await this.publicGetSpotV1Ticker(this.extend(request, params));
1226
- }
1227
- else {
1228
- throw new errors.NotSupported(this.id + ' fetchTicker() does not support ' + market['type'] + ' markets, only spot and swap markets are accepted');
1229
- }
1230
- //
1231
- // spot
1232
- //
1233
- // {
1234
- // "message":"OK",
1235
- // "code":1000,
1236
- // "trace":"6aa5b923-2f57-46e3-876d-feca190e0b82",
1237
- // "data":{
1238
- // "tickers":[
1239
- // {
1240
- // "symbol":"ETH_BTC",
1241
- // "last_price":"0.036037",
1242
- // "quote_volume_24h":"4380.6660000000",
1243
- // "base_volume_24h":"159.3582006712",
1244
- // "high_24h":"0.036972",
1245
- // "low_24h":"0.035524",
1246
- // "open_24h":"0.036561",
1247
- // "close_24h":"0.036037",
1248
- // "best_ask":"0.036077",
1249
- // "best_ask_size":"9.9500",
1250
- // "best_bid":"0.035983",
1251
- // "best_bid_size":"4.2792",
1252
- // "fluctuation":"-0.0143",
1253
- // "url":"https://www.bitmart.com/trade?symbol=ETH_BTC"
1254
- // }
1255
- // ]
1256
- // }
1257
- // }
1258
- //
1259
- // swap
1260
- //
1261
- // {
1262
- // "message":"OK",
1263
- // "code":1000,
1264
- // "trace":"4a0ebceb-d3f7-45a3-8feb-f61e230e24cd",
1265
- // "data":{
1266
- // "tickers":[
1267
- // {
1268
- // "contract_symbol":"DOGEUSDT",
1269
- // "last_price":"0.130180",
1270
- // "index_price":"0.13028635",
1271
- // "last_funding_rate":"0.00002025",
1272
- // "price_change_percent_24h":"-2.326",
1273
- // "volume_24h":"116789313.01797258",
1274
- // "url":"https://futures.bitmart.com/en?symbol=DOGEUSDT",
1275
- // "high_price":"0.134520",
1276
- // "low_price":"0.128570",
1277
- // "legal_coin_price":"0.13017401"
1278
- // }
1279
- // ]
1280
- // }
1281
- // }
1282
- //
1283
- const data = this.safeValue(response, 'data', {});
1284
- const tickers = this.safeValue(data, 'tickers', []);
1285
- // fails in naming for contract tickers 'contract_symbol'
1286
- let tickersById = undefined;
1287
- if (market['spot']) {
1288
- tickersById = this.indexBy(tickers, 'symbol');
1289
- }
1290
- else if (market['swap']) {
1291
- tickersById = this.indexBy(tickers, 'contract_symbol');
1292
- }
1293
- const ticker = this.safeValue(tickersById, market['id']);
1294
- return this.parseTicker(ticker, market);
1295
- }
1296
- async fetchTickers(symbols = undefined, params = {}) {
1297
- /**
1298
- * @method
1299
- * @name bitmart#fetchTickers
1300
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1301
- * @see https://developer-pro.bitmart.com/en/spot/#get-ticker-of-all-pairs-v2
1302
- * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1303
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1304
- * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1305
- */
1306
- await this.loadMarkets();
1307
- symbols = this.marketSymbols(symbols);
1308
- let type = undefined;
1309
- let market = undefined;
1310
- if (symbols !== undefined) {
1311
- const symbol = this.safeValue(symbols, 0);
1312
- market = this.market(symbol);
1313
- }
1314
- [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
1315
- let response = undefined;
1316
- if (type === 'spot') {
1317
- response = await this.publicGetSpotV2Ticker(params);
1318
- }
1319
- else if (type === 'swap') {
1320
- response = await this.publicGetContractV1Tickers(params);
1321
- }
1322
- else {
1323
- throw new errors.NotSupported(this.id + ' fetchTickers() does not support ' + type + ' markets, only spot and swap markets are accepted');
1324
- }
1325
- const data = this.safeValue(response, 'data', {});
1326
- const tickers = this.safeValue(data, 'tickers', []);
1327
- const result = {};
1328
- for (let i = 0; i < tickers.length; i++) {
1329
- const ticker = this.parseTicker(tickers[i]);
1330
- const symbol = ticker['symbol'];
1331
- result[symbol] = ticker;
1332
- }
1333
- return this.filterByArrayTickers(result, 'symbol', symbols);
1334
- }
1335
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
1336
- /**
1337
- * @method
1338
- * @name bitmart#fetchOrderBook
1339
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1340
- * @see https://developer-pro.bitmart.com/en/spot/#get-depth-v3
1341
- * @see https://developer-pro.bitmart.com/en/futures/#get-market-depth
1342
- * @param {string} symbol unified symbol of the market to fetch the order book for
1343
- * @param {int} [limit] the maximum amount of order book entries to return
1344
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1345
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1346
- */
1347
- await this.loadMarkets();
1348
- const market = this.market(symbol);
1349
- const request = {
1350
- 'symbol': market['id'],
1351
- };
1352
- let response = undefined;
1353
- if (market['spot']) {
1354
- if (limit !== undefined) {
1355
- request['limit'] = limit; // default 35, max 50
1356
- }
1357
- response = await this.publicGetSpotQuotationV3Books(this.extend(request, params));
1358
- }
1359
- else if (market['swap']) {
1360
- response = await this.publicGetContractPublicDepth(this.extend(request, params));
1361
- }
1362
- else {
1363
- throw new errors.NotSupported(this.id + ' fetchOrderBook() does not support ' + market['type'] + ' markets, only spot and swap markets are accepted');
1364
- }
1365
- //
1366
- // spot
1367
- //
1368
- // {
1369
- // "code": 1000,
1370
- // "message": "success",
1371
- // "data": {
1372
- // "ts": "1695264191808",
1373
- // "symbol": "BTC_USDT",
1374
- // "asks": [
1375
- // ["26942.57","0.06492"],
1376
- // ["26942.73","0.05447"],
1377
- // ["26943.00","0.07154"]
1378
- // ],
1379
- // "bids": [
1380
- // ["26942.45","0.00074"],
1381
- // ["26941.53","0.00371"],
1382
- // ["26940.94","0.08992"]
1383
- // ]
1384
- // },
1385
- // "trace": "430a7f69581d4258a8e4b424dfb10782.73.16952341919017619"
1386
- // }
1387
- //
1388
- // swap
1389
- //
1390
- // {
1391
- // "code": 1000,
1392
- // "message": "Ok",
1393
- // "data": {
1394
- // "asks": [
1395
- // ["26938.3","3499","3499"],
1396
- // ["26938.5","14702","18201"],
1397
- // ["26938.6","20457","38658"]
1398
- // ],
1399
- // "bids": [
1400
- // ["26938.2","20","20"],
1401
- // ["26937.9","1913","1933"],
1402
- // ["26937.8","2588","4521"]
1403
- // ],
1404
- // "timestamp": 1695264383999,
1405
- // "symbol": "BTCUSDT"
1406
- // },
1407
- // "trace": "4cad855074664097ac6ba5258c47305d.72.16952643834721135"
1408
- // }
1409
- //
1410
- const data = this.safeValue(response, 'data', {});
1411
- const timestamp = this.safeInteger2(data, 'ts', 'timestamp');
1412
- return this.parseOrderBook(data, market['symbol'], timestamp);
1413
- }
1414
- parseTrade(trade, market = undefined) {
1415
- //
1416
- // public fetchTrades spot ( amount = count * price )
1417
- //
1418
- // {
1419
- // "amount": "818.94",
1420
- // "order_time": "1637601839035", // ETH/USDT
1421
- // "price": "4221.99",
1422
- // "count": "0.19397",
1423
- // "type": "buy"
1424
- // }
1425
- //
1426
- // spot: fetchMyTrades
1427
- //
1428
- // {
1429
- // "tradeId":"182342999769370687",
1430
- // "orderId":"183270218784142990",
1431
- // "clientOrderId":"183270218784142990",
1432
- // "symbol":"ADA_USDT",
1433
- // "side":"buy",
1434
- // "orderMode":"spot",
1435
- // "type":"market",
1436
- // "price":"0.245948",
1437
- // "size":"20.71",
1438
- // "notional":"5.09358308",
1439
- // "fee":"0.00509358",
1440
- // "feeCoinName":"USDT",
1441
- // "tradeRole":"taker",
1442
- // "createTime":1695658457836,
1443
- // }
1444
- //
1445
- // swap: fetchMyTrades
1446
- //
1447
- // {
1448
- // "order_id": "230930336848609",
1449
- // "trade_id": "6212604014",
1450
- // "symbol": "BTCUSDT",
1451
- // "side": 3,
1452
- // "price": "26910.4",
1453
- // "vol": "1",
1454
- // "exec_type": "Taker",
1455
- // "profit": false,
1456
- // "create_time": 1695961596692,
1457
- // "realised_profit": "-0.0003",
1458
- // "paid_fees": "0.01614624"
1459
- // }
1460
- //
1461
- // ws swap
1462
- //
1463
- // {
1464
- // 'fee': '-0.000044502',
1465
- // 'feeCcy': 'USDT',
1466
- // 'fillPrice': '74.17',
1467
- // 'fillQty': '1',
1468
- // 'lastTradeID': 6802340762
1469
- // }
1470
- //
1471
- const timestamp = this.safeIntegerN(trade, ['order_time', 'createTime', 'create_time']);
1472
- const isPublicTrade = ('order_time' in trade);
1473
- let amount = undefined;
1474
- let cost = undefined;
1475
- let type = undefined;
1476
- let side = undefined;
1477
- if (isPublicTrade) {
1478
- amount = this.safeString(trade, 'count');
1479
- cost = this.safeString(trade, 'amount');
1480
- side = this.safeString(trade, 'type');
1481
- }
1482
- else {
1483
- amount = this.safeStringN(trade, ['size', 'vol', 'fillQty']);
1484
- cost = this.safeString(trade, 'notional');
1485
- type = this.safeString(trade, 'type');
1486
- side = this.parseOrderSide(this.safeString(trade, 'side'));
1487
- }
1488
- const marketId = this.safeString(trade, 'symbol');
1489
- market = this.safeMarket(marketId, market);
1490
- const feeCostString = this.safeString2(trade, 'fee', 'paid_fees');
1491
- let fee = undefined;
1492
- if (feeCostString !== undefined) {
1493
- const feeCurrencyId = this.safeString(trade, 'feeCoinName');
1494
- let feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
1495
- if (feeCurrencyCode === undefined) {
1496
- feeCurrencyCode = (side === 'buy') ? market['base'] : market['quote'];
1497
- }
1498
- fee = {
1499
- 'cost': feeCostString,
1500
- 'currency': feeCurrencyCode,
1501
- };
1502
- }
1503
- return this.safeTrade({
1504
- 'info': trade,
1505
- 'id': this.safeStringN(trade, ['tradeId', 'trade_id', 'lastTradeID']),
1506
- 'order': this.safeString2(trade, 'orderId', 'order_id'),
1507
- 'timestamp': timestamp,
1508
- 'datetime': this.iso8601(timestamp),
1509
- 'symbol': market['symbol'],
1510
- 'type': type,
1511
- 'side': side,
1512
- 'price': this.safeString2(trade, 'price', 'fillPrice'),
1513
- 'amount': amount,
1514
- 'cost': cost,
1515
- 'takerOrMaker': this.safeStringLower2(trade, 'tradeRole', 'exec_type'),
1516
- 'fee': fee,
1517
- }, market);
1518
- }
1519
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
1520
- /**
1521
- * @method
1522
- * @name bitmart#fetchTrades
1523
- * @description get the list of most recent trades for a particular symbol
1524
- * @param {string} symbol unified symbol of the market to fetch trades for
1525
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
1526
- * @param {int} [limit] the maximum amount of trades to fetch
1527
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1528
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1529
- */
1530
- await this.loadMarkets();
1531
- const market = this.market(symbol);
1532
- if (!market['spot']) {
1533
- throw new errors.NotSupported(this.id + ' fetchTrades() does not support ' + market['type'] + ' orders, only spot orders are accepted');
1534
- }
1535
- const request = {
1536
- 'symbol': market['id'],
1537
- };
1538
- const response = await this.publicGetSpotV1SymbolsTrades(this.extend(request, params));
1539
- //
1540
- // spot
1541
- //
1542
- // {
1543
- // "message":"OK",
1544
- // "code":1000,
1545
- // "trace":"222d74c0-8f6d-49d9-8e1b-98118c50eeba",
1546
- // "data":{
1547
- // "trades":[
1548
- // {
1549
- // "amount":"0.005703",
1550
- // "order_time":1599652045394,
1551
- // "price":"0.034029",
1552
- // "count":"0.1676",
1553
- // "type":"sell"
1554
- // },
1555
- // ]
1556
- // }
1557
- // }
1558
- //
1559
- const data = this.safeValue(response, 'data', {});
1560
- const trades = this.safeValue(data, 'trades', []);
1561
- return this.parseTrades(trades, market, since, limit);
1562
- }
1563
- parseOHLCV(ohlcv, market = undefined) {
1564
- //
1565
- // spot
1566
- // [
1567
- // "1699512060", // timestamp
1568
- // "36746.49", // open
1569
- // "36758.71", // high
1570
- // "36736.13", // low
1571
- // "36755.99", // close
1572
- // "2.83965", // base volume
1573
- // "104353.57" // quote volume
1574
- // ]
1575
- //
1576
- // swap
1577
- // {
1578
- // "low_price": "20090.3",
1579
- // "high_price": "20095.5",
1580
- // "open_price": "20092.6",
1581
- // "close_price": "20091.4",
1582
- // "volume": "8748",
1583
- // "timestamp": 1665002281
1584
- // }
1585
- //
1586
- // ws
1587
- // [
1588
- // 1631056350, // timestamp
1589
- // "46532.83", // open
1590
- // "46555.71", // high
1591
- // "46511.41", // low
1592
- // "46555.71", // close
1593
- // "0.25", // volume
1594
- // ]
1595
- //
1596
- // ws swap
1597
- // {
1598
- // "symbol":"BTCUSDT",
1599
- // "o":"146.24",
1600
- // "h":"146.24",
1601
- // "l":"146.24",
1602
- // "c":"146.24",
1603
- // "v":"146"
1604
- // }
1605
- //
1606
- if (Array.isArray(ohlcv)) {
1607
- return [
1608
- this.safeTimestamp(ohlcv, 0),
1609
- this.safeNumber(ohlcv, 1),
1610
- this.safeNumber(ohlcv, 2),
1611
- this.safeNumber(ohlcv, 3),
1612
- this.safeNumber(ohlcv, 4),
1613
- this.safeNumber(ohlcv, 5),
1614
- ];
1615
- }
1616
- else {
1617
- return [
1618
- this.safeTimestamp2(ohlcv, 'timestamp', 'ts'),
1619
- this.safeNumber2(ohlcv, 'open_price', 'o'),
1620
- this.safeNumber2(ohlcv, 'high_price', 'h'),
1621
- this.safeNumber2(ohlcv, 'low_price', 'l'),
1622
- this.safeNumber2(ohlcv, 'close_price', 'c'),
1623
- this.safeNumber2(ohlcv, 'volume', 'v'),
1624
- ];
1625
- }
1626
- }
1627
- async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
1628
- /**
1629
- * @method
1630
- * @name bitmart#fetchOHLCV
1631
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1632
- * @see https://developer-pro.bitmart.com/en/spot/#get-history-k-line-v3
1633
- * @see https://developer-pro.bitmart.com/en/futures/#get-k-line
1634
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1635
- * @param {string} timeframe the length of time each candle represents
1636
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
1637
- * @param {int} [limit] the maximum amount of candles to fetch
1638
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1639
- * @param {int} [params.until] timestamp of the latest candle in ms
1640
- * @param {boolean} [params.paginate] *spot only* 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)
1641
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1642
- */
1643
- await this.loadMarkets();
1644
- let paginate = false;
1645
- [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
1646
- if (paginate) {
1647
- return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 200);
1648
- }
1649
- const market = this.market(symbol);
1650
- const duration = this.parseTimeframe(timeframe);
1651
- const parsedTimeframe = this.safeInteger(this.timeframes, timeframe);
1652
- let request = {
1653
- 'symbol': market['id'],
1654
- };
1655
- if (parsedTimeframe !== undefined) {
1656
- request['step'] = parsedTimeframe;
1657
- }
1658
- else {
1659
- request['step'] = timeframe;
1660
- }
1661
- if (market['spot']) {
1662
- [request, params] = this.handleUntilOption('before', request, params, 0.001);
1663
- if (limit !== undefined) {
1664
- request['limit'] = limit;
1665
- }
1666
- if (since !== undefined) {
1667
- request['after'] = this.parseToInt((since / 1000)) - 1;
1668
- }
1669
- }
1670
- else {
1671
- const maxLimit = 1200;
1672
- if (limit === undefined) {
1673
- limit = maxLimit;
1674
- }
1675
- limit = Math.min(maxLimit, limit);
1676
- const now = this.parseToInt(this.milliseconds() / 1000);
1677
- if (since === undefined) {
1678
- const start = now - limit * duration;
1679
- request['start_time'] = start;
1680
- request['end_time'] = now;
1681
- }
1682
- else {
1683
- const start = this.parseToInt((since / 1000)) - 1;
1684
- const end = this.sum(start, limit * duration);
1685
- request['start_time'] = start;
1686
- request['end_time'] = Math.min(end, now);
1687
- }
1688
- [request, params] = this.handleUntilOption('end_time', request, params, 0.001);
1689
- }
1690
- let response = undefined;
1691
- if (market['swap']) {
1692
- response = await this.publicGetContractPublicKline(this.extend(request, params));
1693
- }
1694
- else {
1695
- response = await this.publicGetSpotQuotationV3Klines(this.extend(request, params));
1696
- }
1697
- //
1698
- // spot
1699
- //
1700
- // {
1701
- // "code": 1000,
1702
- // "message": "success",
1703
- // "data": [
1704
- // ["1699512060","36746.49","36758.71","36736.13","36755.99","2.83965","104353.57"],
1705
- // ["1699512120","36756.00","36758.70","36737.14","36737.63","1.96070","72047.10"],
1706
- // ["1699512180","36737.63","36740.45","36737.62","36740.44","0.63194","23217.62"]
1707
- // ],
1708
- // "trace": "6591fc7b508845359d5fa442e3b3a4fb.72.16995122398750695"
1709
- // }
1710
- //
1711
- // swap
1712
- //
1713
- // {
1714
- // "code": 1000,
1715
- // "message": "Ok",
1716
- // "data": [
1717
- // {
1718
- // "low_price": "20090.3",
1719
- // "high_price": "20095.5",
1720
- // "open_price": "20092.6",
1721
- // "close_price": "20091.4",
1722
- // "volume": "8748",
1723
- // "timestamp": 1665002281
1724
- // },
1725
- // ...
1726
- // ],
1727
- // "trace": "96c989db-e0f5-46f5-bba6-60cfcbde699b"
1728
- // }
1729
- //
1730
- const ohlcv = this.safeValue(response, 'data', []);
1731
- return this.parseOHLCVs(ohlcv, market, timeframe, since, limit);
1732
- }
1733
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1734
- /**
1735
- * @method
1736
- * @name bitmart#fetchMyTrades
1737
- * @see https://developer-pro.bitmart.com/en/spot/#account-trade-list-v4-signed
1738
- * @see https://developer-pro.bitmart.com/en/futures/#get-order-trade-keyed
1739
- * @description fetch all trades made by the user
1740
- * @param {string} symbol unified market symbol
1741
- * @param {int} [since] the earliest time in ms to fetch trades for
1742
- * @param {int} [limit] the maximum number of trades structures to retrieve
1743
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1744
- * @param {int} [params.until] the latest time in ms to fetch trades for
1745
- * @param {boolean} [params.marginMode] *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders (only isolated margin orders are supported)
1746
- * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1747
- */
1748
- await this.loadMarkets();
1749
- let market = undefined;
1750
- const request = {};
1751
- if (symbol !== undefined) {
1752
- market = this.market(symbol);
1753
- request['symbol'] = market['id'];
1754
- }
1755
- let type = undefined;
1756
- let response = undefined;
1757
- [type, params] = this.handleMarketTypeAndParams('fetchMyTrades', market, params);
1758
- const until = this.safeIntegerN(params, ['until', 'endTime', 'end_time']);
1759
- params = this.omit(params, ['until']);
1760
- if (type === 'spot') {
1761
- let marginMode = undefined;
1762
- [marginMode, params] = this.handleMarginModeAndParams('fetchMyTrades', params);
1763
- if (marginMode === 'isolated') {
1764
- request['orderMode'] = 'iso_margin';
1765
- }
1766
- const options = this.safeValue(this.options, 'fetchMyTrades', {});
1767
- const defaultLimit = this.safeInteger(options, 'limit', 200);
1768
- if (limit === undefined) {
1769
- limit = defaultLimit;
1770
- }
1771
- request['limit'] = limit;
1772
- if (since !== undefined) {
1773
- request['startTime'] = since;
1774
- }
1775
- if (until !== undefined) {
1776
- request['endTime'] = until;
1777
- }
1778
- response = await this.privatePostSpotV4QueryTrades(this.extend(request, params));
1779
- }
1780
- else if (type === 'swap') {
1781
- if (symbol === undefined) {
1782
- throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
1783
- }
1784
- if (since !== undefined) {
1785
- request['start_time'] = since;
1786
- }
1787
- if (until !== undefined) {
1788
- request['end_time'] = until;
1789
- }
1790
- response = await this.privateGetContractPrivateTrades(this.extend(request, params));
1791
- }
1792
- else {
1793
- throw new errors.NotSupported(this.id + ' fetchMyTrades() does not support ' + type + ' orders, only spot and swap orders are accepted');
1794
- }
1795
- //
1796
- // spot
1797
- //
1798
- // {
1799
- // "code":1000,
1800
- // "message":"success",
1801
- // "data":[
1802
- // {
1803
- // "tradeId":"182342999769370687",
1804
- // "orderId":"183270218784142990",
1805
- // "clientOrderId":"183270218784142990",
1806
- // "symbol":"ADA_USDT",
1807
- // "side":"buy",
1808
- // "orderMode":"spot",
1809
- // "type":"market",
1810
- // "price":"0.245948",
1811
- // "size":"20.71",
1812
- // "notional":"5.09358308",
1813
- // "fee":"0.00509358",
1814
- // "feeCoinName":"USDT",
1815
- // "tradeRole":"taker",
1816
- // "createTime":1695658457836,
1817
- // "updateTime":1695658457836
1818
- // }
1819
- // ],
1820
- // "trace":"fbaee9e0e2f5442fba5b3262fc86b0ac.65.16956593456523085"
1821
- // }
1822
- //
1823
- // swap
1824
- //
1825
- // {
1826
- // "code": 1000,
1827
- // "message": "Ok",
1828
- // "data": [
1829
- // {
1830
- // "order_id": "230930336848609",
1831
- // "trade_id": "6212604014",
1832
- // "symbol": "BTCUSDT",
1833
- // "side": 3,
1834
- // "price": "26910.4",
1835
- // "vol": "1",
1836
- // "exec_type": "Taker",
1837
- // "profit": false,
1838
- // "create_time": 1695961596692,
1839
- // "realised_profit": "-0.0003",
1840
- // "paid_fees": "0.01614624"
1841
- // },
1842
- // ],
1843
- // "trace": "4cad855074634097ac6ba5257c47305d.62.16959616054873723"
1844
- // }
1845
- //
1846
- const data = this.safeValue(response, 'data', []);
1847
- return this.parseTrades(data, market, since, limit);
1848
- }
1849
- async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
1850
- /**
1851
- * @method
1852
- * @name bitmart#fetchOrderTrades
1853
- * @see https://developer-pro.bitmart.com/en/spot/#order-trade-list-v4-signed
1854
- * @description fetch all the trades made from a single order
1855
- * @param {string} id order id
1856
- * @param {string} symbol unified market symbol
1857
- * @param {int} [since] the earliest time in ms to fetch trades for
1858
- * @param {int} [limit] the maximum number of trades to retrieve
1859
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1860
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1861
- */
1862
- await this.loadMarkets();
1863
- const request = {
1864
- 'orderId': id,
1865
- };
1866
- const response = await this.privatePostSpotV4QueryOrderTrades(this.extend(request, params));
1867
- const data = this.safeValue(response, 'data', {});
1868
- return this.parseTrades(data, undefined, since, limit);
1869
- }
1870
- customParseBalance(response, marketType) {
1871
- const data = this.safeValue(response, 'data', {});
1872
- let wallet = undefined;
1873
- if (marketType === 'swap') {
1874
- wallet = this.safeValue(response, 'data', []);
1875
- }
1876
- else if (marketType === 'margin') {
1877
- wallet = this.safeValue(data, 'symbols', []);
1878
- }
1879
- else {
1880
- wallet = this.safeValue(data, 'wallet', []);
1881
- }
1882
- const result = { 'info': response };
1883
- if (marketType === 'margin') {
1884
- for (let i = 0; i < wallet.length; i++) {
1885
- const entry = wallet[i];
1886
- const marketId = this.safeString(entry, 'symbol');
1887
- const symbol = this.safeSymbol(marketId, undefined, '_');
1888
- const base = this.safeValue(entry, 'base', {});
1889
- const quote = this.safeValue(entry, 'quote', {});
1890
- const baseCode = this.safeCurrencyCode(this.safeString(base, 'currency'));
1891
- const quoteCode = this.safeCurrencyCode(this.safeString(quote, 'currency'));
1892
- const subResult = {};
1893
- subResult[baseCode] = this.parseBalanceHelper(base);
1894
- subResult[quoteCode] = this.parseBalanceHelper(quote);
1895
- result[symbol] = this.safeBalance(subResult);
1896
- }
1897
- return result;
1898
- }
1899
- else {
1900
- for (let i = 0; i < wallet.length; i++) {
1901
- const balance = wallet[i];
1902
- let currencyId = this.safeString2(balance, 'id', 'currency');
1903
- currencyId = this.safeString(balance, 'coin_code', currencyId);
1904
- const code = this.safeCurrencyCode(currencyId);
1905
- const account = this.account();
1906
- account['free'] = this.safeString2(balance, 'available', 'available_balance');
1907
- account['used'] = this.safeString2(balance, 'frozen', 'frozen_balance');
1908
- result[code] = account;
1909
- }
1910
- return this.safeBalance(result);
1911
- }
1912
- }
1913
- parseBalanceHelper(entry) {
1914
- const account = this.account();
1915
- account['used'] = this.safeString(entry, 'frozen');
1916
- account['free'] = this.safeString(entry, 'available');
1917
- account['total'] = this.safeString(entry, 'total_asset');
1918
- const debt = this.safeString(entry, 'borrow_unpaid');
1919
- const interest = this.safeString(entry, 'interest_unpaid');
1920
- account['debt'] = Precise["default"].stringAdd(debt, interest);
1921
- return account;
1922
- }
1923
- async fetchBalance(params = {}) {
1924
- /**
1925
- * @method
1926
- * @name bitmart#fetchBalance
1927
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
1928
- * @see https://developer-pro.bitmart.com/en/spot/#get-spot-wallet-balance
1929
- * @see https://developer-pro.bitmart.com/en/futures/#get-contract-assets-detail
1930
- * @see https://developer-pro.bitmart.com/en/spot/#get-account-balance
1931
- * @see https://developer-pro.bitmart.com/en/spot/#get-margin-account-details-isolated
1932
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1933
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1934
- */
1935
- await this.loadMarkets();
1936
- let marketType = undefined;
1937
- [marketType, params] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
1938
- const marginMode = this.safeString(params, 'marginMode');
1939
- const isMargin = this.safeValue(params, 'margin', false);
1940
- params = this.omit(params, ['margin', 'marginMode']);
1941
- if (marginMode !== undefined || isMargin) {
1942
- marketType = 'margin';
1943
- }
1944
- let response = undefined;
1945
- if (marketType === 'spot') {
1946
- response = await this.privateGetSpotV1Wallet(params);
1947
- }
1948
- else if (marketType === 'swap') {
1949
- response = await this.privateGetContractPrivateAssetsDetail(params);
1950
- }
1951
- else if (marketType === 'account') {
1952
- response = await this.privateGetAccountV1Wallet(params);
1953
- }
1954
- else if (marketType === 'margin') {
1955
- response = await this.privateGetSpotV1MarginIsolatedAccount(params);
1956
- }
1957
- else {
1958
- throw new errors.NotSupported(this.id + ' fetchBalance() does not support ' + marketType + ' markets, only spot, swap and account and margin markets are accepted');
1959
- }
1960
- //
1961
- // spot
1962
- //
1963
- // {
1964
- // "message":"OK",
1965
- // "code":1000,
1966
- // "trace":"39069916-72f9-44c7-acde-2ad5afd21cad",
1967
- // "data":{
1968
- // "wallet":[
1969
- // {"id":"BTC","name":"Bitcoin","available":"0.00000062","frozen":"0.00000000"},
1970
- // {"id":"ETH","name":"Ethereum","available":"0.00002277","frozen":"0.00000000"},
1971
- // {"id":"BMX","name":"BitMart Token","available":"0.00000000","frozen":"0.00000000"}
1972
- // ]
1973
- // }
1974
- // }
1975
- //
1976
- // account
1977
- //
1978
- // {
1979
- // "message":"OK",
1980
- // "code":1000,
1981
- // "trace":"5c3b7fc7-93b2-49ef-bb59-7fdc56915b59",
1982
- // "data":{
1983
- // "wallet":[
1984
- // {"currency":"BTC","name":"Bitcoin","available":"0.00000062","frozen":"0.00000000"},
1985
- // {"currency":"ETH","name":"Ethereum","available":"0.00002277","frozen":"0.00000000"}
1986
- // ]
1987
- // }
1988
- // }
1989
- //
1990
- // swap
1991
- //
1992
- // {
1993
- // "code": 1000,
1994
- // "message": "Ok",
1995
- // "data": [
1996
- // {
1997
- // "currency": "USDT",
1998
- // "available_balance": "0",
1999
- // "frozen_balance": "0",
2000
- // "unrealized": "0",
2001
- // "equity": "0",
2002
- // "position_deposit": "0"
2003
- // },
2004
- // ...
2005
- // ],
2006
- // "trace": "f9da3a39-cf45-42e7-914d-294f565dfc33"
2007
- // }
2008
- //
2009
- // margin
2010
- //
2011
- // {
2012
- // "message": "OK",
2013
- // "code": 1000,
2014
- // "trace": "61dd6ab265c04064b72d8bc9b205f741.71.16701055600915302",
2015
- // "data": {
2016
- // "symbols": [
2017
- // {
2018
- // "symbol": "BTC_USDT",
2019
- // "risk_rate": "999.00",
2020
- // "risk_level": "1",
2021
- // "buy_enabled": false,
2022
- // "sell_enabled": false,
2023
- // "liquidate_price": null,
2024
- // "liquidate_rate": "1.15",
2025
- // "base": {
2026
- // "currency": "BTC",
2027
- // "borrow_enabled": true,
2028
- // "borrowed": "0.00000000",
2029
- // "available": "0.00000000",
2030
- // "frozen": "0.00000000",
2031
- // "net_asset": "0.00000000",
2032
- // "net_assetBTC": "0.00000000",
2033
- // "total_asset": "0.00000000",
2034
- // "borrow_unpaid": "0.00000000",
2035
- // "interest_unpaid": "0.00000000"
2036
- // },
2037
- // "quote": {
2038
- // "currency": "USDT",
2039
- // "borrow_enabled": true,
2040
- // "borrowed": "0.00000000",
2041
- // "available": "20.00000000",
2042
- // "frozen": "0.00000000",
2043
- // "net_asset": "20.00000000",
2044
- // "net_assetBTC": "0.00118008",
2045
- // "total_asset": "20.00000000",
2046
- // "borrow_unpaid": "0.00000000",
2047
- // "interest_unpaid": "0.00000000"
2048
- // }
2049
- // }
2050
- // ]
2051
- // }
2052
- // }
2053
- //
2054
- return this.customParseBalance(response, marketType);
2055
- }
2056
- parseTradingFee(fee, market = undefined) {
2057
- //
2058
- // {
2059
- // "symbol": "ETH_USDT",
2060
- // "taker_fee_rate": "0.0025",
2061
- // "maker_fee_rate": "0.0025"
2062
- // }
2063
- //
2064
- const marketId = this.safeString(fee, 'symbol');
2065
- const symbol = this.safeSymbol(marketId);
2066
- return {
2067
- 'info': fee,
2068
- 'symbol': symbol,
2069
- 'maker': this.safeNumber(fee, 'maker_fee_rate'),
2070
- 'taker': this.safeNumber(fee, 'taker_fee_rate'),
2071
- };
2072
- }
2073
- async fetchTradingFee(symbol, params = {}) {
2074
- /**
2075
- * @method
2076
- * @name bitmart#fetchTradingFee
2077
- * @description fetch the trading fees for a market
2078
- * @param {string} symbol unified market symbol
2079
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2080
- * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
2081
- */
2082
- await this.loadMarkets();
2083
- const market = this.market(symbol);
2084
- if (!market['spot']) {
2085
- throw new errors.NotSupported(this.id + ' fetchTradingFee() does not support ' + market['type'] + ' orders, only spot orders are accepted');
2086
- }
2087
- const request = {
2088
- 'symbol': market['id'],
2089
- };
2090
- const response = await this.privateGetSpotV1TradeFee(this.extend(request, params));
2091
- //
2092
- // {
2093
- // "message": "OK",
2094
- // "code": "1000",
2095
- // "trace": "5a6f1e40-37fe-4849-a494-03279fadcc62",
2096
- // "data": {
2097
- // "symbol": "ETH_USDT",
2098
- // "taker_fee_rate": "0.0025",
2099
- // "maker_fee_rate": "0.0025"
2100
- // }
2101
- // }
2102
- //
2103
- const data = this.safeValue(response, 'data');
2104
- return this.parseTradingFee(data);
2105
- }
2106
- parseOrder(order, market = undefined) {
2107
- //
2108
- // createOrder
2109
- //
2110
- // {
2111
- // "order_id": 2707217580
2112
- // }
2113
- //
2114
- // swap
2115
- // "data": {
2116
- // "order_id": 231116359426639,
2117
- // "price": "market price"
2118
- // },
2119
- //
2120
- // cancelOrder
2121
- //
2122
- // "2707217580" // order id
2123
- //
2124
- // spot fetchOrder, fetchOrdersByStatus, fetchOpenOrders, fetchClosedOrders
2125
- //
2126
- // {
2127
- // "order_id":1736871726781,
2128
- // "symbol":"BTC_USDT",
2129
- // "create_time":1591096004000,
2130
- // "side":"sell",
2131
- // "type":"market", // limit, market, limit_maker, ioc
2132
- // "price":"0.00",
2133
- // "price_avg":"0.00",
2134
- // "size":"0.02000",
2135
- // "notional":"0.00000000",
2136
- // "filled_notional":"0.00000000",
2137
- // "filled_size":"0.00000",
2138
- // "status":"8"
2139
- // }
2140
- //
2141
- // spot v4
2142
- // {
2143
- // "orderId" : "118100034543076010",
2144
- // "clientOrderId" : "118100034543076010",
2145
- // "symbol" : "BTC_USDT",
2146
- // "side" : "buy",
2147
- // "orderMode" : "spot",
2148
- // "type" : "limit",
2149
- // "state" : "filled",
2150
- // "price" : "48800.00",
2151
- // "priceAvg" : "39999.00",
2152
- // "size" : "0.10000",
2153
- // "filledSize" : "0.10000",
2154
- // "notional" : "4880.00000000",
2155
- // "filledNotional" : "3999.90000000",
2156
- // "createTime" : 1681701557927,
2157
- // "updateTime" : 1681701559408
2158
- // }
2159
- //
2160
- // swap: fetchOrder, fetchOpenOrders, fetchClosedOrders
2161
- //
2162
- // {
2163
- // "order_id": "230935812485489",
2164
- // "client_order_id": "",
2165
- // "price": "24000",
2166
- // "size": "1",
2167
- // "symbol": "BTCUSDT",
2168
- // "state": 2,
2169
- // "side": 1,
2170
- // "type": "limit",
2171
- // "leverage": "10",
2172
- // "open_type": "isolated",
2173
- // "deal_avg_price": "0",
2174
- // "deal_size": "0",
2175
- // "create_time": 1695702258629,
2176
- // "update_time": 1695702258642,
2177
- // "activation_price_type": 0,
2178
- // "activation_price": "",
2179
- // "callback_rate": ""
2180
- // }
2181
- //
2182
- let id = undefined;
2183
- if (typeof order === 'string') {
2184
- id = order;
2185
- order = {};
2186
- }
2187
- id = this.safeString2(order, 'order_id', 'orderId', id);
2188
- const timestamp = this.safeInteger2(order, 'create_time', 'createTime');
2189
- const marketId = this.safeString(order, 'symbol');
2190
- const symbol = this.safeSymbol(marketId, market);
2191
- market = this.safeMarket(symbol, market);
2192
- const orderType = this.safeString(market, 'type', 'spot');
2193
- let type = this.safeString(order, 'type');
2194
- let timeInForce = undefined;
2195
- let postOnly = undefined;
2196
- if (type === 'limit_maker') {
2197
- type = 'limit';
2198
- postOnly = true;
2199
- timeInForce = 'PO';
2200
- }
2201
- if (type === 'ioc') {
2202
- type = 'limit';
2203
- timeInForce = 'IOC';
2204
- }
2205
- let priceString = this.safeString(order, 'price');
2206
- if (priceString === 'market price') {
2207
- priceString = undefined;
2208
- }
2209
- const trailingActivationPrice = this.safeNumber(order, 'activation_price');
2210
- return this.safeOrder({
2211
- 'id': id,
2212
- 'clientOrderId': this.safeString(order, 'client_order_id'),
2213
- 'info': order,
2214
- 'timestamp': timestamp,
2215
- 'datetime': this.iso8601(timestamp),
2216
- 'lastTradeTimestamp': this.safeInteger(order, 'update_time'),
2217
- 'symbol': symbol,
2218
- 'type': type,
2219
- 'timeInForce': timeInForce,
2220
- 'postOnly': postOnly,
2221
- 'side': this.parseOrderSide(this.safeString(order, 'side')),
2222
- 'price': this.omitZero(priceString),
2223
- 'stopPrice': trailingActivationPrice,
2224
- 'triggerPrice': trailingActivationPrice,
2225
- 'amount': this.omitZero(this.safeString(order, 'size')),
2226
- 'cost': this.safeString2(order, 'filled_notional', 'filledNotional'),
2227
- 'average': this.safeStringN(order, ['price_avg', 'priceAvg', 'deal_avg_price']),
2228
- 'filled': this.safeStringN(order, ['filled_size', 'filledSize', 'deal_size']),
2229
- 'remaining': undefined,
2230
- 'status': this.parseOrderStatusByType(orderType, this.safeString2(order, 'status', 'state')),
2231
- 'fee': undefined,
2232
- 'trades': undefined,
2233
- }, market);
2234
- }
2235
- parseOrderSide(side) {
2236
- const sides = {
2237
- '1': 'buy',
2238
- '2': 'buy',
2239
- '3': 'sell',
2240
- '4': 'sell',
2241
- };
2242
- return this.safeString(sides, side, side);
2243
- }
2244
- parseOrderStatusByType(type, status) {
2245
- const statusesByType = {
2246
- 'spot': {
2247
- '1': 'rejected',
2248
- '2': 'open',
2249
- '3': 'rejected',
2250
- '4': 'open',
2251
- '5': 'open',
2252
- '6': 'closed',
2253
- '7': 'canceled',
2254
- '8': 'canceled',
2255
- 'new': 'open',
2256
- 'partially_filled': 'open',
2257
- 'filled': 'closed',
2258
- 'partially_canceled': 'canceled',
2259
- },
2260
- 'swap': {
2261
- '1': 'open',
2262
- '2': 'open',
2263
- '4': 'closed', // Completed
2264
- },
2265
- };
2266
- const statuses = this.safeValue(statusesByType, type, {});
2267
- return this.safeString(statuses, status, status);
2268
- }
2269
- async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
2270
- /**
2271
- * @method
2272
- * @name bitmart#createMarketBuyOrderWithCost
2273
- * @description create a market buy order by providing the symbol and cost
2274
- * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2275
- * @param {string} symbol unified symbol of the market to create an order in
2276
- * @param {float} cost how much you want to trade in units of the quote currency
2277
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2278
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2279
- */
2280
- await this.loadMarkets();
2281
- const market = this.market(symbol);
2282
- if (!market['spot']) {
2283
- throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
2284
- }
2285
- params['createMarketBuyOrderRequiresPrice'] = false;
2286
- return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
2287
- }
2288
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
2289
- /**
2290
- * @method
2291
- * @name bitmart#createOrder
2292
- * @description create a trade order
2293
- * @see https://developer-pro.bitmart.com/en/spot/#new-order-v2-signed
2294
- * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2295
- * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2296
- * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2297
- * @param {string} symbol unified symbol of the market to create an order in
2298
- * @param {string} type 'market', 'limit' or 'trailing' for swap markets only
2299
- * @param {string} side 'buy' or 'sell'
2300
- * @param {float} amount how much of currency you want to trade in units of base currency
2301
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2302
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2303
- * @param {string} [params.marginMode] 'cross' or 'isolated'
2304
- * @param {string} [params.leverage] *swap only* leverage level
2305
- * @param {string} [params.clientOrderId] client order id of the order
2306
- * @param {boolean} [params.reduceOnly] *swap only* reduce only
2307
- * @param {boolean} [params.postOnly] make sure the order is posted to the order book and not matched immediately
2308
- * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
2309
- * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
2310
- * @param {int} [params.price_way] *swap only* 1: price way long, 2: price way short
2311
- * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2312
- * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2313
- * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2314
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2315
- */
2316
- await this.loadMarkets();
2317
- const market = this.market(symbol);
2318
- const result = this.handleMarginModeAndParams('createOrder', params);
2319
- const marginMode = this.safeString(result, 0);
2320
- const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2321
- const isTriggerOrder = triggerPrice !== undefined;
2322
- let response = undefined;
2323
- if (market['spot']) {
2324
- const spotRequest = this.createSpotOrderRequest(symbol, type, side, amount, price, params);
2325
- if (marginMode === 'isolated') {
2326
- response = await this.privatePostSpotV1MarginSubmitOrder(spotRequest);
2327
- }
2328
- else {
2329
- response = await this.privatePostSpotV2SubmitOrder(spotRequest);
2330
- }
2331
- }
2332
- else {
2333
- const swapRequest = this.createSwapOrderRequest(symbol, type, side, amount, price, params);
2334
- if (isTriggerOrder) {
2335
- response = await this.privatePostContractPrivateSubmitPlanOrder(swapRequest);
2336
- }
2337
- else {
2338
- response = await this.privatePostContractPrivateSubmitOrder(swapRequest);
2339
- }
2340
- }
2341
- //
2342
- // spot and margin
2343
- //
2344
- // {
2345
- // "code": 1000,
2346
- // "trace":"886fb6ae-456b-4654-b4e0-d681ac05cea1",
2347
- // "message": "OK",
2348
- // "data": {
2349
- // "order_id": 2707217580
2350
- // }
2351
- // }
2352
- //
2353
- // swap
2354
- // {"code":1000,"message":"Ok","data":{"order_id":231116359426639,"price":"market price"},"trace":"7f9c94e10f9d4513bc08a7bfc2a5559a.62.16996369620521911"}
2355
- //
2356
- const data = this.safeValue(response, 'data', {});
2357
- const order = this.parseOrder(data, market);
2358
- order['type'] = type;
2359
- order['side'] = side;
2360
- order['amount'] = amount;
2361
- order['price'] = price;
2362
- return order;
2363
- }
2364
- createSwapOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
2365
- /**
2366
- * @method
2367
- * @name bitmart#createSwapOrderRequest
2368
- * @ignore
2369
- * @description create a trade order
2370
- * @see https://developer-pro.bitmart.com/en/futures/#submit-order-signed
2371
- * @see https://developer-pro.bitmart.com/en/futures/#submit-plan-order-signed
2372
- * @param {string} symbol unified symbol of the market to create an order in
2373
- * @param {string} type 'market', 'limit' or 'trailing'
2374
- * @param {string} side 'buy' or 'sell'
2375
- * @param {float} amount how much of currency you want to trade in units of base currency
2376
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2377
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2378
- * @param {int} [params.leverage] leverage level
2379
- * @param {boolean} [params.reduceOnly] *swap only* reduce only
2380
- * @param {string} [params.marginMode] 'cross' or 'isolated', default is 'cross'
2381
- * @param {string} [params.clientOrderId] client order id of the order
2382
- * @param {string} [params.triggerPrice] *swap only* the price to trigger a stop order
2383
- * @param {int} [params.price_type] *swap only* 1: last price, 2: fair price, default is 1
2384
- * @param {int} [params.price_way] *swap only* 1: price way long, 2: price way short
2385
- * @param {int} [params.activation_price_type] *swap trailing order only* 1: last price, 2: fair price, default is 1
2386
- * @param {string} [params.trailingPercent] *swap only* the percent to trail away from the current market price, min 0.1 max 5
2387
- * @param {string} [params.trailingTriggerPrice] *swap only* the price to trigger a trailing order, default uses the price argument
2388
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2389
- */
2390
- const market = this.market(symbol);
2391
- const request = {
2392
- 'symbol': market['id'],
2393
- 'type': type,
2394
- 'size': parseInt(this.amountToPrecision(symbol, amount)),
2395
- };
2396
- const timeInForce = this.safeString(params, 'timeInForce');
2397
- const mode = this.safeInteger(params, 'mode'); // only for swap
2398
- const isMarketOrder = type === 'market';
2399
- let postOnly = undefined;
2400
- const reduceOnly = this.safeValue(params, 'reduceOnly');
2401
- const isExchangeSpecificPo = (mode === 4);
2402
- [postOnly, params] = this.handlePostOnly(isMarketOrder, isExchangeSpecificPo, params);
2403
- const ioc = ((timeInForce === 'IOC') || (mode === 3));
2404
- const isLimitOrder = (type === 'limit') || postOnly || ioc;
2405
- if (timeInForce === 'GTC') {
2406
- request['mode'] = 1;
2407
- }
2408
- else if (timeInForce === 'FOK') {
2409
- request['mode'] = 2;
2410
- }
2411
- else if (timeInForce === 'IOC') {
2412
- request['mode'] = 3;
2413
- }
2414
- if (postOnly) {
2415
- request['mode'] = 4;
2416
- }
2417
- const triggerPrice = this.safeStringN(params, ['triggerPrice', 'stopPrice', 'trigger_price']);
2418
- const isTriggerOrder = triggerPrice !== undefined;
2419
- const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activation_price', price);
2420
- const trailingPercent = this.safeString2(params, 'trailingPercent', 'callback_rate');
2421
- const isTrailingPercentOrder = trailingPercent !== undefined;
2422
- if (isLimitOrder) {
2423
- request['price'] = this.priceToPrecision(symbol, price);
2424
- }
2425
- else if (type === 'trailing' || isTrailingPercentOrder) {
2426
- request['callback_rate'] = trailingPercent;
2427
- request['activation_price'] = this.priceToPrecision(symbol, trailingTriggerPrice);
2428
- request['activation_price_type'] = this.safeInteger(params, 'activation_price_type', 1);
2429
- }
2430
- if (isTriggerOrder) {
2431
- request['executive_price'] = this.priceToPrecision(symbol, price);
2432
- request['trigger_price'] = this.priceToPrecision(symbol, triggerPrice);
2433
- request['price_type'] = this.safeInteger(params, 'price_type', 1);
2434
- if (side === 'buy') {
2435
- if (reduceOnly) {
2436
- request['price_way'] = 2;
2437
- }
2438
- else {
2439
- request['price_way'] = 1;
2440
- }
2441
- }
2442
- else if (side === 'sell') {
2443
- if (reduceOnly) {
2444
- request['price_way'] = 1;
2445
- }
2446
- else {
2447
- request['price_way'] = 2;
2448
- }
2449
- }
2450
- }
2451
- if (side === 'buy') {
2452
- if (reduceOnly) {
2453
- request['side'] = 2; // buy close short
2454
- }
2455
- else {
2456
- request['side'] = 1; // buy open long
2457
- }
2458
- }
2459
- else if (side === 'sell') {
2460
- if (reduceOnly) {
2461
- request['side'] = 3; // sell close long
2462
- }
2463
- else {
2464
- request['side'] = 4; // sell open short
2465
- }
2466
- }
2467
- let marginMode = undefined;
2468
- [marginMode, params] = this.handleMarginModeAndParams('createOrder', params, 'cross');
2469
- request['open_type'] = marginMode;
2470
- const clientOrderId = this.safeString(params, 'clientOrderId');
2471
- if (clientOrderId !== undefined) {
2472
- params = this.omit(params, 'clientOrderId');
2473
- request['client_order_id'] = clientOrderId;
2474
- }
2475
- const leverage = this.safeInteger(params, 'leverage', 1);
2476
- params = this.omit(params, ['timeInForce', 'postOnly', 'reduceOnly', 'leverage', 'trailingTriggerPrice', 'trailingPercent', 'triggerPrice', 'stopPrice']);
2477
- request['leverage'] = this.numberToString(leverage);
2478
- return this.extend(request, params);
2479
- }
2480
- createSpotOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
2481
- /**
2482
- * @method
2483
- * @name bitmart#createSpotOrderRequest
2484
- * @ignore
2485
- * @description create a spot order request
2486
- * @see https://developer-pro.bitmart.com/en/spot/#place-spot-order
2487
- * @see https://developer-pro.bitmart.com/en/spot/#place-margin-order
2488
- * @param {string} symbol unified symbol of the market to create an order in
2489
- * @param {string} type 'market' or 'limit'
2490
- * @param {string} side 'buy' or 'sell'
2491
- * @param {float} amount how much of currency you want to trade in units of base currency
2492
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
2493
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2494
- * @param {string} [params.marginMode] 'cross' or 'isolated'
2495
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2496
- */
2497
- const market = this.market(symbol);
2498
- const request = {
2499
- 'symbol': market['id'],
2500
- 'side': side,
2501
- 'type': type,
2502
- };
2503
- const timeInForce = this.safeString(params, 'timeInForce');
2504
- if (timeInForce === 'FOK') {
2505
- throw new errors.InvalidOrder(this.id + ' createOrder() only accepts timeInForce parameter values of IOC or PO');
2506
- }
2507
- const mode = this.safeInteger(params, 'mode'); // only for swap
2508
- const isMarketOrder = type === 'market';
2509
- let postOnly = undefined;
2510
- const isExchangeSpecificPo = (type === 'limit_maker') || (mode === 4);
2511
- [postOnly, params] = this.handlePostOnly(isMarketOrder, isExchangeSpecificPo, params);
2512
- params = this.omit(params, ['timeInForce', 'postOnly']);
2513
- const ioc = ((timeInForce === 'IOC') || (type === 'ioc'));
2514
- const isLimitOrder = (type === 'limit') || postOnly || ioc;
2515
- // method = 'privatePostSpotV2SubmitOrder';
2516
- if (isLimitOrder) {
2517
- request['size'] = this.amountToPrecision(symbol, amount);
2518
- request['price'] = this.priceToPrecision(symbol, price);
2519
- }
2520
- else if (isMarketOrder) {
2521
- // for market buy it requires the amount of quote currency to spend
2522
- if (side === 'buy') {
2523
- let notional = this.safeNumber2(params, 'cost', 'notional');
2524
- params = this.omit(params, 'cost');
2525
- let createMarketBuyOrderRequiresPrice = true;
2526
- [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
2527
- if (createMarketBuyOrderRequiresPrice) {
2528
- if ((price === undefined) && (notional === undefined)) {
2529
- throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend in the amount argument or in the "notional" extra parameter (the exchange-specific behaviour)');
2530
- }
2531
- else {
2532
- const amountString = this.numberToString(amount);
2533
- const priceString = this.numberToString(price);
2534
- notional = this.parseNumber(Precise["default"].stringMul(amountString, priceString));
2535
- }
2536
- }
2537
- else {
2538
- notional = (notional === undefined) ? amount : notional;
2539
- }
2540
- request['notional'] = this.decimalToPrecision(notional, number.TRUNCATE, market['precision']['price'], this.precisionMode);
2541
- }
2542
- else if (side === 'sell') {
2543
- request['size'] = this.amountToPrecision(symbol, amount);
2544
- }
2545
- }
2546
- if (postOnly) {
2547
- request['type'] = 'limit_maker';
2548
- }
2549
- if (ioc) {
2550
- request['type'] = 'ioc';
2551
- }
2552
- return this.extend(request, params);
2553
- }
2554
- async cancelOrder(id, symbol = undefined, params = {}) {
2555
- /**
2556
- * @method
2557
- * @name bitmart#cancelOrder
2558
- * @description cancels an open order
2559
- * @see https://developer-pro.bitmart.com/en/futures/#cancel-order-signed
2560
- * @see https://developer-pro.bitmart.com/en/spot/#cancel-order-v3-signed
2561
- * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2562
- * @see https://developer-pro.bitmart.com/en/futures/#cancel-plan-order-signed
2563
- * @param {string} id order id
2564
- * @param {string} symbol unified symbol of the market the order was made in
2565
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2566
- * @param {string} [params.clientOrderId] *spot only* the client order id of the order to cancel
2567
- * @param {boolean} [params.stop] *swap only* whether the order is a stop order
2568
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2569
- */
2570
- if (symbol === undefined) {
2571
- throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
2572
- }
2573
- await this.loadMarkets();
2574
- const market = this.market(symbol);
2575
- const request = {
2576
- 'symbol': market['id'],
2577
- };
2578
- const clientOrderId = this.safeString2(params, 'clientOrderId', 'client_order_id');
2579
- if (clientOrderId !== undefined) {
2580
- request['client_order_id'] = clientOrderId;
2581
- }
2582
- else {
2583
- request['order_id'] = id.toString();
2584
- }
2585
- params = this.omit(params, ['clientOrderId']);
2586
- let response = undefined;
2587
- if (market['spot']) {
2588
- response = await this.privatePostSpotV3CancelOrder(this.extend(request, params));
2589
- }
2590
- else {
2591
- const stop = this.safeValue2(params, 'stop', 'trigger');
2592
- params = this.omit(params, ['stop', 'trigger']);
2593
- if (!stop) {
2594
- response = await this.privatePostContractPrivateCancelOrder(this.extend(request, params));
2595
- }
2596
- else {
2597
- response = await this.privatePostContractPrivateCancelPlanOrder(this.extend(request, params));
2598
- }
2599
- }
2600
- // swap
2601
- // {"code":1000,"message":"Ok","trace":"7f9c94e10f9d4513bc08a7bfc2a5559a.55.16959817848001851"}
2602
- //
2603
- // spot
2604
- //
2605
- // {
2606
- // "code": 1000,
2607
- // "trace":"886fb6ae-456b-4654-b4e0-d681ac05cea1",
2608
- // "message": "OK",
2609
- // "data": {
2610
- // "result": true
2611
- // }
2612
- // }
2613
- //
2614
- // spot alternative
2615
- //
2616
- // {
2617
- // "code": 1000,
2618
- // "trace":"886fb6ae-456b-4654-b4e0-d681ac05cea1",
2619
- // "message": "OK",
2620
- // "data": true
2621
- // }
2622
- //
2623
- if (market['swap']) {
2624
- return response;
2625
- }
2626
- const data = this.safeValue(response, 'data');
2627
- if (data === true) {
2628
- return this.parseOrder(id, market);
2629
- }
2630
- const succeeded = this.safeValue(data, 'succeed');
2631
- if (succeeded !== undefined) {
2632
- id = this.safeString(succeeded, 0);
2633
- if (id === undefined) {
2634
- throw new errors.InvalidOrder(this.id + ' cancelOrder() failed to cancel ' + symbol + ' order id ' + id);
2635
- }
2636
- }
2637
- else {
2638
- const result = this.safeValue(data, 'result');
2639
- if (!result) {
2640
- throw new errors.InvalidOrder(this.id + ' cancelOrder() ' + symbol + ' order id ' + id + ' is filled or canceled');
2641
- }
2642
- }
2643
- const order = this.parseOrder(id, market);
2644
- return this.extend(order, { 'id': id });
2645
- }
2646
- async cancelAllOrders(symbol = undefined, params = {}) {
2647
- /**
2648
- * @method
2649
- * @name bitmart#cancelAllOrders
2650
- * @description cancel all open orders in a market
2651
- * @see https://developer-pro.bitmart.com/en/spot/#cancel-all-orders
2652
- * @see https://developer-pro.bitmart.com/en/futures/#cancel-all-orders-signed
2653
- * @param {string} symbol unified market symbol of the market to cancel orders in
2654
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2655
- * @param {string} [params.side] *spot only* 'buy' or 'sell'
2656
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2657
- */
2658
- await this.loadMarkets();
2659
- const request = {};
2660
- let market = undefined;
2661
- if (symbol !== undefined) {
2662
- market = this.market(symbol);
2663
- request['symbol'] = market['id'];
2664
- }
2665
- let response = undefined;
2666
- let type = undefined;
2667
- [type, params] = this.handleMarketTypeAndParams('cancelAllOrders', market, params);
2668
- if (type === 'spot') {
2669
- response = await this.privatePostSpotV1CancelOrders(this.extend(request, params));
2670
- }
2671
- else if (type === 'swap') {
2672
- if (symbol === undefined) {
2673
- throw new errors.ArgumentsRequired(this.id + ' cancelAllOrders() requires a symbol argument');
2674
- }
2675
- response = await this.privatePostContractPrivateCancelOrders(this.extend(request, params));
2676
- }
2677
- //
2678
- // spot
2679
- //
2680
- // {
2681
- // "code": 1000,
2682
- // "trace":"886fb6ae-456b-4654-b4e0-d681ac05cea1",
2683
- // "message": "OK",
2684
- // "data": {}
2685
- // }
2686
- //
2687
- // swap
2688
- //
2689
- // {
2690
- // "code": 1000,
2691
- // "message": "Ok",
2692
- // "trace": "7f9c94e10f9d4513bc08a7bfc2a5559a.70.16954131323145323"
2693
- // }
2694
- //
2695
- return response;
2696
- }
2697
- async fetchOrdersByStatus(status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
2698
- if (symbol === undefined) {
2699
- throw new errors.ArgumentsRequired(this.id + ' fetchOrdersByStatus() requires a symbol argument');
2700
- }
2701
- await this.loadMarkets();
2702
- const market = this.market(symbol);
2703
- if (!market['spot']) {
2704
- throw new errors.NotSupported(this.id + ' fetchOrdersByStatus() does not support ' + market['type'] + ' orders, only spot orders are accepted');
2705
- }
2706
- const request = {
2707
- 'symbol': market['id'],
2708
- 'offset': 1,
2709
- 'N': 100, // max limit is 100
2710
- };
2711
- if (status === 'open') {
2712
- request['status'] = 9;
2713
- }
2714
- else if (status === 'closed') {
2715
- request['status'] = 6;
2716
- }
2717
- else if (status === 'canceled') {
2718
- request['status'] = 8;
2719
- }
2720
- else {
2721
- request['status'] = status;
2722
- }
2723
- const response = await this.privateGetSpotV3Orders(this.extend(request, params));
2724
- //
2725
- // spot
2726
- //
2727
- // {
2728
- // "message":"OK",
2729
- // "code":1000,
2730
- // "trace":"70e7d427-7436-4fb8-8cdd-97e1f5eadbe9",
2731
- // "data":{
2732
- // "current_page":1,
2733
- // "orders":[
2734
- // {
2735
- // "order_id":2147601241,
2736
- // "symbol":"BTC_USDT",
2737
- // "create_time":1591099963000,
2738
- // "side":"sell",
2739
- // "type":"limit",
2740
- // "price":"9000.00",
2741
- // "price_avg":"0.00",
2742
- // "size":"1.00000",
2743
- // "notional":"9000.00000000",
2744
- // "filled_notional":"0.00000000",
2745
- // "filled_size":"0.00000",
2746
- // "status":"4"
2747
- // }
2748
- // ]
2749
- // }
2750
- // }
2751
- //
2752
- const data = this.safeValue(response, 'data', {});
2753
- const orders = this.safeValue(data, 'orders', []);
2754
- return this.parseOrders(orders, market, since, limit);
2755
- }
2756
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2757
- /**
2758
- * @method
2759
- * @name bitmart#fetchOpenOrders
2760
- * @see https://developer-pro.bitmart.com/en/spot/#current-open-orders-v4-signed
2761
- * @see https://developer-pro.bitmart.com/en/futures/#get-all-open-orders-keyed
2762
- * @see https://developer-pro.bitmart.com/en/futures/#get-all-current-plan-orders-keyed
2763
- * @description fetch all unfilled currently open orders
2764
- * @param {string} symbol unified market symbol
2765
- * @param {int} [since] the earliest time in ms to fetch open orders for
2766
- * @param {int} [limit] the maximum number of open order structures to retrieve
2767
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2768
- * @param {boolean} [params.marginMode] *spot* whether to fetch trades for margin orders or spot orders, defaults to spot orders (only isolated margin orders are supported)
2769
- * @param {int} [params.until] *spot* the latest time in ms to fetch orders for
2770
- * @param {string} [params.type] *swap* order type, 'limit' or 'market'
2771
- * @param {string} [params.order_state] *swap* the order state, 'all' or 'partially_filled', default is 'all'
2772
- * @param {string} [params.orderType] *swap only* 'limit', 'market', or 'trailing'
2773
- * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch trailing orders
2774
- * @param {boolean} [params.trigger] *swap only* set to true if you want to fetch trigger orders
2775
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2776
- */
2777
- await this.loadMarkets();
2778
- let market = undefined;
2779
- const request = {};
2780
- if (symbol !== undefined) {
2781
- market = this.market(symbol);
2782
- request['symbol'] = market['id'];
2783
- }
2784
- if (limit !== undefined) {
2785
- request['limit'] = limit;
2786
- }
2787
- let type = undefined;
2788
- let response = undefined;
2789
- [type, params] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
2790
- if (type === 'spot') {
2791
- let marginMode = undefined;
2792
- [marginMode, params] = this.handleMarginModeAndParams('fetchOpenOrders', params);
2793
- if (marginMode === 'isolated') {
2794
- request['orderMode'] = 'iso_margin';
2795
- }
2796
- if (since !== undefined) {
2797
- request['startTime'] = since;
2798
- }
2799
- const until = this.safeInteger2(params, 'until', 'endTime');
2800
- if (until !== undefined) {
2801
- params = this.omit(params, ['endTime']);
2802
- request['endTime'] = until;
2803
- }
2804
- response = await this.privatePostSpotV4QueryOpenOrders(this.extend(request, params));
2805
- }
2806
- else if (type === 'swap') {
2807
- const isStop = this.safeValue2(params, 'stop', 'trigger');
2808
- params = this.omit(params, ['stop', 'trigger']);
2809
- if (isStop) {
2810
- response = await this.privateGetContractPrivateCurrentPlanOrder(this.extend(request, params));
2811
- }
2812
- else {
2813
- const trailing = this.safeValue(params, 'trailing', false);
2814
- let orderType = this.safeString(params, 'orderType');
2815
- params = this.omit(params, ['orderType', 'trailing']);
2816
- if (trailing) {
2817
- orderType = 'trailing';
2818
- }
2819
- if (orderType !== undefined) {
2820
- request['type'] = orderType;
2821
- }
2822
- response = await this.privateGetContractPrivateGetOpenOrders(this.extend(request, params));
2823
- }
2824
- }
2825
- else {
2826
- throw new errors.NotSupported(this.id + ' fetchOpenOrders() does not support ' + type + ' orders, only spot and swap orders are accepted');
2827
- }
2828
- //
2829
- // spot
2830
- //
2831
- // {
2832
- // "code": 1000,
2833
- // "message": "success",
2834
- // "data": [
2835
- // {
2836
- // "orderId": "183299373022163211",
2837
- // "clientOrderId": "183299373022163211",
2838
- // "symbol": "BTC_USDT",
2839
- // "side": "buy",
2840
- // "orderMode": "spot",
2841
- // "type": "limit",
2842
- // "state": "new",
2843
- // "price": "25000.00",
2844
- // "priceAvg": "0.00",
2845
- // "size": "0.00020",
2846
- // "filledSize": "0.00000",
2847
- // "notional": "5.00000000",
2848
- // "filledNotional": "0.00000000",
2849
- // "createTime": 1695703703338,
2850
- // "updateTime": 1695703703359
2851
- // }
2852
- // ],
2853
- // "trace": "15f11d48e3234c81a2e786cr2e7a38e6.71.16957022303515933"
2854
- // }
2855
- //
2856
- // swap
2857
- //
2858
- // {
2859
- // "code": 1000,
2860
- // "message": "Ok",
2861
- // "data": [
2862
- // {
2863
- // "order_id": "230935812485489",
2864
- // "client_order_id": "",
2865
- // "price": "24000",
2866
- // "size": "1",
2867
- // "symbol": "BTCUSDT",
2868
- // "state": 2,
2869
- // "side": 1,
2870
- // "type": "limit",
2871
- // "leverage": "10",
2872
- // "open_type": "isolated",
2873
- // "deal_avg_price": "0",
2874
- // "deal_size": "0",
2875
- // "create_time": 1695702258629,
2876
- // "update_time": 1695702258642
2877
- // }
2878
- // ],
2879
- // "trace": "7f9d94g10f9d4513bc08a7rfc3a5559a.71.16957022303515933"
2880
- // }
2881
- //
2882
- const data = this.safeValue(response, 'data', []);
2883
- return this.parseOrders(data, market, since, limit);
2884
- }
2885
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2886
- /**
2887
- * @method
2888
- * @name bitmart#fetchClosedOrders
2889
- * @see https://developer-pro.bitmart.com/en/spot/#account-orders-v4-signed
2890
- * @see https://developer-pro.bitmart.com/en/futures/#get-order-history-keyed
2891
- * @description fetches information on multiple closed orders made by the user
2892
- * @param {string} symbol unified market symbol of the market orders were made in
2893
- * @param {int} [since] the earliest time in ms to fetch orders for
2894
- * @param {int} [limit] the maximum number of order structures to retrieve
2895
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2896
- * @param {int} [params.until] timestamp in ms of the latest entry
2897
- * @param {string} [params.marginMode] *spot only* 'cross' or 'isolated', for margin trading
2898
- * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2899
- */
2900
- await this.loadMarkets();
2901
- let market = undefined;
2902
- const request = {};
2903
- if (symbol !== undefined) {
2904
- market = this.market(symbol);
2905
- request['symbol'] = market['id'];
2906
- }
2907
- let type = undefined;
2908
- [type, params] = this.handleMarketTypeAndParams('fetchClosedOrders', market, params);
2909
- if (type !== 'spot') {
2910
- if (symbol === undefined) {
2911
- throw new errors.ArgumentsRequired(this.id + ' fetchClosedOrders() requires a symbol argument');
2912
- }
2913
- }
2914
- let marginMode = undefined;
2915
- [marginMode, params] = this.handleMarginModeAndParams('fetchClosedOrders', params);
2916
- if (marginMode === 'isolated') {
2917
- request['orderMode'] = 'iso_margin';
2918
- }
2919
- const startTimeKey = (type === 'spot') ? 'startTime' : 'start_time';
2920
- if (since !== undefined) {
2921
- request[startTimeKey] = since;
2922
- }
2923
- const endTimeKey = (type === 'spot') ? 'endTime' : 'end_time';
2924
- const until = this.safeInteger2(params, 'until', endTimeKey);
2925
- if (until !== undefined) {
2926
- params = this.omit(params, ['until']);
2927
- request[endTimeKey] = until;
2928
- }
2929
- let response = undefined;
2930
- if (type === 'spot') {
2931
- response = await this.privatePostSpotV4QueryHistoryOrders(this.extend(request, params));
2932
- }
2933
- else {
2934
- response = await this.privateGetContractPrivateOrderHistory(this.extend(request, params));
2935
- }
2936
- const data = this.safeValue(response, 'data', []);
2937
- return this.parseOrders(data, market, since, limit);
2938
- }
2939
- async fetchCanceledOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2940
- /**
2941
- * @method
2942
- * @name bitmart#fetchCanceledOrders
2943
- * @description fetches information on multiple canceled orders made by the user
2944
- * @param {string} symbol unified market symbol of the market orders were made in
2945
- * @param {int} [since] timestamp in ms of the earliest order, default is undefined
2946
- * @param {int} [limit] max number of orders to return, default is undefined
2947
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2948
- * @returns {object} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2949
- */
2950
- return await this.fetchOrdersByStatus('canceled', symbol, since, limit, params);
2951
- }
2952
- async fetchOrder(id, symbol = undefined, params = {}) {
2953
- /**
2954
- * @method
2955
- * @name bitmart#fetchOrder
2956
- * @description fetches information on an order made by the user
2957
- * @see https://developer-pro.bitmart.com/en/spot/#query-order-by-id-v4-signed
2958
- * @see https://developer-pro.bitmart.com/en/spot/#query-order-by-clientorderid-v4-signed
2959
- * @see https://developer-pro.bitmart.com/en/futures/#get-order-detail-keyed
2960
- * @param {string} id the id of the order
2961
- * @param {string} symbol unified symbol of the market the order was made in
2962
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2963
- * @param {string} [params.clientOrderId] *spot* fetch the order by client order id instead of order id
2964
- * @param {string} [params.orderType] *swap only* 'limit', 'market', 'liquidate', 'bankruptcy', 'adl' or 'trailing'
2965
- * @param {boolean} [params.trailing] *swap only* set to true if you want to fetch a trailing order
2966
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2967
- */
2968
- await this.loadMarkets();
2969
- const request = {};
2970
- let type = undefined;
2971
- let market = undefined;
2972
- let response = undefined;
2973
- if (symbol !== undefined) {
2974
- market = this.market(symbol);
2975
- }
2976
- [type, params] = this.handleMarketTypeAndParams('fetchOrder', market, params);
2977
- if (type === 'spot') {
2978
- const clientOrderId = this.safeString(params, 'clientOrderId');
2979
- if (!clientOrderId) {
2980
- request['orderId'] = id;
2981
- }
2982
- if (clientOrderId !== undefined) {
2983
- response = await this.privatePostSpotV4QueryClientOrder(this.extend(request, params));
2984
- }
2985
- else {
2986
- response = await this.privatePostSpotV4QueryOrder(this.extend(request, params));
2987
- }
2988
- }
2989
- else if (type === 'swap') {
2990
- if (symbol === undefined) {
2991
- throw new errors.ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
2992
- }
2993
- const trailing = this.safeValue(params, 'trailing', false);
2994
- let orderType = this.safeString(params, 'orderType');
2995
- params = this.omit(params, ['orderType', 'trailing']);
2996
- if (trailing) {
2997
- orderType = 'trailing';
2998
- }
2999
- if (orderType !== undefined) {
3000
- request['type'] = orderType;
3001
- }
3002
- request['symbol'] = market['id'];
3003
- request['order_id'] = id;
3004
- response = await this.privateGetContractPrivateOrder(this.extend(request, params));
3005
- }
3006
- //
3007
- // spot
3008
- //
3009
- // {
3010
- // "code": 1000,
3011
- // "message": "success",
3012
- // "data": {
3013
- // "orderId": "183347420821295423",
3014
- // "clientOrderId": "183347420821295423",
3015
- // "symbol": "BTC_USDT",
3016
- // "side": "buy",
3017
- // "orderMode": "spot",
3018
- // "type": "limit",
3019
- // "state": "new",
3020
- // "price": "24000.00",
3021
- // "priceAvg": "0.00",
3022
- // "size": "0.00022",
3023
- // "filledSize": "0.00000",
3024
- // "notional": "5.28000000",
3025
- // "filledNotional": "0.00000000",
3026
- // "createTime": 1695783014734,
3027
- // "updateTime": 1695783014762
3028
- // },
3029
- // "trace": "ce3e6422c8b44d5fag855348a68693ed.63.14957831547451715"
3030
- // }
3031
- //
3032
- // swap
3033
- //
3034
- // {
3035
- // "code": 1000,
3036
- // "message": "Ok",
3037
- // "data": {
3038
- // "order_id": "230927283405028",
3039
- // "client_order_id": "",
3040
- // "price": "23000",
3041
- // "size": "1",
3042
- // "symbol": "BTCUSDT",
3043
- // "state": 2,
3044
- // "side": 1,
3045
- // "type": "limit",
3046
- // "leverage": "10",
3047
- // "open_type": "isolated",
3048
- // "deal_avg_price": "0",
3049
- // "deal_size": "0",
3050
- // "create_time": 1695783433600,
3051
- // "update_time": 1695783433613
3052
- // },
3053
- // "trace": "4cad855075664097af6ba5257c47605d.63.14957831547451715"
3054
- // }
3055
- //
3056
- const data = this.safeValue(response, 'data', {});
3057
- return this.parseOrder(data, market);
3058
- }
3059
- async fetchDepositAddress(code, params = {}) {
3060
- /**
3061
- * @method
3062
- * @name bitmart#fetchDepositAddress
3063
- * @description fetch the deposit address for a currency associated with this account
3064
- * @param {string} code unified currency code
3065
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3066
- * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
3067
- */
3068
- await this.loadMarkets();
3069
- const currency = this.currency(code);
3070
- const request = {
3071
- 'currency': currency['id'],
3072
- };
3073
- if (code === 'USDT') {
3074
- const defaultNetworks = this.safeValue(this.options, 'defaultNetworks');
3075
- const defaultNetwork = this.safeStringUpper(defaultNetworks, code);
3076
- const networks = this.safeValue(this.options, 'networks', {});
3077
- let networkInner = this.safeStringUpper(params, 'network', defaultNetwork); // this line allows the user to specify either ERC20 or ETH
3078
- networkInner = this.safeString(networks, networkInner, networkInner); // handle ERC20>ETH alias
3079
- if (networkInner !== undefined) {
3080
- request['currency'] = request['currency'] + '-' + networkInner; // when network the currency need to be changed to currency + '-' + network https://developer-pro.bitmart.com/en/account/withdraw_apply.html on the end of page
3081
- params = this.omit(params, 'network');
3082
- }
3083
- }
3084
- const response = await this.privateGetAccountV1DepositAddress(this.extend(request, params));
3085
- //
3086
- // {
3087
- // "message":"OK",
3088
- // "code":1000,
3089
- // "trace":"0e6edd79-f77f-4251-abe5-83ba75d06c1a",
3090
- // "data":{
3091
- // "currency":"USDT-TRC20",
3092
- // "chain":"USDT-TRC20",
3093
- // "address":"TGR3ghy2b5VLbyAYrmiE15jasR6aPHTvC5",
3094
- // "address_memo":""
3095
- // }
3096
- // }
3097
- //
3098
- const data = this.safeValue(response, 'data', {});
3099
- const address = this.safeString(data, 'address');
3100
- const tag = this.safeString(data, 'address_memo');
3101
- const chain = this.safeString(data, 'chain');
3102
- let network = undefined;
3103
- if (chain !== undefined) {
3104
- const parts = chain.split('-');
3105
- const networkId = this.safeString(parts, 1);
3106
- network = this.safeNetwork(networkId);
3107
- }
3108
- this.checkAddress(address);
3109
- return {
3110
- 'currency': code,
3111
- 'address': address,
3112
- 'tag': tag,
3113
- 'network': network,
3114
- 'info': response,
3115
- };
3116
- }
3117
- safeNetwork(networkId) {
3118
- // TODO: parse
3119
- return networkId;
3120
- }
3121
- async withdraw(code, amount, address, tag = undefined, params = {}) {
3122
- /**
3123
- * @method
3124
- * @name bitmart#withdraw
3125
- * @description make a withdrawal
3126
- * @param {string} code unified currency code
3127
- * @param {float} amount the amount to withdraw
3128
- * @param {string} address the address to withdraw to
3129
- * @param {string} tag
3130
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3131
- * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3132
- */
3133
- [tag, params] = this.handleWithdrawTagAndParams(tag, params);
3134
- this.checkAddress(address);
3135
- await this.loadMarkets();
3136
- const currency = this.currency(code);
3137
- const request = {
3138
- 'currency': currency['id'],
3139
- 'amount': amount,
3140
- 'destination': 'To Digital Address',
3141
- 'address': address,
3142
- };
3143
- if (tag !== undefined) {
3144
- request['address_memo'] = tag;
3145
- }
3146
- if (code === 'USDT') {
3147
- const defaultNetworks = this.safeValue(this.options, 'defaultNetworks');
3148
- const defaultNetwork = this.safeStringUpper(defaultNetworks, code);
3149
- const networks = this.safeValue(this.options, 'networks', {});
3150
- let network = this.safeStringUpper(params, 'network', defaultNetwork); // this line allows the user to specify either ERC20 or ETH
3151
- network = this.safeString(networks, network, network); // handle ERC20>ETH alias
3152
- if (network !== undefined) {
3153
- request['currency'] = request['currency'] + '-' + network; // when network the currency need to be changed to currency + '-' + network https://developer-pro.bitmart.com/en/account/withdraw_apply.html on the end of page
3154
- params = this.omit(params, 'network');
3155
- }
3156
- }
3157
- const response = await this.privatePostAccountV1WithdrawApply(this.extend(request, params));
3158
- //
3159
- // {
3160
- // "code": 1000,
3161
- // "trace":"886fb6ae-456b-4654-b4e0-d681ac05cea1",
3162
- // "message": "OK",
3163
- // "data": {
3164
- // "withdraw_id": "121212"
3165
- // }
3166
- // }
3167
- //
3168
- const data = this.safeValue(response, 'data');
3169
- const transaction = this.parseTransaction(data, currency);
3170
- return this.extend(transaction, {
3171
- 'code': code,
3172
- 'address': address,
3173
- 'tag': tag,
3174
- });
3175
- }
3176
- async fetchTransactionsByType(type, code = undefined, since = undefined, limit = undefined, params = {}) {
3177
- await this.loadMarkets();
3178
- if (limit === undefined) {
3179
- limit = 50; // max 50
3180
- }
3181
- const request = {
3182
- 'operation_type': type,
3183
- 'offset': 1,
3184
- 'N': limit,
3185
- };
3186
- let currency = undefined;
3187
- if (code !== undefined) {
3188
- currency = this.currency(code);
3189
- request['currency'] = currency['id'];
3190
- }
3191
- if (code === 'USDT') {
3192
- const defaultNetworks = this.safeValue(this.options, 'defaultNetworks');
3193
- const defaultNetwork = this.safeStringUpper(defaultNetworks, code);
3194
- const networks = this.safeValue(this.options, 'networks', {});
3195
- let network = this.safeStringUpper(params, 'network', defaultNetwork); // this line allows the user to specify either ERC20 or ETH
3196
- network = this.safeString(networks, network, network); // handle ERC20>ETH alias
3197
- if (network !== undefined) {
3198
- request['currency'] += '-' + network; // when network the currency need to be changed to currency + '-' + network https://developer-pro.bitmart.com/en/account/withdraw_apply.html on the end of page
3199
- currency['code'] = request['currency']; // update currency code to filter
3200
- params = this.omit(params, 'network');
3201
- }
3202
- }
3203
- const response = await this.privateGetAccountV2DepositWithdrawHistory(this.extend(request, params));
3204
- //
3205
- // {
3206
- // "message":"OK",
3207
- // "code":1000,
3208
- // "trace":"142bf92a-fc50-4689-92b6-590886f90b97",
3209
- // "data":{
3210
- // "records":[
3211
- // {
3212
- // "withdraw_id":"1679952",
3213
- // "deposit_id":"",
3214
- // "operation_type":"withdraw",
3215
- // "currency":"BMX",
3216
- // "apply_time":1588867374000,
3217
- // "arrival_amount":"59.000000000000",
3218
- // "fee":"1.000000000000",
3219
- // "status":0,
3220
- // "address":"0xe57b69a8776b37860407965B73cdFFBDFe668Bb5",
3221
- // "address_memo":"",
3222
- // "tx_id":""
3223
- // },
3224
- // ]
3225
- // }
3226
- // }
3227
- //
3228
- const data = this.safeValue(response, 'data', {});
3229
- const records = this.safeValue(data, 'records', []);
3230
- return this.parseTransactions(records, currency, since, limit);
3231
- }
3232
- async fetchDeposit(id, code = undefined, params = {}) {
3233
- /**
3234
- * @method
3235
- * @name bitmart#fetchDeposit
3236
- * @description fetch information on a deposit
3237
- * @param {string} id deposit id
3238
- * @param {string} code not used by bitmart fetchDeposit ()
3239
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3240
- * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3241
- */
3242
- await this.loadMarkets();
3243
- const request = {
3244
- 'id': id,
3245
- };
3246
- const response = await this.privateGetAccountV1DepositWithdrawDetail(this.extend(request, params));
3247
- //
3248
- // {
3249
- // "message":"OK",
3250
- // "code":1000,
3251
- // "trace":"f7f74924-14da-42a6-b7f2-d3799dd9a612",
3252
- // "data":{
3253
- // "record":{
3254
- // "withdraw_id":"",
3255
- // "deposit_id":"1679952",
3256
- // "operation_type":"deposit",
3257
- // "currency":"BMX",
3258
- // "apply_time":1588867374000,
3259
- // "arrival_amount":"59.000000000000",
3260
- // "fee":"1.000000000000",
3261
- // "status":0,
3262
- // "address":"0xe57b69a8776b37860407965B73cdFFBDFe668Bb5",
3263
- // "address_memo":"",
3264
- // "tx_id":""
3265
- // }
3266
- // }
3267
- // }
3268
- //
3269
- const data = this.safeValue(response, 'data', {});
3270
- const record = this.safeValue(data, 'record', {});
3271
- return this.parseTransaction(record);
3272
- }
3273
- async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
3274
- /**
3275
- * @method
3276
- * @name bitmart#fetchDeposits
3277
- * @description fetch all deposits made to an account
3278
- * @param {string} code unified currency code
3279
- * @param {int} [since] the earliest time in ms to fetch deposits for
3280
- * @param {int} [limit] the maximum number of deposits structures to retrieve
3281
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3282
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3283
- */
3284
- return await this.fetchTransactionsByType('deposit', code, since, limit, params);
3285
- }
3286
- async fetchWithdrawal(id, code = undefined, params = {}) {
3287
- /**
3288
- * @method
3289
- * @name bitmart#fetchWithdrawal
3290
- * @description fetch data on a currency withdrawal via the withdrawal id
3291
- * @param {string} id withdrawal id
3292
- * @param {string} code not used by bitmart.fetchWithdrawal
3293
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3294
- * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3295
- */
3296
- await this.loadMarkets();
3297
- const request = {
3298
- 'id': id,
3299
- };
3300
- const response = await this.privateGetAccountV1DepositWithdrawDetail(this.extend(request, params));
3301
- //
3302
- // {
3303
- // "message":"OK",
3304
- // "code":1000,
3305
- // "trace":"f7f74924-14da-42a6-b7f2-d3799dd9a612",
3306
- // "data":{
3307
- // "record":{
3308
- // "withdraw_id":"1679952",
3309
- // "deposit_id":"",
3310
- // "operation_type":"withdraw",
3311
- // "currency":"BMX",
3312
- // "apply_time":1588867374000,
3313
- // "arrival_amount":"59.000000000000",
3314
- // "fee":"1.000000000000",
3315
- // "status":0,
3316
- // "address":"0xe57b69a8776b37860407965B73cdFFBDFe668Bb5",
3317
- // "address_memo":"",
3318
- // "tx_id":""
3319
- // }
3320
- // }
3321
- // }
3322
- //
3323
- const data = this.safeValue(response, 'data', {});
3324
- const record = this.safeValue(data, 'record', {});
3325
- return this.parseTransaction(record);
3326
- }
3327
- async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
3328
- /**
3329
- * @method
3330
- * @name bitmart#fetchWithdrawals
3331
- * @description fetch all withdrawals made from an account
3332
- * @param {string} code unified currency code
3333
- * @param {int} [since] the earliest time in ms to fetch withdrawals for
3334
- * @param {int} [limit] the maximum number of withdrawals structures to retrieve
3335
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3336
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3337
- */
3338
- return await this.fetchTransactionsByType('withdraw', code, since, limit, params);
3339
- }
3340
- parseTransactionStatus(status) {
3341
- const statuses = {
3342
- '0': 'pending',
3343
- '1': 'pending',
3344
- '2': 'pending',
3345
- '3': 'ok',
3346
- '4': 'canceled',
3347
- '5': 'failed', // Fail
3348
- };
3349
- return this.safeString(statuses, status, status);
3350
- }
3351
- parseTransaction(transaction, currency = undefined) {
3352
- //
3353
- // withdraw
3354
- //
3355
- // {
3356
- // "withdraw_id": "121212"
3357
- // }
3358
- //
3359
- // fetchDeposits, fetchWithdrawals, fetchWithdrawal
3360
- //
3361
- // {
3362
- // "withdraw_id":"1679952",
3363
- // "deposit_id":"",
3364
- // "operation_type":"withdraw",
3365
- // "currency":"BMX",
3366
- // "apply_time":1588867374000,
3367
- // "arrival_amount":"59.000000000000",
3368
- // "fee":"1.000000000000",
3369
- // "status":0,
3370
- // "address":"0xe57b69a8776b37860407965B73cdFFBDFe668Bb5",
3371
- // "address_memo":"",
3372
- // "tx_id":""
3373
- // }
3374
- //
3375
- let id = undefined;
3376
- const withdrawId = this.safeString(transaction, 'withdraw_id');
3377
- const depositId = this.safeString(transaction, 'deposit_id');
3378
- let type = undefined;
3379
- if ((withdrawId !== undefined) && (withdrawId !== '')) {
3380
- type = 'withdraw';
3381
- id = withdrawId;
3382
- }
3383
- else if ((depositId !== undefined) && (depositId !== '')) {
3384
- type = 'deposit';
3385
- id = depositId;
3386
- }
3387
- const amount = this.safeNumber(transaction, 'arrival_amount');
3388
- const timestamp = this.safeInteger(transaction, 'apply_time');
3389
- const currencyId = this.safeString(transaction, 'currency');
3390
- const code = this.safeCurrencyCode(currencyId, currency);
3391
- const status = this.parseTransactionStatus(this.safeString(transaction, 'status'));
3392
- const feeCost = this.safeNumber(transaction, 'fee');
3393
- let fee = undefined;
3394
- if (feeCost !== undefined) {
3395
- fee = {
3396
- 'cost': feeCost,
3397
- 'currency': code,
3398
- };
3399
- }
3400
- const txid = this.safeString(transaction, 'tx_id');
3401
- const address = this.safeString(transaction, 'address');
3402
- const tag = this.safeString(transaction, 'address_memo');
3403
- return {
3404
- 'info': transaction,
3405
- 'id': id,
3406
- 'currency': code,
3407
- 'amount': amount,
3408
- 'network': undefined,
3409
- 'address': address,
3410
- 'addressFrom': undefined,
3411
- 'addressTo': undefined,
3412
- 'tag': tag,
3413
- 'tagFrom': undefined,
3414
- 'tagTo': undefined,
3415
- 'status': status,
3416
- 'type': type,
3417
- 'updated': undefined,
3418
- 'txid': txid,
3419
- 'internal': undefined,
3420
- 'comment': undefined,
3421
- 'timestamp': (timestamp !== 0) ? timestamp : undefined,
3422
- 'datetime': (timestamp !== 0) ? this.iso8601(timestamp) : undefined,
3423
- 'fee': fee,
3424
- };
3425
- }
3426
- async repayIsolatedMargin(symbol, code, amount, params = {}) {
3427
- /**
3428
- * @method
3429
- * @name bitmart#repayIsolatedMargin
3430
- * @description repay borrowed margin and interest
3431
- * @see https://developer-pro.bitmart.com/en/spot/#margin-repay-isolated
3432
- * @param {string} symbol unified market symbol
3433
- * @param {string} code unified currency code of the currency to repay
3434
- * @param {string} amount the amount to repay
3435
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3436
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
3437
- */
3438
- await this.loadMarkets();
3439
- const market = this.market(symbol);
3440
- const currency = this.currency(code);
3441
- const request = {
3442
- 'symbol': market['id'],
3443
- 'currency': currency['id'],
3444
- 'amount': this.currencyToPrecision(code, amount),
3445
- };
3446
- const response = await this.privatePostSpotV1MarginIsolatedRepay(this.extend(request, params));
3447
- //
3448
- // {
3449
- // "message": "OK",
3450
- // "code": 1000,
3451
- // "trace": "b0a60b4c-e986-4b54-a190-8f7c05ddf685",
3452
- // "data": {
3453
- // "repay_id": "2afcc16d99bd4707818c5a355dc89bed"
3454
- // }
3455
- // }
3456
- //
3457
- const data = this.safeValue(response, 'data', {});
3458
- const transaction = this.parseMarginLoan(data, currency);
3459
- return this.extend(transaction, {
3460
- 'amount': amount,
3461
- 'symbol': symbol,
3462
- });
3463
- }
3464
- async borrowIsolatedMargin(symbol, code, amount, params = {}) {
3465
- /**
3466
- * @method
3467
- * @name bitmart#borrowIsolatedMargin
3468
- * @description create a loan to borrow margin
3469
- * @see https://developer-pro.bitmart.com/en/spot/#margin-borrow-isolated
3470
- * @param {string} symbol unified market symbol
3471
- * @param {string} code unified currency code of the currency to borrow
3472
- * @param {string} amount the amount to borrow
3473
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3474
- * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
3475
- */
3476
- await this.loadMarkets();
3477
- const market = this.market(symbol);
3478
- const currency = this.currency(code);
3479
- const request = {
3480
- 'symbol': market['id'],
3481
- 'currency': currency['id'],
3482
- 'amount': this.currencyToPrecision(code, amount),
3483
- };
3484
- const response = await this.privatePostSpotV1MarginIsolatedBorrow(this.extend(request, params));
3485
- //
3486
- // {
3487
- // "message": "OK",
3488
- // "code": 1000,
3489
- // "trace": "e6fda683-181e-4e78-ac9c-b27c4c8ba035",
3490
- // "data": {
3491
- // "borrow_id": "629a7177a4ed4cf09869c6a4343b788c"
3492
- // }
3493
- // }
3494
- //
3495
- const data = this.safeValue(response, 'data', {});
3496
- const transaction = this.parseMarginLoan(data, currency);
3497
- return this.extend(transaction, {
3498
- 'amount': amount,
3499
- 'symbol': symbol,
3500
- });
3501
- }
3502
- parseMarginLoan(info, currency = undefined) {
3503
- //
3504
- // borrowMargin
3505
- //
3506
- // {
3507
- // "borrow_id": "629a7177a4ed4cf09869c6a4343b788c",
3508
- // }
3509
- //
3510
- // repayMargin
3511
- //
3512
- // {
3513
- // "repay_id": "2afcc16d99bd4707818c5a355dc89bed",
3514
- // }
3515
- //
3516
- return {
3517
- 'id': this.safeString2(info, 'borrow_id', 'repay_id'),
3518
- 'currency': this.safeCurrencyCode(undefined, currency),
3519
- 'amount': undefined,
3520
- 'symbol': undefined,
3521
- 'timestamp': undefined,
3522
- 'datetime': undefined,
3523
- 'info': info,
3524
- };
3525
- }
3526
- async fetchIsolatedBorrowRate(symbol, params = {}) {
3527
- /**
3528
- * @method
3529
- * @name bitmart#fetchIsolatedBorrowRate
3530
- * @description fetch the rate of interest to borrow a currency for margin trading
3531
- * @see https://developer-pro.bitmart.com/en/spot/#get-trading-pair-borrowing-rate-and-amount-keyed
3532
- * @param {string} symbol unified symbol of the market to fetch the borrow rate for
3533
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3534
- * @returns {object} an [isolated borrow rate structure]{@link https://github.com/ccxt/ccxt/wiki/Manual#isolated-borrow-rate-structure}
3535
- */
3536
- await this.loadMarkets();
3537
- const market = this.market(symbol);
3538
- const request = {
3539
- 'symbol': market['id'],
3540
- };
3541
- const response = await this.privateGetSpotV1MarginIsolatedPairs(this.extend(request, params));
3542
- //
3543
- // {
3544
- // "message": "OK",
3545
- // "code": 1000,
3546
- // "trace": "0985a130-a5ae-4fc1-863f-4704e214f585",
3547
- // "data": {
3548
- // "symbols": [
3549
- // {
3550
- // "symbol": "BTC_USDT",
3551
- // "max_leverage": "5",
3552
- // "symbol_enabled": true,
3553
- // "base": {
3554
- // "currency": "BTC",
3555
- // "daily_interest": "0.00055000",
3556
- // "hourly_interest": "0.00002291",
3557
- // "max_borrow_amount": "2.00000000",
3558
- // "min_borrow_amount": "0.00000001",
3559
- // "borrowable_amount": "0.00670810"
3560
- // },
3561
- // "quote": {
3562
- // "currency": "USDT",
3563
- // "daily_interest": "0.00055000",
3564
- // "hourly_interest": "0.00002291",
3565
- // "max_borrow_amount": "50000.00000000",
3566
- // "min_borrow_amount": "0.00000001",
3567
- // "borrowable_amount": "135.12575038"
3568
- // }
3569
- // }
3570
- // ]
3571
- // }
3572
- // }
3573
- //
3574
- const data = this.safeValue(response, 'data', {});
3575
- const symbols = this.safeValue(data, 'symbols', []);
3576
- const borrowRate = this.safeValue(symbols, 0);
3577
- return this.parseIsolatedBorrowRate(borrowRate, market);
3578
- }
3579
- parseIsolatedBorrowRate(info, market = undefined) {
3580
- //
3581
- // {
3582
- // "symbol": "BTC_USDT",
3583
- // "max_leverage": "5",
3584
- // "symbol_enabled": true,
3585
- // "base": {
3586
- // "currency": "BTC",
3587
- // "daily_interest": "0.00055000",
3588
- // "hourly_interest": "0.00002291",
3589
- // "max_borrow_amount": "2.00000000",
3590
- // "min_borrow_amount": "0.00000001",
3591
- // "borrowable_amount": "0.00670810"
3592
- // },
3593
- // "quote": {
3594
- // "currency": "USDT",
3595
- // "daily_interest": "0.00055000",
3596
- // "hourly_interest": "0.00002291",
3597
- // "max_borrow_amount": "50000.00000000",
3598
- // "min_borrow_amount": "0.00000001",
3599
- // "borrowable_amount": "135.12575038"
3600
- // }
3601
- // }
3602
- //
3603
- const marketId = this.safeString(info, 'symbol');
3604
- const symbol = this.safeSymbol(marketId, market);
3605
- const baseData = this.safeValue(info, 'base', {});
3606
- const quoteData = this.safeValue(info, 'quote', {});
3607
- const baseId = this.safeString(baseData, 'currency');
3608
- const quoteId = this.safeString(quoteData, 'currency');
3609
- return {
3610
- 'symbol': symbol,
3611
- 'base': this.safeCurrencyCode(baseId),
3612
- 'baseRate': this.safeNumber(baseData, 'hourly_interest'),
3613
- 'quote': this.safeCurrencyCode(quoteId),
3614
- 'quoteRate': this.safeNumber(quoteData, 'hourly_interest'),
3615
- 'period': 3600000,
3616
- 'timestamp': undefined,
3617
- 'datetime': undefined,
3618
- 'info': info,
3619
- };
3620
- }
3621
- async fetchIsolatedBorrowRates(params = {}) {
3622
- /**
3623
- * @method
3624
- * @name bitmart#fetchIsolatedBorrowRates
3625
- * @description fetch the borrow interest rates of all currencies, currently only works for isolated margin
3626
- * @see https://developer-pro.bitmart.com/en/spot/#get-trading-pair-borrowing-rate-and-amount-keyed
3627
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3628
- * @returns {object} a list of [isolated borrow rate structures]{@link https://docs.ccxt.com/#/?id=isolated-borrow-rate-structure}
3629
- */
3630
- await this.loadMarkets();
3631
- const response = await this.privateGetSpotV1MarginIsolatedPairs(params);
3632
- //
3633
- // {
3634
- // "message": "OK",
3635
- // "code": 1000,
3636
- // "trace": "0985a130-a5ae-4fc1-863f-4704e214f585",
3637
- // "data": {
3638
- // "symbols": [
3639
- // {
3640
- // "symbol": "BTC_USDT",
3641
- // "max_leverage": "5",
3642
- // "symbol_enabled": true,
3643
- // "base": {
3644
- // "currency": "BTC",
3645
- // "daily_interest": "0.00055000",
3646
- // "hourly_interest": "0.00002291",
3647
- // "max_borrow_amount": "2.00000000",
3648
- // "min_borrow_amount": "0.00000001",
3649
- // "borrowable_amount": "0.00670810"
3650
- // },
3651
- // "quote": {
3652
- // "currency": "USDT",
3653
- // "daily_interest": "0.00055000",
3654
- // "hourly_interest": "0.00002291",
3655
- // "max_borrow_amount": "50000.00000000",
3656
- // "min_borrow_amount": "0.00000001",
3657
- // "borrowable_amount": "135.12575038"
3658
- // }
3659
- // }
3660
- // ]
3661
- // }
3662
- // }
3663
- //
3664
- const data = this.safeValue(response, 'data', {});
3665
- const symbols = this.safeValue(data, 'symbols', []);
3666
- const result = [];
3667
- for (let i = 0; i < symbols.length; i++) {
3668
- const symbol = this.safeValue(symbols, i);
3669
- result.push(this.parseIsolatedBorrowRate(symbol));
3670
- }
3671
- return result;
3672
- }
3673
- async transfer(code, amount, fromAccount, toAccount, params = {}) {
3674
- /**
3675
- * @method
3676
- * @name bitmart#transfer
3677
- * @description transfer currency internally between wallets on the same account, currently only supports transfer between spot and margin
3678
- * @see https://developer-pro.bitmart.com/en/spot/#margin-asset-transfer-signed
3679
- * @see https://developer-pro.bitmart.com/en/futures/#transfer-signed
3680
- * @param {string} code unified currency code
3681
- * @param {float} amount amount to transfer
3682
- * @param {string} fromAccount account to transfer from
3683
- * @param {string} toAccount account to transfer to
3684
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3685
- * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
3686
- */
3687
- await this.loadMarkets();
3688
- const currency = this.currency(code);
3689
- const amountToPrecision = this.currencyToPrecision(code, amount);
3690
- const request = {
3691
- 'amount': amountToPrecision,
3692
- 'currency': currency['id'],
3693
- };
3694
- const fromId = this.convertTypeToAccount(fromAccount);
3695
- const toId = this.convertTypeToAccount(toAccount);
3696
- if (fromAccount === 'spot') {
3697
- if (toAccount === 'margin') {
3698
- request['side'] = 'in';
3699
- request['symbol'] = toId;
3700
- }
3701
- else if (toAccount === 'swap') {
3702
- request['type'] = 'spot_to_contract';
3703
- }
3704
- }
3705
- else if (toAccount === 'spot') {
3706
- if (fromAccount === 'margin') {
3707
- request['side'] = 'out';
3708
- request['symbol'] = fromId;
3709
- }
3710
- else if (fromAccount === 'swap') {
3711
- request['type'] = 'contract_to_spot';
3712
- }
3713
- }
3714
- else {
3715
- throw new errors.ArgumentsRequired(this.id + ' transfer() requires either fromAccount or toAccount to be spot');
3716
- }
3717
- let response = undefined;
3718
- if ((fromAccount === 'margin') || (toAccount === 'margin')) {
3719
- response = await this.privatePostSpotV1MarginIsolatedTransfer(this.extend(request, params));
3720
- }
3721
- else if ((fromAccount === 'swap') || (toAccount === 'swap')) {
3722
- response = await this.privatePostAccountV1TransferContract(this.extend(request, params));
3723
- }
3724
- //
3725
- // margin
3726
- //
3727
- // {
3728
- // "message": "OK",
3729
- // "code": 1000,
3730
- // "trace": "b26cecec-ef5a-47d9-9531-2bd3911d3d55",
3731
- // "data": {
3732
- // "transfer_id": "ca90d97a621e47d49774f19af6b029f5"
3733
- // }
3734
- // }
3735
- //
3736
- // swap
3737
- //
3738
- // {
3739
- // "message": "OK",
3740
- // "code": 1000,
3741
- // "trace": "4cad858074667097ac6ba5257c57305d.68.16953302431189455",
3742
- // "data": {
3743
- // "currency": "USDT",
3744
- // "amount": "5"
3745
- // }
3746
- // }
3747
- //
3748
- const data = this.safeValue(response, 'data', {});
3749
- return this.extend(this.parseTransfer(data, currency), {
3750
- 'status': this.parseTransferStatus(this.safeString2(response, 'code', 'message')),
3751
- });
3752
- }
3753
- parseTransferStatus(status) {
3754
- const statuses = {
3755
- '1000': 'ok',
3756
- 'OK': 'ok',
3757
- 'FINISHED': 'ok',
3758
- };
3759
- return this.safeString(statuses, status, status);
3760
- }
3761
- parseTransferToAccount(type) {
3762
- const types = {
3763
- 'contract_to_spot': 'spot',
3764
- 'spot_to_contract': 'swap',
3765
- };
3766
- return this.safeString(types, type, type);
3767
- }
3768
- parseTransferFromAccount(type) {
3769
- const types = {
3770
- 'contract_to_spot': 'swap',
3771
- 'spot_to_contract': 'spot',
3772
- };
3773
- return this.safeString(types, type, type);
3774
- }
3775
- parseTransfer(transfer, currency = undefined) {
3776
- //
3777
- // margin
3778
- //
3779
- // {
3780
- // "transfer_id": "ca90d97a621e47d49774f19af6b029f5"
3781
- // }
3782
- //
3783
- // swap
3784
- //
3785
- // {
3786
- // "currency": "USDT",
3787
- // "amount": "5"
3788
- // }
3789
- //
3790
- // fetchTransfers
3791
- //
3792
- // {
3793
- // "transfer_id": "902463535961567232",
3794
- // "currency": "USDT",
3795
- // "amount": "5",
3796
- // "type": "contract_to_spot",
3797
- // "state": "FINISHED",
3798
- // "timestamp": 1695330539565
3799
- // }
3800
- //
3801
- const currencyId = this.safeString(transfer, 'currency');
3802
- const timestamp = this.safeInteger(transfer, 'timestamp');
3803
- return {
3804
- 'id': this.safeString(transfer, 'transfer_id'),
3805
- 'timestamp': timestamp,
3806
- 'datetime': this.iso8601(timestamp),
3807
- 'currency': this.safeCurrencyCode(currencyId, currency),
3808
- 'amount': this.safeNumber(transfer, 'amount'),
3809
- 'fromAccount': this.parseTransferFromAccount(this.safeString(transfer, 'type')),
3810
- 'toAccount': this.parseTransferToAccount(this.safeString(transfer, 'type')),
3811
- 'status': this.parseTransferStatus(this.safeString(transfer, 'state')),
3812
- };
3813
- }
3814
- async fetchTransfers(code = undefined, since = undefined, limit = undefined, params = {}) {
3815
- /**
3816
- * @method
3817
- * @name bitmart#fetchTransfers
3818
- * @description fetch a history of internal transfers made on an account, only transfers between spot and swap are supported
3819
- * @see https://developer-pro.bitmart.com/en/futures/#get-transfer-list-signed
3820
- * @param {string} code unified currency code of the currency transferred
3821
- * @param {int} [since] the earliest time in ms to fetch transfers for
3822
- * @param {int} [limit] the maximum number of transfer structures to retrieve
3823
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3824
- * @param {int} [params.page] the required number of pages, default is 1, max is 1000
3825
- * @param {int} [params.until] the latest time in ms to fetch transfers for
3826
- * @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/#/?id=transfer-structure}
3827
- */
3828
- await this.loadMarkets();
3829
- if (limit === undefined) {
3830
- limit = 10;
3831
- }
3832
- const request = {
3833
- 'page': this.safeInteger(params, 'page', 1),
3834
- 'limit': limit, // default is 10, max is 100
3835
- };
3836
- let currency = undefined;
3837
- if (code !== undefined) {
3838
- currency = this.currency(code);
3839
- request['currency'] = currency['id'];
3840
- }
3841
- if (since !== undefined) {
3842
- request['time_start'] = since;
3843
- }
3844
- if (limit !== undefined) {
3845
- request['limit'] = limit;
3846
- }
3847
- const until = this.safeInteger2(params, 'until', 'till'); // unified in milliseconds
3848
- const endTime = this.safeInteger(params, 'time_end', until); // exchange-specific in milliseconds
3849
- params = this.omit(params, ['till', 'until']);
3850
- if (endTime !== undefined) {
3851
- request['time_end'] = endTime;
3852
- }
3853
- const response = await this.privatePostAccountV1TransferContractList(this.extend(request, params));
3854
- //
3855
- // {
3856
- // "message": "OK",
3857
- // "code": 1000,
3858
- // "trace": "7f9d93e10f9g4513bc08a7btc2a5559a.69.16953325693032193",
3859
- // "data": {
3860
- // "records": [
3861
- // {
3862
- // "transfer_id": "902463535961567232",
3863
- // "currency": "USDT",
3864
- // "amount": "5",
3865
- // "type": "contract_to_spot",
3866
- // "state": "FINISHED",
3867
- // "timestamp": 1695330539565
3868
- // },
3869
- // ]
3870
- // }
3871
- // }
3872
- //
3873
- const data = this.safeValue(response, 'data', {});
3874
- const records = this.safeValue(data, 'records', []);
3875
- return this.parseTransfers(records, currency, since, limit);
3876
- }
3877
- async fetchBorrowInterest(code = undefined, symbol = undefined, since = undefined, limit = undefined, params = {}) {
3878
- /**
3879
- * @method
3880
- * @name bitmart#fetchBorrowInterest
3881
- * @description fetch the interest owed by the user for borrowing currency for margin trading
3882
- * @see https://developer-pro.bitmart.com/en/spot/#get-borrow-record-isolated
3883
- * @param {string} code unified currency code
3884
- * @param {string} symbol unified market symbol when fetch interest in isolated markets
3885
- * @param {int} [since] the earliest time in ms to fetch borrrow interest for
3886
- * @param {int} [limit] the maximum number of structures to retrieve
3887
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3888
- * @returns {object[]} a list of [borrow interest structures]{@link https://docs.ccxt.com/#/?id=borrow-interest-structure}
3889
- */
3890
- if (symbol === undefined) {
3891
- throw new errors.ArgumentsRequired(this.id + ' fetchBorrowInterest() requires a symbol argument');
3892
- }
3893
- await this.loadMarkets();
3894
- const market = this.market(symbol);
3895
- const request = {
3896
- 'symbol': market['id'],
3897
- };
3898
- if (limit !== undefined) {
3899
- request['N'] = limit;
3900
- }
3901
- if (since !== undefined) {
3902
- request['start_time'] = since;
3903
- }
3904
- const response = await this.privateGetSpotV1MarginIsolatedBorrowRecord(this.extend(request, params));
3905
- //
3906
- // {
3907
- // "message": "OK",
3908
- // "code": 1000,
3909
- // "trace": "8ea27a2a-4aba-49fa-961d-43a0137b0ef3",
3910
- // "data": {
3911
- // "records": [
3912
- // {
3913
- // "borrow_id": "1659045283903rNvJnuRTJNL5J53n",
3914
- // "symbol": "BTC_USDT",
3915
- // "currency": "USDT",
3916
- // "borrow_amount": "100.00000000",
3917
- // "daily_interest": "0.00055000",
3918
- // "hourly_interest": "0.00002291",
3919
- // "interest_amount": "0.00229166",
3920
- // "create_time": 1659045284000
3921
- // },
3922
- // ]
3923
- // }
3924
- // }
3925
- //
3926
- const data = this.safeValue(response, 'data', {});
3927
- const rows = this.safeValue(data, 'records', []);
3928
- const interest = this.parseBorrowInterests(rows, market);
3929
- return this.filterByCurrencySinceLimit(interest, code, since, limit);
3930
- }
3931
- parseBorrowInterest(info, market = undefined) {
3932
- //
3933
- // {
3934
- // "borrow_id": "1657664327844Lk5eJJugXmdHHZoe",
3935
- // "symbol": "BTC_USDT",
3936
- // "currency": "USDT",
3937
- // "borrow_amount": "20.00000000",
3938
- // "daily_interest": "0.00055000",
3939
- // "hourly_interest": "0.00002291",
3940
- // "interest_amount": "0.00045833",
3941
- // "create_time": 1657664329000
3942
- // }
3943
- //
3944
- const marketId = this.safeString(info, 'symbol');
3945
- market = this.safeMarket(marketId, market);
3946
- const timestamp = this.safeInteger(info, 'create_time');
3947
- return {
3948
- 'symbol': this.safeString(market, 'symbol'),
3949
- 'marginMode': 'isolated',
3950
- 'currency': this.safeCurrencyCode(this.safeString(info, 'currency')),
3951
- 'interest': this.safeNumber(info, 'interest_amount'),
3952
- 'interestRate': this.safeNumber(info, 'hourly_interest'),
3953
- 'amountBorrowed': this.safeNumber(info, 'borrow_amount'),
3954
- 'timestamp': timestamp,
3955
- 'datetime': this.iso8601(timestamp),
3956
- 'info': info,
3957
- };
3958
- }
3959
- async fetchOpenInterest(symbol, params = {}) {
3960
- /**
3961
- * @method
3962
- * @name bitmart#fetchOpenInterest
3963
- * @description Retrieves the open interest of a currency
3964
- * @see https://developer-pro.bitmart.com/en/futures/#get-futures-openinterest
3965
- * @param {string} symbol Unified CCXT market symbol
3966
- * @param {object} [params] exchange specific parameters
3967
- * @returns {object} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure}
3968
- */
3969
- await this.loadMarkets();
3970
- const market = this.market(symbol);
3971
- if (!market['contract']) {
3972
- throw new errors.BadRequest(this.id + ' fetchOpenInterest() supports contract markets only');
3973
- }
3974
- const request = {
3975
- 'symbol': market['id'],
3976
- };
3977
- const response = await this.publicGetContractPublicOpenInterest(this.extend(request, params));
3978
- //
3979
- // {
3980
- // "code": 1000,
3981
- // "message": "Ok",
3982
- // "data": {
3983
- // "timestamp": 1694657502415,
3984
- // "symbol": "BTCUSDT",
3985
- // "open_interest": "265231.721368593081729069",
3986
- // "open_interest_value": "7006353.83988919"
3987
- // },
3988
- // "trace": "7f9c94e10f9d4513bc08a7bfc2a5559a.72.16946575108274991"
3989
- // }
3990
- //
3991
- const data = this.safeValue(response, 'data', {});
3992
- return this.parseOpenInterest(data, market);
3993
- }
3994
- parseOpenInterest(interest, market = undefined) {
3995
- //
3996
- // {
3997
- // "timestamp": 1694657502415,
3998
- // "symbol": "BTCUSDT",
3999
- // "open_interest": "265231.721368593081729069",
4000
- // "open_interest_value": "7006353.83988919"
4001
- // }
4002
- //
4003
- const timestamp = this.safeInteger(interest, 'timestamp');
4004
- const id = this.safeString(interest, 'symbol');
4005
- return this.safeOpenInterest({
4006
- 'symbol': this.safeSymbol(id, market),
4007
- 'openInterestAmount': this.safeNumber(interest, 'open_interest'),
4008
- 'openInterestValue': this.safeNumber(interest, 'open_interest_value'),
4009
- 'timestamp': timestamp,
4010
- 'datetime': this.iso8601(timestamp),
4011
- 'info': interest,
4012
- }, market);
4013
- }
4014
- async setLeverage(leverage, symbol = undefined, params = {}) {
4015
- /**
4016
- * @method
4017
- * @name bitmart#setLeverage
4018
- * @description set the level of leverage for a market
4019
- * @see https://developer-pro.bitmart.com/en/futures/#submit-leverage-signed
4020
- * @param {float} leverage the rate of leverage
4021
- * @param {string} symbol unified market symbol
4022
- * @param {object} [params] extra parameters specific to the exchange API endpoint
4023
- * @param {string} [params.marginMode] 'isolated' or 'cross'
4024
- * @returns {object} response from the exchange
4025
- */
4026
- if (symbol === undefined) {
4027
- throw new errors.ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
4028
- }
4029
- let marginMode = undefined;
4030
- [marginMode, params] = this.handleMarginModeAndParams('setLeverage', params);
4031
- this.checkRequiredArgument('setLeverage', marginMode, 'marginMode', ['isolated', 'cross']);
4032
- await this.loadMarkets();
4033
- const market = this.market(symbol);
4034
- if (!market['swap']) {
4035
- throw new errors.BadSymbol(this.id + ' setLeverage() supports swap contracts only');
4036
- }
4037
- const request = {
4038
- 'symbol': market['id'],
4039
- 'leverage': leverage.toString(),
4040
- 'open_type': marginMode,
4041
- };
4042
- return await this.privatePostContractPrivateSubmitLeverage(this.extend(request, params));
4043
- }
4044
- async fetchFundingRate(symbol, params = {}) {
4045
- /**
4046
- * @method
4047
- * @name bitmart#fetchFundingRate
4048
- * @description fetch the current funding rate
4049
- * @see https://developer-pro.bitmart.com/en/futures/#get-current-funding-rate
4050
- * @param {string} symbol unified market symbol
4051
- * @param {object} [params] extra parameters specific to the exchange API endpoint
4052
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
4053
- */
4054
- await this.loadMarkets();
4055
- const market = this.market(symbol);
4056
- if (!market['swap']) {
4057
- throw new errors.BadSymbol(this.id + ' fetchFundingRate() supports swap contracts only');
4058
- }
4059
- const request = {
4060
- 'symbol': market['id'],
4061
- };
4062
- const response = await this.publicGetContractPublicFundingRate(this.extend(request, params));
4063
- //
4064
- // {
4065
- // "code": 1000,
4066
- // "message": "Ok",
4067
- // "data": {
4068
- // "timestamp": 1695184410697,
4069
- // "symbol": "BTCUSDT",
4070
- // "rate_value": "-0.00002614",
4071
- // "expected_rate": "-0.00002"
4072
- // },
4073
- // "trace": "4cad855074654097ac7ba5257c47305d.54.16951844206655589"
4074
- // }
4075
- //
4076
- const data = this.safeValue(response, 'data', {});
4077
- return this.parseFundingRate(data, market);
4078
- }
4079
- parseFundingRate(contract, market = undefined) {
4080
- //
4081
- // {
4082
- // "timestamp": 1695184410697,
4083
- // "symbol": "BTCUSDT",
4084
- // "rate_value": "-0.00002614",
4085
- // "expected_rate": "-0.00002"
4086
- // }
4087
- //
4088
- const marketId = this.safeString(contract, 'symbol');
4089
- const timestamp = this.safeInteger(contract, 'timestamp');
4090
- return {
4091
- 'info': contract,
4092
- 'symbol': this.safeSymbol(marketId, market),
4093
- 'markPrice': undefined,
4094
- 'indexPrice': undefined,
4095
- 'interestRate': undefined,
4096
- 'estimatedSettlePrice': undefined,
4097
- 'timestamp': timestamp,
4098
- 'datetime': this.iso8601(timestamp),
4099
- 'fundingRate': this.safeNumber(contract, 'expected_rate'),
4100
- 'fundingTimestamp': undefined,
4101
- 'fundingDatetime': undefined,
4102
- 'nextFundingRate': undefined,
4103
- 'nextFundingTimestamp': undefined,
4104
- 'nextFundingDatetime': undefined,
4105
- 'previousFundingRate': this.safeNumber(contract, 'rate_value'),
4106
- 'previousFundingTimestamp': undefined,
4107
- 'previousFundingDatetime': undefined,
4108
- };
4109
- }
4110
- async fetchPosition(symbol, params = {}) {
4111
- /**
4112
- * @method
4113
- * @name bitmart#fetchPosition
4114
- * @description fetch data on a single open contract trade position
4115
- * @see https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
4116
- * @param {string} symbol unified market symbol of the market the position is held in
4117
- * @param {object} [params] extra parameters specific to the exchange API endpoint
4118
- * @returns {object} a [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
4119
- */
4120
- await this.loadMarkets();
4121
- const market = this.market(symbol);
4122
- const request = {
4123
- 'symbol': market['id'],
4124
- };
4125
- const response = await this.privateGetContractPrivatePosition(this.extend(request, params));
4126
- //
4127
- // {
4128
- // "code": 1000,
4129
- // "message": "Ok",
4130
- // "data": [
4131
- // {
4132
- // "symbol": "BTCUSDT",
4133
- // "leverage": "10",
4134
- // "timestamp": 1696392515269,
4135
- // "current_fee": "0.0014250028",
4136
- // "open_timestamp": 1696392256998,
4137
- // "current_value": "27.4039",
4138
- // "mark_price": "27.4039",
4139
- // "position_value": "27.4079",
4140
- // "position_cross": "3.75723474",
4141
- // "maintenance_margin": "0.1370395",
4142
- // "close_vol": "0",
4143
- // "close_avg_price": "0",
4144
- // "open_avg_price": "27407.9",
4145
- // "entry_price": "27407.9",
4146
- // "current_amount": "1",
4147
- // "unrealized_value": "-0.004",
4148
- // "realized_value": "-0.01644474",
4149
- // "position_type": 1
4150
- // }
4151
- // ],
4152
- // "trace":"4cad855074664097ac5ba5257c47305d.67.16963925142065945"
4153
- // }
4154
- //
4155
- const data = this.safeValue(response, 'data', []);
4156
- const first = this.safeValue(data, 0, {});
4157
- return this.parsePosition(first, market);
4158
- }
4159
- async fetchPositions(symbols = undefined, params = {}) {
4160
- /**
4161
- * @method
4162
- * @name bitmart#fetchPositions
4163
- * @description fetch all open contract positions
4164
- * @see https://developer-pro.bitmart.com/en/futures/#get-current-position-keyed
4165
- * @param {string[]|undefined} symbols list of unified market symbols
4166
- * @param {object} [params] extra parameters specific to the exchange API endpoint
4167
- * @returns {object[]} a list of [position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
4168
- */
4169
- await this.loadMarkets();
4170
- let market = undefined;
4171
- let symbolsLength = undefined;
4172
- if (symbols !== undefined) {
4173
- symbolsLength = symbols.length;
4174
- const first = this.safeString(symbols, 0);
4175
- market = this.market(first);
4176
- }
4177
- const request = {};
4178
- if (symbolsLength === 1) {
4179
- // only supports symbols as undefined or sending one symbol
4180
- request['symbol'] = market['id'];
4181
- }
4182
- const response = await this.privateGetContractPrivatePosition(this.extend(request, params));
4183
- //
4184
- // {
4185
- // "code": 1000,
4186
- // "message": "Ok",
4187
- // "data": [
4188
- // {
4189
- // "symbol": "BTCUSDT",
4190
- // "leverage": "10",
4191
- // "timestamp": 1696392515269,
4192
- // "current_fee": "0.0014250028",
4193
- // "open_timestamp": 1696392256998,
4194
- // "current_value": "27.4039",
4195
- // "mark_price": "27.4039",
4196
- // "position_value": "27.4079",
4197
- // "position_cross": "3.75723474",
4198
- // "maintenance_margin": "0.1370395",
4199
- // "close_vol": "0",
4200
- // "close_avg_price": "0",
4201
- // "open_avg_price": "27407.9",
4202
- // "entry_price": "27407.9",
4203
- // "current_amount": "1",
4204
- // "unrealized_value": "-0.004",
4205
- // "realized_value": "-0.01644474",
4206
- // "position_type": 1
4207
- // },
4208
- // ],
4209
- // "trace":"4cad855074664097ac5ba5257c47305d.67.16963925142065945"
4210
- // }
4211
- //
4212
- const positions = this.safeValue(response, 'data', []);
4213
- const result = [];
4214
- for (let i = 0; i < positions.length; i++) {
4215
- result.push(this.parsePosition(positions[i]));
4216
- }
4217
- symbols = this.marketSymbols(symbols);
4218
- return this.filterByArrayPositions(result, 'symbol', symbols, false);
4219
- }
4220
- parsePosition(position, market = undefined) {
4221
- //
4222
- // {
4223
- // "symbol": "BTCUSDT",
4224
- // "leverage": "10",
4225
- // "timestamp": 1696392515269,
4226
- // "current_fee": "0.0014250028",
4227
- // "open_timestamp": 1696392256998,
4228
- // "current_value": "27.4039",
4229
- // "mark_price": "27.4039",
4230
- // "position_value": "27.4079",
4231
- // "position_cross": "3.75723474",
4232
- // "maintenance_margin": "0.1370395",
4233
- // "close_vol": "0",
4234
- // "close_avg_price": "0",
4235
- // "open_avg_price": "27407.9",
4236
- // "entry_price": "27407.9",
4237
- // "current_amount": "1",
4238
- // "unrealized_value": "-0.004",
4239
- // "realized_value": "-0.01644474",
4240
- // "position_type": 1
4241
- // }
4242
- //
4243
- const marketId = this.safeString(position, 'symbol');
4244
- market = this.safeMarket(marketId, market);
4245
- const symbol = market['symbol'];
4246
- const timestamp = this.safeInteger(position, 'timestamp');
4247
- const side = this.safeInteger(position, 'position_type');
4248
- const maintenanceMargin = this.safeString(position, 'maintenance_margin');
4249
- const notional = this.safeString(position, 'current_value');
4250
- const collateral = this.safeString(position, 'position_cross');
4251
- const maintenanceMarginPercentage = Precise["default"].stringDiv(maintenanceMargin, notional);
4252
- const marginRatio = Precise["default"].stringDiv(maintenanceMargin, collateral);
4253
- return this.safePosition({
4254
- 'info': position,
4255
- 'id': undefined,
4256
- 'symbol': symbol,
4257
- 'timestamp': timestamp,
4258
- 'datetime': this.iso8601(timestamp),
4259
- 'lastUpdateTimestamp': undefined,
4260
- 'hedged': undefined,
4261
- 'side': (side === 1) ? 'long' : 'short',
4262
- 'contracts': this.safeNumber(position, 'current_amount'),
4263
- 'contractSize': this.safeNumber(market, 'contractSize'),
4264
- 'entryPrice': this.safeNumber(position, 'entry_price'),
4265
- 'markPrice': this.safeNumber(position, 'mark_price'),
4266
- 'lastPrice': undefined,
4267
- 'notional': this.parseNumber(notional),
4268
- 'leverage': this.safeNumber(position, 'leverage'),
4269
- 'collateral': this.parseNumber(collateral),
4270
- 'initialMargin': undefined,
4271
- 'initialMarginPercentage': undefined,
4272
- 'maintenanceMargin': this.parseNumber(maintenanceMargin),
4273
- 'maintenanceMarginPercentage': this.parseNumber(maintenanceMarginPercentage),
4274
- 'unrealizedPnl': this.safeNumber(position, 'unrealized_value'),
4275
- 'realizedPnl': this.safeNumber(position, 'realized_value'),
4276
- 'liquidationPrice': undefined,
4277
- 'marginMode': undefined,
4278
- 'percentage': undefined,
4279
- 'marginRatio': this.parseNumber(marginRatio),
4280
- 'stopLossPrice': undefined,
4281
- 'takeProfitPrice': undefined,
4282
- });
4283
- }
4284
- async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
4285
- /**
4286
- * @method
4287
- * @name bitmart#fetchMyLiquidations
4288
- * @description retrieves the users liquidated positions
4289
- * @see https://developer-pro.bitmart.com/en/futures/#get-order-history-keyed
4290
- * @param {string} symbol unified CCXT market symbol
4291
- * @param {int} [since] the earliest time in ms to fetch liquidations for
4292
- * @param {int} [limit] the maximum number of liquidation structures to retrieve
4293
- * @param {object} [params] exchange specific parameters for the bitmart api endpoint
4294
- * @param {int} [params.until] timestamp in ms of the latest liquidation
4295
- * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
4296
- */
4297
- if (symbol === undefined) {
4298
- throw new errors.ArgumentsRequired(this.id + ' fetchMyLiquidations() requires a symbol argument');
4299
- }
4300
- await this.loadMarkets();
4301
- const market = this.market(symbol);
4302
- if (!market['swap']) {
4303
- throw new errors.NotSupported(this.id + ' fetchMyLiquidations() supports swap markets only');
4304
- }
4305
- let request = {
4306
- 'symbol': market['id'],
4307
- };
4308
- if (since !== undefined) {
4309
- request['start_time'] = since;
4310
- }
4311
- [request, params] = this.handleUntilOption('end_time', request, params);
4312
- const response = await this.privateGetContractPrivateOrderHistory(this.extend(request, params));
4313
- //
4314
- // {
4315
- // "code": 1000,
4316
- // "message": "Ok",
4317
- // "data": [
4318
- // {
4319
- // "order_id": "231007865458273",
4320
- // "client_order_id": "",
4321
- // "price": "27407.9",
4322
- // "size": "1",
4323
- // "symbol": "BTCUSDT",
4324
- // "state": 4,
4325
- // "side": 3,
4326
- // "type": "liquidate",
4327
- // "leverage": "10",
4328
- // "open_type": "isolated",
4329
- // "deal_avg_price": "27422.6",
4330
- // "deal_size": "1",
4331
- // "create_time": 1696405864011,
4332
- // "update_time": 1696405864045
4333
- // },
4334
- // ],
4335
- // "trace": "4cad855074664097ac6ba4257c47305d.71.16965658195443021"
4336
- // }
4337
- //
4338
- const data = this.safeValue(response, 'data', []);
4339
- const result = [];
4340
- for (let i = 0; i < data.length; i++) {
4341
- const entry = data[i];
4342
- const checkLiquidation = this.safeString(entry, 'type');
4343
- if (checkLiquidation === 'liquidate') {
4344
- result.push(entry);
4345
- }
4346
- }
4347
- return this.parseLiquidations(result, market, since, limit);
4348
- }
4349
- parseLiquidation(liquidation, market = undefined) {
4350
- //
4351
- // {
4352
- // "order_id": "231007865458273",
4353
- // "client_order_id": "",
4354
- // "price": "27407.9",
4355
- // "size": "1",
4356
- // "symbol": "BTCUSDT",
4357
- // "state": 4,
4358
- // "side": 3,
4359
- // "type": "market",
4360
- // "leverage": "10",
4361
- // "open_type": "isolated",
4362
- // "deal_avg_price": "27422.6",
4363
- // "deal_size": "1",
4364
- // "create_time": 1696405864011,
4365
- // "update_time": 1696405864045
4366
- // }
4367
- //
4368
- const marketId = this.safeString(liquidation, 'symbol');
4369
- const timestamp = this.safeInteger(liquidation, 'update_time');
4370
- const contractsString = this.safeString(liquidation, 'deal_size');
4371
- const contractSizeString = this.safeString(market, 'contractSize');
4372
- const priceString = this.safeString(liquidation, 'deal_avg_price');
4373
- const baseValueString = Precise["default"].stringMul(contractsString, contractSizeString);
4374
- const quoteValueString = Precise["default"].stringMul(baseValueString, priceString);
4375
- return this.safeLiquidation({
4376
- 'info': liquidation,
4377
- 'symbol': this.safeSymbol(marketId, market),
4378
- 'contracts': this.parseNumber(contractsString),
4379
- 'contractSize': this.parseNumber(contractSizeString),
4380
- 'price': this.parseNumber(priceString),
4381
- 'baseValue': this.parseNumber(baseValueString),
4382
- 'quoteValue': this.parseNumber(quoteValueString),
4383
- 'timestamp': timestamp,
4384
- 'datetime': this.iso8601(timestamp),
4385
- });
4386
- }
4387
- nonce() {
4388
- return this.milliseconds();
4389
- }
4390
- sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
4391
- const baseUrl = this.implodeHostname(this.urls['api']['rest']);
4392
- let url = baseUrl + '/' + this.implodeParams(path, params);
4393
- const query = this.omit(params, this.extractParams(path));
4394
- let queryString = '';
4395
- const getOrDelete = (method === 'GET') || (method === 'DELETE');
4396
- if (getOrDelete) {
4397
- if (Object.keys(query).length) {
4398
- queryString = this.urlencode(query);
4399
- url += '?' + queryString;
4400
- }
4401
- }
4402
- if (api === 'private') {
4403
- this.checkRequiredCredentials();
4404
- const timestamp = this.milliseconds().toString();
4405
- const brokerId = this.safeString(this.options, 'brokerId', 'CCXTxBitmart000');
4406
- headers = {
4407
- 'X-BM-KEY': this.apiKey,
4408
- 'X-BM-TIMESTAMP': timestamp,
4409
- 'X-BM-BROKER-ID': brokerId,
4410
- 'Content-Type': 'application/json',
4411
- };
4412
- if (!getOrDelete) {
4413
- body = this.json(query);
4414
- queryString = body;
4415
- }
4416
- const auth = timestamp + '#' + this.uid + '#' + queryString;
4417
- const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
4418
- headers['X-BM-SIGN'] = signature;
4419
- }
4420
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
4421
- }
4422
- handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
4423
- if (response === undefined) {
4424
- return undefined;
4425
- }
4426
- //
4427
- // spot
4428
- //
4429
- // {"message":"Bad Request [to is empty]","code":50000,"trace":"f9d46e1b-4edb-4d07-a06e-4895fb2fc8fc","data":{}}
4430
- // {"message":"Bad Request [from is empty]","code":50000,"trace":"579986f7-c93a-4559-926b-06ba9fa79d76","data":{}}
4431
- // {"message":"Kline size over 500","code":50004,"trace":"d625caa8-e8ca-4bd2-b77c-958776965819","data":{}}
4432
- // {"message":"Balance not enough","code":50020,"trace":"7c709d6a-3292-462c-98c5-32362540aeef","data":{}}
4433
- //
4434
- // contract
4435
- //
4436
- // {"errno":"OK","message":"INVALID_PARAMETER","code":49998,"trace":"eb5ebb54-23cd-4de2-9064-e090b6c3b2e3","data":null}
4437
- //
4438
- const message = this.safeStringLower(response, 'message');
4439
- const isErrorMessage = (message !== undefined) && (message !== 'ok') && (message !== 'success');
4440
- const errorCode = this.safeString(response, 'code');
4441
- const isErrorCode = (errorCode !== undefined) && (errorCode !== '1000');
4442
- if (isErrorCode || isErrorMessage) {
4443
- const feedback = this.id + ' ' + body;
4444
- this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
4445
- this.throwBroadlyMatchedException(this.exceptions['broad'], errorCode, feedback);
4446
- this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
4447
- this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
4448
- throw new errors.ExchangeError(feedback); // unknown message
4449
- }
4450
- return undefined;
4451
- }
4452
- }
4453
-
4454
- module.exports = bitmart;