ccxt 4.2.10 → 4.2.12

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 (383) hide show
  1. package/README.md +5 -5
  2. package/build.sh +4 -4
  3. package/dist/ccxt.browser.js +695 -282
  4. package/dist/ccxt.browser.min.js +3 -3
  5. package/dist/cjs/_virtual/agent.js +7 -0
  6. package/dist/cjs/_virtual/parse-proxy-response.js +7 -0
  7. package/dist/cjs/_virtual/promisify.js +7 -0
  8. package/dist/cjs/ccxt.js +1 -1
  9. package/dist/cjs/js/ccxt.js +474 -0
  10. package/dist/cjs/js/src/abstract/ace.js +9 -0
  11. package/dist/cjs/js/src/abstract/alpaca.js +9 -0
  12. package/dist/cjs/js/src/abstract/ascendex.js +9 -0
  13. package/dist/cjs/js/src/abstract/bigone.js +9 -0
  14. package/dist/cjs/js/src/abstract/binance.js +9 -0
  15. package/dist/cjs/js/src/abstract/bingx.js +9 -0
  16. package/dist/cjs/js/src/abstract/bit2c.js +9 -0
  17. package/dist/cjs/js/src/abstract/bitbank.js +9 -0
  18. package/dist/cjs/js/src/abstract/bitbns.js +9 -0
  19. package/dist/cjs/js/src/abstract/bitfinex.js +9 -0
  20. package/dist/cjs/js/src/abstract/bitfinex2.js +9 -0
  21. package/dist/cjs/js/src/abstract/bitflyer.js +9 -0
  22. package/dist/cjs/js/src/abstract/bitforex.js +9 -0
  23. package/dist/cjs/js/src/abstract/bitget.js +9 -0
  24. package/dist/cjs/js/src/abstract/bithumb.js +9 -0
  25. package/dist/cjs/js/src/abstract/bitmart.js +9 -0
  26. package/dist/cjs/js/src/abstract/bitmex.js +9 -0
  27. package/dist/cjs/js/src/abstract/bitopro.js +9 -0
  28. package/dist/cjs/js/src/abstract/bitpanda.js +9 -0
  29. package/dist/cjs/js/src/abstract/bitrue.js +9 -0
  30. package/dist/cjs/js/src/abstract/bitso.js +9 -0
  31. package/dist/cjs/js/src/abstract/bitstamp.js +9 -0
  32. package/dist/cjs/js/src/abstract/bitteam.js +9 -0
  33. package/dist/cjs/js/src/abstract/bitvavo.js +9 -0
  34. package/dist/cjs/js/src/abstract/bl3p.js +9 -0
  35. package/dist/cjs/js/src/abstract/blockchaincom.js +9 -0
  36. package/dist/cjs/js/src/abstract/btcalpha.js +9 -0
  37. package/dist/cjs/js/src/abstract/btcbox.js +9 -0
  38. package/dist/cjs/js/src/abstract/btcmarkets.js +9 -0
  39. package/dist/cjs/js/src/abstract/btcturk.js +9 -0
  40. package/dist/cjs/js/src/abstract/bybit.js +9 -0
  41. package/dist/cjs/js/src/abstract/cex.js +9 -0
  42. package/dist/cjs/js/src/abstract/coinbase.js +9 -0
  43. package/dist/cjs/js/src/abstract/coinbasepro.js +9 -0
  44. package/dist/cjs/js/src/abstract/coincheck.js +9 -0
  45. package/dist/cjs/js/src/abstract/coinex.js +9 -0
  46. package/dist/cjs/js/src/abstract/coinlist.js +9 -0
  47. package/dist/cjs/js/src/abstract/coinmate.js +9 -0
  48. package/dist/cjs/js/src/abstract/coinone.js +9 -0
  49. package/dist/cjs/js/src/abstract/coinsph.js +9 -0
  50. package/dist/cjs/js/src/abstract/coinspot.js +9 -0
  51. package/dist/cjs/js/src/abstract/cryptocom.js +9 -0
  52. package/dist/cjs/js/src/abstract/currencycom.js +9 -0
  53. package/dist/cjs/js/src/abstract/delta.js +9 -0
  54. package/dist/cjs/js/src/abstract/deribit.js +9 -0
  55. package/dist/cjs/js/src/abstract/digifinex.js +9 -0
  56. package/dist/cjs/js/src/abstract/exmo.js +9 -0
  57. package/dist/cjs/js/src/abstract/gate.js +9 -0
  58. package/dist/cjs/js/src/abstract/gemini.js +9 -0
  59. package/dist/cjs/js/src/abstract/hitbtc.js +9 -0
  60. package/dist/cjs/js/src/abstract/hollaex.js +9 -0
  61. package/dist/cjs/js/src/abstract/htx.js +9 -0
  62. package/dist/cjs/js/src/abstract/huobijp.js +9 -0
  63. package/dist/cjs/js/src/abstract/idex.js +9 -0
  64. package/dist/cjs/js/src/abstract/independentreserve.js +9 -0
  65. package/dist/cjs/js/src/abstract/indodax.js +9 -0
  66. package/dist/cjs/js/src/abstract/kraken.js +9 -0
  67. package/dist/cjs/js/src/abstract/krakenfutures.js +9 -0
  68. package/dist/cjs/js/src/abstract/kucoin.js +9 -0
  69. package/dist/cjs/js/src/abstract/kucoinfutures.js +9 -0
  70. package/dist/cjs/js/src/abstract/kuna.js +9 -0
  71. package/dist/cjs/js/src/abstract/latoken.js +9 -0
  72. package/dist/cjs/js/src/abstract/lbank.js +9 -0
  73. package/dist/cjs/js/src/abstract/luno.js +9 -0
  74. package/dist/cjs/js/src/abstract/lykke.js +9 -0
  75. package/dist/cjs/js/src/abstract/mercado.js +9 -0
  76. package/dist/cjs/js/src/abstract/mexc.js +9 -0
  77. package/dist/cjs/js/src/abstract/ndax.js +9 -0
  78. package/dist/cjs/js/src/abstract/novadax.js +9 -0
  79. package/dist/cjs/js/src/abstract/oceanex.js +9 -0
  80. package/dist/cjs/js/src/abstract/okcoin.js +9 -0
  81. package/dist/cjs/js/src/abstract/okx.js +9 -0
  82. package/dist/cjs/js/src/abstract/p2b.js +9 -0
  83. package/dist/cjs/js/src/abstract/paymium.js +9 -0
  84. package/dist/cjs/js/src/abstract/phemex.js +9 -0
  85. package/dist/cjs/js/src/abstract/poloniex.js +9 -0
  86. package/dist/cjs/js/src/abstract/poloniexfutures.js +9 -0
  87. package/dist/cjs/js/src/abstract/probit.js +9 -0
  88. package/dist/cjs/js/src/abstract/timex.js +9 -0
  89. package/dist/cjs/js/src/abstract/tokocrypto.js +9 -0
  90. package/dist/cjs/js/src/abstract/upbit.js +9 -0
  91. package/dist/cjs/js/src/abstract/wavesexchange.js +9 -0
  92. package/dist/cjs/js/src/abstract/wazirx.js +9 -0
  93. package/dist/cjs/js/src/abstract/whitebit.js +9 -0
  94. package/dist/cjs/js/src/abstract/woo.js +9 -0
  95. package/dist/cjs/js/src/abstract/yobit.js +9 -0
  96. package/dist/cjs/js/src/abstract/zaif.js +9 -0
  97. package/dist/cjs/js/src/abstract/zonda.js +9 -0
  98. package/dist/cjs/js/src/ace.js +1058 -0
  99. package/dist/cjs/js/src/alpaca.js +1125 -0
  100. package/dist/cjs/js/src/ascendex.js +3360 -0
  101. package/dist/cjs/js/src/base/Exchange.js +5110 -0
  102. package/dist/cjs/js/src/base/Precise.js +263 -0
  103. package/dist/cjs/js/src/base/errors.js +299 -0
  104. package/dist/cjs/js/src/base/functions/crypto.js +78 -0
  105. package/dist/cjs/js/src/base/functions/encode.js +44 -0
  106. package/dist/cjs/js/src/base/functions/generic.js +193 -0
  107. package/dist/cjs/js/src/base/functions/misc.js +96 -0
  108. package/dist/cjs/js/src/base/functions/number.js +297 -0
  109. package/dist/cjs/js/src/base/functions/platform.js +28 -0
  110. package/dist/cjs/js/src/base/functions/rsa.js +34 -0
  111. package/dist/cjs/js/src/base/functions/string.js +48 -0
  112. package/dist/cjs/js/src/base/functions/throttle.js +66 -0
  113. package/dist/cjs/js/src/base/functions/time.js +187 -0
  114. package/dist/cjs/js/src/base/functions/totp.js +24 -0
  115. package/dist/cjs/js/src/base/functions/type.js +162 -0
  116. package/dist/cjs/js/src/base/functions.js +157 -0
  117. package/dist/cjs/js/src/base/ws/Cache.js +254 -0
  118. package/dist/cjs/js/src/base/ws/Client.js +299 -0
  119. package/dist/cjs/js/src/base/ws/Future.js +34 -0
  120. package/dist/cjs/js/src/base/ws/OrderBook.js +107 -0
  121. package/dist/cjs/js/src/base/ws/OrderBookSide.js +281 -0
  122. package/dist/cjs/js/src/base/ws/WsClient.js +69 -0
  123. package/dist/cjs/js/src/bequant.js +33 -0
  124. package/dist/cjs/js/src/bigone.js +2142 -0
  125. package/dist/cjs/js/src/binance.js +9729 -0
  126. package/dist/cjs/js/src/binancecoinm.js +45 -0
  127. package/dist/cjs/js/src/binanceus.js +84 -0
  128. package/dist/cjs/js/src/binanceusdm.js +58 -0
  129. package/dist/cjs/js/src/bingx.js +3737 -0
  130. package/dist/cjs/js/src/bit2c.js +916 -0
  131. package/dist/cjs/js/src/bitbank.js +1000 -0
  132. package/dist/cjs/js/src/bitbay.js +17 -0
  133. package/dist/cjs/js/src/bitbns.js +1220 -0
  134. package/dist/cjs/js/src/bitcoincom.js +17 -0
  135. package/dist/cjs/js/src/bitfinex.js +1670 -0
  136. package/dist/cjs/js/src/bitfinex2.js +2990 -0
  137. package/dist/cjs/js/src/bitflyer.js +1045 -0
  138. package/dist/cjs/js/src/bitforex.js +852 -0
  139. package/dist/cjs/js/src/bitget.js +8284 -0
  140. package/dist/cjs/js/src/bithumb.js +1090 -0
  141. package/dist/cjs/js/src/bitmart.js +4454 -0
  142. package/dist/cjs/js/src/bitmex.js +2884 -0
  143. package/dist/cjs/js/src/bitopro.js +1724 -0
  144. package/dist/cjs/js/src/bitpanda.js +2002 -0
  145. package/dist/cjs/js/src/bitrue.js +3253 -0
  146. package/dist/cjs/js/src/bitso.js +1753 -0
  147. package/dist/cjs/js/src/bitstamp.js +2188 -0
  148. package/dist/cjs/js/src/bitteam.js +2309 -0
  149. package/dist/cjs/js/src/bitvavo.js +1968 -0
  150. package/dist/cjs/js/src/bl3p.js +447 -0
  151. package/dist/cjs/js/src/blockchaincom.js +1160 -0
  152. package/dist/cjs/js/src/btcalpha.js +929 -0
  153. package/dist/cjs/js/src/btcbox.js +565 -0
  154. package/dist/cjs/js/src/btcmarkets.js +1237 -0
  155. package/dist/cjs/js/src/btcturk.js +929 -0
  156. package/dist/cjs/js/src/bybit.js +7646 -0
  157. package/dist/cjs/js/src/cex.js +1693 -0
  158. package/dist/cjs/js/src/coinbase.js +3274 -0
  159. package/dist/cjs/js/src/coinbasepro.js +1866 -0
  160. package/dist/cjs/js/src/coincheck.js +843 -0
  161. package/dist/cjs/js/src/coinex.js +5414 -0
  162. package/dist/cjs/js/src/coinlist.js +2329 -0
  163. package/dist/cjs/js/src/coinmate.js +989 -0
  164. package/dist/cjs/js/src/coinone.js +1185 -0
  165. package/dist/cjs/js/src/coinsph.js +1933 -0
  166. package/dist/cjs/js/src/coinspot.js +548 -0
  167. package/dist/cjs/js/src/cryptocom.js +3007 -0
  168. package/dist/cjs/js/src/currencycom.js +2015 -0
  169. package/dist/cjs/js/src/delta.js +3256 -0
  170. package/dist/cjs/js/src/deribit.js +3306 -0
  171. package/dist/cjs/js/src/digifinex.js +4307 -0
  172. package/dist/cjs/js/src/exmo.js +2645 -0
  173. package/dist/cjs/js/src/fmfwio.js +34 -0
  174. package/dist/cjs/js/src/gate.js +7054 -0
  175. package/dist/cjs/js/src/gateio.js +16 -0
  176. package/dist/cjs/js/src/gemini.js +1801 -0
  177. package/dist/cjs/js/src/hitbtc.js +3660 -0
  178. package/dist/cjs/js/src/hitbtc3.js +19 -0
  179. package/dist/cjs/js/src/hollaex.js +1882 -0
  180. package/dist/cjs/js/src/htx.js +9024 -0
  181. package/dist/cjs/js/src/huobi.js +16 -0
  182. package/dist/cjs/js/src/huobijp.js +1918 -0
  183. package/dist/cjs/js/src/idex.js +1770 -0
  184. package/dist/cjs/js/src/independentreserve.js +759 -0
  185. package/dist/cjs/js/src/indodax.js +1069 -0
  186. package/dist/cjs/js/src/kraken.js +2861 -0
  187. package/dist/cjs/js/src/krakenfutures.js +2407 -0
  188. package/dist/cjs/js/src/kucoin.js +4489 -0
  189. package/dist/cjs/js/src/kucoinfutures.js +2475 -0
  190. package/dist/cjs/js/src/kuna.js +1949 -0
  191. package/dist/cjs/js/src/latoken.js +1729 -0
  192. package/dist/cjs/js/src/lbank.js +2825 -0
  193. package/dist/cjs/js/src/luno.js +1044 -0
  194. package/dist/cjs/js/src/lykke.js +1303 -0
  195. package/dist/cjs/js/src/mercado.js +897 -0
  196. package/dist/cjs/js/src/mexc.js +5407 -0
  197. package/dist/cjs/js/src/ndax.js +2450 -0
  198. package/dist/cjs/js/src/novadax.js +1556 -0
  199. package/dist/cjs/js/src/oceanex.js +964 -0
  200. package/dist/cjs/js/src/okcoin.js +3115 -0
  201. package/dist/cjs/js/src/okx.js +7329 -0
  202. package/dist/cjs/js/src/p2b.js +1243 -0
  203. package/dist/cjs/js/src/paymium.js +597 -0
  204. package/dist/cjs/js/src/phemex.js +4715 -0
  205. package/dist/cjs/js/src/poloniex.js +2356 -0
  206. package/dist/cjs/js/src/poloniexfutures.js +1794 -0
  207. package/dist/cjs/js/src/pro/alpaca.js +714 -0
  208. package/dist/cjs/js/src/pro/ascendex.js +957 -0
  209. package/dist/cjs/js/src/pro/bequant.js +33 -0
  210. package/dist/cjs/js/src/pro/binance.js +2796 -0
  211. package/dist/cjs/js/src/pro/binancecoinm.js +23 -0
  212. package/dist/cjs/js/src/pro/binanceus.js +51 -0
  213. package/dist/cjs/js/src/pro/binanceusdm.js +32 -0
  214. package/dist/cjs/js/src/pro/bingx.js +944 -0
  215. package/dist/cjs/js/src/pro/bitcoincom.js +29 -0
  216. package/dist/cjs/js/src/pro/bitfinex.js +672 -0
  217. package/dist/cjs/js/src/pro/bitfinex2.js +1159 -0
  218. package/dist/cjs/js/src/pro/bitget.js +1733 -0
  219. package/dist/cjs/js/src/pro/bitmart.js +1486 -0
  220. package/dist/cjs/js/src/pro/bitmex.js +1576 -0
  221. package/dist/cjs/js/src/pro/bitopro.js +327 -0
  222. package/dist/cjs/js/src/pro/bitpanda.js +1341 -0
  223. package/dist/cjs/js/src/pro/bitrue.js +462 -0
  224. package/dist/cjs/js/src/pro/bitstamp.js +547 -0
  225. package/dist/cjs/js/src/pro/bitvavo.js +704 -0
  226. package/dist/cjs/js/src/pro/blockchaincom.js +794 -0
  227. package/dist/cjs/js/src/pro/bybit.js +1843 -0
  228. package/dist/cjs/js/src/pro/cex.js +1510 -0
  229. package/dist/cjs/js/src/pro/coinbase.js +561 -0
  230. package/dist/cjs/js/src/pro/coinbasepro.js +968 -0
  231. package/dist/cjs/js/src/pro/coinex.js +1095 -0
  232. package/dist/cjs/js/src/pro/cryptocom.js +1020 -0
  233. package/dist/cjs/js/src/pro/currencycom.js +563 -0
  234. package/dist/cjs/js/src/pro/deribit.js +825 -0
  235. package/dist/cjs/js/src/pro/exmo.js +658 -0
  236. package/dist/cjs/js/src/pro/gate.js +1316 -0
  237. package/dist/cjs/js/src/pro/gateio.js +16 -0
  238. package/dist/cjs/js/src/pro/gemini.js +649 -0
  239. package/dist/cjs/js/src/pro/hitbtc.js +1293 -0
  240. package/dist/cjs/js/src/pro/hollaex.js +597 -0
  241. package/dist/cjs/js/src/pro/htx.js +2383 -0
  242. package/dist/cjs/js/src/pro/huobi.js +16 -0
  243. package/dist/cjs/js/src/pro/huobijp.js +606 -0
  244. package/dist/cjs/js/src/pro/idex.js +714 -0
  245. package/dist/cjs/js/src/pro/independentreserve.js +280 -0
  246. package/dist/cjs/js/src/pro/kraken.js +1364 -0
  247. package/dist/cjs/js/src/pro/krakenfutures.js +1500 -0
  248. package/dist/cjs/js/src/pro/kucoin.js +1052 -0
  249. package/dist/cjs/js/src/pro/kucoinfutures.js +981 -0
  250. package/dist/cjs/js/src/pro/luno.js +322 -0
  251. package/dist/cjs/js/src/pro/mexc.js +1170 -0
  252. package/dist/cjs/js/src/pro/ndax.js +545 -0
  253. package/dist/cjs/js/src/pro/okcoin.js +760 -0
  254. package/dist/cjs/js/src/pro/okx.js +1558 -0
  255. package/dist/cjs/js/src/pro/phemex.js +1511 -0
  256. package/dist/cjs/js/src/pro/poloniex.js +1253 -0
  257. package/dist/cjs/js/src/pro/poloniexfutures.js +1014 -0
  258. package/dist/cjs/js/src/pro/probit.js +586 -0
  259. package/dist/cjs/js/src/pro/upbit.js +234 -0
  260. package/dist/cjs/js/src/pro/wazirx.js +776 -0
  261. package/dist/cjs/js/src/pro/whitebit.js +927 -0
  262. package/dist/cjs/js/src/pro/woo.js +769 -0
  263. package/dist/cjs/js/src/probit.js +1865 -0
  264. package/dist/cjs/js/src/static_dependencies/fflake/browser.js +401 -0
  265. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncrypt.js +195 -0
  266. package/dist/cjs/js/src/static_dependencies/jsencrypt/JSEncryptRSAKey.js +308 -0
  267. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/asn1.js +554 -0
  268. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/base64.js +94 -0
  269. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/hex.js +70 -0
  270. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/asn1js/int10.js +91 -0
  271. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/base64.js +16 -0
  272. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/jsbn.js +1760 -0
  273. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/prng4.js +52 -0
  274. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rng.js +81 -0
  275. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/rsa.js +376 -0
  276. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsbn/util.js +70 -0
  277. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/asn1-1.0.js +1580 -0
  278. package/dist/cjs/js/src/static_dependencies/jsencrypt/lib/jsrsasign/yahoo.js +74 -0
  279. package/dist/cjs/js/src/static_dependencies/noble-curves/_shortw_utils.js +24 -0
  280. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/curve.js +158 -0
  281. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/edwards.js +429 -0
  282. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/hash-to-curve.js +176 -0
  283. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/modular.js +324 -0
  284. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/montgomery.js +163 -0
  285. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/utils.js +245 -0
  286. package/dist/cjs/js/src/static_dependencies/noble-curves/abstract/weierstrass.js +1018 -0
  287. package/dist/cjs/js/src/static_dependencies/noble-curves/ed25519.js +383 -0
  288. package/dist/cjs/js/src/static_dependencies/noble-curves/secp256k1.js +258 -0
  289. package/dist/cjs/js/src/static_dependencies/noble-hashes/_assert.js +53 -0
  290. package/dist/cjs/js/src/static_dependencies/noble-hashes/_sha2.js +120 -0
  291. package/dist/cjs/js/src/static_dependencies/noble-hashes/_u64.js +69 -0
  292. package/dist/cjs/js/src/static_dependencies/noble-hashes/crypto.js +7 -0
  293. package/dist/cjs/js/src/static_dependencies/noble-hashes/hmac.js +83 -0
  294. package/dist/cjs/js/src/static_dependencies/noble-hashes/md5.js +240 -0
  295. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha1.js +91 -0
  296. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha256.js +130 -0
  297. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha3.js +214 -0
  298. package/dist/cjs/js/src/static_dependencies/noble-hashes/sha512.js +239 -0
  299. package/dist/cjs/js/src/static_dependencies/noble-hashes/utils.js +93 -0
  300. package/dist/cjs/js/src/static_dependencies/node-fetch/body.js +354 -0
  301. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/abort-error.js +16 -0
  302. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/base.js +20 -0
  303. package/dist/cjs/js/src/static_dependencies/node-fetch/errors/fetch-error.js +30 -0
  304. package/dist/cjs/js/src/static_dependencies/node-fetch/headers.js +239 -0
  305. package/dist/cjs/js/src/static_dependencies/node-fetch/index.js +372 -0
  306. package/dist/cjs/js/src/static_dependencies/node-fetch/request.js +273 -0
  307. package/dist/cjs/js/src/static_dependencies/node-fetch/response.js +139 -0
  308. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/get-search.js +14 -0
  309. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is-redirect.js +16 -0
  310. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/is.js +81 -0
  311. package/dist/cjs/js/src/static_dependencies/node-fetch/utils/referrer.js +292 -0
  312. package/dist/cjs/js/src/static_dependencies/proxies/agent-base/index.js +103 -0
  313. package/dist/cjs/js/src/static_dependencies/proxies/http-proxy-agent/index.js +140 -0
  314. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/index.js +175 -0
  315. package/dist/cjs/js/src/static_dependencies/proxies/https-proxy-agent/parse-proxy-response.js +95 -0
  316. package/dist/cjs/js/src/static_dependencies/qs/index.cjs.js +7 -0
  317. package/dist/cjs/js/src/static_dependencies/scure-base/index.js +383 -0
  318. package/dist/cjs/js/src/timex.js +1562 -0
  319. package/dist/cjs/js/src/tokocrypto.js +2542 -0
  320. package/dist/cjs/js/src/upbit.js +1844 -0
  321. package/dist/cjs/js/src/wavesexchange.js +2607 -0
  322. package/dist/cjs/js/src/wazirx.js +953 -0
  323. package/dist/cjs/js/src/whitebit.js +2309 -0
  324. package/dist/cjs/js/src/woo.js +2715 -0
  325. package/dist/cjs/js/src/yobit.js +1314 -0
  326. package/dist/cjs/js/src/zaif.js +736 -0
  327. package/dist/cjs/js/src/zonda.js +1883 -0
  328. package/dist/cjs/src/base/Exchange.js +11 -0
  329. package/dist/cjs/src/bingx.js +0 -10
  330. package/dist/cjs/src/bitget.js +14 -5
  331. package/dist/cjs/src/bybit.js +1 -1
  332. package/dist/cjs/src/kucoin.js +29 -5
  333. package/js/ccxt.d.ts +1 -1
  334. package/js/ccxt.js +1 -1
  335. package/js/src/abstract/bigone.d.ts +18 -0
  336. package/js/src/abstract/binance.d.ts +2 -0
  337. package/js/src/abstract/binancecoinm.d.ts +2 -0
  338. package/js/src/abstract/binanceus.d.ts +2 -0
  339. package/js/src/abstract/binanceusdm.d.ts +2 -0
  340. package/js/src/abstract/bybit.d.ts +1 -0
  341. package/js/src/abstract/gate.d.ts +11 -0
  342. package/js/src/abstract/gateio.d.ts +11 -0
  343. package/js/src/alpaca.js +18 -18
  344. package/js/src/base/Exchange.d.ts +6 -1
  345. package/js/src/base/Exchange.js +112 -12
  346. package/js/src/bigone.d.ts +1 -2
  347. package/js/src/bigone.js +340 -145
  348. package/js/src/binance.js +15 -8
  349. package/js/src/bingx.d.ts +0 -1
  350. package/js/src/bingx.js +9 -12
  351. package/js/src/bitfinex.d.ts +2 -2
  352. package/js/src/bitfinex.js +2 -3
  353. package/js/src/bitget.js +35 -13
  354. package/js/src/bitmart.d.ts +2 -2
  355. package/js/src/bitmart.js +3 -3
  356. package/js/src/bitmex.js +1 -0
  357. package/js/src/bybit.js +3 -1
  358. package/js/src/coinlist.js +2 -3
  359. package/js/src/coinsph.js +2 -3
  360. package/js/src/deribit.js +1 -0
  361. package/js/src/gate.d.ts +4 -4
  362. package/js/src/gate.js +22 -3
  363. package/js/src/hitbtc.d.ts +4 -4
  364. package/js/src/hitbtc.js +2 -3
  365. package/js/src/htx.js +4 -7
  366. package/js/src/huobijp.js +2 -3
  367. package/js/src/kraken.js +1 -0
  368. package/js/src/kucoin.js +29 -5
  369. package/js/src/mexc.js +2 -1
  370. package/js/src/okx.js +13 -3
  371. package/js/src/pro/binance.d.ts +2 -23
  372. package/js/src/pro/binance.js +58 -22
  373. package/js/src/pro/coinbase.d.ts +2 -2
  374. package/js/src/pro/coinbase.js +4 -1
  375. package/js/src/pro/coinbasepro.d.ts +2 -2
  376. package/js/src/pro/hitbtc.d.ts +2 -2
  377. package/js/src/pro/poloniex.d.ts +2 -2
  378. package/js/src/upbit.d.ts +3 -101
  379. package/js/src/upbit.js +12 -12
  380. package/js/src/woo.js +2 -0
  381. package/package.json +11 -11
  382. package/skip-tests.json +5 -0
  383. package/tests-manager.sh +2 -2
