ccxt 4.5.31 → 4.5.33

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 (992) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +7 -7
  3. package/dist/cjs/ccxt.js +6 -1
  4. package/dist/cjs/src/abstract/alpaca.js +1 -1
  5. package/dist/cjs/src/abstract/apex.js +1 -1
  6. package/dist/cjs/src/abstract/arkham.js +1 -1
  7. package/dist/cjs/src/abstract/ascendex.js +1 -1
  8. package/dist/cjs/src/abstract/aster.js +11 -0
  9. package/dist/cjs/src/abstract/backpack.js +1 -1
  10. package/dist/cjs/src/abstract/bigone.js +1 -1
  11. package/dist/cjs/src/abstract/binance.js +1 -1
  12. package/dist/cjs/src/abstract/bingx.js +1 -1
  13. package/dist/cjs/src/abstract/bit2c.js +1 -1
  14. package/dist/cjs/src/abstract/bitbank.js +1 -1
  15. package/dist/cjs/src/abstract/bitbns.js +1 -1
  16. package/dist/cjs/src/abstract/bitfinex.js +1 -1
  17. package/dist/cjs/src/abstract/bitflyer.js +1 -1
  18. package/dist/cjs/src/abstract/bitget.js +1 -1
  19. package/dist/cjs/src/abstract/bithumb.js +1 -1
  20. package/dist/cjs/src/abstract/bitmart.js +1 -1
  21. package/dist/cjs/src/abstract/bitmex.js +1 -1
  22. package/dist/cjs/src/abstract/bitopro.js +1 -1
  23. package/dist/cjs/src/abstract/bitrue.js +1 -1
  24. package/dist/cjs/src/abstract/bitso.js +1 -1
  25. package/dist/cjs/src/abstract/bitstamp.js +1 -1
  26. package/dist/cjs/src/abstract/bitteam.js +1 -1
  27. package/dist/cjs/src/abstract/bittrade.js +1 -1
  28. package/dist/cjs/src/abstract/bitvavo.js +1 -1
  29. package/dist/cjs/src/abstract/blockchaincom.js +1 -1
  30. package/dist/cjs/src/abstract/blofin.js +1 -1
  31. package/dist/cjs/src/abstract/btcalpha.js +1 -1
  32. package/dist/cjs/src/abstract/btcbox.js +1 -1
  33. package/dist/cjs/src/abstract/btcmarkets.js +1 -1
  34. package/dist/cjs/src/abstract/btcturk.js +1 -1
  35. package/dist/cjs/src/abstract/bullish.js +1 -1
  36. package/dist/cjs/src/abstract/bybit.js +1 -1
  37. package/dist/cjs/src/abstract/bydfi.js +1 -1
  38. package/dist/cjs/src/abstract/cex.js +1 -1
  39. package/dist/cjs/src/abstract/coinbase.js +1 -1
  40. package/dist/cjs/src/abstract/coinbaseexchange.js +1 -1
  41. package/dist/cjs/src/abstract/coinbaseinternational.js +1 -1
  42. package/dist/cjs/src/abstract/coincatch.js +1 -1
  43. package/dist/cjs/src/abstract/coincheck.js +1 -1
  44. package/dist/cjs/src/abstract/coinex.js +1 -1
  45. package/dist/cjs/src/abstract/coinmate.js +1 -1
  46. package/dist/cjs/src/abstract/coinmetro.js +1 -1
  47. package/dist/cjs/src/abstract/coinone.js +1 -1
  48. package/dist/cjs/src/abstract/coinsph.js +1 -1
  49. package/dist/cjs/src/abstract/coinspot.js +1 -1
  50. package/dist/cjs/src/abstract/cryptocom.js +1 -1
  51. package/dist/cjs/src/abstract/cryptomus.js +1 -1
  52. package/dist/cjs/src/abstract/deepcoin.js +1 -1
  53. package/dist/cjs/src/abstract/defx.js +1 -1
  54. package/dist/cjs/src/abstract/delta.js +1 -1
  55. package/dist/cjs/src/abstract/deribit.js +1 -1
  56. package/dist/cjs/src/abstract/derive.js +1 -1
  57. package/dist/cjs/src/abstract/digifinex.js +1 -1
  58. package/dist/cjs/src/abstract/dydx.js +1 -1
  59. package/dist/cjs/src/abstract/exmo.js +1 -1
  60. package/dist/cjs/src/abstract/foxbit.js +1 -1
  61. package/dist/cjs/src/abstract/gate.js +1 -1
  62. package/dist/cjs/src/abstract/gemini.js +1 -1
  63. package/dist/cjs/src/abstract/hashkey.js +1 -1
  64. package/dist/cjs/src/abstract/hibachi.js +1 -1
  65. package/dist/cjs/src/abstract/hitbtc.js +1 -1
  66. package/dist/cjs/src/abstract/hollaex.js +1 -1
  67. package/dist/cjs/src/abstract/htx.js +1 -1
  68. package/dist/cjs/src/abstract/hyperliquid.js +1 -1
  69. package/dist/cjs/src/abstract/independentreserve.js +1 -1
  70. package/dist/cjs/src/abstract/indodax.js +1 -1
  71. package/dist/cjs/src/abstract/kraken.js +1 -1
  72. package/dist/cjs/src/abstract/krakenfutures.js +1 -1
  73. package/dist/cjs/src/abstract/kucoin.js +1 -1
  74. package/dist/cjs/src/abstract/kucoinfutures.js +1 -1
  75. package/dist/cjs/src/abstract/latoken.js +1 -1
  76. package/dist/cjs/src/abstract/lbank.js +1 -1
  77. package/dist/cjs/src/abstract/luno.js +1 -1
  78. package/dist/cjs/src/abstract/mercado.js +1 -1
  79. package/dist/cjs/src/abstract/mexc.js +1 -1
  80. package/dist/cjs/src/abstract/modetrade.js +1 -1
  81. package/dist/cjs/src/abstract/ndax.js +1 -1
  82. package/dist/cjs/src/abstract/novadax.js +1 -1
  83. package/dist/cjs/src/abstract/okx.js +1 -1
  84. package/dist/cjs/src/abstract/onetrading.js +1 -1
  85. package/dist/cjs/src/abstract/oxfun.js +1 -1
  86. package/dist/cjs/src/abstract/p2b.js +1 -1
  87. package/dist/cjs/src/abstract/paradex.js +1 -1
  88. package/dist/cjs/src/abstract/paymium.js +1 -1
  89. package/dist/cjs/src/abstract/phemex.js +1 -1
  90. package/dist/cjs/src/abstract/poloniex.js +1 -1
  91. package/dist/cjs/src/abstract/probit.js +1 -1
  92. package/dist/cjs/src/abstract/timex.js +1 -1
  93. package/dist/cjs/src/abstract/tokocrypto.js +1 -1
  94. package/dist/cjs/src/abstract/toobit.js +1 -1
  95. package/dist/cjs/src/abstract/upbit.js +1 -1
  96. package/dist/cjs/src/abstract/wavesexchange.js +1 -1
  97. package/dist/cjs/src/abstract/whitebit.js +1 -1
  98. package/dist/cjs/src/abstract/woo.js +1 -1
  99. package/dist/cjs/src/abstract/woofipro.js +1 -1
  100. package/dist/cjs/src/abstract/xt.js +1 -1
  101. package/dist/cjs/src/abstract/yobit.js +1 -1
  102. package/dist/cjs/src/abstract/zaif.js +1 -1
  103. package/dist/cjs/src/abstract/zebpay.js +1 -1
  104. package/dist/cjs/src/abstract/zonda.js +1 -1
  105. package/dist/cjs/src/alpaca.js +1 -1
  106. package/dist/cjs/src/apex.js +1 -1
  107. package/dist/cjs/src/arkham.js +1 -1
  108. package/dist/cjs/src/ascendex.js +1 -1
  109. package/dist/cjs/src/aster.js +3803 -0
  110. package/dist/cjs/src/backpack.js +2 -2
  111. package/dist/cjs/src/base/Exchange.js +19 -1
  112. package/dist/cjs/src/base/Precise.js +0 -6
  113. package/dist/cjs/src/base/errors.js +0 -6
  114. package/dist/cjs/src/base/functions/crypto.js +1 -1
  115. package/dist/cjs/src/base/functions/encode.js +1 -1
  116. package/dist/cjs/src/base/functions/misc.js +0 -1
  117. package/dist/cjs/src/base/functions/number.js +0 -6
  118. package/dist/cjs/src/base/functions/platform.js +0 -6
  119. package/dist/cjs/src/base/functions/rsa.js +0 -1
  120. package/dist/cjs/src/base/functions/string.js +0 -6
  121. package/dist/cjs/src/base/functions/throttle.js +1 -1
  122. package/dist/cjs/src/base/functions/time.js +0 -6
  123. package/dist/cjs/src/base/functions/totp.js +0 -1
  124. package/dist/cjs/src/base/functions/type.js +0 -6
  125. package/dist/cjs/src/base/functions.js +1 -1
  126. package/dist/cjs/src/base/ws/Cache.js +0 -6
  127. package/dist/cjs/src/base/ws/Client.js +0 -1
  128. package/dist/cjs/src/base/ws/Future.js +1 -1
  129. package/dist/cjs/src/base/ws/OrderBook.js +1 -1
  130. package/dist/cjs/src/base/ws/OrderBookSide.js +0 -6
  131. package/dist/cjs/src/base/ws/WsClient.js +1 -1
  132. package/dist/cjs/src/bequant.js +1 -1
  133. package/dist/cjs/src/bigone.js +2 -2
  134. package/dist/cjs/src/binance.js +4 -1
  135. package/dist/cjs/src/binancecoinm.js +1 -1
  136. package/dist/cjs/src/binanceus.js +1 -1
  137. package/dist/cjs/src/binanceusdm.js +1 -1
  138. package/dist/cjs/src/bingx.js +74 -1
  139. package/dist/cjs/src/bit2c.js +1 -1
  140. package/dist/cjs/src/bitbank.js +1 -1
  141. package/dist/cjs/src/bitbns.js +1 -1
  142. package/dist/cjs/src/bitfinex.js +1 -1
  143. package/dist/cjs/src/bitflyer.js +1 -1
  144. package/dist/cjs/src/bitget.js +4 -2
  145. package/dist/cjs/src/bithumb.js +1 -1
  146. package/dist/cjs/src/bitmart.js +1 -1
  147. package/dist/cjs/src/bitmex.js +1 -1
  148. package/dist/cjs/src/bitopro.js +1 -1
  149. package/dist/cjs/src/bitrue.js +1 -1
  150. package/dist/cjs/src/bitso.js +1 -1
  151. package/dist/cjs/src/bitstamp.js +1 -1
  152. package/dist/cjs/src/bitteam.js +1 -1
  153. package/dist/cjs/src/bittrade.js +1 -1
  154. package/dist/cjs/src/blockchaincom.js +1 -1
  155. package/dist/cjs/src/blofin.js +1 -1
  156. package/dist/cjs/src/btcalpha.js +1 -1
  157. package/dist/cjs/src/btcbox.js +1 -1
  158. package/dist/cjs/src/btcmarkets.js +1 -1
  159. package/dist/cjs/src/btcturk.js +1 -1
  160. package/dist/cjs/src/bullish.js +1 -1
  161. package/dist/cjs/src/bybit.js +10 -4
  162. package/dist/cjs/src/bydfi.js +1 -1
  163. package/dist/cjs/src/cex.js +1 -1
  164. package/dist/cjs/src/coinbaseadvanced.js +1 -1
  165. package/dist/cjs/src/coincatch.js +1 -1
  166. package/dist/cjs/src/coincheck.js +1 -1
  167. package/dist/cjs/src/coinex.js +1 -1
  168. package/dist/cjs/src/coinmate.js +1 -1
  169. package/dist/cjs/src/coinmetro.js +1 -1
  170. package/dist/cjs/src/coinone.js +1 -1
  171. package/dist/cjs/src/coinsph.js +0 -1
  172. package/dist/cjs/src/coinspot.js +1 -1
  173. package/dist/cjs/src/cryptocom.js +1 -1
  174. package/dist/cjs/src/cryptomus.js +2 -2
  175. package/dist/cjs/src/deepcoin.js +1 -1
  176. package/dist/cjs/src/defx.js +1 -1
  177. package/dist/cjs/src/delta.js +1 -1
  178. package/dist/cjs/src/deribit.js +1 -1
  179. package/dist/cjs/src/derive.js +1 -1
  180. package/dist/cjs/src/digifinex.js +1 -1
  181. package/dist/cjs/src/dydx.js +1 -1
  182. package/dist/cjs/src/exmo.js +1 -1
  183. package/dist/cjs/src/fmfwio.js +1 -1
  184. package/dist/cjs/src/foxbit.js +1 -1
  185. package/dist/cjs/src/gate.js +5 -2
  186. package/dist/cjs/src/gateio.js +1 -1
  187. package/dist/cjs/src/gemini.js +1 -1
  188. package/dist/cjs/src/hashkey.js +1 -1
  189. package/dist/cjs/src/hibachi.js +1 -1
  190. package/dist/cjs/src/hitbtc.js +0 -1
  191. package/dist/cjs/src/hollaex.js +1 -1
  192. package/dist/cjs/src/htx.js +2 -2
  193. package/dist/cjs/src/huobi.js +1 -1
  194. package/dist/cjs/src/hyperliquid.js +1 -1
  195. package/dist/cjs/src/independentreserve.js +1 -1
  196. package/dist/cjs/src/indodax.js +1 -1
  197. package/dist/cjs/src/kraken.js +1 -1
  198. package/dist/cjs/src/krakenfutures.js +54 -10
  199. package/dist/cjs/src/kucoin.js +1 -1
  200. package/dist/cjs/src/kucoinfutures.js +1 -1
  201. package/dist/cjs/src/latoken.js +1 -1
  202. package/dist/cjs/src/lbank.js +1 -1
  203. package/dist/cjs/src/luno.js +1 -1
  204. package/dist/cjs/src/mercado.js +1 -1
  205. package/dist/cjs/src/mexc.js +1 -1
  206. package/dist/cjs/src/modetrade.js +1 -1
  207. package/dist/cjs/src/myokx.js +1 -1
  208. package/dist/cjs/src/ndax.js +1 -1
  209. package/dist/cjs/src/novadax.js +1 -1
  210. package/dist/cjs/src/okx.js +15 -6
  211. package/dist/cjs/src/okxus.js +1 -1
  212. package/dist/cjs/src/onetrading.js +1 -1
  213. package/dist/cjs/src/oxfun.js +1 -1
  214. package/dist/cjs/src/p2b.js +1 -1
  215. package/dist/cjs/src/paradex.js +1 -1
  216. package/dist/cjs/src/paymium.js +1 -1
  217. package/dist/cjs/src/poloniex.js +1 -1
  218. package/dist/cjs/src/pro/alpaca.js +1 -1
  219. package/dist/cjs/src/pro/apex.js +1 -1
  220. package/dist/cjs/src/pro/arkham.js +1 -1
  221. package/dist/cjs/src/pro/ascendex.js +1 -1
  222. package/dist/cjs/src/pro/aster.js +1046 -0
  223. package/dist/cjs/src/pro/backpack.js +3 -2
  224. package/dist/cjs/src/pro/bequant.js +1 -1
  225. package/dist/cjs/src/pro/binancecoinm.js +1 -1
  226. package/dist/cjs/src/pro/binanceus.js +1 -1
  227. package/dist/cjs/src/pro/binanceusdm.js +1 -1
  228. package/dist/cjs/src/pro/bingx.js +1 -1
  229. package/dist/cjs/src/pro/bitfinex.js +1 -1
  230. package/dist/cjs/src/pro/bitget.js +6 -6
  231. package/dist/cjs/src/pro/bithumb.js +1 -1
  232. package/dist/cjs/src/pro/bitmart.js +1 -1
  233. package/dist/cjs/src/pro/bitmex.js +1 -1
  234. package/dist/cjs/src/pro/bitrue.js +1 -1
  235. package/dist/cjs/src/pro/bitstamp.js +1 -1
  236. package/dist/cjs/src/pro/bitvavo.js +1 -1
  237. package/dist/cjs/src/pro/blockchaincom.js +1 -1
  238. package/dist/cjs/src/pro/blofin.js +1 -1
  239. package/dist/cjs/src/pro/bullish.js +1 -1
  240. package/dist/cjs/src/pro/bybit.js +1 -1
  241. package/dist/cjs/src/pro/bydfi.js +1 -1
  242. package/dist/cjs/src/pro/cex.js +1 -1
  243. package/dist/cjs/src/pro/coinbase.js +1 -1
  244. package/dist/cjs/src/pro/coinbaseadvanced.js +1 -1
  245. package/dist/cjs/src/pro/coinbaseexchange.js +1 -1
  246. package/dist/cjs/src/pro/coinbaseinternational.js +1 -1
  247. package/dist/cjs/src/pro/coincatch.js +1 -1
  248. package/dist/cjs/src/pro/coincheck.js +1 -1
  249. package/dist/cjs/src/pro/coinex.js +1 -1
  250. package/dist/cjs/src/pro/coinone.js +1 -1
  251. package/dist/cjs/src/pro/cryptocom.js +1 -1
  252. package/dist/cjs/src/pro/deepcoin.js +1 -1
  253. package/dist/cjs/src/pro/defx.js +1 -1
  254. package/dist/cjs/src/pro/deribit.js +1 -1
  255. package/dist/cjs/src/pro/dydx.js +2 -2
  256. package/dist/cjs/src/pro/exmo.js +1 -1
  257. package/dist/cjs/src/pro/gate.js +1 -1
  258. package/dist/cjs/src/pro/gateio.js +1 -1
  259. package/dist/cjs/src/pro/gemini.js +1 -1
  260. package/dist/cjs/src/pro/hashkey.js +1 -1
  261. package/dist/cjs/src/pro/hitbtc.js +1 -1
  262. package/dist/cjs/src/pro/hollaex.js +1 -1
  263. package/dist/cjs/src/pro/htx.js +1 -1
  264. package/dist/cjs/src/pro/huobi.js +1 -1
  265. package/dist/cjs/src/pro/hyperliquid.js +1 -1
  266. package/dist/cjs/src/pro/independentreserve.js +1 -1
  267. package/dist/cjs/src/pro/kraken.js +1 -1
  268. package/dist/cjs/src/pro/krakenfutures.js +1 -1
  269. package/dist/cjs/src/pro/kucoin.js +1 -1
  270. package/dist/cjs/src/pro/kucoinfutures.js +1 -1
  271. package/dist/cjs/src/pro/lbank.js +0 -1
  272. package/dist/cjs/src/pro/luno.js +1 -1
  273. package/dist/cjs/src/pro/mexc.js +1 -1
  274. package/dist/cjs/src/pro/myokx.js +1 -1
  275. package/dist/cjs/src/pro/ndax.js +1 -1
  276. package/dist/cjs/src/pro/okx.js +2 -2
  277. package/dist/cjs/src/pro/okxus.js +1 -1
  278. package/dist/cjs/src/pro/onetrading.js +1 -1
  279. package/dist/cjs/src/pro/oxfun.js +1 -1
  280. package/dist/cjs/src/pro/p2b.js +1 -1
  281. package/dist/cjs/src/pro/paradex.js +143 -3
  282. package/dist/cjs/src/pro/phemex.js +1 -1
  283. package/dist/cjs/src/pro/poloniex.js +1 -1
  284. package/dist/cjs/src/pro/probit.js +1 -1
  285. package/dist/cjs/src/pro/toobit.js +1 -1
  286. package/dist/cjs/src/pro/upbit.js +1 -1
  287. package/dist/cjs/src/pro/whitebit.js +1 -1
  288. package/dist/cjs/src/pro/xt.js +1 -1
  289. package/dist/cjs/src/probit.js +1 -1
  290. package/dist/cjs/src/protobuf/mexc/compiled.cjs.js +1 -0
  291. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/base/v1beta1/coin.js +0 -1
  292. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/v1beta1/multisig.js +0 -1
  293. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/crypto/secp256k1/keys.js +0 -1
  294. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/tx/signing/v1beta1/signing.js +0 -1
  295. package/dist/cjs/src/static_dependencies/dydx-v4-client/cosmos/tx/v1beta1/tx.js +0 -1
  296. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/accountplus/tx.js +0 -1
  297. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/clob_pair.js +0 -1
  298. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order.js +0 -1
  299. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order_removals.js +0 -1
  300. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/tx.js +0 -1
  301. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/transfer.js +0 -1
  302. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/tx.js +0 -1
  303. package/dist/cjs/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/subaccount.js +0 -1
  304. package/dist/cjs/src/static_dependencies/dydx-v4-client/google/protobuf/any.js +0 -1
  305. package/dist/cjs/src/static_dependencies/dydx-v4-client/helpers.js +0 -6
  306. package/dist/cjs/src/static_dependencies/dydx-v4-client/onboarding.js +0 -1
  307. package/dist/cjs/src/static_dependencies/dydx-v4-client/registry.js +0 -1
  308. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +0 -6
  309. package/dist/cjs/src/static_dependencies/ethers/address/address.js +1 -1
  310. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +0 -6
  311. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +0 -1
  312. package/dist/cjs/src/static_dependencies/ethers/coders/anonymous.js +0 -1
  313. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +0 -1
  314. package/dist/cjs/src/static_dependencies/ethers/coders/boolean.js +0 -1
  315. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +0 -1
  316. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +0 -1
  317. package/dist/cjs/src/static_dependencies/ethers/coders/null.js +0 -1
  318. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +0 -1
  319. package/dist/cjs/src/static_dependencies/ethers/coders/string.js +0 -1
  320. package/dist/cjs/src/static_dependencies/ethers/coders/tuple.js +0 -1
  321. package/dist/cjs/src/static_dependencies/ethers/fragments.js +0 -6
  322. package/dist/cjs/src/static_dependencies/ethers/hash/typed-data.js +0 -6
  323. package/dist/cjs/src/static_dependencies/ethers/index.js +10 -1
  324. package/dist/cjs/src/static_dependencies/ethers/interface.js +0 -6
  325. package/dist/cjs/src/static_dependencies/ethers/typed.js +0 -6
  326. package/dist/cjs/src/static_dependencies/ethers/utils/base58.js +13 -1
  327. package/dist/cjs/src/static_dependencies/ethers/utils/data.js +6 -1
  328. package/dist/cjs/src/static_dependencies/ethers/utils/errors.js +9 -1
  329. package/dist/cjs/src/static_dependencies/ethers/utils/events.js +0 -6
  330. package/dist/cjs/src/static_dependencies/ethers/utils/fixednumber.js +0 -6
  331. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +7 -1
  332. package/dist/cjs/src/static_dependencies/ethers/utils/maths.js +5 -1
  333. package/dist/cjs/src/static_dependencies/ethers/utils/properties.js +0 -6
  334. package/dist/cjs/src/static_dependencies/ethers/utils/utf8.js +8 -1
  335. package/dist/cjs/src/static_dependencies/fflake/browser.js +1 -1
  336. package/dist/cjs/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -1
  337. package/dist/cjs/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -1
  338. package/dist/cjs/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +1 -1
  339. package/dist/cjs/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -6
  340. package/dist/cjs/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -6
  341. package/dist/cjs/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -6
  342. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -1
  343. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +1 -1
  344. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -6
  345. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +1 -1
  346. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +1 -1
  347. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -6
  348. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +1 -1
  349. package/dist/cjs/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -6
  350. package/dist/cjs/src/static_dependencies/messagepack/msgpack.js +0 -6
  351. package/dist/cjs/src/static_dependencies/noble-curves/_shortw_utils.js +1 -1
  352. package/dist/cjs/src/static_dependencies/noble-curves/abstract/curve.js +1 -1
  353. package/dist/cjs/src/static_dependencies/noble-curves/abstract/edwards.js +1 -1
  354. package/dist/cjs/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +0 -1
  355. package/dist/cjs/src/static_dependencies/noble-curves/abstract/modular.js +1 -1
  356. package/dist/cjs/src/static_dependencies/noble-curves/abstract/montgomery.js +1 -1
  357. package/dist/cjs/src/static_dependencies/noble-curves/abstract/poseidon.js +1 -1
  358. package/dist/cjs/src/static_dependencies/noble-curves/abstract/utils.js +0 -6
  359. package/dist/cjs/src/static_dependencies/noble-curves/abstract/weierstrass.js +1 -1
  360. package/dist/cjs/src/static_dependencies/noble-curves/ed25519.js +1 -1
  361. package/dist/cjs/src/static_dependencies/noble-curves/p256.js +1 -1
  362. package/dist/cjs/src/static_dependencies/noble-curves/secp256k1.js +1 -1
  363. package/dist/cjs/src/static_dependencies/noble-hashes/_assert.js +0 -6
  364. package/dist/cjs/src/static_dependencies/noble-hashes/_sha2.js +0 -1
  365. package/dist/cjs/src/static_dependencies/noble-hashes/_u64.js +0 -6
  366. package/dist/cjs/src/static_dependencies/noble-hashes/crypto.js +0 -6
  367. package/dist/cjs/src/static_dependencies/noble-hashes/hmac.js +0 -1
  368. package/dist/cjs/src/static_dependencies/noble-hashes/md5.js +0 -1
  369. package/dist/cjs/src/static_dependencies/noble-hashes/pbkdf2.js +0 -1
  370. package/dist/cjs/src/static_dependencies/noble-hashes/ripemd160.js +0 -1
  371. package/dist/cjs/src/static_dependencies/noble-hashes/sha1.js +0 -1
  372. package/dist/cjs/src/static_dependencies/noble-hashes/sha256.js +0 -1
  373. package/dist/cjs/src/static_dependencies/noble-hashes/sha3.js +0 -1
  374. package/dist/cjs/src/static_dependencies/noble-hashes/sha512.js +0 -1
  375. package/dist/cjs/src/static_dependencies/noble-hashes/utils.js +1 -1
  376. package/dist/cjs/src/static_dependencies/node-fetch/body.js +5 -1
  377. package/dist/cjs/src/static_dependencies/node-fetch/errors/abort-error.js +0 -1
  378. package/dist/cjs/src/static_dependencies/node-fetch/errors/base.js +0 -6
  379. package/dist/cjs/src/static_dependencies/node-fetch/errors/fetch-error.js +0 -1
  380. package/dist/cjs/src/static_dependencies/node-fetch/headers.js +5 -1
  381. package/dist/cjs/src/static_dependencies/node-fetch/index.js +7 -1
  382. package/dist/cjs/src/static_dependencies/node-fetch/request.js +7 -1
  383. package/dist/cjs/src/static_dependencies/node-fetch/response.js +5 -1
  384. package/dist/cjs/src/static_dependencies/node-fetch/utils/get-search.js +0 -6
  385. package/dist/cjs/src/static_dependencies/node-fetch/utils/is-redirect.js +0 -6
  386. package/dist/cjs/src/static_dependencies/node-fetch/utils/is.js +0 -6
  387. package/dist/cjs/src/static_dependencies/node-fetch/utils/referrer.js +0 -1
  388. package/dist/cjs/src/static_dependencies/proxies/agent-base/index.js +0 -1
  389. package/dist/cjs/src/static_dependencies/proxies/http-proxy-agent/index.js +0 -1
  390. package/dist/cjs/src/static_dependencies/proxies/https-proxy-agent/index.js +0 -1
  391. package/dist/cjs/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +0 -6
  392. package/dist/cjs/src/static_dependencies/qs/formats.js +0 -6
  393. package/dist/cjs/src/static_dependencies/qs/index.js +0 -1
  394. package/dist/cjs/src/static_dependencies/qs/parse.js +0 -1
  395. package/dist/cjs/src/static_dependencies/qs/stringify.js +0 -1
  396. package/dist/cjs/src/static_dependencies/qs/utils.js +0 -6
  397. package/dist/cjs/src/static_dependencies/scure-base/index.js +0 -6
  398. package/dist/cjs/src/static_dependencies/scure-bip32/index.js +19 -1
  399. package/dist/cjs/src/static_dependencies/scure-bip39/index.js +1 -1
  400. package/dist/cjs/src/static_dependencies/scure-bip39/wordlists/english.js +0 -6
  401. package/dist/cjs/src/static_dependencies/scure-starknet/index.js +1 -1
  402. package/dist/cjs/src/static_dependencies/starknet/constants.js +1 -1
  403. package/dist/cjs/src/static_dependencies/starknet/types/calldata.js +0 -6
  404. package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/abi.js +0 -6
  405. package/dist/cjs/src/static_dependencies/starknet/types/lib/contract/index.js +0 -6
  406. package/dist/cjs/src/static_dependencies/starknet/types/lib/index.js +0 -6
  407. package/dist/cjs/src/static_dependencies/starknet/types/typedData.js +0 -6
  408. package/dist/cjs/src/static_dependencies/starknet/utils/assert.js +0 -6
  409. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +1 -1
  410. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +1 -1
  411. package/dist/cjs/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +1 -1
  412. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/byteArray.js +0 -1
  413. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/cairo.js +0 -1
  414. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +0 -6
  415. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +0 -6
  416. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +0 -6
  417. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/formatter.js +0 -1
  418. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/index.js +1 -1
  419. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/index.js +0 -1
  420. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +0 -1
  421. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +0 -6
  422. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +0 -1
  423. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/requestParser.js +0 -1
  424. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/responseParser.js +0 -1
  425. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/tuple.js +1 -1
  426. package/dist/cjs/src/static_dependencies/starknet/utils/calldata/validate.js +4 -1
  427. package/dist/cjs/src/static_dependencies/starknet/utils/encode.js +0 -1
  428. package/dist/cjs/src/static_dependencies/starknet/utils/hash/classHash.js +3 -1
  429. package/dist/cjs/src/static_dependencies/starknet/utils/merkle.js +0 -1
  430. package/dist/cjs/src/static_dependencies/starknet/utils/num.js +0 -1
  431. package/dist/cjs/src/static_dependencies/starknet/utils/selector.js +0 -1
  432. package/dist/cjs/src/static_dependencies/starknet/utils/shortString.js +0 -1
  433. package/dist/cjs/src/static_dependencies/starknet/utils/typedData.js +1 -1
  434. package/dist/cjs/src/static_dependencies/watchable/src/unpromise.js +0 -6
  435. package/dist/cjs/src/static_dependencies/zklink/zklink-sdk-web.js +0 -6
  436. package/dist/cjs/src/timex.js +0 -1
  437. package/dist/cjs/src/tokocrypto.js +1 -1
  438. package/dist/cjs/src/toobit.js +1 -1
  439. package/dist/cjs/src/upbit.js +1 -1
  440. package/dist/cjs/src/wavesexchange.js +1 -1
  441. package/dist/cjs/src/whitebit.js +3 -3
  442. package/dist/cjs/src/woo.js +1 -1
  443. package/dist/cjs/src/woofipro.js +1 -1
  444. package/dist/cjs/src/xt.js +1 -1
  445. package/dist/cjs/src/yobit.js +1 -1
  446. package/dist/cjs/src/zaif.js +1 -1
  447. package/dist/cjs/src/zebpay.js +1 -1
  448. package/dist/cjs/src/zonda.js +1 -1
  449. package/js/ccxt.d.ts +8 -2
  450. package/js/ccxt.js +6 -8
  451. package/js/src/abstract/alpaca.js +0 -6
  452. package/js/src/abstract/apex.js +0 -6
  453. package/js/src/abstract/arkham.js +0 -6
  454. package/js/src/abstract/ascendex.js +0 -6
  455. package/js/src/abstract/aster.d.ts +88 -0
  456. package/js/src/abstract/aster.js +5 -0
  457. package/js/src/abstract/backpack.js +0 -6
  458. package/js/src/abstract/bequant.js +0 -6
  459. package/js/src/abstract/bigone.js +0 -6
  460. package/js/src/abstract/binance.d.ts +3 -0
  461. package/js/src/abstract/binance.js +0 -6
  462. package/js/src/abstract/binancecoinm.d.ts +3 -0
  463. package/js/src/abstract/binancecoinm.js +0 -6
  464. package/js/src/abstract/binanceus.d.ts +3 -0
  465. package/js/src/abstract/binanceus.js +0 -6
  466. package/js/src/abstract/binanceusdm.d.ts +3 -0
  467. package/js/src/abstract/binanceusdm.js +0 -6
  468. package/js/src/abstract/bingx.js +0 -6
  469. package/js/src/abstract/bit2c.js +0 -6
  470. package/js/src/abstract/bitbank.js +0 -6
  471. package/js/src/abstract/bitbns.js +0 -6
  472. package/js/src/abstract/bitfinex.js +0 -6
  473. package/js/src/abstract/bitflyer.js +0 -6
  474. package/js/src/abstract/bitget.js +0 -6
  475. package/js/src/abstract/bithumb.js +0 -6
  476. package/js/src/abstract/bitmart.js +0 -6
  477. package/js/src/abstract/bitmex.js +0 -6
  478. package/js/src/abstract/bitopro.js +0 -6
  479. package/js/src/abstract/bitrue.js +0 -6
  480. package/js/src/abstract/bitso.js +0 -6
  481. package/js/src/abstract/bitstamp.js +0 -6
  482. package/js/src/abstract/bitteam.js +0 -6
  483. package/js/src/abstract/bittrade.js +0 -6
  484. package/js/src/abstract/bitvavo.js +0 -6
  485. package/js/src/abstract/blockchaincom.js +0 -6
  486. package/js/src/abstract/blofin.js +0 -6
  487. package/js/src/abstract/btcalpha.js +0 -6
  488. package/js/src/abstract/btcbox.js +0 -6
  489. package/js/src/abstract/btcmarkets.js +0 -6
  490. package/js/src/abstract/btcturk.js +0 -6
  491. package/js/src/abstract/bullish.js +0 -6
  492. package/js/src/abstract/bybit.js +0 -6
  493. package/js/src/abstract/bydfi.js +0 -6
  494. package/js/src/abstract/cex.js +0 -6
  495. package/js/src/abstract/coinbase.js +0 -6
  496. package/js/src/abstract/coinbaseadvanced.js +0 -6
  497. package/js/src/abstract/coinbaseexchange.js +0 -6
  498. package/js/src/abstract/coinbaseinternational.js +0 -6
  499. package/js/src/abstract/coincatch.js +0 -6
  500. package/js/src/abstract/coincheck.js +0 -6
  501. package/js/src/abstract/coinex.js +0 -6
  502. package/js/src/abstract/coinmate.js +0 -6
  503. package/js/src/abstract/coinmetro.js +0 -6
  504. package/js/src/abstract/coinone.js +0 -6
  505. package/js/src/abstract/coinsph.js +0 -6
  506. package/js/src/abstract/coinspot.js +0 -6
  507. package/js/src/abstract/cryptocom.js +0 -6
  508. package/js/src/abstract/cryptomus.js +0 -6
  509. package/js/src/abstract/deepcoin.js +0 -6
  510. package/js/src/abstract/defx.js +0 -6
  511. package/js/src/abstract/delta.js +0 -6
  512. package/js/src/abstract/deribit.js +0 -6
  513. package/js/src/abstract/derive.js +0 -6
  514. package/js/src/abstract/digifinex.js +0 -6
  515. package/js/src/abstract/dydx.js +0 -6
  516. package/js/src/abstract/exmo.js +0 -6
  517. package/js/src/abstract/fmfwio.js +0 -6
  518. package/js/src/abstract/foxbit.js +0 -6
  519. package/js/src/abstract/gate.js +0 -6
  520. package/js/src/abstract/gateio.js +0 -6
  521. package/js/src/abstract/gemini.js +0 -6
  522. package/js/src/abstract/hashkey.js +0 -6
  523. package/js/src/abstract/hibachi.js +0 -6
  524. package/js/src/abstract/hitbtc.js +0 -6
  525. package/js/src/abstract/hollaex.js +0 -6
  526. package/js/src/abstract/htx.js +0 -6
  527. package/js/src/abstract/huobi.js +0 -6
  528. package/js/src/abstract/hyperliquid.js +0 -6
  529. package/js/src/abstract/independentreserve.js +0 -6
  530. package/js/src/abstract/indodax.js +0 -6
  531. package/js/src/abstract/kraken.js +0 -6
  532. package/js/src/abstract/krakenfutures.d.ts +1 -0
  533. package/js/src/abstract/krakenfutures.js +0 -6
  534. package/js/src/abstract/kucoin.js +0 -6
  535. package/js/src/abstract/kucoinfutures.js +0 -6
  536. package/js/src/abstract/latoken.js +0 -6
  537. package/js/src/abstract/lbank.js +0 -6
  538. package/js/src/abstract/luno.js +0 -6
  539. package/js/src/abstract/mercado.js +0 -6
  540. package/js/src/abstract/mexc.js +0 -6
  541. package/js/src/abstract/modetrade.js +0 -6
  542. package/js/src/abstract/myokx.js +0 -6
  543. package/js/src/abstract/ndax.js +0 -6
  544. package/js/src/abstract/novadax.js +0 -6
  545. package/js/src/abstract/okx.js +0 -6
  546. package/js/src/abstract/okxus.js +0 -6
  547. package/js/src/abstract/onetrading.js +0 -6
  548. package/js/src/abstract/oxfun.js +0 -6
  549. package/js/src/abstract/p2b.js +0 -6
  550. package/js/src/abstract/paradex.js +0 -6
  551. package/js/src/abstract/paymium.js +0 -6
  552. package/js/src/abstract/phemex.js +0 -6
  553. package/js/src/abstract/poloniex.js +0 -6
  554. package/js/src/abstract/probit.js +0 -6
  555. package/js/src/abstract/timex.js +0 -6
  556. package/js/src/abstract/tokocrypto.js +0 -6
  557. package/js/src/abstract/toobit.js +0 -6
  558. package/js/src/abstract/upbit.js +0 -6
  559. package/js/src/abstract/wavesexchange.js +0 -6
  560. package/js/src/abstract/whitebit.js +0 -6
  561. package/js/src/abstract/woo.js +0 -6
  562. package/js/src/abstract/woofipro.js +0 -6
  563. package/js/src/abstract/xt.js +0 -6
  564. package/js/src/abstract/yobit.js +0 -6
  565. package/js/src/abstract/zaif.js +0 -6
  566. package/js/src/abstract/zebpay.js +0 -6
  567. package/js/src/abstract/zonda.js +0 -6
  568. package/js/src/alpaca.js +0 -6
  569. package/js/src/apex.js +0 -6
  570. package/js/src/arkham.js +0 -6
  571. package/js/src/ascendex.js +0 -6
  572. package/js/src/aster.d.ts +563 -0
  573. package/js/src/aster.js +3796 -0
  574. package/js/src/backpack.js +1 -7
  575. package/js/src/base/Exchange.d.ts +1 -0
  576. package/js/src/base/Exchange.js +19 -6
  577. package/js/src/base/Precise.js +0 -6
  578. package/js/src/base/errorHierarchy.js +0 -6
  579. package/js/src/base/errors.js +0 -6
  580. package/js/src/base/functions/crypto.js +0 -6
  581. package/js/src/base/functions/encode.js +0 -6
  582. package/js/src/base/functions/generic.js +0 -6
  583. package/js/src/base/functions/misc.js +0 -6
  584. package/js/src/base/functions/number.js +0 -6
  585. package/js/src/base/functions/platform.js +0 -6
  586. package/js/src/base/functions/rsa.js +0 -6
  587. package/js/src/base/functions/string.js +0 -6
  588. package/js/src/base/functions/throttle.js +0 -6
  589. package/js/src/base/functions/time.js +0 -6
  590. package/js/src/base/functions/totp.js +0 -6
  591. package/js/src/base/functions/type.js +0 -6
  592. package/js/src/base/functions.js +0 -6
  593. package/js/src/base/types.js +0 -6
  594. package/js/src/base/ws/Cache.js +0 -6
  595. package/js/src/base/ws/Client.js +0 -6
  596. package/js/src/base/ws/Future.js +0 -6
  597. package/js/src/base/ws/OrderBook.js +0 -6
  598. package/js/src/base/ws/OrderBookSide.js +0 -6
  599. package/js/src/base/ws/WsClient.js +0 -6
  600. package/js/src/base/ws/functions.js +0 -6
  601. package/js/src/bequant.js +0 -6
  602. package/js/src/bigone.js +1 -7
  603. package/js/src/binance.js +3 -6
  604. package/js/src/binancecoinm.js +0 -6
  605. package/js/src/binanceus.js +0 -6
  606. package/js/src/binanceusdm.js +0 -6
  607. package/js/src/bingx.d.ts +12 -1
  608. package/js/src/bingx.js +73 -6
  609. package/js/src/bit2c.js +0 -6
  610. package/js/src/bitbank.js +0 -6
  611. package/js/src/bitbns.js +0 -6
  612. package/js/src/bitfinex.js +0 -6
  613. package/js/src/bitflyer.js +0 -6
  614. package/js/src/bitget.js +3 -7
  615. package/js/src/bithumb.js +0 -6
  616. package/js/src/bitmart.js +0 -6
  617. package/js/src/bitmex.js +0 -6
  618. package/js/src/bitopro.js +0 -6
  619. package/js/src/bitrue.js +0 -6
  620. package/js/src/bitso.js +0 -6
  621. package/js/src/bitstamp.js +0 -6
  622. package/js/src/bitteam.js +0 -6
  623. package/js/src/bittrade.js +0 -6
  624. package/js/src/bitvavo.js +0 -6
  625. package/js/src/blockchaincom.js +0 -6
  626. package/js/src/blofin.js +0 -6
  627. package/js/src/btcalpha.js +0 -6
  628. package/js/src/btcbox.js +0 -6
  629. package/js/src/btcmarkets.js +0 -6
  630. package/js/src/btcturk.js +0 -6
  631. package/js/src/bullish.js +0 -6
  632. package/js/src/bybit.js +9 -9
  633. package/js/src/bydfi.js +0 -6
  634. package/js/src/cex.js +0 -6
  635. package/js/src/coinbase.js +0 -6
  636. package/js/src/coinbaseadvanced.js +0 -6
  637. package/js/src/coinbaseexchange.js +0 -6
  638. package/js/src/coinbaseinternational.js +0 -6
  639. package/js/src/coincatch.js +0 -6
  640. package/js/src/coincheck.js +0 -6
  641. package/js/src/coinex.js +0 -6
  642. package/js/src/coinmate.js +0 -6
  643. package/js/src/coinmetro.js +0 -6
  644. package/js/src/coinone.js +0 -6
  645. package/js/src/coinsph.js +0 -6
  646. package/js/src/coinspot.js +0 -6
  647. package/js/src/cryptocom.js +0 -6
  648. package/js/src/cryptomus.js +1 -7
  649. package/js/src/deepcoin.js +0 -6
  650. package/js/src/defx.js +0 -6
  651. package/js/src/delta.js +0 -6
  652. package/js/src/deribit.js +0 -6
  653. package/js/src/derive.js +0 -6
  654. package/js/src/digifinex.js +0 -6
  655. package/js/src/dydx.js +0 -6
  656. package/js/src/exmo.js +0 -6
  657. package/js/src/fmfwio.js +0 -6
  658. package/js/src/foxbit.js +0 -6
  659. package/js/src/gate.js +4 -7
  660. package/js/src/gateio.js +0 -6
  661. package/js/src/gemini.js +0 -6
  662. package/js/src/hashkey.js +0 -6
  663. package/js/src/hibachi.js +0 -6
  664. package/js/src/hitbtc.js +0 -6
  665. package/js/src/hollaex.js +0 -6
  666. package/js/src/htx.js +1 -7
  667. package/js/src/huobi.js +0 -6
  668. package/js/src/hyperliquid.js +0 -6
  669. package/js/src/independentreserve.js +0 -6
  670. package/js/src/indodax.js +0 -6
  671. package/js/src/kraken.js +0 -6
  672. package/js/src/krakenfutures.d.ts +23 -0
  673. package/js/src/krakenfutures.js +53 -15
  674. package/js/src/kucoin.js +0 -6
  675. package/js/src/kucoinfutures.js +0 -6
  676. package/js/src/latoken.js +0 -6
  677. package/js/src/lbank.js +0 -6
  678. package/js/src/luno.js +0 -6
  679. package/js/src/mercado.js +0 -6
  680. package/js/src/mexc.js +0 -6
  681. package/js/src/modetrade.js +0 -6
  682. package/js/src/myokx.js +0 -6
  683. package/js/src/ndax.js +0 -6
  684. package/js/src/novadax.js +0 -6
  685. package/js/src/okx.js +14 -11
  686. package/js/src/okxus.js +0 -6
  687. package/js/src/onetrading.js +0 -6
  688. package/js/src/oxfun.js +0 -6
  689. package/js/src/p2b.js +0 -6
  690. package/js/src/paradex.js +0 -6
  691. package/js/src/paymium.js +0 -6
  692. package/js/src/phemex.js +0 -6
  693. package/js/src/poloniex.js +0 -6
  694. package/js/src/pro/alpaca.js +0 -6
  695. package/js/src/pro/apex.js +0 -6
  696. package/js/src/pro/arkham.js +0 -6
  697. package/js/src/pro/ascendex.js +0 -6
  698. package/js/src/pro/aster.d.ts +273 -0
  699. package/js/src/pro/aster.js +1039 -0
  700. package/js/src/pro/backpack.js +2 -7
  701. package/js/src/pro/bequant.js +0 -6
  702. package/js/src/pro/binance.js +0 -6
  703. package/js/src/pro/binancecoinm.js +0 -6
  704. package/js/src/pro/binanceus.js +0 -6
  705. package/js/src/pro/binanceusdm.js +0 -6
  706. package/js/src/pro/bingx.js +0 -6
  707. package/js/src/pro/bitfinex.js +0 -6
  708. package/js/src/pro/bitget.js +5 -11
  709. package/js/src/pro/bithumb.js +0 -6
  710. package/js/src/pro/bitmart.js +0 -6
  711. package/js/src/pro/bitmex.js +0 -6
  712. package/js/src/pro/bitopro.js +0 -6
  713. package/js/src/pro/bitrue.js +0 -6
  714. package/js/src/pro/bitstamp.js +0 -6
  715. package/js/src/pro/bittrade.js +0 -6
  716. package/js/src/pro/bitvavo.js +0 -6
  717. package/js/src/pro/blockchaincom.js +0 -6
  718. package/js/src/pro/blofin.js +0 -6
  719. package/js/src/pro/bullish.js +0 -6
  720. package/js/src/pro/bybit.js +0 -6
  721. package/js/src/pro/bydfi.js +0 -6
  722. package/js/src/pro/cex.js +0 -6
  723. package/js/src/pro/coinbase.js +0 -6
  724. package/js/src/pro/coinbaseadvanced.js +0 -6
  725. package/js/src/pro/coinbaseexchange.js +0 -6
  726. package/js/src/pro/coinbaseinternational.js +0 -6
  727. package/js/src/pro/coincatch.js +0 -6
  728. package/js/src/pro/coincheck.js +0 -6
  729. package/js/src/pro/coinex.js +0 -6
  730. package/js/src/pro/coinone.js +0 -6
  731. package/js/src/pro/cryptocom.js +0 -6
  732. package/js/src/pro/deepcoin.js +0 -6
  733. package/js/src/pro/defx.js +0 -6
  734. package/js/src/pro/deribit.js +0 -6
  735. package/js/src/pro/derive.js +0 -6
  736. package/js/src/pro/dydx.js +1 -7
  737. package/js/src/pro/exmo.js +0 -6
  738. package/js/src/pro/gate.js +0 -6
  739. package/js/src/pro/gateio.js +0 -6
  740. package/js/src/pro/gemini.js +0 -6
  741. package/js/src/pro/hashkey.js +0 -6
  742. package/js/src/pro/hitbtc.js +0 -6
  743. package/js/src/pro/hollaex.js +0 -6
  744. package/js/src/pro/htx.js +0 -6
  745. package/js/src/pro/huobi.js +0 -6
  746. package/js/src/pro/hyperliquid.js +0 -6
  747. package/js/src/pro/independentreserve.js +0 -6
  748. package/js/src/pro/kraken.js +0 -6
  749. package/js/src/pro/krakenfutures.js +0 -6
  750. package/js/src/pro/kucoin.js +0 -6
  751. package/js/src/pro/kucoinfutures.js +0 -6
  752. package/js/src/pro/lbank.js +0 -6
  753. package/js/src/pro/luno.js +0 -6
  754. package/js/src/pro/mexc.js +0 -6
  755. package/js/src/pro/modetrade.js +0 -6
  756. package/js/src/pro/myokx.js +0 -6
  757. package/js/src/pro/ndax.js +0 -6
  758. package/js/src/pro/okx.js +1 -7
  759. package/js/src/pro/okxus.js +0 -6
  760. package/js/src/pro/onetrading.js +0 -6
  761. package/js/src/pro/oxfun.js +0 -6
  762. package/js/src/pro/p2b.js +0 -6
  763. package/js/src/pro/paradex.d.ts +17 -1
  764. package/js/src/pro/paradex.js +143 -9
  765. package/js/src/pro/phemex.js +0 -6
  766. package/js/src/pro/poloniex.js +0 -6
  767. package/js/src/pro/probit.js +0 -6
  768. package/js/src/pro/toobit.js +0 -6
  769. package/js/src/pro/upbit.js +0 -6
  770. package/js/src/pro/whitebit.js +0 -6
  771. package/js/src/pro/woo.js +0 -6
  772. package/js/src/pro/woofipro.js +0 -6
  773. package/js/src/pro/xt.js +0 -6
  774. package/js/src/probit.js +0 -6
  775. package/js/src/protobuf/mexc/compiled.cjs +0 -6
  776. package/js/src/static_dependencies/dydx-v4-client/cosmos/base/v1beta1/coin.js +0 -6
  777. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/keys.js +0 -6
  778. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/multisig/v1beta1/multisig.js +0 -6
  779. package/js/src/static_dependencies/dydx-v4-client/cosmos/crypto/secp256k1/keys.js +0 -6
  780. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/signing/v1beta1/signing.js +0 -6
  781. package/js/src/static_dependencies/dydx-v4-client/cosmos/tx/v1beta1/tx.js +0 -6
  782. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/accountplus/tx.js +0 -6
  783. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/block_rate_limit_config.js +0 -6
  784. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/clob_pair.js +0 -6
  785. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/equity_tier_limit_config.js +0 -6
  786. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/finalize_block.js +0 -6
  787. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations.js +0 -6
  788. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/liquidations_config.js +0 -6
  789. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/matches.js +0 -6
  790. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order.js +0 -6
  791. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/order_removals.js +0 -6
  792. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/clob/tx.js +0 -6
  793. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/transfer.js +0 -6
  794. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/sending/tx.js +0 -6
  795. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/asset_position.js +0 -6
  796. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/perpetual_position.js +0 -6
  797. package/js/src/static_dependencies/dydx-v4-client/dydxprotocol/subaccounts/subaccount.js +0 -6
  798. package/js/src/static_dependencies/dydx-v4-client/google/protobuf/any.js +0 -6
  799. package/js/src/static_dependencies/dydx-v4-client/helpers.js +0 -6
  800. package/js/src/static_dependencies/dydx-v4-client/long/index.cjs +0 -6
  801. package/js/src/static_dependencies/dydx-v4-client/onboarding.js +0 -6
  802. package/js/src/static_dependencies/dydx-v4-client/registry.js +0 -6
  803. package/js/src/static_dependencies/ethers/abi-coder.js +0 -6
  804. package/js/src/static_dependencies/ethers/address/address.js +0 -6
  805. package/js/src/static_dependencies/ethers/address/checks.js +0 -6
  806. package/js/src/static_dependencies/ethers/address/contract-address.js +0 -6
  807. package/js/src/static_dependencies/ethers/address/index.js +0 -6
  808. package/js/src/static_dependencies/ethers/bytes32.js +0 -6
  809. package/js/src/static_dependencies/ethers/coders/abstract-coder.js +0 -6
  810. package/js/src/static_dependencies/ethers/coders/address.js +0 -6
  811. package/js/src/static_dependencies/ethers/coders/anonymous.js +0 -6
  812. package/js/src/static_dependencies/ethers/coders/array.js +0 -6
  813. package/js/src/static_dependencies/ethers/coders/boolean.js +0 -6
  814. package/js/src/static_dependencies/ethers/coders/bytes.js +0 -6
  815. package/js/src/static_dependencies/ethers/coders/fixed-bytes.js +0 -6
  816. package/js/src/static_dependencies/ethers/coders/null.js +0 -6
  817. package/js/src/static_dependencies/ethers/coders/number.js +0 -6
  818. package/js/src/static_dependencies/ethers/coders/string.js +0 -6
  819. package/js/src/static_dependencies/ethers/coders/tuple.js +0 -6
  820. package/js/src/static_dependencies/ethers/fragments.js +0 -6
  821. package/js/src/static_dependencies/ethers/hash/index.js +0 -6
  822. package/js/src/static_dependencies/ethers/hash/solidity.js +0 -6
  823. package/js/src/static_dependencies/ethers/hash/typed-data.js +0 -6
  824. package/js/src/static_dependencies/ethers/index.js +0 -6
  825. package/js/src/static_dependencies/ethers/interface.js +0 -6
  826. package/js/src/static_dependencies/ethers/typed.js +0 -6
  827. package/js/src/static_dependencies/ethers/utils/base58.js +0 -6
  828. package/js/src/static_dependencies/ethers/utils/base64-browser.js +0 -6
  829. package/js/src/static_dependencies/ethers/utils/base64.js +0 -6
  830. package/js/src/static_dependencies/ethers/utils/data.js +0 -6
  831. package/js/src/static_dependencies/ethers/utils/errors.js +0 -6
  832. package/js/src/static_dependencies/ethers/utils/events.js +0 -6
  833. package/js/src/static_dependencies/ethers/utils/fixednumber.js +0 -6
  834. package/js/src/static_dependencies/ethers/utils/index.js +0 -6
  835. package/js/src/static_dependencies/ethers/utils/maths.js +0 -6
  836. package/js/src/static_dependencies/ethers/utils/properties.js +0 -6
  837. package/js/src/static_dependencies/ethers/utils/rlp-decode.js +0 -6
  838. package/js/src/static_dependencies/ethers/utils/rlp-encode.js +0 -6
  839. package/js/src/static_dependencies/ethers/utils/rlp.js +0 -6
  840. package/js/src/static_dependencies/ethers/utils/units.js +0 -6
  841. package/js/src/static_dependencies/ethers/utils/utf8.js +0 -6
  842. package/js/src/static_dependencies/ethers/utils/uuid.js +0 -6
  843. package/js/src/static_dependencies/fflake/browser.js +0 -6
  844. package/js/src/static_dependencies/jsencrypt/JSEncrypt.js +0 -6
  845. package/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +0 -6
  846. package/js/src/static_dependencies/jsencrypt/index.js +0 -6
  847. package/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +0 -6
  848. package/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +0 -6
  849. package/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +0 -6
  850. package/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +0 -6
  851. package/js/src/static_dependencies/jsencrypt/lib/asn1js/oids.js +0 -6
  852. package/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +0 -6
  853. package/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +0 -6
  854. package/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +0 -6
  855. package/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +0 -6
  856. package/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +0 -6
  857. package/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +0 -6
  858. package/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +0 -6
  859. package/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +0 -6
  860. package/js/src/static_dependencies/messagepack/msgpack.js +0 -6
  861. package/js/src/static_dependencies/noble-curves/_shortw_utils.js +0 -6
  862. package/js/src/static_dependencies/noble-curves/abstract/curve.js +0 -6
  863. package/js/src/static_dependencies/noble-curves/abstract/edwards.js +0 -6
  864. package/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +0 -6
  865. package/js/src/static_dependencies/noble-curves/abstract/modular.js +0 -6
  866. package/js/src/static_dependencies/noble-curves/abstract/montgomery.js +0 -6
  867. package/js/src/static_dependencies/noble-curves/abstract/poseidon.js +0 -6
  868. package/js/src/static_dependencies/noble-curves/abstract/utils.js +0 -6
  869. package/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +0 -6
  870. package/js/src/static_dependencies/noble-curves/bn.js +0 -6
  871. package/js/src/static_dependencies/noble-curves/ed25519.js +0 -6
  872. package/js/src/static_dependencies/noble-curves/ed448.js +0 -6
  873. package/js/src/static_dependencies/noble-curves/index.js +0 -6
  874. package/js/src/static_dependencies/noble-curves/jubjub.js +0 -6
  875. package/js/src/static_dependencies/noble-curves/p256.js +0 -6
  876. package/js/src/static_dependencies/noble-curves/p384.js +0 -6
  877. package/js/src/static_dependencies/noble-curves/p521.js +0 -6
  878. package/js/src/static_dependencies/noble-curves/pasta.js +0 -6
  879. package/js/src/static_dependencies/noble-curves/secp256k1.js +0 -6
  880. package/js/src/static_dependencies/noble-hashes/_assert.js +0 -6
  881. package/js/src/static_dependencies/noble-hashes/_blake2.js +0 -6
  882. package/js/src/static_dependencies/noble-hashes/_sha2.js +0 -6
  883. package/js/src/static_dependencies/noble-hashes/_u64.js +0 -6
  884. package/js/src/static_dependencies/noble-hashes/argon2.js +0 -6
  885. package/js/src/static_dependencies/noble-hashes/blake2b.js +0 -6
  886. package/js/src/static_dependencies/noble-hashes/blake2s.js +0 -6
  887. package/js/src/static_dependencies/noble-hashes/blake3.js +0 -6
  888. package/js/src/static_dependencies/noble-hashes/crypto.js +0 -6
  889. package/js/src/static_dependencies/noble-hashes/cryptoNode.js +0 -6
  890. package/js/src/static_dependencies/noble-hashes/eskdf.js +0 -6
  891. package/js/src/static_dependencies/noble-hashes/hkdf.js +0 -6
  892. package/js/src/static_dependencies/noble-hashes/hmac.js +0 -6
  893. package/js/src/static_dependencies/noble-hashes/index.js +0 -6
  894. package/js/src/static_dependencies/noble-hashes/md5.js +0 -6
  895. package/js/src/static_dependencies/noble-hashes/pbkdf2.js +0 -6
  896. package/js/src/static_dependencies/noble-hashes/ripemd160.js +0 -6
  897. package/js/src/static_dependencies/noble-hashes/scrypt.js +0 -6
  898. package/js/src/static_dependencies/noble-hashes/sha1.js +0 -6
  899. package/js/src/static_dependencies/noble-hashes/sha256.js +0 -6
  900. package/js/src/static_dependencies/noble-hashes/sha3-addons.js +0 -6
  901. package/js/src/static_dependencies/noble-hashes/sha3.js +0 -6
  902. package/js/src/static_dependencies/noble-hashes/sha512.js +0 -6
  903. package/js/src/static_dependencies/noble-hashes/utils.js +0 -6
  904. package/js/src/static_dependencies/node-fetch/body.js +0 -6
  905. package/js/src/static_dependencies/node-fetch/errors/abort-error.js +0 -6
  906. package/js/src/static_dependencies/node-fetch/errors/base.js +0 -6
  907. package/js/src/static_dependencies/node-fetch/errors/fetch-error.js +0 -6
  908. package/js/src/static_dependencies/node-fetch/headers.js +0 -6
  909. package/js/src/static_dependencies/node-fetch/index.js +0 -6
  910. package/js/src/static_dependencies/node-fetch/request.js +0 -6
  911. package/js/src/static_dependencies/node-fetch/response.js +0 -6
  912. package/js/src/static_dependencies/node-fetch/utils/get-search.js +0 -6
  913. package/js/src/static_dependencies/node-fetch/utils/is-redirect.js +0 -6
  914. package/js/src/static_dependencies/node-fetch/utils/is.js +0 -6
  915. package/js/src/static_dependencies/node-fetch/utils/referrer.js +0 -6
  916. package/js/src/static_dependencies/proxies/agent-base/helpers.js +0 -6
  917. package/js/src/static_dependencies/proxies/agent-base/index.js +0 -6
  918. package/js/src/static_dependencies/proxies/http-proxy-agent/index.js +0 -6
  919. package/js/src/static_dependencies/proxies/https-proxy-agent/index.js +0 -6
  920. package/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +0 -6
  921. package/js/src/static_dependencies/qs/formats.js +0 -6
  922. package/js/src/static_dependencies/qs/index.js +0 -6
  923. package/js/src/static_dependencies/qs/parse.js +0 -6
  924. package/js/src/static_dependencies/qs/stringify.js +0 -6
  925. package/js/src/static_dependencies/qs/utils.js +0 -6
  926. package/js/src/static_dependencies/scure-base/index.js +0 -6
  927. package/js/src/static_dependencies/scure-bip32/index.js +0 -6
  928. package/js/src/static_dependencies/scure-bip39/index.js +0 -6
  929. package/js/src/static_dependencies/scure-bip39/wordlists/english.js +0 -6
  930. package/js/src/static_dependencies/scure-starknet/index.js +0 -6
  931. package/js/src/static_dependencies/starknet/constants.js +0 -6
  932. package/js/src/static_dependencies/starknet/index.js +0 -6
  933. package/js/src/static_dependencies/starknet/types/cairoEnum.js +0 -6
  934. package/js/src/static_dependencies/starknet/types/calldata.js +0 -6
  935. package/js/src/static_dependencies/starknet/types/index.js +0 -6
  936. package/js/src/static_dependencies/starknet/types/lib/contract/abi.js +0 -6
  937. package/js/src/static_dependencies/starknet/types/lib/contract/index.js +0 -6
  938. package/js/src/static_dependencies/starknet/types/lib/contract/legacy.js +0 -6
  939. package/js/src/static_dependencies/starknet/types/lib/contract/sierra.js +0 -6
  940. package/js/src/static_dependencies/starknet/types/lib/index.js +0 -6
  941. package/js/src/static_dependencies/starknet/types/typedData.js +0 -6
  942. package/js/src/static_dependencies/starknet/utils/address.js +0 -6
  943. package/js/src/static_dependencies/starknet/utils/assert.js +0 -6
  944. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/felt.js +0 -6
  945. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint256.js +0 -6
  946. package/js/src/static_dependencies/starknet/utils/cairoDataTypes/uint512.js +0 -6
  947. package/js/src/static_dependencies/starknet/utils/calldata/byteArray.js +0 -6
  948. package/js/src/static_dependencies/starknet/utils/calldata/cairo.js +0 -6
  949. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoCustomEnum.js +0 -6
  950. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoOption.js +0 -6
  951. package/js/src/static_dependencies/starknet/utils/calldata/enum/CairoResult.js +0 -6
  952. package/js/src/static_dependencies/starknet/utils/calldata/enum/index.js +0 -6
  953. package/js/src/static_dependencies/starknet/utils/calldata/formatter.js +0 -6
  954. package/js/src/static_dependencies/starknet/utils/calldata/index.js +0 -6
  955. package/js/src/static_dependencies/starknet/utils/calldata/parser/index.js +0 -6
  956. package/js/src/static_dependencies/starknet/utils/calldata/parser/interface.js +0 -6
  957. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-0-1.1.0.js +0 -6
  958. package/js/src/static_dependencies/starknet/utils/calldata/parser/parser-2.0.0.js +0 -6
  959. package/js/src/static_dependencies/starknet/utils/calldata/propertyOrder.js +0 -6
  960. package/js/src/static_dependencies/starknet/utils/calldata/requestParser.js +0 -6
  961. package/js/src/static_dependencies/starknet/utils/calldata/responseParser.js +0 -6
  962. package/js/src/static_dependencies/starknet/utils/calldata/tuple.js +0 -6
  963. package/js/src/static_dependencies/starknet/utils/calldata/validate.js +0 -6
  964. package/js/src/static_dependencies/starknet/utils/encode.js +0 -6
  965. package/js/src/static_dependencies/starknet/utils/hash/classHash.js +0 -6
  966. package/js/src/static_dependencies/starknet/utils/hash/index.js +0 -6
  967. package/js/src/static_dependencies/starknet/utils/merkle.js +0 -6
  968. package/js/src/static_dependencies/starknet/utils/num.js +0 -6
  969. package/js/src/static_dependencies/starknet/utils/selector.js +0 -6
  970. package/js/src/static_dependencies/starknet/utils/shortString.js +0 -6
  971. package/js/src/static_dependencies/starknet/utils/starknetId.js +0 -6
  972. package/js/src/static_dependencies/starknet/utils/typedData.js +0 -6
  973. package/js/src/static_dependencies/starknet/utils/uint256.js +0 -6
  974. package/js/src/static_dependencies/starknet/utils/url.js +0 -6
  975. package/js/src/static_dependencies/watchable/src/index.js +0 -6
  976. package/js/src/static_dependencies/watchable/src/types.js +0 -6
  977. package/js/src/static_dependencies/watchable/src/unpromise.js +0 -6
  978. package/js/src/static_dependencies/zklink/zklink-sdk-web.js +0 -6
  979. package/js/src/timex.js +0 -6
  980. package/js/src/tokocrypto.js +0 -6
  981. package/js/src/toobit.js +0 -6
  982. package/js/src/upbit.js +0 -6
  983. package/js/src/wavesexchange.js +0 -6
  984. package/js/src/whitebit.js +2 -8
  985. package/js/src/woo.js +0 -6
  986. package/js/src/woofipro.js +0 -6
  987. package/js/src/xt.js +0 -6
  988. package/js/src/yobit.js +0 -6
  989. package/js/src/zaif.js +0 -6
  990. package/js/src/zebpay.js +0 -6
  991. package/js/src/zonda.js +0 -6
  992. package/package.json +1 -1
