ccxt 4.2.17 → 4.2.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (439) hide show
  1. package/README.md +9 -9
  2. package/dist/ccxt.browser.js +48992 -47725
  3. package/dist/ccxt.browser.min.js +3 -3
  4. package/dist/cjs/ccxt.js +12 -1
  5. package/dist/cjs/src/alpaca.js +18 -18
  6. package/dist/cjs/src/ascendex.js +13 -6
  7. package/dist/cjs/src/base/Exchange.js +266 -27
  8. package/dist/cjs/src/bigone.js +434 -168
  9. package/dist/cjs/src/binance.js +163 -34
  10. package/dist/cjs/src/binanceus.js +8 -0
  11. package/dist/cjs/src/bingx.js +183 -41
  12. package/dist/cjs/src/bitfinex.js +2 -3
  13. package/dist/cjs/src/bitget.js +59 -16
  14. package/dist/cjs/src/bitmart.js +5 -5
  15. package/dist/cjs/src/bitmex.js +4 -6
  16. package/dist/cjs/src/bitpanda.js +5 -1991
  17. package/dist/cjs/src/bitstamp.js +8 -0
  18. package/dist/cjs/src/bybit.js +27 -47
  19. package/dist/cjs/src/coinbase.js +176 -26
  20. package/dist/cjs/src/coincheck.js +1 -0
  21. package/dist/cjs/src/coinex.js +3 -0
  22. package/dist/cjs/src/coinlist.js +13 -6
  23. package/dist/cjs/src/coinone.js +2 -2
  24. package/dist/cjs/src/coinsph.js +4 -5
  25. package/dist/cjs/src/delta.js +7 -1
  26. package/dist/cjs/src/deribit.js +17 -4
  27. package/dist/cjs/src/gate.js +151 -169
  28. package/dist/cjs/src/gemini.js +1 -1
  29. package/dist/cjs/src/hitbtc.js +2 -3
  30. package/dist/cjs/src/htx.js +157 -7
  31. package/dist/cjs/src/huobijp.js +2 -3
  32. package/dist/cjs/src/independentreserve.js +7 -5
  33. package/dist/cjs/src/kraken.js +86 -54
  34. package/dist/cjs/src/kucoin.js +5 -0
  35. package/dist/cjs/src/kucoinfutures.js +131 -77
  36. package/dist/cjs/src/lbank.js +60 -33
  37. package/dist/cjs/src/luno.js +84 -2
  38. package/dist/cjs/src/mexc.js +3 -3
  39. package/dist/cjs/src/oceanex.js +1 -1
  40. package/dist/cjs/src/okx.js +23 -11
  41. package/dist/cjs/{js/src/bitpanda.js → src/onetrading.js} +39 -39
  42. package/dist/cjs/src/phemex.js +37 -27
  43. package/dist/cjs/src/poloniexfutures.js +1 -0
  44. package/dist/cjs/src/pro/binance.js +66 -25
  45. package/dist/cjs/src/pro/bitget.js +1 -1
  46. package/dist/cjs/src/pro/bitpanda.js +5 -1330
  47. package/dist/cjs/src/pro/coinbase.js +4 -1
  48. package/dist/cjs/src/pro/coincheck.js +208 -0
  49. package/dist/cjs/src/pro/hitbtc.js +5 -4
  50. package/dist/cjs/src/pro/htx.js +6 -1
  51. package/dist/cjs/src/pro/kraken.js +1 -1
  52. package/dist/cjs/src/pro/krakenfutures.js +7 -1
  53. package/dist/cjs/src/pro/kucoin.js +46 -36
  54. package/dist/cjs/src/pro/kucoinfutures.js +45 -37
  55. package/dist/cjs/src/pro/lbank.js +881 -0
  56. package/dist/cjs/src/pro/okx.js +52 -2
  57. package/dist/cjs/{js/src/pro/bitpanda.js → src/pro/onetrading.js} +4 -7
  58. package/dist/cjs/src/pro/poloniex.js +2 -2
  59. package/dist/cjs/src/pro/poloniexfutures.js +43 -35
  60. package/dist/cjs/src/pro/woo.js +126 -0
  61. package/dist/cjs/src/probit.js +4 -2
  62. package/dist/cjs/src/upbit.js +12 -12
  63. package/dist/cjs/src/wavesexchange.js +1 -1
  64. package/dist/cjs/src/whitebit.js +1 -0
  65. package/dist/cjs/src/woo.js +56 -0
  66. package/js/ccxt.d.ts +14 -2
  67. package/js/ccxt.js +10 -2
  68. package/js/src/abstract/bitpanda.d.ts +4 -4
  69. package/js/src/abstract/bitstamp.d.ts +8 -0
  70. package/js/src/abstract/gate.d.ts +1 -0
  71. package/js/src/abstract/gateio.d.ts +1 -0
  72. package/js/src/abstract/htx.d.ts +3 -0
  73. package/js/src/abstract/huobi.d.ts +3 -0
  74. package/js/src/abstract/luno.d.ts +1 -0
  75. package/js/src/abstract/onetrading.d.ts +38 -0
  76. package/js/src/ascendex.js +2 -0
  77. package/js/src/base/Exchange.d.ts +2 -3
  78. package/js/src/base/Exchange.js +5 -2
  79. package/js/src/binance.js +7 -1
  80. package/js/src/bingx.d.ts +1 -0
  81. package/js/src/bingx.js +26 -0
  82. package/js/src/bitget.js +22 -3
  83. package/js/src/bitpanda.d.ts +2 -72
  84. package/js/src/bitpanda.js +5 -1991
  85. package/js/src/bitstamp.js +8 -0
  86. package/js/src/bybit.js +21 -47
  87. package/js/src/coincheck.js +1 -0
  88. package/js/src/deribit.js +16 -4
  89. package/js/src/gate.d.ts +1 -0
  90. package/js/src/gate.js +50 -110
  91. package/js/src/htx.js +3 -0
  92. package/js/src/kraken.d.ts +1 -0
  93. package/js/src/kraken.js +40 -39
  94. package/js/src/lbank.js +1 -0
  95. package/js/src/luno.d.ts +3 -1
  96. package/js/src/luno.js +84 -2
  97. package/js/src/mexc.js +1 -2
  98. package/js/src/onetrading.d.ts +74 -0
  99. package/js/src/onetrading.js +2003 -0
  100. package/js/src/poloniexfutures.js +1 -0
  101. package/js/src/pro/binance.js +7 -2
  102. package/js/src/pro/bitget.js +1 -1
  103. package/js/src/pro/bitpanda.d.ts +2 -34
  104. package/js/src/pro/bitpanda.js +5 -1330
  105. package/js/src/pro/coincheck.d.ts +12 -0
  106. package/js/src/pro/coincheck.js +209 -0
  107. package/js/src/pro/kucoin.js +43 -35
  108. package/js/src/pro/kucoinfutures.js +45 -37
  109. package/js/src/pro/lbank.d.ts +29 -0
  110. package/js/src/pro/lbank.js +882 -0
  111. package/js/src/pro/onetrading.d.ts +36 -0
  112. package/js/src/pro/onetrading.js +1339 -0
  113. package/js/src/pro/poloniexfutures.js +43 -35
  114. package/js/src/whitebit.js +1 -0
  115. package/package.json +2 -2
  116. package/rollup.config.js +2 -0
  117. package/skip-tests.json +14 -2
  118. package/test-commonjs.cjs +25 -1
  119. package/dist/cjs/js/ccxt.js +0 -476
  120. package/dist/cjs/js/src/abstract/alpaca.js +0 -9
  121. package/dist/cjs/js/src/abstract/ascendex.js +0 -9
  122. package/dist/cjs/js/src/abstract/bigone.js +0 -9
  123. package/dist/cjs/js/src/abstract/binance.js +0 -9
  124. package/dist/cjs/js/src/abstract/bingx.js +0 -9
  125. package/dist/cjs/js/src/abstract/bit2c.js +0 -9
  126. package/dist/cjs/js/src/abstract/bitbank.js +0 -9
  127. package/dist/cjs/js/src/abstract/bitbns.js +0 -9
  128. package/dist/cjs/js/src/abstract/bitfinex.js +0 -9
  129. package/dist/cjs/js/src/abstract/bitfinex2.js +0 -9
  130. package/dist/cjs/js/src/abstract/bitflyer.js +0 -9
  131. package/dist/cjs/js/src/abstract/bitforex.js +0 -9
  132. package/dist/cjs/js/src/abstract/bitget.js +0 -9
  133. package/dist/cjs/js/src/abstract/bithumb.js +0 -9
  134. package/dist/cjs/js/src/abstract/bitmart.js +0 -9
  135. package/dist/cjs/js/src/abstract/bitmex.js +0 -9
  136. package/dist/cjs/js/src/abstract/bitopro.js +0 -9
  137. package/dist/cjs/js/src/abstract/bitpanda.js +0 -9
  138. package/dist/cjs/js/src/abstract/bitrue.js +0 -9
  139. package/dist/cjs/js/src/abstract/bitso.js +0 -9
  140. package/dist/cjs/js/src/abstract/bitstamp.js +0 -9
  141. package/dist/cjs/js/src/abstract/bitteam.js +0 -9
  142. package/dist/cjs/js/src/abstract/bitvavo.js +0 -9
  143. package/dist/cjs/js/src/abstract/bl3p.js +0 -9
  144. package/dist/cjs/js/src/abstract/blockchaincom.js +0 -9
  145. package/dist/cjs/js/src/abstract/btcalpha.js +0 -9
  146. package/dist/cjs/js/src/abstract/btcbox.js +0 -9
  147. package/dist/cjs/js/src/abstract/btcmarkets.js +0 -9
  148. package/dist/cjs/js/src/abstract/btcturk.js +0 -9
  149. package/dist/cjs/js/src/abstract/bybit.js +0 -9
  150. package/dist/cjs/js/src/abstract/cex.js +0 -9
  151. package/dist/cjs/js/src/abstract/coinbase.js +0 -9
  152. package/dist/cjs/js/src/abstract/coinbasepro.js +0 -9
  153. package/dist/cjs/js/src/abstract/coincheck.js +0 -9
  154. package/dist/cjs/js/src/abstract/coinex.js +0 -9
  155. package/dist/cjs/js/src/abstract/coinlist.js +0 -9
  156. package/dist/cjs/js/src/abstract/coinmate.js +0 -9
  157. package/dist/cjs/js/src/abstract/coinone.js +0 -9
  158. package/dist/cjs/js/src/abstract/coinsph.js +0 -9
  159. package/dist/cjs/js/src/abstract/coinspot.js +0 -9
  160. package/dist/cjs/js/src/abstract/cryptocom.js +0 -9
  161. package/dist/cjs/js/src/abstract/currencycom.js +0 -9
  162. package/dist/cjs/js/src/abstract/delta.js +0 -9
  163. package/dist/cjs/js/src/abstract/deribit.js +0 -9
  164. package/dist/cjs/js/src/abstract/digifinex.js +0 -9
  165. package/dist/cjs/js/src/abstract/exmo.js +0 -9
  166. package/dist/cjs/js/src/abstract/gate.js +0 -9
  167. package/dist/cjs/js/src/abstract/gemini.js +0 -9
  168. package/dist/cjs/js/src/abstract/hitbtc.js +0 -9
  169. package/dist/cjs/js/src/abstract/hollaex.js +0 -9
  170. package/dist/cjs/js/src/abstract/htx.js +0 -9
  171. package/dist/cjs/js/src/abstract/huobijp.js +0 -9
  172. package/dist/cjs/js/src/abstract/idex.js +0 -9
  173. package/dist/cjs/js/src/abstract/independentreserve.js +0 -9
  174. package/dist/cjs/js/src/abstract/indodax.js +0 -9
  175. package/dist/cjs/js/src/abstract/kraken.js +0 -9
  176. package/dist/cjs/js/src/abstract/krakenfutures.js +0 -9
  177. package/dist/cjs/js/src/abstract/kucoin.js +0 -9
  178. package/dist/cjs/js/src/abstract/kucoinfutures.js +0 -9
  179. package/dist/cjs/js/src/abstract/kuna.js +0 -9
  180. package/dist/cjs/js/src/abstract/latoken.js +0 -9
  181. package/dist/cjs/js/src/abstract/lbank.js +0 -9
  182. package/dist/cjs/js/src/abstract/luno.js +0 -9
  183. package/dist/cjs/js/src/abstract/lykke.js +0 -9
  184. package/dist/cjs/js/src/abstract/mercado.js +0 -9
  185. package/dist/cjs/js/src/abstract/mexc.js +0 -9
  186. package/dist/cjs/js/src/abstract/ndax.js +0 -9
  187. package/dist/cjs/js/src/abstract/novadax.js +0 -9
  188. package/dist/cjs/js/src/abstract/oceanex.js +0 -9
  189. package/dist/cjs/js/src/abstract/okcoin.js +0 -9
  190. package/dist/cjs/js/src/abstract/okx.js +0 -9
  191. package/dist/cjs/js/src/abstract/p2b.js +0 -9
  192. package/dist/cjs/js/src/abstract/paymium.js +0 -9
  193. package/dist/cjs/js/src/abstract/phemex.js +0 -9
  194. package/dist/cjs/js/src/abstract/poloniex.js +0 -9
  195. package/dist/cjs/js/src/abstract/poloniexfutures.js +0 -9
  196. package/dist/cjs/js/src/abstract/probit.js +0 -9
  197. package/dist/cjs/js/src/abstract/timex.js +0 -9
  198. package/dist/cjs/js/src/abstract/tokocrypto.js +0 -9
  199. package/dist/cjs/js/src/abstract/upbit.js +0 -9
  200. package/dist/cjs/js/src/abstract/wavesexchange.js +0 -9
  201. package/dist/cjs/js/src/abstract/wazirx.js +0 -9
  202. package/dist/cjs/js/src/abstract/whitebit.js +0 -9
  203. package/dist/cjs/js/src/abstract/woo.js +0 -9
  204. package/dist/cjs/js/src/abstract/yobit.js +0 -9
  205. package/dist/cjs/js/src/abstract/zaif.js +0 -9
  206. package/dist/cjs/js/src/abstract/zonda.js +0 -9
  207. package/dist/cjs/js/src/ace.js +0 -1058
  208. package/dist/cjs/js/src/alpaca.js +0 -1125
  209. package/dist/cjs/js/src/ascendex.js +0 -3365
  210. package/dist/cjs/js/src/base/Exchange.js +0 -5257
  211. package/dist/cjs/js/src/base/Precise.js +0 -263
  212. package/dist/cjs/js/src/base/errors.js +0 -299
  213. package/dist/cjs/js/src/base/functions/crypto.js +0 -78
  214. package/dist/cjs/js/src/base/functions/encode.js +0 -44
  215. package/dist/cjs/js/src/base/functions/generic.js +0 -193
  216. package/dist/cjs/js/src/base/functions/misc.js +0 -96
  217. package/dist/cjs/js/src/base/functions/number.js +0 -297
  218. package/dist/cjs/js/src/base/functions/platform.js +0 -28
  219. package/dist/cjs/js/src/base/functions/rsa.js +0 -34
  220. package/dist/cjs/js/src/base/functions/string.js +0 -48
  221. package/dist/cjs/js/src/base/functions/throttle.js +0 -66
  222. package/dist/cjs/js/src/base/functions/time.js +0 -187
  223. package/dist/cjs/js/src/base/functions/totp.js +0 -24
  224. package/dist/cjs/js/src/base/functions/type.js +0 -162
  225. package/dist/cjs/js/src/base/functions.js +0 -157
  226. package/dist/cjs/js/src/base/ws/Cache.js +0 -254
  227. package/dist/cjs/js/src/base/ws/Client.js +0 -299
  228. package/dist/cjs/js/src/base/ws/Future.js +0 -34
  229. package/dist/cjs/js/src/base/ws/OrderBook.js +0 -107
  230. package/dist/cjs/js/src/base/ws/OrderBookSide.js +0 -281
  231. package/dist/cjs/js/src/base/ws/WsClient.js +0 -69
  232. package/dist/cjs/js/src/bequant.js +0 -33
  233. package/dist/cjs/js/src/bigone.js +0 -2213
  234. package/dist/cjs/js/src/binance.js +0 -9845
  235. package/dist/cjs/js/src/binancecoinm.js +0 -45
  236. package/dist/cjs/js/src/binanceus.js +0 -92
  237. package/dist/cjs/js/src/binanceusdm.js +0 -58
  238. package/dist/cjs/js/src/bingx.js +0 -3846
  239. package/dist/cjs/js/src/bit2c.js +0 -916
  240. package/dist/cjs/js/src/bitbank.js +0 -1000
  241. package/dist/cjs/js/src/bitbay.js +0 -17
  242. package/dist/cjs/js/src/bitbns.js +0 -1220
  243. package/dist/cjs/js/src/bitcoincom.js +0 -17
  244. package/dist/cjs/js/src/bitfinex.js +0 -1670
  245. package/dist/cjs/js/src/bitfinex2.js +0 -2990
  246. package/dist/cjs/js/src/bitflyer.js +0 -1045
  247. package/dist/cjs/js/src/bitforex.js +0 -852
  248. package/dist/cjs/js/src/bitget.js +0 -8295
  249. package/dist/cjs/js/src/bithumb.js +0 -1090
  250. package/dist/cjs/js/src/bitmart.js +0 -4454
  251. package/dist/cjs/js/src/bitmex.js +0 -2881
  252. package/dist/cjs/js/src/bitopro.js +0 -1724
  253. package/dist/cjs/js/src/bitrue.js +0 -3253
  254. package/dist/cjs/js/src/bitso.js +0 -1753
  255. package/dist/cjs/js/src/bitstamp.js +0 -2188
  256. package/dist/cjs/js/src/bitteam.js +0 -2309
  257. package/dist/cjs/js/src/bitvavo.js +0 -1968
  258. package/dist/cjs/js/src/bl3p.js +0 -447
  259. package/dist/cjs/js/src/blockchaincom.js +0 -1160
  260. package/dist/cjs/js/src/btcalpha.js +0 -929
  261. package/dist/cjs/js/src/btcbox.js +0 -565
  262. package/dist/cjs/js/src/btcmarkets.js +0 -1237
  263. package/dist/cjs/js/src/btcturk.js +0 -929
  264. package/dist/cjs/js/src/bybit.js +0 -7650
  265. package/dist/cjs/js/src/cex.js +0 -1693
  266. package/dist/cjs/js/src/coinbase.js +0 -3424
  267. package/dist/cjs/js/src/coinbasepro.js +0 -1866
  268. package/dist/cjs/js/src/coincheck.js +0 -843
  269. package/dist/cjs/js/src/coinex.js +0 -5417
  270. package/dist/cjs/js/src/coinlist.js +0 -2337
  271. package/dist/cjs/js/src/coinmate.js +0 -989
  272. package/dist/cjs/js/src/coinone.js +0 -1185
  273. package/dist/cjs/js/src/coinsph.js +0 -1933
  274. package/dist/cjs/js/src/coinspot.js +0 -548
  275. package/dist/cjs/js/src/cryptocom.js +0 -3007
  276. package/dist/cjs/js/src/currencycom.js +0 -2015
  277. package/dist/cjs/js/src/delta.js +0 -3262
  278. package/dist/cjs/js/src/deribit.js +0 -3306
  279. package/dist/cjs/js/src/digifinex.js +0 -4307
  280. package/dist/cjs/js/src/exmo.js +0 -2645
  281. package/dist/cjs/js/src/fmfwio.js +0 -34
  282. package/dist/cjs/js/src/gate.js +0 -7077
  283. package/dist/cjs/js/src/gateio.js +0 -16
  284. package/dist/cjs/js/src/gemini.js +0 -1801
  285. package/dist/cjs/js/src/hitbtc.js +0 -3660
  286. package/dist/cjs/js/src/hitbtc3.js +0 -19
  287. package/dist/cjs/js/src/hollaex.js +0 -1882
  288. package/dist/cjs/js/src/htx.js +0 -9174
  289. package/dist/cjs/js/src/huobi.js +0 -16
  290. package/dist/cjs/js/src/huobijp.js +0 -1918
  291. package/dist/cjs/js/src/idex.js +0 -1770
  292. package/dist/cjs/js/src/independentreserve.js +0 -761
  293. package/dist/cjs/js/src/indodax.js +0 -1069
  294. package/dist/cjs/js/src/kraken.js +0 -2891
  295. package/dist/cjs/js/src/krakenfutures.js +0 -2407
  296. package/dist/cjs/js/src/kucoin.js +0 -4494
  297. package/dist/cjs/js/src/kucoinfutures.js +0 -2529
  298. package/dist/cjs/js/src/kuna.js +0 -1949
  299. package/dist/cjs/js/src/latoken.js +0 -1729
  300. package/dist/cjs/js/src/lbank.js +0 -2851
  301. package/dist/cjs/js/src/luno.js +0 -1044
  302. package/dist/cjs/js/src/lykke.js +0 -1303
  303. package/dist/cjs/js/src/mercado.js +0 -897
  304. package/dist/cjs/js/src/mexc.js +0 -5407
  305. package/dist/cjs/js/src/ndax.js +0 -2450
  306. package/dist/cjs/js/src/novadax.js +0 -1556
  307. package/dist/cjs/js/src/oceanex.js +0 -964
  308. package/dist/cjs/js/src/okcoin.js +0 -3115
  309. package/dist/cjs/js/src/okx.js +0 -7331
  310. package/dist/cjs/js/src/p2b.js +0 -1243
  311. package/dist/cjs/js/src/paymium.js +0 -597
  312. package/dist/cjs/js/src/phemex.js +0 -4725
  313. package/dist/cjs/js/src/poloniex.js +0 -2356
  314. package/dist/cjs/js/src/poloniexfutures.js +0 -1794
  315. package/dist/cjs/js/src/pro/alpaca.js +0 -714
  316. package/dist/cjs/js/src/pro/ascendex.js +0 -957
  317. package/dist/cjs/js/src/pro/bequant.js +0 -33
  318. package/dist/cjs/js/src/pro/binance.js +0 -2796
  319. package/dist/cjs/js/src/pro/binancecoinm.js +0 -23
  320. package/dist/cjs/js/src/pro/binanceus.js +0 -51
  321. package/dist/cjs/js/src/pro/binanceusdm.js +0 -32
  322. package/dist/cjs/js/src/pro/bingx.js +0 -944
  323. package/dist/cjs/js/src/pro/bitcoincom.js +0 -29
  324. package/dist/cjs/js/src/pro/bitfinex.js +0 -672
  325. package/dist/cjs/js/src/pro/bitfinex2.js +0 -1159
  326. package/dist/cjs/js/src/pro/bitget.js +0 -1733
  327. package/dist/cjs/js/src/pro/bitmart.js +0 -1486
  328. package/dist/cjs/js/src/pro/bitmex.js +0 -1576
  329. package/dist/cjs/js/src/pro/bitopro.js +0 -327
  330. package/dist/cjs/js/src/pro/bitrue.js +0 -462
  331. package/dist/cjs/js/src/pro/bitstamp.js +0 -547
  332. package/dist/cjs/js/src/pro/bitvavo.js +0 -704
  333. package/dist/cjs/js/src/pro/blockchaincom.js +0 -794
  334. package/dist/cjs/js/src/pro/bybit.js +0 -1843
  335. package/dist/cjs/js/src/pro/cex.js +0 -1510
  336. package/dist/cjs/js/src/pro/coinbase.js +0 -561
  337. package/dist/cjs/js/src/pro/coinbasepro.js +0 -968
  338. package/dist/cjs/js/src/pro/coinex.js +0 -1095
  339. package/dist/cjs/js/src/pro/cryptocom.js +0 -1020
  340. package/dist/cjs/js/src/pro/currencycom.js +0 -563
  341. package/dist/cjs/js/src/pro/deribit.js +0 -825
  342. package/dist/cjs/js/src/pro/exmo.js +0 -658
  343. package/dist/cjs/js/src/pro/gate.js +0 -1316
  344. package/dist/cjs/js/src/pro/gateio.js +0 -16
  345. package/dist/cjs/js/src/pro/gemini.js +0 -649
  346. package/dist/cjs/js/src/pro/hitbtc.js +0 -1294
  347. package/dist/cjs/js/src/pro/hollaex.js +0 -597
  348. package/dist/cjs/js/src/pro/htx.js +0 -2388
  349. package/dist/cjs/js/src/pro/huobi.js +0 -16
  350. package/dist/cjs/js/src/pro/huobijp.js +0 -606
  351. package/dist/cjs/js/src/pro/idex.js +0 -714
  352. package/dist/cjs/js/src/pro/independentreserve.js +0 -280
  353. package/dist/cjs/js/src/pro/kraken.js +0 -1364
  354. package/dist/cjs/js/src/pro/krakenfutures.js +0 -1506
  355. package/dist/cjs/js/src/pro/kucoin.js +0 -1054
  356. package/dist/cjs/js/src/pro/kucoinfutures.js +0 -981
  357. package/dist/cjs/js/src/pro/luno.js +0 -322
  358. package/dist/cjs/js/src/pro/mexc.js +0 -1170
  359. package/dist/cjs/js/src/pro/ndax.js +0 -545
  360. package/dist/cjs/js/src/pro/okcoin.js +0 -760
  361. package/dist/cjs/js/src/pro/okx.js +0 -1608
  362. package/dist/cjs/js/src/pro/phemex.js +0 -1511
  363. package/dist/cjs/js/src/pro/poloniex.js +0 -1253
  364. package/dist/cjs/js/src/pro/poloniexfutures.js +0 -1014
  365. package/dist/cjs/js/src/pro/probit.js +0 -586
  366. package/dist/cjs/js/src/pro/upbit.js +0 -234
  367. package/dist/cjs/js/src/pro/wazirx.js +0 -776
  368. package/dist/cjs/js/src/pro/whitebit.js +0 -927
  369. package/dist/cjs/js/src/pro/woo.js +0 -895
  370. package/dist/cjs/js/src/probit.js +0 -1867
  371. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +0 -401
  372. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -195
  373. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -308
  374. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +0 -554
  375. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -94
  376. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -70
  377. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -91
  378. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -16
  379. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +0 -1760
  380. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -52
  381. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +0 -81
  382. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +0 -376
  383. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -70
  384. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +0 -1580
  385. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -74
  386. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +0 -24
  387. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +0 -158
  388. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +0 -429
  389. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +0 -176
  390. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +0 -324
  391. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +0 -163
  392. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +0 -245
  393. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +0 -1018
  394. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +0 -383
  395. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +0 -258
  396. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +0 -53
  397. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +0 -120
  398. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +0 -69
  399. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +0 -7
  400. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +0 -83
  401. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +0 -240
  402. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +0 -91
  403. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +0 -130
  404. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +0 -214
  405. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +0 -239
  406. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +0 -93
  407. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +0 -354
  408. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +0 -16
  409. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +0 -20
  410. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +0 -30
  411. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +0 -239
  412. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +0 -372
  413. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +0 -273
  414. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +0 -139
  415. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +0 -14
  416. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +0 -16
  417. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +0 -81
  418. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +0 -292
  419. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +0 -103
  420. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +0 -140
  421. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +0 -175
  422. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +0 -95
  423. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +0 -7
  424. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +0 -383
  425. package/dist/cjs/js/src/timex.js +0 -1562
  426. package/dist/cjs/js/src/tokocrypto.js +0 -2542
  427. package/dist/cjs/js/src/upbit.js +0 -1844
  428. package/dist/cjs/js/src/wavesexchange.js +0 -2607
  429. package/dist/cjs/js/src/wazirx.js +0 -953
  430. package/dist/cjs/js/src/whitebit.js +0 -2309
  431. package/dist/cjs/js/src/woo.js +0 -2769
  432. package/dist/cjs/js/src/yobit.js +0 -1314
  433. package/dist/cjs/js/src/zaif.js +0 -736
  434. package/dist/cjs/js/src/zonda.js +0 -1883
  435. package/dist/cjs/src/abstract/bitpanda.js +0 -9
  436. package/test.ts +0 -0
  437. /package/dist/cjs/{js/src/abstract/ace.js → src/abstract/onetrading.js} +0 -0
  438. /package/dist/cjs/{js/src → src}/pro/coinone.js +0 -0
  439. /package/js/src/abstract/{bitpanda.js → onetrading.js} +0 -0
