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