@@ -0,0 +1,3796 @@
1
+ // ---------------------------------------------------------------------------
2
+ import Exchange from './abstract/aster.js';
3
+ import { AccountNotEnabled, AccountSuspended, ArgumentsRequired, AuthenticationError, BadRequest, BadResponse, BadSymbol, DuplicateOrderId, ExchangeClosedByUser, ExchangeError, InsufficientFunds, InvalidNonce, InvalidOrder, MarketClosed, NetworkError, NoChange, NotSupported, OperationFailed, OperationRejected, OrderImmediatelyFillable, OrderNotFillable, OrderNotFound, PermissionDenied, RateLimitExceeded, RequestTimeout } from './base/errors.js';
4
+ import { TRUNCATE, TICK_SIZE } from './base/functions/number.js';
5
+ import Precise from './base/Precise.js';
6
+ import { sha256 } from './static_dependencies/noble-hashes/sha256.js';
7
+ import { ecdsa } from './base/functions/crypto.js';
8
+ import { keccak_256 as keccak } from './static_dependencies/noble-hashes/sha3.js';
9
+ import { secp256k1 } from './static_dependencies/noble-curves/secp256k1.js';
10
+ // ---------------------------------------------------------------------------xs
11
+ /**
12
+ * @class aster
13
+ * @augments Exchange
14
+ */
15
+ export default class aster extends Exchange {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'aster',
19
+ 'name': 'Aster',
20
+ 'countries': ['US'],
21
+ // 3 req/s for free
22
+ // 150 req/s for subscribers: https://aster.markets/data
23
+ // for brokers: https://aster.markets/docs/api-references/broker-api/#authentication-and-rate-limit
24
+ 'rateLimit': 333,
25
+ 'hostname': 'aster.markets',
26
+ 'certified': false,
27
+ 'pro': true,
28
+ 'dex': true,
29
+ 'urls': {
30
+ 'logo': 'https://github.com/user-attachments/assets/4982201b-73cd-4d7a-8907-e69e239e9609',
31
+ 'www': 'https://www.asterdex.com/en',
32
+ 'api': {
33
+ 'fapiPublic': 'https://fapi.asterdex.com/fapi',
34
+ 'fapiPrivate': 'https://fapi.asterdex.com/fapi',
35
+ 'sapiPublic': 'https://sapi.asterdex.com/api',
36
+ 'sapiPrivate': 'https://sapi.asterdex.com/api',
37
+ },
38
+ 'doc': 'https://github.com/asterdex/api-docs',
39
+ 'fees': 'https://docs.asterdex.com/product/asterex-simple/fees-and-slippage',
40
+ 'referral': {
41
+ 'url': 'https://www.asterdex.com/en/referral/aA1c2B',
42
+ 'discount': 0.1,
43
+ },
44
+ },
45
+ 'has': {
46
+ 'CORS': undefined,
47
+ 'spot': false,
48
+ 'margin': false,
49
+ 'swap': false,
50
+ 'future': false,
51
+ 'option': false,
52
+ 'addMargin': true,
53
+ 'borrowCrossMargin': false,
54
+ 'borrowIsolatedMargin': false,
55
+ 'cancelAllOrders': true,
56
+ 'cancelOrder': true,
57
+ 'cancelOrders': true,
58
+ 'closeAllPositions': false,
59
+ 'closePosition': false,
60
+ 'createConvertTrade': false,
61
+ 'createDepositAddress': false,
62
+ 'createLimitBuyOrder': false,
63
+ 'createLimitSellOrder': false,
64
+ 'createMarketBuyOrder': false,
65
+ 'createMarketBuyOrderWithCost': false,
66
+ 'createMarketOrderWithCost': false,
67
+ 'createMarketSellOrder': false,
68
+ 'createMarketSellOrderWithCost': false,
69
+ 'createOrder': true,
70
+ 'createOrders': false,
71
+ 'createOrderWithTakeProfitAndStopLoss': false,
72
+ 'createPostOnlyOrder': false,
73
+ 'createReduceOnlyOrder': false,
74
+ 'createStopLimitOrder': false,
75
+ 'createStopLossOrder': false,
76
+ 'createStopMarketOrder': false,
77
+ 'createStopOrder': false,
78
+ 'createTakeProfitOrder': false,
79
+ 'createTrailingPercentOrder': false,
80
+ 'createTriggerOrder': false,
81
+ 'editOrder': false,
82
+ 'editOrders': false,
83
+ 'fetchAccounts': undefined,
84
+ 'fetchBalance': true,
85
+ 'fetchBidsAsks': false,
86
+ 'fetchBorrowInterest': false,
87
+ 'fetchBorrowRateHistories': false,
88
+ 'fetchBorrowRateHistory': false,
89
+ 'fetchCanceledAndClosedOrders': 'emulated',
90
+ 'fetchCanceledOrders': 'emulated',
91
+ 'fetchClosedOrder': false,
92
+ 'fetchClosedOrders': 'emulated',
93
+ 'fetchConvertCurrencies': false,
94
+ 'fetchConvertQuote': false,
95
+ 'fetchConvertTrade': false,
96
+ 'fetchConvertTradeHistory': false,
97
+ 'fetchCrossBorrowRate': false,
98
+ 'fetchCrossBorrowRates': false,
99
+ 'fetchCurrencies': true,
100
+ 'fetchDeposit': false,
101
+ 'fetchDepositAddress': false,
102
+ 'fetchDepositAddresses': false,
103
+ 'fetchDepositAddressesByNetwork': false,
104
+ 'fetchDeposits': false,
105
+ 'fetchDepositsWithdrawals': false,
106
+ 'fetchDepositWithdrawFee': 'emulated',
107
+ 'fetchDepositWithdrawFees': false,
108
+ 'fetchFundingHistory': true,
109
+ 'fetchFundingInterval': 'emulated',
110
+ 'fetchFundingIntervals': true,
111
+ 'fetchFundingRate': true,
112
+ 'fetchFundingRateHistory': true,
113
+ 'fetchFundingRates': true,
114
+ 'fetchGreeks': false,
115
+ 'fetchIndexOHLCV': false,
116
+ 'fetchIsolatedBorrowRate': 'emulated',
117
+ 'fetchIsolatedBorrowRates': false,
118
+ 'fetchL3OrderBook': false,
119
+ 'fetchLastPrices': false,
120
+ 'fetchLedger': true,
121
+ 'fetchLedgerEntry': false,
122
+ 'fetchLeverage': 'emulated',
123
+ 'fetchLeverages': true,
124
+ 'fetchLeverageTiers': false,
125
+ 'fetchLiquidations': false,
126
+ 'fetchLongShortRatio': false,
127
+ 'fetchLongShortRatioHistory': false,
128
+ 'fetchMarginAdjustmentHistory': true,
129
+ 'fetchMarginMode': 'emulated',
130
+ 'fetchMarginModes': true,
131
+ 'fetchMarketLeverageTiers': 'emulated',
132
+ 'fetchMarkets': true,
133
+ 'fetchMarkOHLCV': false,
134
+ 'fetchMarkPrice': false,
135
+ 'fetchMarkPrices': false,
136
+ 'fetchMyLiquidations': false,
137
+ 'fetchMySettlementHistory': false,
138
+ 'fetchMyTrades': true,
139
+ 'fetchOHLCV': true,
140
+ 'fetchOpenInterest': false,
141
+ 'fetchOpenInterestHistory': false,
142
+ 'fetchOpenOrder': true,
143
+ 'fetchOpenOrders': true,
144
+ 'fetchOption': false,
145
+ 'fetchOptionChain': false,
146
+ 'fetchOrder': true,
147
+ 'fetchOrderBook': true,
148
+ 'fetchOrderBooks': false,
149
+ 'fetchOrders': true,
150
+ 'fetchOrderTrades': false,
151
+ 'fetchPosition': false,
152
+ 'fetchPositionHistory': false,
153
+ 'fetchPositionMode': true,
154
+ 'fetchPositions': true,
155
+ 'fetchPositionsHistory': false,
156
+ 'fetchPositionsRisk': true,
157
+ 'fetchPremiumIndexOHLCV': false,
158
+ 'fetchSettlementHistory': false,
159
+ 'fetchStatus': false,
160
+ 'fetchTicker': true,
161
+ 'fetchTickers': true,
162
+ 'fetchTime': true,
163
+ 'fetchTrades': true,
164
+ 'fetchTradingFee': true,
165
+ 'fetchTradingFees': false,
166
+ 'fetchTradingLimits': 'emulated',
167
+ 'fetchTransactionFee': 'emulated',
168
+ 'fetchTransactionFees': false,
169
+ 'fetchTransactions': false,
170
+ 'fetchTransfer': false,
171
+ 'fetchTransfers': false,
172
+ 'fetchUnderlyingAssets': false,
173
+ 'fetchVolatilityHistory': false,
174
+ 'fetchWithdrawAddresses': false,
175
+ 'fetchWithdrawal': false,
176
+ 'fetchWithdrawals': false,
177
+ 'fetchWithdrawalWhitelist': false,
178
+ 'reduceMargin': true,
179
+ 'repayCrossMargin': false,
180
+ 'repayIsolatedMargin': false,
181
+ 'sandbox': false,
182
+ 'setLeverage': true,
183
+ 'setMargin': false,
184
+ 'setMarginMode': true,
185
+ 'setPositionMode': true,
186
+ 'signIn': false,
187
+ 'transfer': true,
188
+ 'withdraw': true,
189
+ },
190
+ 'api': {
191
+ 'fapiPublic': {
192
+ 'get': [
193
+ 'v1/ping',
194
+ 'v1/time',
195
+ 'v1/exchangeInfo',
196
+ 'v1/depth',
197
+ 'v1/trades',
198
+ 'v1/historicalTrades',
199
+ 'v1/aggTrades',
200
+ 'v1/klines',
201
+ 'v1/indexPriceKlines',
202
+ 'v1/markPriceKlines',
203
+ 'v1/premiumIndex',
204
+ 'v1/fundingRate',
205
+ 'v1/fundingInfo',
206
+ 'v1/ticker/24hr',
207
+ 'v1/ticker/price',
208
+ 'v1/ticker/bookTicker',
209
+ 'v1/adlQuantile',
210
+ 'v1/forceOrders',
211
+ ],
212
+ 'post': [
213
+ 'v1/listenKey',
214
+ ],
215
+ 'put': [
216
+ 'v1/listenKey',
217
+ ],
218
+ 'delete': [
219
+ 'v1/listenKey',
220
+ ],
221
+ },
222
+ 'fapiPrivate': {
223
+ 'get': [
224
+ 'v1/positionSide/dual',
225
+ 'v1/multiAssetsMargin',
226
+ 'v1/order',
227
+ 'v1/openOrder',
228
+ 'v1/openOrders',
229
+ 'v1/allOrders',
230
+ 'v2/balance',
231
+ 'v3/balance',
232
+ 'v3/account',
233
+ 'v4/account',
234
+ 'v1/positionMargin/history',
235
+ 'v2/positionRisk',
236
+ 'v3/positionRisk',
237
+ 'v1/userTrades',
238
+ 'v1/income',
239
+ 'v1/leverageBracket',
240
+ 'v1/commissionRate',
241
+ ],
242
+ 'post': [
243
+ 'v1/positionSide/dual',
244
+ 'v1/multiAssetsMargin',
245
+ 'v1/order',
246
+ 'v1/order/test',
247
+ 'v1/batchOrders',
248
+ 'v1/asset/wallet/transfer',
249
+ 'v1/countdownCancelAll',
250
+ 'v1/leverage',
251
+ 'v1/marginType',
252
+ 'v1/positionMargin',
253
+ ],
254
+ 'delete': [
255
+ 'v1/order',
256
+ 'v1/allOpenOrders',
257
+ 'v1/batchOrders',
258
+ ],
259
+ },
260
+ 'sapiPublic': {
261
+ 'get': [
262
+ 'v1/ping',
263
+ 'v1/time',
264
+ 'v1/exchangeInfo',
265
+ 'v1/depth',
266
+ 'v1/trades',
267
+ 'v1/historicalTrades',
268
+ 'v1/aggTrades',
269
+ 'v1/klines',
270
+ 'v1/ticker/24hr',
271
+ 'v1/ticker/price',
272
+ 'v1/ticker/bookTicker',
273
+ 'v1/aster/withdraw/estimateFee',
274
+ ],
275
+ 'post': [
276
+ 'v1/getNonce',
277
+ 'v1/createApiKey',
278
+ 'v1/listenKey',
279
+ ],
280
+ 'put': [
281
+ 'v1/listenKey',
282
+ ],
283
+ 'delete': [
284
+ 'v1/listenKey',
285
+ ],
286
+ },
287
+ 'sapiPrivate': {
288
+ 'get': [
289
+ 'v1/commissionRate',
290
+ 'v1/order',
291
+ 'v1/openOrders',
292
+ 'v1/allOrders',
293
+ 'v1/transactionHistory',
294
+ 'v1/account',
295
+ 'v1/userTrades',
296
+ ],
297
+ 'post': [
298
+ 'v1/order',
299
+ 'v1/asset/wallet/transfer',
300
+ 'v1/asset/sendToAddress',
301
+ 'v1/aster/user-withdraw',
302
+ ],
303
+ 'delete': [
304
+ 'v1/order',
305
+ 'v1/allOpenOrders',
306
+ ],
307
+ },
308
+ },
309
+ 'timeframes': {
310
+ '1m': '1m',
311
+ '3m': '3m',
312
+ '5m': '5m',
313
+ '15m': '15m',
314
+ '30m': '30m',
315
+ '1h': '1h',
316
+ '2h': '2h',
317
+ '4h': '4h',
318
+ '6h': '6h',
319
+ '8h': '8h',
320
+ '12h': '12h',
321
+ '1d': '1d',
322
+ '3d': '3d',
323
+ '1w': '1w',
324
+ '1M': '1M',
325
+ },
326
+ 'precisionMode': TICK_SIZE,
327
+ 'requiredCredentials': {
328
+ 'apiKey': true,
329
+ 'secret': true,
330
+ },
331
+ 'fees': {
332
+ 'trading': {
333
+ 'tierBased': true,
334
+ 'percentage': true,
335
+ 'maker': this.parseNumber('0.0001'),
336
+ 'taker': this.parseNumber('0.00035'),
337
+ },
338
+ },
339
+ 'options': {
340
+ 'recvWindow': 10 * 1000,
341
+ 'defaultTimeInForce': 'GTC',
342
+ 'zeroAddress': '0x0000000000000000000000000000000000000000',
343
+ 'quoteOrderQty': true,
344
+ 'accountsByType': {
345
+ 'spot': 'SPOT',
346
+ 'future': 'FUTURE',
347
+ 'linear': 'FUTURE',
348
+ 'swap': 'FUTURE',
349
+ },
350
+ 'networks': {
351
+ 'ERC20': 'ETH',
352
+ 'BEP20': 'BSC',
353
+ 'ARB': 'Arbitrum',
354
+ },
355
+ 'networksToChainId': {
356
+ 'ETH': 1,
357
+ 'BSC': 56,
358
+ 'Arbitrum': 42161,
359
+ },
360
+ },
361
+ 'exceptions': {
362
+ 'exact': {
363
+ // 10xx - General Server or Network issues
364
+ '-1000': OperationFailed,
365
+ '-1001': NetworkError,
366
+ '-1002': AuthenticationError,
367
+ '-1003': RateLimitExceeded,
368
+ '-1004': DuplicateOrderId,
369
+ '-1005': BadRequest,
370
+ '-1006': BadResponse,
371
+ '-1007': RequestTimeout,
372
+ '-1010': OperationFailed,
373
+ '-1011': PermissionDenied,
374
+ '-1013': BadRequest,
375
+ '-1014': OrderNotFillable,
376
+ '-1015': RateLimitExceeded,
377
+ '-1016': ExchangeClosedByUser,
378
+ '-1020': NotSupported,
379
+ '-1021': InvalidNonce,
380
+ '-1022': AuthenticationError,
381
+ '-1023': BadRequest,
382
+ // 11xx - Request issues
383
+ '-1100': BadRequest,
384
+ '-1101': BadRequest,
385
+ '-1102': ArgumentsRequired,
386
+ '-1103': BadRequest,
387
+ '-1104': BadRequest,
388
+ '-1105': ArgumentsRequired,
389
+ '-1106': BadRequest,
390
+ '-1108': BadRequest,
391
+ '-1109': BadRequest,
392
+ '-1110': BadSymbol,
393
+ '-1111': BadRequest,
394
+ '-1112': BadRequest,
395
+ '-1113': BadRequest,
396
+ '-1114': BadRequest,
397
+ '-1115': InvalidOrder,
398
+ '-1116': InvalidOrder,
399
+ '-1117': InvalidOrder,
400
+ '-1118': InvalidOrder,
401
+ '-1119': InvalidOrder,
402
+ '-1120': BadRequest,
403
+ '-1121': BadSymbol,
404
+ '-1125': AuthenticationError,
405
+ '-1127': BadRequest,
406
+ '-1128': BadRequest,
407
+ '-1130': BadRequest,
408
+ '-1136': InvalidOrder,
409
+ // 20xx - Processing Issues
410
+ '-2010': InvalidOrder,
411
+ '-2011': OrderNotFound,
412
+ '-2013': OrderNotFound,
413
+ '-2014': AuthenticationError,
414
+ '-2015': AuthenticationError,
415
+ '-2016': MarketClosed,
416
+ '-2018': InsufficientFunds,
417
+ '-2019': InsufficientFunds,
418
+ '-2020': OrderNotFillable,
419
+ '-2021': OrderImmediatelyFillable,
420
+ '-2022': OperationRejected,
421
+ '-2023': AccountSuspended,
422
+ '-2024': InsufficientFunds,
423
+ '-2025': RateLimitExceeded,
424
+ '-2026': NotSupported,
425
+ '-2027': BadRequest,
426
+ '-2028': BadRequest,
427
+ // 40xx - Filters and other Issues
428
+ '-4000': InvalidOrder,
429
+ '-4001': InvalidOrder,
430
+ '-4002': InvalidOrder,
431
+ '-4003': InvalidOrder,
432
+ '-4004': InvalidOrder,
433
+ '-4005': InvalidOrder,
434
+ '-4006': InvalidOrder,
435
+ '-4007': InvalidOrder,
436
+ '-4008': InvalidOrder,
437
+ '-4009': InvalidOrder,
438
+ '-4010': InvalidOrder,
439
+ '-4011': InvalidOrder,
440
+ '-4012': RateLimitExceeded,
441
+ '-4013': InvalidOrder,
442
+ '-4014': InvalidOrder,
443
+ '-4015': InvalidOrder,
444
+ '-4016': InvalidOrder,
445
+ '-4017': InvalidOrder,
446
+ '-4018': InvalidOrder,
447
+ '-4019': BadRequest,
448
+ '-4020': BadRequest,
449
+ '-4021': BadRequest,
450
+ '-4022': MarketClosed,
451
+ '-4023': InvalidOrder,
452
+ '-4024': InvalidOrder,
453
+ '-4025': BadRequest,
454
+ '-4026': BadRequest,
455
+ '-4027': BadRequest,
456
+ '-4028': BadRequest,
457
+ '-4029': BadRequest,
458
+ '-4030': BadRequest,
459
+ '-4031': BadRequest,
460
+ '-4032': RateLimitExceeded,
461
+ '-4033': AccountNotEnabled,
462
+ '-4044': BadRequest,
463
+ '-4045': RateLimitExceeded,
464
+ '-4046': NoChange,
465
+ '-4047': OperationRejected,
466
+ '-4048': OperationRejected,
467
+ '-4049': OperationRejected,
468
+ '-4050': InsufficientFunds,
469
+ '-4051': InsufficientFunds,
470
+ '-4052': NoChange,
471
+ '-4053': OperationRejected,
472
+ '-4054': OperationRejected,
473
+ '-4055': ArgumentsRequired,
474
+ '-4056': AuthenticationError,
475
+ '-4057': AuthenticationError,
476
+ '-4058': InvalidOrder,
477
+ '-4059': NoChange,
478
+ '-4060': InvalidOrder,
479
+ '-4061': InvalidOrder,
480
+ '-4062': OperationRejected,
481
+ '-4063': BadRequest,
482
+ '-4064': BadRequest,
483
+ '-4065': BadRequest,
484
+ '-4066': BadRequest,
485
+ '-4067': OperationRejected,
486
+ '-4068': OperationRejected,
487
+ '-4069': BadRequest,
488
+ '-4070': InvalidOrder,
489
+ '-4071': InvalidOrder,
490
+ '-4072': NoChange,
491
+ '-4073': BadRequest,
492
+ '-4074': InvalidOrder,
493
+ '-4075': OperationRejected,
494
+ '-4076': OperationRejected,
495
+ '-4077': RateLimitExceeded,
496
+ '-4078': BadRequest,
497
+ '-4079': BadRequest,
498
+ '-4080': BadRequest,
499
+ '-4081': BadRequest,
500
+ '-4082': RateLimitExceeded,
501
+ '-4083': OperationFailed,
502
+ '-4084': NotSupported,
503
+ '-4085': BadRequest,
504
+ '-4086': BadRequest,
505
+ '-4087': PermissionDenied,
506
+ '-4088': PermissionDenied,
507
+ '-4104': BadSymbol,
508
+ '-4114': InvalidOrder,
509
+ '-4115': DuplicateOrderId,
510
+ '-4118': InsufficientFunds,
511
+ '-4131': InvalidOrder,
512
+ '-4135': InvalidOrder,
513
+ '-4137': InvalidOrder,
514
+ '-4138': OperationRejected,
515
+ '-4139': InvalidOrder,
516
+ '-4140': OperationRejected,
517
+ '-4141': MarketClosed,
518
+ '-4142': InvalidOrder,
519
+ '-4144': BadSymbol,
520
+ '-4161': OperationRejected,
521
+ '-4164': InvalidOrder,
522
+ '-4165': BadRequest,
523
+ '-4183': InvalidOrder,
524
+ '-4184': InvalidOrder,
525
+ '-5060': OperationRejected,
526
+ '-5076': OperationRejected, // {"code":-5076,"msg":"Total order value should be more than 5 USDT"}
527
+ },
528
+ 'broad': {},
529
+ },
530
+ });
531
+ }
532
+ isInverse(type, subType = undefined) {
533
+ if (subType === undefined) {
534
+ return (type === 'delivery');
535
+ }
536
+ else {
537
+ return subType === 'inverse';
538
+ }
539
+ }
540
+ isLinear(type, subType = undefined) {
541
+ if (subType === undefined) {
542
+ return (type === 'future') || (type === 'swap');
543
+ }
544
+ else {
545
+ return subType === 'linear';
546
+ }
547
+ }
548
+ /**
549
+ * @method
550
+ * @name aster#fetchCurrencies
551
+ * @description fetches all available currencies on an exchange
552
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#trading-specification-information
553
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#exchange-information
554
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
555
+ * @returns {object} an associative dictionary of currencies
556
+ */
557
+ async fetchCurrencies(params = {}) {
558
+ const promises = [
559
+ this.sapiPublicGetV1ExchangeInfo(params),
560
+ this.fapiPublicGetV1ExchangeInfo(params),
561
+ ];
562
+ const results = await Promise.all(promises);
563
+ const sapiResult = this.safeDict(results, 0, {});
564
+ const sapiRows = this.safeList(sapiResult, 'assets', []);
565
+ const fapiResult = this.safeDict(results, 1, {});
566
+ const fapiRows = this.safeList(fapiResult, 'assets', []);
567
+ const rows = this.arrayConcat(sapiRows, fapiRows);
568
+ //
569
+ // [
570
+ // {
571
+ // "asset": "USDT",
572
+ // "marginAvailable": true,
573
+ // "autoAssetExchange": "-10000"
574
+ // }
575
+ // ]
576
+ //
577
+ const result = {};
578
+ for (let i = 0; i < rows.length; i++) {
579
+ const currency = rows[i];
580
+ const currencyId = this.safeString(currency, 'asset');
581
+ const code = this.safeCurrencyCode(currencyId);
582
+ result[code] = this.safeCurrencyStructure({
583
+ 'info': currency,
584
+ 'code': code,
585
+ 'id': currencyId,
586
+ 'name': code,
587
+ 'active': undefined,
588
+ 'deposit': undefined,
589
+ 'withdraw': undefined,
590
+ 'fee': undefined,
591
+ 'precision': undefined,
592
+ 'limits': {
593
+ 'amount': {
594
+ 'min': undefined,
595
+ 'max': undefined,
596
+ },
597
+ 'withdraw': {
598
+ 'min': undefined,
599
+ 'max': undefined,
600
+ },
601
+ 'deposit': {
602
+ 'min': undefined,
603
+ 'max': undefined,
604
+ },
605
+ },
606
+ 'networks': undefined,
607
+ 'type': 'crypto', // atm exchange api provides only cryptos
608
+ });
609
+ }
610
+ return result;
611
+ }
612
+ /**
613
+ * @method
614
+ * @name aster#fetchMarkets
615
+ * @description retrieves data on all markets for bigone
616
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#trading-specification-information
617
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#exchange-information
618
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
619
+ * @returns {object[]} an array of objects representing market data
620
+ */
621
+ async fetchMarkets(params = {}) {
622
+ const promises = [
623
+ this.sapiPublicGetV1ExchangeInfo(params),
624
+ this.fapiPublicGetV1ExchangeInfo(params),
625
+ ];
626
+ const results = await Promise.all(promises);
627
+ const sapiResult = this.safeDict(results, 0, {});
628
+ const sapiRows = this.safeList(sapiResult, 'symbols', []);
629
+ const fapiResult = this.safeDict(results, 1, {});
630
+ const fapiRows = this.safeList(fapiResult, 'symbols', []);
631
+ const rows = this.arrayConcat(sapiRows, fapiRows);
632
+ //
633
+ // [
634
+ // {
635
+ // "symbol": "BTCUSDT",
636
+ // "pair": "BTCUSDT",
637
+ // "contractType": "PERPETUAL",
638
+ // "deliveryDate": 4133404800000,
639
+ // "onboardDate": 1627628400000,
640
+ // "status": "TRADING",
641
+ // "maintMarginPercent": "2.5000",
642
+ // "requiredMarginPercent": "5.0000",
643
+ // "baseAsset": "BTC",
644
+ // "quoteAsset": "USDT",
645
+ // "marginAsset": "USDT",
646
+ // "pricePrecision": 1,
647
+ // "quantityPrecision": 3,
648
+ // "baseAssetPrecision": 8,
649
+ // "quotePrecision": 8,
650
+ // "underlyingType": "COIN",
651
+ // "underlyingSubType": [],
652
+ // "settlePlan": 0,
653
+ // "triggerProtect": "0.0200",
654
+ // "liquidationFee": "0.025000",
655
+ // "marketTakeBound": "0.02",
656
+ // "filters": [
657
+ // {
658
+ // "minPrice": "1",
659
+ // "maxPrice": "1000000",
660
+ // "filterType": "PRICE_FILTER",
661
+ // "tickSize": "0.1"
662
+ // },
663
+ // {
664
+ // "stepSize": "0.001",
665
+ // "filterType": "LOT_SIZE",
666
+ // "maxQty": "100",
667
+ // "minQty": "0.001"
668
+ // },
669
+ // {
670
+ // "stepSize": "0.001",
671
+ // "filterType": "MARKET_LOT_SIZE",
672
+ // "maxQty": "10",
673
+ // "minQty": "0.001"
674
+ // },
675
+ // {
676
+ // "limit": 200,
677
+ // "filterType": "MAX_NUM_ORDERS"
678
+ // },
679
+ // {
680
+ // "limit": 10,
681
+ // "filterType": "MAX_NUM_ALGO_ORDERS"
682
+ // },
683
+ // {
684
+ // "notional": "5",
685
+ // "filterType": "MIN_NOTIONAL"
686
+ // },
687
+ // {
688
+ // "multiplierDown": "0.9800",
689
+ // "multiplierUp": "1.0200",
690
+ // "multiplierDecimal": "4",
691
+ // "filterType": "PERCENT_PRICE"
692
+ // }
693
+ // ],
694
+ // "orderTypes": [
695
+ // "LIMIT",
696
+ // "MARKET",
697
+ // "STOP",
698
+ // "STOP_MARKET",
699
+ // "TAKE_PROFIT",
700
+ // "TAKE_PROFIT_MARKET",
701
+ // "TRAILING_STOP_MARKET"
702
+ // ],
703
+ // "timeInForce": [
704
+ // "GTC",
705
+ // "IOC",
706
+ // "FOK",
707
+ // "GTX",
708
+ // "RPI"
709
+ // ]
710
+ // }
711
+ // ]
712
+ //
713
+ const fees = this.fees;
714
+ const result = [];
715
+ for (let i = 0; i < rows.length; i++) {
716
+ let swap = false;
717
+ const market = rows[i];
718
+ const id = this.safeString(market, 'symbol');
719
+ const baseId = this.safeString(market, 'baseAsset');
720
+ const quoteId = this.safeString(market, 'quoteAsset');
721
+ const base = this.safeCurrencyCode(baseId);
722
+ const quote = this.safeCurrencyCode(quoteId);
723
+ const contractType = this.safeString(market, 'contractType');
724
+ const contract = contractType !== undefined;
725
+ let spot = true;
726
+ if (contractType === 'PERPETUAL') {
727
+ swap = true;
728
+ spot = false;
729
+ }
730
+ let contractSize = undefined;
731
+ let linear = undefined;
732
+ let inverse = undefined;
733
+ let symbol = base + '/' + quote;
734
+ let settle = undefined;
735
+ let settleId = undefined;
736
+ if (contract) {
737
+ settleId = this.safeString(market, 'marginAsset');
738
+ settle = this.safeCurrencyCode(settleId);
739
+ if (swap) {
740
+ symbol = symbol + ':' + settle;
741
+ }
742
+ linear = settle === quote;
743
+ inverse = settle === base;
744
+ contractSize = this.safeNumber2(market, 'contractSize', 'unit', this.parseNumber('1'));
745
+ }
746
+ let unifiedType = undefined;
747
+ if (spot) {
748
+ unifiedType = 'spot';
749
+ }
750
+ else if (swap) {
751
+ unifiedType = 'swap';
752
+ }
753
+ const status = this.safeString(market, 'status');
754
+ const active = status === 'TRADING';
755
+ const filters = this.safeList(market, 'filters', []);
756
+ const filtersByType = this.indexBy(filters, 'filterType');
757
+ const entry = this.safeMarketStructure({
758
+ 'id': id,
759
+ 'symbol': symbol,
760
+ 'base': base,
761
+ 'quote': quote,
762
+ 'settle': settle,
763
+ 'baseId': baseId,
764
+ 'quoteId': quoteId,
765
+ 'settleId': settleId,
766
+ 'type': unifiedType,
767
+ 'spot': spot,
768
+ 'margin': false,
769
+ 'swap': swap,
770
+ 'future': false,
771
+ 'option': false,
772
+ 'active': active,
773
+ 'contract': contract,
774
+ 'linear': linear,
775
+ 'inverse': inverse,
776
+ 'taker': fees['trading']['taker'],
777
+ 'maker': fees['trading']['maker'],
778
+ 'contractSize': contractSize,
779
+ 'expiry': undefined,
780
+ 'expiryDatetime': undefined,
781
+ 'strike': undefined,
782
+ 'optionType': undefined,
783
+ 'precision': {
784
+ 'amount': this.parseNumber(this.parsePrecision(this.safeString(market, 'quantityPrecision'))),
785
+ 'price': this.parseNumber(this.parsePrecision(this.safeString(market, 'pricePrecision'))),
786
+ 'base': this.parseNumber(this.parsePrecision(this.safeString(market, 'baseAssetPrecision'))),
787
+ 'quote': this.parseNumber(this.parsePrecision(this.safeString(market, 'quotePrecision'))),
788
+ },
789
+ 'limits': {
790
+ 'leverage': {
791
+ 'min': undefined,
792
+ 'max': undefined,
793
+ },
794
+ 'amount': {
795
+ 'min': undefined,
796
+ 'max': undefined,
797
+ },
798
+ 'price': {
799
+ 'min': undefined,
800
+ 'max': undefined,
801
+ },
802
+ 'cost': {
803
+ 'min': undefined,
804
+ 'max': undefined,
805
+ },
806
+ },
807
+ 'created': this.safeInteger(market, 'onboardDate'),
808
+ 'info': market,
809
+ });
810
+ if ('PRICE_FILTER' in filtersByType) {
811
+ const filter = this.safeDict(filtersByType, 'PRICE_FILTER', {});
812
+ entry['limits']['price'] = {
813
+ 'min': this.safeNumber(filter, 'minPrice'),
814
+ 'max': this.safeNumber(filter, 'maxPrice'),
815
+ };
816
+ entry['precision']['price'] = this.safeNumber(filter, 'tickSize');
817
+ }
818
+ if ('LOT_SIZE' in filtersByType) {
819
+ const filter = this.safeDict(filtersByType, 'LOT_SIZE', {});
820
+ entry['precision']['amount'] = this.safeNumber(filter, 'stepSize');
821
+ entry['limits']['amount'] = {
822
+ 'min': this.safeNumber(filter, 'minQty'),
823
+ 'max': this.safeNumber(filter, 'maxQty'),
824
+ };
825
+ }
826
+ if ('MARKET_LOT_SIZE' in filtersByType) {
827
+ const filter = this.safeDict(filtersByType, 'MARKET_LOT_SIZE', {});
828
+ entry['limits']['market'] = {
829
+ 'min': this.safeNumber(filter, 'minQty'),
830
+ 'max': this.safeNumber(filter, 'maxQty'),
831
+ };
832
+ }
833
+ if (('MIN_NOTIONAL' in filtersByType) || ('NOTIONAL' in filtersByType)) {
834
+ const filter = this.safeDict2(filtersByType, 'MIN_NOTIONAL', 'NOTIONAL', {});
835
+ entry['limits']['cost']['min'] = this.safeNumber(filter, 'notional');
836
+ }
837
+ result.push(entry);
838
+ }
839
+ return result;
840
+ }
841
+ /**
842
+ * @method
843
+ * @name aster#fetchTime
844
+ * @description fetches the current integer timestamp in milliseconds from the exchange server
845
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#check-server-time
846
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
847
+ * @returns {int} the current integer timestamp in milliseconds from the exchange server
848
+ */
849
+ async fetchTime(params = {}) {
850
+ const response = await this.fapiPublicGetV1Time(params);
851
+ //
852
+ // {
853
+ // "serverTime": 1499827319559
854
+ // }
855
+ //
856
+ return this.safeInteger(response, 'serverTime');
857
+ }
858
+ parseOHLCV(ohlcv, market = undefined) {
859
+ //
860
+ // [
861
+ // 1631158560000,
862
+ // "208.1850",
863
+ // "208.1850",
864
+ // "208.1850",
865
+ // "208.1850",
866
+ // "11.84",
867
+ // 1631158619999,
868
+ // "2464.910400",
869
+ // 1,
870
+ // "11.84",
871
+ // "2464.910400",
872
+ // "0"
873
+ // ]
874
+ //
875
+ return [
876
+ this.safeInteger(ohlcv, 0),
877
+ this.safeNumber(ohlcv, 1),
878
+ this.safeNumber(ohlcv, 2),
879
+ this.safeNumber(ohlcv, 3),
880
+ this.safeNumber(ohlcv, 4),
881
+ this.safeNumber(ohlcv, 5),
882
+ ];
883
+ }
884
+ /**
885
+ * @method
886
+ * @name aster#fetchOHLCV
887
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
888
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#k-line-data
889
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#klinecandlestick-data
890
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
891
+ * @param {string} timeframe the length of time each candle represents
892
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
893
+ * @param {int} [limit] the maximum amount of candles to fetch
894
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
895
+ * @param {string} [params.price] "mark" or "index" for mark price and index price candles
896
+ * @param {int} [params.until] the latest time in ms to fetch orders for
897
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
898
+ */
899
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
900
+ if (symbol === undefined) {
901
+ throw new ArgumentsRequired(this.id + ' fetchOHLCV() requires a symbol argument');
902
+ }
903
+ await this.loadMarkets();
904
+ const market = this.market(symbol);
905
+ let request = {};
906
+ if (since !== undefined) {
907
+ request['startTime'] = since;
908
+ }
909
+ if (limit !== undefined) {
910
+ if (limit > 1500) {
911
+ limit = 1500; // Default 500; max 1500.
912
+ }
913
+ request['limit'] = limit;
914
+ }
915
+ [request, params] = this.handleUntilOption('endTime', request, params);
916
+ request['interval'] = this.safeString(this.timeframes, timeframe, timeframe);
917
+ const price = this.safeString(params, 'price');
918
+ const isMark = (price === 'mark');
919
+ const isIndex = (price === 'index');
920
+ params = this.omit(params, 'price');
921
+ let response = undefined;
922
+ if (isMark) {
923
+ request['symbol'] = market['id'];
924
+ response = await this.fapiPublicGetV1MarkPriceKlines(this.extend(request, params));
925
+ }
926
+ else if (isIndex) {
927
+ request['pair'] = market['id'];
928
+ response = await this.fapiPublicGetV1IndexPriceKlines(this.extend(request, params));
929
+ }
930
+ else {
931
+ request['symbol'] = market['id'];
932
+ if (market['linear']) {
933
+ response = await this.fapiPublicGetV1Klines(this.extend(request, params));
934
+ }
935
+ else {
936
+ response = await this.sapiPublicGetV1Klines(this.extend(request, params));
937
+ }
938
+ }
939
+ //
940
+ // [
941
+ // [
942
+ // 1631158560000,
943
+ // "208.1850",
944
+ // "208.1850",
945
+ // "208.1850",
946
+ // "208.1850",
947
+ // "11.84",
948
+ // 1631158619999,
949
+ // "2464.910400",
950
+ // 1,
951
+ // "11.84",
952
+ // "2464.910400",
953
+ // "0"
954
+ // ]
955
+ // ]
956
+ //
957
+ return this.parseOHLCVs(response, market, timeframe, since, limit);
958
+ }
959
+ parseTrade(trade, market = undefined) {
960
+ //
961
+ // fetchTrades
962
+ //
963
+ // {
964
+ // "id": 3913206,
965
+ // "price": "644.100",
966
+ // "qty": "0.08",
967
+ // "quoteQty": "51.528",
968
+ // "time": 1749784506633,
969
+ // "isBuyerMaker": true
970
+ // }
971
+ //
972
+ // {
973
+ // "id": 657,
974
+ // "price": "1.01000000",
975
+ // "qty": "5.00000000",
976
+ // "baseQty": "4.95049505",
977
+ // "time": 1755156533943,
978
+ // "isBuyerMaker": false
979
+ // }
980
+ //
981
+ // fetchMyTrades
982
+ //
983
+ // {
984
+ // "buyer": false,
985
+ // "commission": "-0.07819010",
986
+ // "commissionAsset": "USDT",
987
+ // "id": 698759,
988
+ // "maker": false,
989
+ // "orderId": 25851813,
990
+ // "price": "7819.01",
991
+ // "qty": "0.002",
992
+ // "quoteQty": "15.63802",
993
+ // "realizedPnl": "-0.91539999",
994
+ // "side": "SELL",
995
+ // "positionSide": "SHORT",
996
+ // "symbol": "BTCUSDT",
997
+ // "time": 1569514978020
998
+ // }
999
+ //
1000
+ const id = this.safeString(trade, 'id');
1001
+ const symbol = market['symbol'];
1002
+ const currencyId = this.safeString(trade, 'commissionAsset');
1003
+ const currencyCode = this.safeCurrencyCode(currencyId);
1004
+ const amountString = this.safeString(trade, 'qty');
1005
+ const priceString = this.safeString(trade, 'price');
1006
+ const costString = this.safeString2(trade, 'quoteQty', 'baseQty');
1007
+ const timestamp = this.safeInteger(trade, 'time');
1008
+ let side = this.safeStringLower(trade, 'side');
1009
+ const isMaker = this.safeBool(trade, 'maker');
1010
+ let takerOrMaker = undefined;
1011
+ if (isMaker !== undefined) {
1012
+ takerOrMaker = isMaker ? 'maker' : 'taker';
1013
+ }
1014
+ const isBuyerMaker = this.safeBool(trade, 'isBuyerMaker');
1015
+ if (isBuyerMaker !== undefined) {
1016
+ side = isBuyerMaker ? 'sell' : 'buy';
1017
+ }
1018
+ return this.safeTrade({
1019
+ 'id': id,
1020
+ 'info': trade,
1021
+ 'timestamp': timestamp,
1022
+ 'datetime': this.iso8601(timestamp),
1023
+ 'symbol': symbol,
1024
+ 'order': this.safeString(trade, 'orderId'),
1025
+ 'type': undefined,
1026
+ 'side': side,
1027
+ 'takerOrMaker': takerOrMaker,
1028
+ 'price': priceString,
1029
+ 'amount': amountString,
1030
+ 'cost': costString,
1031
+ 'fee': {
1032
+ 'cost': this.parseNumber(Precise.stringAbs(this.safeString(trade, 'commission'))),
1033
+ 'currency': currencyCode,
1034
+ },
1035
+ }, market);
1036
+ }
1037
+ /**
1038
+ * @method
1039
+ * @name aster#fetchTrades
1040
+ * @description get the list of most recent trades for a particular symbol
1041
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#recent-trades-list
1042
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#recent-trades-list
1043
+ * @param {string} symbol unified symbol of the market to fetch trades for
1044
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
1045
+ * @param {int} [limit] the maximum amount of trades to fetch
1046
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1047
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
1048
+ */
1049
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
1050
+ if (symbol === undefined) {
1051
+ throw new ArgumentsRequired(this.id + ' fetchTrades() requires a symbol argument');
1052
+ }
1053
+ await this.loadMarkets();
1054
+ const market = this.market(symbol);
1055
+ const request = {
1056
+ 'symbol': market['id'],
1057
+ };
1058
+ if (limit !== undefined) {
1059
+ if (limit > 1000) {
1060
+ limit = 1000; // Default 500; max 1000.
1061
+ }
1062
+ request['limit'] = limit;
1063
+ }
1064
+ let response = undefined;
1065
+ if (market['swap']) {
1066
+ response = await this.fapiPublicGetV1Trades(this.extend(request, params));
1067
+ //
1068
+ // [
1069
+ // {
1070
+ // "id": 3913206,
1071
+ // "price": "644.100",
1072
+ // "qty": "0.08",
1073
+ // "quoteQty": "51.528",
1074
+ // "time": 1749784506633,
1075
+ // "isBuyerMaker": true
1076
+ // }
1077
+ // ]
1078
+ //
1079
+ }
1080
+ else {
1081
+ response = await this.sapiPublicGetV1Trades(this.extend(request, params));
1082
+ // [
1083
+ // {
1084
+ // "id": 657,
1085
+ // "price": "1.01000000",
1086
+ // "qty": "5.00000000",
1087
+ // "baseQty": "4.95049505",
1088
+ // "time": 1755156533943,
1089
+ // "isBuyerMaker": false
1090
+ // }
1091
+ // ]
1092
+ }
1093
+ return this.parseTrades(response, market, since, limit);
1094
+ }
1095
+ /**
1096
+ * @method
1097
+ * @name aster#fetchMyTrades
1098
+ * @description fetch all trades made by the user
1099
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#account-trade-history-user_data
1100
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#account-trade-list-user_data
1101
+ * @param {string} [symbol] unified market symbol
1102
+ * @param {int} [since] the earliest time in ms to fetch trades for
1103
+ * @param {int} [limit] the maximum number of trades structures to retrieve
1104
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1105
+ * @param {int} [params.until] timestamp in ms for the ending date filter, default is undefined
1106
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1107
+ */
1108
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1109
+ if (symbol === undefined) {
1110
+ throw new ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
1111
+ }
1112
+ await this.loadMarkets();
1113
+ const market = this.market(symbol);
1114
+ let request = {
1115
+ 'symbol': market['id'],
1116
+ };
1117
+ if (since !== undefined) {
1118
+ request['startTime'] = since;
1119
+ }
1120
+ if (limit !== undefined) {
1121
+ if (limit > 1000) {
1122
+ limit = 1000; // Default 500; max 1000.
1123
+ }
1124
+ request['limit'] = limit;
1125
+ }
1126
+ [request, params] = this.handleUntilOption('endTime', request, params);
1127
+ let response = undefined;
1128
+ if (market['swap']) {
1129
+ response = await this.fapiPrivateGetV1UserTrades(this.extend(request, params));
1130
+ }
1131
+ else {
1132
+ response = await this.sapiPrivateGetV1UserTrades(this.extend(request, params));
1133
+ }
1134
+ //
1135
+ // [
1136
+ // {
1137
+ // "buyer": false,
1138
+ // "commission": "-0.07819010",
1139
+ // "commissionAsset": "USDT",
1140
+ // "id": 698759,
1141
+ // "maker": false,
1142
+ // "orderId": 25851813,
1143
+ // "price": "7819.01",
1144
+ // "qty": "0.002",
1145
+ // "quoteQty": "15.63802",
1146
+ // "realizedPnl": "-0.91539999",
1147
+ // "side": "SELL",
1148
+ // "positionSide": "SHORT",
1149
+ // "symbol": "BTCUSDT",
1150
+ // "time": 1569514978020
1151
+ // }
1152
+ // ]
1153
+ //
1154
+ return this.parseTrades(response, market, since, limit, params);
1155
+ }
1156
+ /**
1157
+ * @method
1158
+ * @name aster#fetchOrderBook
1159
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1160
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#depth-information
1161
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#order-book
1162
+ * @param {string} symbol unified symbol of the market to fetch the order book for
1163
+ * @param {int} [limit] the maximum amount of order book entries to return
1164
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1165
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1166
+ */
1167
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
1168
+ if (symbol === undefined) {
1169
+ throw new ArgumentsRequired(this.id + ' fetchOrderBook() requires a symbol argument');
1170
+ }
1171
+ await this.loadMarkets();
1172
+ const market = this.market(symbol);
1173
+ const request = {
1174
+ 'symbol': market['id'],
1175
+ };
1176
+ if (limit !== undefined) {
1177
+ // limit: [5, 10, 20, 50, 100, 500, 1000]. Default: 500
1178
+ if (limit > 1000) {
1179
+ limit = 1000; // Default 500; max 1000.
1180
+ }
1181
+ request['limit'] = limit;
1182
+ }
1183
+ let response = undefined;
1184
+ if (market['swap']) {
1185
+ response = await this.fapiPublicGetV1Depth(this.extend(request, params));
1186
+ }
1187
+ else {
1188
+ response = await this.sapiPublicGetV1Depth(this.extend(request, params));
1189
+ }
1190
+ //
1191
+ // {
1192
+ // "lastUpdateId": 1027024,
1193
+ // "E": 1589436922972, // Message output time
1194
+ // "T": 1589436922959, // Transaction time
1195
+ // "bids": [
1196
+ // [
1197
+ // "4.00000000", // PRICE
1198
+ // "431.00000000" // QTY
1199
+ // ]
1200
+ // ],
1201
+ // "asks": [
1202
+ // [
1203
+ // "4.00000200",
1204
+ // "12.00000000"
1205
+ // ]
1206
+ // ]
1207
+ // }
1208
+ //
1209
+ const timestamp = this.safeInteger(response, 'T');
1210
+ return this.parseOrderBook(response, symbol, timestamp, 'bids', 'asks');
1211
+ }
1212
+ /**
1213
+ * @method
1214
+ * @name aster#fetchFundingRateHistory
1215
+ * @description fetches historical funding rate prices
1216
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-funding-rate-history
1217
+ * @param {string} symbol unified symbol of the market to fetch the funding rate history for
1218
+ * @param {int} [since] timestamp in ms of the earliest funding rate to fetch
1219
+ * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
1220
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1221
+ * @param {int} [params.until] timestamp in ms of the latest funding rate
1222
+ * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
1223
+ */
1224
+ async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1225
+ await this.loadMarkets();
1226
+ let request = {};
1227
+ if (symbol !== undefined) {
1228
+ const market = this.market(symbol);
1229
+ request['symbol'] = market['id'];
1230
+ }
1231
+ if (since !== undefined) {
1232
+ request['startTime'] = since;
1233
+ }
1234
+ if (limit !== undefined) {
1235
+ if (limit > 1000) {
1236
+ limit = 1000; // Default 100; max 1000
1237
+ }
1238
+ request['limit'] = limit;
1239
+ }
1240
+ [request, params] = this.handleUntilOption('endTime', request, params);
1241
+ const response = await this.fapiPublicGetV1FundingRate(this.extend(request, params));
1242
+ //
1243
+ // [
1244
+ // {
1245
+ // "symbol": "BTCUSDT",
1246
+ // "fundingTime": 1747209600000,
1247
+ // "fundingRate": "0.00010000"
1248
+ // }
1249
+ // ]
1250
+ //
1251
+ const rates = [];
1252
+ for (let i = 0; i < response.length; i++) {
1253
+ const entry = response[i];
1254
+ const timestamp = this.safeInteger(entry, 'fundingTime');
1255
+ rates.push({
1256
+ 'info': entry,
1257
+ 'symbol': this.safeSymbol(this.safeString(entry, 'symbol'), undefined, undefined, 'swap'),
1258
+ 'fundingRate': this.safeNumber(entry, 'fundingRate'),
1259
+ 'timestamp': timestamp,
1260
+ 'datetime': this.iso8601(timestamp),
1261
+ });
1262
+ }
1263
+ const sorted = this.sortBy(rates, 'timestamp');
1264
+ return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
1265
+ }
1266
+ parseTicker(ticker, market = undefined) {
1267
+ //
1268
+ // spot
1269
+ // {
1270
+ // "symbol": "BTCUSDT",
1271
+ // "priceChange": "-2274.38",
1272
+ // "priceChangePercent": "-2.049",
1273
+ // "weightedAvgPrice": "109524.37084136",
1274
+ // "lastPrice": "108738.78",
1275
+ // "lastQty": "0.00034",
1276
+ // "openPrice": "111013.16",
1277
+ // "highPrice": "111975.81",
1278
+ // "lowPrice": "107459.25",
1279
+ // "volume": "28.67876",
1280
+ // "quoteVolume": "3141023.14551030",
1281
+ // "openTime": "1760578800000",
1282
+ // "closeTime": "1760665024749",
1283
+ // "firstId": "37447",
1284
+ // "lastId": "39698",
1285
+ // "count": "2252",
1286
+ // "baseAsset": "BTC",
1287
+ // "quoteAsset": "USDT",
1288
+ // "bidPrice": "108705.11",
1289
+ // "bidQty": "0.03351",
1290
+ // "askPrice": "108725.99",
1291
+ // "askQty": "0.08724"
1292
+ // }
1293
+ // swap
1294
+ // {
1295
+ // "symbol": "BTCUSDT",
1296
+ // "priceChange": "1845.7",
1297
+ // "priceChangePercent": "1.755",
1298
+ // "weightedAvgPrice": "105515.5",
1299
+ // "lastPrice": "107037.7",
1300
+ // "lastQty": "0.004",
1301
+ // "openPrice": "105192.0",
1302
+ // "highPrice": "107223.5",
1303
+ // "lowPrice": "104431.6",
1304
+ // "volume": "8753.286",
1305
+ // "quoteVolume": "923607368.61",
1306
+ // "openTime": 1749976620000,
1307
+ // "closeTime": 1750063053754,
1308
+ // "firstId": 24195078,
1309
+ // "lastId": 24375783,
1310
+ // "count": 180706
1311
+ // }
1312
+ //
1313
+ const timestamp = this.safeInteger(ticker, 'closeTime');
1314
+ let marketType = undefined;
1315
+ if ('bidQty' in ticker) {
1316
+ marketType = 'spot';
1317
+ }
1318
+ else {
1319
+ marketType = 'contract';
1320
+ }
1321
+ const marketId = this.safeString(ticker, 'symbol');
1322
+ market = this.safeMarket(marketId, market, undefined, marketType);
1323
+ const symbol = market['symbol'];
1324
+ const last = this.safeString(ticker, 'lastPrice');
1325
+ const open = this.safeString(ticker, 'openPrice');
1326
+ let percentage = this.safeString(ticker, 'priceChangePercent');
1327
+ percentage = Precise.stringMul(percentage, '100');
1328
+ const quoteVolume = this.safeString(ticker, 'quoteVolume');
1329
+ const baseVolume = this.safeString(ticker, 'volume');
1330
+ const high = this.safeString(ticker, 'highPrice');
1331
+ const low = this.safeString(ticker, 'lowPrice');
1332
+ return this.safeTicker({
1333
+ 'symbol': symbol,
1334
+ 'timestamp': timestamp,
1335
+ 'datetime': this.iso8601(timestamp),
1336
+ 'high': high,
1337
+ 'low': low,
1338
+ 'bid': this.safeString(ticker, 'bidPrice'),
1339
+ 'bidVolume': this.safeString(ticker, 'bidQty'),
1340
+ 'ask': this.safeString(ticker, 'askPrice'),
1341
+ 'askVolume': this.safeString(ticker, 'askQty'),
1342
+ 'vwap': undefined,
1343
+ 'open': open,
1344
+ 'close': last,
1345
+ 'last': last,
1346
+ 'previousClose': undefined,
1347
+ 'change': undefined,
1348
+ 'percentage': percentage,
1349
+ 'average': undefined,
1350
+ 'baseVolume': baseVolume,
1351
+ 'quoteVolume': quoteVolume,
1352
+ 'markPrice': undefined,
1353
+ 'indexPrice': undefined,
1354
+ 'info': ticker,
1355
+ }, market);
1356
+ }
1357
+ /**
1358
+ * @method
1359
+ * @name aster#fetchTicker
1360
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
1361
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#24h-price-change
1362
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#24hr-ticker-price-change-statistics
1363
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
1364
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1365
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1366
+ */
1367
+ async fetchTicker(symbol, params = {}) {
1368
+ if (symbol === undefined) {
1369
+ throw new ArgumentsRequired(this.id + ' fetchTicker() requires a symbol argument');
1370
+ }
1371
+ await this.loadMarkets();
1372
+ const market = this.market(symbol);
1373
+ const request = {
1374
+ 'symbol': market['id'],
1375
+ };
1376
+ let response = undefined;
1377
+ if (market['swap']) {
1378
+ response = await this.fapiPublicGetV1Ticker24hr(this.extend(request, params));
1379
+ //
1380
+ // {
1381
+ // "symbol": "BTCUSDT",
1382
+ // "priceChange": "1845.7",
1383
+ // "priceChangePercent": "1.755",
1384
+ // "weightedAvgPrice": "105515.5",
1385
+ // "lastPrice": "107037.7",
1386
+ // "lastQty": "0.004",
1387
+ // "openPrice": "105192.0",
1388
+ // "highPrice": "107223.5",
1389
+ // "lowPrice": "104431.6",
1390
+ // "volume": "8753.286",
1391
+ // "quoteVolume": "923607368.61",
1392
+ // "openTime": 1749976620000,
1393
+ // "closeTime": 1750063053754,
1394
+ // "firstId": 24195078,
1395
+ // "lastId": 24375783,
1396
+ // "count": 180706
1397
+ // }
1398
+ //
1399
+ }
1400
+ else {
1401
+ response = await this.sapiPublicGetV1Ticker24hr(this.extend(request, params));
1402
+ // {
1403
+ // "symbol": "BTCUSDT",
1404
+ // "priceChange": "-2274.38",
1405
+ // "priceChangePercent": "-2.049",
1406
+ // "weightedAvgPrice": "109524.37084136",
1407
+ // "lastPrice": "108738.78",
1408
+ // "lastQty": "0.00034",
1409
+ // "openPrice": "111013.16",
1410
+ // "highPrice": "111975.81",
1411
+ // "lowPrice": "107459.25",
1412
+ // "volume": "28.67876",
1413
+ // "quoteVolume": "3141023.14551030",
1414
+ // "openTime": "1760578800000",
1415
+ // "closeTime": "1760665024749",
1416
+ // "firstId": "37447",
1417
+ // "lastId": "39698",
1418
+ // "count": "2252",
1419
+ // "baseAsset": "BTC",
1420
+ // "quoteAsset": "USDT",
1421
+ // "bidPrice": "108705.11",
1422
+ // "bidQty": "0.03351",
1423
+ // "askPrice": "108725.99",
1424
+ // "askQty": "0.08724"
1425
+ // }
1426
+ }
1427
+ return this.parseTicker(response, market);
1428
+ }
1429
+ /**
1430
+ * @method
1431
+ * @name aster#fetchTickers
1432
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
1433
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#24h-price-change
1434
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#24hr-ticker-price-change-statistics
1435
+ * @param {string[]} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
1436
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1437
+ * @param {string} [params.subType] "linear" or "inverse"
1438
+ * @param {string} [params.type] 'spot', 'option', use params["subType"] for swap and future markets
1439
+ * @returns {object} an array of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
1440
+ */
1441
+ async fetchTickers(symbols = undefined, params = {}) {
1442
+ await this.loadMarkets();
1443
+ symbols = this.marketSymbols(symbols, undefined, true, true, true);
1444
+ const market = this.getMarketFromSymbols(symbols);
1445
+ let type = undefined;
1446
+ [type, params] = this.handleMarketTypeAndParams('fetchTickers', market, params);
1447
+ let subType = undefined;
1448
+ [subType, params] = this.handleSubTypeAndParams('fetchTickers', market, params);
1449
+ let response = undefined;
1450
+ if (this.isLinear(type, subType)) {
1451
+ response = await this.fapiPublicGetV1Ticker24hr(params);
1452
+ }
1453
+ else if (type === 'spot') {
1454
+ response = await this.sapiPublicGetV1Ticker24hr(params);
1455
+ }
1456
+ else {
1457
+ throw new NotSupported(this.id + ' fetchTickers() does not support ' + type + ' markets yet');
1458
+ }
1459
+ //
1460
+ // [
1461
+ // {
1462
+ // "symbol": "BTCUSDT",
1463
+ // "priceChange": "1845.7",
1464
+ // "priceChangePercent": "1.755",
1465
+ // "weightedAvgPrice": "105515.5",
1466
+ // "lastPrice": "107037.7",
1467
+ // "lastQty": "0.004",
1468
+ // "openPrice": "105192.0",
1469
+ // "highPrice": "107223.5",
1470
+ // "lowPrice": "104431.6",
1471
+ // "volume": "8753.286",
1472
+ // "quoteVolume": "923607368.61",
1473
+ // "openTime": 1749976620000,
1474
+ // "closeTime": 1750063053754,
1475
+ // "firstId": 24195078,
1476
+ // "lastId": 24375783,
1477
+ // "count": 180706
1478
+ // }
1479
+ // ]
1480
+ //
1481
+ return this.parseTickers(response, symbols);
1482
+ }
1483
+ parseFundingRate(contract, market = undefined) {
1484
+ //
1485
+ // {
1486
+ // "symbol": "BTCUSDT",
1487
+ // "markPrice": "106729.84047826",
1488
+ // "indexPrice": "106775.72673913",
1489
+ // "estimatedSettlePrice": "106708.84997006",
1490
+ // "lastFundingRate": "0.00010000",
1491
+ // "interestRate": "0.00010000",
1492
+ // "nextFundingTime": 1750147200000,
1493
+ // "time": 1750146970000
1494
+ // }
1495
+ // {
1496
+ // "symbol": "INJUSDT",
1497
+ // "interestRate": "0.00010000",
1498
+ // "time": 1756197479000,
1499
+ // "fundingIntervalHours": 8,
1500
+ // "fundingFeeCap": 0.03,
1501
+ // "fundingFeeFloor": -0.03
1502
+ // }
1503
+ //
1504
+ const marketId = this.safeString(contract, 'symbol');
1505
+ const nextFundingTimestamp = this.safeInteger(contract, 'nextFundingTime');
1506
+ const timestamp = this.safeInteger(contract, 'time');
1507
+ const interval = this.safeString(contract, 'fundingIntervalHours');
1508
+ let intervalString = undefined;
1509
+ if (interval !== undefined) {
1510
+ intervalString = interval + 'h';
1511
+ }
1512
+ return {
1513
+ 'info': contract,
1514
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
1515
+ 'markPrice': this.safeNumber(contract, 'markPrice'),
1516
+ 'indexPrice': this.safeNumber(contract, 'indexPrice'),
1517
+ 'interestRate': this.safeNumber(contract, 'interestRate'),
1518
+ 'estimatedSettlePrice': this.safeNumber(contract, 'estimatedSettlePrice'),
1519
+ 'timestamp': timestamp,
1520
+ 'datetime': this.iso8601(timestamp),
1521
+ 'fundingRate': this.safeNumber(contract, 'lastFundingRate'),
1522
+ 'fundingTimestamp': undefined,
1523
+ 'fundingDatetime': undefined,
1524
+ 'nextFundingRate': undefined,
1525
+ 'nextFundingTimestamp': nextFundingTimestamp,
1526
+ 'nextFundingDatetime': this.iso8601(nextFundingTimestamp),
1527
+ 'previousFundingRate': undefined,
1528
+ 'previousFundingTimestamp': undefined,
1529
+ 'previousFundingDatetime': undefined,
1530
+ 'interval': intervalString,
1531
+ };
1532
+ }
1533
+ /**
1534
+ * @method
1535
+ * @name aster#fetchFundingRate
1536
+ * @description fetch the current funding rate
1537
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#mark-price
1538
+ * @param {string} symbol unified market symbol
1539
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1540
+ * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
1541
+ */
1542
+ async fetchFundingRate(symbol, params = {}) {
1543
+ if (symbol === undefined) {
1544
+ throw new ArgumentsRequired(this.id + ' fetchFundingRate() requires a symbol argument');
1545
+ }
1546
+ await this.loadMarkets();
1547
+ const market = this.market(symbol);
1548
+ const request = {
1549
+ 'symbol': market['id'],
1550
+ };
1551
+ const response = await this.fapiPublicGetV1PremiumIndex(this.extend(request, params));
1552
+ //
1553
+ // {
1554
+ // "symbol": "BTCUSDT",
1555
+ // "markPrice": "106729.84047826",
1556
+ // "indexPrice": "106775.72673913",
1557
+ // "estimatedSettlePrice": "106708.84997006",
1558
+ // "lastFundingRate": "0.00010000",
1559
+ // "interestRate": "0.00010000",
1560
+ // "nextFundingTime": 1750147200000,
1561
+ // "time": 1750146970000
1562
+ // }
1563
+ //
1564
+ return this.parseFundingRate(response, market);
1565
+ }
1566
+ /**
1567
+ * @method
1568
+ * @name aster#fetchFundingRates
1569
+ * @description fetch the current funding rate for multiple symbols
1570
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#24hr-ticker-price-change-statistics
1571
+ * @param {string[]} [symbols] list of unified market symbols
1572
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1573
+ * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
1574
+ */
1575
+ async fetchFundingRates(symbols = undefined, params = {}) {
1576
+ await this.loadMarkets();
1577
+ symbols = this.marketSymbols(symbols);
1578
+ const response = await this.fapiPublicGetV1PremiumIndex(this.extend(params));
1579
+ //
1580
+ // [
1581
+ // {
1582
+ // "symbol": "BTCUSDT",
1583
+ // "markPrice": "106729.84047826",
1584
+ // "indexPrice": "106775.72673913",
1585
+ // "estimatedSettlePrice": "106708.84997006",
1586
+ // "lastFundingRate": "0.00010000",
1587
+ // "interestRate": "0.00010000",
1588
+ // "nextFundingTime": 1750147200000,
1589
+ // "time": 1750146970000
1590
+ // }
1591
+ // ]
1592
+ //
1593
+ return this.parseFundingRates(response, symbols);
1594
+ }
1595
+ /**
1596
+ * @method
1597
+ * @name aster#fetchFundingIntervals
1598
+ * @description fetch the funding rate interval for multiple markets
1599
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-funding-rate-config
1600
+ * @param {string[]} [symbols] list of unified market symbols
1601
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1602
+ * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
1603
+ */
1604
+ async fetchFundingIntervals(symbols = undefined, params = {}) {
1605
+ await this.loadMarkets();
1606
+ if (symbols !== undefined) {
1607
+ symbols = this.marketSymbols(symbols);
1608
+ }
1609
+ const response = await this.fapiPublicGetV1FundingInfo(params);
1610
+ //
1611
+ // [
1612
+ // {
1613
+ // "symbol": "INJUSDT",
1614
+ // "interestRate": "0.00010000",
1615
+ // "time": 1756197479000,
1616
+ // "fundingIntervalHours": 8,
1617
+ // "fundingFeeCap": 0.03,
1618
+ // "fundingFeeFloor": -0.03
1619
+ // }
1620
+ // ]
1621
+ //
1622
+ return this.parseFundingRates(response, symbols);
1623
+ }
1624
+ parseBalance(response) {
1625
+ const result = { 'info': response };
1626
+ for (let i = 0; i < response.length; i++) {
1627
+ const balance = response[i];
1628
+ const currencyId = this.safeString(balance, 'asset');
1629
+ const code = this.safeCurrencyCode(currencyId);
1630
+ const account = this.account();
1631
+ account['free'] = this.safeString2(balance, 'free', 'maxWithdrawAmount');
1632
+ account['used'] = this.safeString(balance, 'locked');
1633
+ account['total'] = this.safeString(balance, 'walletBalance');
1634
+ result[code] = account;
1635
+ }
1636
+ return this.safeBalance(result);
1637
+ }
1638
+ /**
1639
+ * @method
1640
+ * @name aster#fetchBalance
1641
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
1642
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#account-information-v4-user_data
1643
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#account-information-user_data
1644
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1645
+ * @param {string} [params.subType] "linear" or "inverse"
1646
+ * @param {string} [params.type] 'spot', 'option', use params["subType"] for swap and future markets
1647
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1648
+ */
1649
+ async fetchBalance(params = {}) {
1650
+ let type = undefined;
1651
+ [type, params] = this.handleMarketTypeAndParams('fetchBalance', undefined, params);
1652
+ let subType = undefined;
1653
+ [subType, params] = this.handleSubTypeAndParams('fetchBalance', undefined, params);
1654
+ let response = undefined;
1655
+ let data = undefined;
1656
+ if (this.isLinear(type, subType)) {
1657
+ response = await this.fapiPrivateGetV4Account(params);
1658
+ data = this.safeList(response, 'assets', []);
1659
+ //
1660
+ // [
1661
+ // {
1662
+ // "asset": "USDT", // asset name
1663
+ // "walletBalance": "23.72469206", // wallet balance
1664
+ // "unrealizedProfit": "0.00000000", // unrealized profit
1665
+ // "marginBalance": "23.72469206", // margin balance
1666
+ // "maintMargin": "0.00000000", // maintenance margin required
1667
+ // "initialMargin": "0.00000000", // total initial margin required with current mark price
1668
+ // "positionInitialMargin": "0.00000000", //initial margin required for positions with current mark price
1669
+ // "openOrderInitialMargin": "0.00000000", // initial margin required for open orders with current mark price
1670
+ // "crossWalletBalance": "23.72469206", // crossed wallet balance
1671
+ // "crossUnPnl": "0.00000000", // unrealized profit of crossed positions
1672
+ // "availableBalance": "23.72469206", // available balance
1673
+ // "maxWithdrawAmount": "23.72469206", // maximum amount for transfer out
1674
+ // "marginAvailable": true, // whether the asset can be used as margin in Multi-Assets mode
1675
+ // "updateTime": 1625474304765 // last update time
1676
+ // }
1677
+ // ]
1678
+ //
1679
+ }
1680
+ else if (type === 'spot') {
1681
+ response = await this.sapiPrivateGetV1Account(params);
1682
+ data = this.safeList(response, 'balances', []);
1683
+ //
1684
+ // [
1685
+ // {
1686
+ // "asset": "BTC",
1687
+ // "free": "4723846.89208129",
1688
+ // "locked": "0.00000000"
1689
+ // }
1690
+ // ]
1691
+ //
1692
+ }
1693
+ else {
1694
+ throw new NotSupported(this.id + ' fetchBalance() does not support ' + type + ' markets yet');
1695
+ }
1696
+ return this.parseBalance(data);
1697
+ }
1698
+ /**
1699
+ * @method
1700
+ * @name aster#setMarginMode
1701
+ * @description set margin mode to 'cross' or 'isolated'
1702
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#change-margin-type-trade
1703
+ * @param {string} marginMode 'cross' or 'isolated'
1704
+ * @param {string} symbol unified market symbol
1705
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1706
+ * @returns {object} response from the exchange
1707
+ */
1708
+ async setMarginMode(marginMode, symbol = undefined, params = {}) {
1709
+ if (symbol === undefined) {
1710
+ throw new ArgumentsRequired(this.id + ' setMarginMode() requires a symbol argument');
1711
+ }
1712
+ marginMode = marginMode.toUpperCase();
1713
+ if (marginMode === 'CROSS') {
1714
+ marginMode = 'CROSSED';
1715
+ }
1716
+ if ((marginMode !== 'ISOLATED') && (marginMode !== 'CROSSED')) {
1717
+ throw new BadRequest(this.id + ' marginMode must be either isolated or cross');
1718
+ }
1719
+ await this.loadMarkets();
1720
+ const market = this.market(symbol);
1721
+ const request = {
1722
+ 'symbol': market['id'],
1723
+ 'marginType': marginMode,
1724
+ };
1725
+ const response = await this.fapiPrivatePostV1MarginType(this.extend(request, params));
1726
+ //
1727
+ // {
1728
+ // "amount": 100.0,
1729
+ // "code": 200,
1730
+ // "msg": "Successfully modify position margin.",
1731
+ // "type": 1
1732
+ // }
1733
+ //
1734
+ return response;
1735
+ }
1736
+ /**
1737
+ * @method
1738
+ * @name aster#fetchPositionMode
1739
+ * @description fetchs the position mode, hedged or one way, hedged for aster is set identically for all linear markets or all inverse markets
1740
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-current-position-modeuser_data
1741
+ * @param {string} symbol unified symbol of the market to fetch the order book for
1742
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1743
+ * @returns {object} an object detailing whether the market is in hedged or one-way mode
1744
+ */
1745
+ async fetchPositionMode(symbol = undefined, params = {}) {
1746
+ const response = await this.fapiPrivateGetV1PositionSideDual(params);
1747
+ //
1748
+ // {
1749
+ // "dualSidePosition": true // "true": Hedge Mode; "false": One-way Mode
1750
+ // }
1751
+ //
1752
+ const dualSidePosition = this.safeBool(response, 'dualSidePosition');
1753
+ return {
1754
+ 'info': response,
1755
+ 'hedged': (dualSidePosition === true),
1756
+ };
1757
+ }
1758
+ /**
1759
+ * @method
1760
+ * @name aster#setPositionMode
1761
+ * @description set hedged to true or false for a market
1762
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#change-position-modetrade
1763
+ * @param {bool} hedged set to true to use dualSidePosition
1764
+ * @param {string} symbol not used by bingx setPositionMode ()
1765
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1766
+ * @returns {object} response from the exchange
1767
+ */
1768
+ async setPositionMode(hedged, symbol = undefined, params = {}) {
1769
+ const request = {
1770
+ 'dualSidePosition': hedged,
1771
+ };
1772
+ //
1773
+ // {
1774
+ // "code": 200,
1775
+ // "msg": "success"
1776
+ // }
1777
+ //
1778
+ return await this.fapiPrivatePostV1PositionSideDual(this.extend(request, params));
1779
+ }
1780
+ parseTradingFee(fee, market = undefined) {
1781
+ const marketId = this.safeString(fee, 'symbol');
1782
+ market = this.safeMarket(marketId, market);
1783
+ const symbol = this.safeSymbol(marketId, market);
1784
+ return {
1785
+ 'info': fee,
1786
+ 'symbol': symbol,
1787
+ 'maker': this.safeNumber(fee, 'makerCommissionRate'),
1788
+ 'taker': this.safeNumber(fee, 'takerCommissionRate'),
1789
+ 'percentage': false,
1790
+ 'tierBased': false,
1791
+ };
1792
+ }
1793
+ /**
1794
+ * @method
1795
+ * @name aster#fetchTradingFee
1796
+ * @description fetch the trading fees for a market
1797
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#get-symbol-fees
1798
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#user-commission-rate-user_data
1799
+ * @param {string} symbol unified market symbol
1800
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1801
+ * @returns {object} a [fee structure]{@link https://docs.ccxt.com/#/?id=fee-structure}
1802
+ */
1803
+ async fetchTradingFee(symbol, params = {}) {
1804
+ await this.loadMarkets();
1805
+ const market = this.market(symbol);
1806
+ const request = {
1807
+ 'symbol': market['id'],
1808
+ };
1809
+ let response = undefined;
1810
+ if (market['swap']) {
1811
+ response = await this.fapiPrivateGetV1CommissionRate(this.extend(request, params));
1812
+ }
1813
+ else {
1814
+ response = await this.sapiPrivateGetV1CommissionRate(this.extend(request, params));
1815
+ }
1816
+ //
1817
+ // {
1818
+ // "symbol": "BTCUSDT",
1819
+ // "makerCommissionRate": "0.0002",
1820
+ // "takerCommissionRate": "0.0004"
1821
+ // }
1822
+ //
1823
+ return this.parseTradingFee(response, market);
1824
+ }
1825
+ parseOrderStatus(status) {
1826
+ const statuses = {
1827
+ 'NEW': 'open',
1828
+ 'PARTIALLY_FILLED': 'open',
1829
+ 'FILLED': 'closed',
1830
+ 'CANCELED': 'canceled',
1831
+ 'REJECTED': 'canceled',
1832
+ 'EXPIRED': 'canceled',
1833
+ };
1834
+ return this.safeString(statuses, status, status);
1835
+ }
1836
+ parseOrderType(type) {
1837
+ const types = {
1838
+ 'LIMIT': 'limit',
1839
+ 'MARKET': 'market',
1840
+ 'STOP': 'limit',
1841
+ 'STOP_MARKET': 'market',
1842
+ 'TAKE_PROFIT': 'limit',
1843
+ 'TAKE_PROFIT_MARKET': 'market',
1844
+ 'TRAILING_STOP_MARKET': 'market',
1845
+ };
1846
+ return this.safeString(types, type, type);
1847
+ }
1848
+ parseOrder(order, market = undefined) {
1849
+ //
1850
+ // swap
1851
+ // {
1852
+ // "avgPrice": "0.00000",
1853
+ // "clientOrderId": "abc",
1854
+ // "cumQuote": "0",
1855
+ // "executedQty": "0",
1856
+ // "orderId": 1917641,
1857
+ // "origQty": "0.40",
1858
+ // "origType": "TRAILING_STOP_MARKET",
1859
+ // "price": "0",
1860
+ // "reduceOnly": false,
1861
+ // "side": "BUY",
1862
+ // "positionSide": "SHORT",
1863
+ // "status": "NEW",
1864
+ // "stopPrice": "9300",
1865
+ // "closePosition": false,
1866
+ // "symbol": "BTCUSDT",
1867
+ // "time": 1579276756075,
1868
+ // "timeInForce": "GTC",
1869
+ // "type": "TRAILING_STOP_MARKET",
1870
+ // "activatePrice": "9020",
1871
+ // "priceRate": "0.3",
1872
+ // "updateTime": 1579276756075,
1873
+ // "workingType": "CONTRACT_PRICE",
1874
+ // "priceProtect": false
1875
+ // }
1876
+ // spot
1877
+ // {
1878
+ // "orderId": 38,
1879
+ // "symbol": "ADA25SLP25",
1880
+ // "status": "FILLED",
1881
+ // "clientOrderId": "afMd4GBQyHkHpGWdiy34Li",
1882
+ // "price": "20",
1883
+ // "avgPrice": "12.0000000000000000",
1884
+ // "origQty": "10",
1885
+ // "executedQty": "10",
1886
+ // "cumQuote": "120",
1887
+ // "timeInForce": "GTC",
1888
+ // "type": "LIMIT",
1889
+ // "side": "BUY",
1890
+ // "stopPrice": "0",
1891
+ // "origType": "LIMIT",
1892
+ // "time": 1649913186270,
1893
+ // "updateTime": 1649913186297
1894
+ // }
1895
+ //
1896
+ const info = order;
1897
+ const marketId = this.safeString(order, 'symbol');
1898
+ market = this.safeMarket(marketId, market);
1899
+ const side = this.safeStringLower(order, 'side');
1900
+ const timestamp = this.safeInteger(order, 'time');
1901
+ const lastTradeTimestamp = this.safeInteger(order, 'updateTime');
1902
+ const statusId = this.safeStringUpper(order, 'status');
1903
+ const rawType = this.safeStringUpper(order, 'type');
1904
+ const stopPriceString = this.safeString(order, 'stopPrice');
1905
+ const triggerPrice = this.parseNumber(this.omitZero(stopPriceString));
1906
+ return this.safeOrder({
1907
+ 'info': info,
1908
+ 'id': this.safeString(order, 'orderId'),
1909
+ 'clientOrderId': this.safeString(order, 'clientOrderId'),
1910
+ 'symbol': this.safeSymbol(marketId, market),
1911
+ 'timestamp': timestamp,
1912
+ 'datetime': this.iso8601(timestamp),
1913
+ 'lastTradeTimestamp': lastTradeTimestamp,
1914
+ 'lastUpdateTimestamp': this.safeInteger(order, 'updateTime'),
1915
+ 'type': this.parseOrderType(rawType),
1916
+ 'timeInForce': this.safeString(order, 'timeInForce'),
1917
+ 'postOnly': undefined,
1918
+ 'side': side,
1919
+ 'price': this.safeString(order, 'price'),
1920
+ 'triggerPrice': triggerPrice,
1921
+ 'average': this.safeString(order, 'avgPrice'),
1922
+ 'cost': this.safeString(order, 'cumQuote'),
1923
+ 'amount': this.safeString(order, 'origQty'),
1924
+ 'filled': this.safeString(order, 'executedQty'),
1925
+ 'remaining': undefined,
1926
+ 'status': this.parseOrderStatus(statusId),
1927
+ 'fee': undefined,
1928
+ 'trades': undefined,
1929
+ 'reduceOnly': this.safeBool2(order, 'reduceOnly', 'ro'),
1930
+ }, market);
1931
+ }
1932
+ /**
1933
+ * @method
1934
+ * @name aster#fetchOrder
1935
+ * @description fetches information on an order made by the user
1936
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#query-order-user_data
1937
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#query-order-user_data
1938
+ * @param {string} id the order id
1939
+ * @param {string} symbol unified symbol of the market the order was made in
1940
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1941
+ * @param {string} [params.clientOrderId] a unique id for the order
1942
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1943
+ */
1944
+ async fetchOrder(id, symbol = undefined, params = {}) {
1945
+ if (symbol === undefined) {
1946
+ throw new ArgumentsRequired(this.id + ' fetchOrder() requires a symbol argument');
1947
+ }
1948
+ await this.loadMarkets();
1949
+ const market = this.market(symbol);
1950
+ const request = {
1951
+ 'symbol': market['id'],
1952
+ };
1953
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'clientOid');
1954
+ params = this.omit(params, ['clientOrderId', 'clientOid']);
1955
+ if (clientOrderId !== undefined) {
1956
+ request['origClientOrderId'] = clientOrderId;
1957
+ }
1958
+ else {
1959
+ request['orderId'] = id;
1960
+ }
1961
+ let response = undefined;
1962
+ if (market['swap']) {
1963
+ response = await this.fapiPrivateGetV1Order(this.extend(request, params));
1964
+ }
1965
+ else {
1966
+ response = await this.sapiPrivateGetV1Order(this.extend(request, params));
1967
+ }
1968
+ return this.parseOrder(response, market);
1969
+ }
1970
+ /**
1971
+ * @method
1972
+ * @name aster#fetchOpenOrder
1973
+ * @description fetch an open order by the id
1974
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#query-current-open-order-user_data
1975
+ * @param {string} id order id
1976
+ * @param {string} symbol unified market symbol
1977
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1978
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1979
+ */
1980
+ async fetchOpenOrder(id, symbol = undefined, params = {}) {
1981
+ if (symbol === undefined) {
1982
+ throw new ArgumentsRequired(this.id + ' fetchOpenOrder() requires a symbol argument');
1983
+ }
1984
+ await this.loadMarkets();
1985
+ const market = this.market(symbol);
1986
+ const request = {
1987
+ 'symbol': market['id'],
1988
+ };
1989
+ const clientOrderId = this.safeString2(params, 'clientOrderId', 'clientOid');
1990
+ params = this.omit(params, ['clientOrderId', 'clientOid']);
1991
+ if (clientOrderId !== undefined) {
1992
+ request['origClientOrderId'] = clientOrderId;
1993
+ }
1994
+ else {
1995
+ request['orderId'] = id;
1996
+ }
1997
+ const response = await this.fapiPrivateGetV1OpenOrder(this.extend(request, params));
1998
+ return this.parseOrder(response, market);
1999
+ }
2000
+ /**
2001
+ * @method
2002
+ * @name aster#fetchOrders
2003
+ * @description fetches information on multiple orders made by the user
2004
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#query-all-orders-user_data
2005
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#all-orders-user_data
2006
+ * @param {string} symbol unified market symbol of the market orders were made in
2007
+ * @param {int} [since] the earliest time in ms to fetch orders for
2008
+ * @param {int} [limit] the maximum number of order structures to retrieve
2009
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2010
+ * @param {int} [params.until] the latest time in ms to fetch orders for
2011
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2012
+ */
2013
+ async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2014
+ await this.loadMarkets();
2015
+ if (symbol === undefined) {
2016
+ throw new ArgumentsRequired(this.id + ' fetchOrders() requires a symbol argument');
2017
+ }
2018
+ const market = this.market(symbol);
2019
+ let request = {
2020
+ 'symbol': market['id'],
2021
+ };
2022
+ if (since !== undefined) {
2023
+ request['startTime'] = since;
2024
+ }
2025
+ if (limit !== undefined) {
2026
+ if (limit > 1000) {
2027
+ limit = 1000; // Default 500; max 1000
2028
+ }
2029
+ request['limit'] = limit;
2030
+ }
2031
+ [request, params] = this.handleUntilOption('endTime', request, params);
2032
+ let response = undefined;
2033
+ if (market['swap']) {
2034
+ response = await this.fapiPrivateGetV1AllOrders(this.extend(request, params));
2035
+ }
2036
+ else {
2037
+ response = await this.sapiPrivateGetV1AllOrders(this.extend(request, params));
2038
+ }
2039
+ return this.parseOrders(response, market, since, limit);
2040
+ }
2041
+ /**
2042
+ * @method
2043
+ * @name aster#fetchOpenOrders
2044
+ * @description fetch all unfilled currently open orders
2045
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#current-open-orders-user_data
2046
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#current-all-open-orders-user_data
2047
+ * @param {string} symbol unified market symbol
2048
+ * @param {int} [since] the earliest time in ms to fetch open orders for
2049
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
2050
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2051
+ * @param {string} [params.subType] "linear" or "inverse"
2052
+ * @param {string} [params.type] 'spot', 'option', use params["subType"] for swap and future markets
2053
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2054
+ */
2055
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2056
+ await this.loadMarkets();
2057
+ const request = {};
2058
+ let market = undefined;
2059
+ let type = undefined;
2060
+ let subType = undefined;
2061
+ [subType, params] = this.handleSubTypeAndParams('fetchOpenOrders', market, params);
2062
+ if (symbol !== undefined) {
2063
+ market = this.market(symbol);
2064
+ request['symbol'] = market['id'];
2065
+ }
2066
+ [type, params] = this.handleMarketTypeAndParams('fetchOpenOrders', market, params);
2067
+ let response = undefined;
2068
+ if (this.isLinear(type, subType)) {
2069
+ response = await this.fapiPrivateGetV1OpenOrders(this.extend(request, params));
2070
+ }
2071
+ else if (type === 'spot') {
2072
+ response = await this.sapiPrivateGetV1OpenOrders(this.extend(request, params));
2073
+ }
2074
+ else {
2075
+ throw new NotSupported(this.id + ' fetchOpenOrders() does not support ' + type + ' markets yet');
2076
+ }
2077
+ //
2078
+ // [
2079
+ // {
2080
+ // "avgPrice": "0.00000",
2081
+ // "clientOrderId": "abc",
2082
+ // "cumQuote": "0",
2083
+ // "executedQty": "0",
2084
+ // "orderId": 1917641,
2085
+ // "origQty": "0.40",
2086
+ // "origType": "TRAILING_STOP_MARKET",
2087
+ // "price": "0",
2088
+ // "reduceOnly": false,
2089
+ // "side": "BUY",
2090
+ // "positionSide": "SHORT",
2091
+ // "status": "NEW",
2092
+ // "stopPrice": "9300",
2093
+ // "closePosition": false,
2094
+ // "symbol": "BTCUSDT",
2095
+ // "time": 1579276756075,
2096
+ // "timeInForce": "GTC",
2097
+ // "type": "TRAILING_STOP_MARKET",
2098
+ // "activatePrice": "9020",
2099
+ // "priceRate": "0.3",
2100
+ // "updateTime": 1579276756075,
2101
+ // "workingType": "CONTRACT_PRICE",
2102
+ // "priceProtect": false
2103
+ // }
2104
+ // ]
2105
+ //
2106
+ return this.parseOrders(response, market, since, limit);
2107
+ }
2108
+ /**
2109
+ * @method
2110
+ * @name aster#createOrder
2111
+ * @description create a trade order
2112
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#place-order-trade
2113
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#new-order--trade
2114
+ * @param {string} symbol unified symbol of the market to create an order in
2115
+ * @param {string} type 'market' or 'limit' or 'STOP' or 'STOP_MARKET' or 'TAKE_PROFIT' or 'TAKE_PROFIT_MARKET' or 'TRAILING_STOP_MARKET'
2116
+ * @param {string} side 'buy' or 'sell'
2117
+ * @param {float} amount how much of you want to trade in units of the base currency
2118
+ * @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
2119
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2120
+ * @param {string} [params.reduceOnly] for swap and future reduceOnly is a string 'true' or 'false' that cant be sent with close position set to true or in hedge mode. For spot margin and option reduceOnly is a boolean.
2121
+ * @param {boolean} [params.test] whether to use the test endpoint or not, default is false
2122
+ * @param {float} [params.trailingPercent] the percent to trail away from the current market price
2123
+ * @param {float} [params.trailingTriggerPrice] the price to trigger a trailing order, default uses the price argument
2124
+ * @param {string} [params.positionSide] "BOTH" for one-way mode, "LONG" for buy side of hedged mode, "SHORT" for sell side of hedged mode
2125
+ * @param {float} [params.triggerPrice] the price that a trigger order is triggered at
2126
+ * @param {float} [params.stopLossPrice] the price that a stop loss order is triggered at
2127
+ * @param {float} [params.takeProfitPrice] the price that a take profit order is triggered at
2128
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2129
+ */
2130
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
2131
+ await this.loadMarkets();
2132
+ const market = this.market(symbol);
2133
+ const test = this.safeBool(params, 'test', false);
2134
+ params = this.omit(params, 'test');
2135
+ const request = this.createOrderRequest(symbol, type, side, amount, price, params);
2136
+ let response = undefined;
2137
+ if (market['swap']) {
2138
+ if (test) {
2139
+ response = await this.fapiPrivatePostV1OrderTest(request);
2140
+ }
2141
+ else {
2142
+ response = await this.fapiPrivatePostV1Order(request);
2143
+ }
2144
+ }
2145
+ else {
2146
+ response = await this.sapiPrivatePostV1Order(request);
2147
+ }
2148
+ return this.parseOrder(response, market);
2149
+ }
2150
+ /**
2151
+ * @method
2152
+ * @name aster#createOrders
2153
+ * @description create a list of trade orders
2154
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#place-multiple-orders--trade
2155
+ * @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
2156
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2157
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2158
+ */
2159
+ async createOrders(orders, params = {}) {
2160
+ await this.loadMarkets();
2161
+ const ordersRequests = [];
2162
+ let orderSymbols = [];
2163
+ if (orders.length > 5) {
2164
+ throw new InvalidOrder(this.id + ' createOrders() order list max 5 orders');
2165
+ }
2166
+ for (let i = 0; i < orders.length; i++) {
2167
+ const rawOrder = orders[i];
2168
+ const marketId = this.safeString(rawOrder, 'symbol');
2169
+ const type = this.safeString(rawOrder, 'type');
2170
+ const side = this.safeString(rawOrder, 'side');
2171
+ const amount = this.safeValue(rawOrder, 'amount');
2172
+ const price = this.safeValue(rawOrder, 'price');
2173
+ const orderParams = this.safeDict(rawOrder, 'params', {});
2174
+ const orderRequest = this.createOrderRequest(marketId, type, side, amount, price, orderParams);
2175
+ ordersRequests.push(orderRequest);
2176
+ }
2177
+ orderSymbols = this.marketSymbols(orderSymbols, undefined, false, true, true);
2178
+ const market = this.market(orderSymbols[0]);
2179
+ if (market['spot']) {
2180
+ throw new NotSupported(this.id + ' createOrders() does not support ' + market['type'] + ' orders');
2181
+ }
2182
+ const request = {
2183
+ 'batchOrders': ordersRequests,
2184
+ };
2185
+ const response = await this.fapiPrivatePostV1BatchOrders(this.extend(request, params));
2186
+ return this.parseOrders(response);
2187
+ }
2188
+ createOrderRequest(symbol, type, side, amount, price = undefined, params = {}) {
2189
+ /**
2190
+ * @method
2191
+ * @ignore
2192
+ * @name aster#createOrderRequest
2193
+ * @description helper function to build the request
2194
+ * @param {string} symbol unified symbol of the market to create an order in
2195
+ * @param {string} type 'market' or 'limit'
2196
+ * @param {string} side 'buy' or 'sell'
2197
+ * @param {float} amount how much you want to trade in units of the base currency
2198
+ * @param {float} [price] the price that the order is to be fulfilled, in units of the quote currency, ignored in market orders
2199
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2200
+ * @returns {object} request to be sent to the exchange
2201
+ */
2202
+ const market = this.market(symbol);
2203
+ const initialUppercaseType = type.toUpperCase();
2204
+ const isMarketOrder = initialUppercaseType === 'MARKET';
2205
+ const isLimitOrder = initialUppercaseType === 'LIMIT';
2206
+ const request = {
2207
+ 'symbol': market['id'],
2208
+ 'side': side.toUpperCase(),
2209
+ };
2210
+ const clientOrderId = this.safeString2(params, 'newClientOrderId', 'clientOrderId');
2211
+ if (clientOrderId !== undefined) {
2212
+ request['newClientOrderId'] = clientOrderId;
2213
+ }
2214
+ const triggerPrice = this.safeString2(params, 'triggerPrice', 'stopPrice');
2215
+ const stopLossPrice = this.safeString(params, 'stopLossPrice', triggerPrice);
2216
+ const takeProfitPrice = this.safeString(params, 'takeProfitPrice');
2217
+ const trailingDelta = this.safeString(params, 'trailingDelta');
2218
+ const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activationPrice');
2219
+ const trailingPercent = this.safeStringN(params, ['trailingPercent', 'callbackRate', 'trailingDelta']);
2220
+ const isTrailingPercentOrder = trailingPercent !== undefined;
2221
+ const isStopLoss = stopLossPrice !== undefined || trailingDelta !== undefined;
2222
+ const isTakeProfit = takeProfitPrice !== undefined;
2223
+ let uppercaseType = initialUppercaseType;
2224
+ let stopPrice = undefined;
2225
+ if (isTrailingPercentOrder) {
2226
+ if (market['swap']) {
2227
+ uppercaseType = 'TRAILING_STOP_MARKET';
2228
+ request['callbackRate'] = trailingPercent;
2229
+ if (trailingTriggerPrice !== undefined) {
2230
+ request['activationPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
2231
+ }
2232
+ }
2233
+ }
2234
+ else if (isStopLoss) {
2235
+ stopPrice = stopLossPrice;
2236
+ if (isMarketOrder) {
2237
+ uppercaseType = 'STOP_MARKET';
2238
+ }
2239
+ else if (isLimitOrder) {
2240
+ uppercaseType = 'STOP';
2241
+ }
2242
+ }
2243
+ else if (isTakeProfit) {
2244
+ stopPrice = takeProfitPrice;
2245
+ if (isMarketOrder) {
2246
+ uppercaseType = 'TAKE_PROFIT_MARKET';
2247
+ }
2248
+ else if (isLimitOrder) {
2249
+ uppercaseType = 'TAKE_PROFIT';
2250
+ }
2251
+ }
2252
+ const postOnly = this.isPostOnly(isMarketOrder, undefined, params);
2253
+ if (postOnly) {
2254
+ request['timeInForce'] = 'GTX';
2255
+ }
2256
+ //
2257
+ // spot
2258
+ // LIMIT timeInForce, quantity, price
2259
+ // MARKET quantity or quoteOrderQty
2260
+ // STOP and TAKE_PROFIT quantity, price, stopPrice
2261
+ // STOP_MARKET and TAKE_PROFIT_MARKET quantity, stopPrice
2262
+ // future
2263
+ // LIMIT timeInForce, quantity, price
2264
+ // MARKET quantity
2265
+ // STOP/TAKE_PROFIT quantity, price, stopPrice
2266
+ // STOP_MARKET/TAKE_PROFIT_MARKET stopPrice
2267
+ // TRAILING_STOP_MARKET callbackRate
2268
+ //
2269
+ // additional required fields depending on the order type
2270
+ const closePosition = this.safeBool(params, 'closePosition', false);
2271
+ let timeInForceIsRequired = false;
2272
+ let priceIsRequired = false;
2273
+ let triggerPriceIsRequired = false;
2274
+ let quantityIsRequired = false;
2275
+ request['type'] = uppercaseType;
2276
+ if (uppercaseType === 'MARKET') {
2277
+ if (market['spot']) {
2278
+ const quoteOrderQty = this.safeBool(this.options, 'quoteOrderQty', true);
2279
+ if (quoteOrderQty) {
2280
+ const quoteOrderQtyNew = this.safeString2(params, 'quoteOrderQty', 'cost');
2281
+ const precision = market['precision']['price'];
2282
+ if (quoteOrderQtyNew !== undefined) {
2283
+ request['quoteOrderQty'] = this.decimalToPrecision(quoteOrderQtyNew, TRUNCATE, precision, this.precisionMode);
2284
+ }
2285
+ else if (price !== undefined) {
2286
+ const amountString = this.numberToString(amount);
2287
+ const priceString = this.numberToString(price);
2288
+ const quoteOrderQuantity = Precise.stringMul(amountString, priceString);
2289
+ request['quoteOrderQty'] = this.decimalToPrecision(quoteOrderQuantity, TRUNCATE, precision, this.precisionMode);
2290
+ }
2291
+ else {
2292
+ quantityIsRequired = true;
2293
+ }
2294
+ }
2295
+ else {
2296
+ quantityIsRequired = true;
2297
+ }
2298
+ }
2299
+ else {
2300
+ quantityIsRequired = true;
2301
+ }
2302
+ }
2303
+ else if (uppercaseType === 'LIMIT') {
2304
+ timeInForceIsRequired = true;
2305
+ quantityIsRequired = true;
2306
+ priceIsRequired = true;
2307
+ }
2308
+ else if ((uppercaseType === 'STOP') || (uppercaseType === 'TAKE_PROFIT')) {
2309
+ quantityIsRequired = true;
2310
+ priceIsRequired = true;
2311
+ triggerPriceIsRequired = true;
2312
+ }
2313
+ else if ((uppercaseType === 'STOP_MARKET') || (uppercaseType === 'TAKE_PROFIT_MARKET')) {
2314
+ if (!closePosition) {
2315
+ quantityIsRequired = true;
2316
+ }
2317
+ triggerPriceIsRequired = true;
2318
+ }
2319
+ else if (uppercaseType === 'TRAILING_STOP_MARKET') {
2320
+ request['callbackRate'] = trailingPercent;
2321
+ if (trailingTriggerPrice !== undefined) {
2322
+ request['activationPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
2323
+ }
2324
+ }
2325
+ if (quantityIsRequired) {
2326
+ const marketAmountPrecision = this.safeString(market['precision'], 'amount');
2327
+ const isPrecisionAvailable = (marketAmountPrecision !== undefined);
2328
+ if (isPrecisionAvailable) {
2329
+ request['quantity'] = this.amountToPrecision(symbol, amount);
2330
+ }
2331
+ else {
2332
+ request['quantity'] = this.parseToNumeric(amount);
2333
+ }
2334
+ }
2335
+ if (priceIsRequired) {
2336
+ if (price === undefined) {
2337
+ throw new InvalidOrder(this.id + ' createOrder() requires a price argument for a ' + type + ' order');
2338
+ }
2339
+ const pricePrecision = this.safeString(market['precision'], 'price');
2340
+ const isPricePrecisionAvailable = (pricePrecision !== undefined);
2341
+ if (isPricePrecisionAvailable) {
2342
+ request['price'] = this.priceToPrecision(symbol, price);
2343
+ }
2344
+ else {
2345
+ request['price'] = this.parseToNumeric(price);
2346
+ }
2347
+ }
2348
+ if (triggerPriceIsRequired) {
2349
+ if (stopPrice === undefined) {
2350
+ throw new InvalidOrder(this.id + ' createOrder() requires a stopPrice extra param for a ' + type + ' order');
2351
+ }
2352
+ if (stopPrice !== undefined) {
2353
+ request['stopPrice'] = this.priceToPrecision(symbol, stopPrice);
2354
+ }
2355
+ }
2356
+ if (timeInForceIsRequired && (this.safeString(params, 'timeInForce') === undefined) && (this.safeString(request, 'timeInForce') === undefined)) {
2357
+ request['timeInForce'] = this.safeString(this.options, 'defaultTimeInForce'); // 'GTC' = Good To Cancel (default), 'IOC' = Immediate Or Cancel
2358
+ }
2359
+ const requestParams = this.omit(params, ['newClientOrderId', 'clientOrderId', 'stopPrice', 'triggerPrice', 'trailingTriggerPrice', 'trailingPercent', 'trailingDelta', 'stopPrice', 'stopLossPrice', 'takeProfitPrice']);
2360
+ return this.extend(request, requestParams);
2361
+ }
2362
+ /**
2363
+ * @method
2364
+ * @name aster#cancelAllOrders
2365
+ * @description cancel all open orders in a market
2366
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#cancel-all-open-orders-trade
2367
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#cancel-all-open-orders-trade
2368
+ * @param {string} symbol unified market symbol of the market to cancel orders in
2369
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2370
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2371
+ */
2372
+ async cancelAllOrders(symbol = undefined, params = {}) {
2373
+ if (symbol === undefined) {
2374
+ throw new ArgumentsRequired(this.id + ' cancelAllOrders() requires a symbol argument');
2375
+ }
2376
+ await this.loadMarkets();
2377
+ const market = this.market(symbol);
2378
+ const request = {
2379
+ 'symbol': market['id'],
2380
+ };
2381
+ let response = undefined;
2382
+ if (market['swap']) {
2383
+ response = await this.fapiPrivateDeleteV1AllOpenOrders(this.extend(request, params));
2384
+ }
2385
+ else {
2386
+ response = await this.sapiPrivateDeleteV1AllOpenOrders(this.extend(request, params));
2387
+ }
2388
+ //
2389
+ // {
2390
+ // "code": "200",
2391
+ // "msg": "The operation of cancel all open order is done."
2392
+ // }
2393
+ //
2394
+ return [
2395
+ this.safeOrder({
2396
+ 'info': response,
2397
+ }),
2398
+ ];
2399
+ }
2400
+ /**
2401
+ * @method
2402
+ * @name aster#cancelOrder
2403
+ * @description cancels an open order
2404
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#cancel-order-trade
2405
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#cancel-order-trade
2406
+ * @param {string} id order id
2407
+ * @param {string} symbol unified symbol of the market the order was made in
2408
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2409
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
2410
+ */
2411
+ async cancelOrder(id, symbol = undefined, params = {}) {
2412
+ if (symbol === undefined) {
2413
+ throw new ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
2414
+ }
2415
+ await this.loadMarkets();
2416
+ const market = this.market(symbol);
2417
+ const request = {
2418
+ 'symbol': market['id'],
2419
+ };
2420
+ const clientOrderId = this.safeStringN(params, ['origClientOrderId', 'clientOrderId', 'newClientStrategyId']);
2421
+ if (clientOrderId !== undefined) {
2422
+ request['origClientOrderId'] = clientOrderId;
2423
+ }
2424
+ else {
2425
+ request['orderId'] = id;
2426
+ }
2427
+ params = this.omit(params, ['origClientOrderId', 'clientOrderId', 'newClientStrategyId']);
2428
+ let response = undefined;
2429
+ if (market['swap']) {
2430
+ response = await this.fapiPrivateDeleteV1Order(this.extend(request, params));
2431
+ }
2432
+ else {
2433
+ response = await this.sapiPrivateDeleteV1Order(this.extend(request, params));
2434
+ }
2435
+ return this.parseOrder(response, market);
2436
+ }
2437
+ /**
2438
+ * @method
2439
+ * @name aster#cancelOrders
2440
+ * @description cancel multiple orders
2441
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#cancel-multiple-orders-trade
2442
+ * @param {string[]} ids order ids
2443
+ * @param {string} [symbol] unified market symbol
2444
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2445
+ *
2446
+ * EXCHANGE SPECIFIC PARAMETERS
2447
+ * @param {string[]} [params.origClientOrderIdList] max length 10 e.g. ["my_id_1","my_id_2"], encode the double quotes. No space after comma
2448
+ * @param {int[]} [params.recvWindow]
2449
+ * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
2450
+ */
2451
+ async cancelOrders(ids, symbol = undefined, params = {}) {
2452
+ if (symbol === undefined) {
2453
+ throw new ArgumentsRequired(this.id + ' cancelOrders() requires a symbol argument');
2454
+ }
2455
+ await this.loadMarkets();
2456
+ const market = this.market(symbol);
2457
+ if (market['spot']) {
2458
+ throw new NotSupported(this.id + ' cancelOrders() does not support ' + market['type'] + ' orders');
2459
+ }
2460
+ const request = {
2461
+ 'symbol': market['id'],
2462
+ };
2463
+ const clientOrderIdList = this.safeList(params, 'origClientOrderIdList');
2464
+ if (clientOrderIdList !== undefined) {
2465
+ request['origClientOrderIdList'] = clientOrderIdList;
2466
+ }
2467
+ else {
2468
+ request['orderIdList'] = ids;
2469
+ }
2470
+ const response = await this.fapiPrivateDeleteV1BatchOrders(this.extend(request, params));
2471
+ //
2472
+ // [
2473
+ // {
2474
+ // "clientOrderId": "myOrder1",
2475
+ // "cumQty": "0",
2476
+ // "cumQuote": "0",
2477
+ // "executedQty": "0",
2478
+ // "orderId": 283194212,
2479
+ // "origQty": "11",
2480
+ // "origType": "TRAILING_STOP_MARKET",
2481
+ // "price": "0",
2482
+ // "reduceOnly": false,
2483
+ // "side": "BUY",
2484
+ // "positionSide": "SHORT",
2485
+ // "status": "CANCELED",
2486
+ // "stopPrice": "9300", // please ignore when order type is TRAILING_STOP_MARKET
2487
+ // "closePosition": false, // if Close-All
2488
+ // "symbol": "BTCUSDT",
2489
+ // "timeInForce": "GTC",
2490
+ // "type": "TRAILING_STOP_MARKET",
2491
+ // "activatePrice": "9020", // activation price, only return with TRAILING_STOP_MARKET order
2492
+ // "priceRate": "0.3", // callback rate, only return with TRAILING_STOP_MARKET order
2493
+ // "updateTime": 1571110484038,
2494
+ // "workingType": "CONTRACT_PRICE",
2495
+ // "priceProtect": false, // if conditional order trigger is protected
2496
+ // },
2497
+ // {
2498
+ // "code": -2011,
2499
+ // "msg": "Unknown order sent."
2500
+ // }
2501
+ // ]
2502
+ //
2503
+ return this.parseOrders(response, market);
2504
+ }
2505
+ /**
2506
+ * @method
2507
+ * @name aster#setLeverage
2508
+ * @description set the level of leverage for a market
2509
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#change-initial-leverage-trade
2510
+ * @param {float} leverage the rate of leverage
2511
+ * @param {string} symbol unified market symbol
2512
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2513
+ * @returns {object} response from the exchange
2514
+ */
2515
+ async setLeverage(leverage, symbol = undefined, params = {}) {
2516
+ if (symbol === undefined) {
2517
+ throw new ArgumentsRequired(this.id + ' setLeverage() requires a symbol argument');
2518
+ }
2519
+ if ((leverage < 1) || (leverage > 125)) {
2520
+ throw new BadRequest(this.id + ' leverage should be between 1 and 125');
2521
+ }
2522
+ await this.loadMarkets();
2523
+ const market = this.market(symbol);
2524
+ const request = {
2525
+ 'symbol': market['id'],
2526
+ 'leverage': leverage,
2527
+ };
2528
+ const response = await this.fapiPrivatePostV1Leverage(this.extend(request, params));
2529
+ //
2530
+ // {
2531
+ // "leverage": 21,
2532
+ // "maxNotionalValue": "1000000",
2533
+ // "symbol": "BTCUSDT"
2534
+ // }
2535
+ //
2536
+ return response;
2537
+ }
2538
+ /**
2539
+ * @method
2540
+ * @name aster#fetchLeverages
2541
+ * @description fetch the set leverage for all markets
2542
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data
2543
+ * @param {string[]} [symbols] a list of unified market symbols
2544
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2545
+ * @returns {object} a list of [leverage structures]{@link https://docs.ccxt.com/#/?id=leverage-structure}
2546
+ */
2547
+ async fetchLeverages(symbols = undefined, params = {}) {
2548
+ await this.loadMarkets();
2549
+ const response = await this.fapiPrivateGetV2PositionRisk(params);
2550
+ //
2551
+ // [
2552
+ // {
2553
+ // "symbol": "INJUSDT",
2554
+ // "positionAmt": "0.0",
2555
+ // "entryPrice": "0.0",
2556
+ // "markPrice": "0.00000000",
2557
+ // "unRealizedProfit": "0.00000000",
2558
+ // "liquidationPrice": "0",
2559
+ // "leverage": "20",
2560
+ // "maxNotionalValue": "25000",
2561
+ // "marginType": "cross",
2562
+ // "isolatedMargin": "0.00000000",
2563
+ // "isAutoAddMargin": "false",
2564
+ // "positionSide": "BOTH",
2565
+ // "notional": "0",
2566
+ // "isolatedWallet": "0",
2567
+ // "updateTime": 0
2568
+ // }
2569
+ // ]
2570
+ //
2571
+ return this.parseLeverages(response, symbols, 'symbol');
2572
+ }
2573
+ parseLeverage(leverage, market = undefined) {
2574
+ //
2575
+ // {
2576
+ // "symbol": "INJUSDT",
2577
+ // "positionAmt": "0.0",
2578
+ // "entryPrice": "0.0",
2579
+ // "markPrice": "0.00000000",
2580
+ // "unRealizedProfit": "0.00000000",
2581
+ // "liquidationPrice": "0",
2582
+ // "leverage": "20",
2583
+ // "maxNotionalValue": "25000",
2584
+ // "marginType": "cross",
2585
+ // "isolatedMargin": "0.00000000",
2586
+ // "isAutoAddMargin": "false",
2587
+ // "positionSide": "BOTH",
2588
+ // "notional": "0",
2589
+ // "isolatedWallet": "0",
2590
+ // "updateTime": 0
2591
+ // }
2592
+ //
2593
+ const marketId = this.safeString(leverage, 'symbol');
2594
+ const marginMode = this.safeStringLower(leverage, 'marginType');
2595
+ const side = this.safeStringLower(leverage, 'positionSide');
2596
+ let longLeverage = undefined;
2597
+ let shortLeverage = undefined;
2598
+ const leverageValue = this.safeInteger(leverage, 'leverage');
2599
+ if ((side === undefined) || (side === 'both')) {
2600
+ longLeverage = leverageValue;
2601
+ shortLeverage = leverageValue;
2602
+ }
2603
+ else if (side === 'long') {
2604
+ longLeverage = leverageValue;
2605
+ }
2606
+ else if (side === 'short') {
2607
+ shortLeverage = leverageValue;
2608
+ }
2609
+ return {
2610
+ 'info': leverage,
2611
+ 'symbol': this.safeSymbol(marketId, market),
2612
+ 'marginMode': marginMode,
2613
+ 'longLeverage': longLeverage,
2614
+ 'shortLeverage': shortLeverage,
2615
+ };
2616
+ }
2617
+ /**
2618
+ * @method
2619
+ * @name aster#fetchMarginModes
2620
+ * @description fetches margin mode of the user
2621
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data
2622
+ * @param {string[]} symbols unified market symbols
2623
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2624
+ * @returns {object} a list of [margin mode structures]{@link https://docs.ccxt.com/#/?id=margin-mode-structure}
2625
+ */
2626
+ async fetchMarginModes(symbols = undefined, params = {}) {
2627
+ await this.loadMarkets();
2628
+ const response = await this.fapiPrivateGetV2PositionRisk(params);
2629
+ //
2630
+ //
2631
+ // [
2632
+ // {
2633
+ // "symbol": "INJUSDT",
2634
+ // "positionAmt": "0.0",
2635
+ // "entryPrice": "0.0",
2636
+ // "markPrice": "0.00000000",
2637
+ // "unRealizedProfit": "0.00000000",
2638
+ // "liquidationPrice": "0",
2639
+ // "leverage": "20",
2640
+ // "maxNotionalValue": "25000",
2641
+ // "marginType": "cross",
2642
+ // "isolatedMargin": "0.00000000",
2643
+ // "isAutoAddMargin": "false",
2644
+ // "positionSide": "BOTH",
2645
+ // "notional": "0",
2646
+ // "isolatedWallet": "0",
2647
+ // "updateTime": 0
2648
+ // }
2649
+ // ]
2650
+ //
2651
+ //
2652
+ return this.parseMarginModes(response, symbols, 'symbol', 'swap');
2653
+ }
2654
+ parseMarginMode(marginMode, market = undefined) {
2655
+ //
2656
+ // {
2657
+ // "symbol": "INJUSDT",
2658
+ // "positionAmt": "0.0",
2659
+ // "entryPrice": "0.0",
2660
+ // "markPrice": "0.00000000",
2661
+ // "unRealizedProfit": "0.00000000",
2662
+ // "liquidationPrice": "0",
2663
+ // "leverage": "20",
2664
+ // "maxNotionalValue": "25000",
2665
+ // "marginType": "cross",
2666
+ // "isolatedMargin": "0.00000000",
2667
+ // "isAutoAddMargin": "false",
2668
+ // "positionSide": "BOTH",
2669
+ // "notional": "0",
2670
+ // "isolatedWallet": "0",
2671
+ // "updateTime": 0
2672
+ // }
2673
+ //
2674
+ const marketId = this.safeString(marginMode, 'symbol');
2675
+ market = this.safeMarket(marketId, market);
2676
+ return {
2677
+ 'info': marginMode,
2678
+ 'symbol': market['symbol'],
2679
+ 'marginMode': this.safeStringLower(marginMode, 'marginType'),
2680
+ };
2681
+ }
2682
+ /**
2683
+ * @method
2684
+ * @name aster#fetchMarginAdjustmentHistory
2685
+ * @description fetches the history of margin added or reduced from contract isolated positions
2686
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-position-margin-change-history-trade
2687
+ * @param {string} symbol unified market symbol
2688
+ * @param {string} [type] "add" or "reduce"
2689
+ * @param {int} [since] timestamp in ms of the earliest change to fetch
2690
+ * @param {int} [limit] the maximum amount of changes to fetch
2691
+ * @param {object} params extra parameters specific to the exchange api endpoint
2692
+ * @param {int} [params.until] timestamp in ms of the latest change to fetch
2693
+ * @returns {object[]} a list of [margin structures]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
2694
+ */
2695
+ async fetchMarginAdjustmentHistory(symbol = undefined, type = undefined, since = undefined, limit = undefined, params = {}) {
2696
+ await this.loadMarkets();
2697
+ if (symbol === undefined) {
2698
+ throw new ArgumentsRequired(this.id + ' fetchMarginAdjustmentHistory () requires a symbol argument');
2699
+ }
2700
+ const market = this.market(symbol);
2701
+ const until = this.safeInteger(params, 'until');
2702
+ params = this.omit(params, 'until');
2703
+ const request = {
2704
+ 'symbol': market['id'],
2705
+ };
2706
+ if (type !== undefined) {
2707
+ request['type'] = (type === 'add') ? 1 : 2;
2708
+ }
2709
+ if (since !== undefined) {
2710
+ request['startTime'] = since;
2711
+ }
2712
+ if (limit !== undefined) {
2713
+ request['limit'] = limit;
2714
+ }
2715
+ if (until !== undefined) {
2716
+ request['endTime'] = until;
2717
+ }
2718
+ const response = await this.fapiPrivateGetV1PositionMarginHistory(this.extend(request, params));
2719
+ //
2720
+ // [
2721
+ // {
2722
+ // "amount": "23.36332311",
2723
+ // "asset": "USDT",
2724
+ // "symbol": "BTCUSDT",
2725
+ // "time": 1578047897183,
2726
+ // "type": 1,
2727
+ // "positionSide": "BOTH"
2728
+ // }
2729
+ // ]
2730
+ //
2731
+ const modifications = this.parseMarginModifications(response);
2732
+ return this.filterBySymbolSinceLimit(modifications, symbol, since, limit);
2733
+ }
2734
+ parseMarginModification(data, market = undefined) {
2735
+ //
2736
+ // {
2737
+ // "amount": "100",
2738
+ // "asset": "USDT",
2739
+ // "symbol": "BTCUSDT",
2740
+ // "time": 1578047900425,
2741
+ // "type": 1,
2742
+ // "positionSide": "LONG"
2743
+ // }
2744
+ //
2745
+ // {
2746
+ // "amount": 100.0,
2747
+ // "code": 200,
2748
+ // "msg": "Successfully modify position margin.",
2749
+ // "type": 1
2750
+ // }
2751
+ //
2752
+ const rawType = this.safeInteger(data, 'type');
2753
+ const errorCode = this.safeString(data, 'code');
2754
+ const marketId = this.safeString(data, 'symbol');
2755
+ const timestamp = this.safeInteger(data, 'time');
2756
+ market = this.safeMarket(marketId, market, undefined, 'swap');
2757
+ const noErrorCode = errorCode === undefined;
2758
+ const success = errorCode === '200';
2759
+ return {
2760
+ 'info': data,
2761
+ 'symbol': market['symbol'],
2762
+ 'type': (rawType === 1) ? 'add' : 'reduce',
2763
+ 'marginMode': 'isolated',
2764
+ 'amount': this.safeNumber(data, 'amount'),
2765
+ 'code': this.safeString(data, 'asset'),
2766
+ 'total': undefined,
2767
+ 'status': (success || noErrorCode) ? 'ok' : 'failed',
2768
+ 'timestamp': timestamp,
2769
+ 'datetime': this.iso8601(timestamp),
2770
+ };
2771
+ }
2772
+ async modifyMarginHelper(symbol, amount, addOrReduce, params = {}) {
2773
+ await this.loadMarkets();
2774
+ const market = this.market(symbol);
2775
+ amount = this.amountToPrecision(symbol, amount);
2776
+ const request = {
2777
+ 'type': addOrReduce,
2778
+ 'symbol': market['id'],
2779
+ 'amount': amount,
2780
+ };
2781
+ const code = market['quote'];
2782
+ const response = await this.fapiPrivatePostV1PositionMargin(this.extend(request, params));
2783
+ //
2784
+ // {
2785
+ // "amount": 100.0,
2786
+ // "code": 200,
2787
+ // "msg": "Successfully modify position margin.",
2788
+ // "type": 1
2789
+ // }
2790
+ //
2791
+ return this.extend(this.parseMarginModification(response, market), {
2792
+ 'code': code,
2793
+ });
2794
+ }
2795
+ /**
2796
+ * @method
2797
+ * @name aster#reduceMargin
2798
+ * @description remove margin from a position
2799
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#modify-isolated-position-margin-trade
2800
+ * @param {string} symbol unified market symbol
2801
+ * @param {float} amount the amount of margin to remove
2802
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2803
+ * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=reduce-margin-structure}
2804
+ */
2805
+ async reduceMargin(symbol, amount, params = {}) {
2806
+ return await this.modifyMarginHelper(symbol, amount, 2, params);
2807
+ }
2808
+ /**
2809
+ * @method
2810
+ * @name aster#addMargin
2811
+ * @description add margin
2812
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#modify-isolated-position-margin-trade
2813
+ * @param {string} symbol unified market symbol
2814
+ * @param {float} amount amount of margin to add
2815
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2816
+ * @returns {object} a [margin structure]{@link https://docs.ccxt.com/#/?id=add-margin-structure}
2817
+ */
2818
+ async addMargin(symbol, amount, params = {}) {
2819
+ return await this.modifyMarginHelper(symbol, amount, 1, params);
2820
+ }
2821
+ parseIncome(income, market = undefined) {
2822
+ //
2823
+ // {
2824
+ // "symbol": "ETHUSDT",
2825
+ // "incomeType": "FUNDING_FEE",
2826
+ // "income": "0.00134317",
2827
+ // "asset": "USDT",
2828
+ // "time": "1621584000000",
2829
+ // "info": "FUNDING_FEE",
2830
+ // "tranId": "4480321991774044580",
2831
+ // "tradeId": ""
2832
+ // }
2833
+ //
2834
+ const marketId = this.safeString(income, 'symbol');
2835
+ const currencyId = this.safeString(income, 'asset');
2836
+ const timestamp = this.safeInteger(income, 'time');
2837
+ return {
2838
+ 'info': income,
2839
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'swap'),
2840
+ 'code': this.safeCurrencyCode(currencyId),
2841
+ 'timestamp': timestamp,
2842
+ 'datetime': this.iso8601(timestamp),
2843
+ 'id': this.safeString(income, 'tranId'),
2844
+ 'amount': this.safeNumber(income, 'income'),
2845
+ };
2846
+ }
2847
+ /**
2848
+ * @method
2849
+ * @name aster#fetchFundingHistory
2850
+ * @description fetch the history of funding payments paid and received on this account
2851
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-income-historyuser_data
2852
+ * @param {string} symbol unified market symbol
2853
+ * @param {int} [since] the earliest time in ms to fetch funding history for
2854
+ * @param {int} [limit] the maximum number of funding history structures to retrieve
2855
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2856
+ * @param {int} [params.until] timestamp in ms of the latest funding history entry
2857
+ * @param {boolean} [params.portfolioMargin] set to true if you would like to fetch the funding history for a portfolio margin account
2858
+ * @param {string} [params.subType] "linear" or "inverse"
2859
+ * @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
2860
+ */
2861
+ async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2862
+ await this.loadMarkets();
2863
+ let market = undefined;
2864
+ let request = {
2865
+ 'incomeType': 'FUNDING_FEE', // "TRANSFER","WELCOME_BONUS", "REALIZED_PNL","FUNDING_FEE", "COMMISSION", "INSURANCE_CLEAR", and "MARKET_MERCHANT_RETURN_REWARD"
2866
+ };
2867
+ if (symbol !== undefined) {
2868
+ market = this.market(symbol);
2869
+ request['symbol'] = market['id'];
2870
+ }
2871
+ [request, params] = this.handleUntilOption('endTime', request, params);
2872
+ if (since !== undefined) {
2873
+ request['startTime'] = since;
2874
+ }
2875
+ if (limit !== undefined) {
2876
+ request['limit'] = Math.min(limit, 1000); // max 1000
2877
+ }
2878
+ const response = await this.fapiPrivateGetV1Income(this.extend(request, params));
2879
+ return this.parseIncomes(response, market, since, limit);
2880
+ }
2881
+ parseLedgerEntry(item, currency = undefined) {
2882
+ //
2883
+ // {
2884
+ // "symbol": "",
2885
+ // "incomeType": "TRANSFER",
2886
+ // "income": "10.00000000",
2887
+ // "asset": "USDT",
2888
+ // "time": 1677645250000,
2889
+ // "info": "TRANSFER",
2890
+ // "tranId": 131001573082,
2891
+ // "tradeId": ""
2892
+ // }
2893
+ //
2894
+ let amount = this.safeString(item, 'income');
2895
+ let direction = undefined;
2896
+ if (Precise.stringLe(amount, '0')) {
2897
+ direction = 'out';
2898
+ amount = Precise.stringMul('-1', amount);
2899
+ }
2900
+ else {
2901
+ direction = 'in';
2902
+ }
2903
+ const currencyId = this.safeString(item, 'asset');
2904
+ const code = this.safeCurrencyCode(currencyId, currency);
2905
+ currency = this.safeCurrency(currencyId, currency);
2906
+ const timestamp = this.safeInteger(item, 'time');
2907
+ const type = this.safeString(item, 'incomeType');
2908
+ return this.safeLedgerEntry({
2909
+ 'info': item,
2910
+ 'id': this.safeString(item, 'tranId'),
2911
+ 'direction': direction,
2912
+ 'account': undefined,
2913
+ 'referenceAccount': undefined,
2914
+ 'referenceId': this.safeString(item, 'tradeId'),
2915
+ 'type': this.parseLedgerEntryType(type),
2916
+ 'currency': code,
2917
+ 'amount': this.parseNumber(amount),
2918
+ 'timestamp': timestamp,
2919
+ 'datetime': this.iso8601(timestamp),
2920
+ 'before': undefined,
2921
+ 'after': undefined,
2922
+ 'status': undefined,
2923
+ 'fee': undefined,
2924
+ }, currency);
2925
+ }
2926
+ parseLedgerEntryType(type) {
2927
+ const ledgerType = {
2928
+ 'TRANSFER': 'transfer',
2929
+ 'WELCOME_BONUS': 'cashback',
2930
+ 'REALIZED_PNL': 'trade',
2931
+ 'FUNDING_FEE': 'fee',
2932
+ 'COMMISSION': 'commission',
2933
+ 'INSURANCE_CLEAR': 'settlement',
2934
+ 'MARKET_MERCHANT_RETURN_REWARD': 'cashback',
2935
+ };
2936
+ return this.safeString(ledgerType, type, type);
2937
+ }
2938
+ /**
2939
+ * @method
2940
+ * @name aster#fetchLedger
2941
+ * @description fetch the history of changes, actions done by the user or operations that altered the balance of the user
2942
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#get-income-historyuser_data
2943
+ * @param {string} [code] unified currency code
2944
+ * @param {int} [since] timestamp in ms of the earliest ledger entry
2945
+ * @param {int} [limit] max number of ledger entries to return
2946
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2947
+ * @param {int} [params.until] timestamp in ms of the latest ledger entry
2948
+ * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger}
2949
+ */
2950
+ async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
2951
+ await this.loadMarkets();
2952
+ let currency = undefined;
2953
+ if (code !== undefined) {
2954
+ currency = this.currency(code);
2955
+ }
2956
+ const request = {};
2957
+ if (since !== undefined) {
2958
+ request['startTime'] = since;
2959
+ }
2960
+ if (limit !== undefined) {
2961
+ request['limit'] = Math.min(limit, 1000); // max 1000
2962
+ }
2963
+ const until = this.safeInteger(params, 'until');
2964
+ if (until !== undefined) {
2965
+ params = this.omit(params, 'until');
2966
+ request['endTime'] = until;
2967
+ }
2968
+ const response = await this.fapiPrivateGetV1Income(this.extend(request, params));
2969
+ //
2970
+ // [
2971
+ // {
2972
+ // "symbol": "",
2973
+ // "incomeType": "TRANSFER",
2974
+ // "income": "10.00000000",
2975
+ // "asset": "USDT",
2976
+ // "time": 1677645250000,
2977
+ // "info": "TRANSFER",
2978
+ // "tranId": 131001573082,
2979
+ // "tradeId": ""
2980
+ // }
2981
+ // ]
2982
+ //
2983
+ return this.parseLedger(response, currency, since, limit);
2984
+ }
2985
+ parsePositionRisk(position, market = undefined) {
2986
+ //
2987
+ // {
2988
+ // "entryPrice": "6563.66500",
2989
+ // "marginType": "isolated",
2990
+ // "isAutoAddMargin": "false",
2991
+ // "isolatedMargin": "15517.54150468",
2992
+ // "leverage": "10",
2993
+ // "liquidationPrice": "5930.78",
2994
+ // "markPrice": "6679.50671178",
2995
+ // "maxNotionalValue": "20000000",
2996
+ // "positionSide": "LONG",
2997
+ // "positionAmt": "20.000",
2998
+ // "symbol": "BTCUSDT",
2999
+ // "unRealizedProfit": "2316.83423560",
3000
+ // "updateTime": 1625474304765
3001
+ // }
3002
+ //
3003
+ const marketId = this.safeString(position, 'symbol');
3004
+ market = this.safeMarket(marketId, market, undefined, 'contract');
3005
+ const symbol = this.safeString(market, 'symbol');
3006
+ const isolatedMarginString = this.safeString(position, 'isolatedMargin');
3007
+ const leverageBrackets = this.safeDict(this.options, 'leverageBrackets', {});
3008
+ const leverageBracket = this.safeList(leverageBrackets, symbol, []);
3009
+ const notionalString = this.safeString2(position, 'notional', 'notionalValue');
3010
+ const notionalStringAbs = Precise.stringAbs(notionalString);
3011
+ let maintenanceMarginPercentageString = undefined;
3012
+ for (let i = 0; i < leverageBracket.length; i++) {
3013
+ const bracket = leverageBracket[i];
3014
+ if (Precise.stringLt(notionalStringAbs, bracket[0])) {
3015
+ break;
3016
+ }
3017
+ maintenanceMarginPercentageString = bracket[1];
3018
+ }
3019
+ const notional = this.parseNumber(notionalStringAbs);
3020
+ const contractsAbs = Precise.stringAbs(this.safeString(position, 'positionAmt'));
3021
+ const contracts = this.parseNumber(contractsAbs);
3022
+ const unrealizedPnlString = this.safeString(position, 'unRealizedProfit');
3023
+ const unrealizedPnl = this.parseNumber(unrealizedPnlString);
3024
+ const liquidationPriceString = this.omitZero(this.safeString(position, 'liquidationPrice'));
3025
+ const liquidationPrice = this.parseNumber(liquidationPriceString);
3026
+ let collateralString = undefined;
3027
+ let marginMode = this.safeString(position, 'marginType');
3028
+ if (marginMode === undefined && isolatedMarginString !== undefined) {
3029
+ marginMode = Precise.stringEq(isolatedMarginString, '0') ? 'cross' : 'isolated';
3030
+ }
3031
+ let side = undefined;
3032
+ if (Precise.stringGt(notionalString, '0')) {
3033
+ side = 'long';
3034
+ }
3035
+ else if (Precise.stringLt(notionalString, '0')) {
3036
+ side = 'short';
3037
+ }
3038
+ const entryPriceString = this.safeString(position, 'entryPrice');
3039
+ const entryPrice = this.parseNumber(entryPriceString);
3040
+ const contractSize = this.safeValue(market, 'contractSize');
3041
+ const contractSizeString = this.numberToString(contractSize);
3042
+ // as oppose to notionalValue
3043
+ const linear = ('notional' in position);
3044
+ if (marginMode === 'cross') {
3045
+ // calculate collateral
3046
+ const precision = this.safeDict(market, 'precision', {});
3047
+ const basePrecisionValue = this.safeString(precision, 'base');
3048
+ const quotePrecisionValue = this.safeString2(precision, 'quote', 'price');
3049
+ const precisionIsUndefined = (basePrecisionValue === undefined) && (quotePrecisionValue === undefined);
3050
+ if (!precisionIsUndefined) {
3051
+ if (linear) {
3052
+ // walletBalance = (liquidationPrice * (±1 + mmp) ± entryPrice) * contracts
3053
+ let onePlusMaintenanceMarginPercentageString = undefined;
3054
+ let entryPriceSignString = entryPriceString;
3055
+ if (side === 'short') {
3056
+ onePlusMaintenanceMarginPercentageString = Precise.stringAdd('1', maintenanceMarginPercentageString);
3057
+ entryPriceSignString = Precise.stringMul('-1', entryPriceSignString);
3058
+ }
3059
+ else {
3060
+ onePlusMaintenanceMarginPercentageString = Precise.stringAdd('-1', maintenanceMarginPercentageString);
3061
+ }
3062
+ const inner = Precise.stringMul(liquidationPriceString, onePlusMaintenanceMarginPercentageString);
3063
+ const leftSide = Precise.stringAdd(inner, entryPriceSignString);
3064
+ const quotePrecision = this.precisionFromString(this.safeString2(precision, 'quote', 'price'));
3065
+ if (quotePrecision !== undefined) {
3066
+ collateralString = Precise.stringDiv(Precise.stringMul(leftSide, contractsAbs), '1', quotePrecision);
3067
+ }
3068
+ }
3069
+ else {
3070
+ // walletBalance = (contracts * contractSize) * (±1/entryPrice - (±1 - mmp) / liquidationPrice)
3071
+ let onePlusMaintenanceMarginPercentageString = undefined;
3072
+ let entryPriceSignString = entryPriceString;
3073
+ if (side === 'short') {
3074
+ onePlusMaintenanceMarginPercentageString = Precise.stringSub('1', maintenanceMarginPercentageString);
3075
+ }
3076
+ else {
3077
+ onePlusMaintenanceMarginPercentageString = Precise.stringSub('-1', maintenanceMarginPercentageString);
3078
+ entryPriceSignString = Precise.stringMul('-1', entryPriceSignString);
3079
+ }
3080
+ const leftSide = Precise.stringMul(contractsAbs, contractSizeString);
3081
+ const rightSide = Precise.stringSub(Precise.stringDiv('1', entryPriceSignString), Precise.stringDiv(onePlusMaintenanceMarginPercentageString, liquidationPriceString));
3082
+ const basePrecision = this.precisionFromString(this.safeString(precision, 'base'));
3083
+ if (basePrecision !== undefined) {
3084
+ collateralString = Precise.stringDiv(Precise.stringMul(leftSide, rightSide), '1', basePrecision);
3085
+ }
3086
+ }
3087
+ }
3088
+ }
3089
+ else {
3090
+ collateralString = this.safeString(position, 'isolatedMargin');
3091
+ }
3092
+ collateralString = (collateralString === undefined) ? '0' : collateralString;
3093
+ const collateral = this.parseNumber(collateralString);
3094
+ const markPrice = this.parseNumber(this.omitZero(this.safeString(position, 'markPrice')));
3095
+ let timestamp = this.safeInteger(position, 'updateTime');
3096
+ if (timestamp === 0) {
3097
+ timestamp = undefined;
3098
+ }
3099
+ const maintenanceMarginPercentage = this.parseNumber(maintenanceMarginPercentageString);
3100
+ let maintenanceMarginString = Precise.stringMul(maintenanceMarginPercentageString, notionalStringAbs);
3101
+ if (maintenanceMarginString === undefined) {
3102
+ // for a while, this new value was a backup to the existing calculations, but in future we might prioritize this
3103
+ maintenanceMarginString = this.safeString(position, 'maintMargin');
3104
+ }
3105
+ const maintenanceMargin = this.parseNumber(maintenanceMarginString);
3106
+ let initialMarginString = undefined;
3107
+ let initialMarginPercentageString = undefined;
3108
+ const leverageString = this.safeString(position, 'leverage');
3109
+ if (leverageString !== undefined) {
3110
+ const leverage = parseInt(leverageString);
3111
+ const rational = this.isRoundNumber(1000 % leverage);
3112
+ initialMarginPercentageString = Precise.stringDiv('1', leverageString, 8);
3113
+ if (!rational) {
3114
+ initialMarginPercentageString = Precise.stringAdd(initialMarginPercentageString, '1e-8');
3115
+ }
3116
+ const unrounded = Precise.stringMul(notionalStringAbs, initialMarginPercentageString);
3117
+ initialMarginString = Precise.stringDiv(unrounded, '1', 8);
3118
+ }
3119
+ else {
3120
+ initialMarginString = this.safeString(position, 'initialMargin');
3121
+ const unrounded = Precise.stringMul(initialMarginString, '1');
3122
+ initialMarginPercentageString = Precise.stringDiv(unrounded, notionalStringAbs, 8);
3123
+ }
3124
+ let marginRatio = undefined;
3125
+ let percentage = undefined;
3126
+ if (!Precise.stringEquals(collateralString, '0')) {
3127
+ marginRatio = this.parseNumber(Precise.stringDiv(Precise.stringAdd(Precise.stringDiv(maintenanceMarginString, collateralString), '5e-5'), '1', 4));
3128
+ percentage = this.parseNumber(Precise.stringMul(Precise.stringDiv(unrealizedPnlString, initialMarginString, 4), '100'));
3129
+ }
3130
+ const positionSide = this.safeString(position, 'positionSide');
3131
+ const hedged = positionSide !== 'BOTH';
3132
+ return this.safePosition({
3133
+ 'info': position,
3134
+ 'id': undefined,
3135
+ 'symbol': symbol,
3136
+ 'contracts': contracts,
3137
+ 'contractSize': contractSize,
3138
+ 'unrealizedPnl': unrealizedPnl,
3139
+ 'leverage': this.parseNumber(leverageString),
3140
+ 'liquidationPrice': liquidationPrice,
3141
+ 'collateral': collateral,
3142
+ 'notional': notional,
3143
+ 'markPrice': markPrice,
3144
+ 'entryPrice': entryPrice,
3145
+ 'timestamp': timestamp,
3146
+ 'initialMargin': this.parseNumber(initialMarginString),
3147
+ 'initialMarginPercentage': this.parseNumber(initialMarginPercentageString),
3148
+ 'maintenanceMargin': maintenanceMargin,
3149
+ 'maintenanceMarginPercentage': maintenanceMarginPercentage,
3150
+ 'marginRatio': marginRatio,
3151
+ 'datetime': this.iso8601(timestamp),
3152
+ 'marginMode': marginMode,
3153
+ 'side': side,
3154
+ 'hedged': hedged,
3155
+ 'percentage': percentage,
3156
+ 'stopLossPrice': undefined,
3157
+ 'takeProfitPrice': undefined,
3158
+ });
3159
+ }
3160
+ /**
3161
+ * @method
3162
+ * @name aster#fetchPositionsRisk
3163
+ * @description fetch positions risk
3164
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data
3165
+ * @param {string[]|undefined} symbols list of unified market symbols
3166
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3167
+ * @returns {object} data on the positions risk
3168
+ */
3169
+ async fetchPositionsRisk(symbols = undefined, params = {}) {
3170
+ if (symbols !== undefined) {
3171
+ if (!Array.isArray(symbols)) {
3172
+ throw new ArgumentsRequired(this.id + ' fetchPositionsRisk() requires an array argument for symbols');
3173
+ }
3174
+ }
3175
+ await this.loadMarkets();
3176
+ await this.loadLeverageBrackets(false, params);
3177
+ const request = {};
3178
+ const response = await this.fapiPrivateGetV2PositionRisk(this.extend(request, params));
3179
+ //
3180
+ // [
3181
+ // {
3182
+ // "entryPrice": "6563.66500",
3183
+ // "marginType": "isolated",
3184
+ // "isAutoAddMargin": "false",
3185
+ // "isolatedMargin": "15517.54150468",
3186
+ // "leverage": "10",
3187
+ // "liquidationPrice": "5930.78",
3188
+ // "markPrice": "6679.50671178",
3189
+ // "maxNotionalValue": "20000000",
3190
+ // "positionSide": "LONG",
3191
+ // "positionAmt": "20.000", // negative value for 'SHORT'
3192
+ // "symbol": "BTCUSDT",
3193
+ // "unRealizedProfit": "2316.83423560",
3194
+ // "updateTime": 1625474304765
3195
+ // }
3196
+ // ]
3197
+ //
3198
+ const result = [];
3199
+ for (let i = 0; i < response.length; i++) {
3200
+ const rawPosition = response[i];
3201
+ const entryPriceString = this.safeString(rawPosition, 'entryPrice');
3202
+ if (Precise.stringGt(entryPriceString, '0')) {
3203
+ result.push(this.parsePositionRisk(response[i]));
3204
+ }
3205
+ }
3206
+ symbols = this.marketSymbols(symbols);
3207
+ return this.filterByArrayPositions(result, 'symbol', symbols, false);
3208
+ }
3209
+ /**
3210
+ * @method
3211
+ * @name aster#fetchPositions
3212
+ * @description fetch all open positions
3213
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data
3214
+ * @param {string[]} [symbols] list of unified market symbols
3215
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3216
+ * @param {string} [params.method] method name to call, "positionRisk", "account" or "option", default is "positionRisk"
3217
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
3218
+ */
3219
+ async fetchPositions(symbols = undefined, params = {}) {
3220
+ let defaultMethod = undefined;
3221
+ [defaultMethod, params] = this.handleOptionAndParams(params, 'fetchPositions', 'method');
3222
+ if (defaultMethod === undefined) {
3223
+ const options = this.safeDict(this.options, 'fetchPositions');
3224
+ if (options === undefined) {
3225
+ defaultMethod = this.safeString(this.options, 'fetchPositions', 'positionRisk');
3226
+ }
3227
+ else {
3228
+ defaultMethod = 'positionRisk';
3229
+ }
3230
+ }
3231
+ if (defaultMethod === 'positionRisk') {
3232
+ return await this.fetchPositionsRisk(symbols, params);
3233
+ }
3234
+ else if (defaultMethod === 'account') {
3235
+ return await this.fetchAccountPositions(symbols, params);
3236
+ }
3237
+ else {
3238
+ throw new NotSupported(this.id + '.options["fetchPositions"]["method"] or params["method"] = "' + defaultMethod + '" is invalid, please choose between "account" and "positionRisk"');
3239
+ }
3240
+ }
3241
+ parseAccountPositions(account, filterClosed = false) {
3242
+ const positions = this.safeList(account, 'positions');
3243
+ const assets = this.safeList(account, 'assets', []);
3244
+ const balances = {};
3245
+ for (let i = 0; i < assets.length; i++) {
3246
+ const entry = assets[i];
3247
+ const currencyId = this.safeString(entry, 'asset');
3248
+ const code = this.safeCurrencyCode(currencyId);
3249
+ const crossWalletBalance = this.safeString(entry, 'crossWalletBalance');
3250
+ const crossUnPnl = this.safeString(entry, 'crossUnPnl');
3251
+ balances[code] = {
3252
+ 'crossMargin': Precise.stringAdd(crossWalletBalance, crossUnPnl),
3253
+ 'crossWalletBalance': crossWalletBalance,
3254
+ };
3255
+ }
3256
+ const result = [];
3257
+ for (let i = 0; i < positions.length; i++) {
3258
+ const position = positions[i];
3259
+ const marketId = this.safeString(position, 'symbol');
3260
+ const market = this.safeMarket(marketId, undefined, undefined, 'contract');
3261
+ const code = market['linear'] ? market['quote'] : market['base'];
3262
+ const maintenanceMargin = this.safeString(position, 'maintMargin');
3263
+ // check for maintenance margin so empty positions are not returned
3264
+ const isPositionOpen = (maintenanceMargin !== '0') && (maintenanceMargin !== '0.00000000');
3265
+ if (!filterClosed || isPositionOpen) {
3266
+ // sometimes not all the codes are correctly returned...
3267
+ if (code in balances) {
3268
+ const parsed = this.parseAccountPosition(this.extend(position, {
3269
+ 'crossMargin': balances[code]['crossMargin'],
3270
+ 'crossWalletBalance': balances[code]['crossWalletBalance'],
3271
+ }), market);
3272
+ result.push(parsed);
3273
+ }
3274
+ }
3275
+ }
3276
+ return result;
3277
+ }
3278
+ parseAccountPosition(position, market = undefined) {
3279
+ const marketId = this.safeString(position, 'symbol');
3280
+ market = this.safeMarket(marketId, market, undefined, 'contract');
3281
+ const symbol = this.safeString(market, 'symbol');
3282
+ const leverageString = this.safeString(position, 'leverage');
3283
+ const leverage = (leverageString !== undefined) ? parseInt(leverageString) : undefined;
3284
+ const initialMarginString = this.safeString(position, 'initialMargin');
3285
+ const initialMargin = this.parseNumber(initialMarginString);
3286
+ let initialMarginPercentageString = undefined;
3287
+ if (leverageString !== undefined) {
3288
+ initialMarginPercentageString = Precise.stringDiv('1', leverageString, 8);
3289
+ const rational = this.isRoundNumber(1000 % leverage);
3290
+ if (!rational) {
3291
+ initialMarginPercentageString = Precise.stringDiv(Precise.stringAdd(initialMarginPercentageString, '1e-8'), '1', 8);
3292
+ }
3293
+ }
3294
+ // as oppose to notionalValue
3295
+ const usdm = ('notional' in position);
3296
+ const maintenanceMarginString = this.safeString(position, 'maintMargin');
3297
+ const maintenanceMargin = this.parseNumber(maintenanceMarginString);
3298
+ const entryPriceString = this.safeString(position, 'entryPrice');
3299
+ let entryPrice = this.parseNumber(entryPriceString);
3300
+ const notionalString = this.safeString2(position, 'notional', 'notionalValue');
3301
+ const notionalStringAbs = Precise.stringAbs(notionalString);
3302
+ const notional = this.parseNumber(notionalStringAbs);
3303
+ let contractsString = this.safeString(position, 'positionAmt');
3304
+ let contractsStringAbs = Precise.stringAbs(contractsString);
3305
+ if (contractsString === undefined) {
3306
+ const entryNotional = Precise.stringMul(Precise.stringMul(leverageString, initialMarginString), entryPriceString);
3307
+ const contractSizeNew = this.safeString(market, 'contractSize');
3308
+ contractsString = Precise.stringDiv(entryNotional, contractSizeNew);
3309
+ contractsStringAbs = Precise.stringDiv(Precise.stringAdd(contractsString, '0.5'), '1', 0);
3310
+ }
3311
+ const contracts = this.parseNumber(contractsStringAbs);
3312
+ const leverageBrackets = this.safeDict(this.options, 'leverageBrackets', {});
3313
+ const leverageBracket = this.safeList(leverageBrackets, symbol, []);
3314
+ let maintenanceMarginPercentageString = undefined;
3315
+ for (let i = 0; i < leverageBracket.length; i++) {
3316
+ const bracket = leverageBracket[i];
3317
+ if (Precise.stringLt(notionalStringAbs, bracket[0])) {
3318
+ break;
3319
+ }
3320
+ maintenanceMarginPercentageString = bracket[1];
3321
+ }
3322
+ const maintenanceMarginPercentage = this.parseNumber(maintenanceMarginPercentageString);
3323
+ const unrealizedPnlString = this.safeString(position, 'unrealizedProfit');
3324
+ const unrealizedPnl = this.parseNumber(unrealizedPnlString);
3325
+ let timestamp = this.safeInteger(position, 'updateTime');
3326
+ if (timestamp === 0) {
3327
+ timestamp = undefined;
3328
+ }
3329
+ let isolated = this.safeBool(position, 'isolated');
3330
+ if (isolated === undefined) {
3331
+ const isolatedMarginRaw = this.safeString(position, 'isolatedMargin');
3332
+ isolated = !Precise.stringEq(isolatedMarginRaw, '0');
3333
+ }
3334
+ let marginMode = undefined;
3335
+ let collateralString = undefined;
3336
+ let walletBalance = undefined;
3337
+ if (isolated) {
3338
+ marginMode = 'isolated';
3339
+ walletBalance = this.safeString(position, 'isolatedWallet');
3340
+ collateralString = Precise.stringAdd(walletBalance, unrealizedPnlString);
3341
+ }
3342
+ else {
3343
+ marginMode = 'cross';
3344
+ walletBalance = this.safeString(position, 'crossWalletBalance');
3345
+ collateralString = this.safeString(position, 'crossMargin');
3346
+ }
3347
+ const collateral = this.parseNumber(collateralString);
3348
+ let marginRatio = undefined;
3349
+ let side = undefined;
3350
+ let percentage = undefined;
3351
+ let liquidationPriceStringRaw = undefined;
3352
+ let liquidationPrice = undefined;
3353
+ const contractSize = this.safeValue(market, 'contractSize');
3354
+ const contractSizeString = this.numberToString(contractSize);
3355
+ if (Precise.stringEquals(notionalString, '0')) {
3356
+ entryPrice = undefined;
3357
+ }
3358
+ else {
3359
+ side = Precise.stringLt(notionalString, '0') ? 'short' : 'long';
3360
+ marginRatio = this.parseNumber(Precise.stringDiv(Precise.stringAdd(Precise.stringDiv(maintenanceMarginString, collateralString), '5e-5'), '1', 4));
3361
+ percentage = this.parseNumber(Precise.stringMul(Precise.stringDiv(unrealizedPnlString, initialMarginString, 4), '100'));
3362
+ if (usdm) {
3363
+ // calculate liquidation price
3364
+ //
3365
+ // liquidationPrice = (walletBalance / (contracts * (±1 + mmp))) + (±entryPrice / (±1 + mmp))
3366
+ //
3367
+ // mmp = maintenanceMarginPercentage
3368
+ // where ± is negative for long and positive for short
3369
+ // TODO: calculate liquidation price for coinm contracts
3370
+ let onePlusMaintenanceMarginPercentageString = undefined;
3371
+ let entryPriceSignString = entryPriceString;
3372
+ if (side === 'short') {
3373
+ onePlusMaintenanceMarginPercentageString = Precise.stringAdd('1', maintenanceMarginPercentageString);
3374
+ }
3375
+ else {
3376
+ onePlusMaintenanceMarginPercentageString = Precise.stringAdd('-1', maintenanceMarginPercentageString);
3377
+ entryPriceSignString = Precise.stringMul('-1', entryPriceSignString);
3378
+ }
3379
+ const leftSide = Precise.stringDiv(walletBalance, Precise.stringMul(contractsStringAbs, onePlusMaintenanceMarginPercentageString));
3380
+ const rightSide = Precise.stringDiv(entryPriceSignString, onePlusMaintenanceMarginPercentageString);
3381
+ liquidationPriceStringRaw = Precise.stringAdd(leftSide, rightSide);
3382
+ }
3383
+ else {
3384
+ // calculate liquidation price
3385
+ //
3386
+ // liquidationPrice = (contracts * contractSize(±1 - mmp)) / (±1/entryPrice * contracts * contractSize - walletBalance)
3387
+ //
3388
+ let onePlusMaintenanceMarginPercentageString = undefined;
3389
+ let entryPriceSignString = entryPriceString;
3390
+ if (side === 'short') {
3391
+ onePlusMaintenanceMarginPercentageString = Precise.stringSub('1', maintenanceMarginPercentageString);
3392
+ }
3393
+ else {
3394
+ onePlusMaintenanceMarginPercentageString = Precise.stringSub('-1', maintenanceMarginPercentageString);
3395
+ entryPriceSignString = Precise.stringMul('-1', entryPriceSignString);
3396
+ }
3397
+ const size = Precise.stringMul(contractsStringAbs, contractSizeString);
3398
+ const leftSide = Precise.stringMul(size, onePlusMaintenanceMarginPercentageString);
3399
+ const rightSide = Precise.stringSub(Precise.stringMul(Precise.stringDiv('1', entryPriceSignString), size), walletBalance);
3400
+ liquidationPriceStringRaw = Precise.stringDiv(leftSide, rightSide);
3401
+ }
3402
+ const pricePrecision = this.precisionFromString(this.safeString(market['precision'], 'price'));
3403
+ const pricePrecisionPlusOne = pricePrecision + 1;
3404
+ const pricePrecisionPlusOneString = pricePrecisionPlusOne.toString();
3405
+ // round half up
3406
+ const rounder = new Precise('5e-' + pricePrecisionPlusOneString);
3407
+ const rounderString = rounder.toString();
3408
+ const liquidationPriceRoundedString = Precise.stringAdd(rounderString, liquidationPriceStringRaw);
3409
+ let truncatedLiquidationPrice = Precise.stringDiv(liquidationPriceRoundedString, '1', pricePrecision);
3410
+ if (truncatedLiquidationPrice[0] === '-') {
3411
+ // user cannot be liquidated
3412
+ // since he has more collateral than the size of the position
3413
+ truncatedLiquidationPrice = undefined;
3414
+ }
3415
+ liquidationPrice = this.parseNumber(truncatedLiquidationPrice);
3416
+ }
3417
+ const positionSide = this.safeString(position, 'positionSide');
3418
+ const hedged = positionSide !== 'BOTH';
3419
+ return {
3420
+ 'info': position,
3421
+ 'id': undefined,
3422
+ 'symbol': symbol,
3423
+ 'timestamp': timestamp,
3424
+ 'datetime': this.iso8601(timestamp),
3425
+ 'initialMargin': initialMargin,
3426
+ 'initialMarginPercentage': this.parseNumber(initialMarginPercentageString),
3427
+ 'maintenanceMargin': maintenanceMargin,
3428
+ 'maintenanceMarginPercentage': maintenanceMarginPercentage,
3429
+ 'entryPrice': entryPrice,
3430
+ 'notional': notional,
3431
+ 'leverage': this.parseNumber(leverageString),
3432
+ 'unrealizedPnl': unrealizedPnl,
3433
+ 'contracts': contracts,
3434
+ 'contractSize': contractSize,
3435
+ 'marginRatio': marginRatio,
3436
+ 'liquidationPrice': liquidationPrice,
3437
+ 'markPrice': undefined,
3438
+ 'collateral': collateral,
3439
+ 'marginMode': marginMode,
3440
+ 'side': side,
3441
+ 'hedged': hedged,
3442
+ 'percentage': percentage,
3443
+ };
3444
+ }
3445
+ /**
3446
+ * @method
3447
+ * @name aster#fetchAccountPositions
3448
+ * @ignore
3449
+ * @description fetch account positions
3450
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#position-information-v2-user_data
3451
+ * @param {string[]} [symbols] list of unified market symbols
3452
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3453
+ * @returns {object} data on account positions
3454
+ */
3455
+ async fetchAccountPositions(symbols = undefined, params = {}) {
3456
+ if (symbols !== undefined) {
3457
+ if (!Array.isArray(symbols)) {
3458
+ throw new ArgumentsRequired(this.id + ' fetchPositions() requires an array argument for symbols');
3459
+ }
3460
+ }
3461
+ await this.loadMarkets();
3462
+ await this.loadLeverageBrackets(false, params);
3463
+ const response = await this.fapiPrivateGetV4Account(params);
3464
+ let filterClosed = undefined;
3465
+ [filterClosed, params] = this.handleOptionAndParams(params, 'fetchAccountPositions', 'filterClosed', false);
3466
+ const result = this.parseAccountPositions(response, filterClosed);
3467
+ symbols = this.marketSymbols(symbols);
3468
+ return this.filterByArrayPositions(result, 'symbol', symbols, false);
3469
+ }
3470
+ async loadLeverageBrackets(reload = false, params = {}) {
3471
+ await this.loadMarkets();
3472
+ // by default cache the leverage bracket
3473
+ // it contains useful stuff like the maintenance margin and initial margin for positions
3474
+ const leverageBrackets = this.safeDict(this.options, 'leverageBrackets');
3475
+ if ((leverageBrackets === undefined) || (reload)) {
3476
+ const response = await this.fapiPrivateGetV1LeverageBracket(params);
3477
+ this.options['leverageBrackets'] = this.createSafeDictionary();
3478
+ for (let i = 0; i < response.length; i++) {
3479
+ const entry = response[i];
3480
+ const marketId = this.safeString(entry, 'symbol');
3481
+ const symbol = this.safeSymbol(marketId, undefined, undefined, 'contract');
3482
+ const brackets = this.safeList(entry, 'brackets', []);
3483
+ const result = [];
3484
+ for (let j = 0; j < brackets.length; j++) {
3485
+ const bracket = brackets[j];
3486
+ const floorValue = this.safeString(bracket, 'notionalFloor');
3487
+ const maintenanceMarginPercentage = this.safeString(bracket, 'maintMarginRatio');
3488
+ result.push([floorValue, maintenanceMarginPercentage]);
3489
+ }
3490
+ this.options['leverageBrackets'][symbol] = result;
3491
+ }
3492
+ }
3493
+ return this.options['leverageBrackets'];
3494
+ }
3495
+ keccakMessage(message) {
3496
+ return '0x' + this.hash(message, keccak, 'hex');
3497
+ }
3498
+ signMessage(message, privateKey) {
3499
+ return this.signHash(this.keccakMessage(message), privateKey.slice(-64));
3500
+ }
3501
+ signWithdrawPayload(withdrawPayload, network) {
3502
+ const zeroAddress = this.safeString(this.options, 'zeroAddress');
3503
+ const chainId = this.safeInteger(withdrawPayload, 'chainId');
3504
+ const domain = {
3505
+ 'chainId': chainId,
3506
+ 'name': 'Aster',
3507
+ 'verifyingContract': zeroAddress,
3508
+ 'version': '1',
3509
+ };
3510
+ const messageTypes = {
3511
+ 'Action': [
3512
+ { 'name': 'type', 'type': 'string' },
3513
+ { 'name': 'destination', 'type': 'address' },
3514
+ { 'name': 'destination Chain', 'type': 'string' },
3515
+ { 'name': 'token', 'type': 'string' },
3516
+ { 'name': 'amount', 'type': 'string' },
3517
+ { 'name': 'fee', 'type': 'string' },
3518
+ { 'name': 'nonce', 'type': 'uint256' },
3519
+ { 'name': 'aster chain', 'type': 'string' },
3520
+ ],
3521
+ };
3522
+ const withdraw = {
3523
+ 'type': 'Withdraw',
3524
+ 'destination': this.safeString(withdrawPayload, 'receiver'),
3525
+ 'destination Chain': network,
3526
+ 'token': this.safeString(withdrawPayload, 'asset'),
3527
+ 'amount': this.safeString(withdrawPayload, 'amount'),
3528
+ 'fee': this.safeString(withdrawPayload, 'fee'),
3529
+ 'nonce': this.safeInteger(withdrawPayload, 'nonce'),
3530
+ 'aster chain': 'Mainnet',
3531
+ };
3532
+ const msg = this.ethEncodeStructuredData(domain, messageTypes, withdraw);
3533
+ const signature = this.signMessage(msg, this.privateKey);
3534
+ return signature;
3535
+ }
3536
+ /**
3537
+ * @method
3538
+ * @name aster#withdraw
3539
+ * @description make a withdrawal
3540
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#withdraw-user_data
3541
+ * @param {string} code unified currency code
3542
+ * @param {float} amount the amount to withdraw
3543
+ * @param {string} address the address to withdraw to
3544
+ * @param {string} tag
3545
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3546
+ * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
3547
+ */
3548
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
3549
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
3550
+ this.checkAddress(address);
3551
+ await this.loadMarkets();
3552
+ const currency = this.currency(code);
3553
+ const request = {
3554
+ 'asset': currency['id'],
3555
+ 'receiver': address,
3556
+ 'nonce': this.milliseconds() * 1000,
3557
+ };
3558
+ let chainId = this.safeInteger(params, 'chainId');
3559
+ // TODO: check how ARBI signature would work
3560
+ const networks = this.safeDict(this.options, 'networks', {});
3561
+ let network = this.safeStringUpper(params, 'network');
3562
+ network = this.safeString(networks, network, network);
3563
+ if ((chainId === undefined) && (network !== undefined)) {
3564
+ const chainIds = this.safeDict(this.options, 'networksToChainId', {});
3565
+ chainId = this.safeInteger(chainIds, network);
3566
+ }
3567
+ if (chainId === undefined) {
3568
+ throw new ArgumentsRequired(this.id + ' withdraw require chainId or network parameter');
3569
+ }
3570
+ request['chainId'] = chainId;
3571
+ const fee = this.safeString(params, 'fee');
3572
+ if (fee === undefined) {
3573
+ throw new ArgumentsRequired(this.id + ' withdraw require fee parameter');
3574
+ }
3575
+ request['fee'] = fee;
3576
+ params = this.omit(params, ['chainId', 'network', 'fee']);
3577
+ request['amount'] = this.currencyToPrecision(code, amount, network);
3578
+ request['userSignature'] = this.signWithdrawPayload(request, network);
3579
+ const response = await this.sapiPrivatePostV1AsterUserWithdraw(this.extend(request, params));
3580
+ return {
3581
+ 'info': response,
3582
+ 'id': this.safeString(response, 'withdrawId'),
3583
+ 'txid': this.safeString(response, 'hash'),
3584
+ 'timestamp': undefined,
3585
+ 'datetime': undefined,
3586
+ 'network': network,
3587
+ 'address': address,
3588
+ 'addressTo': address,
3589
+ 'addressFrom': undefined,
3590
+ 'tag': tag,
3591
+ 'tagTo': tag,
3592
+ 'tagFrom': undefined,
3593
+ 'type': 'withdrawal',
3594
+ 'amount': amount,
3595
+ 'currency': code,
3596
+ 'status': undefined,
3597
+ 'updated': undefined,
3598
+ 'internal': undefined,
3599
+ 'comment': undefined,
3600
+ 'fee': undefined,
3601
+ };
3602
+ }
3603
+ /**
3604
+ * @method
3605
+ * @name aster#transfer
3606
+ * @description transfer currency internally between wallets on the same account
3607
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-spot-api.md#transfer-asset-to-other-address-trade
3608
+ * @see https://github.com/asterdex/api-docs/blob/master/aster-finance-futures-api.md#transfer-between-futures-and-spot-user_data
3609
+ * @param {string} code unified currency code
3610
+ * @param {float} amount amount to transfer
3611
+ * @param {string} fromAccount account to transfer from
3612
+ * @param {string} toAccount account to transfer to
3613
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
3614
+ * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
3615
+ */
3616
+ async transfer(code, amount, fromAccount, toAccount, params = {}) {
3617
+ await this.loadMarkets();
3618
+ const currency = this.currency(code);
3619
+ const request = {
3620
+ 'asset': currency['id'],
3621
+ 'amount': this.currencyToPrecision(code, amount),
3622
+ };
3623
+ let type = undefined;
3624
+ let fromId = undefined;
3625
+ if (fromAccount !== undefined) {
3626
+ fromId = this.convertTypeToAccount(fromAccount).toUpperCase();
3627
+ }
3628
+ let toId = undefined;
3629
+ if (toAccount !== undefined) {
3630
+ toId = this.convertTypeToAccount(toAccount).toUpperCase();
3631
+ }
3632
+ if (fromId === 'SPOT' && toId === 'FUTURE') {
3633
+ type = 'SPOT_FUTURE';
3634
+ }
3635
+ else if (fromId === 'FUTURE' && toId === 'SPOT') {
3636
+ type = 'FUTURE_SPOT';
3637
+ }
3638
+ let response = undefined;
3639
+ if (type !== undefined) {
3640
+ const defaultClientTranId = this.numberToString(this.milliseconds());
3641
+ const clientTranId = this.safeString(params, 'clientTranId', defaultClientTranId);
3642
+ request['kindType'] = type;
3643
+ request['clientTranId'] = clientTranId;
3644
+ response = await this.fapiPrivatePostV1AssetWalletTransfer(this.extend(request, params));
3645
+ }
3646
+ else {
3647
+ // transfer asset to other address
3648
+ request['toAddress'] = toAccount;
3649
+ response = await this.sapiPrivatePostV1AssetSendToAddress(this.extend(request, params));
3650
+ }
3651
+ //
3652
+ // {
3653
+ // "tranId":13526853623,
3654
+ // "status": "SUCCESS"
3655
+ // }
3656
+ //
3657
+ return {
3658
+ 'info': response,
3659
+ 'id': this.safeString(response, 'tranId'),
3660
+ 'txid': undefined,
3661
+ 'timestamp': undefined,
3662
+ 'datetime': undefined,
3663
+ 'network': undefined,
3664
+ 'address': undefined,
3665
+ 'addressTo': fromAccount,
3666
+ 'addressFrom': toAccount,
3667
+ 'tag': undefined,
3668
+ 'tagTo': undefined,
3669
+ 'tagFrom': undefined,
3670
+ 'type': 'transfer',
3671
+ 'amount': amount,
3672
+ 'currency': code,
3673
+ 'status': undefined,
3674
+ 'updated': undefined,
3675
+ 'internal': undefined,
3676
+ 'comment': undefined,
3677
+ 'fee': undefined,
3678
+ };
3679
+ }
3680
+ hashMessage(binaryMessage) {
3681
+ // const binaryMessage = this.encode (message);
3682
+ const binaryMessageLength = this.binaryLength(binaryMessage);
3683
+ const x19 = this.base16ToBinary('19');
3684
+ const newline = this.base16ToBinary('0a');
3685
+ const prefix = this.binaryConcat(x19, this.encode('Ethereum Signed Message:'), newline, this.encode(this.numberToString(binaryMessageLength)));
3686
+ return '0x' + this.hash(this.binaryConcat(prefix, binaryMessage), keccak, 'hex');
3687
+ }
3688
+ signHash(hash, privateKey) {
3689
+ this.checkRequiredCredentials();
3690
+ const signature = ecdsa(hash.slice(-64), privateKey.slice(-64), secp256k1, undefined);
3691
+ const r = signature['r'];
3692
+ const s = signature['s'];
3693
+ const v = this.intToBase16(this.sum(27, signature['v']));
3694
+ return '0x' + r.padStart(64, '0') + s.padStart(64, '0') + v;
3695
+ }
3696
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
3697
+ let url = this.implodeHostname(this.urls['api'][api]) + '/' + path;
3698
+ if (api === 'fapiPublic' || api === 'sapiPublic') {
3699
+ if (Object.keys(params).length) {
3700
+ url += '?' + this.rawencode(params);
3701
+ }
3702
+ }
3703
+ else if (api === 'fapiPrivate' || api === 'sapiPrivate') {
3704
+ this.checkRequiredCredentials();
3705
+ headers = {
3706
+ 'X-MBX-APIKEY': this.apiKey,
3707
+ };
3708
+ const nonce = this.milliseconds();
3709
+ const defaultRecvWindow = this.safeInteger(this.options, 'recvWindow');
3710
+ let extendedParams = this.extend({
3711
+ 'timestamp': nonce,
3712
+ }, params);
3713
+ if (defaultRecvWindow !== undefined) {
3714
+ extendedParams['recvWindow'] = defaultRecvWindow;
3715
+ }
3716
+ const recvWindow = this.safeInteger(params, 'recvWindow');
3717
+ if (recvWindow !== undefined) {
3718
+ extendedParams['recvWindow'] = recvWindow;
3719
+ }
3720
+ let query = undefined;
3721
+ if ((method === 'DELETE') && (path === 'v1/batchOrders')) {
3722
+ const orderidlist = this.safeList(extendedParams, 'orderIdList', []);
3723
+ const origclientorderidlist = this.safeList(extendedParams, 'origClientOrderIdList', []);
3724
+ extendedParams = this.omit(extendedParams, ['orderIdList', 'origClientOrderIdList']);
3725
+ query = this.rawencode(extendedParams);
3726
+ const orderidlistLength = orderidlist.length;
3727
+ const origclientorderidlistLength = origclientorderidlist.length;
3728
+ if (orderidlistLength > 0) {
3729
+ query = query + '&' + 'orderidlist=%5B' + orderidlist.join('%2C') + '%5D';
3730
+ }
3731
+ if (origclientorderidlistLength > 0) {
3732
+ query = query + '&' + 'origclientorderidlist=%5B' + origclientorderidlist.join('%2C') + '%5D';
3733
+ }
3734
+ }
3735
+ else {
3736
+ query = this.rawencode(extendedParams);
3737
+ }
3738
+ let signature = '';
3739
+ if (path.indexOf('v3') >= 0) {
3740
+ const signerAddress = this.options['signerAddress'];
3741
+ if (signerAddress === undefined) {
3742
+ throw new ArgumentsRequired(this.id + ' requires signerAddress in options when use v3 api');
3743
+ }
3744
+ // the keys order matter
3745
+ const keys = Object.keys(extendedParams);
3746
+ const sortedKeys = this.sort(keys);
3747
+ const signingPayload = {};
3748
+ for (let i = 0; i < sortedKeys.length; i++) {
3749
+ const key = sortedKeys[i];
3750
+ signingPayload[key] = extendedParams[key].toString();
3751
+ }
3752
+ const signingHash = this.hashMessage(this.hash(this.ethAbiEncode([
3753
+ 'string', 'address', 'address', 'uint256',
3754
+ ], [this.json(signingPayload), this.walletAddress, signerAddress, nonce]), keccak, 'binary'));
3755
+ signature = this.signHash(signingHash, this.privateKey);
3756
+ extendedParams['user'] = this.walletAddress;
3757
+ extendedParams['signer'] = signerAddress;
3758
+ extendedParams['nonce'] = nonce;
3759
+ query = this.rawencode(extendedParams);
3760
+ }
3761
+ else {
3762
+ signature = this.hmac(this.encode(query), this.encode(this.secret), sha256);
3763
+ }
3764
+ query += '&' + 'signature=' + signature;
3765
+ if (method === 'GET') {
3766
+ url += '?' + query;
3767
+ }
3768
+ else {
3769
+ body = query;
3770
+ headers['Content-Type'] = 'application/x-www-form-urlencoded';
3771
+ }
3772
+ }
3773
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
3774
+ }
3775
+ handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
3776
+ if (response === undefined) {
3777
+ return undefined; // fallback to default error handler
3778
+ }
3779
+ //
3780
+ // {
3781
+ // "code": -1121,
3782
+ // "msg": "Invalid symbol.",
3783
+ // }
3784
+ //
3785
+ const code = this.safeString(response, 'code');
3786
+ const message = this.safeString(response, 'msg');
3787
+ if (code !== undefined && code !== '200') {
3788
+ const feedback = this.id + ' ' + body;
3789
+ this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
3790
+ this.throwExactlyMatchedException(this.exceptions['exact'], code, feedback);
3791
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
3792
+ throw new ExchangeError(feedback); // unknown message
3793
+ }
3794
+ return undefined;
3795
+ }
3796
+ }