@@ -1,3846 +0,0 @@
1
- 'use strict';
2
-
3
- var bingx$1 = require('./abstract/bingx.js');
4
- var errors = require('./base/errors.js');
5
- var Precise = require('./base/Precise.js');
6
- var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
7
- var number = require('./base/functions/number.js');
8
-
9
- // ---------------------------------------------------------------------------
10
- // ---------------------------------------------------------------------------
11
- class bingx extends bingx$1 {
12
- describe() {
13
- return this.deepExtend(super.describe(), {
14
- 'id': 'bingx',
15
- 'name': 'BingX',
16
- 'countries': ['US'],
17
- // cheapest is 60 requests a minute = 1 requests per second on average => ( 1000ms / 1) = 1000 ms between requests on average
18
- 'rateLimit': 1000,
19
- 'version': 'v1',
20
- 'certified': true,
21
- 'pro': true,
22
- 'has': {
23
- 'CORS': undefined,
24
- 'spot': true,
25
- 'margin': false,
26
- 'swap': true,
27
- 'future': false,
28
- 'option': false,
29
- 'cancelAllOrders': true,
30
- 'cancelOrder': true,
31
- 'cancelOrders': true,
32
- 'closeAllPositions': true,
33
- 'closePosition': true,
34
- 'createMarketBuyOrderWithCost': true,
35
- 'createMarketOrderWithCost': true,
36
- 'createMarketSellOrderWithCost': true,
37
- 'createOrder': true,
38
- 'createOrders': true,
39
- 'createOrderWithTakeProfitAndStopLoss': true,
40
- 'createStopLossOrder': true,
41
- 'createTakeProfitOrder': true,
42
- 'createTrailingAmountOrder': true,
43
- 'createTrailingPercentOrder': true,
44
- 'createTriggerOrder': true,
45
- 'fetchBalance': true,
46
- 'fetchClosedOrders': true,
47
- 'fetchCurrencies': true,
48
- 'fetchDepositAddress': true,
49
- 'fetchDeposits': true,
50
- 'fetchDepositWithdrawFee': 'emulated',
51
- 'fetchDepositWithdrawFees': true,
52
- 'fetchFundingRate': true,
53
- 'fetchFundingRateHistory': true,
54
- 'fetchLeverage': true,
55
- 'fetchLiquidations': false,
56
- 'fetchMarkets': true,
57
- 'fetchMyLiquidations': true,
58
- 'fetchOHLCV': true,
59
- 'fetchOpenInterest': true,
60
- 'fetchOpenOrders': true,
61
- 'fetchOrder': true,
62
- 'fetchOrderBook': true,
63
- 'fetchPositions': true,
64
- 'fetchTicker': true,
65
- 'fetchTickers': true,
66
- 'fetchTime': true,
67
- 'fetchTrades': true,
68
- 'fetchTransfers': true,
69
- 'fetchWithdrawals': true,
70
- 'setLeverage': true,
71
- 'setMargin': true,
72
- 'setMarginMode': true,
73
- 'transfer': true,
74
- },
75
- 'hostname': 'bingx.com',
76
- 'urls': {
77
- 'logo': 'https://github-production-user-asset-6210df.s3.amazonaws.com/1294454/253675376-6983b72e-4999-4549-b177-33b374c195e3.jpg',
78
- 'api': {
79
- 'spot': 'https://open-api.{hostname}/openApi',
80
- 'swap': 'https://open-api.{hostname}/openApi',
81
- 'contract': 'https://open-api.{hostname}/openApi',
82
- 'wallets': 'https://open-api.{hostname}/openApi',
83
- 'user': 'https://open-api.{hostname}/openApi',
84
- 'subAccount': 'https://open-api.{hostname}/openApi',
85
- 'account': 'https://open-api.{hostname}/openApi',
86
- 'copyTrading': 'https://open-api.{hostname}/openApi',
87
- },
88
- 'test': {
89
- 'swap': 'https://open-api-vst.{hostname}/openApi', // only swap is really "test" but since the API keys are the same, we want to keep all the functionalities when the user enables the sandboxmode
90
- },
91
- 'www': 'https://bingx.com/',
92
- 'doc': 'https://bingx-api.github.io/docs/',
93
- 'referral': 'https://bingx.com/invite/OHETOM',
94
- },
95
- 'fees': {
96
- 'tierBased': true,
97
- 'spot': {
98
- 'feeSide': 'get',
99
- 'maker': this.parseNumber('0.001'),
100
- 'taker': this.parseNumber('0.001'),
101
- },
102
- 'swap': {
103
- 'feeSide': 'quote',
104
- 'maker': this.parseNumber('0.0002'),
105
- 'taker': this.parseNumber('0.0005'),
106
- },
107
- },
108
- 'requiredCredentials': {
109
- 'apiKey': true,
110
- 'secret': true,
111
- },
112
- 'api': {
113
- 'spot': {
114
- 'v1': {
115
- 'public': {
116
- 'get': {
117
- 'common/symbols': 3,
118
- 'market/trades': 3,
119
- 'market/depth': 3,
120
- 'market/kline': 3,
121
- 'ticker/24hr': 1,
122
- },
123
- },
124
- 'private': {
125
- 'get': {
126
- 'trade/query': 3,
127
- 'trade/openOrders': 3,
128
- 'trade/historyOrders': 3,
129
- 'trade/myTrades': 3,
130
- 'user/commissionRate': 3,
131
- 'account/balance': 3,
132
- },
133
- 'post': {
134
- 'trade/order': 3,
135
- 'trade/cancel': 3,
136
- 'trade/batchOrders': 3,
137
- 'trade/cancelOrders': 3,
138
- 'trade/cancelOpenOrders': 3,
139
- },
140
- },
141
- },
142
- 'v3': {
143
- 'private': {
144
- 'get': {
145
- 'get/asset/transfer': 3,
146
- 'asset/transfer': 3,
147
- 'capital/deposit/hisrec': 3,
148
- 'capital/withdraw/history': 3,
149
- },
150
- 'post': {
151
- 'post/asset/transfer': 3,
152
- },
153
- },
154
- },
155
- },
156
- 'swap': {
157
- 'v1': {
158
- 'private': {
159
- 'get': {
160
- 'positionSide/dual': 1,
161
- },
162
- 'post': {
163
- 'positionSide/dual': 1,
164
- },
165
- },
166
- },
167
- 'v2': {
168
- 'public': {
169
- 'get': {
170
- 'server/time': 3,
171
- 'quote/contracts': 1,
172
- 'quote/price': 1,
173
- 'quote/depth': 1,
174
- 'quote/trades': 1,
175
- 'quote/premiumIndex': 1,
176
- 'quote/fundingRate': 1,
177
- 'quote/klines': 1,
178
- 'quote/openInterest': 1,
179
- 'quote/ticker': 1,
180
- 'quote/bookTicker': 1,
181
- },
182
- },
183
- 'private': {
184
- 'get': {
185
- 'user/balance': 3,
186
- 'user/positions': 3,
187
- 'user/income': 3,
188
- 'trade/openOrders': 3,
189
- 'trade/openOrder': 3,
190
- 'trade/order': 3,
191
- 'trade/marginType': 3,
192
- 'trade/leverage': 3,
193
- 'trade/forceOrders': 3,
194
- 'trade/allOrders': 3,
195
- 'trade/allFillOrders': 3,
196
- 'user/income/export': 3,
197
- 'user/commissionRate': 3,
198
- 'quote/bookTicker': 3,
199
- },
200
- 'post': {
201
- 'trade/order': 3,
202
- 'trade/batchOrders': 3,
203
- 'trade/closeAllPositions': 3,
204
- 'trade/marginType': 3,
205
- 'trade/leverage': 3,
206
- 'trade/positionMargin': 3,
207
- 'trade/order/test': 3,
208
- },
209
- 'delete': {
210
- 'trade/order': 3,
211
- 'trade/batchOrders': 3,
212
- 'trade/allOpenOrders': 3,
213
- },
214
- },
215
- },
216
- 'v3': {
217
- 'public': {
218
- 'get': {
219
- 'quote/klines': 1,
220
- },
221
- },
222
- },
223
- },
224
- 'contract': {
225
- 'v1': {
226
- 'private': {
227
- 'get': {
228
- 'allPosition': 3,
229
- 'allOrders': 3,
230
- 'balance': 3,
231
- },
232
- },
233
- },
234
- },
235
- 'wallets': {
236
- 'v1': {
237
- 'private': {
238
- 'get': {
239
- 'capital/config/getall': 3,
240
- 'capital/deposit/address': 1,
241
- 'capital/innerTransfer/records': 1,
242
- 'capital/subAccount/deposit/address': 1,
243
- 'capital/deposit/subHisrec': 1,
244
- 'capital/subAccount/innerTransfer/records': 1,
245
- },
246
- 'post': {
247
- 'capital/withdraw/apply': 3,
248
- 'capital/innerTransfer/apply': 3,
249
- 'capital/subAccountInnerTransfer/apply': 3,
250
- 'capital/deposit/createSubAddress': 1,
251
- },
252
- },
253
- },
254
- },
255
- 'subAccount': {
256
- 'v1': {
257
- 'private': {
258
- 'get': {
259
- 'list': 3,
260
- 'assets': 3,
261
- 'apiKey/query': 1,
262
- },
263
- 'post': {
264
- 'create': 3,
265
- 'apiKey/create': 3,
266
- 'apiKey/edit': 3,
267
- 'apiKey/del': 3,
268
- 'updateStatus': 3,
269
- },
270
- },
271
- },
272
- },
273
- 'account': {
274
- 'v1': {
275
- 'private': {
276
- 'get': {
277
- 'uid': 1,
278
- },
279
- 'post': {
280
- 'innerTransfer/authorizeSubAccount': 3,
281
- },
282
- },
283
- },
284
- },
285
- 'user': {
286
- 'auth': {
287
- 'private': {
288
- 'post': {
289
- 'userDataStream': 1,
290
- },
291
- 'put': {
292
- 'userDataStream': 1,
293
- },
294
- },
295
- },
296
- },
297
- 'copyTrading': {
298
- 'v1': {
299
- 'private': {
300
- 'get': {
301
- 'swap/trace/currentTrack': 1,
302
- },
303
- 'post': {
304
- 'swap/trace/closeTrackOrder': 1,
305
- 'swap/trace/setTPSL': 1,
306
- },
307
- },
308
- },
309
- },
310
- 'api': {
311
- 'v3': {
312
- 'private': {
313
- 'get': {
314
- 'asset/transfer': 1,
315
- 'capital/deposit/hisrec': 1,
316
- 'capital/withdraw/history': 1,
317
- },
318
- 'post': {
319
- 'post/asset/transfer': 1,
320
- },
321
- },
322
- },
323
- },
324
- },
325
- 'timeframes': {
326
- '1m': '1m',
327
- '3m': '3m',
328
- '5m': '5m',
329
- '15m': '15m',
330
- '30m': '30m',
331
- '1h': '1h',
332
- '2h': '2h',
333
- '4h': '4h',
334
- '6h': '6h',
335
- '12h': '12h',
336
- '1d': '1d',
337
- '3d': '3d',
338
- '1w': '1w',
339
- '1M': '1M',
340
- },
341
- 'precisionMode': number.DECIMAL_PLACES,
342
- 'exceptions': {
343
- 'exact': {
344
- '400': errors.BadRequest,
345
- '401': errors.AuthenticationError,
346
- '403': errors.PermissionDenied,
347
- '404': errors.BadRequest,
348
- '429': errors.DDoSProtection,
349
- '418': errors.PermissionDenied,
350
- '500': errors.ExchangeError,
351
- '504': errors.ExchangeError,
352
- '100001': errors.AuthenticationError,
353
- '100412': errors.AuthenticationError,
354
- '100202': errors.InsufficientFunds,
355
- '100204': errors.BadRequest,
356
- '100400': errors.BadRequest,
357
- '100421': errors.BadSymbol,
358
- '100440': errors.ExchangeError,
359
- '100500': errors.ExchangeError,
360
- '100503': errors.ExchangeError,
361
- '80001': errors.BadRequest,
362
- '80012': errors.ExchangeNotAvailable,
363
- '80014': errors.BadRequest,
364
- '80016': errors.OrderNotFound,
365
- '80017': errors.OrderNotFound,
366
- '100414': errors.AccountSuspended,
367
- '100419': errors.PermissionDenied,
368
- '100437': errors.BadRequest, // {"code":100437,"msg":"The withdrawal amount is lower than the minimum limit, please re-enter.","timestamp":1689258588845}
369
- },
370
- 'broad': {},
371
- },
372
- 'commonCurrencies': {},
373
- 'options': {
374
- 'defaultType': 'spot',
375
- 'accountsByType': {
376
- 'spot': 'FUND',
377
- 'swap': 'PFUTURES',
378
- 'future': 'SFUTURES',
379
- },
380
- 'accountsById': {
381
- 'FUND': 'spot',
382
- 'PFUTURES': 'swap',
383
- 'SFUTURES': 'future',
384
- },
385
- 'recvWindow': 5 * 1000,
386
- 'broker': 'CCXT',
387
- },
388
- });
389
- }
390
- async fetchTime(params = {}) {
391
- /**
392
- * @method
393
- * @name bingx#fetchTime
394
- * @description fetches the current integer timestamp in milliseconds from the bingx server
395
- * @see https://bingx-api.github.io/docs/#/swapV2/base-info.html#Get%20Server%20Time
396
- * @param {object} [params] extra parameters specific to the exchange API endpoint
397
- * @returns {int} the current integer timestamp in milliseconds from the bingx server
398
- */
399
- const response = await this.swapV2PublicGetServerTime(params);
400
- //
401
- // {
402
- // "code": 0,
403
- // "msg": "",
404
- // "data": {
405
- // "serverTime": 1675319535362
406
- // }
407
- // }
408
- //
409
- const data = this.safeValue(response, 'data');
410
- return this.safeInteger(data, 'serverTime');
411
- }
412
- async fetchCurrencies(params = {}) {
413
- /**
414
- * @method
415
- * @name bingx#fetchCurrencies
416
- * @description fetches all available currencies on an exchange
417
- * @see https://bingx-api.github.io/docs/#/common/account-api.html#All%20Coins
418
- * @param {object} [params] extra parameters specific to the exchange API endpoint
419
- * @returns {object} an associative dictionary of currencies
420
- */
421
- if (!this.checkRequiredCredentials(false)) {
422
- return undefined;
423
- }
424
- const isSandbox = this.safeValue(this.options, 'sandboxMode', false);
425
- if (isSandbox) {
426
- return undefined;
427
- }
428
- const response = await this.walletsV1PrivateGetCapitalConfigGetall(params);
429
- //
430
- // {
431
- // "code": 0,
432
- // "timestamp": 1688045966616,
433
- // "data": [
434
- // {
435
- // "coin": "BTC",
436
- // "name": "BTC",
437
- // "networkList": [
438
- // {
439
- // "name": "BTC",
440
- // "network": "BTC",
441
- // "isDefault": true,
442
- // "minConfirm": "2",
443
- // "withdrawEnable": true,
444
- // "withdrawFee": "0.00035",
445
- // "withdrawMax": "1.62842",
446
- // "withdrawMin": "0.0005"
447
- // },
448
- // {
449
- // "name": "BTC",
450
- // "network": "BEP20",
451
- // "isDefault": false,
452
- // "minConfirm": "15",
453
- // "withdrawEnable": true,
454
- // "withdrawFee": "0.00001",
455
- // "withdrawMax": "1.62734",
456
- // "withdrawMin": "0.0001"
457
- // }
458
- // ]
459
- // },
460
- // ...
461
- // ],
462
- // }
463
- //
464
- const data = this.safeValue(response, 'data', []);
465
- const result = {};
466
- for (let i = 0; i < data.length; i++) {
467
- const entry = data[i];
468
- const currencyId = this.safeString(entry, 'coin');
469
- const code = this.safeCurrencyCode(currencyId);
470
- const name = this.safeString(entry, 'name');
471
- const networkList = this.safeValue(entry, 'networkList');
472
- const networks = {};
473
- let fee = undefined;
474
- let active = undefined;
475
- let withdrawEnabled = undefined;
476
- let defaultLimits = {};
477
- for (let j = 0; j < networkList.length; j++) {
478
- const rawNetwork = networkList[j];
479
- const network = this.safeString(rawNetwork, 'network');
480
- const networkCode = this.networkIdToCode(network);
481
- const isDefault = this.safeValue(rawNetwork, 'isDefault');
482
- withdrawEnabled = this.safeValue(rawNetwork, 'withdrawEnable');
483
- const limits = {
484
- 'amounts': { 'min': this.safeNumber(rawNetwork, 'withdrawMin'), 'max': this.safeNumber(rawNetwork, 'withdrawMax') },
485
- };
486
- if (isDefault) {
487
- fee = this.safeNumber(rawNetwork, 'withdrawFee');
488
- active = withdrawEnabled;
489
- defaultLimits = limits;
490
- }
491
- networks[networkCode] = {
492
- 'info': rawNetwork,
493
- 'id': network,
494
- 'network': networkCode,
495
- 'fee': fee,
496
- 'active': active,
497
- 'deposit': undefined,
498
- 'withdraw': withdrawEnabled,
499
- 'precision': undefined,
500
- 'limits': limits,
501
- };
502
- }
503
- result[code] = {
504
- 'info': entry,
505
- 'code': code,
506
- 'id': currencyId,
507
- 'precision': undefined,
508
- 'name': name,
509
- 'active': active,
510
- 'deposit': undefined,
511
- 'withdraw': withdrawEnabled,
512
- 'networks': networks,
513
- 'fee': fee,
514
- 'limits': defaultLimits,
515
- };
516
- }
517
- return result;
518
- }
519
- async fetchSpotMarkets(params) {
520
- const response = await this.spotV1PublicGetCommonSymbols(params);
521
- //
522
- // {
523
- // "code": 0,
524
- // "msg": "",
525
- // "debugMsg": "",
526
- // "data": {
527
- // "symbols": [
528
- // {
529
- // "symbol": "GEAR-USDT",
530
- // "minQty": 735,
531
- // "maxQty": 2941177,
532
- // "minNotional": 5,
533
- // "maxNotional": 20000,
534
- // "status": 1,
535
- // "tickSize": 0.000001,
536
- // "stepSize": 1
537
- // },
538
- // ...
539
- // ]
540
- // }
541
- // }
542
- //
543
- const data = this.safeValue(response, 'data');
544
- const markets = this.safeValue(data, 'symbols', []);
545
- return this.parseMarkets(markets);
546
- }
547
- async fetchSwapMarkets(params) {
548
- const response = await this.swapV2PublicGetQuoteContracts(params);
549
- //
550
- // {
551
- // "code": 0,
552
- // "msg": "",
553
- // "data": [
554
- // {
555
- // "contractId": "100",
556
- // "symbol": "BTC-USDT",
557
- // "size": "0.0001",
558
- // "quantityPrecision": 4,
559
- // "pricePrecision": 1,
560
- // "feeRate": 0.0005,
561
- // "tradeMinLimit": 1,
562
- // "maxLongLeverage": 150,
563
- // "maxShortLeverage": 150,
564
- // "currency": "USDT",
565
- // "asset": "BTC",
566
- // "status": 1
567
- // },
568
- // ...
569
- // ]
570
- // }
571
- //
572
- const markets = this.safeValue(response, 'data', []);
573
- return this.parseMarkets(markets);
574
- }
575
- parseMarket(market) {
576
- const id = this.safeString(market, 'symbol');
577
- const symbolParts = id.split('-');
578
- const baseId = symbolParts[0];
579
- const quoteId = symbolParts[1];
580
- const base = this.safeCurrencyCode(baseId);
581
- const quote = this.safeCurrencyCode(quoteId);
582
- const currency = this.safeString(market, 'currency');
583
- const settle = this.safeCurrencyCode(currency);
584
- let pricePrecision = this.safeInteger(market, 'pricePrecision');
585
- if (pricePrecision === undefined) {
586
- pricePrecision = this.precisionFromString(this.safeString(market, 'tickSize'));
587
- }
588
- let quantityPrecision = this.safeInteger(market, 'quantityPrecision');
589
- if (quantityPrecision === undefined) {
590
- quantityPrecision = this.precisionFromString(this.safeString(market, 'stepSize'));
591
- }
592
- const type = (settle !== undefined) ? 'swap' : 'spot';
593
- const spot = type === 'spot';
594
- const swap = type === 'swap';
595
- let symbol = base + '/' + quote;
596
- if (settle !== undefined) {
597
- symbol += ':' + settle;
598
- }
599
- const fees = this.safeValue(this.fees, type, {});
600
- const contractSize = this.safeNumber(market, 'size');
601
- const isActive = this.safeString(market, 'status') === '1';
602
- const isInverse = (spot) ? undefined : false;
603
- const isLinear = (spot) ? undefined : swap;
604
- return this.safeMarketStructure({
605
- 'id': id,
606
- 'symbol': symbol,
607
- 'base': base,
608
- 'quote': quote,
609
- 'settle': settle,
610
- 'baseId': baseId,
611
- 'quoteId': quoteId,
612
- 'settleId': currency,
613
- 'type': type,
614
- 'spot': spot,
615
- 'margin': false,
616
- 'swap': swap,
617
- 'future': false,
618
- 'option': false,
619
- 'active': isActive,
620
- 'contract': swap,
621
- 'linear': isLinear,
622
- 'inverse': isInverse,
623
- 'taker': this.safeNumber(fees, 'taker'),
624
- 'maker': this.safeNumber(fees, 'maker'),
625
- 'feeSide': this.safeString(fees, 'feeSide'),
626
- 'contractSize': contractSize,
627
- 'expiry': undefined,
628
- 'expiryDatetime': undefined,
629
- 'strike': undefined,
630
- 'optionType': undefined,
631
- 'precision': {
632
- 'amount': quantityPrecision,
633
- 'price': pricePrecision,
634
- },
635
- 'limits': {
636
- 'leverage': {
637
- 'min': undefined,
638
- 'max': this.safeInteger(market, 'maxLongLeverage'),
639
- },
640
- 'amount': {
641
- 'min': this.safeNumber(market, 'minQty'),
642
- 'max': this.safeNumber(market, 'maxQty'),
643
- },
644
- 'price': {
645
- 'min': undefined,
646
- 'max': undefined,
647
- },
648
- 'cost': {
649
- 'min': this.safeNumber(market, 'minNotional'),
650
- 'max': this.safeNumber(market, 'maxNotional'),
651
- },
652
- },
653
- 'created': undefined,
654
- 'info': market,
655
- });
656
- }
657
- async fetchMarkets(params = {}) {
658
- /**
659
- * @method
660
- * @name bingx#fetchMarkets
661
- * @description retrieves data on all markets for bingx
662
- * @see https://bingx-api.github.io/docs/#/spot/market-api.html#Query%20Symbols
663
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#Contract%20Information
664
- * @param {object} [params] extra parameters specific to the exchange API endpoint
665
- * @returns {object[]} an array of objects representing market data
666
- */
667
- const requests = [this.fetchSwapMarkets(params)];
668
- const isSandbox = this.safeValue(this.options, 'sandboxMode', false);
669
- if (!isSandbox) {
670
- requests.push(this.fetchSpotMarkets(params)); // sandbox is swap only
671
- }
672
- const promises = await Promise.all(requests);
673
- const spotMarkets = this.safeValue(promises, 0, []);
674
- const swapMarkets = this.safeValue(promises, 1, []);
675
- return this.arrayConcat(spotMarkets, swapMarkets);
676
- }
677
- async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
678
- /**
679
- * @method
680
- * @name bingx#fetchOHLCV
681
- * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
682
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#K-Line%20Data
683
- * @see https://bingx-api.github.io/docs/#/spot/market-api.html#Candlestick%20chart%20data
684
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#%20K-Line%20Data
685
- * @param {string} symbol unified symbol of the market to fetch OHLCV data for
686
- * @param {string} timeframe the length of time each candle represents
687
- * @param {int} [since] timestamp in ms of the earliest candle to fetch
688
- * @param {int} [limit] the maximum amount of candles to fetch
689
- * @param {object} [params] extra parameters specific to the exchange API endpoint
690
- * @param {int} [params.until] timestamp in ms of the latest candle to fetch
691
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
692
- * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
693
- */
694
- await this.loadMarkets();
695
- let paginate = false;
696
- [paginate, params] = this.handleOptionAndParams(params, 'fetchOHLCV', 'paginate', false);
697
- if (paginate) {
698
- return await this.fetchPaginatedCallDeterministic('fetchOHLCV', symbol, since, limit, timeframe, params, 1440);
699
- }
700
- const market = this.market(symbol);
701
- const request = {
702
- 'symbol': market['id'],
703
- };
704
- request['interval'] = this.safeString(this.timeframes, timeframe, timeframe);
705
- if (since !== undefined) {
706
- request['startTime'] = since;
707
- }
708
- if (limit !== undefined) {
709
- request['limit'] = limit;
710
- }
711
- const until = this.safeInteger2(params, 'until', 'endTime');
712
- if (until !== undefined) {
713
- params = this.omit(params, ['until']);
714
- request['endTime'] = until;
715
- }
716
- let response = undefined;
717
- if (market['spot']) {
718
- response = await this.spotV1PublicGetMarketKline(this.extend(request, params));
719
- }
720
- else {
721
- response = await this.swapV3PublicGetQuoteKlines(this.extend(request, params));
722
- }
723
- //
724
- // {
725
- // "code": 0,
726
- // "msg": "",
727
- // "data": [
728
- // {
729
- // "open": "19396.8",
730
- // "close": "19394.4",
731
- // "high": "19397.5",
732
- // "low": "19385.7",
733
- // "volume": "110.05",
734
- // "time": 1666583700000
735
- // },
736
- // ...
737
- // ]
738
- // }
739
- //
740
- let ohlcvs = this.safeValue(response, 'data', []);
741
- if (!Array.isArray(ohlcvs)) {
742
- ohlcvs = [ohlcvs];
743
- }
744
- return this.parseOHLCVs(ohlcvs, market, timeframe, since, limit);
745
- }
746
- parseOHLCV(ohlcv, market = undefined) {
747
- //
748
- // {
749
- // "open": "19394.4",
750
- // "close": "19379.0",
751
- // "high": "19394.4",
752
- // "low": "19368.3",
753
- // "volume": "167.44",
754
- // "time": 1666584000000
755
- // }
756
- // spot
757
- // [
758
- // 1691402580000,
759
- // 29093.61,
760
- // 29093.93,
761
- // 29087.73,
762
- // 29093.24,
763
- // 0.59,
764
- // 1691402639999,
765
- // 17221.07
766
- // ]
767
- //
768
- if (Array.isArray(ohlcv)) {
769
- return [
770
- this.safeInteger(ohlcv, 0),
771
- this.safeNumber(ohlcv, 1),
772
- this.safeNumber(ohlcv, 2),
773
- this.safeNumber(ohlcv, 3),
774
- this.safeNumber(ohlcv, 4),
775
- this.safeNumber(ohlcv, 5),
776
- ];
777
- }
778
- return [
779
- this.safeInteger(ohlcv, 'time'),
780
- this.safeNumber(ohlcv, 'open'),
781
- this.safeNumber(ohlcv, 'high'),
782
- this.safeNumber(ohlcv, 'low'),
783
- this.safeNumber(ohlcv, 'close'),
784
- this.safeNumber(ohlcv, 'volume'),
785
- ];
786
- }
787
- async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
788
- /**
789
- * @method
790
- * @name bingx#fetchTrades
791
- * @description get the list of most recent trades for a particular symbol
792
- * @see https://bingx-api.github.io/docs/#/spot/market-api.html#Query%20transaction%20records
793
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#The%20latest%20Trade%20of%20a%20Trading%20Pair
794
- * @param {string} symbol unified symbol of the market to fetch trades for
795
- * @param {int} [since] timestamp in ms of the earliest trade to fetch
796
- * @param {int} [limit] the maximum amount of trades to fetch
797
- * @param {object} [params] extra parameters specific to the exchange API endpoint
798
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
799
- */
800
- await this.loadMarkets();
801
- const market = this.market(symbol);
802
- const request = {
803
- 'symbol': market['id'],
804
- };
805
- if (limit !== undefined) {
806
- request['limit'] = Math.min(limit, 100); // avoid API exception "limit should less than 100"
807
- }
808
- let response = undefined;
809
- let marketType = undefined;
810
- [marketType, params] = this.handleMarketTypeAndParams('fetchTrades', market, params);
811
- if (marketType === 'spot') {
812
- response = await this.spotV1PublicGetMarketTrades(this.extend(request, params));
813
- }
814
- else {
815
- response = await this.swapV2PublicGetQuoteTrades(this.extend(request, params));
816
- }
817
- //
818
- // spot
819
- //
820
- // {
821
- // "code": 0,
822
- // "data": [
823
- // {
824
- // "id": 43148253,
825
- // "price": 25714.71,
826
- // "qty": 1.674571,
827
- // "time": 1655085975589,
828
- // "buyerMaker": false
829
- // }
830
- // ]
831
- // }
832
- //
833
- // swap
834
- //
835
- // {
836
- // "code":0,
837
- // "msg":"",
838
- // "data":[
839
- // {
840
- // "time": 1672025549368,
841
- // "isBuyerMaker": true,
842
- // "price": "16885.0",
843
- // "qty": "3.3002",
844
- // "quoteQty": "55723.87"
845
- // },
846
- // ...
847
- // ]
848
- // }
849
- //
850
- const trades = this.safeValue(response, 'data', []);
851
- return this.parseTrades(trades, market, since, limit);
852
- }
853
- parseTrade(trade, market = undefined) {
854
- //
855
- // spot
856
- // fetchTrades
857
- //
858
- // {
859
- // "id": 43148253,
860
- // "price": 25714.71,
861
- // "qty": 1.674571,
862
- // "time": 1655085975589,
863
- // "buyerMaker": false
864
- // }
865
- //
866
- // spot
867
- // fetchMyTrades
868
- // {
869
- // "symbol": "LTC-USDT",
870
- // "id": 36237072,
871
- // "orderId": 1674069326895775744,
872
- // "price": "85.891",
873
- // "qty": "0.0582",
874
- // "quoteQty": "4.9988562000000005",
875
- // "commission": -0.00005820000000000001,
876
- // "commissionAsset": "LTC",
877
- // "time": 1687964205000,
878
- // "isBuyer": true,
879
- // "isMaker": false
880
- // }
881
- //
882
- // swap
883
- // fetchTrades
884
- //
885
- // {
886
- // "time": 1672025549368,
887
- // "isBuyerMaker": true,
888
- // "price": "16885.0",
889
- // "qty": "3.3002",
890
- // "quoteQty": "55723.87"
891
- // }
892
- //
893
- // swap
894
- // fetchMyTrades
895
- //
896
- // {
897
- // "volume": "0.1",
898
- // "price": "106.75",
899
- // "amount": "10.6750",
900
- // "commission": "-0.0053",
901
- // "currency": "USDT",
902
- // "orderId": "1676213270274379776",
903
- // "liquidatedPrice": "0.00",
904
- // "liquidatedMarginRatio": "0.00",
905
- // "filledTime": "2023-07-04T20:56:01.000+0800"
906
- // }
907
- //
908
- //
909
- // ws
910
- //
911
- // spot
912
- //
913
- // {
914
- // "E": 1690214529432,
915
- // "T": 1690214529386,
916
- // "e": "trade",
917
- // "m": true,
918
- // "p": "29110.19",
919
- // "q": "0.1868",
920
- // "s": "BTC-USDT",
921
- // "t": "57903921"
922
- // }
923
- //
924
- // swap
925
- //
926
- // {
927
- // "q": "0.0421",
928
- // "p": "29023.5",
929
- // "T": 1690221401344,
930
- // "m": false,
931
- // "s": "BTC-USDT"
932
- // }
933
- //
934
- let time = this.safeIntegerN(trade, ['time', 'filledTm', 'T']);
935
- const datetimeId = this.safeString(trade, 'filledTm');
936
- if (datetimeId !== undefined) {
937
- time = this.parse8601(datetimeId);
938
- }
939
- if (time === 0) {
940
- time = undefined;
941
- }
942
- const cost = this.safeString(trade, 'quoteQty');
943
- const type = (cost === undefined) ? 'spot' : 'swap';
944
- const currencyId = this.safeStringN(trade, ['currency', 'N', 'commissionAsset']);
945
- const currencyCode = this.safeCurrencyCode(currencyId);
946
- const m = this.safeValue(trade, 'm');
947
- const marketId = this.safeString(trade, 's');
948
- const isBuyerMaker = this.safeValue2(trade, 'buyerMaker', 'isBuyerMaker');
949
- let takeOrMaker = undefined;
950
- if ((isBuyerMaker !== undefined) || (m !== undefined)) {
951
- takeOrMaker = (isBuyerMaker || m) ? 'maker' : 'taker';
952
- }
953
- let side = this.safeStringLower2(trade, 'side', 'S');
954
- if (side === undefined) {
955
- if ((isBuyerMaker !== undefined) || (m !== undefined)) {
956
- side = (isBuyerMaker || m) ? 'sell' : 'buy';
957
- takeOrMaker = 'taker';
958
- }
959
- }
960
- const isBuyer = this.safeValue(trade, 'isBuyer');
961
- if (isBuyer !== undefined) {
962
- side = isBuyer ? 'buy' : 'sell';
963
- }
964
- const isMaker = this.safeValue(trade, 'isMaker');
965
- if (isMaker !== undefined) {
966
- takeOrMaker = isMaker ? 'maker' : 'taker';
967
- }
968
- return this.safeTrade({
969
- 'id': this.safeStringN(trade, ['id', 't']),
970
- 'info': trade,
971
- 'timestamp': time,
972
- 'datetime': this.iso8601(time),
973
- 'symbol': this.safeSymbol(marketId, market, '-', type),
974
- 'order': this.safeString2(trade, 'orderId', 'i'),
975
- 'type': this.safeStringLower(trade, 'o'),
976
- 'side': this.parseOrderSide(side),
977
- 'takerOrMaker': takeOrMaker,
978
- 'price': this.safeString2(trade, 'price', 'p'),
979
- 'amount': this.safeStringN(trade, ['qty', 'volume', 'amount', 'q']),
980
- 'cost': cost,
981
- 'fee': {
982
- 'cost': this.parseNumber(Precise["default"].stringAbs(this.safeString2(trade, 'commission', 'n'))),
983
- 'currency': currencyCode,
984
- 'rate': undefined,
985
- },
986
- }, market);
987
- }
988
- async fetchOrderBook(symbol, limit = undefined, params = {}) {
989
- /**
990
- * @method
991
- * @name bingx#fetchOrderBook
992
- * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
993
- * @see https://bingx-api.github.io/docs/#/spot/market-api.html#Query%20depth%20information
994
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#Get%20Market%20Depth
995
- * @param {string} symbol unified symbol of the market to fetch the order book for
996
- * @param {int} [limit] the maximum amount of order book entries to return
997
- * @param {object} [params] extra parameters specific to the exchange API endpoint
998
- * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
999
- */
1000
- await this.loadMarkets();
1001
- const market = this.market(symbol);
1002
- const request = {
1003
- 'symbol': market['id'],
1004
- };
1005
- if (limit !== undefined) {
1006
- request['limit'] = limit;
1007
- }
1008
- let response = undefined;
1009
- let marketType = undefined;
1010
- [marketType, params] = this.handleMarketTypeAndParams('fetchOrderBook', market, params);
1011
- if (marketType === 'spot') {
1012
- response = await this.spotV1PublicGetMarketDepth(this.extend(request, params));
1013
- }
1014
- else {
1015
- response = await this.swapV2PublicGetQuoteDepth(this.extend(request, params));
1016
- }
1017
- //
1018
- // spot
1019
- //
1020
- // {
1021
- // "code": 0,
1022
- // "data": {
1023
- // "bids": [
1024
- // [
1025
- // "26324.73",
1026
- // "0.37655"
1027
- // ],
1028
- // [
1029
- // "26324.71",
1030
- // "0.31888"
1031
- // ],
1032
- // ],
1033
- // "asks": [
1034
- // [
1035
- // "26340.30",
1036
- // "6.45221"
1037
- // ],
1038
- // [
1039
- // "26340.15",
1040
- // "6.73261"
1041
- // ],
1042
- // ]}
1043
- // }
1044
- //
1045
- // swap
1046
- //
1047
- // {
1048
- // "code": 0,
1049
- // "msg": "",
1050
- // "data": {
1051
- // "T": 1683914263304,
1052
- // "bids": [
1053
- // [
1054
- // "26300.90000000",
1055
- // "30408.00000000"
1056
- // ],
1057
- // [
1058
- // "26300.80000000",
1059
- // "50906.00000000"
1060
- // ],
1061
- // ],
1062
- // "asks": [
1063
- // [
1064
- // "26301.00000000",
1065
- // "43616.00000000"
1066
- // ],
1067
- // [
1068
- // "26301.10000000",
1069
- // "49402.00000000"
1070
- // ],
1071
- // ]}
1072
- // }
1073
- //
1074
- const orderbook = this.safeValue(response, 'data', {});
1075
- const timestamp = this.safeInteger2(orderbook, 'T', 'ts');
1076
- return this.parseOrderBook(orderbook, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
1077
- }
1078
- async fetchFundingRate(symbol, params = {}) {
1079
- /**
1080
- * @method
1081
- * @name bingx#fetchFundingRate
1082
- * @description fetch the current funding rate
1083
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#Current%20Funding%20Rate
1084
- * @param {string} symbol unified market symbol
1085
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1086
- * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
1087
- */
1088
- await this.loadMarkets();
1089
- const market = this.market(symbol);
1090
- const request = {
1091
- 'symbol': market['id'],
1092
- };
1093
- const response = await this.swapV2PublicGetQuotePremiumIndex(this.extend(request, params));
1094
- //
1095
- // {
1096
- // "code":0,
1097
- // "msg":"",
1098
- // "data":[
1099
- // {
1100
- // "symbol": "BTC-USDT",
1101
- // "markPrice": "16884.5",
1102
- // "indexPrice": "16886.9",
1103
- // "lastFundingRate": "0.0001",
1104
- // "nextFundingTime": 1672041600000
1105
- // },
1106
- // ...
1107
- // ]
1108
- // }
1109
- //
1110
- const data = this.safeValue(response, 'data', {});
1111
- return this.parseFundingRate(data, market);
1112
- }
1113
- parseFundingRate(contract, market = undefined) {
1114
- //
1115
- // {
1116
- // "symbol": "BTC-USDT",
1117
- // "markPrice": "16884.5",
1118
- // "indexPrice": "16886.9",
1119
- // "lastFundingRate": "0.0001",
1120
- // "nextFundingTime": 1672041600000
1121
- // }
1122
- //
1123
- const marketId = this.safeString(contract, 'symbol');
1124
- const nextFundingTimestamp = this.safeInteger(contract, 'nextFundingTime');
1125
- return {
1126
- 'info': contract,
1127
- 'symbol': this.safeSymbol(marketId, market, '-', 'swap'),
1128
- 'markPrice': this.safeNumber(contract, 'markPrice'),
1129
- 'indexPrice': this.safeNumber(contract, 'indexPrice'),
1130
- 'interestRate': undefined,
1131
- 'estimatedSettlePrice': undefined,
1132
- 'timestamp': undefined,
1133
- 'datetime': undefined,
1134
- 'fundingRate': this.safeNumber(contract, 'lastFundingRate'),
1135
- 'fundingTimestamp': undefined,
1136
- 'fundingDatetime': undefined,
1137
- 'nextFundingRate': undefined,
1138
- 'nextFundingTimestamp': nextFundingTimestamp,
1139
- 'nextFundingDatetime': this.iso8601(nextFundingTimestamp),
1140
- 'previousFundingRate': undefined,
1141
- 'previousFundingTimestamp': undefined,
1142
- 'previousFundingDatetime': undefined,
1143
- };
1144
- }
1145
- async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1146
- /**
1147
- * @method
1148
- * @name bingx#fetchFundingRateHistory
1149
- * @description fetches historical funding rate prices
1150
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#Funding%20Rate%20History
1151
- * @param {string} symbol unified symbol of the market to fetch the funding rate history for
1152
- * @param {int} [since] timestamp in ms of the earliest funding rate to fetch
1153
- * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
1154
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1155
- * @param {int} [params.until] timestamp in ms of the latest funding rate to fetch
1156
- * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
1157
- * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
1158
- */
1159
- if (symbol === undefined) {
1160
- throw new errors.ArgumentsRequired(this.id + ' fetchFundingRateHistory() requires a symbol argument');
1161
- }
1162
- await this.loadMarkets();
1163
- let paginate = false;
1164
- [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
1165
- if (paginate) {
1166
- return await this.fetchPaginatedCallDeterministic('fetchFundingRateHistory', symbol, since, limit, '8h', params);
1167
- }
1168
- const market = this.market(symbol);
1169
- const request = {
1170
- 'symbol': market['id'],
1171
- };
1172
- if (since !== undefined) {
1173
- request['startTime'] = since;
1174
- }
1175
- if (limit !== undefined) {
1176
- request['limit'] = limit;
1177
- }
1178
- const until = this.safeInteger2(params, 'until', 'startTime');
1179
- if (until !== undefined) {
1180
- params = this.omit(params, ['until']);
1181
- request['startTime'] = until;
1182
- }
1183
- const response = await this.swapV2PublicGetQuoteFundingRate(this.extend(request, params));
1184
- //
1185
- // {
1186
- // "code":0,
1187
- // "msg":"",
1188
- // "data":[
1189
- // {
1190
- // "symbol": "BTC-USDT",
1191
- // "fundingRate": "0.0001",
1192
- // "fundingTime": 1585684800000
1193
- // },
1194
- // ...
1195
- // ]
1196
- // }
1197
- //
1198
- const data = this.safeValue(response, 'data', []);
1199
- const rates = [];
1200
- for (let i = 0; i < data.length; i++) {
1201
- const entry = data[i];
1202
- const marketId = this.safeString(entry, 'symbol');
1203
- const symbolInner = this.safeSymbol(marketId, market, '-', 'swap');
1204
- const timestamp = this.safeInteger(entry, 'fundingTime');
1205
- rates.push({
1206
- 'info': entry,
1207
- 'symbol': symbolInner,
1208
- 'fundingRate': this.safeNumber(entry, 'fundingRate'),
1209
- 'timestamp': timestamp,
1210
- 'datetime': this.iso8601(timestamp),
1211
- });
1212
- }
1213
- const sorted = this.sortBy(rates, 'timestamp');
1214
- return this.filterBySymbolSinceLimit(sorted, market['symbol'], since, limit);
1215
- }
1216
- async fetchOpenInterest(symbol, params = {}) {
1217
- /**
1218
- * @method
1219
- * @name bingx#fetchOpenInterest
1220
- * @description Retrieves the open interest of a currency
1221
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#Get%20Swap%20Open%20Positions
1222
- * @param {string} symbol Unified CCXT market symbol
1223
- * @param {object} [params] exchange specific parameters
1224
- * @returns {object} an open interest structure{@link https://docs.ccxt.com/#/?id=open-interest-structure}
1225
- */
1226
- await this.loadMarkets();
1227
- const market = this.market(symbol);
1228
- const request = {
1229
- 'symbol': market['id'],
1230
- };
1231
- const response = await this.swapV2PublicGetQuoteOpenInterest(this.extend(request, params));
1232
- //
1233
- // {
1234
- // "code": 0,
1235
- // "msg": "",
1236
- // "data": {
1237
- // "openInterest": "3289641547.10",
1238
- // "symbol": "BTC-USDT",
1239
- // "time": 1672026617364
1240
- // }
1241
- // }
1242
- //
1243
- const data = this.safeValue(response, 'data', {});
1244
- return this.parseOpenInterest(data, market);
1245
- }
1246
- parseOpenInterest(interest, market = undefined) {
1247
- //
1248
- // {
1249
- // "openInterest": "3289641547.10",
1250
- // "symbol": "BTC-USDT",
1251
- // "time": 1672026617364
1252
- // }
1253
- //
1254
- const timestamp = this.safeInteger(interest, 'time');
1255
- const id = this.safeString(interest, 'symbol');
1256
- const symbol = this.safeSymbol(id, market, '-', 'swap');
1257
- const openInterest = this.safeNumber(interest, 'openInterest');
1258
- return this.safeOpenInterest({
1259
- 'symbol': symbol,
1260
- 'baseVolume': undefined,
1261
- 'quoteVolume': undefined,
1262
- 'openInterestAmount': undefined,
1263
- 'openInterestValue': openInterest,
1264
- 'timestamp': timestamp,
1265
- 'datetime': this.iso8601(timestamp),
1266
- 'info': interest,
1267
- }, market);
1268
- }
1269
- async fetchTicker(symbol, params = {}) {
1270
- /**
1271
- * @method
1272
- * @name bingx#fetchTicker
1273
- * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1274
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#Get%20Ticker
1275
- * @see https://bingx-api.github.io/docs/#/spot/market-api.html#24%E5%B0%8F%E6%97%B6%E4%BB%B7%E6%A0%BC%E5%8F%98%E5%8A%A8%E6%83%85%E5%86%B5
1276
- * @param {string} symbol unified symbol of the market to fetch the ticker for
1277
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1278
- * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1279
- */
1280
- await this.loadMarkets();
1281
- const market = this.market(symbol);
1282
- const request = {
1283
- 'symbol': market['id'],
1284
- };
1285
- let response = undefined;
1286
- if (market['spot']) {
1287
- response = await this.spotV1PublicGetTicker24hr(this.extend(request, params));
1288
- }
1289
- else {
1290
- response = await this.swapV2PublicGetQuoteTicker(this.extend(request, params));
1291
- }
1292
- const data = this.safeValue(response, 'data');
1293
- const ticker = this.safeValue(data, 0, data);
1294
- return this.parseTicker(ticker, market);
1295
- }
1296
- async fetchTickers(symbols = undefined, params = {}) {
1297
- /**
1298
- * @method
1299
- * @name bingx#fetchTickers
1300
- * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1301
- * @see https://bingx-api.github.io/docs/#/swapV2/market-api.html#Get%20Ticker
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
- let market = undefined;
1308
- if (symbols !== undefined) {
1309
- symbols = this.marketSymbols(symbols);
1310
- const firstSymbol = this.safeString(symbols, 0);
1311
- market = this.market(firstSymbol);
1312
- }
1313
- let type = undefined;
1314
- [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
1315
- let response = undefined;
1316
- if (type === 'spot') {
1317
- response = await this.spotV1PublicGetTicker24hr(params);
1318
- }
1319
- else {
1320
- response = await this.swapV2PublicGetQuoteTicker(params);
1321
- }
1322
- const tickers = this.safeValue(response, 'data');
1323
- return this.parseTickers(tickers, symbols);
1324
- }
1325
- parseTicker(ticker, market = undefined) {
1326
- //
1327
- // spot
1328
- // {
1329
- // "symbol": "BTC-USDT",
1330
- // "openPrice": "26032.08",
1331
- // "highPrice": "26178.86",
1332
- // "lowPrice": "25968.18",
1333
- // "lastPrice": "26113.60",
1334
- // "volume": "1161.79",
1335
- // "quoteVolume": "30288466.44",
1336
- // "openTime": "1693081020762",
1337
- // "closeTime": "1693167420762",
1338
- // added 2023-11-10:
1339
- // "bidPrice": 16726.0,
1340
- // "bidQty": 0.05,
1341
- // "askPrice": 16726.0,
1342
- // "askQty": 0.05,
1343
- // }
1344
- // swap
1345
- //
1346
- // {
1347
- // "symbol": "BTC-USDT",
1348
- // "priceChange": "52.5",
1349
- // "priceChangePercent": "0.31%", // they started to add the percent sign in value
1350
- // "lastPrice": "16880.5",
1351
- // "lastQty": "2.2238", // only present in swap!
1352
- // "highPrice": "16897.5",
1353
- // "lowPrice": "16726.0",
1354
- // "volume": "245870.1692",
1355
- // "quoteVolume": "4151395117.73",
1356
- // "openPrice": "16832.0",
1357
- // "openTime": 1672026667803,
1358
- // "closeTime": 1672026648425,
1359
- // added 2023-11-10:
1360
- // "bidPrice": 16726.0,
1361
- // "bidQty": 0.05,
1362
- // "askPrice": 16726.0,
1363
- // "askQty": 0.05,
1364
- // }
1365
- //
1366
- const marketId = this.safeString(ticker, 'symbol');
1367
- const lastQty = this.safeString(ticker, 'lastQty');
1368
- // in spot markets, lastQty is not present
1369
- // it's (bad, but) the only way we can check the tickers origin
1370
- const type = (lastQty === undefined) ? 'spot' : 'swap';
1371
- market = this.safeMarket(marketId, market, undefined, type);
1372
- const symbol = market['symbol'];
1373
- const open = this.safeString(ticker, 'openPrice');
1374
- const high = this.safeString(ticker, 'highPrice');
1375
- const low = this.safeString(ticker, 'lowPrice');
1376
- const close = this.safeString(ticker, 'lastPrice');
1377
- const quoteVolume = this.safeString(ticker, 'quoteVolume');
1378
- const baseVolume = this.safeString(ticker, 'volume');
1379
- let percentage = this.safeString(ticker, 'priceChangePercent');
1380
- if (percentage !== undefined) {
1381
- percentage = percentage.replace('%', '');
1382
- }
1383
- const change = this.safeString(ticker, 'priceChange');
1384
- const ts = this.safeInteger(ticker, 'closeTime');
1385
- const datetime = this.iso8601(ts);
1386
- const bid = this.safeString(ticker, 'bidPrice');
1387
- const bidVolume = this.safeString(ticker, 'bidQty');
1388
- const ask = this.safeString(ticker, 'askPrice');
1389
- const askVolume = this.safeString(ticker, 'askQty');
1390
- return this.safeTicker({
1391
- 'symbol': symbol,
1392
- 'timestamp': ts,
1393
- 'datetime': datetime,
1394
- 'high': high,
1395
- 'low': low,
1396
- 'bid': bid,
1397
- 'bidVolume': bidVolume,
1398
- 'ask': ask,
1399
- 'askVolume': askVolume,
1400
- 'vwap': undefined,
1401
- 'open': open,
1402
- 'close': close,
1403
- 'last': undefined,
1404
- 'previousClose': undefined,
1405
- 'change': change,
1406
- 'percentage': percentage,
1407
- 'average': undefined,
1408
- 'baseVolume': baseVolume,
1409
- 'quoteVolume': quoteVolume,
1410
- 'info': ticker,
1411
- }, market);
1412
- }
1413
- async fetchBalance(params = {}) {
1414
- /**
1415
- * @method
1416
- * @name bingx#fetchBalance
1417
- * @description query for balance and get the amount of funds available for trading or funds locked in orders
1418
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Assets
1419
- * @see https://bingx-api.github.io/docs/#/swapV2/account-api.html#Get%20Perpetual%20Swap%20Account%20Asset%20Information
1420
- * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
1421
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1422
- * @param {boolean} [params.standard] whether to fetch standard contract balances
1423
- * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1424
- */
1425
- await this.loadMarkets();
1426
- let response = undefined;
1427
- let standard = undefined;
1428
- [standard, params] = this.handleOptionAndParams(params, 'fetchBalance', 'standard', false);
1429
- const [marketType, marketTypeQuery] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
1430
- if (standard) {
1431
- response = await this.contractV1PrivateGetBalance(marketTypeQuery);
1432
- }
1433
- else if (marketType === 'spot') {
1434
- response = await this.spotV1PrivateGetAccountBalance(marketTypeQuery);
1435
- }
1436
- else {
1437
- response = await this.swapV2PrivateGetUserBalance(marketTypeQuery);
1438
- }
1439
- //
1440
- // spot
1441
- //
1442
- // {
1443
- // "code": 0,
1444
- // "msg": "",
1445
- // "ttl": 1,
1446
- // "data": {
1447
- // "balances": [
1448
- // {
1449
- // "asset": "USDT",
1450
- // "free": "16.73971130673954",
1451
- // "locked": "0"
1452
- // }
1453
- // ]
1454
- // }
1455
- // }
1456
- //
1457
- // swap
1458
- //
1459
- // {
1460
- // "code": 0,
1461
- // "msg": "",
1462
- // "data": {
1463
- // "balance": {
1464
- // "asset": "USDT",
1465
- // "balance": "15.6128",
1466
- // "equity": "15.6128",
1467
- // "unrealizedProfit": "0.0000",
1468
- // "realisedProfit": "0.0000",
1469
- // "availableMargin": "15.6128",
1470
- // "usedMargin": "0.0000",
1471
- // "freezedMargin": "0.0000"
1472
- // }
1473
- // }
1474
- // }
1475
- // standard futures
1476
- // {
1477
- // "code":"0",
1478
- // "timestamp":"1691148990942",
1479
- // "data":[
1480
- // {
1481
- // "asset":"VST",
1482
- // "balance":"100000.00000000000000000000",
1483
- // "crossWalletBalance":"100000.00000000000000000000",
1484
- // "crossUnPnl":"0",
1485
- // "availableBalance":"100000.00000000000000000000",
1486
- // "maxWithdrawAmount":"100000.00000000000000000000",
1487
- // "marginAvailable":false,
1488
- // "updateTime":"1691148990902"
1489
- // },
1490
- // {
1491
- // "asset":"USDT",
1492
- // "balance":"0",
1493
- // "crossWalletBalance":"0",
1494
- // "crossUnPnl":"0",
1495
- // "availableBalance":"0",
1496
- // "maxWithdrawAmount":"0",
1497
- // "marginAvailable":false,
1498
- // "updateTime":"1691148990902"
1499
- // },
1500
- // ]
1501
- // }
1502
- //
1503
- return this.parseBalance(response);
1504
- }
1505
- parseBalance(response) {
1506
- const data = this.safeValue(response, 'data');
1507
- const balances = this.safeValue2(data, 'balance', 'balances', data);
1508
- const result = { 'info': response };
1509
- if (Array.isArray(balances)) {
1510
- for (let i = 0; i < balances.length; i++) {
1511
- const balance = balances[i];
1512
- const currencyId = this.safeString(balance, 'asset');
1513
- const code = this.safeCurrencyCode(currencyId);
1514
- const account = this.account();
1515
- account['free'] = this.safeString2(balance, 'free', 'availableBalance');
1516
- account['used'] = this.safeString(balance, 'locked');
1517
- account['total'] = this.safeString(balance, 'balance');
1518
- result[code] = account;
1519
- }
1520
- }
1521
- else {
1522
- const currencyId = this.safeString(balances, 'asset');
1523
- const code = this.safeCurrencyCode(currencyId);
1524
- const account = this.account();
1525
- account['free'] = this.safeString(balances, 'availableMargin');
1526
- account['used'] = this.safeString(balances, 'usedMargin');
1527
- result[code] = account;
1528
- }
1529
- return this.safeBalance(result);
1530
- }
1531
- async fetchPositions(symbols = undefined, params = {}) {
1532
- /**
1533
- * @method
1534
- * @name bingx#fetchPositions
1535
- * @description fetch all open positions
1536
- * @see https://bingx-api.github.io/docs/#/swapV2/account-api.html#Perpetual%20Swap%20Positions
1537
- * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Query%20standard%20contract%20balance
1538
- * @param {string[]|undefined} symbols list of unified market symbols
1539
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1540
- * @param {boolean} [params.standard] whether to fetch standard contract positions
1541
- * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
1542
- */
1543
- await this.loadMarkets();
1544
- symbols = this.marketSymbols(symbols);
1545
- let standard = undefined;
1546
- [standard, params] = this.handleOptionAndParams(params, 'fetchPositions', 'standard', false);
1547
- let response = undefined;
1548
- if (standard) {
1549
- response = await this.contractV1PrivateGetAllPosition(params);
1550
- }
1551
- else {
1552
- response = await this.swapV2PrivateGetUserPositions(params);
1553
- }
1554
- //
1555
- // {
1556
- // "code": 0,
1557
- // "msg": "",
1558
- // "data": [
1559
- // {
1560
- // "symbol": "BTC-USDT",
1561
- // "positionId": "12345678",
1562
- // "positionSide": "LONG",
1563
- // "isolated": true,
1564
- // "positionAmt": "123.33",
1565
- // "availableAmt": "128.99",
1566
- // "unrealizedProfit": "1.22",
1567
- // "realisedProfit": "8.1",
1568
- // "initialMargin": "123.33",
1569
- // "avgPrice": "2.2",
1570
- // "leverage": 10,
1571
- // }
1572
- // ]
1573
- // }
1574
- //
1575
- const positions = this.safeValue(response, 'data', []);
1576
- return this.parsePositions(positions, symbols);
1577
- }
1578
- parsePosition(position, market = undefined) {
1579
- //
1580
- // {
1581
- // "symbol": "BTC-USDT",
1582
- // "positionId": "12345678",
1583
- // "positionSide": "LONG",
1584
- // "isolated": true,
1585
- // "positionAmt": "123.33",
1586
- // "availableAmt": "128.99",
1587
- // "unrealizedProfit": "1.22",
1588
- // "realisedProfit": "8.1",
1589
- // "initialMargin": "123.33",
1590
- // "avgPrice": "2.2",
1591
- // "leverage": 10,
1592
- // }
1593
- //
1594
- // standard position
1595
- //
1596
- // {
1597
- // "currentPrice": "82.91",
1598
- // "symbol": "LTC/USDT",
1599
- // "initialMargin": "5.00000000000000000000",
1600
- // "unrealizedProfit": "-0.26464500",
1601
- // "leverage": "20.000000000",
1602
- // "isolated": true,
1603
- // "entryPrice": "83.13",
1604
- // "positionSide": "LONG",
1605
- // "positionAmt": "1.20365912",
1606
- // }
1607
- //
1608
- let marketId = this.safeString(position, 'symbol', '');
1609
- marketId = marketId.replace('/', '-'); // standard return different format
1610
- const isolated = this.safeValue(position, 'isolated');
1611
- let marginMode = undefined;
1612
- if (isolated !== undefined) {
1613
- marginMode = isolated ? 'isolated' : 'cross';
1614
- }
1615
- return this.safePosition({
1616
- 'info': position,
1617
- 'id': this.safeString(position, 'positionId'),
1618
- 'symbol': this.safeSymbol(marketId, market, '-', 'swap'),
1619
- 'notional': this.safeNumber(position, 'positionAmt'),
1620
- 'marginMode': marginMode,
1621
- 'liquidationPrice': undefined,
1622
- 'entryPrice': this.safeNumber2(position, 'avgPrice', 'entryPrice'),
1623
- 'unrealizedPnl': this.safeNumber(position, 'unrealizedProfit'),
1624
- 'realizedPnl': this.safeNumber(position, 'realisedProfit'),
1625
- 'percentage': undefined,
1626
- 'contracts': this.safeNumber(position, 'positionAmt'),
1627
- 'contractSize': undefined,
1628
- 'markPrice': undefined,
1629
- 'lastPrice': undefined,
1630
- 'side': this.safeStringLower(position, 'positionSide'),
1631
- 'hedged': undefined,
1632
- 'timestamp': undefined,
1633
- 'datetime': undefined,
1634
- 'lastUpdateTimestamp': undefined,
1635
- 'maintenanceMargin': undefined,
1636
- 'maintenanceMarginPercentage': undefined,
1637
- 'collateral': this.safeNumber(position, 'positionAmt'),
1638
- 'initialMargin': this.safeNumber(position, 'initialMargin'),
1639
- 'initialMarginPercentage': undefined,
1640
- 'leverage': this.safeNumber(position, 'leverage'),
1641
- 'marginRatio': undefined,
1642
- 'stopLossPrice': undefined,
1643
- 'takeProfitPrice': undefined,
1644
- });
1645
- }
1646
- async createMarketOrderWithCost(symbol, side, cost, params = {}) {
1647
- /**
1648
- * @method
1649
- * @name bingx#createMarketOrderWithCost
1650
- * @description create a market order by providing the symbol, side and cost
1651
- * @param {string} symbol unified symbol of the market to create an order in
1652
- * @param {string} side 'buy' or 'sell'
1653
- * @param {float} cost how much you want to trade in units of the quote currency
1654
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1655
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1656
- */
1657
- params['quoteOrderQty'] = cost;
1658
- return await this.createOrder(symbol, 'market', side, cost, undefined, params);
1659
- }
1660
- async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
1661
- /**
1662
- * @method
1663
- * @name bingx#createMarketBuyOrderWithCost
1664
- * @description create a market buy order by providing the symbol and cost
1665
- * @param {string} symbol unified symbol of the market to create an order in
1666
- * @param {float} cost how much you want to trade in units of the quote currency
1667
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1668
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1669
- */
1670
- params['quoteOrderQty'] = cost;
1671
- return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
1672
- }
1673
- async createMarketSellOrderWithCost(symbol, cost, params = {}) {
1674
- /**
1675
- * @method
1676
- * @name bingx#createMarketSellOrderWithCost
1677
- * @description create a market sell order by providing the symbol and cost
1678
- * @param {string} symbol unified symbol of the market to create an order in
1679
- * @param {float} cost how much you want to trade in units of the quote currency
1680
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1681
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1682
- */
1683
- params['quoteOrderQty'] = cost;
1684
- return await this.createOrder(symbol, 'market', 'sell', cost, undefined, params);
1685
- }
1686
- createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
1687
- /**
1688
- * @method
1689
- * @ignore
1690
- * @name bingx#createOrderRequest
1691
- * @description helper function to build request
1692
- * @param {string} symbol unified symbol of the market to create an order in
1693
- * @param {string} type 'market' or 'limit'
1694
- * @param {string} side 'buy' or 'sell'
1695
- * @param {float} amount how much you want to trade in units of the base currency
1696
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1697
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1698
- * @returns {object} request to be sent to the exchange
1699
- */
1700
- const market = this.market(symbol);
1701
- let postOnly = undefined;
1702
- let marketType = undefined;
1703
- [marketType, params] = this.handleMarketTypeAndParams('createOrder', market, params);
1704
- type = type.toUpperCase();
1705
- const request = {
1706
- 'symbol': market['id'],
1707
- 'type': type,
1708
- 'side': side.toUpperCase(),
1709
- };
1710
- const isMarketOrder = type === 'MARKET';
1711
- const isSpot = marketType === 'spot';
1712
- const exchangeClientOrderId = isSpot ? 'newClientOrderId' : 'clientOrderID';
1713
- const clientOrderId = this.safeString2(params, exchangeClientOrderId, 'clientOrderId');
1714
- if (clientOrderId !== undefined) {
1715
- request[exchangeClientOrderId] = clientOrderId;
1716
- }
1717
- const timeInForce = this.safeStringUpper(params, 'timeInForce');
1718
- if (timeInForce === 'IOC') {
1719
- request['timeInForce'] = 'IOC';
1720
- }
1721
- if (isSpot) {
1722
- [postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'POC', params);
1723
- if (postOnly || (timeInForce === 'POC')) {
1724
- request['timeInForce'] = 'POC';
1725
- }
1726
- const cost = this.safeNumber2(params, 'cost', 'quoteOrderQty');
1727
- params = this.omit(params, 'cost');
1728
- if (cost !== undefined) {
1729
- request['quoteOrderQty'] = this.parseToNumeric(this.costToPrecision(symbol, cost));
1730
- }
1731
- else {
1732
- if (market['spot'] && isMarketOrder && (price !== undefined)) {
1733
- // keep the legacy behavior, to avoid breaking the old spot-market-buying code
1734
- const calculatedCost = Precise["default"].stringMul(this.numberToString(amount), this.numberToString(price));
1735
- request['quoteOrderQty'] = this.parseToNumeric(calculatedCost);
1736
- }
1737
- else {
1738
- request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1739
- }
1740
- }
1741
- if (!isMarketOrder) {
1742
- request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1743
- }
1744
- }
1745
- else {
1746
- [postOnly, params] = this.handlePostOnly(isMarketOrder, timeInForce === 'PostOnly', params);
1747
- if (postOnly || (timeInForce === 'PostOnly')) {
1748
- request['timeInForce'] = 'PostOnly';
1749
- }
1750
- else if (timeInForce === 'GTC') {
1751
- request['timeInForce'] = 'GTC';
1752
- }
1753
- else if (timeInForce === 'FOK') {
1754
- request['timeInForce'] = 'FOK';
1755
- }
1756
- const triggerPrice = this.safeString2(params, 'stopPrice', 'triggerPrice');
1757
- const stopLossPrice = this.safeString(params, 'stopLossPrice');
1758
- const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
1759
- const trailingAmount = this.safeString(params, 'trailingAmount');
1760
- const trailingPercent = this.safeString2(params, 'trailingPercent', 'priceRate');
1761
- const isTriggerOrder = triggerPrice !== undefined;
1762
- const isStopLossPriceOrder = stopLossPrice !== undefined;
1763
- const isTakeProfitPriceOrder = takeProfitPrice !== undefined;
1764
- const isTrailingAmountOrder = trailingAmount !== undefined;
1765
- const isTrailingPercentOrder = trailingPercent !== undefined;
1766
- const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
1767
- const stopLoss = this.safeValue(params, 'stopLoss');
1768
- const takeProfit = this.safeValue(params, 'takeProfit');
1769
- const isStopLoss = stopLoss !== undefined;
1770
- const isTakeProfit = takeProfit !== undefined;
1771
- if (((type === 'LIMIT') || (type === 'TRIGGER_LIMIT') || (type === 'STOP') || (type === 'TAKE_PROFIT')) && !isTrailing) {
1772
- request['price'] = this.parseToNumeric(this.priceToPrecision(symbol, price));
1773
- }
1774
- let reduceOnly = this.safeValue(params, 'reduceOnly', false);
1775
- if (isTriggerOrder) {
1776
- request['stopPrice'] = this.parseToNumeric(this.priceToPrecision(symbol, triggerPrice));
1777
- if (isMarketOrder || (type === 'TRIGGER_MARKET')) {
1778
- request['type'] = 'TRIGGER_MARKET';
1779
- }
1780
- else if ((type === 'LIMIT') || (type === 'TRIGGER_LIMIT')) {
1781
- request['type'] = 'TRIGGER_LIMIT';
1782
- }
1783
- }
1784
- else if (isStopLossPriceOrder || isTakeProfitPriceOrder) {
1785
- // This can be used to set the stop loss and take profit, but the position needs to be opened first
1786
- reduceOnly = true;
1787
- if (isStopLossPriceOrder) {
1788
- request['stopPrice'] = this.parseToNumeric(this.priceToPrecision(symbol, stopLossPrice));
1789
- if (isMarketOrder || (type === 'STOP_MARKET')) {
1790
- request['type'] = 'STOP_MARKET';
1791
- }
1792
- else if ((type === 'LIMIT') || (type === 'STOP')) {
1793
- request['type'] = 'STOP';
1794
- }
1795
- }
1796
- else if (isTakeProfitPriceOrder) {
1797
- request['stopPrice'] = this.parseToNumeric(this.priceToPrecision(symbol, takeProfitPrice));
1798
- if (isMarketOrder || (type === 'TAKE_PROFIT_MARKET')) {
1799
- request['type'] = 'TAKE_PROFIT_MARKET';
1800
- }
1801
- else if ((type === 'LIMIT') || (type === 'TAKE_PROFIT')) {
1802
- request['type'] = 'TAKE_PROFIT';
1803
- }
1804
- }
1805
- }
1806
- else if (isTrailing) {
1807
- request['type'] = 'TRAILING_STOP_MARKET';
1808
- if (isTrailingAmountOrder) {
1809
- request['price'] = this.parseToNumeric(trailingAmount);
1810
- }
1811
- else if (isTrailingPercentOrder) {
1812
- const requestTrailingPercent = Precise["default"].stringDiv(trailingPercent, '100');
1813
- request['priceRate'] = this.parseToNumeric(requestTrailingPercent);
1814
- }
1815
- }
1816
- if (isStopLoss || isTakeProfit) {
1817
- if (isStopLoss) {
1818
- const slTriggerPrice = this.safeString2(stopLoss, 'triggerPrice', 'stopPrice', stopLoss);
1819
- const slWorkingType = this.safeString(stopLoss, 'workingType', 'MARK_PRICE');
1820
- const slType = this.safeString(stopLoss, 'type', 'STOP_MARKET');
1821
- const slRequest = {
1822
- 'stopPrice': this.parseToNumeric(this.priceToPrecision(symbol, slTriggerPrice)),
1823
- 'workingType': slWorkingType,
1824
- 'type': slType,
1825
- };
1826
- const slPrice = this.safeString(stopLoss, 'price');
1827
- if (slPrice !== undefined) {
1828
- slRequest['price'] = this.parseToNumeric(this.priceToPrecision(symbol, slPrice));
1829
- }
1830
- const slQuantity = this.safeString(stopLoss, 'quantity', amount);
1831
- slRequest['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, slQuantity));
1832
- request['stopLoss'] = this.json(slRequest);
1833
- }
1834
- if (isTakeProfit) {
1835
- const tkTriggerPrice = this.safeString2(takeProfit, 'triggerPrice', 'stopPrice', takeProfit);
1836
- const tkWorkingType = this.safeString(takeProfit, 'workingType', 'MARK_PRICE');
1837
- const tpType = this.safeString(takeProfit, 'type', 'TAKE_PROFIT_MARKET');
1838
- const tpRequest = {
1839
- 'stopPrice': this.parseToNumeric(this.priceToPrecision(symbol, tkTriggerPrice)),
1840
- 'workingType': tkWorkingType,
1841
- 'type': tpType,
1842
- };
1843
- const slPrice = this.safeString(takeProfit, 'price');
1844
- if (slPrice !== undefined) {
1845
- tpRequest['price'] = this.parseToNumeric(this.priceToPrecision(symbol, slPrice));
1846
- }
1847
- const tkQuantity = this.safeString(takeProfit, 'quantity', amount);
1848
- tpRequest['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, tkQuantity));
1849
- request['takeProfit'] = this.json(tpRequest);
1850
- }
1851
- }
1852
- let positionSide = undefined;
1853
- if (reduceOnly) {
1854
- positionSide = (side === 'buy') ? 'SHORT' : 'LONG';
1855
- }
1856
- else {
1857
- positionSide = (side === 'buy') ? 'LONG' : 'SHORT';
1858
- }
1859
- request['positionSide'] = positionSide;
1860
- request['quantity'] = this.parseToNumeric(this.amountToPrecision(symbol, amount));
1861
- params = this.omit(params, ['reduceOnly', 'triggerPrice', 'stopLossPrice', 'takeProfitPrice', 'trailingAmount', 'trailingPercent', 'takeProfit', 'stopLoss', 'clientOrderId']);
1862
- }
1863
- return this.extend(request, params);
1864
- }
1865
- async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1866
- /**
1867
- * @method
1868
- * @name bingx#createOrder
1869
- * @description create a trade order
1870
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Trade%20order
1871
- * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Create%20an%20Order
1872
- * @param {string} symbol unified symbol of the market to create an order in
1873
- * @param {string} type 'market' or 'limit'
1874
- * @param {string} side 'buy' or 'sell'
1875
- * @param {float} amount how much you want to trade in units of the base currency
1876
- * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1877
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1878
- * @param {string} [params.clientOrderId] a unique id for the order
1879
- * @param {bool} [params.postOnly] true to place a post only order
1880
- * @param {string} [params.timeInForce] spot supports 'PO' and 'IOC', swap supports 'PO', 'GTC', 'IOC' and 'FOK'
1881
- * @param {bool} [params.reduceOnly] *swap only* true or false whether the order is reduce only
1882
- * @param {float} [params.triggerPrice] *swap only* triggerPrice at which the attached take profit / stop loss order will be triggered
1883
- * @param {float} [params.stopLossPrice] *swap only* stop loss trigger price
1884
- * @param {float} [params.takeProfitPrice] *swap only* take profit trigger price
1885
- * @param {float} [params.cost] the quote quantity that can be used as an alternative for the amount
1886
- * @param {float} [params.trailingAmount] *swap only* the quote amount to trail away from the current market price
1887
- * @param {float} [params.trailingPercent] *swap only* the percent to trail away from the current market price
1888
- * @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered
1889
- * @param {float} [params.takeProfit.triggerPrice] take profit trigger price
1890
- * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered
1891
- * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
1892
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1893
- */
1894
- await this.loadMarkets();
1895
- const market = this.market(symbol);
1896
- const request = this.createOrderRequest(symbol, type, side, amount, price, params);
1897
- let response = undefined;
1898
- if (market['swap']) {
1899
- response = await this.swapV2PrivatePostTradeOrder(request);
1900
- }
1901
- else {
1902
- response = await this.spotV1PrivatePostTradeOrder(request);
1903
- }
1904
- //
1905
- // spot
1906
- //
1907
- // {
1908
- // "code": 0,
1909
- // "msg": "",
1910
- // "data": {
1911
- // "symbol": "XRP-USDT",
1912
- // "orderId": 1514090846268424192,
1913
- // "transactTime": 1649822362855,
1914
- // "price": "0.5",
1915
- // "origQty": "10",
1916
- // "executedQty": "0",
1917
- // "cummulativeQuoteQty": "0",
1918
- // "status": "PENDING",
1919
- // "type": "LIMIT",
1920
- // "side": "BUY"
1921
- // }
1922
- // }
1923
- //
1924
- // swap
1925
- //
1926
- // {
1927
- // "code": 0,
1928
- // "msg": "",
1929
- // "data": {
1930
- // "order": {
1931
- // "symbol": "BTC-USDT",
1932
- // "orderId": 1709036527545438208,
1933
- // "side": "BUY",
1934
- // "positionSide": "LONG",
1935
- // "type": "TRIGGER_LIMIT",
1936
- // "clientOrderID": "",
1937
- // "workingType": ""
1938
- // }
1939
- // }
1940
- // }
1941
- //
1942
- if (typeof response === 'string') {
1943
- // broken api engine : order-ids are too long numbers (i.e. 1742930526912864656)
1944
- // and JSON.parse can not handle them in JS, so we have to use .parseJson
1945
- // however, when order has an attached SL/TP, their value types need extra parsing
1946
- response = this.fixStringifiedJsonMembers(response);
1947
- response = this.parseJson(response);
1948
- }
1949
- const data = this.safeValue(response, 'data', {});
1950
- const order = this.safeValue(data, 'order', data);
1951
- return this.parseOrder(order, market);
1952
- }
1953
- async createOrders(orders, params = {}) {
1954
- /**
1955
- * @method
1956
- * @name bingx#createOrders
1957
- * @description create a list of trade orders
1958
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Batch%20Placing%20Orders
1959
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Bulk%20order
1960
- * @param {Array} orders list of orders to create, each object should contain the parameters required by createOrder, namely symbol, type, side, amount, price and params
1961
- * @param {object} [params] extra parameters specific to the exchange API endpoint
1962
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1963
- */
1964
- await this.loadMarkets();
1965
- const ordersRequests = [];
1966
- let symbol = undefined;
1967
- for (let i = 0; i < orders.length; i++) {
1968
- const rawOrder = orders[i];
1969
- const marketId = this.safeString(rawOrder, 'symbol');
1970
- if (symbol === undefined) {
1971
- symbol = marketId;
1972
- }
1973
- else {
1974
- if (symbol !== marketId) {
1975
- throw new errors.BadRequest(this.id + ' createOrders() requires all orders to have the same symbol');
1976
- }
1977
- }
1978
- const type = this.safeString(rawOrder, 'type');
1979
- const side = this.safeString(rawOrder, 'side');
1980
- const amount = this.safeNumber(rawOrder, 'amount');
1981
- const price = this.safeNumber(rawOrder, 'price');
1982
- const orderParams = this.safeValue(rawOrder, 'params', {});
1983
- const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
1984
- ordersRequests.push(orderRequest);
1985
- }
1986
- const market = this.market(symbol);
1987
- const request = {};
1988
- let response = undefined;
1989
- if (market['swap']) {
1990
- request['batchOrders'] = this.json(ordersRequests);
1991
- response = await this.swapV2PrivatePostTradeBatchOrders(request);
1992
- }
1993
- else {
1994
- request['data'] = this.json(ordersRequests);
1995
- response = await this.spotV1PrivatePostTradeBatchOrders(request);
1996
- }
1997
- //
1998
- // spot
1999
- //
2000
- // {
2001
- // "code": 0,
2002
- // "msg": "",
2003
- // "debugMsg": "",
2004
- // "data": {
2005
- // "orders": [
2006
- // {
2007
- // "symbol": "BTC-USDT",
2008
- // "orderId": 1720661389564968960,
2009
- // "transactTime": 1699072618272,
2010
- // "price": "25000",
2011
- // "origQty": "0.0002",
2012
- // "executedQty": "0",
2013
- // "cummulativeQuoteQty": "0",
2014
- // "status": "PENDING",
2015
- // "type": "LIMIT",
2016
- // "side": "BUY"
2017
- // },
2018
- // ]
2019
- // }
2020
- // }
2021
- //
2022
- // swap
2023
- //
2024
- // {
2025
- // "code": 0,
2026
- // "msg": "",
2027
- // "data": {
2028
- // "orders": [
2029
- // {
2030
- // "symbol": "BTC-USDT",
2031
- // "orderId": 1720657081994006528,
2032
- // "side": "BUY",
2033
- // "positionSide": "LONG",
2034
- // "type": "LIMIT",
2035
- // "clientOrderID": "",
2036
- // "workingType": ""
2037
- // },
2038
- // ]
2039
- // }
2040
- // }
2041
- //
2042
- const data = this.safeValue(response, 'data', {});
2043
- const result = this.safeValue(data, 'orders', []);
2044
- return this.parseOrders(result, market);
2045
- }
2046
- parseOrderSide(side) {
2047
- const sides = {
2048
- 'BUY': 'buy',
2049
- 'SELL': 'sell',
2050
- 'SHORT': 'sell',
2051
- 'LONG': 'buy',
2052
- };
2053
- return this.safeString(sides, side, side);
2054
- }
2055
- parseOrder(order, market = undefined) {
2056
- //
2057
- // spot
2058
- // createOrder, createOrders, cancelOrder
2059
- //
2060
- // {
2061
- // "symbol": "XRP-USDT",
2062
- // "orderId": 1514090846268424192,
2063
- // "transactTime": 1649822362855,
2064
- // "price": "0.5",
2065
- // "origQty": "10",
2066
- // "executedQty": "0",
2067
- // "cummulativeQuoteQty": "0",
2068
- // "status": "PENDING",
2069
- // "type": "LIMIT",
2070
- // "side": "BUY"
2071
- // }
2072
- //
2073
- // fetchOrder
2074
- //
2075
- // {
2076
- // "symbol": "ETH-USDT",
2077
- // "orderId": "1660602123001266176",
2078
- // "price": "1700",
2079
- // "origQty": "0.003",
2080
- // "executedQty": "0",
2081
- // "cummulativeQuoteQty": "0",
2082
- // "status": "PENDING",
2083
- // "type": "LIMIT",
2084
- // "side": "BUY",
2085
- // "time": "1684753373276",
2086
- // "updateTime": "1684753373276",
2087
- // "origQuoteOrderQty": "0",
2088
- // "fee": "0",
2089
- // "feeAsset": "ETH"
2090
- // }
2091
- //
2092
- // fetchOpenOrders, fetchClosedOrders
2093
- //
2094
- // {
2095
- // "symbol": "XRP-USDT",
2096
- // "orderId": 1514073325788200960,
2097
- // "price": "0.5",
2098
- // "StopPrice": "0",
2099
- // "origQty": "20",
2100
- // "executedQty": "10",
2101
- // "cummulativeQuoteQty": "5",
2102
- // "status": "PENDING",
2103
- // "type": "LIMIT",
2104
- // "side": "BUY",
2105
- // "time": 1649818185647,
2106
- // "updateTime": 1649818185647,
2107
- // "origQuoteOrderQty": "0"
2108
- // "fee": "-0.01"
2109
- // }
2110
- //
2111
- //
2112
- // swap
2113
- // createOrder, createOrders
2114
- //
2115
- // {
2116
- // "symbol": "BTC-USDT",
2117
- // "orderId": 1590973236294713344,
2118
- // "side": "BUY",
2119
- // "positionSide": "LONG",
2120
- // "type": "LIMIT"
2121
- // }
2122
- //
2123
- // fetchOrder, fetchOpenOrders, fetchClosedOrders
2124
- //
2125
- // {
2126
- // "symbol": "BTC-USDT",
2127
- // "orderId": 1709036527545438208,
2128
- // "side": "BUY",
2129
- // "positionSide": "LONG",
2130
- // "type": "TRIGGER_LIMIT",
2131
- // "origQty": "0.0010",
2132
- // "price": "22000.0",
2133
- // "executedQty": "0.0000",
2134
- // "avgPrice": "0.0",
2135
- // "cumQuote": "",
2136
- // "stopPrice": "23000.0",
2137
- // "profit": "",
2138
- // "commission": "",
2139
- // "status": "NEW",
2140
- // "time": 1696301035187,
2141
- // "updateTime": 1696301035187,
2142
- // "clientOrderId": "",
2143
- // "leverage": "",
2144
- // "takeProfit": "",
2145
- // "stopLoss": "",
2146
- // "advanceAttr": 0,
2147
- // "positionID": 0,
2148
- // "takeProfitEntrustPrice": 0,
2149
- // "stopLossEntrustPrice": 0,
2150
- // "orderType": "",
2151
- // "workingType": "MARK_PRICE"
2152
- // }
2153
- // with tp and sl
2154
- // {
2155
- // orderId: 1741440894764281900,
2156
- // symbol: 'LTC-USDT',
2157
- // positionSide: 'LONG',
2158
- // side: 'BUY',
2159
- // type: 'MARKET',
2160
- // price: 0,
2161
- // quantity: 1,
2162
- // stopPrice: 0,
2163
- // workingType: 'MARK_PRICE',
2164
- // clientOrderID: '',
2165
- // timeInForce: 'GTC',
2166
- // priceRate: 0,
2167
- // stopLoss: '{"stopPrice":50,"workingType":"MARK_PRICE","type":"STOP_MARKET","quantity":1}',
2168
- // takeProfit: '{"stopPrice":150,"workingType":"MARK_PRICE","type":"TAKE_PROFIT_MARKET","quantity":1}',
2169
- // reduceOnly: false
2170
- // }
2171
- //
2172
- const positionSide = this.safeString2(order, 'positionSide', 'ps');
2173
- const marketType = (positionSide === undefined) ? 'spot' : 'swap';
2174
- const marketId = this.safeString2(order, 'symbol', 's');
2175
- if (market === undefined) {
2176
- market = this.safeMarket(marketId, undefined, undefined, marketType);
2177
- }
2178
- const symbol = this.safeSymbol(marketId, market, '-', marketType);
2179
- const orderId = this.safeString2(order, 'orderId', 'i');
2180
- const side = this.safeStringLower2(order, 'side', 'S');
2181
- const type = this.safeStringLower2(order, 'type', 'o');
2182
- const timestamp = this.safeIntegerN(order, ['time', 'transactTime', 'E']);
2183
- const lastTradeTimestamp = this.safeInteger2(order, 'updateTime', 'T');
2184
- const price = this.safeString2(order, 'price', 'p');
2185
- const average = this.safeString2(order, 'avgPrice', 'ap');
2186
- const amount = this.safeString2(order, 'origQty', 'q');
2187
- const filled = this.safeString2(order, 'executedQty', 'z');
2188
- const statusId = this.safeString2(order, 'status', 'X');
2189
- let feeCurrencyCode = this.safeString2(order, 'feeAsset', 'N');
2190
- const feeCost = this.safeStringN(order, ['fee', 'commission', 'n']);
2191
- if ((feeCurrencyCode === undefined)) {
2192
- if (market['spot']) {
2193
- if (side === 'buy') {
2194
- feeCurrencyCode = market['base'];
2195
- }
2196
- else {
2197
- feeCurrencyCode = market['quote'];
2198
- }
2199
- }
2200
- else {
2201
- feeCurrencyCode = market['quote'];
2202
- }
2203
- }
2204
- const fee = {
2205
- 'currency': feeCurrencyCode,
2206
- 'cost': Precise["default"].stringAbs(feeCost),
2207
- };
2208
- const clientOrderId = this.safeStringN(order, ['clientOrderID', 'origClientOrderId', 'c']);
2209
- let stopLoss = this.safeValue(order, 'stopLoss');
2210
- let stopLossPrice = undefined;
2211
- if (stopLoss !== undefined) {
2212
- stopLossPrice = this.safeNumber(stopLoss, 'stopLoss');
2213
- }
2214
- if ((stopLoss !== undefined) && (typeof stopLoss !== 'number')) {
2215
- // stopLoss: '{"stopPrice":50,"workingType":"MARK_PRICE","type":"STOP_MARKET","quantity":1}',
2216
- if (typeof stopLoss === 'string') {
2217
- stopLoss = this.parseJson(stopLoss);
2218
- }
2219
- stopLossPrice = this.safeNumber(stopLoss, 'stopPrice');
2220
- }
2221
- let takeProfit = this.safeValue(order, 'takeProfit');
2222
- let takeProfitPrice = undefined;
2223
- if (takeProfit !== undefined) {
2224
- takeProfitPrice = this.safeNumber(takeProfit, 'takeProfit');
2225
- }
2226
- if ((takeProfit !== undefined) && (typeof takeProfit !== 'number')) {
2227
- // takeProfit: '{"stopPrice":150,"workingType":"MARK_PRICE","type":"TAKE_PROFIT_MARKET","quantity":1}',
2228
- if (typeof takeProfit === 'string') {
2229
- takeProfit = this.parseJson(takeProfit);
2230
- }
2231
- takeProfitPrice = this.safeNumber(takeProfit, 'stopPrice');
2232
- }
2233
- return this.safeOrder({
2234
- 'info': order,
2235
- 'id': orderId,
2236
- 'clientOrderId': clientOrderId,
2237
- 'timestamp': timestamp,
2238
- 'datetime': this.iso8601(timestamp),
2239
- 'lastTradeTimestamp': lastTradeTimestamp,
2240
- 'lastUpdateTimestamp': this.safeInteger(order, 'updateTime'),
2241
- 'symbol': symbol,
2242
- 'type': type,
2243
- 'timeInForce': undefined,
2244
- 'postOnly': undefined,
2245
- 'side': this.parseOrderSide(side),
2246
- 'price': price,
2247
- 'stopPrice': this.safeNumber(order, 'stopPrice'),
2248
- 'triggerPrice': this.safeNumber(order, 'stopPrice'),
2249
- 'stopLossPrice': stopLossPrice,
2250
- 'takeProfitPrice': takeProfitPrice,
2251
- 'average': average,
2252
- 'cost': undefined,
2253
- 'amount': amount,
2254
- 'filled': filled,
2255
- 'remaining': undefined,
2256
- 'status': this.parseOrderStatus(statusId),
2257
- 'fee': fee,
2258
- 'trades': undefined,
2259
- }, market);
2260
- }
2261
- parseOrderStatus(status) {
2262
- const statuses = {
2263
- 'NEW': 'open',
2264
- 'PENDING': 'open',
2265
- 'PARTIALLY_FILLED': 'open',
2266
- 'FILLED': 'closed',
2267
- 'CANCELED': 'canceled',
2268
- 'CANCELLED': 'canceled',
2269
- 'FAILED': 'failed',
2270
- };
2271
- return this.safeString(statuses, status, status);
2272
- }
2273
- async cancelOrder(id, symbol = undefined, params = {}) {
2274
- /**
2275
- * @method
2276
- * @name bingx#cancelOrder
2277
- * @description cancels an open order
2278
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Cancel%20an%20Order
2279
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20an%20Order
2280
- * @param {string} id order id
2281
- * @param {string} symbol unified symbol of the market the order was made in
2282
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2283
- * @param {string} [params.clientOrderId] a unique id for the order
2284
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2285
- */
2286
- if (symbol === undefined) {
2287
- throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
2288
- }
2289
- await this.loadMarkets();
2290
- const market = this.market(symbol);
2291
- const request = {
2292
- 'symbol': market['id'],
2293
- };
2294
- const clientOrderId = this.safeString2(params, 'clientOrderId', 'clientOrderID');
2295
- params = this.omit(params, ['clientOrderId']);
2296
- if (clientOrderId !== undefined) {
2297
- request['clientOrderID'] = clientOrderId;
2298
- }
2299
- else {
2300
- request['orderId'] = id;
2301
- }
2302
- let response = undefined;
2303
- const [marketType, query] = this.handleMarketTypeAndParams('cancelOrder', market, params);
2304
- if (marketType === 'spot') {
2305
- response = await this.spotV1PrivatePostTradeCancel(this.extend(request, query));
2306
- }
2307
- else {
2308
- response = await this.swapV2PrivateDeleteTradeOrder(this.extend(request, query));
2309
- }
2310
- //
2311
- // spot
2312
- //
2313
- // {
2314
- // "code": 0,
2315
- // "msg": "",
2316
- // "data": {
2317
- // "symbol": "XRP-USDT",
2318
- // "orderId": 1514090846268424192,
2319
- // "price": "0.5",
2320
- // "origQty": "10",
2321
- // "executedQty": "0",
2322
- // "cummulativeQuoteQty": "0",
2323
- // "status": "CANCELED",
2324
- // "type": "LIMIT",
2325
- // "side": "BUY"
2326
- // }
2327
- // }
2328
- //
2329
- // swap
2330
- //
2331
- // {
2332
- // "code": 0,
2333
- // "msg": "",
2334
- // "data": {
2335
- // "order": {
2336
- // "symbol": "LINK-USDT",
2337
- // "orderId": 1597783850786750464,
2338
- // "side": "BUY",
2339
- // "positionSide": "LONG",
2340
- // "type": "TRIGGER_MARKET",
2341
- // "origQty": "5.0",
2342
- // "price": "5.0000",
2343
- // "executedQty": "0.0",
2344
- // "avgPrice": "0.0000",
2345
- // "cumQuote": "0",
2346
- // "stopPrice": "5.0000",
2347
- // "profit": "",
2348
- // "commission": "",
2349
- // "status": "CANCELLED",
2350
- // "time": 1669776330000,
2351
- // "updateTime": 1669776330000
2352
- // }
2353
- // }
2354
- // }
2355
- //
2356
- const data = this.safeValue(response, 'data');
2357
- const first = this.safeValue(data, 'order', data);
2358
- return this.parseOrder(first, market);
2359
- }
2360
- async cancelAllOrders(symbol = undefined, params = {}) {
2361
- /**
2362
- * @method
2363
- * @name bingx#cancelAllOrders
2364
- * @description cancel all open orders
2365
- * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Cancel%20orders%20by%20symbol
2366
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20All%20Orders
2367
- * @param {string} [symbol] unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
2368
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2369
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2370
- */
2371
- if (symbol === undefined) {
2372
- throw new errors.ArgumentsRequired(this.id + ' cancelAllOrders() requires a symbol argument');
2373
- }
2374
- await this.loadMarkets();
2375
- const market = this.market(symbol);
2376
- const request = {
2377
- 'symbol': market['id'],
2378
- };
2379
- let response = undefined;
2380
- if (market['spot']) {
2381
- response = await this.spotV1PrivatePostTradeCancelOpenOrders(this.extend(request, params));
2382
- //
2383
- // {
2384
- // "code": 0,
2385
- // "msg": "",
2386
- // "debugMsg": "",
2387
- // "data": {
2388
- // "orders": [{
2389
- // "symbol": "ADA-USDT",
2390
- // "orderId": 1740659971369992192,
2391
- // "transactTime": 1703840651730,
2392
- // "price": 5,
2393
- // "stopPrice": 0,
2394
- // "origQty": 10,
2395
- // "executedQty": 0,
2396
- // "cummulativeQuoteQty": 0,
2397
- // "status": "CANCELED",
2398
- // "type": "LIMIT",
2399
- // "side": "SELL"
2400
- // }]
2401
- // }
2402
- // }
2403
- //
2404
- }
2405
- else if (market['swap']) {
2406
- response = await this.swapV2PrivateDeleteTradeAllOpenOrders(this.extend(request, params));
2407
- //
2408
- // {
2409
- // "code": 0,
2410
- // "msg": "",
2411
- // "data": {
2412
- // "success": [
2413
- // {
2414
- // "symbol": "LINK-USDT",
2415
- // "orderId": 1597783835095859200,
2416
- // "side": "BUY",
2417
- // "positionSide": "LONG",
2418
- // "type": "TRIGGER_LIMIT",
2419
- // "origQty": "5.0",
2420
- // "price": "9.0000",
2421
- // "executedQty": "0.0",
2422
- // "avgPrice": "0.0000",
2423
- // "cumQuote": "0",
2424
- // "stopPrice": "9.5000",
2425
- // "profit": "",
2426
- // "commission": "",
2427
- // "status": "NEW",
2428
- // "time": 1669776326000,
2429
- // "updateTime": 1669776326000
2430
- // }
2431
- // ],
2432
- // "failed": null
2433
- // }
2434
- // }
2435
- //
2436
- }
2437
- else {
2438
- throw new errors.BadRequest(this.id + ' cancelAllOrders is only supported for spot and swap markets.');
2439
- }
2440
- return response;
2441
- }
2442
- async cancelOrders(ids, symbol = undefined, params = {}) {
2443
- /**
2444
- * @method
2445
- * @name bingx#cancelOrders
2446
- * @description cancel multiple orders
2447
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Cancel%20a%20Batch%20of%20Orders
2448
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Cancel%20a%20Batch%20of%20Orders
2449
- * @param {string[]} ids order ids
2450
- * @param {string} symbol unified market symbol, default is undefined
2451
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2452
- * @param {string[]} [params.clientOrderIds] client order ids
2453
- * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2454
- */
2455
- if (symbol === undefined) {
2456
- throw new errors.ArgumentsRequired(this.id + ' cancelOrders() requires a symbol argument');
2457
- }
2458
- await this.loadMarkets();
2459
- const market = this.market(symbol);
2460
- const request = {
2461
- 'symbol': market['id'],
2462
- };
2463
- const clientOrderIds = this.safeValue(params, 'clientOrderIds');
2464
- params = this.omit(params, 'clientOrderIds');
2465
- let idsToParse = ids;
2466
- const areClientOrderIds = (clientOrderIds !== undefined);
2467
- if (areClientOrderIds) {
2468
- idsToParse = clientOrderIds;
2469
- }
2470
- const parsedIds = [];
2471
- for (let i = 0; i < idsToParse.length; i++) {
2472
- const id = idsToParse[i];
2473
- const stringId = id.toString();
2474
- parsedIds.push(stringId);
2475
- }
2476
- let response = undefined;
2477
- if (market['spot']) {
2478
- const spotReqKey = areClientOrderIds ? 'clientOrderIDs' : 'orderIds';
2479
- request[spotReqKey] = parsedIds.join(',');
2480
- response = await this.spotV1PrivatePostTradeCancelOrders(this.extend(request, params));
2481
- }
2482
- else {
2483
- if (areClientOrderIds) {
2484
- request['clientOrderIDList'] = this.json(parsedIds);
2485
- }
2486
- else {
2487
- request['orderIdList'] = parsedIds;
2488
- }
2489
- response = await this.swapV2PrivateDeleteTradeBatchOrders(this.extend(request, params));
2490
- }
2491
- //
2492
- // {
2493
- // "code": 0,
2494
- // "msg": "",
2495
- // "data": {
2496
- // "success": [
2497
- // {
2498
- // "symbol": "LINK-USDT",
2499
- // "orderId": 1597783850786750464,
2500
- // "side": "BUY",
2501
- // "positionSide": "LONG",
2502
- // "type": "TRIGGER_MARKET",
2503
- // "origQty": "5.0",
2504
- // "price": "5.5710",
2505
- // "executedQty": "0.0",
2506
- // "avgPrice": "0.0000",
2507
- // "cumQuote": "0",
2508
- // "stopPrice": "5.0000",
2509
- // "profit": "0.0000",
2510
- // "commission": "0.000000",
2511
- // "status": "CANCELLED",
2512
- // "time": 1669776330000,
2513
- // "updateTime": 1672370837000
2514
- // }
2515
- // ],
2516
- // "failed": null
2517
- // }
2518
- // }
2519
- //
2520
- return response;
2521
- }
2522
- async fetchOrder(id, symbol = undefined, params = {}) {
2523
- /**
2524
- * @method
2525
- * @name bingx#fetchOrder
2526
- * @description fetches information on an order made by the user
2527
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Orders
2528
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20Order
2529
- * @param {string} symbol unified symbol of the market the order was made in
2530
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2531
- * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2532
- */
2533
- if (symbol === undefined) {
2534
- throw new errors.ArgumentsRequired(this.id + ' fetchOrders() requires a symbol argument');
2535
- }
2536
- await this.loadMarkets();
2537
- const market = this.market(symbol);
2538
- const request = {
2539
- 'symbol': market['id'],
2540
- 'orderId': id,
2541
- };
2542
- let response = undefined;
2543
- const [marketType, query] = this.handleMarketTypeAndParams('fetchOrder', market, params);
2544
- if (marketType === 'spot') {
2545
- response = await this.spotV1PrivateGetTradeQuery(this.extend(request, query));
2546
- }
2547
- else {
2548
- response = await this.swapV2PrivateGetTradeOrder(this.extend(request, query));
2549
- }
2550
- //
2551
- // spot
2552
- //
2553
- // {
2554
- // "code": 0,
2555
- // "msg": "",
2556
- // "data": {
2557
- // "symbol": "XRP-USDT",
2558
- // "orderId": 1514087361158316032,
2559
- // "price": "0.5",
2560
- // "origQty": "10",
2561
- // "executedQty": "0",
2562
- // "cummulativeQuoteQty": "0",
2563
- // "status": "CANCELED",
2564
- // "type": "LIMIT",
2565
- // "side": "BUY",
2566
- // "time": 1649821532000,
2567
- // "updateTime": 1649821543000,
2568
- // "origQuoteOrderQty": "0",
2569
- // "fee": "0",
2570
- // "feeAsset": "XRP"
2571
- // }
2572
- // }
2573
- //
2574
- // swap
2575
- //
2576
- // {
2577
- // "code": 0,
2578
- // "msg": "",
2579
- // "data": {
2580
- // "order": {
2581
- // "symbol": "BTC-USDT",
2582
- // "orderId": 1597597642269917184,
2583
- // "side": "SELL",
2584
- // "positionSide": "LONG",
2585
- // "type": "TAKE_PROFIT_MARKET",
2586
- // "origQty": "1.0000",
2587
- // "price": "0.0",
2588
- // "executedQty": "0.0000",
2589
- // "avgPrice": "0.0",
2590
- // "cumQuote": "",
2591
- // "stopPrice": "16494.0",
2592
- // "profit": "",
2593
- // "commission": "",
2594
- // "status": "FILLED",
2595
- // "time": 1669731935000,
2596
- // "updateTime": 1669752524000
2597
- // }
2598
- // }
2599
- // }
2600
- //
2601
- const data = this.safeValue(response, 'data');
2602
- const first = this.safeValue(data, 'order', data);
2603
- return this.parseOrder(first, market);
2604
- }
2605
- async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2606
- /**
2607
- * @method
2608
- * @name bingx#fetchOpenOrders
2609
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Open%20Orders
2610
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20all%20current%20pending%20orders
2611
- * @description fetch all unfilled currently open orders
2612
- * @param {string} symbol unified market symbol
2613
- * @param {int} [since] the earliest time in ms to fetch open orders for
2614
- * @param {int} [limit] the maximum number of open order structures to retrieve
2615
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2616
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2617
- */
2618
- await this.loadMarkets();
2619
- let market = undefined;
2620
- const request = {};
2621
- if (symbol !== undefined) {
2622
- market = this.market(symbol);
2623
- request['symbol'] = market['id'];
2624
- }
2625
- let response = undefined;
2626
- const [marketType, query] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
2627
- if (marketType === 'spot') {
2628
- response = await this.spotV1PrivateGetTradeOpenOrders(this.extend(request, query));
2629
- }
2630
- else {
2631
- response = await this.swapV2PrivateGetTradeOpenOrders(this.extend(request, query));
2632
- }
2633
- //
2634
- // spot
2635
- //
2636
- // {
2637
- // "code": 0,
2638
- // "msg": "",
2639
- // "data": {
2640
- // "orders": [
2641
- // {
2642
- // "symbol": "XRP-USDT",
2643
- // "orderId": 1514073325788200960,
2644
- // "price": "0.5",
2645
- // "origQty": "20",
2646
- // "executedQty": "0",
2647
- // "cummulativeQuoteQty": "0",
2648
- // "status": "PENDING",
2649
- // "type": "LIMIT",
2650
- // "side": "BUY",
2651
- // "time": 1649818185647,
2652
- // "updateTime": 1649818185647,
2653
- // "origQuoteOrderQty": "0"
2654
- // }
2655
- // ]
2656
- // }
2657
- // }
2658
- //
2659
- // swap
2660
- //
2661
- // {
2662
- // "code": 0,
2663
- // "msg": "",
2664
- // "data": {
2665
- // "orders": [
2666
- // {
2667
- // "symbol": "LINK-USDT",
2668
- // "orderId": 1585839271162413056,
2669
- // "side": "BUY",
2670
- // "positionSide": "LONG",
2671
- // "type": "TRIGGER_MARKET",
2672
- // "origQty": "5.0",
2673
- // "price": "9",
2674
- // "executedQty": "0.0",
2675
- // "avgPrice": "0",
2676
- // "cumQuote": "0",
2677
- // "stopPrice": "5",
2678
- // "profit": "0.0000",
2679
- // "commission": "0.000000",
2680
- // "status": "CANCELLED",
2681
- // "time": 1667631605000,
2682
- // "updateTime": 1667631605000
2683
- // },
2684
- // ]
2685
- // }
2686
- // }
2687
- //
2688
- const data = this.safeValue(response, 'data', []);
2689
- const orders = this.safeValue(data, 'orders', []);
2690
- return this.parseOrders(orders, market, since, limit);
2691
- }
2692
- async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2693
- /**
2694
- * @method
2695
- * @name bingx#fetchClosedOrders
2696
- * @description fetches information on multiple closed orders made by the user
2697
- * @see https://bingx-api.github.io/docs/#/spot/trade-api.html#Query%20Order%20History
2698
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
2699
- * @see https://bingx-api.github.io/docs/#/standard/contract-interface.html#Historical%20order
2700
- * @param {string} [symbol] unified market symbol of the market orders were made in
2701
- * @param {int} [since] the earliest time in ms to fetch orders for
2702
- * @param {int} [limit] the maximum number of order structures to retrieve
2703
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2704
- * @param {int} [params.until] the latest time in ms to fetch orders for
2705
- * @param {boolean} [params.standard] whether to fetch standard contract orders
2706
- * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2707
- */
2708
- if (symbol === undefined) {
2709
- throw new errors.ArgumentsRequired(this.id + ' fetchClosedOrders() requires a symbol argument');
2710
- }
2711
- await this.loadMarkets();
2712
- const market = this.market(symbol);
2713
- const request = {
2714
- 'symbol': market['id'],
2715
- };
2716
- let response = undefined;
2717
- let standard = undefined;
2718
- [standard, params] = this.handleOptionAndParams(params, 'fetchClosedOrders', 'standard', false);
2719
- const [marketType, query] = this.handleMarketTypeAndParams('fetchClosedOrders', market, params);
2720
- if (standard) {
2721
- response = await this.contractV1PrivateGetAllOrders(this.extend(request, query));
2722
- }
2723
- else if (marketType === 'spot') {
2724
- response = await this.spotV1PrivateGetTradeHistoryOrders(this.extend(request, query));
2725
- }
2726
- else {
2727
- response = await this.swapV2PrivateGetTradeAllOrders(this.extend(request, query));
2728
- }
2729
- //
2730
- // spot
2731
- //
2732
- // {
2733
- // "code": 0,
2734
- // "msg": "",
2735
- // "data": {
2736
- // "orders": [
2737
- // {
2738
- // "symbol": "XRP-USDT",
2739
- // "orderId": 1514073325788200960,
2740
- // "price": "0.5",
2741
- // "origQty": "20",
2742
- // "executedQty": "0",
2743
- // "cummulativeQuoteQty": "0",
2744
- // "status": "PENDING",
2745
- // "type": "LIMIT",
2746
- // "side": "BUY",
2747
- // "time": 1649818185647,
2748
- // "updateTime": 1649818185647,
2749
- // "origQuoteOrderQty": "0"
2750
- // }
2751
- // ]
2752
- // }
2753
- // }
2754
- //
2755
- // swap
2756
- //
2757
- // {
2758
- // "code": 0,
2759
- // "msg": "",
2760
- // "data": {
2761
- // "orders": [
2762
- // {
2763
- // "symbol": "LINK-USDT",
2764
- // "orderId": 1585839271162413056,
2765
- // "side": "BUY",
2766
- // "positionSide": "LONG",
2767
- // "type": "TRIGGER_MARKET",
2768
- // "origQty": "5.0",
2769
- // "price": "9",
2770
- // "executedQty": "0.0",
2771
- // "avgPrice": "0",
2772
- // "cumQuote": "0",
2773
- // "stopPrice": "5",
2774
- // "profit": "0.0000",
2775
- // "commission": "0.000000",
2776
- // "status": "CANCELLED",
2777
- // "time": 1667631605000,
2778
- // "updateTime": 1667631605000
2779
- // },
2780
- // ]
2781
- // }
2782
- // }
2783
- //
2784
- const data = this.safeValue(response, 'data', []);
2785
- const orders = this.safeValue(data, 'orders', []);
2786
- return this.parseOrders(orders, market, since, limit);
2787
- }
2788
- async transfer(code, amount, fromAccount, toAccount, params = {}) {
2789
- /**
2790
- * @method
2791
- * @name bingx#transfer
2792
- * @description transfer currency internally between wallets on the same account
2793
- * @see https://bingx-api.github.io/docs/#/spot/account-api.html#User%20Universal%20Transfer
2794
- * @param {string} code unified currency code
2795
- * @param {float} amount amount to transfer
2796
- * @param {string} fromAccount account to transfer from
2797
- * @param {string} toAccount account to transfer to
2798
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2799
- * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2800
- */
2801
- await this.loadMarkets();
2802
- const currency = this.currency(code);
2803
- const accountsByType = this.safeValue(this.options, 'accountsByType', {});
2804
- const fromId = this.safeString(accountsByType, fromAccount, fromAccount);
2805
- const toId = this.safeString(accountsByType, toAccount, toAccount);
2806
- const request = {
2807
- 'asset': currency['id'],
2808
- 'amount': this.currencyToPrecision(code, amount),
2809
- 'type': fromId + '_' + toId,
2810
- };
2811
- const response = await this.spotV3PrivateGetGetAssetTransfer(this.extend(request, params));
2812
- //
2813
- // {
2814
- // "tranId":13526853623
2815
- // }
2816
- //
2817
- return {
2818
- 'info': response,
2819
- 'id': this.safeString(response, 'tranId'),
2820
- 'timestamp': undefined,
2821
- 'datetime': undefined,
2822
- 'currency': code,
2823
- 'amount': amount,
2824
- 'fromAccount': fromAccount,
2825
- 'toAccount': toAccount,
2826
- 'status': undefined,
2827
- };
2828
- }
2829
- async fetchTransfers(code = undefined, since = undefined, limit = undefined, params = {}) {
2830
- /**
2831
- * @method
2832
- * @name bingx#fetchTransfers
2833
- * @description fetch a history of internal transfers made on an account
2834
- * @see https://bingx-api.github.io/docs/#/spot/account-api.html#Query%20User%20Universal%20Transfer%20History%20(USER_DATA)
2835
- * @param {string} [code] unified currency code of the currency transferred
2836
- * @param {int} [since] the earliest time in ms to fetch transfers for
2837
- * @param {int} [limit] the maximum number of transfers structures to retrieve
2838
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2839
- * @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2840
- */
2841
- await this.loadMarkets();
2842
- let currency = undefined;
2843
- if (code !== undefined) {
2844
- currency = this.currency(code);
2845
- }
2846
- const accountsByType = this.safeValue(this.options, 'accountsByType', {});
2847
- const fromAccount = this.safeString(params, 'fromAccount');
2848
- const toAccount = this.safeString(params, 'toAccount');
2849
- const fromId = this.safeString(accountsByType, fromAccount, fromAccount);
2850
- const toId = this.safeString(accountsByType, toAccount, toAccount);
2851
- if (fromId === undefined || toId === undefined) {
2852
- throw new errors.ExchangeError(this.id + ' fromAccount & toAccount parameter are required');
2853
- }
2854
- const request = {
2855
- 'type': fromId + '_' + toId,
2856
- };
2857
- if (since !== undefined) {
2858
- request['startTime'] = since;
2859
- }
2860
- if (limit !== undefined) {
2861
- request['size'] = limit;
2862
- }
2863
- const response = await this.spotV3PrivateGetAssetTransfer(this.extend(request, params));
2864
- //
2865
- // {
2866
- // "total": 3,
2867
- // "rows": [
2868
- // {
2869
- // "asset":"USDT",
2870
- // "amount":"-100.00000000000000000000",
2871
- // "type":"FUND_SFUTURES",
2872
- // "status":"CONFIRMED",
2873
- // "tranId":1067594500957016069,
2874
- // "timestamp":1658388859000
2875
- // },
2876
- // ]
2877
- // }
2878
- //
2879
- const rows = this.safeValue(response, 'rows', []);
2880
- return this.parseTransfers(rows, currency, since, limit);
2881
- }
2882
- parseTransfer(transfer, currency = undefined) {
2883
- const tranId = this.safeString(transfer, 'tranId');
2884
- const timestamp = this.safeInteger(transfer, 'timestamp');
2885
- const currencyCode = this.safeCurrencyCode(undefined, currency);
2886
- const status = this.safeString(transfer, 'status');
2887
- const accountsById = this.safeValue(this.options, 'accountsById', {});
2888
- const typeId = this.safeString(transfer, 'type');
2889
- const typeIdSplit = typeId.split('_');
2890
- const fromId = this.safeString(typeIdSplit, 0);
2891
- const toId = this.safeString(typeId, 1);
2892
- const fromAccount = this.safeString(accountsById, fromId, fromId);
2893
- const toAccount = this.safeString(accountsById, toId, toId);
2894
- return {
2895
- 'info': transfer,
2896
- 'id': tranId,
2897
- 'timestamp': timestamp,
2898
- 'datetime': this.iso8601(timestamp),
2899
- 'currency': currencyCode,
2900
- 'amount': this.safeNumber(transfer, 'amount'),
2901
- 'fromAccount': fromAccount,
2902
- 'toAccount': toAccount,
2903
- 'status': status,
2904
- };
2905
- }
2906
- async fetchDepositAddress(code, params = {}) {
2907
- /**
2908
- * @method
2909
- * @name bingx#fetchDepositAddress
2910
- * @description fetch the deposit address for a currency associated with this account
2911
- * @see https://bingx-api.github.io/docs/#/common/sub-account#Query%20Main%20Account%20Deposit%20Address
2912
- * @param {string} code unified currency code
2913
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2914
- * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
2915
- */
2916
- await this.loadMarkets();
2917
- const currency = this.currency(code);
2918
- const defaultRecvWindow = this.safeInteger(this.options, 'recvWindow');
2919
- const recvWindow = this.safeInteger(this.parseParams, 'recvWindow', defaultRecvWindow);
2920
- const request = {
2921
- 'coin': currency['id'],
2922
- 'offset': 0,
2923
- 'limit': 1000,
2924
- 'recvWindow': recvWindow,
2925
- };
2926
- const response = await this.walletsV1PrivateGetCapitalDepositAddress(this.extend(request, params));
2927
- //
2928
- // {
2929
- // "code": "0",
2930
- // "timestamp": "1695200226859",
2931
- // "data": {
2932
- // "data": [
2933
- // {
2934
- // "coinId": "799",
2935
- // "coin": "USDT",
2936
- // "network": "BEP20",
2937
- // "address": "6a7eda2817462dabb6493277a2cfe0f5c3f2550b",
2938
- // "tag": ''
2939
- // }
2940
- // ],
2941
- // "total": "1"
2942
- // }
2943
- // }
2944
- //
2945
- const data = this.safeValue(this.safeValue(response, 'data'), 'data');
2946
- const parsed = this.parseDepositAddresses(data, [currency['code']], false);
2947
- return this.indexBy(parsed, 'network');
2948
- }
2949
- parseDepositAddress(depositAddress, currency = undefined) {
2950
- //
2951
- // {
2952
- // "coinId": "799",
2953
- // "coin": "USDT",
2954
- // "network": "BEP20",
2955
- // "address": "6a7eda2817462dabb6493277a2cfe0f5c3f2550b",
2956
- // "tag": ''
2957
- // }
2958
- //
2959
- const address = this.safeString(depositAddress, 'address');
2960
- const tag = this.safeString(depositAddress, 'tag');
2961
- const currencyId = this.safeString(depositAddress, 'coin');
2962
- currency = this.safeCurrency(currencyId, currency);
2963
- const code = currency['code'];
2964
- const network = this.safeString(depositAddress, 'network');
2965
- this.checkAddress(address);
2966
- return {
2967
- 'currency': code,
2968
- 'address': address,
2969
- 'tag': tag,
2970
- 'network': network,
2971
- 'info': depositAddress,
2972
- };
2973
- }
2974
- async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
2975
- /**
2976
- * @method
2977
- * @name bingx#fetchDeposits
2978
- * @description fetch all deposits made to an account
2979
- * @see https://bingx-api.github.io/docs/#/spot/account-api.html#Deposit%20History(supporting%20network)
2980
- * @param {string} [code] unified currency code
2981
- * @param {int} [since] the earliest time in ms to fetch deposits for
2982
- * @param {int} [limit] the maximum number of deposits structures to retrieve
2983
- * @param {object} [params] extra parameters specific to the exchange API endpoint
2984
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2985
- */
2986
- await this.loadMarkets();
2987
- const request = {};
2988
- let currency = undefined;
2989
- if (code !== undefined) {
2990
- currency = this.currency(code);
2991
- request['coin'] = currency['id'];
2992
- }
2993
- if (since !== undefined) {
2994
- request['startTime'] = since;
2995
- }
2996
- if (limit !== undefined) {
2997
- request['limit'] = limit; // default 1000
2998
- }
2999
- const response = await this.spotV3PrivateGetCapitalDepositHisrec(this.extend(request, params));
3000
- //
3001
- // [
3002
- // {
3003
- // "amount":"0.00999800",
3004
- // "coin":"PAXG",
3005
- // "network":"ETH",
3006
- // "status":1,
3007
- // "address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
3008
- // "addressTag":"",
3009
- // "txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
3010
- // "insertTime":1599621997000,
3011
- // "transferType":0,
3012
- // "unlockConfirm":"12/12", // confirm times for unlocking
3013
- // "confirmTimes":"12/12"
3014
- // },
3015
- // ]
3016
- //
3017
- return this.parseTransactions(response, currency, since, limit);
3018
- }
3019
- async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
3020
- /**
3021
- * @method
3022
- * @name bingx#fetchWithdrawals
3023
- * @description fetch all withdrawals made from an account
3024
- * @see https://bingx-api.github.io/docs/#/spot/account-api.html#Withdraw%20History%20(supporting%20network)
3025
- * @param {string} [code] unified currency code
3026
- * @param {int} [since] the earliest time in ms to fetch withdrawals for
3027
- * @param {int} [limit] the maximum number of withdrawals structures to retrieve
3028
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3029
- * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3030
- */
3031
- await this.loadMarkets();
3032
- const request = {};
3033
- let currency = undefined;
3034
- if (code !== undefined) {
3035
- currency = this.currency(code);
3036
- request['coin'] = currency['id'];
3037
- }
3038
- if (since !== undefined) {
3039
- request['startTime'] = since;
3040
- }
3041
- if (limit !== undefined) {
3042
- request['limit'] = limit; // default 1000
3043
- }
3044
- const response = await this.spotV3PrivateGetCapitalWithdrawHistory(this.extend(request, params));
3045
- //
3046
- // [
3047
- // {
3048
- // "address": "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
3049
- // "amount": "8.91000000",
3050
- // "applyTime": "2019-10-12 11:12:02",
3051
- // "coin": "USDT",
3052
- // "id": "b6ae22b3aa844210a7041aee7589627c",
3053
- // "withdrawOrderId": "WITHDRAWtest123",
3054
- // "network": "ETH",
3055
- // "transferType": 0
3056
- // "status": 6,
3057
- // "transactionFee": "0.004",
3058
- // "confirmNo":3,
3059
- // "info": "The address is not valid. Please confirm with the recipient",
3060
- // "txId": "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268"
3061
- // },
3062
- // ]
3063
- //
3064
- return this.parseTransactions(response, currency, since, limit);
3065
- }
3066
- parseTransaction(transaction, currency = undefined) {
3067
- //
3068
- // fetchDeposits
3069
- //
3070
- // {
3071
- // "amount":"0.00999800",
3072
- // "coin":"PAXG",
3073
- // "network":"ETH",
3074
- // "status":1,
3075
- // "address":"0x788cabe9236ce061e5a892e1a59395a81fc8d62c",
3076
- // "addressTag":"",
3077
- // "txId":"0xaad4654a3234aa6118af9b4b335f5ae81c360b2394721c019b5d1e75328b09f3",
3078
- // "insertTime":1599621997000,
3079
- // "transferType":0,
3080
- // "unlockConfirm":"12/12", // confirm times for unlocking
3081
- // "confirmTimes":"12/12"
3082
- // }
3083
- //
3084
- // fetchWithdrawals
3085
- //
3086
- // {
3087
- // "address": "0x94df8b352de7f46f64b01d3666bf6e936e44ce60",
3088
- // "amount": "8.91000000",
3089
- // "applyTime": "2019-10-12 11:12:02",
3090
- // "coin": "USDT",
3091
- // "id": "b6ae22b3aa844210a7041aee7589627c",
3092
- // "withdrawOrderId": "WITHDRAWtest123",
3093
- // "network": "ETH",
3094
- // "transferType": 0
3095
- // "status": 6,
3096
- // "transactionFee": "0.004",
3097
- // "confirmNo":3,
3098
- // "info": "The address is not valid. Please confirm with the recipient",
3099
- // "txId": "0xb5ef8c13b968a406cc62a93a8bd80f9e9a906ef1b3fcf20a2e48573c17659268"
3100
- // }
3101
- //
3102
- // withdraw
3103
- //
3104
- // {
3105
- // "code":0,
3106
- // "timestamp":1705274263621,
3107
- // "data":{
3108
- // "id":"1264246141278773252"
3109
- // }
3110
- // }
3111
- //
3112
- // parse withdraw-type output first...
3113
- //
3114
- const data = this.safeValue(transaction, 'data');
3115
- const dataId = (data === undefined) ? undefined : this.safeString(data, 'id');
3116
- const id = this.safeString(transaction, 'id', dataId);
3117
- const address = this.safeString(transaction, 'address');
3118
- const tag = this.safeString(transaction, 'addressTag');
3119
- let timestamp = this.safeInteger(transaction, 'insertTime');
3120
- let datetime = this.iso8601(timestamp);
3121
- if (timestamp === undefined) {
3122
- datetime = this.safeString(transaction, 'applyTime');
3123
- timestamp = this.parse8601(datetime);
3124
- }
3125
- const network = this.safeString(transaction, 'network');
3126
- const currencyId = this.safeString(transaction, 'coin');
3127
- let code = this.safeCurrencyCode(currencyId, currency);
3128
- if ((code !== undefined) && (code !== network) && code.indexOf(network) >= 0) {
3129
- if (network !== undefined) {
3130
- code = code.replace(network, '');
3131
- }
3132
- }
3133
- const rawType = this.safeString(transaction, 'transferType');
3134
- const type = (rawType === '0') ? 'deposit' : 'withdrawal';
3135
- return {
3136
- 'info': transaction,
3137
- 'id': id,
3138
- 'txid': this.safeString(transaction, 'txId'),
3139
- 'type': type,
3140
- 'currency': code,
3141
- 'network': this.networkIdToCode(network),
3142
- 'amount': this.safeNumber(transaction, 'amount'),
3143
- 'status': this.parseTransactionStatus(this.safeString(transaction, 'status')),
3144
- 'timestamp': timestamp,
3145
- 'datetime': datetime,
3146
- 'address': address,
3147
- 'addressFrom': undefined,
3148
- 'addressTo': address,
3149
- 'tag': tag,
3150
- 'tagFrom': tag,
3151
- 'tagTo': undefined,
3152
- 'updated': undefined,
3153
- 'comment': this.safeString(transaction, 'info'),
3154
- 'fee': {
3155
- 'currency': code,
3156
- 'cost': this.safeNumber(transaction, 'transactionFee'),
3157
- 'rate': undefined,
3158
- },
3159
- 'internal': undefined,
3160
- };
3161
- }
3162
- parseTransactionStatus(status) {
3163
- const statuses = {
3164
- '0': 'pending',
3165
- '1': 'ok',
3166
- '10': 'pending',
3167
- '20': 'rejected',
3168
- '30': 'ok',
3169
- '40': 'rejected',
3170
- '50': 'ok',
3171
- '60': 'pending',
3172
- '70': 'rejected',
3173
- '2': 'pending',
3174
- '3': 'rejected',
3175
- '4': 'pending',
3176
- '5': 'rejected',
3177
- '6': 'ok',
3178
- };
3179
- return this.safeString(statuses, status, status);
3180
- }
3181
- async setMarginMode(marginMode, symbol = undefined, params = {}) {
3182
- /**
3183
- * @method
3184
- * @name bingx#setMarginMode
3185
- * @description set margin mode to 'cross' or 'isolated'
3186
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Switch%20Margin%20Mode
3187
- * @param {string} marginMode 'cross' or 'isolated'
3188
- * @param {string} symbol unified market symbol
3189
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3190
- * @returns {object} response from the exchange
3191
- */
3192
- if (symbol === undefined) {
3193
- throw new errors.ArgumentsRequired(this.id + ' setMarginMode() requires a symbol argument');
3194
- }
3195
- await this.loadMarkets();
3196
- const market = this.market(symbol);
3197
- if (market['type'] !== 'swap') {
3198
- throw new errors.BadSymbol(this.id + ' setMarginMode() supports swap contracts only');
3199
- }
3200
- marginMode = marginMode.toUpperCase();
3201
- if (marginMode === 'CROSS') {
3202
- marginMode = 'CROSSED';
3203
- }
3204
- if (marginMode !== 'ISOLATED' && marginMode !== 'CROSSED') {
3205
- throw new errors.BadRequest(this.id + ' setMarginMode() marginMode argument should be isolated or cross');
3206
- }
3207
- const request = {
3208
- 'symbol': market['id'],
3209
- 'marginType': marginMode,
3210
- };
3211
- return await this.swapV2PrivatePostTradeMarginType(this.extend(request, params));
3212
- }
3213
- async setMargin(symbol, amount, params = {}) {
3214
- /**
3215
- * @method
3216
- * @name bingx#setMargin
3217
- * @description Either adds or reduces margin in an isolated position in order to set the margin to a specific value
3218
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Adjust%20isolated%20margin
3219
- * @param {string} symbol unified market symbol of the market to set margin in
3220
- * @param {float} amount the amount to set the margin to
3221
- * @param {object} [params] parameters specific to the bingx api endpoint
3222
- * @returns {object} A [margin structure]{@link https://docs.ccxt.com/#/?id=add-margin-structure}
3223
- */
3224
- const type = this.safeInteger(params, 'type'); // 1 increase margin 2 decrease margin
3225
- if (type === undefined) {
3226
- throw new errors.ArgumentsRequired(this.id + ' setMargin() requires a type parameter either 1 (increase margin) or 2 (decrease margin)');
3227
- }
3228
- if (!this.inArray(type, [1, 2])) {
3229
- throw new errors.ArgumentsRequired(this.id + ' setMargin() requires a type parameter either 1 (increase margin) or 2 (decrease margin)');
3230
- }
3231
- await this.loadMarkets();
3232
- const market = this.market(symbol);
3233
- const request = {
3234
- 'symbol': market['id'],
3235
- 'amount': this.amountToPrecision(market['symbol'], amount),
3236
- 'type': type,
3237
- };
3238
- const response = await this.swapV2PrivatePostTradePositionMargin(this.extend(request, params));
3239
- //
3240
- // {
3241
- // "code": 0,
3242
- // "msg": "",
3243
- // "amount": 1,
3244
- // "type": 1
3245
- // }
3246
- //
3247
- return response;
3248
- }
3249
- async fetchLeverage(symbol, params = {}) {
3250
- /**
3251
- * @method
3252
- * @name bingx#fetchLeverage
3253
- * @description fetch the set leverage for a market
3254
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20Leverage
3255
- * @param {string} symbol unified market symbol
3256
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3257
- * @returns {object} a [leverage structure]{@link https://docs.ccxt.com/#/?id=leverage-structure}
3258
- */
3259
- await this.loadMarkets();
3260
- const market = this.market(symbol);
3261
- const request = {
3262
- 'symbol': market['id'],
3263
- };
3264
- const response = await this.swapV2PrivateGetTradeLeverage(this.extend(request, params));
3265
- //
3266
- // {
3267
- // "code": 0,
3268
- // "msg": "",
3269
- // "data": {
3270
- // "longLeverage": 6,
3271
- // "shortLeverage": 6
3272
- // }
3273
- // }
3274
- //
3275
- return response;
3276
- }
3277
- async setLeverage(leverage, symbol = undefined, params = {}) {
3278
- /**
3279
- * @method
3280
- * @name bingx#setLeverage
3281
- * @description set the level of leverage for a market
3282
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Switch%20Leverage
3283
- * @param {float} leverage the rate of leverage
3284
- * @param {string} symbol unified market symbol
3285
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3286
- * @returns {object} response from the exchange
3287
- */
3288
- if (symbol === undefined) {
3289
- throw new errors.ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
3290
- }
3291
- const side = this.safeStringUpper(params, 'side');
3292
- this.checkRequiredArgument('setLeverage', side, 'side', ['LONG', 'SHORT']);
3293
- await this.loadMarkets();
3294
- const market = this.market(symbol);
3295
- const request = {
3296
- 'symbol': market['id'],
3297
- 'side': side,
3298
- 'leverage': leverage,
3299
- };
3300
- //
3301
- // {
3302
- // "code": 0,
3303
- // "msg": "",
3304
- // "data": {
3305
- // "leverage": 6,
3306
- // "symbol": "BTC-USDT"
3307
- // }
3308
- // }
3309
- //
3310
- return await this.swapV2PrivatePostTradeLeverage(this.extend(request, params));
3311
- }
3312
- async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3313
- /**
3314
- * @method
3315
- * @name bingx#fetchMyTrades
3316
- * @description fetch all trades made by the user
3317
- * @see https://bingx-api.github.io/docs/#/en-us/spot/trade-api.html#Query%20Order%20History
3318
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#Query%20historical%20transaction%20orders
3319
- * @param {string} [symbol] unified market symbol
3320
- * @param {int} [since] the earliest time in ms to fetch trades for
3321
- * @param {int} [limit] the maximum number of trades structures to retrieve
3322
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3323
- * @param {int} [params.until] timestamp in ms for the ending date filter, default is undefined
3324
- * @param {string} params.trandingUnit COIN (directly represent assets such as BTC and ETH) or CONT (represents the number of contract sheets)
3325
- * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
3326
- */
3327
- if (symbol === undefined) {
3328
- throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
3329
- }
3330
- await this.loadMarkets();
3331
- const market = this.market(symbol);
3332
- const now = this.milliseconds();
3333
- let response = undefined;
3334
- const request = {
3335
- 'symbol': market['id'],
3336
- };
3337
- if (since !== undefined) {
3338
- const startTimeReq = market['spot'] ? 'startTime' : 'startTs';
3339
- request[startTimeReq] = since;
3340
- }
3341
- else if (market['swap']) {
3342
- request['startTs'] = now - 7776000000; // 90 days
3343
- }
3344
- const until = this.safeInteger(params, 'until');
3345
- params = this.omit(params, 'until');
3346
- if (until !== undefined) {
3347
- const endTimeReq = market['spot'] ? 'endTime' : 'endTs';
3348
- request[endTimeReq] = until;
3349
- }
3350
- else if (market['swap']) {
3351
- request['endTs'] = now;
3352
- }
3353
- let fills = undefined;
3354
- if (market['spot']) {
3355
- response = await this.spotV1PrivateGetTradeMyTrades(this.extend(request, params));
3356
- const data = this.safeValue(response, 'data', []);
3357
- fills = this.safeValue(data, 'fills', []);
3358
- //
3359
- // {
3360
- // "code": 0,
3361
- // "msg": "",
3362
- // "debugMsg": "",
3363
- // "data": {
3364
- // "fills": [
3365
- // {
3366
- // "symbol": "LTC-USDT",
3367
- // "id": 36237072,
3368
- // "orderId": 1674069326895775744,
3369
- // "price": "85.891",
3370
- // "qty": "0.0582",
3371
- // "quoteQty": "4.9988562000000005",
3372
- // "commission": -0.00005820000000000001,
3373
- // "commissionAsset": "LTC",
3374
- // "time": 1687964205000,
3375
- // "isBuyer": true,
3376
- // "isMaker": false
3377
- // }
3378
- // ]
3379
- // }
3380
- // }
3381
- //
3382
- }
3383
- else {
3384
- const tradingUnit = this.safeStringUpper(params, 'tradingUnit', 'CONT');
3385
- params = this.omit(params, 'tradingUnit');
3386
- request['tradingUnit'] = tradingUnit;
3387
- response = await this.swapV2PrivateGetTradeAllFillOrders(this.extend(request, params));
3388
- const data = this.safeValue(response, 'data', []);
3389
- fills = this.safeValue(data, 'fill_orders', []);
3390
- //
3391
- // {
3392
- // "code": "0",
3393
- // "msg": '',
3394
- // "data": { fill_orders: [
3395
- // {
3396
- // "volume": "0.1",
3397
- // "price": "106.75",
3398
- // "amount": "10.6750",
3399
- // "commission": "-0.0053",
3400
- // "currency": "USDT",
3401
- // "orderId": "1676213270274379776",
3402
- // "liquidatedPrice": "0.00",
3403
- // "liquidatedMarginRatio": "0.00",
3404
- // "filledTime": "2023-07-04T20:56:01.000+0800"
3405
- // }
3406
- // ]
3407
- // }
3408
- // }
3409
- //
3410
- }
3411
- return this.parseTrades(fills, market, since, limit, params);
3412
- }
3413
- parseDepositWithdrawFee(fee, currency = undefined) {
3414
- //
3415
- // {
3416
- // "coin": "BTC",
3417
- // "name": "BTC",
3418
- // "networkList": [
3419
- // {
3420
- // "name": "BTC",
3421
- // "network": "BTC",
3422
- // "isDefault": true,
3423
- // "minConfirm": "2",
3424
- // "withdrawEnable": true,
3425
- // "withdrawFee": "0.00035",
3426
- // "withdrawMax": "1.62842",
3427
- // "withdrawMin": "0.0005"
3428
- // },
3429
- // {
3430
- // "name": "BTC",
3431
- // "network": "BEP20",
3432
- // "isDefault": false,
3433
- // "minConfirm": "15",
3434
- // "withdrawEnable": true,
3435
- // "withdrawFee": "0.00001",
3436
- // "withdrawMax": "1.62734",
3437
- // "withdrawMin": "0.0001"
3438
- // }
3439
- // ]
3440
- // }
3441
- //
3442
- const networkList = this.safeValue(fee, 'networkList', []);
3443
- const networkListLength = networkList.length;
3444
- const result = {
3445
- 'info': fee,
3446
- 'withdraw': {
3447
- 'fee': undefined,
3448
- 'percentage': undefined,
3449
- },
3450
- 'deposit': {
3451
- 'fee': undefined,
3452
- 'percentage': undefined,
3453
- },
3454
- 'networks': {},
3455
- };
3456
- if (networkListLength !== 0) {
3457
- for (let i = 0; i < networkListLength; i++) {
3458
- const network = networkList[i];
3459
- const networkId = this.safeString(network, 'network');
3460
- const isDefault = this.safeValue(network, 'isDefault');
3461
- const currencyCode = this.safeString(currency, 'code');
3462
- const networkCode = this.networkIdToCode(networkId, currencyCode);
3463
- result['networks'][networkCode] = {
3464
- 'deposit': { 'fee': undefined, 'percentage': undefined },
3465
- 'withdraw': { 'fee': this.safeNumber(network, 'withdrawFee'), 'percentage': false },
3466
- };
3467
- if (isDefault) {
3468
- result['withdraw']['fee'] = this.safeNumber(network, 'withdrawFee');
3469
- result['withdraw']['percentage'] = false;
3470
- }
3471
- }
3472
- }
3473
- return result;
3474
- }
3475
- async fetchDepositWithdrawFees(codes = undefined, params = {}) {
3476
- /**
3477
- * @method
3478
- * @name bingx#fetchDepositWithdrawFees
3479
- * @description fetch deposit and withdraw fees
3480
- * @see https://bingx-api.github.io/docs/#/common/account-api.html#All%20Coins'%20Information
3481
- * @param {string[]|undefined} codes list of unified currency codes
3482
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3483
- * @returns {object} a list of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
3484
- */
3485
- await this.loadMarkets();
3486
- const response = await this.walletsV1PrivateGetCapitalConfigGetall(params);
3487
- const coins = this.safeValue(response, 'data');
3488
- return this.parseDepositWithdrawFees(coins, codes, 'coin');
3489
- }
3490
- async withdraw(code, amount, address, tag = undefined, params = {}) {
3491
- /**
3492
- * @method
3493
- * @name bingx#withdraw
3494
- * @description make a withdrawal
3495
- * @see https://bingx-api.github.io/docs/#/common/account-api.html#Withdraw
3496
- * @param {string} code unified currency code
3497
- * @param {float} amount the amount to withdraw
3498
- * @param {string} address the address to withdraw to
3499
- * @param {string} [tag]
3500
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3501
- * @param {int} [params.walletType] 1 fund account, 2 standard account, 3 perpetual account
3502
- * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3503
- */
3504
- await this.loadMarkets();
3505
- const currency = this.currency(code);
3506
- let walletType = this.safeInteger(params, 'walletType');
3507
- if (walletType === undefined) {
3508
- walletType = 1;
3509
- }
3510
- if (!this.inArray(walletType, [1, 2, 3])) {
3511
- throw new errors.BadRequest(this.id + ' withdraw() requires either 1 fund account, 2 standard futures account, 3 perpetual account for walletType');
3512
- }
3513
- const request = {
3514
- 'coin': currency['id'],
3515
- 'address': address,
3516
- 'amount': this.numberToString(amount),
3517
- 'walletType': walletType,
3518
- };
3519
- const network = this.safeStringUpper(params, 'network');
3520
- if (network !== undefined) {
3521
- request['network'] = this.networkCodeToId(network);
3522
- }
3523
- params = this.omit(params, ['walletType', 'network']);
3524
- const response = await this.walletsV1PrivatePostCapitalWithdrawApply(this.extend(request, params));
3525
- const data = this.safeValue(response, 'data');
3526
- // {
3527
- // "code":0,
3528
- // "timestamp":1689258953651,
3529
- // "data":{
3530
- // "id":"1197073063359000577"
3531
- // }
3532
- // }
3533
- this.parseTransaction(data);
3534
- }
3535
- parseParams(params) {
3536
- const sortedParams = this.keysort(params);
3537
- const keys = Object.keys(sortedParams);
3538
- for (let i = 0; i < keys.length; i++) {
3539
- const key = keys[i];
3540
- const value = sortedParams[key];
3541
- if (Array.isArray(value)) {
3542
- let arrStr = '[';
3543
- for (let j = 0; j < value.length; j++) {
3544
- const arrayElement = value[j];
3545
- if (j > 0) {
3546
- arrStr += ',';
3547
- }
3548
- arrStr += arrayElement.toString();
3549
- }
3550
- arrStr += ']';
3551
- sortedParams[key] = arrStr;
3552
- }
3553
- }
3554
- return sortedParams;
3555
- }
3556
- async fetchMyLiquidations(symbol = undefined, since = undefined, limit = undefined, params = {}) {
3557
- /**
3558
- * @method
3559
- * @name bingx#fetchMyLiquidations
3560
- * @description retrieves the users liquidated positions
3561
- * @see https://bingx-api.github.io/docs/#/swapV2/trade-api.html#User's%20Force%20Orders
3562
- * @param {string} [symbol] unified CCXT market symbol
3563
- * @param {int} [since] the earliest time in ms to fetch liquidations for
3564
- * @param {int} [limit] the maximum number of liquidation structures to retrieve
3565
- * @param {object} [params] exchange specific parameters for the bingx api endpoint
3566
- * @param {int} [params.until] timestamp in ms of the latest liquidation
3567
- * @returns {object} an array of [liquidation structures]{@link https://docs.ccxt.com/#/?id=liquidation-structure}
3568
- */
3569
- await this.loadMarkets();
3570
- let request = {
3571
- 'autoCloseType': 'LIQUIDATION',
3572
- };
3573
- [request, params] = this.handleUntilOption('endTime', request, params);
3574
- let market = undefined;
3575
- if (symbol !== undefined) {
3576
- market = this.market(symbol);
3577
- request['symbol'] = symbol;
3578
- }
3579
- if (since !== undefined) {
3580
- request['startTime'] = since;
3581
- }
3582
- if (limit !== undefined) {
3583
- request['limit'] = limit;
3584
- }
3585
- const response = await this.swapV2PrivateGetTradeForceOrders(this.extend(request, params));
3586
- //
3587
- // {
3588
- // "code": 0,
3589
- // "msg": "",
3590
- // "data": {
3591
- // "orders": [
3592
- // {
3593
- // "time": "int64",
3594
- // "symbol": "string",
3595
- // "side": "string",
3596
- // "type": "string",
3597
- // "positionSide": "string",
3598
- // "cumQuote": "string",
3599
- // "status": "string",
3600
- // "stopPrice": "string",
3601
- // "price": "string",
3602
- // "origQty": "string",
3603
- // "avgPrice": "string",
3604
- // "executedQty": "string",
3605
- // "orderId": "int64",
3606
- // "profit": "string",
3607
- // "commission": "string",
3608
- // "workingType": "string",
3609
- // "updateTime": "int64"
3610
- // },
3611
- // ]
3612
- // }
3613
- // }
3614
- //
3615
- const data = this.safeValue(response, 'data', {});
3616
- const liquidations = this.safeValue(data, 'orders', []);
3617
- return this.parseLiquidations(liquidations, market, since, limit);
3618
- }
3619
- parseLiquidation(liquidation, market = undefined) {
3620
- //
3621
- // {
3622
- // "time": "int64",
3623
- // "symbol": "string",
3624
- // "side": "string",
3625
- // "type": "string",
3626
- // "positionSide": "string",
3627
- // "cumQuote": "string",
3628
- // "status": "string",
3629
- // "stopPrice": "string",
3630
- // "price": "string",
3631
- // "origQty": "string",
3632
- // "avgPrice": "string",
3633
- // "executedQty": "string",
3634
- // "orderId": "int64",
3635
- // "profit": "string",
3636
- // "commission": "string",
3637
- // "workingType": "string",
3638
- // "updateTime": "int64"
3639
- // }
3640
- //
3641
- const marketId = this.safeString(liquidation, 'symbol');
3642
- const timestamp = this.safeInteger(liquidation, 'time');
3643
- const contractsString = this.safeString(liquidation, 'executedQty');
3644
- const contractSizeString = this.safeString(market, 'contractSize');
3645
- const priceString = this.safeString(liquidation, 'avgPrice');
3646
- const baseValueString = Precise["default"].stringMul(contractsString, contractSizeString);
3647
- const quoteValueString = Precise["default"].stringMul(baseValueString, priceString);
3648
- return this.safeLiquidation({
3649
- 'info': liquidation,
3650
- 'symbol': this.safeSymbol(marketId, market),
3651
- 'contracts': this.parseNumber(contractsString),
3652
- 'contractSize': this.parseNumber(contractSizeString),
3653
- 'price': this.parseNumber(priceString),
3654
- 'baseValue': this.parseNumber(baseValueString),
3655
- 'quoteValue': this.parseNumber(quoteValueString),
3656
- 'timestamp': timestamp,
3657
- 'datetime': this.iso8601(timestamp),
3658
- });
3659
- }
3660
- async closePosition(symbol, side = undefined, params = {}) {
3661
- /**
3662
- * @method
3663
- * @name bingx#closePosition
3664
- * @description closes open positions for a market
3665
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
3666
- * @param {string} symbol Unified CCXT market symbol
3667
- * @param {string} [side] not used by bingx
3668
- * @param {object} [params] extra parameters specific to the bingx api endpoint
3669
- * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
3670
- */
3671
- await this.loadMarkets();
3672
- const market = this.market(symbol);
3673
- const request = {
3674
- 'symbol': market['id'],
3675
- };
3676
- const response = await this.swapV2PrivatePostTradeCloseAllPositions(this.extend(request, params));
3677
- //
3678
- // {
3679
- // "code": 0,
3680
- // "msg": "",
3681
- // "data": {
3682
- // "success": [
3683
- // 1727686766700486656,
3684
- // ],
3685
- // "failed": null
3686
- // }
3687
- // }
3688
- //
3689
- const data = this.safeValue(response, 'data');
3690
- return this.parseOrder(data);
3691
- }
3692
- async closeAllPositions(params = {}) {
3693
- /**
3694
- * @method
3695
- * @name bitget#closePositions
3696
- * @description closes open positions for a market
3697
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#One-Click%20Close%20All%20Positions
3698
- * @param {object} [params] extra parameters specific to the okx api endpoint
3699
- * @param {string} [params.recvWindow] request valid time window value
3700
- * @returns {object[]} [A list of position structures]{@link https://docs.ccxt.com/#/?id=position-structure}
3701
- */
3702
- await this.loadMarkets();
3703
- const defaultRecvWindow = this.safeInteger(this.options, 'recvWindow');
3704
- const recvWindow = this.safeInteger(this.parseParams, 'recvWindow', defaultRecvWindow);
3705
- let marketType = undefined;
3706
- [marketType, params] = this.handleMarketTypeAndParams('closeAllPositions', undefined, params);
3707
- if (marketType === 'margin') {
3708
- throw new errors.BadRequest(this.id + ' closePositions () cannot be used for ' + marketType + ' markets');
3709
- }
3710
- const request = {
3711
- 'recvWindow': recvWindow,
3712
- };
3713
- const response = await this.swapV2PrivatePostTradeCloseAllPositions(this.extend(request, params));
3714
- //
3715
- // {
3716
- // "code": 0,
3717
- // "msg": "",
3718
- // "data": {
3719
- // "success": [
3720
- // 1727686766700486656,
3721
- // 1727686767048613888
3722
- // ],
3723
- // "failed": null
3724
- // }
3725
- // }
3726
- //
3727
- const data = this.safeValue(response, 'data', {});
3728
- const success = this.safeValue(data, 'success', []);
3729
- const positions = [];
3730
- for (let i = 0; i < success.length; i++) {
3731
- const position = this.parsePosition({ 'positionId': success[i] });
3732
- positions.push(position);
3733
- }
3734
- return positions;
3735
- }
3736
- async setPositionMode(hedged, symbol = undefined, params = {}) {
3737
- /**
3738
- * @method
3739
- * @name bingx#setPositionMode
3740
- * @description set hedged to true or false for a market
3741
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/trade-api.html#Set%20Position%20Mode
3742
- * @param {bool} hedged set to true to use dualSidePosition
3743
- * @param {string} symbol not used by bingx setPositionMode ()
3744
- * @param {object} [params] extra parameters specific to the exchange API endpoint
3745
- * @returns {object} response from the exchange
3746
- */
3747
- let dualSidePosition = undefined;
3748
- if (hedged) {
3749
- dualSidePosition = 'true';
3750
- }
3751
- else {
3752
- dualSidePosition = 'false';
3753
- }
3754
- const request = {
3755
- 'dualSidePosition': dualSidePosition,
3756
- };
3757
- //
3758
- // {
3759
- // code: '0',
3760
- // msg: '',
3761
- // timeStamp: '1703327432734',
3762
- // data: { dualSidePosition: 'false' }
3763
- // }
3764
- //
3765
- return await this.swapV1PrivatePostPositionSideDual(this.extend(request, params));
3766
- }
3767
- sign(path, section = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3768
- const type = section[0];
3769
- const version = section[1];
3770
- const access = section[2];
3771
- const isSandbox = this.safeValue(this.options, 'sandboxMode', false);
3772
- if (isSandbox && (type !== 'swap')) {
3773
- throw new errors.NotSupported(this.id + ' does not have a testnet/sandbox URL for ' + type + ' endpoints');
3774
- }
3775
- let url = this.implodeHostname(this.urls['api'][type]);
3776
- if (type === 'spot' && version === 'v3') {
3777
- url += '/api';
3778
- }
3779
- else {
3780
- url += '/' + type;
3781
- }
3782
- url += '/' + version + '/';
3783
- path = this.implodeParams(path, params);
3784
- url += path;
3785
- params = this.omit(params, this.extractParams(path));
3786
- params = this.keysort(params);
3787
- if (access === 'public') {
3788
- params['timestamp'] = this.nonce();
3789
- if (Object.keys(params).length) {
3790
- url += '?' + this.urlencode(params);
3791
- }
3792
- }
3793
- else if (access === 'private') {
3794
- this.checkRequiredCredentials();
3795
- params['timestamp'] = this.nonce();
3796
- const parsedParams = this.parseParams(params);
3797
- let query = this.urlencode(parsedParams);
3798
- const signature = this.hmac(this.encode(this.rawencode(parsedParams)), this.encode(this.secret), sha256.sha256);
3799
- if (Object.keys(params).length) {
3800
- query = '?' + query + '&';
3801
- }
3802
- else {
3803
- query += '?';
3804
- }
3805
- query += 'signature=' + signature;
3806
- headers = {
3807
- 'X-BX-APIKEY': this.apiKey,
3808
- 'X-SOURCE-KEY': this.safeString(this.options, 'broker', 'CCXT'),
3809
- };
3810
- url += query;
3811
- }
3812
- return { 'url': url, 'method': method, 'body': body, 'headers': headers };
3813
- }
3814
- nonce() {
3815
- return this.milliseconds();
3816
- }
3817
- setSandboxMode(enable) {
3818
- super.setSandboxMode(enable);
3819
- this.options['sandboxMode'] = enable;
3820
- }
3821
- handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3822
- if (response === undefined) {
3823
- return undefined; // fallback to default error handler
3824
- }
3825
- //
3826
- // {
3827
- // "code": 80014,
3828
- // "msg": "Invalid parameters, err:Key: 'GetTickerRequest.Symbol' Error:Field validation for "Symbol" failed on the "len=0|endswith=-USDT" tag",
3829
- // "data": {
3830
- // }
3831
- // }
3832
- //
3833
- const code = this.safeString(response, 'code');
3834
- const message = this.safeString(response, 'msg');
3835
- if (code !== undefined && code !== '0') {
3836
- const feedback = this.id + ' ' + body;
3837
- this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
3838
- this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
3839
- this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
3840
- throw new errors.ExchangeError(feedback); // unknown message
3841
- }
3842
- return undefined;
3843
- }
3844
- }
3845
-
3846
- module.exports = bingx;