@@ -0,0 +1,1794 @@
1
+ 'use strict';
2
+
3
+ var Precise = require('./base/Precise.js');
4
+ var poloniexfutures$1 = require('./abstract/poloniexfutures.js');
5
+ var number = require('./base/functions/number.js');
6
+ var errors = require('./base/errors.js');
7
+ var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * @class poloniexfutures
13
+ * @augments Exchange
14
+ */
15
+ class poloniexfutures extends poloniexfutures$1 {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'poloniexfutures',
19
+ 'name': 'Poloniex Futures',
20
+ 'countries': ['US'],
21
+ // 30 requests per second
22
+ 'rateLimit': 33.3,
23
+ 'certified': false,
24
+ 'pro': true,
25
+ 'version': 'v1',
26
+ 'has': {
27
+ 'CORS': undefined,
28
+ 'spot': false,
29
+ 'margin': true,
30
+ 'swap': true,
31
+ 'future': false,
32
+ 'option': undefined,
33
+ 'createOrder': true,
34
+ 'fetchBalance': true,
35
+ 'fetchClosedOrders': true,
36
+ 'fetchCurrencies': false,
37
+ 'fetchFundingRate': true,
38
+ 'fetchL3OrderBook': true,
39
+ 'fetchMarkets': true,
40
+ 'fetchMyTrades': true,
41
+ 'fetchOHLCV': true,
42
+ 'fetchOpenOrders': true,
43
+ 'fetchOrder': true,
44
+ 'fetchOrderBook': true,
45
+ 'fetchOrdersByStatus': true,
46
+ 'fetchPositions': true,
47
+ 'fetchTicker': true,
48
+ 'fetchTickers': true,
49
+ 'fetchTime': true,
50
+ 'fetchTrades': true,
51
+ 'setMarginMode': true,
52
+ },
53
+ 'timeframes': {
54
+ '1m': 1,
55
+ '5m': 5,
56
+ '15m': 15,
57
+ '30m': 30,
58
+ '1h': 60,
59
+ '2h': 120,
60
+ '4h': 480,
61
+ '12h': 720,
62
+ '1d': 1440,
63
+ '1w': 10080,
64
+ },
65
+ 'urls': {
66
+ 'logo': 'https://user-images.githubusercontent.com/1294454/27766817-e9456312-5ee6-11e7-9b3c-b628ca5626a5.jpg',
67
+ 'api': {
68
+ 'public': 'https://futures-api.poloniex.com',
69
+ 'private': 'https://futures-api.poloniex.com',
70
+ },
71
+ 'www': 'https://www.poloniex.com',
72
+ 'doc': 'https://futures-docs.poloniex.com',
73
+ 'fees': 'https://poloniex.com/fee-schedule',
74
+ 'referral': 'https://poloniex.com/signup?c=UBFZJRPJ',
75
+ },
76
+ 'api': {
77
+ 'public': {
78
+ 'get': {
79
+ 'contracts/active': 10,
80
+ 'contracts/{symbol}': 10,
81
+ 'ticker': 10,
82
+ 'tickers': 10,
83
+ 'level2/snapshot': 180.002,
84
+ 'level2/depth': 180.002,
85
+ 'level2/message/query': 180.002,
86
+ 'level3/snapshot': 180.002,
87
+ 'trade/history': 10,
88
+ 'interest/query': 10,
89
+ 'index/query': 10,
90
+ 'mark-price/{symbol}/current': 10,
91
+ 'premium/query': 10,
92
+ 'funding-rate/{symbol}/current': 10,
93
+ 'timestamp': 10,
94
+ 'status': 10,
95
+ 'kline/query': 10,
96
+ },
97
+ 'post': {
98
+ 'bullet-public': 10,
99
+ },
100
+ },
101
+ 'private': {
102
+ 'get': {
103
+ 'account-overview': 1,
104
+ 'transaction-history': 1,
105
+ 'maxActiveOrders': 1,
106
+ 'maxRiskLimit': 1,
107
+ 'userFeeRate': 1,
108
+ 'marginType/query': 1,
109
+ 'orders': 1,
110
+ 'stopOrders': 1,
111
+ 'recentDoneOrders': 1,
112
+ 'orders/{order-id}': 1,
113
+ 'clientOrderId/{clientOid}': 1,
114
+ 'fills': 1,
115
+ 'openOrderStatistics': 1,
116
+ 'position': 1.5,
117
+ 'positions': 1.5,
118
+ 'funding-history': 1,
119
+ },
120
+ 'post': {
121
+ 'orders': 1.5,
122
+ 'batchOrders': 1.5,
123
+ 'position/margin/auto-deposit-status': 1.5,
124
+ 'position/margin/deposit-margin': 1.5,
125
+ 'position/margin/withdraw-margin': 1.5,
126
+ 'bullet-private': 1,
127
+ 'marginType/change': 1,
128
+ },
129
+ 'delete': {
130
+ 'orders/{order-id}': 1.5,
131
+ 'orders': 150.016,
132
+ 'stopOrders': 150.016,
133
+ },
134
+ },
135
+ },
136
+ 'precisionMode': number.TICK_SIZE,
137
+ 'fees': {
138
+ 'trading': {
139
+ 'tierBased': false,
140
+ 'percentage': true,
141
+ 'taker': this.parseNumber('0.00075'),
142
+ 'maker': this.parseNumber('0.0001'),
143
+ },
144
+ 'funding': {
145
+ 'tierBased': false,
146
+ 'percentage': false,
147
+ 'withdraw': {},
148
+ 'deposit': {},
149
+ },
150
+ },
151
+ 'commonCurrencies': {},
152
+ 'requiredCredentials': {
153
+ 'apiKey': true,
154
+ 'secret': true,
155
+ 'password': true,
156
+ },
157
+ 'options': {
158
+ 'networks': {
159
+ 'OMNI': 'omni',
160
+ 'ERC20': 'eth',
161
+ 'TRC20': 'trx',
162
+ },
163
+ 'versions': {
164
+ 'public': {
165
+ 'GET': {
166
+ 'ticker': 'v2',
167
+ 'tickers': 'v2',
168
+ 'level3/snapshot': 'v2',
169
+ },
170
+ },
171
+ },
172
+ },
173
+ 'exceptions': {
174
+ 'exact': {
175
+ '400': errors.BadRequest,
176
+ '401': errors.AuthenticationError,
177
+ '403': errors.NotSupported,
178
+ '404': errors.NotSupported,
179
+ '405': errors.NotSupported,
180
+ '415': errors.BadRequest,
181
+ '429': errors.RateLimitExceeded,
182
+ '500': errors.ExchangeNotAvailable,
183
+ '503': errors.ExchangeNotAvailable,
184
+ '400001': errors.AuthenticationError,
185
+ '400002': errors.InvalidNonce,
186
+ '400003': errors.AuthenticationError,
187
+ '400004': errors.AuthenticationError,
188
+ '400005': errors.AuthenticationError,
189
+ '400006': errors.AuthenticationError,
190
+ '400007': errors.AuthenticationError,
191
+ '404000': errors.NotSupported,
192
+ '400100': errors.BadRequest,
193
+ '411100': errors.AccountSuspended,
194
+ '500000': errors.ExchangeNotAvailable, // Internal Server Error -- We had a problem with our server. Try again later.
195
+ },
196
+ 'broad': {
197
+ 'Position does not exist': errors.OrderNotFound, // { "code":"200000", "msg":"Position does not exist" }
198
+ },
199
+ },
200
+ });
201
+ }
202
+ async fetchMarkets(params = {}) {
203
+ /**
204
+ * @method
205
+ * @name poloniexfutures#fetchMarkets
206
+ * @description retrieves data on all markets for poloniexfutures
207
+ * @see https://futures-docs.poloniex.com/#symbol-2
208
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
209
+ * @returns {object[]} an array of objects representing market data
210
+ */
211
+ const response = await this.publicGetContractsActive(params);
212
+ //
213
+ // {
214
+ // "code": "200000",
215
+ // "data": [
216
+ // {
217
+ // "symbol": "APTUSDTPERP",
218
+ // "takerFixFee": "0E-10",
219
+ // "nextFundingRateTime": "20145603",
220
+ // "makerFixFee": "0E-10",
221
+ // "type": "FFWCSX",
222
+ // "predictedFundingFeeRate": "0.000000",
223
+ // "turnoverOf24h": "386037.46704292",
224
+ // "initialMargin": "0.05",
225
+ // "isDeleverage": true,
226
+ // "createdAt": "1666681959000",
227
+ // "fundingBaseSymbol": ".APTINT8H",
228
+ // "lowPriceOf24h": "4.34499979019165",
229
+ // "lastTradePrice": "4.4090000000",
230
+ // "indexPriceTickSize": "0.001",
231
+ // "fairMethod": "FundingRate",
232
+ // "takerFeeRate": "0.00040",
233
+ // "order": "102",
234
+ // "updatedAt": "1671076377000",
235
+ // "displaySettleCurrency": "USDT",
236
+ // "indexPrice": "4.418",
237
+ // "multiplier": "1.0",
238
+ // "maxLeverage": "20",
239
+ // "fundingQuoteSymbol": ".USDTINT8H",
240
+ // "quoteCurrency": "USDT",
241
+ // "maxOrderQty": "1000000",
242
+ // "maxPrice": "1000000.0000000000",
243
+ // "maintainMargin": "0.025",
244
+ // "status": "Open",
245
+ // "displayNameMap": [Object],
246
+ // "openInterest": "2367",
247
+ // "highPriceOf24h": "4.763999938964844",
248
+ // "fundingFeeRate": "0.000000",
249
+ // "volumeOf24h": "83540.00000000",
250
+ // "riskStep": "500000",
251
+ // "isQuanto": true,
252
+ // "maxRiskLimit": "20000",
253
+ // "rootSymbol": "USDT",
254
+ // "baseCurrency": "APT",
255
+ // "firstOpenDate": "1666701000000",
256
+ // "tickSize": "0.001",
257
+ // "markMethod": "FairPrice",
258
+ // "indexSymbol": ".PAPTUSDT",
259
+ // "markPrice": "4.418",
260
+ // "minRiskLimit": "1000000",
261
+ // "settlementFixFee": "0E-10",
262
+ // "settlementSymbol": '',
263
+ // "priceChgPctOf24h": "-0.0704",
264
+ // "fundingRateSymbol": ".APTUSDTPERPFPI8H",
265
+ // "makerFeeRate": "0.00010",
266
+ // "isInverse": false,
267
+ // "lotSize": "1",
268
+ // "settleCurrency": "USDT",
269
+ // "settlementFeeRate": "0.0"
270
+ // },
271
+ // ]
272
+ // }
273
+ //
274
+ const data = this.safeValue(response, 'data', []);
275
+ return this.parseMarkets(data);
276
+ }
277
+ parseMarket(market) {
278
+ const id = this.safeString(market, 'symbol');
279
+ const baseId = this.safeString(market, 'baseCurrency');
280
+ const quoteId = this.safeString(market, 'quoteCurrency');
281
+ const settleId = this.safeString(market, 'rootSymbol');
282
+ const base = this.safeCurrencyCode(baseId);
283
+ const quote = this.safeCurrencyCode(quoteId);
284
+ const settle = this.safeCurrencyCode(settleId);
285
+ const symbol = base + '/' + quote + ':' + settle;
286
+ const inverse = this.safeValue(market, 'isInverse');
287
+ const status = this.safeString(market, 'status');
288
+ const multiplier = this.safeString(market, 'multiplier');
289
+ const tickSize = this.safeNumber(market, 'indexPriceTickSize');
290
+ const lotSize = this.safeNumber(market, 'lotSize');
291
+ const limitAmountMax = this.safeNumber(market, 'maxOrderQty');
292
+ const limitPriceMax = this.safeNumber(market, 'maxPrice');
293
+ return {
294
+ 'id': id,
295
+ 'symbol': symbol,
296
+ 'base': base,
297
+ 'quote': quote,
298
+ 'settle': settle,
299
+ 'baseId': baseId,
300
+ 'quoteId': quoteId,
301
+ 'settleId': settleId,
302
+ 'type': 'swap',
303
+ 'spot': false,
304
+ 'margin': false,
305
+ 'swap': true,
306
+ 'future': false,
307
+ 'option': false,
308
+ 'active': (status === 'Open'),
309
+ 'contract': true,
310
+ 'linear': !inverse,
311
+ 'inverse': inverse,
312
+ 'taker': this.safeNumber(market, 'takerFeeRate'),
313
+ 'maker': this.safeNumber(market, 'makerFeeRate'),
314
+ 'contractSize': this.parseNumber(Precise["default"].stringAbs(multiplier)),
315
+ 'expiry': undefined,
316
+ 'expiryDatetime': undefined,
317
+ 'strike': undefined,
318
+ 'optionType': undefined,
319
+ 'precision': {
320
+ 'amount': lotSize,
321
+ 'price': tickSize,
322
+ },
323
+ 'limits': {
324
+ 'leverage': {
325
+ 'min': this.parseNumber('1'),
326
+ 'max': this.safeNumber(market, 'maxLeverage'),
327
+ },
328
+ 'amount': {
329
+ 'min': lotSize,
330
+ 'max': limitAmountMax,
331
+ },
332
+ 'price': {
333
+ 'min': tickSize,
334
+ 'max': limitPriceMax,
335
+ },
336
+ 'cost': {
337
+ 'min': undefined,
338
+ 'max': undefined,
339
+ },
340
+ },
341
+ 'created': this.safeInteger(market, 'firstOpenDate'),
342
+ 'info': market,
343
+ };
344
+ }
345
+ parseTicker(ticker, market = undefined) {
346
+ //
347
+ // {
348
+ // "symbol": "BTCUSDTPERP", // Market of the symbol
349
+ // "sequence": 45, // Sequence number which is used to judge the continuity of the pushed messages
350
+ // "side": "sell", // Transaction side of the last traded taker order
351
+ // "price": 3600.00, // Filled price
352
+ // "size": 16, // Filled quantity
353
+ // "tradeId": "5c9dcf4170744d6f5a3d32fb", // Order ID
354
+ // "bestBidSize": 795, // Best bid size
355
+ // "bestBidPrice": 3200.00, // Best bid
356
+ // "bestAskPrice": 3600.00, // Best ask size
357
+ // "bestAskSize": 284, // Best ask
358
+ // "ts": 1553846081210004941 // Filled time - nanosecond
359
+ // }
360
+ //
361
+ // {
362
+ // "volume": 30449670, //24h Volume
363
+ // "turnover": 845169919063, //24h Turnover
364
+ // "lastPrice": 3551, //Last price
365
+ // "priceChgPct": 0.0043, //24h Change
366
+ // "ts": 1547697294838004923 //Snapshot time (nanosecond)
367
+ // }
368
+ //
369
+ const marketId = this.safeString(ticker, 'symbol');
370
+ const symbol = this.safeSymbol(marketId, market);
371
+ const timestamp = this.safeIntegerProduct(ticker, 'ts', 0.000001);
372
+ const last = this.safeString2(ticker, 'price', 'lastPrice');
373
+ const percentage = Precise["default"].stringMul(this.safeString(ticker, 'priceChgPct'), '100');
374
+ return this.safeTicker({
375
+ 'symbol': symbol,
376
+ 'timestamp': timestamp,
377
+ 'datetime': this.iso8601(timestamp),
378
+ 'high': undefined,
379
+ 'low': undefined,
380
+ 'bid': this.safeString(ticker, 'bestBidPrice'),
381
+ 'bidVolume': this.safeString(ticker, 'bestBidSize'),
382
+ 'ask': this.safeString(ticker, 'bestAskPrice'),
383
+ 'askVolume': this.safeString(ticker, 'bestAskSize'),
384
+ 'vwap': undefined,
385
+ 'open': undefined,
386
+ 'close': last,
387
+ 'last': last,
388
+ 'previousClose': undefined,
389
+ 'change': undefined,
390
+ 'percentage': percentage,
391
+ 'average': undefined,
392
+ 'baseVolume': this.safeString2(ticker, 'size', 'volume'),
393
+ 'quoteVolume': this.safeString(ticker, 'turnover'),
394
+ 'info': ticker,
395
+ }, market);
396
+ }
397
+ async fetchTicker(symbol, params = {}) {
398
+ /**
399
+ * @method
400
+ * @name poloniexfutures#fetchTicker
401
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
402
+ * @see https://futures-docs.poloniex.com/#get-real-time-ticker-2-0
403
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
404
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
405
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
406
+ */
407
+ await this.loadMarkets();
408
+ const market = this.market(symbol);
409
+ const request = {
410
+ 'symbol': market['id'],
411
+ };
412
+ const response = await this.publicGetTicker(this.extend(request, params));
413
+ //
414
+ // {
415
+ // "code": "200000",
416
+ // "data": {
417
+ // "sequence": "11574719",
418
+ // "symbol": "BTCUSDTPERP",
419
+ // "side": "sell",
420
+ // "size": "1",
421
+ // "price": "16990.1",
422
+ // "bestBidSize": "3",
423
+ // "bestBidPrice": "16990.1",
424
+ // "bestAskPrice": "16991.0",
425
+ // "tradeId": "639c8a529fd7cf0001af4157",
426
+ // "bestAskSize": "505",
427
+ // "ts": "1671203410721232337"
428
+ // }
429
+ // }
430
+ //
431
+ return this.parseTicker(this.safeValue(response, 'data', {}), market);
432
+ }
433
+ async fetchTickers(symbols = undefined, params = {}) {
434
+ /**
435
+ * @method
436
+ * @name poloniexfutures#fetchTickers
437
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
438
+ * @see https://futures-docs.poloniex.com/#get-real-time-ticker-of-all-symbols
439
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
440
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
441
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
442
+ */
443
+ await this.loadMarkets();
444
+ const response = await this.publicGetTickers(params);
445
+ return this.parseTickers(this.safeValue(response, 'data', []), symbols);
446
+ }
447
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
448
+ /**
449
+ * @method
450
+ * @name poloniexfuturesfutures#fetchOrderBook
451
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
452
+ * @see https://futures-docs.poloniex.com/#get-full-order-book-level-2
453
+ * @see https://futures-docs.poloniex.com/#get-full-order-book-level-3
454
+ * @param {string} symbol unified symbol of the market to fetch the order book for
455
+ * @param {int} [limit] the maximum amount of order book entries to return
456
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
457
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
458
+ */
459
+ await this.loadMarkets();
460
+ const level = this.safeNumber(params, 'level');
461
+ params = this.omit(params, 'level');
462
+ if (level !== undefined && level !== 2 && level !== 3) {
463
+ throw new errors.BadRequest(this.id + ' fetchOrderBook() can only return level 2 & 3');
464
+ }
465
+ const market = this.market(symbol);
466
+ const request = {
467
+ 'symbol': market['id'],
468
+ };
469
+ let response = undefined;
470
+ if (level === 3) {
471
+ response = await this.publicGetLevel3Snapshot(this.extend(request, params));
472
+ }
473
+ else {
474
+ response = await this.publicGetLevel2Snapshot(this.extend(request, params));
475
+ }
476
+ // L2
477
+ //
478
+ // {
479
+ // "code": "200000",
480
+ // "data": {
481
+ // "symbol": "BTCUSDTPERP",
482
+ // "sequence": 1669149851334,
483
+ // "asks": [
484
+ // [
485
+ // 16952,
486
+ // 12
487
+ // ],
488
+ // ],
489
+ // "bids": [
490
+ // [
491
+ // 16951.9,
492
+ // 13
493
+ // ],
494
+ // ],
495
+ // }
496
+ //
497
+ // L3
498
+ //
499
+ // {
500
+ // "code": "200000",
501
+ // "data": {
502
+ // "symbol": "BTCUSDTPERP",
503
+ // "sequence": 1669149851334,
504
+ // "asks": [
505
+ // [
506
+ // "639c95388cba5100084eabce",
507
+ // "16952.0",
508
+ // "1",
509
+ // 1671206200542484700
510
+ // ],
511
+ // ],
512
+ // "bids": [
513
+ // [
514
+ // "626659d83385c200072e690b",
515
+ // "17.0",
516
+ // "1000",
517
+ // 1650874840161291000
518
+ // ],
519
+ // ],
520
+ // }
521
+ //
522
+ const data = this.safeValue(response, 'data', {});
523
+ const timestamp = this.safeIntegerProduct(data, 'ts', 0.000001);
524
+ let orderbook = undefined;
525
+ if (level === 3) {
526
+ orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 1, 2);
527
+ }
528
+ else {
529
+ orderbook = this.parseOrderBook(data, market['symbol'], timestamp, 'bids', 'asks', 0, 1);
530
+ }
531
+ orderbook['nonce'] = this.safeInteger(data, 'sequence');
532
+ return orderbook;
533
+ }
534
+ async fetchL3OrderBook(symbol, limit = undefined, params = {}) {
535
+ /**
536
+ * @method
537
+ * @name poloniexfutures#fetchL3OrderBook
538
+ * @description fetches level 3 information on open orders with bid (buy) and ask (sell) prices, volumes and other data
539
+ * @see https://futures-docs.poloniex.com/#get-full-order-book-level-3
540
+ * @param {string} symbol unified market symbol
541
+ * @param {int} [limit] max number of orders to return, default is undefined
542
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
543
+ * @returns {object} an [order book structure]{@link https://docs.ccxt.com/#/?id=order-book-structure}
544
+ */
545
+ await this.loadMarkets();
546
+ const market = this.market(symbol);
547
+ return this.fetchOrderBook(market['id'], undefined, { 'level': 3 });
548
+ }
549
+ parseTrade(trade, market = undefined) {
550
+ //
551
+ // fetchTrades (public)
552
+ //
553
+ // {
554
+ // "sequence": 11827985,
555
+ // "side": "buy",
556
+ // "size": 101,
557
+ // "price": "16864.0000000000",
558
+ // "takerOrderId": "639c986f0ac2470007be75ee",
559
+ // "makerOrderId": "639c986fa69d280007b76111",
560
+ // "tradeId": "639c986f9fd7cf0001afd7ee",
561
+ // "ts": 1671207023485924400
562
+ // }
563
+ //
564
+ // fetchMyTrades
565
+ //
566
+ // {
567
+ // "symbol": "BTCUSDTPERP", //Ticker symbol of the contract
568
+ // "tradeId": "5ce24c1f0c19fc3c58edc47c", //Trade ID
569
+ // "orderId": "5ce24c16b210233c36ee321d", // Order ID
570
+ // "side": "sell", //Transaction side
571
+ // "liquidity": "taker", //Liquidity- taker or maker
572
+ // "price": "8302", //Filled price
573
+ // "size": 10, //Filled amount
574
+ // "value": "0.001204529", //Order value
575
+ // "feeRate": "0.0005", //Floating fees
576
+ // "fixFee": "0.00000006", //Fixed fees
577
+ // "feeCurrency": "XBT", //Charging currency
578
+ // "stop": "", //A mark to the stop order type
579
+ // "fee": "0.0000012022", //Transaction fee
580
+ // "orderType": "limit", //Order type
581
+ // "tradeType": "trade", //Trade type (trade, liquidation, ADL or settlement)
582
+ // "createdAt": 1558334496000, //Time the order created
583
+ // "settleCurrency": "XBT", //settlement currency
584
+ // "tradeTime": 1558334496000000000 //trade time in nanosecond
585
+ // }
586
+ //
587
+ const marketId = this.safeString(trade, 'symbol');
588
+ market = this.safeMarket(marketId, market, '-');
589
+ const id = this.safeString(trade, 'tradeId');
590
+ const orderId = this.safeString(trade, 'orderId');
591
+ const takerOrMaker = this.safeString(trade, 'liquidity');
592
+ let timestamp = this.safeInteger(trade, 'ts');
593
+ if (timestamp !== undefined) {
594
+ timestamp = this.parseToInt(timestamp / 1000000);
595
+ }
596
+ else {
597
+ timestamp = this.safeInteger(trade, 'createdAt');
598
+ // if it's a historical v1 trade, the exchange returns timestamp in seconds
599
+ if (('dealValue' in trade) && (timestamp !== undefined)) {
600
+ timestamp = timestamp * 1000;
601
+ }
602
+ }
603
+ const priceString = this.safeString(trade, 'price');
604
+ const amountString = this.safeString(trade, 'size');
605
+ const side = this.safeString(trade, 'side');
606
+ let fee = undefined;
607
+ const feeCostString = this.safeString(trade, 'fee');
608
+ if (feeCostString !== undefined) {
609
+ const feeCurrencyId = this.safeString(trade, 'feeCurrency');
610
+ let feeCurrency = this.safeCurrencyCode(feeCurrencyId);
611
+ if (feeCurrency === undefined) {
612
+ feeCurrency = (side === 'sell') ? market['quote'] : market['base'];
613
+ }
614
+ fee = {
615
+ 'cost': feeCostString,
616
+ 'currency': feeCurrency,
617
+ 'rate': this.safeString(trade, 'feeRate'),
618
+ };
619
+ }
620
+ let type = this.safeString(trade, 'orderType');
621
+ if (type === 'match') {
622
+ type = undefined;
623
+ }
624
+ const costString = this.safeString(trade, 'value');
625
+ return this.safeTrade({
626
+ 'info': trade,
627
+ 'id': id,
628
+ 'order': orderId,
629
+ 'timestamp': timestamp,
630
+ 'datetime': this.iso8601(timestamp),
631
+ 'symbol': market['symbol'],
632
+ 'type': type,
633
+ 'takerOrMaker': takerOrMaker,
634
+ 'side': side,
635
+ 'price': priceString,
636
+ 'amount': amountString,
637
+ 'cost': costString,
638
+ 'fee': fee,
639
+ }, market);
640
+ }
641
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
642
+ /**
643
+ * @method
644
+ * @name poloniexfutures#fetchTrades
645
+ * @description get the list of most recent trades for a particular symbol
646
+ * @see https://futures-docs.poloniex.com/#historical-data
647
+ * @param {string} symbol unified symbol of the market to fetch trades for
648
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
649
+ * @param {int} [limit] the maximum amount of trades to fetch
650
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
651
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
652
+ */
653
+ await this.loadMarkets();
654
+ const market = this.market(symbol);
655
+ const request = {
656
+ 'symbol': market['id'],
657
+ };
658
+ const response = await this.publicGetTradeHistory(this.extend(request, params));
659
+ //
660
+ // {
661
+ // "code": "200000",
662
+ // "data": [
663
+ // {
664
+ // "sequence": 11827985,
665
+ // "side": "buy",
666
+ // "size": 101,
667
+ // "price": "16864.0000000000",
668
+ // "takerOrderId": "639c986f0ac2470007be75ee",
669
+ // "makerOrderId": "639c986fa69d280007b76111",
670
+ // "tradeId": "639c986f9fd7cf0001afd7ee",
671
+ // "ts": 1671207023485924400
672
+ // },
673
+ // }
674
+ //
675
+ const trades = this.safeValue(response, 'data', []);
676
+ return this.parseTrades(trades, market, since, limit);
677
+ }
678
+ async fetchTime(params = {}) {
679
+ /**
680
+ * @method
681
+ * @name poloniexfutures#fetchTime
682
+ * @description fetches the current integer timestamp in milliseconds from the poloniexfutures server
683
+ * @see https://futures-docs.poloniex.com/#time
684
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
685
+ * @returns {int} the current integer timestamp in milliseconds from the poloniexfutures server
686
+ */
687
+ const response = await this.publicGetTimestamp(params);
688
+ //
689
+ // {
690
+ // "code":"200000",
691
+ // "msg":"success",
692
+ // "data":1546837113087
693
+ // }
694
+ //
695
+ return this.safeInteger(response, 'data');
696
+ }
697
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
698
+ /**
699
+ * @method
700
+ * @name poloniexfutures#fetchOHLCV
701
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
702
+ * @see https://futures-docs.poloniex.com/#k-chart
703
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
704
+ * @param {string} timeframe the length of time each candle represents
705
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
706
+ * @param {int} [limit] the maximum amount of candles to fetch
707
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
708
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
709
+ */
710
+ await this.loadMarkets();
711
+ const market = this.market(symbol);
712
+ const marketId = market['id'];
713
+ const parsedTimeframe = this.safeInteger(this.timeframes, timeframe);
714
+ const request = {
715
+ 'symbol': marketId,
716
+ };
717
+ if (parsedTimeframe !== undefined) {
718
+ request['granularity'] = parsedTimeframe;
719
+ }
720
+ else {
721
+ request['granularity'] = timeframe;
722
+ }
723
+ const duration = this.parseTimeframe(timeframe) * 1000;
724
+ let endAt = this.milliseconds();
725
+ if (since !== undefined) {
726
+ request['from'] = since;
727
+ if (limit === undefined) {
728
+ limit = this.safeInteger(this.options, 'fetchOHLCVLimit', 200);
729
+ }
730
+ endAt = this.sum(since, limit * duration);
731
+ request['to'] = endAt;
732
+ }
733
+ else if (limit !== undefined) {
734
+ since = endAt - limit * duration;
735
+ request['from'] = since;
736
+ }
737
+ const response = await this.publicGetKlineQuery(this.extend(request, params));
738
+ //
739
+ // {
740
+ // "code": "200000",
741
+ // "data": [
742
+ // [1636459200000, 4779.3, 4792.1, 4768.7, 4770.3, 78051],
743
+ // [1636460100000, 4770.25, 4778.55, 4757.55, 4777.25, 80164],
744
+ // [1636461000000, 4777.25, 4791.45, 4774.5, 4791.3, 51555]
745
+ // ]
746
+ // }
747
+ //
748
+ const data = this.safeValue(response, 'data', []);
749
+ return this.parseOHLCVs(data, market, timeframe, since, limit);
750
+ }
751
+ parseBalance(response) {
752
+ const result = {
753
+ 'info': response,
754
+ 'timestamp': undefined,
755
+ 'datetime': undefined,
756
+ };
757
+ const data = this.safeValue(response, 'data');
758
+ const currencyId = this.safeString(data, 'currency');
759
+ const code = this.safeCurrencyCode(currencyId);
760
+ const account = this.account();
761
+ account['free'] = this.safeString(data, 'availableBalance');
762
+ account['total'] = this.safeString(data, 'accountEquity');
763
+ result[code] = account;
764
+ return this.safeBalance(result);
765
+ }
766
+ async fetchBalance(params = {}) {
767
+ /**
768
+ * @method
769
+ * @name poloniexfutures#fetchBalance
770
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
771
+ * @see https://futures-docs.poloniex.com/#get-account-overview
772
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
773
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
774
+ */
775
+ await this.loadMarkets();
776
+ const currencyId = this.safeString(params, 'currency');
777
+ let request = {};
778
+ if (currencyId !== undefined) {
779
+ const currency = this.currency(currencyId);
780
+ request = {
781
+ 'currency': currency['id'],
782
+ };
783
+ }
784
+ const response = await this.privateGetAccountOverview(this.extend(request, params));
785
+ //
786
+ // {
787
+ // "code": "200000",
788
+ // "data": {
789
+ // "accountEquity": 0.00005,
790
+ // "unrealisedPNL": 0,
791
+ // "marginBalance": 0.00005,
792
+ // "positionMargin": 0,
793
+ // "orderMargin": 0,
794
+ // "frozenFunds": 0,
795
+ // "availableBalance": 0.00005,
796
+ // "currency": "XBT"
797
+ // }
798
+ // }
799
+ //
800
+ return this.parseBalance(response);
801
+ }
802
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
803
+ /**
804
+ * @method
805
+ * @name poloniexfutures#createOrder
806
+ * @description Create an order on the exchange
807
+ * @see https://futures-docs.poloniex.com/#place-an-order
808
+ * @param {string} symbol Unified CCXT market symbol
809
+ * @param {string} type 'limit' or 'market'
810
+ * @param {string} side 'buy' or 'sell'
811
+ * @param {float} amount the amount of currency to trade
812
+ * @param {float} [price] *ignored in "market" orders* the price at which the order is to be fullfilled at in units of the quote currency
813
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
814
+ * @param {float} [params.leverage] Leverage size of the order
815
+ * @param {float} [params.stopPrice] The price at which a trigger order is triggered at
816
+ * @param {bool} [params.reduceOnly] A mark to reduce the position size only. Set to false by default. Need to set the position size when reduceOnly is true.
817
+ * @param {string} [params.timeInForce] GTC, GTT, IOC, or FOK, default is GTC, limit orders only
818
+ * @param {string} [params.postOnly] Post only flag, invalid when timeInForce is IOC or FOK
819
+ * @param {string} [params.clientOid] client order id, defaults to uuid if not passed
820
+ * @param {string} [params.remark] remark for the order, length cannot exceed 100 utf8 characters
821
+ * @param {string} [params.stop] 'up' or 'down', defaults to 'up' if side is sell and 'down' if side is buy, requires stopPrice
822
+ * @param {string} [params.stopPriceType] TP, IP or MP, defaults to TP
823
+ * @param {bool} [params.closeOrder] set to true to close position
824
+ * @param {bool} [params.forceHold] A mark to forcely hold the funds for an order, even though it's an order to reduce the position size. This helps the order stay on the order book and not get canceled when the position size changes. Set to false by default.
825
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
826
+ */
827
+ await this.loadMarkets();
828
+ const market = this.market(symbol);
829
+ // required param, cannot be used twice
830
+ const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId', this.uuid());
831
+ params = this.omit(params, ['clientOid', 'clientOrderId']);
832
+ if (amount < 1) {
833
+ throw new errors.InvalidOrder(this.id + ' createOrder() minimum contract order amount is 1');
834
+ }
835
+ const preciseAmount = parseInt(this.amountToPrecision(symbol, amount));
836
+ const request = {
837
+ 'clientOid': clientOrderId,
838
+ 'side': side,
839
+ 'symbol': market['id'],
840
+ 'type': type,
841
+ 'size': preciseAmount,
842
+ 'leverage': 1,
843
+ };
844
+ const stopPrice = this.safeValue2(params, 'triggerPrice', 'stopPrice');
845
+ if (stopPrice) {
846
+ request['stop'] = (side === 'buy') ? 'up' : 'down';
847
+ const stopPriceType = this.safeString(params, 'stopPriceType', 'TP');
848
+ request['stopPriceType'] = stopPriceType;
849
+ request['stopPrice'] = this.priceToPrecision(symbol, stopPrice);
850
+ }
851
+ const timeInForce = this.safeStringUpper(params, 'timeInForce');
852
+ if (type === 'limit') {
853
+ if (price === undefined) {
854
+ throw new errors.ArgumentsRequired(this.id + ' createOrder() requires a price argument for limit orders');
855
+ }
856
+ else {
857
+ request['price'] = this.priceToPrecision(symbol, price);
858
+ }
859
+ if (timeInForce !== undefined) {
860
+ request['timeInForce'] = timeInForce;
861
+ }
862
+ }
863
+ const postOnly = this.safeValue(params, 'postOnly', false);
864
+ const hidden = this.safeValue(params, 'hidden');
865
+ if (postOnly && (hidden !== undefined)) {
866
+ throw new errors.BadRequest(this.id + ' createOrder() does not support the postOnly parameter together with a hidden parameter');
867
+ }
868
+ const iceberg = this.safeValue(params, 'iceberg');
869
+ if (iceberg) {
870
+ const visibleSize = this.safeValue(params, 'visibleSize');
871
+ if (visibleSize === undefined) {
872
+ throw new errors.ArgumentsRequired(this.id + ' createOrder() requires a visibleSize parameter for iceberg orders');
873
+ }
874
+ }
875
+ params = this.omit(params, ['timeInForce', 'stopPrice', 'triggerPrice']); // Time in force only valid for limit orders, exchange error when gtc for market orders
876
+ const response = await this.privatePostOrders(this.extend(request, params));
877
+ //
878
+ // {
879
+ // "code": "200000",
880
+ // "data": {
881
+ // "orderId": "619717484f1d010001510cde",
882
+ // },
883
+ // }
884
+ //
885
+ const data = this.safeValue(response, 'data', {});
886
+ return this.safeOrder({
887
+ 'id': this.safeString(data, 'orderId'),
888
+ 'clientOrderId': undefined,
889
+ 'timestamp': undefined,
890
+ 'datetime': undefined,
891
+ 'lastTradeTimestamp': undefined,
892
+ 'symbol': undefined,
893
+ 'type': undefined,
894
+ 'side': undefined,
895
+ 'price': undefined,
896
+ 'amount': undefined,
897
+ 'cost': undefined,
898
+ 'average': undefined,
899
+ 'filled': undefined,
900
+ 'remaining': undefined,
901
+ 'status': undefined,
902
+ 'fee': undefined,
903
+ 'trades': undefined,
904
+ 'timeInForce': undefined,
905
+ 'postOnly': undefined,
906
+ 'stopPrice': undefined,
907
+ 'info': response,
908
+ }, market);
909
+ }
910
+ async cancelOrder(id, symbol = undefined, params = {}) {
911
+ /**
912
+ * @method
913
+ * @name poloniexfutures#cancelOrder
914
+ * @description cancels an open order
915
+ * @see https://futures-docs.poloniex.com/#cancel-an-order
916
+ * @param {string} id order id
917
+ * @param {string} symbol unified symbol of the market the order was made in
918
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
919
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
920
+ */
921
+ await this.loadMarkets();
922
+ const request = {
923
+ 'order-id': id,
924
+ };
925
+ const response = await this.privateDeleteOrdersOrderId(this.extend(request, params));
926
+ //
927
+ // {
928
+ // "code": "200000",
929
+ // "data": {
930
+ // "cancelledOrderIds": [
931
+ // "619714b8b6353000014c505a",
932
+ // ],
933
+ // "cancelFailedOrders": [
934
+ // {
935
+ // "orderId": "63a9c5c2b9e7d70007eb0cd5",
936
+ // "orderState": "2"
937
+ // }
938
+ // ],
939
+ // },
940
+ // }
941
+ //
942
+ const data = this.safeValue(response, 'data');
943
+ const cancelledOrderIds = this.safeValue(data, 'cancelledOrderIds');
944
+ const cancelledOrderIdsLength = cancelledOrderIds.length;
945
+ if (cancelledOrderIdsLength === 0) {
946
+ throw new errors.InvalidOrder(this.id + ' cancelOrder() order already cancelled');
947
+ }
948
+ return this.parseOrder(data);
949
+ }
950
+ async fetchPositions(symbols = undefined, params = {}) {
951
+ /**
952
+ * @method
953
+ * @name poloniexfutures#fetchPositions
954
+ * @description fetch all open positions
955
+ * @see https://futures-docs.poloniex.com/#get-position-list
956
+ * @param {string[]|undefined} symbols list of unified market symbols
957
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
958
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
959
+ */
960
+ await this.loadMarkets();
961
+ const response = await this.privateGetPositions(params);
962
+ //
963
+ // {
964
+ // "code": "200000",
965
+ // "data": [
966
+ // {
967
+ // "id": "615ba79f83a3410001cde321",
968
+ // "symbol": "ETHUSDTM",
969
+ // "autoDeposit": false,
970
+ // "maintMarginReq": 0.005,
971
+ // "riskLimit": 1000000,
972
+ // "realLeverage": 18.61,
973
+ // "crossMode": false,
974
+ // "delevPercentage": 0.86,
975
+ // "openingTimestamp": 1638563515618,
976
+ // "currentTimestamp": 1638576872774,
977
+ // "currentQty": 2,
978
+ // "currentCost": 83.64200000,
979
+ // "currentComm": 0.05018520,
980
+ // "unrealisedCost": 83.64200000,
981
+ // "realisedGrossCost": 0.00000000,
982
+ // "realisedCost": 0.05018520,
983
+ // "isOpen": true,
984
+ // "markPrice": 4225.01,
985
+ // "markValue": 84.50020000,
986
+ // "posCost": 83.64200000,
987
+ // "posCross": 0.0000000000,
988
+ // "posInit": 3.63660870,
989
+ // "posComm": 0.05236717,
990
+ // "posLoss": 0.00000000,
991
+ // "posMargin": 3.68897586,
992
+ // "posMaint": 0.50637594,
993
+ // "maintMargin": 4.54717586,
994
+ // "realisedGrossPnl": 0.00000000,
995
+ // "realisedPnl": -0.05018520,
996
+ // "unrealisedPnl": 0.85820000,
997
+ // "unrealisedPnlPcnt": 0.0103,
998
+ // "unrealisedRoePcnt": 0.2360,
999
+ // "avgEntryPrice": 4182.10,
1000
+ // "liquidationPrice": 4023.00,
1001
+ // "bankruptPrice": 4000.25,
1002
+ // "settleCurrency": "USDT",
1003
+ // "isInverse": false
1004
+ // }
1005
+ // ]
1006
+ // }
1007
+ //
1008
+ const data = this.safeValue(response, 'data');
1009
+ return this.parsePositions(data, symbols);
1010
+ }
1011
+ parsePosition(position, market = undefined) {
1012
+ //
1013
+ // {
1014
+ // "code": "200000",
1015
+ // "data": [
1016
+ // {
1017
+ // "id": "615ba79f83a3410001cde321", // Position ID
1018
+ // "symbol": "ETHUSDTM", // Symbol
1019
+ // "autoDeposit": false, // Auto deposit margin or not
1020
+ // "maintMarginReq": 0.005, // Maintenance margin requirement
1021
+ // "riskLimit": 1000000, // Risk limit
1022
+ // "realLeverage": 25.92, // Leverage of the order
1023
+ // "crossMode": false, // Cross mode or not
1024
+ // "delevPercentage": 0.76, // ADL ranking percentile
1025
+ // "openingTimestamp": 1638578546031, // Open time
1026
+ // "currentTimestamp": 1638578563580, // Current timestamp
1027
+ // "currentQty": 2, // Current postion quantity
1028
+ // "currentCost": 83.787, // Current postion value
1029
+ // "currentComm": 0.0167574, // Current commission
1030
+ // "unrealisedCost": 83.787, // Unrealised value
1031
+ // "realisedGrossCost": 0.0, // Accumulated realised gross profit value
1032
+ // "realisedCost": 0.0167574, // Current realised position value
1033
+ // "isOpen": true, // Opened position or not
1034
+ // "markPrice": 4183.38, // Mark price
1035
+ // "markValue": 83.6676, // Mark value
1036
+ // "posCost": 83.787, // Position value
1037
+ // "posCross": 0.0, // added margin
1038
+ // "posInit": 3.35148, // Leverage margin
1039
+ // "posComm": 0.05228309, // Bankruptcy cost
1040
+ // "posLoss": 0.0, // Funding fees paid out
1041
+ // "posMargin": 3.40376309, // Position margin
1042
+ // "posMaint": 0.50707892, // Maintenance margin
1043
+ // "maintMargin": 3.28436309, // Position margin
1044
+ // "realisedGrossPnl": 0.0, // Accumulated realised gross profit value
1045
+ // "realisedPnl": -0.0167574, // Realised profit and loss
1046
+ // "unrealisedPnl": -0.1194, // Unrealised profit and loss
1047
+ // "unrealisedPnlPcnt": -0.0014, // Profit-loss ratio of the position
1048
+ // "unrealisedRoePcnt": -0.0356, // Rate of return on investment
1049
+ // "avgEntryPrice": 4189.35, // Average entry price
1050
+ // "liquidationPrice": 4044.55, // Liquidation price
1051
+ // "bankruptPrice": 4021.75, // Bankruptcy price
1052
+ // "settleCurrency": "USDT", // Currency used to clear and settle the trades
1053
+ // "isInverse": false
1054
+ // }
1055
+ // ]
1056
+ // }
1057
+ //
1058
+ const symbol = this.safeString(position, 'symbol');
1059
+ market = this.safeMarket(symbol, market);
1060
+ const timestamp = this.safeInteger(position, 'currentTimestamp');
1061
+ const size = this.safeString(position, 'currentQty');
1062
+ let side;
1063
+ if (Precise["default"].stringGt(size, '0')) {
1064
+ side = 'long';
1065
+ }
1066
+ else if (Precise["default"].stringLt(size, '0')) {
1067
+ side = 'short';
1068
+ }
1069
+ const notional = Precise["default"].stringAbs(this.safeString(position, 'posCost'));
1070
+ const initialMargin = this.safeString(position, 'posInit');
1071
+ const initialMarginPercentage = Precise["default"].stringDiv(initialMargin, notional);
1072
+ // const marginRatio = Precise.stringDiv (maintenanceRate, collateral);
1073
+ const unrealisedPnl = this.safeString(position, 'unrealisedPnl');
1074
+ const crossMode = this.safeValue(position, 'crossMode');
1075
+ // currently crossMode is always set to false and only isolated positions are supported
1076
+ const marginMode = crossMode ? 'cross' : 'isolated';
1077
+ return {
1078
+ 'info': position,
1079
+ 'id': undefined,
1080
+ 'symbol': this.safeString(market, 'symbol'),
1081
+ 'timestamp': timestamp,
1082
+ 'datetime': this.iso8601(timestamp),
1083
+ 'initialMargin': this.parseNumber(initialMargin),
1084
+ 'initialMarginPercentage': this.parseNumber(initialMarginPercentage),
1085
+ 'maintenanceMargin': this.safeNumber(position, 'posMaint'),
1086
+ 'maintenanceMarginPercentage': this.safeNumber(position, 'maintMarginReq'),
1087
+ 'entryPrice': this.safeNumber(position, 'avgEntryPrice'),
1088
+ 'notional': this.parseNumber(notional),
1089
+ 'leverage': this.safeNumber(position, 'realLeverage'),
1090
+ 'unrealizedPnl': this.parseNumber(unrealisedPnl),
1091
+ 'contracts': this.parseNumber(Precise["default"].stringAbs(size)),
1092
+ 'contractSize': this.safeValue(market, 'contractSize'),
1093
+ 'marginRatio': undefined,
1094
+ 'liquidationPrice': this.safeNumber(position, 'liquidationPrice'),
1095
+ 'markPrice': this.safeNumber(position, 'markPrice'),
1096
+ 'collateral': this.safeNumber(position, 'maintMargin'),
1097
+ 'marginMode': marginMode,
1098
+ 'side': side,
1099
+ 'percentage': this.parseNumber(Precise["default"].stringDiv(unrealisedPnl, initialMargin)),
1100
+ 'stopLossPrice': undefined,
1101
+ 'takeProfitPrice': undefined,
1102
+ };
1103
+ }
1104
+ async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1105
+ /**
1106
+ * @method
1107
+ * @name poloniexfutures#fetchFundingHistory
1108
+ * @description fetch the history of funding payments paid and received on this account
1109
+ * @see https://futures-docs.poloniex.com/#get-funding-history
1110
+ * @param {string} symbol unified market symbol
1111
+ * @param {int} [since] the earliest time in ms to fetch funding history for
1112
+ * @param {int} [limit] the maximum number of funding history structures to retrieve
1113
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1114
+ * @returns {object} a [funding history structure]{@link https://docs.ccxt.com/#/?id=funding-history-structure}
1115
+ */
1116
+ if (symbol === undefined) {
1117
+ throw new errors.ArgumentsRequired(this.id + ' fetchFundingHistory() requires a symbol argument');
1118
+ }
1119
+ await this.loadMarkets();
1120
+ const market = this.market(symbol);
1121
+ const request = {
1122
+ 'symbol': market['id'],
1123
+ };
1124
+ if (since !== undefined) {
1125
+ request['startAt'] = since;
1126
+ }
1127
+ if (limit !== undefined) {
1128
+ // * Since is ignored if limit is defined
1129
+ request['maxCount'] = limit;
1130
+ }
1131
+ const response = await this.privateGetFundingHistory(this.extend(request, params));
1132
+ //
1133
+ // {
1134
+ // "code": "200000",
1135
+ // "data": {
1136
+ // "dataList": [
1137
+ // {
1138
+ // "id": 239471298749817,
1139
+ // "symbol": "ETHUSDTM",
1140
+ // "timePoint": 1638532800000,
1141
+ // "fundingRate": 0.000100,
1142
+ // "markPrice": 4612.8300000000,
1143
+ // "positionQty": 12,
1144
+ // "positionCost": 553.5396000000,
1145
+ // "funding": -0.0553539600,
1146
+ // "settleCurrency": "USDT"
1147
+ // },
1148
+ // ...
1149
+ // ],
1150
+ // "hasMore": true
1151
+ // }
1152
+ // }
1153
+ //
1154
+ const data = this.safeValue(response, 'data');
1155
+ const dataList = this.safeValue(data, 'dataList', []);
1156
+ const dataListLength = dataList.length;
1157
+ const fees = [];
1158
+ for (let i = 0; i < dataListLength; i++) {
1159
+ const listItem = dataList[i];
1160
+ const timestamp = this.safeInteger(listItem, 'timePoint');
1161
+ fees.push({
1162
+ 'info': listItem,
1163
+ 'symbol': symbol,
1164
+ 'code': this.safeCurrencyCode(this.safeString(listItem, 'settleCurrency')),
1165
+ 'timestamp': timestamp,
1166
+ 'datetime': this.iso8601(timestamp),
1167
+ 'id': this.safeNumber(listItem, 'id'),
1168
+ 'amount': this.safeNumber(listItem, 'funding'),
1169
+ 'fundingRate': this.safeNumber(listItem, 'fundingRate'),
1170
+ 'markPrice': this.safeNumber(listItem, 'markPrice'),
1171
+ 'positionQty': this.safeNumber(listItem, 'positionQty'),
1172
+ 'positionCost': this.safeNumber(listItem, 'positionCost'),
1173
+ });
1174
+ }
1175
+ return fees;
1176
+ }
1177
+ async cancelAllOrders(symbol = undefined, params = {}) {
1178
+ /**
1179
+ * @method
1180
+ * @name poloniexfutures#cancelAllOrders
1181
+ * @description cancel all open orders
1182
+ * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1183
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1184
+ * @param {object} [params.stop] When true, all the trigger orders will be cancelled
1185
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1186
+ */
1187
+ await this.loadMarkets();
1188
+ const request = {};
1189
+ if (symbol !== undefined) {
1190
+ request['symbol'] = this.marketId(symbol);
1191
+ }
1192
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1193
+ params = this.omit(params, ['stop', 'trigger']);
1194
+ let response = undefined;
1195
+ if (stop) {
1196
+ response = await this.privateDeleteStopOrders(this.extend(request, params));
1197
+ }
1198
+ else {
1199
+ response = await this.privateDeleteOrders(this.extend(request, params));
1200
+ }
1201
+ //
1202
+ // {
1203
+ // "code": "200000",
1204
+ // "data": {
1205
+ // "cancelledOrderIds": [
1206
+ // "619714b8b6353000014c505a",
1207
+ // ],
1208
+ // },
1209
+ // }
1210
+ //
1211
+ const data = this.safeValue(response, 'data');
1212
+ const result = [];
1213
+ const cancelledOrderIds = this.safeValue(data, 'cancelledOrderIds');
1214
+ const cancelledOrderIdsLength = cancelledOrderIds.length;
1215
+ for (let i = 0; i < cancelledOrderIdsLength; i++) {
1216
+ const cancelledOrderId = this.safeString(cancelledOrderIds, i);
1217
+ result.push({
1218
+ 'id': cancelledOrderId,
1219
+ 'clientOrderId': undefined,
1220
+ 'timestamp': undefined,
1221
+ 'datetime': undefined,
1222
+ 'lastTradeTimestamp': undefined,
1223
+ 'symbol': undefined,
1224
+ 'type': undefined,
1225
+ 'side': undefined,
1226
+ 'price': undefined,
1227
+ 'amount': undefined,
1228
+ 'cost': undefined,
1229
+ 'average': undefined,
1230
+ 'filled': undefined,
1231
+ 'remaining': undefined,
1232
+ 'status': undefined,
1233
+ 'fee': undefined,
1234
+ 'trades': undefined,
1235
+ 'timeInForce': undefined,
1236
+ 'postOnly': undefined,
1237
+ 'stopPrice': undefined,
1238
+ 'info': response,
1239
+ });
1240
+ }
1241
+ return result;
1242
+ }
1243
+ async fetchOrdersByStatus(status, symbol = undefined, since = undefined, limit = undefined, params = {}) {
1244
+ /**
1245
+ * @method
1246
+ * @name poloniexfutures#fetchOrdersByStatus
1247
+ * @description fetches a list of orders placed on the exchange
1248
+ * @see https://futures-docs.poloniex.com/#get-order-list
1249
+ * @see https://futures-docs.poloniex.com/#get-untriggered-stop-order-list
1250
+ * @param {string} status 'active' or 'closed', only 'active' is valid for stop orders
1251
+ * @param {string} symbol unified symbol for the market to retrieve orders from
1252
+ * @param {int} [since] timestamp in ms of the earliest order to retrieve
1253
+ * @param {int} [limit] The maximum number of orders to retrieve
1254
+ * @param {object} [params] exchange specific parameters
1255
+ * @param {bool} [params.stop] set to true to retrieve untriggered stop orders
1256
+ * @param {int} [params.until] End time in ms
1257
+ * @param {string} [params.side] buy or sell
1258
+ * @param {string} [params.type] limit or market
1259
+ * @returns An [array of order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1260
+ */
1261
+ await this.loadMarkets();
1262
+ const stop = this.safeValue2(params, 'stop', 'trigger');
1263
+ const until = this.safeInteger2(params, 'until', 'till');
1264
+ params = this.omit(params, ['triger', 'stop', 'until', 'till']);
1265
+ if (status === 'closed') {
1266
+ status = 'done';
1267
+ }
1268
+ const request = {};
1269
+ if (!stop) {
1270
+ request['status'] = (status === 'open') ? 'active' : 'done';
1271
+ }
1272
+ else if (status !== 'open') {
1273
+ throw new errors.BadRequest(this.id + ' fetchOrdersByStatus() can only fetch untriggered stop orders');
1274
+ }
1275
+ let market = undefined;
1276
+ if (symbol !== undefined) {
1277
+ market = this.market(symbol);
1278
+ request['symbol'] = market['id'];
1279
+ }
1280
+ if (since !== undefined) {
1281
+ request['startAt'] = since;
1282
+ }
1283
+ if (until !== undefined) {
1284
+ request['endAt'] = until;
1285
+ }
1286
+ let response = undefined;
1287
+ if (stop) {
1288
+ response = await this.privateGetStopOrders(this.extend(request, params));
1289
+ }
1290
+ else {
1291
+ response = await this.privateGetOrders(this.extend(request, params));
1292
+ }
1293
+ //
1294
+ // {
1295
+ // "code": "200000",
1296
+ // "data": {
1297
+ // "totalNum": 1,
1298
+ // "totalPage": 1,
1299
+ // "pageSize": 50,
1300
+ // "currentPage": 1,
1301
+ // "items": [
1302
+ // {
1303
+ // "symbol": "ADAUSDTPERP",
1304
+ // "leverage": "1",
1305
+ // "hidden": false,
1306
+ // "forceHold": false,
1307
+ // "closeOrder": false,
1308
+ // "type": "limit",
1309
+ // "isActive": true,
1310
+ // "createdAt": 1678936920000,
1311
+ // "orderTime": 1678936920480905922,
1312
+ // "price": "0.3",
1313
+ // "iceberg": false,
1314
+ // "stopTriggered": false,
1315
+ // "id": "64128b582cc0710007a3c840",
1316
+ // "value": "3",
1317
+ // "timeInForce": "GTC",
1318
+ // "updatedAt": 1678936920000,
1319
+ // "side": "buy",
1320
+ // "stopPriceType": "",
1321
+ // "dealValue": "0",
1322
+ // "dealSize": 0,
1323
+ // "settleCurrency": "USDT",
1324
+ // "stp": "",
1325
+ // "filledValue": "0",
1326
+ // "postOnly": false,
1327
+ // "size": 1,
1328
+ // "stop": "",
1329
+ // "filledSize": 0,
1330
+ // "reduceOnly": false,
1331
+ // "marginType": 1,
1332
+ // "cancelExist": false,
1333
+ // "clientOid": "ba669f39-dfcc-4664-9801-a42d06e59c2e",
1334
+ // "status": "open"
1335
+ // }
1336
+ // ]
1337
+ // }
1338
+ // }
1339
+ //
1340
+ const responseData = this.safeValue(response, 'data', {});
1341
+ const orders = this.safeValue(responseData, 'items', []);
1342
+ const ordersLength = orders.length;
1343
+ const result = [];
1344
+ for (let i = 0; i < ordersLength; i++) {
1345
+ const order = orders[i];
1346
+ const orderStatus = this.safeString(order, 'status');
1347
+ if (status === orderStatus) {
1348
+ result.push(orders[i]);
1349
+ }
1350
+ }
1351
+ return this.parseOrders(result, market, since, limit);
1352
+ }
1353
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1354
+ /**
1355
+ * @method
1356
+ * @name poloniexfutures#fetchOpenOrders
1357
+ * @description fetch all unfilled currently open orders
1358
+ * @see https://futures-docs.poloniex.com/#get-order-list
1359
+ * @see https://futures-docs.poloniex.com/#get-untriggered-stop-order-list
1360
+ * @param {string} symbol unified market symbol
1361
+ * @param {int} [since] the earliest time in ms to fetch open orders for
1362
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
1363
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1364
+ * @param {int} [params.till] end time in ms
1365
+ * @param {string} [params.side] buy or sell
1366
+ * @param {string} [params.type] limit, or market
1367
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1368
+ */
1369
+ return await this.fetchOrdersByStatus('open', symbol, since, limit, params);
1370
+ }
1371
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1372
+ /**
1373
+ * @method
1374
+ * @name poloniexfutures#fetchClosedOrders
1375
+ * @description fetches information on multiple closed orders made by the user
1376
+ * @see https://futures-docs.poloniex.com/#get-order-list
1377
+ * @see https://futures-docs.poloniex.com/#get-untriggered-stop-order-list
1378
+ * @param {string} symbol unified market symbol of the market orders were made in
1379
+ * @param {int} [since] the earliest time in ms to fetch orders for
1380
+ * @param {int} [limit] the maximum number of order structures to retrieve
1381
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1382
+ * @param {int} [params.till] end time in ms
1383
+ * @param {string} [params.side] buy or sell
1384
+ * @param {string} [params.type] limit, or market
1385
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1386
+ */
1387
+ return await this.fetchOrdersByStatus('closed', symbol, since, limit, params);
1388
+ }
1389
+ async fetchOrder(id = undefined, symbol = undefined, params = {}) {
1390
+ /**
1391
+ * @method
1392
+ * @name poloniexfutures#fetchOrder
1393
+ * @description fetches information on an order made by the user
1394
+ * @see https://futures-docs.poloniex.com/#get-details-of-a-single-order
1395
+ * @see https://futures-docs.poloniex.com/#get-single-order-by-clientoid
1396
+ * @param {string} symbol unified symbol of the market the order was made in
1397
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1398
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1399
+ */
1400
+ await this.loadMarkets();
1401
+ const request = {};
1402
+ let response = undefined;
1403
+ if (id === undefined) {
1404
+ const clientOrderId = this.safeString2(params, 'clientOid', 'clientOrderId');
1405
+ if (clientOrderId === undefined) {
1406
+ throw new errors.InvalidOrder(this.id + ' fetchOrder() requires parameter id or params.clientOid');
1407
+ }
1408
+ request['clientOid'] = clientOrderId;
1409
+ params = this.omit(params, ['clientOid', 'clientOrderId']);
1410
+ response = await this.privateGetClientOrderIdClientOid(this.extend(request, params));
1411
+ }
1412
+ else {
1413
+ request['order-id'] = id;
1414
+ response = await this.privateGetOrdersOrderId(this.extend(request, params));
1415
+ }
1416
+ //
1417
+ // {
1418
+ // "code": "200000",
1419
+ // "data": {
1420
+ // "symbol": "ADAUSDTPERP",
1421
+ // "leverage": "1",
1422
+ // "hidden": false,
1423
+ // "forceHold": false,
1424
+ // "closeOrder": false,
1425
+ // "type": "market",
1426
+ // "isActive": false,
1427
+ // "createdAt": 1678929587000,
1428
+ // "orderTime": 1678929587248115582,
1429
+ // "iceberg": false,
1430
+ // "stopTriggered": false,
1431
+ // "id": "64126eb38c6919000737dcdc",
1432
+ // "value": "3.1783",
1433
+ // "timeInForce": "GTC",
1434
+ // "updatedAt": 1678929587000,
1435
+ // "side": "buy",
1436
+ // "stopPriceType": "",
1437
+ // "dealValue": "3.1783",
1438
+ // "dealSize": 1,
1439
+ // "settleCurrency": "USDT",
1440
+ // "trades": [
1441
+ // {
1442
+ // "feePay": "0.00158915",
1443
+ // "tradeId": "64126eb36803eb0001ff99bc"
1444
+ // }
1445
+ // ],
1446
+ // "endAt": 1678929587000,
1447
+ // "stp": "",
1448
+ // "filledValue": "3.1783",
1449
+ // "postOnly": false,
1450
+ // "size": 1,
1451
+ // "stop": "",
1452
+ // "filledSize": 1,
1453
+ // "reduceOnly": false,
1454
+ // "marginType": 1,
1455
+ // "cancelExist": false,
1456
+ // "clientOid": "d19e8fcb-2df4-44bc-afd4-67dd42048246",
1457
+ // "status": "done"
1458
+ // }
1459
+ // }
1460
+ //
1461
+ const market = (symbol !== undefined) ? this.market(symbol) : undefined;
1462
+ const responseData = this.safeValue(response, 'data');
1463
+ return this.parseOrder(responseData, market);
1464
+ }
1465
+ parseOrder(order, market = undefined) {
1466
+ //
1467
+ // createOrder
1468
+ //
1469
+ // {
1470
+ // "code": "200000",
1471
+ // "data": {
1472
+ // "orderId": "619717484f1d010001510cde",
1473
+ // },
1474
+ // }
1475
+ //
1476
+ // fetchOrder
1477
+ //
1478
+ // {
1479
+ // "symbol": "ADAUSDTPERP",
1480
+ // "leverage": "1",
1481
+ // "hidden": false,
1482
+ // "forceHold": false,
1483
+ // "closeOrder": false,
1484
+ // "type": "market",
1485
+ // "isActive": false,
1486
+ // "createdAt": 1678929587000,
1487
+ // "orderTime": 1678929587248115582,
1488
+ // "iceberg": false,
1489
+ // "stopTriggered": false,
1490
+ // "id": "64126eb38c6919000737dcdc",
1491
+ // "value": "3.1783",
1492
+ // "timeInForce": "GTC",
1493
+ // "updatedAt": 1678929587000,
1494
+ // "side": "buy",
1495
+ // "stopPriceType": "",
1496
+ // "dealValue": "3.1783",
1497
+ // "dealSize": 1,
1498
+ // "settleCurrency": "USDT",
1499
+ // "trades": [
1500
+ // {
1501
+ // "feePay": "0.00158915",
1502
+ // "tradeId": "64126eb36803eb0001ff99bc"
1503
+ // }
1504
+ // ],
1505
+ // "endAt": 1678929587000,
1506
+ // "stp": "",
1507
+ // "filledValue": "3.1783",
1508
+ // "postOnly": false,
1509
+ // "size": 1,
1510
+ // "stop": "",
1511
+ // "filledSize": 1,
1512
+ // "reduceOnly": false,
1513
+ // "marginType": 1,
1514
+ // "cancelExist": false,
1515
+ // "clientOid": "d19e8fcb-2df4-44bc-afd4-67dd42048246",
1516
+ // "status": "done"
1517
+ // }
1518
+ //
1519
+ // cancelOrder
1520
+ //
1521
+ // {
1522
+ // "cancelledOrderIds": [
1523
+ // "619714b8b6353000014c505a",
1524
+ // ],
1525
+ // "cancelFailedOrders": [
1526
+ // {
1527
+ // "orderId": "63a9c5c2b9e7d70007eb0cd5",
1528
+ // "orderState": "2"
1529
+ // }
1530
+ // ],
1531
+ // },
1532
+ //
1533
+ const marketId = this.safeString(order, 'symbol');
1534
+ market = this.safeMarket(marketId, market);
1535
+ const timestamp = this.safeInteger(order, 'createdAt');
1536
+ // price is zero for market order
1537
+ // omitZero is called in safeOrder2
1538
+ const feeCurrencyId = this.safeString(order, 'feeCurrency');
1539
+ const filled = this.safeString(order, 'dealSize');
1540
+ const rawCost = this.safeString2(order, 'dealFunds', 'filledValue');
1541
+ let average = undefined;
1542
+ if (Precise["default"].stringGt(filled, '0')) {
1543
+ const contractSize = this.safeString(market, 'contractSize');
1544
+ if (market['linear']) {
1545
+ average = Precise["default"].stringDiv(rawCost, Precise["default"].stringMul(contractSize, filled));
1546
+ }
1547
+ else {
1548
+ average = Precise["default"].stringDiv(Precise["default"].stringMul(contractSize, filled), rawCost);
1549
+ }
1550
+ }
1551
+ // precision reported by their api is 8 d.p.
1552
+ // const average = Precise.stringDiv (rawCost, Precise.stringMul (filled, market['contractSize']));
1553
+ // bool
1554
+ const isActive = this.safeValue(order, 'isActive', false);
1555
+ const cancelExist = this.safeValue(order, 'cancelExist', false);
1556
+ const status = isActive ? 'open' : 'closed';
1557
+ let id = this.safeString(order, 'id');
1558
+ if ('cancelledOrderIds' in order) {
1559
+ const cancelledOrderIds = this.safeValue(order, 'cancelledOrderIds');
1560
+ id = this.safeString(cancelledOrderIds, 0);
1561
+ }
1562
+ return this.safeOrder({
1563
+ 'info': order,
1564
+ 'id': id,
1565
+ 'clientOrderId': this.safeString(order, 'clientOid'),
1566
+ 'symbol': this.safeString(market, 'symbol'),
1567
+ 'type': this.safeString(order, 'type'),
1568
+ 'timeInForce': this.safeString(order, 'timeInForce'),
1569
+ 'postOnly': this.safeValue(order, 'postOnly'),
1570
+ 'side': this.safeString(order, 'side'),
1571
+ 'amount': this.safeString(order, 'size'),
1572
+ 'price': this.safeString(order, 'price'),
1573
+ 'stopPrice': this.safeString(order, 'stopPrice'),
1574
+ 'cost': this.safeString(order, 'dealValue'),
1575
+ 'filled': filled,
1576
+ 'remaining': undefined,
1577
+ 'timestamp': timestamp,
1578
+ 'datetime': this.iso8601(timestamp),
1579
+ 'fee': {
1580
+ 'currency': this.safeCurrencyCode(feeCurrencyId),
1581
+ 'cost': this.safeString(order, 'fee'),
1582
+ },
1583
+ 'status': cancelExist ? 'canceled' : status,
1584
+ 'lastTradeTimestamp': undefined,
1585
+ 'average': average,
1586
+ 'trades': undefined,
1587
+ }, market);
1588
+ }
1589
+ async fetchFundingRate(symbol, params = {}) {
1590
+ /**
1591
+ * @method
1592
+ * @name poloniexfutures#fetchFundingRate
1593
+ * @description fetch the current funding rate
1594
+ * @see https://futures-docs.poloniex.com/#get-premium-index
1595
+ * @param {string} symbol unified market symbol
1596
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1597
+ * @returns {object} a [funding rate structure]{@link https://docs.ccxt.com/#/?id=funding-rate-structure}
1598
+ */
1599
+ await this.loadMarkets();
1600
+ const market = this.market(symbol);
1601
+ const request = {
1602
+ 'symbol': market['id'],
1603
+ };
1604
+ const response = await this.publicGetFundingRateSymbolCurrent(this.extend(request, params));
1605
+ //
1606
+ // {
1607
+ // "symbol": ".BTCUSDTPERPFPI8H",
1608
+ // "granularity": 28800000,
1609
+ // "timePoint": 1558000800000,
1610
+ // "value": 0.00375,
1611
+ // "predictedValue": 0.00375
1612
+ // }
1613
+ //
1614
+ const data = this.safeValue(response, 'data');
1615
+ const fundingTimestamp = this.safeInteger(data, 'timePoint');
1616
+ // the website displayes the previous funding rate as "funding rate"
1617
+ return {
1618
+ 'info': data,
1619
+ 'symbol': market['symbol'],
1620
+ 'markPrice': undefined,
1621
+ 'indexPrice': undefined,
1622
+ 'interestRate': undefined,
1623
+ 'estimatedSettlePrice': undefined,
1624
+ 'timestamp': undefined,
1625
+ 'datetime': undefined,
1626
+ 'fundingRate': this.safeNumber(data, 'predictedValue'),
1627
+ 'fundingTimestamp': undefined,
1628
+ 'fundingDatetime': undefined,
1629
+ 'nextFundingRate': undefined,
1630
+ 'nextFundingTimestamp': undefined,
1631
+ 'nextFundingDatetime': undefined,
1632
+ 'previousFundingRate': this.safeNumber(data, 'value'),
1633
+ 'previousFundingTimestamp': fundingTimestamp,
1634
+ 'previousFundingDatetime': this.iso8601(fundingTimestamp),
1635
+ };
1636
+ }
1637
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1638
+ /**
1639
+ * @method
1640
+ * @name poloniexfutures#fetchMyTrades
1641
+ * @description fetch all trades made by the user
1642
+ * @see https://futures-docs.poloniex.com/#get-fills
1643
+ * @param {string} symbol unified market symbol
1644
+ * @param {int} [since] the earliest time in ms to fetch trades for
1645
+ * @param {int} [limit] the maximum number of trades structures to retrieve
1646
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1647
+ * @param {string} orderIdFills filles for a specific order (other parameters can be ignored if specified)
1648
+ * @param {string} side buy or sell
1649
+ * @param {string} type limit, market, limit_stop or market_stop
1650
+ * @param {int} endAt end time (milisecond)
1651
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1652
+ */
1653
+ await this.loadMarkets();
1654
+ const request = {};
1655
+ let market = undefined;
1656
+ if (symbol !== undefined) {
1657
+ market = this.market(symbol);
1658
+ request['symbol'] = market['id'];
1659
+ }
1660
+ if (since !== undefined) {
1661
+ request['startAt'] = since;
1662
+ }
1663
+ const response = await this.privateGetFills(this.extend(request, params));
1664
+ //
1665
+ // {
1666
+ // "code": "200000",
1667
+ // "data": {
1668
+ // "currentPage":1,
1669
+ // "pageSize":1,
1670
+ // "totalNum":251915,
1671
+ // "totalPage":251915,
1672
+ // "items":[
1673
+ // {
1674
+ // "symbol": "BTCUSDTPERP", //Ticker symbol of the contract
1675
+ // "tradeId": "5ce24c1f0c19fc3c58edc47c", //Trade ID
1676
+ // "orderId": "5ce24c16b210233c36ee321d", // Order ID
1677
+ // "side": "sell", //Transaction side
1678
+ // "liquidity": "taker", //Liquidity- taker or maker
1679
+ // "price": "8302", //Filled price
1680
+ // "size": 10, //Filled amount
1681
+ // "value": "0.001204529", //Order value
1682
+ // "feeRate": "0.0005", //Floating fees
1683
+ // "fixFee": "0.00000006", //Fixed fees
1684
+ // "feeCurrency": "XBT", //Charging currency
1685
+ // "stop": "", //A mark to the stop order type
1686
+ // "fee": "0.0000012022", //Transaction fee
1687
+ // "orderType": "limit", //Order type
1688
+ // "tradeType": "trade", //Trade type (trade, liquidation, ADL or settlement)
1689
+ // "createdAt": 1558334496000, //Time the order created
1690
+ // "settleCurrency": "XBT", //settlement currency
1691
+ // "tradeTime": 1558334496000000000 //trade time in nanosecond
1692
+ // }
1693
+ // ]
1694
+ // }
1695
+ // }
1696
+ //
1697
+ const data = this.safeValue(response, 'data', {});
1698
+ const trades = this.safeValue(data, 'items', {});
1699
+ return this.parseTrades(trades, market, since, limit);
1700
+ }
1701
+ async setMarginMode(marginMode, symbol, params = {}) {
1702
+ /**
1703
+ * @method
1704
+ * @name poloniexfutures#setMarginMode
1705
+ * @description set margin mode to 'cross' or 'isolated'
1706
+ * @see https://futures-docs.poloniex.com/#change-margin-mode
1707
+ * @param {int} marginMode 0 (isolated) or 1 (cross)
1708
+ * @param {string} symbol unified market symbol
1709
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1710
+ * @returns {object} response from the exchange
1711
+ */
1712
+ if (symbol === undefined) {
1713
+ throw new errors.ArgumentsRequired(this.id + ' setMarginMode() requires a symbol argument');
1714
+ }
1715
+ if ((marginMode !== 0) && (marginMode !== 1)) {
1716
+ throw new errors.ArgumentsRequired(this.id + ' setMarginMode() marginMode must be 0 (isolated) or 1 (cross)');
1717
+ }
1718
+ await this.loadMarkets();
1719
+ const market = this.market(symbol);
1720
+ const request = {
1721
+ 'symbol': market['id'],
1722
+ 'marginType': marginMode,
1723
+ };
1724
+ return await this.privatePostMarginTypeChange(request);
1725
+ }
1726
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1727
+ let url = this.urls['api'][api];
1728
+ const versions = this.safeValue(this.options, 'versions', {});
1729
+ const apiVersions = this.safeValue(versions, api, {});
1730
+ const methodVersions = this.safeValue(apiVersions, method, {});
1731
+ const defaultVersion = this.safeString(methodVersions, path, this.version);
1732
+ const version = this.safeString(params, 'version', defaultVersion);
1733
+ const tail = '/api/' + version + '/' + this.implodeParams(path, params);
1734
+ url += tail;
1735
+ const query = this.omit(params, this.extractParams(path));
1736
+ const queryLength = Object.keys(query).length;
1737
+ if (api === 'public') {
1738
+ if (queryLength) {
1739
+ url += '?' + this.urlencode(query);
1740
+ }
1741
+ }
1742
+ else {
1743
+ this.checkRequiredCredentials();
1744
+ let endpoint = '/api/v1/' + this.implodeParams(path, params);
1745
+ const bodyEncoded = this.urlencode(query);
1746
+ if (method !== 'GET' && method !== 'HEAD') {
1747
+ body = query;
1748
+ }
1749
+ else {
1750
+ if (queryLength && bodyEncoded !== '') {
1751
+ url += '?' + bodyEncoded;
1752
+ endpoint += '?' + bodyEncoded;
1753
+ }
1754
+ }
1755
+ const now = this.milliseconds().toString();
1756
+ let endpart = '';
1757
+ if (body !== undefined) {
1758
+ body = this.json(query);
1759
+ endpart = body;
1760
+ }
1761
+ const payload = now + method + endpoint + endpart;
1762
+ const signature = this.hmac(this.encode(payload), this.encode(this.secret), sha256.sha256, 'base64');
1763
+ headers = {
1764
+ 'PF-API-SIGN': signature,
1765
+ 'PF-API-TIMESTAMP': now,
1766
+ 'PF-API-KEY': this.apiKey,
1767
+ 'PF-API-PASSPHRASE': this.password,
1768
+ };
1769
+ headers['Content-Type'] = 'application/json';
1770
+ }
1771
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1772
+ }
1773
+ handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1774
+ if (!response) {
1775
+ this.throwBroadlyMatchedException(this.exceptions['broad'], body, body);
1776
+ return undefined;
1777
+ }
1778
+ //
1779
+ // bad
1780
+ // { "code": "400100", "msg": "validation.createOrder.clientOidIsRequired" }
1781
+ // good
1782
+ // { code: "200000", data: { ... }}
1783
+ //
1784
+ const errorCode = this.safeString(response, 'code');
1785
+ const message = this.safeString(response, 'msg', '');
1786
+ const feedback = this.id + ' ' + message;
1787
+ this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
1788
+ this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
1789
+ this.throwBroadlyMatchedException(this.exceptions['broad'], body, feedback);
1790
+ return undefined;
1791
+ }
1792
+ }
1793
+
1794
+ module.exports = poloniexfutures;