ccxt 4.2.11 → 4.2.13

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 (392) hide show
  1. package/README.md +5 -5
  2. package/build.sh +2 -2
  3. package/dist/ccxt.browser.js +1347 -490
  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 +2209 -0
  125. package/dist/cjs/js/src/binance.js +9736 -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 +3807 -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 +8291 -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 +3424 -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 +7072 -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 +9049 -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 +761 -0
  185. package/dist/cjs/js/src/indodax.js +1069 -0
  186. package/dist/cjs/js/src/kraken.js +2857 -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 +2851 -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 +7330 -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 +4722 -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 +1608 -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 +1867 -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 +2765 -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/js/ccxt.d.ts +1 -1
  329. package/js/ccxt.js +1 -1
  330. package/js/src/abstract/bigone.d.ts +18 -0
  331. package/js/src/abstract/binance.d.ts +2 -0
  332. package/js/src/abstract/binancecoinm.d.ts +2 -0
  333. package/js/src/abstract/binanceus.d.ts +2 -0
  334. package/js/src/abstract/binanceusdm.d.ts +2 -0
  335. package/js/src/abstract/bingx.d.ts +2 -0
  336. package/js/src/abstract/bybit.d.ts +1 -0
  337. package/js/src/abstract/gate.d.ts +11 -0
  338. package/js/src/abstract/gateio.d.ts +11 -0
  339. package/js/src/abstract/okx.d.ts +1 -0
  340. package/js/src/alpaca.js +18 -18
  341. package/js/src/base/Exchange.d.ts +5 -1
  342. package/js/src/base/Exchange.js +101 -12
  343. package/js/src/bigone.d.ts +3 -2
  344. package/js/src/bigone.js +429 -167
  345. package/js/src/binance.js +48 -34
  346. package/js/src/bingx.js +115 -38
  347. package/js/src/bitfinex.d.ts +2 -2
  348. package/js/src/bitfinex.js +2 -3
  349. package/js/src/bitget.js +33 -13
  350. package/js/src/bitmart.d.ts +2 -2
  351. package/js/src/bitmart.js +5 -5
  352. package/js/src/bitmex.js +1 -0
  353. package/js/src/bybit.js +2 -0
  354. package/js/src/coinbase.d.ts +26 -3
  355. package/js/src/coinbase.js +176 -26
  356. package/js/src/coinlist.js +3 -4
  357. package/js/src/coinone.js +1 -1
  358. package/js/src/coinsph.js +2 -3
  359. package/js/src/deribit.js +1 -0
  360. package/js/src/gate.d.ts +4 -4
  361. package/js/src/gate.js +96 -59
  362. package/js/src/gemini.js +1 -1
  363. package/js/src/hitbtc.d.ts +4 -4
  364. package/js/src/hitbtc.js +2 -3
  365. package/js/src/htx.d.ts +1 -0
  366. package/js/src/htx.js +29 -7
  367. package/js/src/huobijp.js +2 -3
  368. package/js/src/independentreserve.js +7 -5
  369. package/js/src/kraken.js +3 -6
  370. package/js/src/lbank.js +59 -33
  371. package/js/src/mexc.js +2 -1
  372. package/js/src/oceanex.js +1 -1
  373. package/js/src/okx.js +14 -3
  374. package/js/src/phemex.js +9 -2
  375. package/js/src/pro/binance.d.ts +2 -23
  376. package/js/src/pro/binance.js +58 -22
  377. package/js/src/pro/coinbase.d.ts +2 -2
  378. package/js/src/pro/coinbase.js +4 -1
  379. package/js/src/pro/coinbasepro.d.ts +2 -2
  380. package/js/src/pro/hitbtc.d.ts +2 -2
  381. package/js/src/pro/kraken.js +1 -1
  382. package/js/src/pro/okx.d.ts +1 -0
  383. package/js/src/pro/okx.js +52 -2
  384. package/js/src/pro/poloniex.d.ts +2 -2
  385. package/js/src/probit.js +4 -2
  386. package/js/src/upbit.d.ts +3 -101
  387. package/js/src/upbit.js +12 -12
  388. package/js/src/wavesexchange.js +1 -1
  389. package/js/src/woo.d.ts +2 -0
  390. package/js/src/woo.js +52 -0
  391. package/package.json +1 -1
  392. package/skip-tests.json +5 -0
@@ -0,0 +1,2765 @@
1
+ 'use strict';
2
+
3
+ var woo$1 = require('./abstract/woo.js');
4
+ var errors = require('./base/errors.js');
5
+ var Precise = require('./base/Precise.js');
6
+ var number = require('./base/functions/number.js');
7
+ var sha256 = require('./static_dependencies/noble-hashes/sha256.js');
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * @class woo
13
+ * @augments Exchange
14
+ */
15
+ class woo extends woo$1 {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'woo',
19
+ 'name': 'WOO X',
20
+ 'countries': ['KY'],
21
+ 'rateLimit': 100,
22
+ 'version': 'v1',
23
+ 'certified': true,
24
+ 'pro': true,
25
+ 'hostname': 'woo.org',
26
+ 'has': {
27
+ 'CORS': undefined,
28
+ 'spot': true,
29
+ 'margin': true,
30
+ 'swap': true,
31
+ 'future': false,
32
+ 'option': false,
33
+ 'addMargin': false,
34
+ 'cancelAllOrders': true,
35
+ 'cancelOrder': true,
36
+ 'cancelWithdraw': false,
37
+ 'closeAllPositions': false,
38
+ 'closePosition': false,
39
+ 'createDepositAddress': false,
40
+ 'createMarketBuyOrderWithCost': true,
41
+ 'createMarketOrder': false,
42
+ 'createMarketOrderWithCost': false,
43
+ 'createMarketSellOrderWithCost': false,
44
+ 'createOrder': true,
45
+ 'createReduceOnlyOrder': true,
46
+ 'createStopLimitOrder': false,
47
+ 'createStopMarketOrder': false,
48
+ 'createStopOrder': false,
49
+ 'createTrailingAmountOrder': true,
50
+ 'createTrailingPercentOrder': true,
51
+ 'fetchAccounts': true,
52
+ 'fetchBalance': true,
53
+ 'fetchCanceledOrders': false,
54
+ 'fetchClosedOrder': false,
55
+ 'fetchClosedOrders': false,
56
+ 'fetchCurrencies': true,
57
+ 'fetchDepositAddress': false,
58
+ 'fetchDeposits': true,
59
+ 'fetchDepositsWithdrawals': true,
60
+ 'fetchFundingHistory': true,
61
+ 'fetchFundingRate': true,
62
+ 'fetchFundingRateHistory': true,
63
+ 'fetchFundingRates': true,
64
+ 'fetchIndexOHLCV': false,
65
+ 'fetchLedger': true,
66
+ 'fetchLeverage': true,
67
+ 'fetchMarginMode': false,
68
+ 'fetchMarkets': true,
69
+ 'fetchMarkOHLCV': false,
70
+ 'fetchMyTrades': true,
71
+ 'fetchOHLCV': true,
72
+ 'fetchOpenInterestHistory': false,
73
+ 'fetchOpenOrder': false,
74
+ 'fetchOpenOrders': false,
75
+ 'fetchOrder': true,
76
+ 'fetchOrderBook': true,
77
+ 'fetchOrders': true,
78
+ 'fetchOrderTrades': true,
79
+ 'fetchPosition': true,
80
+ 'fetchPositionMode': false,
81
+ 'fetchPositions': true,
82
+ 'fetchPremiumIndexOHLCV': false,
83
+ 'fetchStatus': false,
84
+ 'fetchTicker': false,
85
+ 'fetchTickers': false,
86
+ 'fetchTime': false,
87
+ 'fetchTrades': true,
88
+ 'fetchTradingFee': false,
89
+ 'fetchTradingFees': true,
90
+ 'fetchTransactions': 'emulated',
91
+ 'fetchTransfers': true,
92
+ 'fetchWithdrawals': true,
93
+ 'reduceMargin': false,
94
+ 'setLeverage': true,
95
+ 'setMargin': false,
96
+ 'transfer': true,
97
+ 'withdraw': true, // exchange have that endpoint disabled atm, but was once implemented in ccxt per old docs: https://kronosresearch.github.io/wootrade-documents/#token-withdraw
98
+ },
99
+ 'timeframes': {
100
+ '1m': '1m',
101
+ '5m': '5m',
102
+ '15m': '15m',
103
+ '30m': '30m',
104
+ '1h': '1h',
105
+ '4h': '4h',
106
+ '12h': '12h',
107
+ '1d': '1d',
108
+ '1w': '1w',
109
+ '1M': '1mon',
110
+ '1y': '1y',
111
+ },
112
+ 'urls': {
113
+ 'logo': 'https://user-images.githubusercontent.com/1294454/150730761-1a00e5e0-d28c-480f-9e65-089ce3e6ef3b.jpg',
114
+ 'api': {
115
+ 'pub': 'https://api-pub.woo.org',
116
+ 'public': 'https://api.{hostname}',
117
+ 'private': 'https://api.{hostname}',
118
+ },
119
+ 'test': {
120
+ 'pub': 'https://api-pub.staging.woo.org',
121
+ 'public': 'https://api.staging.woo.org',
122
+ 'private': 'https://api.staging.woo.org',
123
+ },
124
+ 'www': 'https://woo.org/',
125
+ 'doc': [
126
+ 'https://docs.woo.org/',
127
+ ],
128
+ 'fees': [
129
+ 'https://support.woo.org/hc/en-001/articles/4404611795353--Trading-Fees',
130
+ ],
131
+ 'referral': {
132
+ 'url': 'https://x.woo.org/register?ref=YWOWC96B',
133
+ 'discount': 0.35,
134
+ },
135
+ },
136
+ 'api': {
137
+ 'v1': {
138
+ 'pub': {
139
+ 'get': {
140
+ 'hist/kline': 10,
141
+ 'hist/trades': 1,
142
+ },
143
+ },
144
+ 'public': {
145
+ 'get': {
146
+ 'info': 1,
147
+ 'info/{symbol}': 1,
148
+ 'system_info': 1,
149
+ 'market_trades': 1,
150
+ 'token': 1,
151
+ 'token_network': 1,
152
+ 'funding_rates': 1,
153
+ 'funding_rate/{symbol}': 1,
154
+ 'funding_rate_history': 1,
155
+ 'futures': 1,
156
+ 'futures/{symbol}': 1,
157
+ 'orderbook/{symbol}': 1,
158
+ 'kline': 1,
159
+ },
160
+ },
161
+ 'private': {
162
+ 'get': {
163
+ 'client/token': 1,
164
+ 'order/{oid}': 1,
165
+ 'client/order/{client_order_id}': 1,
166
+ 'orders': 1,
167
+ 'client/trade/{tid}': 1,
168
+ 'order/{oid}/trades': 1,
169
+ 'client/trades': 1,
170
+ 'asset/deposit': 10,
171
+ 'asset/history': 60,
172
+ 'sub_account/all': 60,
173
+ 'sub_account/assets': 60,
174
+ 'token_interest': 60,
175
+ 'token_interest/{token}': 60,
176
+ 'interest/history': 60,
177
+ 'interest/repay': 60,
178
+ 'funding_fee/history': 30,
179
+ 'positions': 3.33,
180
+ 'position/{symbol}': 3.33,
181
+ 'client/transaction_history': 60,
182
+ },
183
+ 'post': {
184
+ 'order': 5,
185
+ 'asset/main_sub_transfer': 30,
186
+ 'asset/withdraw': 30,
187
+ 'interest/repay': 60,
188
+ 'client/account_mode': 120,
189
+ 'client/leverage': 120,
190
+ },
191
+ 'delete': {
192
+ 'order': 1,
193
+ 'client/order': 1,
194
+ 'orders': 1,
195
+ 'asset/withdraw': 120, // implemented in ccxt, disabled on the exchange side https://kronosresearch.github.io/wootrade-documents/#cancel-withdraw-request
196
+ },
197
+ },
198
+ },
199
+ 'v2': {
200
+ 'private': {
201
+ 'get': {
202
+ 'client/holding': 1,
203
+ },
204
+ },
205
+ },
206
+ 'v3': {
207
+ 'public': {
208
+ 'get': {
209
+ 'insuranceFund': 3,
210
+ },
211
+ },
212
+ 'private': {
213
+ 'get': {
214
+ 'algo/order/{oid}': 1,
215
+ 'algo/orders': 1,
216
+ 'balances': 1,
217
+ 'accountinfo': 60,
218
+ 'positions': 3.33,
219
+ 'buypower': 1,
220
+ 'referrals': 60,
221
+ 'referral_rewards': 60,
222
+ 'convert/exchangeInfo': 1,
223
+ 'convert/assetInfo': 1,
224
+ 'convert/rfq': 60,
225
+ 'convert/trade': 1,
226
+ 'convert/trades': 1,
227
+ },
228
+ 'post': {
229
+ 'algo/order': 5,
230
+ 'convert/rft': 60,
231
+ },
232
+ 'put': {
233
+ 'order/{oid}': 2,
234
+ 'order/client/{client_order_id}': 2,
235
+ 'algo/order/{oid}': 2,
236
+ 'algo/order/client/{client_order_id}': 2,
237
+ },
238
+ 'delete': {
239
+ 'algo/order/{order_id}': 1,
240
+ 'algo/orders/pending': 1,
241
+ 'algo/orders/pending/{symbol}': 1,
242
+ 'orders/pending': 1,
243
+ },
244
+ },
245
+ },
246
+ },
247
+ 'fees': {
248
+ 'trading': {
249
+ 'tierBased': true,
250
+ 'percentage': true,
251
+ 'maker': this.parseNumber('0.0002'),
252
+ 'taker': this.parseNumber('0.0005'),
253
+ },
254
+ },
255
+ 'options': {
256
+ 'sandboxMode': false,
257
+ 'createMarketBuyOrderRequiresPrice': true,
258
+ // these network aliases require manual mapping here
259
+ 'network-aliases-for-tokens': {
260
+ 'HT': 'ERC20',
261
+ 'OMG': 'ERC20',
262
+ 'UATOM': 'ATOM',
263
+ 'ZRX': 'ZRX',
264
+ },
265
+ 'networks': {
266
+ 'TRX': 'TRON',
267
+ 'TRC20': 'TRON',
268
+ 'ERC20': 'ETH',
269
+ 'BEP20': 'BSC',
270
+ },
271
+ // override defaultNetworkCodePriorities for a specific currency
272
+ 'defaultNetworkCodeForCurrencies': {
273
+ // 'USDT': 'TRC20',
274
+ // 'BTC': 'BTC',
275
+ },
276
+ 'transfer': {
277
+ 'fillResponseFromRequest': true,
278
+ },
279
+ 'brokerId': 'bc830de7-50f3-460b-9ee0-f430f83f9dad',
280
+ },
281
+ 'commonCurrencies': {},
282
+ 'exceptions': {
283
+ 'exact': {
284
+ '-1000': errors.ExchangeError,
285
+ '-1001': errors.AuthenticationError,
286
+ '-1002': errors.AuthenticationError,
287
+ '-1003': errors.RateLimitExceeded,
288
+ '-1004': errors.BadRequest,
289
+ '-1005': errors.BadRequest,
290
+ '-1006': errors.BadRequest,
291
+ '-1007': errors.BadRequest,
292
+ '-1008': errors.InvalidOrder,
293
+ '-1009': errors.BadRequest,
294
+ '-1011': errors.ExchangeError,
295
+ '-1012': errors.BadRequest,
296
+ '-1101': errors.InvalidOrder,
297
+ '-1102': errors.InvalidOrder,
298
+ '-1103': errors.InvalidOrder,
299
+ '-1104': errors.InvalidOrder,
300
+ '-1105': errors.InvalidOrder, // { "code": -1105, "message": "Price is X% too high or X% too low from the mid price." }
301
+ },
302
+ 'broad': {
303
+ 'symbol must not be blank': errors.BadRequest,
304
+ 'The token is not supported': errors.BadRequest,
305
+ 'Your order and symbol are not valid or already canceled': errors.BadRequest,
306
+ 'Insufficient WOO. Please enable margin trading for leverage trading': errors.BadRequest, // when selling insufficent token [-1012]
307
+ },
308
+ },
309
+ 'precisionMode': number.TICK_SIZE,
310
+ });
311
+ }
312
+ async fetchMarkets(params = {}) {
313
+ /**
314
+ * @method
315
+ * @name woo#fetchMarkets
316
+ * @description retrieves data on all markets for woo
317
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
318
+ * @returns {object[]} an array of objects representing market data
319
+ */
320
+ const response = await this.v1PublicGetInfo(params);
321
+ //
322
+ // {
323
+ // "rows": [
324
+ // {
325
+ // "symbol": "SPOT_AAVE_USDT",
326
+ // "quote_min": 0,
327
+ // "quote_max": 100000,
328
+ // "quote_tick": 0.01,
329
+ // "base_min": 0.01,
330
+ // "base_max": 7284,
331
+ // "base_tick": 0.0001,
332
+ // "min_notional": 10,
333
+ // "price_range": 0.1,
334
+ // "created_time": "0",
335
+ // "updated_time": "1639107647.988",
336
+ // "is_stable": 0
337
+ // },
338
+ // ...
339
+ // "success": true
340
+ // }
341
+ //
342
+ const data = this.safeValue(response, 'rows', []);
343
+ return this.parseMarkets(data);
344
+ }
345
+ parseMarket(market) {
346
+ const marketId = this.safeString(market, 'symbol');
347
+ const parts = marketId.split('_');
348
+ const first = this.safeString(parts, 0);
349
+ let marketType;
350
+ let spot = false;
351
+ let swap = false;
352
+ if (first === 'SPOT') {
353
+ spot = true;
354
+ marketType = 'spot';
355
+ }
356
+ else if (first === 'PERP') {
357
+ swap = true;
358
+ marketType = 'swap';
359
+ }
360
+ const baseId = this.safeString(parts, 1);
361
+ const quoteId = this.safeString(parts, 2);
362
+ const base = this.safeCurrencyCode(baseId);
363
+ const quote = this.safeCurrencyCode(quoteId);
364
+ let settleId = undefined;
365
+ let settle = undefined;
366
+ let symbol = base + '/' + quote;
367
+ let contractSize = undefined;
368
+ let linear = undefined;
369
+ let margin = true;
370
+ const contract = swap;
371
+ if (contract) {
372
+ margin = false;
373
+ settleId = this.safeString(parts, 2);
374
+ settle = this.safeCurrencyCode(settleId);
375
+ symbol = base + '/' + quote + ':' + settle;
376
+ contractSize = this.parseNumber('1');
377
+ linear = true;
378
+ }
379
+ return {
380
+ 'id': marketId,
381
+ 'symbol': symbol,
382
+ 'base': base,
383
+ 'quote': quote,
384
+ 'settle': settle,
385
+ 'baseId': baseId,
386
+ 'quoteId': quoteId,
387
+ 'settleId': settleId,
388
+ 'type': marketType,
389
+ 'spot': spot,
390
+ 'margin': margin,
391
+ 'swap': swap,
392
+ 'future': false,
393
+ 'option': false,
394
+ 'active': undefined,
395
+ 'contract': contract,
396
+ 'linear': linear,
397
+ 'inverse': undefined,
398
+ 'contractSize': contractSize,
399
+ 'expiry': undefined,
400
+ 'expiryDatetime': undefined,
401
+ 'strike': undefined,
402
+ 'optionType': undefined,
403
+ 'precision': {
404
+ 'amount': this.safeNumber(market, 'base_tick'),
405
+ 'price': this.safeNumber(market, 'quote_tick'),
406
+ },
407
+ 'limits': {
408
+ 'leverage': {
409
+ 'min': undefined,
410
+ 'max': undefined,
411
+ },
412
+ 'amount': {
413
+ 'min': this.safeNumber(market, 'base_min'),
414
+ 'max': this.safeNumber(market, 'base_max'),
415
+ },
416
+ 'price': {
417
+ 'min': this.safeNumber(market, 'quote_min'),
418
+ 'max': this.safeNumber(market, 'quote_max'),
419
+ },
420
+ 'cost': {
421
+ 'min': this.safeNumber(market, 'min_notional'),
422
+ 'max': undefined,
423
+ },
424
+ },
425
+ 'created': this.safeTimestamp(market, 'created_time'),
426
+ 'info': market,
427
+ };
428
+ }
429
+ async fetchTrades(symbol, since = undefined, limit = undefined, params = {}) {
430
+ /**
431
+ * @method
432
+ * @name woo#fetchTrades
433
+ * @description get the list of most recent trades for a particular symbol
434
+ * @param {string} symbol unified symbol of the market to fetch trades for
435
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
436
+ * @param {int} [limit] the maximum amount of trades to fetch
437
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
438
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
439
+ */
440
+ await this.loadMarkets();
441
+ const market = this.market(symbol);
442
+ const request = {
443
+ 'symbol': market['id'],
444
+ };
445
+ if (limit !== undefined) {
446
+ request['limit'] = limit;
447
+ }
448
+ const response = await this.v1PublicGetMarketTrades(this.extend(request, params));
449
+ //
450
+ // {
451
+ // "success": true,
452
+ // "rows": [
453
+ // {
454
+ // "symbol": "SPOT_BTC_USDT",
455
+ // "side": "SELL",
456
+ // "executed_price": 46222.35,
457
+ // "executed_quantity": 0.0012,
458
+ // "executed_timestamp": "1641241162.329"
459
+ // },
460
+ // {
461
+ // "symbol": "SPOT_BTC_USDT",
462
+ // "side": "SELL",
463
+ // "executed_price": 46222.35,
464
+ // "executed_quantity": 0.0012,
465
+ // "executed_timestamp": "1641241162.329"
466
+ // },
467
+ // {
468
+ // "symbol": "SPOT_BTC_USDT",
469
+ // "side": "BUY",
470
+ // "executed_price": 46224.32,
471
+ // "executed_quantity": 0.00039,
472
+ // "executed_timestamp": "1641241162.287"
473
+ // },
474
+ // ...
475
+ // ]
476
+ // }
477
+ //
478
+ const resultResponse = this.safeValue(response, 'rows', {});
479
+ return this.parseTrades(resultResponse, market, since, limit);
480
+ }
481
+ parseTrade(trade, market = undefined) {
482
+ //
483
+ // public/market_trades
484
+ //
485
+ // {
486
+ // "symbol": "SPOT_BTC_USDT",
487
+ // "side": "SELL",
488
+ // "executed_price": 46222.35,
489
+ // "executed_quantity": 0.0012,
490
+ // "executed_timestamp": "1641241162.329"
491
+ // }
492
+ //
493
+ // fetchOrderTrades, fetchOrder
494
+ //
495
+ // {
496
+ // "id": "99119876",
497
+ // "symbol": "SPOT_WOO_USDT",
498
+ // "fee": "0.0024",
499
+ // "side": "BUY",
500
+ // "executed_timestamp": "1641481113.084",
501
+ // "order_id": "87001234",
502
+ // "order_tag": "default", <-- this param only in "fetchOrderTrades"
503
+ // "executed_price": "1",
504
+ // "executed_quantity": "12",
505
+ // "fee_asset": "WOO",
506
+ // "is_maker": "1"
507
+ // }
508
+ //
509
+ const isFromFetchOrder = ('id' in trade);
510
+ const timestamp = this.safeTimestamp(trade, 'executed_timestamp');
511
+ const marketId = this.safeString(trade, 'symbol');
512
+ market = this.safeMarket(marketId, market);
513
+ const symbol = market['symbol'];
514
+ const price = this.safeString(trade, 'executed_price');
515
+ const amount = this.safeString(trade, 'executed_quantity');
516
+ const order_id = this.safeString(trade, 'order_id');
517
+ const fee = this.parseTokenAndFeeTemp(trade, 'fee_asset', 'fee');
518
+ const cost = Precise["default"].stringMul(price, amount);
519
+ const side = this.safeStringLower(trade, 'side');
520
+ const id = this.safeString(trade, 'id');
521
+ let takerOrMaker = undefined;
522
+ if (isFromFetchOrder) {
523
+ const isMaker = this.safeString(trade, 'is_maker') === '1';
524
+ takerOrMaker = isMaker ? 'maker' : 'taker';
525
+ }
526
+ return this.safeTrade({
527
+ 'id': id,
528
+ 'timestamp': timestamp,
529
+ 'datetime': this.iso8601(timestamp),
530
+ 'symbol': symbol,
531
+ 'side': side,
532
+ 'price': price,
533
+ 'amount': amount,
534
+ 'cost': cost,
535
+ 'order': order_id,
536
+ 'takerOrMaker': takerOrMaker,
537
+ 'type': undefined,
538
+ 'fee': fee,
539
+ 'info': trade,
540
+ }, market);
541
+ }
542
+ parseTokenAndFeeTemp(item, feeTokenKey, feeAmountKey) {
543
+ const feeCost = this.safeString(item, feeAmountKey);
544
+ let fee = undefined;
545
+ if (feeCost !== undefined) {
546
+ const feeCurrencyId = this.safeString(item, feeTokenKey);
547
+ const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
548
+ fee = {
549
+ 'cost': feeCost,
550
+ 'currency': feeCurrencyCode,
551
+ };
552
+ }
553
+ return fee;
554
+ }
555
+ async fetchTradingFees(params = {}) {
556
+ /**
557
+ * @method
558
+ * @name woo#fetchTradingFees
559
+ * @description fetch the trading fees for multiple markets
560
+ * @see https://docs.woo.org/#get-account-information-new
561
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
562
+ * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
563
+ */
564
+ await this.loadMarkets();
565
+ const response = await this.v3PrivateGetAccountinfo(params);
566
+ //
567
+ // {
568
+ // "success": true,
569
+ // "data": {
570
+ // "applicationId": "dsa",
571
+ // "account": "dsa",
572
+ // "alias": "haha",
573
+ // "accountMode": "MARGIN",
574
+ // "leverage": 1,
575
+ // "takerFeeRate": 1,
576
+ // "makerFeeRate": 1,
577
+ // "interestRate": 1,
578
+ // "futuresTakerFeeRate": 1,
579
+ // "futuresMakerFeeRate": 1,
580
+ // "otpauth": true,
581
+ // "marginRatio": 1,
582
+ // "openMarginRatio": 1,
583
+ // "initialMarginRatio": 1,
584
+ // "maintenanceMarginRatio": 1,
585
+ // "totalCollateral": 1,
586
+ // "freeCollateral": 1,
587
+ // "totalAccountValue": 1,
588
+ // "totalVaultValue": 1,
589
+ // "totalStakingValue": 1
590
+ // },
591
+ // "timestamp": 1673323685109
592
+ // }
593
+ //
594
+ const data = this.safeValue(response, 'data', {});
595
+ const maker = this.safeString(data, 'makerFeeRate');
596
+ const taker = this.safeString(data, 'takerFeeRate');
597
+ const result = {};
598
+ for (let i = 0; i < this.symbols.length; i++) {
599
+ const symbol = this.symbols[i];
600
+ result[symbol] = {
601
+ 'info': response,
602
+ 'symbol': symbol,
603
+ 'maker': this.parseNumber(Precise["default"].stringDiv(maker, '10000')),
604
+ 'taker': this.parseNumber(Precise["default"].stringDiv(taker, '10000')),
605
+ 'percentage': true,
606
+ 'tierBased': true,
607
+ };
608
+ }
609
+ return result;
610
+ }
611
+ async fetchCurrencies(params = {}) {
612
+ /**
613
+ * @method
614
+ * @name woo#fetchCurrencies
615
+ * @description fetches all available currencies on an exchange
616
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
617
+ * @returns {object} an associative dictionary of currencies
618
+ */
619
+ const result = {};
620
+ const tokenResponse = await this.v1PublicGetToken(params);
621
+ //
622
+ // {
623
+ // "rows": [
624
+ // {
625
+ // "token": "ETH_USDT",
626
+ // "fullname": "Tether",
627
+ // "decimals": 6,
628
+ // "balance_token": "USDT",
629
+ // "created_time": "0",
630
+ // "updated_time": "0"
631
+ // },
632
+ // {
633
+ // "token": "BSC_USDT",
634
+ // "fullname": "Tether",
635
+ // "decimals": 18,
636
+ // "balance_token": "USDT",
637
+ // "created_time": "0",
638
+ // "updated_time": "0"
639
+ // },
640
+ // {
641
+ // "token": "ZEC",
642
+ // "fullname": "ZCash",
643
+ // "decimals": 8,
644
+ // "balance_token": "ZEC",
645
+ // "created_time": "0",
646
+ // "updated_time": "0"
647
+ // },
648
+ // ...
649
+ // ],
650
+ // "success": true
651
+ // }
652
+ //
653
+ // only make one request for currrencies...
654
+ // const tokenNetworkResponse = await this.v1PublicGetTokenNetwork (params);
655
+ //
656
+ // {
657
+ // "rows": [
658
+ // {
659
+ // "protocol": "ERC20",
660
+ // "token": "USDT",
661
+ // "name": "Ethereum",
662
+ // "minimum_withdrawal": 30,
663
+ // "withdrawal_fee": 25,
664
+ // "allow_deposit": 1,
665
+ // "allow_withdraw": 1
666
+ // },
667
+ // {
668
+ // "protocol": "TRC20",
669
+ // "token": "USDT",
670
+ // "name": "Tron",
671
+ // "minimum_withdrawal": 30,
672
+ // "withdrawal_fee": 1,
673
+ // "allow_deposit": 1,
674
+ // "allow_withdraw": 1
675
+ // },
676
+ // ...
677
+ // ],
678
+ // "success": true
679
+ // }
680
+ //
681
+ const tokenRows = this.safeValue(tokenResponse, 'rows', []);
682
+ const networksByCurrencyId = this.groupBy(tokenRows, 'balance_token');
683
+ const currencyIds = Object.keys(networksByCurrencyId);
684
+ for (let i = 0; i < currencyIds.length; i++) {
685
+ const currencyId = currencyIds[i];
686
+ const networks = networksByCurrencyId[currencyId];
687
+ const code = this.safeCurrencyCode(currencyId);
688
+ let name = undefined;
689
+ let minPrecision = undefined;
690
+ const resultingNetworks = {};
691
+ for (let j = 0; j < networks.length; j++) {
692
+ const network = networks[j];
693
+ name = this.safeString(network, 'fullname');
694
+ const networkId = this.safeString(network, 'token');
695
+ const splitted = networkId.split('_');
696
+ const unifiedNetwork = splitted[0];
697
+ const precision = this.parsePrecision(this.safeString(network, 'decimals'));
698
+ if (precision !== undefined) {
699
+ minPrecision = (minPrecision === undefined) ? precision : Precise["default"].stringMin(precision, minPrecision);
700
+ }
701
+ resultingNetworks[unifiedNetwork] = {
702
+ 'id': networkId,
703
+ 'network': unifiedNetwork,
704
+ 'limits': {
705
+ 'withdraw': {
706
+ 'min': undefined,
707
+ 'max': undefined,
708
+ },
709
+ 'deposit': {
710
+ 'min': undefined,
711
+ 'max': undefined,
712
+ },
713
+ },
714
+ 'active': undefined,
715
+ 'deposit': undefined,
716
+ 'withdraw': undefined,
717
+ 'fee': undefined,
718
+ 'precision': this.parseNumber(precision),
719
+ 'info': network,
720
+ };
721
+ }
722
+ result[code] = {
723
+ 'id': currencyId,
724
+ 'name': name,
725
+ 'code': code,
726
+ 'precision': this.parseNumber(minPrecision),
727
+ 'active': undefined,
728
+ 'fee': undefined,
729
+ 'networks': resultingNetworks,
730
+ 'deposit': undefined,
731
+ 'withdraw': undefined,
732
+ 'limits': {
733
+ 'deposit': {
734
+ 'min': undefined,
735
+ 'max': undefined,
736
+ },
737
+ 'withdraw': {
738
+ 'min': undefined,
739
+ 'max': undefined,
740
+ },
741
+ },
742
+ 'info': networks,
743
+ };
744
+ }
745
+ return result;
746
+ }
747
+ async createMarketBuyOrderWithCost(symbol, cost, params = {}) {
748
+ /**
749
+ * @method
750
+ * @name woo#createMarketBuyOrderWithCost
751
+ * @description create a market buy order by providing the symbol and cost
752
+ * @see https://docs.woo.org/#send-order
753
+ * @param {string} symbol unified symbol of the market to create an order in
754
+ * @param {float} cost how much you want to trade in units of the quote currency
755
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
756
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
757
+ */
758
+ await this.loadMarkets();
759
+ const market = this.market(symbol);
760
+ if (!market['spot']) {
761
+ throw new errors.NotSupported(this.id + ' createMarketBuyOrderWithCost() supports spot orders only');
762
+ }
763
+ params['createMarketBuyOrderRequiresPrice'] = false;
764
+ return await this.createOrder(symbol, 'market', 'buy', cost, undefined, params);
765
+ }
766
+ async createTrailingAmountOrder(symbol, type, side, amount, price = undefined, trailingAmount = undefined, trailingTriggerPrice = undefined, params = {}) {
767
+ /**
768
+ * @method
769
+ * @name createTrailingAmountOrder
770
+ * @description create a trailing order by providing the symbol, type, side, amount, price and trailingAmount
771
+ * @param {string} symbol unified symbol of the market to create an order in
772
+ * @param {string} type 'market' or 'limit'
773
+ * @param {string} side 'buy' or 'sell'
774
+ * @param {float} amount how much you want to trade in units of the base currency, or number of contracts
775
+ * @param {float} [price] the price for the order to be filled at, in units of the quote currency, ignored in market orders
776
+ * @param {float} trailingAmount the quote amount to trail away from the current market price
777
+ * @param {float} trailingTriggerPrice the price to activate a trailing order, default uses the price argument
778
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
779
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
780
+ */
781
+ if (trailingAmount === undefined) {
782
+ throw new errors.ArgumentsRequired(this.id + ' createTrailingAmountOrder() requires a trailingAmount argument');
783
+ }
784
+ if (trailingTriggerPrice === undefined) {
785
+ throw new errors.ArgumentsRequired(this.id + ' createTrailingAmountOrder() requires a trailingTriggerPrice argument');
786
+ }
787
+ params['trailingAmount'] = trailingAmount;
788
+ params['trailingTriggerPrice'] = trailingTriggerPrice;
789
+ return await this.createOrder(symbol, type, side, amount, price, params);
790
+ }
791
+ async createTrailingPercentOrder(symbol, type, side, amount, price = undefined, trailingPercent = undefined, trailingTriggerPrice = undefined, params = {}) {
792
+ /**
793
+ * @method
794
+ * @name createTrailingPercentOrder
795
+ * @description create a trailing order by providing the symbol, type, side, amount, price and trailingPercent
796
+ * @param {string} symbol unified symbol of the market to create an order in
797
+ * @param {string} type 'market' or 'limit'
798
+ * @param {string} side 'buy' or 'sell'
799
+ * @param {float} amount how much you want to trade in units of the base currency, or number of contracts
800
+ * @param {float} [price] the price for the order to be filled at, in units of the quote currency, ignored in market orders
801
+ * @param {float} trailingPercent the percent to trail away from the current market price
802
+ * @param {float} trailingTriggerPrice the price to activate a trailing order, default uses the price argument
803
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
804
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
805
+ */
806
+ if (trailingPercent === undefined) {
807
+ throw new errors.ArgumentsRequired(this.id + ' createTrailingPercentOrder() requires a trailingPercent argument');
808
+ }
809
+ if (trailingTriggerPrice === undefined) {
810
+ throw new errors.ArgumentsRequired(this.id + ' createTrailingPercentOrder() requires a trailingTriggerPrice argument');
811
+ }
812
+ params['trailingPercent'] = trailingPercent;
813
+ params['trailingTriggerPrice'] = trailingTriggerPrice;
814
+ return await this.createOrder(symbol, type, side, amount, price, params);
815
+ }
816
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
817
+ /**
818
+ * @method
819
+ * @name woo#createOrder
820
+ * @description create a trade order
821
+ * @see https://docs.woo.org/#send-order
822
+ * @see https://docs.woo.org/#send-algo-order
823
+ * @param {string} symbol unified symbol of the market to create an order in
824
+ * @param {string} type 'market' or 'limit'
825
+ * @param {string} side 'buy' or 'sell'
826
+ * @param {float} amount how much of currency you want to trade in units of base currency
827
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
828
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
829
+ * @param {float} [params.triggerPrice] The price a trigger order is triggered at
830
+ * @param {object} [params.takeProfit] *takeProfit object in params* containing the triggerPrice at which the attached take profit order will be triggered (perpetual swap markets only)
831
+ * @param {float} [params.takeProfit.triggerPrice] take profit trigger price
832
+ * @param {object} [params.stopLoss] *stopLoss object in params* containing the triggerPrice at which the attached stop loss order will be triggered (perpetual swap markets only)
833
+ * @param {float} [params.stopLoss.triggerPrice] stop loss trigger price
834
+ * @param {float} [params.algoType] 'STOP'or 'TRAILING_STOP' or 'OCO' or 'CLOSE_POSITION'
835
+ * @param {float} [params.cost] *spot market buy only* the quote quantity that can be used as an alternative for the amount
836
+ * @param {string} [params.trailingAmount] the quote amount to trail away from the current market price
837
+ * @param {string} [params.trailingPercent] the percent to trail away from the current market price
838
+ * @param {string} [params.trailingTriggerPrice] the price to trigger a trailing order, default uses the price argument
839
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
840
+ */
841
+ const reduceOnly = this.safeValue2(params, 'reduceOnly', 'reduce_only');
842
+ params = this.omit(params, ['reduceOnly', 'reduce_only']);
843
+ const orderType = type.toUpperCase();
844
+ await this.loadMarkets();
845
+ const market = this.market(symbol);
846
+ const orderSide = side.toUpperCase();
847
+ const request = {
848
+ 'symbol': market['id'],
849
+ 'side': orderSide,
850
+ };
851
+ const stopPrice = this.safeNumber2(params, 'triggerPrice', 'stopPrice');
852
+ const stopLoss = this.safeValue(params, 'stopLoss');
853
+ const takeProfit = this.safeValue(params, 'takeProfit');
854
+ const algoType = this.safeString(params, 'algoType');
855
+ const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activatedPrice', price);
856
+ const trailingAmount = this.safeString2(params, 'trailingAmount', 'callbackValue');
857
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRate');
858
+ const isTrailingAmountOrder = trailingAmount !== undefined;
859
+ const isTrailingPercentOrder = trailingPercent !== undefined;
860
+ const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
861
+ const isStop = isTrailing || stopPrice !== undefined || stopLoss !== undefined || takeProfit !== undefined || (this.safeValue(params, 'childOrders') !== undefined);
862
+ const isMarket = orderType === 'MARKET';
863
+ const timeInForce = this.safeStringLower(params, 'timeInForce');
864
+ const postOnly = this.isPostOnly(isMarket, undefined, params);
865
+ const reduceOnlyKey = isStop ? 'reduceOnly' : 'reduce_only';
866
+ const clientOrderIdKey = isStop ? 'clientOrderId' : 'client_order_id';
867
+ const orderQtyKey = isStop ? 'quantity' : 'order_quantity';
868
+ const priceKey = isStop ? 'price' : 'order_price';
869
+ const typeKey = isStop ? 'type' : 'order_type';
870
+ request[typeKey] = orderType; // LIMIT/MARKET/IOC/FOK/POST_ONLY/ASK/BID
871
+ if (!isStop) {
872
+ if (postOnly) {
873
+ request['order_type'] = 'POST_ONLY';
874
+ }
875
+ else if (timeInForce === 'fok') {
876
+ request['order_type'] = 'FOK';
877
+ }
878
+ else if (timeInForce === 'ioc') {
879
+ request['order_type'] = 'IOC';
880
+ }
881
+ }
882
+ if (reduceOnly) {
883
+ request[reduceOnlyKey] = reduceOnly;
884
+ }
885
+ if (price !== undefined) {
886
+ request[priceKey] = this.priceToPrecision(symbol, price);
887
+ }
888
+ if (isMarket && !isStop) {
889
+ // for market buy it requires the amount of quote currency to spend
890
+ if (market['spot'] && orderSide === 'BUY') {
891
+ let quoteAmount = undefined;
892
+ let createMarketBuyOrderRequiresPrice = true;
893
+ [createMarketBuyOrderRequiresPrice, params] = this.handleOptionAndParams(params, 'createOrder', 'createMarketBuyOrderRequiresPrice', true);
894
+ const cost = this.safeNumber2(params, 'cost', 'order_amount');
895
+ params = this.omit(params, ['cost', 'order_amount']);
896
+ if (cost !== undefined) {
897
+ quoteAmount = this.costToPrecision(symbol, cost);
898
+ }
899
+ else if (createMarketBuyOrderRequiresPrice) {
900
+ if (price === undefined) {
901
+ throw new errors.InvalidOrder(this.id + ' createOrder() requires the price argument for market buy orders to calculate the total cost to spend (amount * price), alternatively set the createMarketBuyOrderRequiresPrice option or param to false and pass the cost to spend (quote quantity) in the amount argument');
902
+ }
903
+ else {
904
+ const amountString = this.numberToString(amount);
905
+ const priceString = this.numberToString(price);
906
+ const costRequest = Precise["default"].stringMul(amountString, priceString);
907
+ quoteAmount = this.costToPrecision(symbol, costRequest);
908
+ }
909
+ }
910
+ else {
911
+ quoteAmount = this.costToPrecision(symbol, amount);
912
+ }
913
+ request['order_amount'] = quoteAmount;
914
+ }
915
+ else {
916
+ request['order_quantity'] = this.amountToPrecision(symbol, amount);
917
+ }
918
+ }
919
+ else if (algoType !== 'POSITIONAL_TP_SL') {
920
+ request[orderQtyKey] = this.amountToPrecision(symbol, amount);
921
+ }
922
+ const clientOrderId = this.safeStringN(params, ['clOrdID', 'clientOrderId', 'client_order_id']);
923
+ if (clientOrderId !== undefined) {
924
+ request[clientOrderIdKey] = clientOrderId;
925
+ }
926
+ if (isTrailing) {
927
+ if (trailingTriggerPrice === undefined) {
928
+ throw new errors.ArgumentsRequired(this.id + ' createOrder() requires a trailingTriggerPrice parameter for trailing orders');
929
+ }
930
+ request['activatedPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
931
+ request['algoType'] = 'TRAILING_STOP';
932
+ if (isTrailingAmountOrder) {
933
+ request['callbackValue'] = trailingAmount;
934
+ }
935
+ else if (isTrailingPercentOrder) {
936
+ const convertedTrailingPercent = Precise["default"].stringDiv(trailingPercent, '100');
937
+ request['callbackRate'] = convertedTrailingPercent;
938
+ }
939
+ }
940
+ else if (stopPrice !== undefined) {
941
+ if (algoType !== 'TRAILING_STOP') {
942
+ request['triggerPrice'] = this.priceToPrecision(symbol, stopPrice);
943
+ request['algoType'] = 'STOP';
944
+ }
945
+ }
946
+ else if ((stopLoss !== undefined) || (takeProfit !== undefined)) {
947
+ request['algoType'] = 'BRACKET';
948
+ const outterOrder = {
949
+ 'symbol': market['id'],
950
+ 'reduceOnly': false,
951
+ 'algoType': 'POSITIONAL_TP_SL',
952
+ 'childOrders': [],
953
+ };
954
+ const closeSide = (orderSide === 'BUY') ? 'SELL' : 'BUY';
955
+ if (stopLoss !== undefined) {
956
+ const stopLossPrice = this.safeNumber2(stopLoss, 'triggerPrice', 'price', stopLoss);
957
+ const stopLossOrder = {
958
+ 'side': closeSide,
959
+ 'algoType': 'STOP_LOSS',
960
+ 'triggerPrice': this.priceToPrecision(symbol, stopLossPrice),
961
+ 'type': 'CLOSE_POSITION',
962
+ 'reduceOnly': true,
963
+ };
964
+ outterOrder['childOrders'].push(stopLossOrder);
965
+ }
966
+ if (takeProfit !== undefined) {
967
+ const takeProfitPrice = this.safeNumber2(takeProfit, 'triggerPrice', 'price', takeProfit);
968
+ const takeProfitOrder = {
969
+ 'side': closeSide,
970
+ 'algoType': 'TAKE_PROFIT',
971
+ 'triggerPrice': this.priceToPrecision(symbol, takeProfitPrice),
972
+ 'type': 'CLOSE_POSITION',
973
+ 'reduceOnly': true,
974
+ };
975
+ outterOrder['childOrders'].push(takeProfitOrder);
976
+ }
977
+ request['childOrders'] = [outterOrder];
978
+ }
979
+ params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'postOnly', 'timeInForce', 'stopPrice', 'triggerPrice', 'stopLoss', 'takeProfit', 'trailingPercent', 'trailingAmount', 'trailingTriggerPrice']);
980
+ let response = undefined;
981
+ if (isStop) {
982
+ response = await this.v3PrivatePostAlgoOrder(this.extend(request, params));
983
+ }
984
+ else {
985
+ response = await this.v1PrivatePostOrder(this.extend(request, params));
986
+ }
987
+ // {
988
+ // "success": true,
989
+ // "timestamp": "1641383206.489",
990
+ // "order_id": "86980774",
991
+ // "order_type": "LIMIT",
992
+ // "order_price": "1", // null for "MARKET" order
993
+ // "order_quantity": "12", // null for "MARKET" order
994
+ // "order_amount": null, // NOT-null for "MARKET" order
995
+ // "client_order_id": "0"
996
+ // }
997
+ // stop orders
998
+ // {
999
+ // "success": true,
1000
+ // "data": {
1001
+ // "rows": [
1002
+ // {
1003
+ // "orderId": "1578938",
1004
+ // "clientOrderId": "0",
1005
+ // "algoType": "STOP_LOSS",
1006
+ // "quantity": "0.1"
1007
+ // }
1008
+ // ]
1009
+ // },
1010
+ // "timestamp": "1686149372216"
1011
+ // }
1012
+ const data = this.safeValue(response, 'data');
1013
+ if (data !== undefined) {
1014
+ const rows = this.safeValue(data, 'rows', []);
1015
+ return this.parseOrder(rows[0], market);
1016
+ }
1017
+ const order = this.parseOrder(response, market);
1018
+ order['type'] = type;
1019
+ return order;
1020
+ }
1021
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1022
+ /**
1023
+ * @method
1024
+ * @name woo#editOrder
1025
+ * @description edit a trade order
1026
+ * @see https://docs.woo.org/#edit-order
1027
+ * @see https://docs.woo.org/#edit-order-by-client_order_id
1028
+ * @see https://docs.woo.org/#edit-algo-order
1029
+ * @see https://docs.woo.org/#edit-algo-order-by-client_order_id
1030
+ * @param {string} id order id
1031
+ * @param {string} symbol unified symbol of the market to create an order in
1032
+ * @param {string} type 'market' or 'limit'
1033
+ * @param {string} side 'buy' or 'sell'
1034
+ * @param {float} amount how much of currency you want to trade in units of base currency
1035
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1036
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1037
+ * @param {float} [params.triggerPrice] The price a trigger order is triggered at
1038
+ * @param {float} [params.stopLossPrice] price to trigger stop-loss orders
1039
+ * @param {float} [params.takeProfitPrice] price to trigger take-profit orders
1040
+ * @param {string} [params.trailingAmount] the quote amount to trail away from the current market price
1041
+ * @param {string} [params.trailingPercent] the percent to trail away from the current market price
1042
+ * @param {string} [params.trailingTriggerPrice] the price to trigger a trailing order, default uses the price argument
1043
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1044
+ */
1045
+ await this.loadMarkets();
1046
+ const market = this.market(symbol);
1047
+ const request = {
1048
+ // 'quantity': this.amountToPrecision (symbol, amount),
1049
+ // 'price': this.priceToPrecision (symbol, price),
1050
+ };
1051
+ if (price !== undefined) {
1052
+ request['price'] = this.priceToPrecision(symbol, price);
1053
+ }
1054
+ if (amount !== undefined) {
1055
+ request['quantity'] = this.amountToPrecision(symbol, amount);
1056
+ }
1057
+ const clientOrderIdUnified = this.safeString2(params, 'clOrdID', 'clientOrderId');
1058
+ const clientOrderIdExchangeSpecific = this.safeString(params, 'client_order_id', clientOrderIdUnified);
1059
+ const isByClientOrder = clientOrderIdExchangeSpecific !== undefined;
1060
+ const stopPrice = this.safeNumberN(params, ['triggerPrice', 'stopPrice', 'takeProfitPrice', 'stopLossPrice']);
1061
+ if (stopPrice !== undefined) {
1062
+ request['triggerPrice'] = this.priceToPrecision(symbol, stopPrice);
1063
+ }
1064
+ const trailingTriggerPrice = this.safeString2(params, 'trailingTriggerPrice', 'activatedPrice', price);
1065
+ const trailingAmount = this.safeString2(params, 'trailingAmount', 'callbackValue');
1066
+ const trailingPercent = this.safeString2(params, 'trailingPercent', 'callbackRate');
1067
+ const isTrailingAmountOrder = trailingAmount !== undefined;
1068
+ const isTrailingPercentOrder = trailingPercent !== undefined;
1069
+ const isTrailing = isTrailingAmountOrder || isTrailingPercentOrder;
1070
+ if (isTrailing) {
1071
+ if (trailingTriggerPrice !== undefined) {
1072
+ request['activatedPrice'] = this.priceToPrecision(symbol, trailingTriggerPrice);
1073
+ }
1074
+ if (isTrailingAmountOrder) {
1075
+ request['callbackValue'] = trailingAmount;
1076
+ }
1077
+ else if (isTrailingPercentOrder) {
1078
+ const convertedTrailingPercent = Precise["default"].stringDiv(trailingPercent, '100');
1079
+ request['callbackRate'] = convertedTrailingPercent;
1080
+ }
1081
+ }
1082
+ params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id', 'stopPrice', 'triggerPrice', 'takeProfitPrice', 'stopLossPrice', 'trailingTriggerPrice', 'trailingAmount', 'trailingPercent']);
1083
+ const isStop = isTrailing || (stopPrice !== undefined) || (this.safeValue(params, 'childOrders') !== undefined);
1084
+ let response = undefined;
1085
+ if (isByClientOrder) {
1086
+ request['client_order_id'] = clientOrderIdExchangeSpecific;
1087
+ if (isStop) {
1088
+ response = await this.v3PrivatePutAlgoOrderClientClientOrderId(this.extend(request, params));
1089
+ }
1090
+ else {
1091
+ response = await this.v3PrivatePutOrderClientClientOrderId(this.extend(request, params));
1092
+ }
1093
+ }
1094
+ else {
1095
+ request['oid'] = id;
1096
+ if (isStop) {
1097
+ response = await this.v3PrivatePutAlgoOrderOid(this.extend(request, params));
1098
+ }
1099
+ else {
1100
+ response = await this.v3PrivatePutOrderOid(this.extend(request, params));
1101
+ }
1102
+ }
1103
+ //
1104
+ // {
1105
+ // "code": 0,
1106
+ // "data": {
1107
+ // "status": "string",
1108
+ // "success": true
1109
+ // },
1110
+ // "message": "string",
1111
+ // "success": true,
1112
+ // "timestamp": 0
1113
+ // }
1114
+ //
1115
+ const data = this.safeValue(response, 'data', {});
1116
+ return this.parseOrder(data, market);
1117
+ }
1118
+ async cancelOrder(id, symbol = undefined, params = {}) {
1119
+ /**
1120
+ * @method
1121
+ * @name woo#cancelOrder
1122
+ * @see https://docs.woo.org/#cancel-algo-order
1123
+ * @see https://docs.woo.org/#cancel-order
1124
+ * @see https://docs.woo.org/#cancel-order-by-client_order_id
1125
+ * @description cancels an open order
1126
+ * @param {string} id order id
1127
+ * @param {string} symbol unified symbol of the market the order was made in
1128
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1129
+ * @param {boolean} [params.stop] whether the order is a stop/algo order
1130
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1131
+ */
1132
+ const stop = this.safeValue(params, 'stop', false);
1133
+ params = this.omit(params, 'stop');
1134
+ if (!stop && (symbol === undefined)) {
1135
+ throw new errors.ArgumentsRequired(this.id + ' cancelOrder() requires a symbol argument');
1136
+ }
1137
+ await this.loadMarkets();
1138
+ let market = undefined;
1139
+ if (symbol !== undefined) {
1140
+ market = this.market(symbol);
1141
+ }
1142
+ const request = {};
1143
+ const clientOrderIdUnified = this.safeString2(params, 'clOrdID', 'clientOrderId');
1144
+ const clientOrderIdExchangeSpecific = this.safeString(params, 'client_order_id', clientOrderIdUnified);
1145
+ const isByClientOrder = clientOrderIdExchangeSpecific !== undefined;
1146
+ let response = undefined;
1147
+ if (stop) {
1148
+ request['order_id'] = id;
1149
+ response = await this.v3PrivateDeleteAlgoOrderOrderId(this.extend(request, params));
1150
+ }
1151
+ else {
1152
+ request['symbol'] = market['id'];
1153
+ if (isByClientOrder) {
1154
+ request['client_order_id'] = clientOrderIdExchangeSpecific;
1155
+ params = this.omit(params, ['clOrdID', 'clientOrderId', 'client_order_id']);
1156
+ response = await this.v1PrivateDeleteClientOrder(this.extend(request, params));
1157
+ }
1158
+ else {
1159
+ request['order_id'] = id;
1160
+ response = await this.v1PrivateDeleteOrder(this.extend(request, params));
1161
+ }
1162
+ }
1163
+ //
1164
+ // { success: true, status: "CANCEL_SENT" }
1165
+ //
1166
+ const extendParams = { 'symbol': symbol };
1167
+ if (isByClientOrder) {
1168
+ extendParams['client_order_id'] = clientOrderIdExchangeSpecific;
1169
+ }
1170
+ else {
1171
+ extendParams['id'] = id;
1172
+ }
1173
+ return this.extend(this.parseOrder(response), extendParams);
1174
+ }
1175
+ async cancelAllOrders(symbol = undefined, params = {}) {
1176
+ /**
1177
+ * @method
1178
+ * @name woo#cancelAllOrders
1179
+ * @see https://docs.woo.org/#cancel-all-pending-orders
1180
+ * @see https://docs.woo.org/#cancel-orders
1181
+ * @see https://docs.woo.org/#cancel-all-pending-algo-orders
1182
+ * @description cancel all open orders in a market
1183
+ * @param {string} symbol unified market symbol
1184
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1185
+ * @param {boolean} [params.stop] whether the order is a stop/algo order
1186
+ * @returns {object} an list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1187
+ */
1188
+ await this.loadMarkets();
1189
+ const stop = this.safeValue(params, 'stop');
1190
+ params = this.omit(params, 'stop');
1191
+ if (stop) {
1192
+ return await this.v3PrivateDeleteAlgoOrdersPending(params);
1193
+ }
1194
+ if (symbol === undefined) {
1195
+ throw new errors.ArgumentsRequired(this.id + ' cancelOrders() requires a symbol argument');
1196
+ }
1197
+ const market = this.market(symbol);
1198
+ const request = {
1199
+ 'symbol': market['id'],
1200
+ };
1201
+ const response = await this.v1PrivateDeleteOrders(this.extend(request, params));
1202
+ //
1203
+ // {
1204
+ // "success":true,
1205
+ // "status":"CANCEL_ALL_SENT"
1206
+ // }
1207
+ //
1208
+ return response;
1209
+ }
1210
+ async fetchOrder(id, symbol = undefined, params = {}) {
1211
+ /**
1212
+ * @method
1213
+ * @name woo#fetchOrder
1214
+ * @see https://docs.woo.org/#get-algo-order
1215
+ * @see https://docs.woo.org/#get-order
1216
+ * @description fetches information on an order made by the user
1217
+ * @param {string} symbol unified symbol of the market the order was made in
1218
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1219
+ * @param {boolean} [params.stop] whether the order is a stop/algo order
1220
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1221
+ */
1222
+ await this.loadMarkets();
1223
+ const market = (symbol !== undefined) ? this.market(symbol) : undefined;
1224
+ const stop = this.safeValue(params, 'stop');
1225
+ params = this.omit(params, 'stop');
1226
+ const request = {};
1227
+ const clientOrderId = this.safeString2(params, 'clOrdID', 'clientOrderId');
1228
+ let response = undefined;
1229
+ if (stop) {
1230
+ request['oid'] = id;
1231
+ response = await this.v3PrivateGetAlgoOrderOid(this.extend(request, params));
1232
+ }
1233
+ else if (clientOrderId) {
1234
+ request['client_order_id'] = clientOrderId;
1235
+ response = await this.v1PrivateGetClientOrderClientOrderId(this.extend(request, params));
1236
+ }
1237
+ else {
1238
+ request['oid'] = id;
1239
+ response = await this.v1PrivateGetOrderOid(this.extend(request, params));
1240
+ }
1241
+ //
1242
+ // {
1243
+ // "success": true,
1244
+ // "symbol": "SPOT_WOO_USDT",
1245
+ // "status": "FILLED", // FILLED, NEW
1246
+ // "side": "BUY",
1247
+ // "created_time": "1641480933.000",
1248
+ // "order_id": "87541111",
1249
+ // "order_tag": "default",
1250
+ // "price": "1",
1251
+ // "type": "LIMIT",
1252
+ // "quantity": "12",
1253
+ // "amount": null,
1254
+ // "visible": "12",
1255
+ // "executed": "12", // or any partial amount
1256
+ // "total_fee": "0.0024",
1257
+ // "fee_asset": "WOO",
1258
+ // "client_order_id": null,
1259
+ // "average_executed_price": "1",
1260
+ // "Transactions": [
1261
+ // {
1262
+ // "id": "99111647",
1263
+ // "symbol": "SPOT_WOO_USDT",
1264
+ // "fee": "0.0024",
1265
+ // "side": "BUY",
1266
+ // "executed_timestamp": "1641482113.084",
1267
+ // "order_id": "87541111",
1268
+ // "executed_price": "1",
1269
+ // "executed_quantity": "12",
1270
+ // "fee_asset": "WOO",
1271
+ // "is_maker": "1"
1272
+ // }
1273
+ // ]
1274
+ // }
1275
+ //
1276
+ const orders = this.safeValue(response, 'data', response);
1277
+ return this.parseOrder(orders, market);
1278
+ }
1279
+ async fetchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1280
+ /**
1281
+ * @method
1282
+ * @name woo#fetchOrders
1283
+ * @description fetches information on multiple orders made by the user
1284
+ * @see https://docs.woo.org/#get-orders
1285
+ * @see https://docs.woo.org/#get-algo-orders
1286
+ * @param {string} symbol unified market symbol of the market orders were made in
1287
+ * @param {int} [since] the earliest time in ms to fetch orders for
1288
+ * @param {int} [limit] the maximum number of order structures to retrieve
1289
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1290
+ * @param {boolean} [params.stop] whether the order is a stop/algo order
1291
+ * @param {boolean} [params.isTriggered] whether the order has been triggered (false by default)
1292
+ * @param {string} [params.side] 'buy' or 'sell'
1293
+ * @param {boolean} [params.trailing] set to true if you want to fetch trailing orders
1294
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1295
+ */
1296
+ await this.loadMarkets();
1297
+ const request = {};
1298
+ let market = undefined;
1299
+ const stop = this.safeValue(params, 'stop');
1300
+ const trailing = this.safeValue(params, 'trailing', false);
1301
+ params = this.omit(params, ['stop', 'trailing']);
1302
+ if (symbol !== undefined) {
1303
+ market = this.market(symbol);
1304
+ request['symbol'] = market['id'];
1305
+ }
1306
+ if (since !== undefined) {
1307
+ if (stop || trailing) {
1308
+ request['createdTimeStart'] = since;
1309
+ }
1310
+ else {
1311
+ request['start_t'] = since;
1312
+ }
1313
+ }
1314
+ if (stop) {
1315
+ request['algoType'] = 'stop';
1316
+ }
1317
+ else if (trailing) {
1318
+ request['algoType'] = 'TRAILING_STOP';
1319
+ }
1320
+ let response = undefined;
1321
+ if (stop || trailing) {
1322
+ response = await this.v3PrivateGetAlgoOrders(this.extend(request, params));
1323
+ }
1324
+ else {
1325
+ response = await this.v1PrivateGetOrders(this.extend(request, params));
1326
+ }
1327
+ //
1328
+ // {
1329
+ // "success":true,
1330
+ // "meta":{
1331
+ // "total":1,
1332
+ // "records_per_page":100,
1333
+ // "current_page":1
1334
+ // },
1335
+ // "rows":[
1336
+ // {
1337
+ // "symbol":"PERP_BTC_USDT",
1338
+ // "status":"FILLED",
1339
+ // "side":"SELL",
1340
+ // "created_time":"1611617776.000",
1341
+ // "updated_time":"1611617776.000",
1342
+ // "order_id":52121167,
1343
+ // "order_tag":"default",
1344
+ // "price":null,
1345
+ // "type":"MARKET",
1346
+ // "quantity":0.002,
1347
+ // "amount":null,
1348
+ // "visible":0,
1349
+ // "executed":0.002,
1350
+ // "total_fee":0.01732885,
1351
+ // "fee_asset":"USDT",
1352
+ // "client_order_id":null,
1353
+ // "average_executed_price":28881.41
1354
+ // }
1355
+ // ]
1356
+ // }
1357
+ //
1358
+ const data = this.safeValue(response, 'data', response);
1359
+ const orders = this.safeValue(data, 'rows');
1360
+ return this.parseOrders(orders, market, since, limit, params);
1361
+ }
1362
+ parseTimeInForce(timeInForce) {
1363
+ const timeInForces = {
1364
+ 'ioc': 'IOC',
1365
+ 'fok': 'FOK',
1366
+ 'post_only': 'PO',
1367
+ };
1368
+ return this.safeString(timeInForces, timeInForce, undefined);
1369
+ }
1370
+ parseOrder(order, market = undefined) {
1371
+ //
1372
+ // Possible input functions:
1373
+ // * createOrder
1374
+ // * cancelOrder
1375
+ // * fetchOrder
1376
+ // * fetchOrders
1377
+ // const isFromFetchOrder = ('order_tag' in order); TO_DO
1378
+ //
1379
+ // stop order after creating it:
1380
+ // {
1381
+ // "orderId": "1578938",
1382
+ // "clientOrderId": "0",
1383
+ // "algoType": "STOP_LOSS",
1384
+ // "quantity": "0.1"
1385
+ // }
1386
+ // stop order after fetching it:
1387
+ // {
1388
+ // "algoOrderId": "1578958",
1389
+ // "clientOrderId": "0",
1390
+ // "rootAlgoOrderId": "1578958",
1391
+ // "parentAlgoOrderId": "0",
1392
+ // "symbol": "SPOT_LTC_USDT",
1393
+ // "orderTag": "default",
1394
+ // "algoType": "STOP_LOSS",
1395
+ // "side": "BUY",
1396
+ // "quantity": "0.1",
1397
+ // "isTriggered": false,
1398
+ // "triggerPrice": "100",
1399
+ // "triggerStatus": "USELESS",
1400
+ // "type": "LIMIT",
1401
+ // "rootAlgoStatus": "CANCELLED",
1402
+ // "algoStatus": "CANCELLED",
1403
+ // "triggerPriceType": "MARKET_PRICE",
1404
+ // "price": "75",
1405
+ // "triggerTime": "0",
1406
+ // "totalExecutedQuantity": "0",
1407
+ // "averageExecutedPrice": "0",
1408
+ // "totalFee": "0",
1409
+ // "feeAsset": '',
1410
+ // "reduceOnly": false,
1411
+ // "createdTime": "1686149609.744",
1412
+ // "updatedTime": "1686149903.362"
1413
+ // }
1414
+ //
1415
+ const timestamp = this.safeTimestampN(order, ['timestamp', 'created_time', 'createdTime']);
1416
+ const orderId = this.safeStringN(order, ['order_id', 'orderId', 'algoOrderId']);
1417
+ const clientOrderId = this.omitZero(this.safeString2(order, 'client_order_id', 'clientOrderId')); // Somehow, this always returns 0 for limit order
1418
+ const marketId = this.safeString(order, 'symbol');
1419
+ market = this.safeMarket(marketId, market);
1420
+ const symbol = market['symbol'];
1421
+ const price = this.safeString2(order, 'order_price', 'price');
1422
+ const amount = this.safeString2(order, 'order_quantity', 'quantity'); // This is base amount
1423
+ const cost = this.safeString2(order, 'order_amount', 'amount'); // This is quote amount
1424
+ const orderType = this.safeStringLower2(order, 'order_type', 'type');
1425
+ const status = this.safeValue2(order, 'status', 'algoStatus');
1426
+ const side = this.safeStringLower(order, 'side');
1427
+ const filled = this.omitZero(this.safeValue2(order, 'executed', 'totalExecutedQuantity'));
1428
+ const average = this.omitZero(this.safeString2(order, 'average_executed_price', 'averageExecutedPrice'));
1429
+ const remaining = Precise["default"].stringSub(cost, filled);
1430
+ const fee = this.safeValue2(order, 'total_fee', 'totalFee');
1431
+ const feeCurrency = this.safeString2(order, 'fee_asset', 'feeAsset');
1432
+ const transactions = this.safeValue(order, 'Transactions');
1433
+ const stopPrice = this.safeNumber(order, 'triggerPrice');
1434
+ let takeProfitPrice = undefined;
1435
+ let stopLossPrice = undefined;
1436
+ const childOrders = this.safeValue(order, 'childOrders');
1437
+ if (childOrders !== undefined) {
1438
+ const first = this.safeValue(childOrders, 0);
1439
+ const innerChildOrders = this.safeValue(first, 'childOrders', []);
1440
+ const innerChildOrdersLength = innerChildOrders.length;
1441
+ if (innerChildOrdersLength > 0) {
1442
+ const takeProfitOrder = this.safeValue(innerChildOrders, 0);
1443
+ const stopLossOrder = this.safeValue(innerChildOrders, 1);
1444
+ takeProfitPrice = this.safeNumber(takeProfitOrder, 'triggerPrice');
1445
+ stopLossPrice = this.safeNumber(stopLossOrder, 'triggerPrice');
1446
+ }
1447
+ }
1448
+ const lastUpdateTimestamp = this.safeTimestamp2(order, 'updatedTime', 'updated_time');
1449
+ return this.safeOrder({
1450
+ 'id': orderId,
1451
+ 'clientOrderId': clientOrderId,
1452
+ 'timestamp': timestamp,
1453
+ 'datetime': this.iso8601(timestamp),
1454
+ 'lastTradeTimestamp': undefined,
1455
+ 'lastUpdateTimestamp': lastUpdateTimestamp,
1456
+ 'status': this.parseOrderStatus(status),
1457
+ 'symbol': symbol,
1458
+ 'type': orderType,
1459
+ 'timeInForce': this.parseTimeInForce(orderType),
1460
+ 'postOnly': undefined,
1461
+ 'reduceOnly': this.safeValue(order, 'reduce_only'),
1462
+ 'side': side,
1463
+ 'price': price,
1464
+ 'stopPrice': stopPrice,
1465
+ 'triggerPrice': stopPrice,
1466
+ 'takeProfitPrice': takeProfitPrice,
1467
+ 'stopLossPrice': stopLossPrice,
1468
+ 'average': average,
1469
+ 'amount': amount,
1470
+ 'filled': filled,
1471
+ 'remaining': remaining,
1472
+ 'cost': cost,
1473
+ 'trades': transactions,
1474
+ 'fee': {
1475
+ 'cost': fee,
1476
+ 'currency': feeCurrency,
1477
+ },
1478
+ 'info': order,
1479
+ }, market);
1480
+ }
1481
+ parseOrderStatus(status) {
1482
+ if (status !== undefined) {
1483
+ const statuses = {
1484
+ 'NEW': 'open',
1485
+ 'FILLED': 'closed',
1486
+ 'CANCEL_SENT': 'canceled',
1487
+ 'CANCEL_ALL_SENT': 'canceled',
1488
+ 'CANCELLED': 'canceled',
1489
+ 'PARTIAL_FILLED': 'open',
1490
+ 'REJECTED': 'rejected',
1491
+ 'INCOMPLETE': 'open',
1492
+ 'COMPLETED': 'closed',
1493
+ };
1494
+ return this.safeString(statuses, status, status);
1495
+ }
1496
+ return status;
1497
+ }
1498
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
1499
+ /**
1500
+ * @method
1501
+ * @name woo#fetchOrderBook
1502
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
1503
+ * @param {string} symbol unified symbol of the market to fetch the order book for
1504
+ * @param {int} [limit] the maximum amount of order book entries to return
1505
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1506
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
1507
+ */
1508
+ await this.loadMarkets();
1509
+ const market = this.market(symbol);
1510
+ const request = {
1511
+ 'symbol': market['id'],
1512
+ };
1513
+ if (limit !== undefined) {
1514
+ limit = Math.min(limit, 1000);
1515
+ request['max_level'] = limit;
1516
+ }
1517
+ const response = await this.v1PublicGetOrderbookSymbol(this.extend(request, params));
1518
+ //
1519
+ // {
1520
+ // "success": true,
1521
+ // "timestamp": "1641562961192",
1522
+ // "asks": [
1523
+ // { price: '0.921', quantity: "76.01" },
1524
+ // { price: '0.933', quantity: "477.10" },
1525
+ // ...
1526
+ // ],
1527
+ // "bids": [
1528
+ // { price: '0.940', quantity: "13502.47" },
1529
+ // { price: '0.932', quantity: "43.91" },
1530
+ // ...
1531
+ // ]
1532
+ // }
1533
+ //
1534
+ const timestamp = this.safeInteger(response, 'timestamp');
1535
+ return this.parseOrderBook(response, symbol, timestamp, 'bids', 'asks', 'price', 'quantity');
1536
+ }
1537
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
1538
+ /**
1539
+ * @method
1540
+ * @name woo#fetchOHLCV
1541
+ * @see https://docs.woo.org/#kline-public
1542
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1543
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1544
+ * @param {string} timeframe the length of time each candle represents
1545
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
1546
+ * @param {int} [limit] the maximum amount of candles to fetch
1547
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1548
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1549
+ */
1550
+ await this.loadMarkets();
1551
+ const market = this.market(symbol);
1552
+ const request = {
1553
+ 'symbol': market['id'],
1554
+ 'type': this.safeString(this.timeframes, timeframe, timeframe),
1555
+ };
1556
+ if (limit !== undefined) {
1557
+ request['limit'] = Math.min(limit, 1000);
1558
+ }
1559
+ const response = await this.v1PublicGetKline(this.extend(request, params));
1560
+ // {
1561
+ // "success": true,
1562
+ // "rows": [
1563
+ // {
1564
+ // "open": "0.94238",
1565
+ // "close": "0.94271",
1566
+ // "low": "0.94238",
1567
+ // "high": "0.94296",
1568
+ // "volume": "73.55",
1569
+ // "amount": "69.32040520",
1570
+ // "symbol": "SPOT_WOO_USDT",
1571
+ // "type": "1m",
1572
+ // "start_timestamp": "1641584700000",
1573
+ // "end_timestamp": "1641584760000"
1574
+ // },
1575
+ // {
1576
+ // "open": "0.94186",
1577
+ // "close": "0.94186",
1578
+ // "low": "0.94186",
1579
+ // "high": "0.94186",
1580
+ // "volume": "64.00",
1581
+ // "amount": "60.27904000",
1582
+ // "symbol": "SPOT_WOO_USDT",
1583
+ // "type": "1m",
1584
+ // "start_timestamp": "1641584640000",
1585
+ // "end_timestamp": "1641584700000"
1586
+ // },
1587
+ // ...
1588
+ // ]
1589
+ // }
1590
+ const data = this.safeValue(response, 'rows', []);
1591
+ return this.parseOHLCVs(data, market, timeframe, since, limit);
1592
+ }
1593
+ parseOHLCV(ohlcv, market = undefined) {
1594
+ // example response in fetchOHLCV
1595
+ return [
1596
+ this.safeInteger(ohlcv, 'start_timestamp'),
1597
+ this.safeNumber(ohlcv, 'open'),
1598
+ this.safeNumber(ohlcv, 'high'),
1599
+ this.safeNumber(ohlcv, 'low'),
1600
+ this.safeNumber(ohlcv, 'close'),
1601
+ this.safeNumber(ohlcv, 'volume'),
1602
+ ];
1603
+ }
1604
+ async fetchOrderTrades(id, symbol = undefined, since = undefined, limit = undefined, params = {}) {
1605
+ /**
1606
+ * @method
1607
+ * @name woo#fetchOrderTrades
1608
+ * @description fetch all the trades made from a single order
1609
+ * @param {string} id order id
1610
+ * @param {string} symbol unified market symbol
1611
+ * @param {int} [since] the earliest time in ms to fetch trades for
1612
+ * @param {int} [limit] the maximum number of trades to retrieve
1613
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1614
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1615
+ */
1616
+ await this.loadMarkets();
1617
+ let market = undefined;
1618
+ if (symbol !== undefined) {
1619
+ market = this.market(symbol);
1620
+ }
1621
+ const request = {
1622
+ 'oid': id,
1623
+ };
1624
+ const response = await this.v1PrivateGetOrderOidTrades(this.extend(request, params));
1625
+ // {
1626
+ // "success": true,
1627
+ // "rows": [
1628
+ // {
1629
+ // "id": "99111647",
1630
+ // "symbol": "SPOT_WOO_USDT",
1631
+ // "fee": "0.0024",
1632
+ // "side": "BUY",
1633
+ // "executed_timestamp": "1641482113.084",
1634
+ // "order_id": "87541111",
1635
+ // "order_tag": "default",
1636
+ // "executed_price": "1",
1637
+ // "executed_quantity": "12",
1638
+ // "fee_asset": "WOO",
1639
+ // "is_maker": "1"
1640
+ // }
1641
+ // ]
1642
+ // }
1643
+ const trades = this.safeValue(response, 'rows', []);
1644
+ return this.parseTrades(trades, market, since, limit, params);
1645
+ }
1646
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1647
+ /**
1648
+ * @method
1649
+ * @name woo#fetchMyTrades
1650
+ * @description fetch all trades made by the user
1651
+ * @param {string} symbol unified market symbol
1652
+ * @param {int} [since] the earliest time in ms to fetch trades for
1653
+ * @param {int} [limit] the maximum number of trades structures to retrieve
1654
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1655
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1656
+ */
1657
+ await this.loadMarkets();
1658
+ const request = {};
1659
+ let market = undefined;
1660
+ if (symbol !== undefined) {
1661
+ market = this.market(symbol);
1662
+ request['symbol'] = market['id'];
1663
+ }
1664
+ if (since !== undefined) {
1665
+ request['start_t'] = since;
1666
+ }
1667
+ const response = await this.v1PrivateGetClientTrades(this.extend(request, params));
1668
+ // {
1669
+ // "success": true,
1670
+ // "meta": {
1671
+ // "records_per_page": 25,
1672
+ // "current_page": 1
1673
+ // },
1674
+ // "rows": [
1675
+ // {
1676
+ // "id": 5,
1677
+ // "symbol": "SPOT_BTC_USDT",
1678
+ // "order_id": 211,
1679
+ // "order_tag": "default",
1680
+ // "executed_price": 10892.84,
1681
+ // "executed_quantity": 0.002,
1682
+ // "is_maker": 0,
1683
+ // "side": "SELL",
1684
+ // "fee": 0,
1685
+ // "fee_asset": "USDT",
1686
+ // "executed_timestamp": "1566264290.250"
1687
+ // },
1688
+ // ...
1689
+ // ]
1690
+ // }
1691
+ const trades = this.safeValue(response, 'rows', []);
1692
+ return this.parseTrades(trades, market, since, limit, params);
1693
+ }
1694
+ async fetchAccounts(params = {}) {
1695
+ /**
1696
+ * @method
1697
+ * @name woo#fetchAccounts
1698
+ * @description fetch all the accounts associated with a profile
1699
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1700
+ * @returns {object} a dictionary of [account structures]{@link https://docs.ccxt.com/#/?id=account-structure} indexed by the account type
1701
+ */
1702
+ const response = await this.v1PrivateGetSubAccountAssets(params);
1703
+ //
1704
+ // {
1705
+ // "rows": [{
1706
+ // "application_id": "13e4fc34-e2ff-4cb7-b1e4-4c22fee7d365",
1707
+ // "account": "Main",
1708
+ // "usdt_balance": "4.0"
1709
+ // },
1710
+ // {
1711
+ // "application_id": "432952aa-a401-4e26-aff6-972920aebba3",
1712
+ // "account": "subaccount",
1713
+ // "usdt_balance": "1.0"
1714
+ // }
1715
+ // ],
1716
+ // "success": true
1717
+ // }
1718
+ //
1719
+ const rows = this.safeValue(response, 'rows', []);
1720
+ return this.parseAccounts(rows, params);
1721
+ }
1722
+ parseAccount(account) {
1723
+ //
1724
+ // {
1725
+ // "application_id": "336952aa-a401-4e26-aff6-972920aebba3",
1726
+ // "account": "subaccount",
1727
+ // "usdt_balance": "1.0",
1728
+ // }
1729
+ //
1730
+ const accountId = this.safeString(account, 'account');
1731
+ return {
1732
+ 'info': account,
1733
+ 'id': this.safeString(account, 'application_id'),
1734
+ 'name': accountId,
1735
+ 'code': undefined,
1736
+ 'type': accountId === 'Main' ? 'main' : 'subaccount',
1737
+ };
1738
+ }
1739
+ async fetchBalance(params = {}) {
1740
+ /**
1741
+ * @method
1742
+ * @name woo#fetchBalance
1743
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
1744
+ * @see https://docs.woo.org/#get-current-holding-get-balance-new
1745
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1746
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1747
+ */
1748
+ await this.loadMarkets();
1749
+ const response = await this.v3PrivateGetBalances(params);
1750
+ //
1751
+ // {
1752
+ // "success": true,
1753
+ // "data": {
1754
+ // "holding": [
1755
+ // {
1756
+ // "token": "0_token",
1757
+ // "holding": 1,
1758
+ // "frozen": 0,
1759
+ // "staked": 0,
1760
+ // "unbonding": 0,
1761
+ // "vault": 0,
1762
+ // "interest": 0,
1763
+ // "pendingShortQty": 0,
1764
+ // "pendingLongQty": 0,
1765
+ // "availableBalance": 0,
1766
+ // "updatedTime": 312321.121
1767
+ // }
1768
+ // ]
1769
+ // },
1770
+ // "timestamp": 1673323746259
1771
+ // }
1772
+ //
1773
+ const data = this.safeValue(response, 'data');
1774
+ return this.parseBalance(data);
1775
+ }
1776
+ parseBalance(response) {
1777
+ const result = {
1778
+ 'info': response,
1779
+ };
1780
+ const balances = this.safeValue(response, 'holding', []);
1781
+ for (let i = 0; i < balances.length; i++) {
1782
+ const balance = balances[i];
1783
+ const code = this.safeCurrencyCode(this.safeString(balance, 'token'));
1784
+ const account = this.account();
1785
+ account['total'] = this.safeString(balance, 'holding');
1786
+ account['free'] = this.safeString(balance, 'availableBalance');
1787
+ result[code] = account;
1788
+ }
1789
+ return this.safeBalance(result);
1790
+ }
1791
+ async fetchDepositAddress(code, params = {}) {
1792
+ /**
1793
+ * @method
1794
+ * @name woo#fetchDepositAddress
1795
+ * @description fetch the deposit address for a currency associated with this account
1796
+ * @param {string} code unified currency code
1797
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1798
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1799
+ */
1800
+ // this method is TODO because of networks unification
1801
+ await this.loadMarkets();
1802
+ const currency = this.currency(code);
1803
+ const networkCodeDefault = this.defaultNetworkCodeForCurrency(code);
1804
+ const networkCode = this.safeString(params, 'network', networkCodeDefault);
1805
+ params = this.omit(params, 'network');
1806
+ const codeForExchange = networkCode + '_' + currency['code'];
1807
+ const request = {
1808
+ 'token': codeForExchange,
1809
+ };
1810
+ const response = await this.v1PrivateGetAssetDeposit(this.extend(request, params));
1811
+ // {
1812
+ // "success": true,
1813
+ // "address": "3Jmtjx5544T4smrit9Eroe4PCrRkpDeKjP",
1814
+ // "extra": ''
1815
+ // }
1816
+ const tag = this.safeString(response, 'extra');
1817
+ const address = this.safeString(response, 'address');
1818
+ this.checkAddress(address);
1819
+ return {
1820
+ 'currency': code,
1821
+ 'address': address,
1822
+ 'tag': tag,
1823
+ 'network': networkCode,
1824
+ 'info': response,
1825
+ };
1826
+ }
1827
+ async getAssetHistoryRows(code = undefined, since = undefined, limit = undefined, params = {}) {
1828
+ await this.loadMarkets();
1829
+ const request = {};
1830
+ let currency = undefined;
1831
+ if (code !== undefined) {
1832
+ currency = this.currency(code);
1833
+ request['balance_token'] = currency['id'];
1834
+ }
1835
+ if (since !== undefined) {
1836
+ request['start_t'] = since;
1837
+ }
1838
+ if (limit !== undefined) {
1839
+ request['pageSize'] = limit;
1840
+ }
1841
+ const transactionType = this.safeString(params, 'type');
1842
+ params = this.omit(params, 'type');
1843
+ if (transactionType !== undefined) {
1844
+ request['type'] = transactionType;
1845
+ }
1846
+ const response = await this.v1PrivateGetAssetHistory(this.extend(request, params));
1847
+ // {
1848
+ // "rows": [
1849
+ // {
1850
+ // "id": "22010508193900165",
1851
+ // "token": "TRON_USDT",
1852
+ // "extra": '',
1853
+ // "amount": "13.75848500",
1854
+ // "status": "COMPLETED",
1855
+ // "account": null,
1856
+ // "description": null,
1857
+ // "user_id": "42222",
1858
+ // "application_id": "6ad2b303-f354-45c0-8105-9f5f19d0e335",
1859
+ // "external_id": "220105081900134",
1860
+ // "target_address": "TXnyFSnAYad3YCaqtwMw9jvXKkeU39NLnK",
1861
+ // "source_address": "TYDzsYUEpvnYmQk4zGP9sWWcTEd2MiAtW6",
1862
+ // "type": "BALANCE",
1863
+ // "token_side": "DEPOSIT",
1864
+ // "tx_id": "35b0004022f6b3ad07f39a0b7af199f6b258c2c3e2c7cdc93c67efa74fd625ee",
1865
+ // "fee_token": '',
1866
+ // "fee_amount": "0.00000000",
1867
+ // "created_time": "1641370779.442",
1868
+ // "updated_time": "1641370779.465",
1869
+ // "is_new_target_address": null,
1870
+ // "confirmed_number": "29",
1871
+ // "confirming_threshold": "27",
1872
+ // "audit_tag": "1",
1873
+ // "audit_result": "0",
1874
+ // "balance_token": null, // TODO -write to support, that this seems broken. here should be the token id
1875
+ // "network_name": null // TODO -write to support, that this seems broken. here should be the network id
1876
+ // }
1877
+ // ],
1878
+ // "meta": { total: '1', records_per_page: "25", current_page: "1" },
1879
+ // "success": true
1880
+ // }
1881
+ return [currency, this.safeValue(response, 'rows', {})];
1882
+ }
1883
+ async fetchLedger(code = undefined, since = undefined, limit = undefined, params = {}) {
1884
+ /**
1885
+ * @method
1886
+ * @name woo#fetchLedger
1887
+ * @description fetch the history of changes, actions done by the user or operations that altered balance of the user
1888
+ * @param {string} code unified currency code, default is undefined
1889
+ * @param {int} [since] timestamp in ms of the earliest ledger entry, default is undefined
1890
+ * @param {int} [limit] max number of ledger entrys to return, default is undefined
1891
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1892
+ * @returns {object} a [ledger structure]{@link https://docs.ccxt.com/#/?id=ledger-structure}
1893
+ */
1894
+ const [currency, rows] = await this.getAssetHistoryRows(code, since, limit, params);
1895
+ return this.parseLedger(rows, currency, since, limit, params);
1896
+ }
1897
+ parseLedgerEntry(item, currency = undefined) {
1898
+ const networkizedCode = this.safeString(item, 'token');
1899
+ const currencyDefined = this.getCurrencyFromChaincode(networkizedCode, currency);
1900
+ const code = currencyDefined['code'];
1901
+ const amount = this.safeNumber(item, 'amount');
1902
+ const side = this.safeString(item, 'token_side');
1903
+ const direction = (side === 'DEPOSIT') ? 'in' : 'out';
1904
+ const timestamp = this.safeTimestamp(item, 'created_time');
1905
+ const fee = this.parseTokenAndFeeTemp(item, 'fee_token', 'fee_amount');
1906
+ return {
1907
+ 'id': this.safeString(item, 'id'),
1908
+ 'currency': code,
1909
+ 'account': this.safeString(item, 'account'),
1910
+ 'referenceAccount': undefined,
1911
+ 'referenceId': this.safeString(item, 'tx_id'),
1912
+ 'status': this.parseTransactionStatus(this.safeString(item, 'status')),
1913
+ 'amount': amount,
1914
+ 'before': undefined,
1915
+ 'after': undefined,
1916
+ 'fee': fee,
1917
+ 'direction': direction,
1918
+ 'timestamp': timestamp,
1919
+ 'datetime': this.iso8601(timestamp),
1920
+ 'type': this.parseLedgerEntryType(this.safeString(item, 'type')),
1921
+ 'info': item,
1922
+ };
1923
+ }
1924
+ parseLedgerEntryType(type) {
1925
+ const types = {
1926
+ 'BALANCE': 'transaction',
1927
+ 'COLLATERAL': 'transfer', // Funds moved between portfolios
1928
+ };
1929
+ return this.safeString(types, type, type);
1930
+ }
1931
+ getCurrencyFromChaincode(networkizedCode, currency) {
1932
+ if (currency !== undefined) {
1933
+ return currency;
1934
+ }
1935
+ else {
1936
+ const parts = networkizedCode.split('_');
1937
+ const partsLength = parts.length;
1938
+ const firstPart = this.safeString(parts, 0);
1939
+ let currencyId = this.safeString(parts, 1, firstPart);
1940
+ if (partsLength > 2) {
1941
+ currencyId += '_' + this.safeString(parts, 2);
1942
+ }
1943
+ currency = this.safeCurrency(currencyId);
1944
+ }
1945
+ return currency;
1946
+ }
1947
+ async fetchDeposits(code = undefined, since = undefined, limit = undefined, params = {}) {
1948
+ /**
1949
+ * @method
1950
+ * @name woo#fetchDeposits
1951
+ * @description fetch all deposits made to an account
1952
+ * @param {string} code unified currency code
1953
+ * @param {int} [since] the earliest time in ms to fetch deposits for
1954
+ * @param {int} [limit] the maximum number of deposits structures to retrieve
1955
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1956
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1957
+ */
1958
+ const request = {
1959
+ 'token_side': 'DEPOSIT',
1960
+ };
1961
+ return await this.fetchDepositsWithdrawals(code, since, limit, this.extend(request, params));
1962
+ }
1963
+ async fetchWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
1964
+ /**
1965
+ * @method
1966
+ * @name woo#fetchWithdrawals
1967
+ * @description fetch all withdrawals made from an account
1968
+ * @param {string} code unified currency code
1969
+ * @param {int} [since] the earliest time in ms to fetch withdrawals for
1970
+ * @param {int} [limit] the maximum number of withdrawals structures to retrieve
1971
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1972
+ * @returns {object[]} a list of [transaction structures]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1973
+ */
1974
+ const request = {
1975
+ 'token_side': 'WITHDRAW',
1976
+ };
1977
+ return await this.fetchDepositsWithdrawals(code, since, limit, this.extend(request, params));
1978
+ }
1979
+ async fetchDepositsWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
1980
+ /**
1981
+ * @method
1982
+ * @name woo#fetchDepositsWithdrawals
1983
+ * @description fetch history of deposits and withdrawals
1984
+ * @param {string} [code] unified currency code for the currency of the deposit/withdrawals, default is undefined
1985
+ * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
1986
+ * @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
1987
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1988
+ * @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1989
+ */
1990
+ const request = {
1991
+ 'type': 'BALANCE',
1992
+ };
1993
+ const [currency, rows] = await this.getAssetHistoryRows(code, since, limit, this.extend(request, params));
1994
+ //
1995
+ // {
1996
+ // "rows":[],
1997
+ // "meta":{
1998
+ // "total":0,
1999
+ // "records_per_page":25,
2000
+ // "current_page":1
2001
+ // },
2002
+ // "success":true
2003
+ // }
2004
+ //
2005
+ return this.parseTransactions(rows, currency, since, limit, params);
2006
+ }
2007
+ parseTransaction(transaction, currency = undefined) {
2008
+ // example in fetchLedger
2009
+ const networkizedCode = this.safeString(transaction, 'token');
2010
+ const currencyDefined = this.getCurrencyFromChaincode(networkizedCode, currency);
2011
+ const code = currencyDefined['code'];
2012
+ let movementDirection = this.safeStringLower(transaction, 'token_side');
2013
+ if (movementDirection === 'withdraw') {
2014
+ movementDirection = 'withdrawal';
2015
+ }
2016
+ const fee = this.parseTokenAndFeeTemp(transaction, 'fee_token', 'fee_amount');
2017
+ const addressTo = this.safeString(transaction, 'target_address');
2018
+ const addressFrom = this.safeString(transaction, 'source_address');
2019
+ const timestamp = this.safeTimestamp(transaction, 'created_time');
2020
+ return {
2021
+ 'info': transaction,
2022
+ 'id': this.safeString2(transaction, 'id', 'withdraw_id'),
2023
+ 'txid': this.safeString(transaction, 'tx_id'),
2024
+ 'timestamp': timestamp,
2025
+ 'datetime': this.iso8601(timestamp),
2026
+ 'address': undefined,
2027
+ 'addressFrom': addressFrom,
2028
+ 'addressTo': addressTo,
2029
+ 'tag': this.safeString(transaction, 'extra'),
2030
+ 'tagFrom': undefined,
2031
+ 'tagTo': undefined,
2032
+ 'type': movementDirection,
2033
+ 'amount': this.safeNumber(transaction, 'amount'),
2034
+ 'currency': code,
2035
+ 'status': this.parseTransactionStatus(this.safeString(transaction, 'status')),
2036
+ 'updated': this.safeTimestamp(transaction, 'updated_time'),
2037
+ 'comment': undefined,
2038
+ 'internal': undefined,
2039
+ 'fee': fee,
2040
+ 'network': undefined,
2041
+ };
2042
+ }
2043
+ parseTransactionStatus(status) {
2044
+ const statuses = {
2045
+ 'NEW': 'pending',
2046
+ 'CONFIRMING': 'pending',
2047
+ 'PROCESSING': 'pending',
2048
+ 'COMPLETED': 'ok',
2049
+ 'CANCELED': 'canceled',
2050
+ };
2051
+ return this.safeString(statuses, status, status);
2052
+ }
2053
+ async transfer(code, amount, fromAccount, toAccount, params = {}) {
2054
+ /**
2055
+ * @method
2056
+ * @name woo#transfer
2057
+ * @description transfer currency internally between wallets on the same account
2058
+ * @param {string} code unified currency code
2059
+ * @param {float} amount amount to transfer
2060
+ * @param {string} fromAccount account to transfer from
2061
+ * @param {string} toAccount account to transfer to
2062
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2063
+ * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2064
+ */
2065
+ await this.loadMarkets();
2066
+ const currency = this.currency(code);
2067
+ const request = {
2068
+ 'token': currency['id'],
2069
+ 'amount': this.parseNumber(amount),
2070
+ 'from_application_id': fromAccount,
2071
+ 'to_application_id': toAccount,
2072
+ };
2073
+ const response = await this.v1PrivatePostAssetMainSubTransfer(this.extend(request, params));
2074
+ //
2075
+ // {
2076
+ // "success": true,
2077
+ // "id": 200
2078
+ // }
2079
+ //
2080
+ const transfer = this.parseTransfer(response, currency);
2081
+ const transferOptions = this.safeValue(this.options, 'transfer', {});
2082
+ const fillResponseFromRequest = this.safeValue(transferOptions, 'fillResponseFromRequest', true);
2083
+ if (fillResponseFromRequest) {
2084
+ transfer['amount'] = amount;
2085
+ transfer['fromAccount'] = fromAccount;
2086
+ transfer['toAccount'] = toAccount;
2087
+ }
2088
+ return transfer;
2089
+ }
2090
+ async fetchTransfers(code = undefined, since = undefined, limit = undefined, params = {}) {
2091
+ /**
2092
+ * @method
2093
+ * @name woo#fetchTransfers
2094
+ * @description fetch a history of internal transfers made on an account
2095
+ * @param {string} code unified currency code of the currency transferred
2096
+ * @param {int} [since] the earliest time in ms to fetch transfers for
2097
+ * @param {int} [limit] the maximum number of transfers structures to retrieve
2098
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2099
+ * @returns {object[]} a list of [transfer structures]{@link https://docs.ccxt.com/#/?id=transfer-structure}
2100
+ */
2101
+ const request = {
2102
+ 'type': 'COLLATERAL',
2103
+ };
2104
+ const [currency, rows] = await this.getAssetHistoryRows(code, since, limit, this.extend(request, params));
2105
+ return this.parseTransfers(rows, currency, since, limit, params);
2106
+ }
2107
+ parseTransfer(transfer, currency = undefined) {
2108
+ //
2109
+ // getAssetHistoryRows
2110
+ // {
2111
+ // "created_time": "1579399877.041", // Unix epoch time in seconds
2112
+ // "updated_time": "1579399877.041", // Unix epoch time in seconds
2113
+ // "id": "202029292829292",
2114
+ // "external_id": "202029292829292",
2115
+ // "application_id": null,
2116
+ // "token": "ETH",
2117
+ // "target_address": "0x31d64B3230f8baDD91dE1710A65DF536aF8f7cDa",
2118
+ // "source_address": "0x70fd25717f769c7f9a46b319f0f9103c0d887af0",
2119
+ // "extra": "",
2120
+ // "type": "BALANCE",
2121
+ // "token_side": "DEPOSIT",
2122
+ // "amount": 1000,
2123
+ // "tx_id": "0x8a74c517bc104c8ebad0c3c3f64b1f302ed5f8bca598ae4459c63419038106b6",
2124
+ // "fee_token": null,
2125
+ // "fee_amount": null,
2126
+ // "status": "CONFIRMING"
2127
+ // }
2128
+ //
2129
+ // v1PrivatePostAssetMainSubTransfer
2130
+ // {
2131
+ // "success": true,
2132
+ // "id": 200
2133
+ // }
2134
+ //
2135
+ const networkizedCode = this.safeString(transfer, 'token');
2136
+ const currencyDefined = this.getCurrencyFromChaincode(networkizedCode, currency);
2137
+ const code = currencyDefined['code'];
2138
+ let movementDirection = this.safeStringLower(transfer, 'token_side');
2139
+ if (movementDirection === 'withdraw') {
2140
+ movementDirection = 'withdrawal';
2141
+ }
2142
+ let fromAccount = undefined;
2143
+ let toAccount = undefined;
2144
+ if (movementDirection === 'withdraw') {
2145
+ fromAccount = undefined;
2146
+ toAccount = 'spot';
2147
+ }
2148
+ else if (movementDirection === 'deposit') {
2149
+ fromAccount = 'spot';
2150
+ toAccount = undefined;
2151
+ }
2152
+ const timestamp = this.safeTimestamp(transfer, 'created_time');
2153
+ const success = this.safeValue(transfer, 'success');
2154
+ let status = undefined;
2155
+ if (success !== undefined) {
2156
+ status = success ? 'ok' : 'failed';
2157
+ }
2158
+ return {
2159
+ 'id': this.safeString(transfer, 'id'),
2160
+ 'timestamp': timestamp,
2161
+ 'datetime': this.iso8601(timestamp),
2162
+ 'currency': code,
2163
+ 'amount': this.safeNumber(transfer, 'amount'),
2164
+ 'fromAccount': fromAccount,
2165
+ 'toAccount': toAccount,
2166
+ 'status': this.parseTransferStatus(this.safeString(transfer, 'status', status)),
2167
+ 'info': transfer,
2168
+ };
2169
+ }
2170
+ parseTransferStatus(status) {
2171
+ const statuses = {
2172
+ 'NEW': 'pending',
2173
+ 'CONFIRMING': 'pending',
2174
+ 'PROCESSING': 'pending',
2175
+ 'COMPLETED': 'ok',
2176
+ 'CANCELED': 'canceled',
2177
+ };
2178
+ return this.safeString(statuses, status, status);
2179
+ }
2180
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
2181
+ /**
2182
+ * @method
2183
+ * @name woo#withdraw
2184
+ * @description make a withdrawal
2185
+ * @param {string} code unified currency code
2186
+ * @param {float} amount the amount to withdraw
2187
+ * @param {string} address the address to withdraw to
2188
+ * @param {string} tag
2189
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2190
+ * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
2191
+ */
2192
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
2193
+ await this.loadMarkets();
2194
+ this.checkAddress(address);
2195
+ const currency = this.currency(code);
2196
+ const request = {
2197
+ 'amount': amount,
2198
+ 'address': address,
2199
+ };
2200
+ if (tag !== undefined) {
2201
+ request['extra'] = tag;
2202
+ }
2203
+ const networks = this.safeValue(this.options, 'networks', {});
2204
+ const currencyNetworks = this.safeValue(currency, 'networks', {});
2205
+ const network = this.safeStringUpper(params, 'network');
2206
+ const networkId = this.safeString(networks, network, network);
2207
+ const coinNetwork = this.safeValue(currencyNetworks, networkId, {});
2208
+ const coinNetworkId = this.safeString(coinNetwork, 'id');
2209
+ if (coinNetworkId === undefined) {
2210
+ throw new errors.BadRequest(this.id + ' withdraw() require network parameter');
2211
+ }
2212
+ request['token'] = coinNetworkId;
2213
+ const response = await this.v1PrivatePostAssetWithdraw(this.extend(request, params));
2214
+ //
2215
+ // {
2216
+ // "success": true,
2217
+ // "withdraw_id": "20200119145703654"
2218
+ // }
2219
+ //
2220
+ return this.parseTransaction(response, currency);
2221
+ }
2222
+ async repayMargin(code, amount, symbol = undefined, params = {}) {
2223
+ /**
2224
+ * @method
2225
+ * @name woo#repayMargin
2226
+ * @description repay borrowed margin and interest
2227
+ * @see https://docs.woo.org/#repay-interest
2228
+ * @param {string} code unified currency code of the currency to repay
2229
+ * @param {float} amount the amount to repay
2230
+ * @param {string} symbol not used by woo.repayMargin ()
2231
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2232
+ * @returns {object} a [margin loan structure]{@link https://docs.ccxt.com/#/?id=margin-loan-structure}
2233
+ */
2234
+ await this.loadMarkets();
2235
+ let market = undefined;
2236
+ if (symbol !== undefined) {
2237
+ market = this.market(symbol);
2238
+ symbol = market['symbol'];
2239
+ }
2240
+ const currency = this.currency(code);
2241
+ const request = {
2242
+ 'token': currency['id'],
2243
+ 'amount': this.currencyToPrecision(code, amount),
2244
+ };
2245
+ const response = await this.v1PrivatePostInterestRepay(this.extend(request, params));
2246
+ //
2247
+ // {
2248
+ // "success": true,
2249
+ // }
2250
+ //
2251
+ const transaction = this.parseMarginLoan(response, currency);
2252
+ return this.extend(transaction, {
2253
+ 'amount': amount,
2254
+ 'symbol': symbol,
2255
+ });
2256
+ }
2257
+ parseMarginLoan(info, currency = undefined) {
2258
+ //
2259
+ // {
2260
+ // "success": true,
2261
+ // }
2262
+ //
2263
+ return {
2264
+ 'id': undefined,
2265
+ 'currency': this.safeCurrencyCode(undefined, currency),
2266
+ 'amount': undefined,
2267
+ 'symbol': undefined,
2268
+ 'timestamp': undefined,
2269
+ 'datetime': undefined,
2270
+ 'info': info,
2271
+ };
2272
+ }
2273
+ nonce() {
2274
+ return this.milliseconds();
2275
+ }
2276
+ sign(path, section = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
2277
+ const version = section[0];
2278
+ const access = section[1];
2279
+ const pathWithParams = this.implodeParams(path, params);
2280
+ let url = this.implodeHostname(this.urls['api'][access]);
2281
+ url += '/' + version + '/';
2282
+ params = this.omit(params, this.extractParams(path));
2283
+ params = this.keysort(params);
2284
+ if (access === 'public') {
2285
+ url += access + '/' + pathWithParams;
2286
+ if (Object.keys(params).length) {
2287
+ url += '?' + this.urlencode(params);
2288
+ }
2289
+ }
2290
+ else {
2291
+ this.checkRequiredCredentials();
2292
+ if (method === 'POST' && (path === 'algo/order' || path === 'order')) {
2293
+ const isSandboxMode = this.safeValue(this.options, 'sandboxMode', false);
2294
+ if (!isSandboxMode) {
2295
+ const applicationId = 'bc830de7-50f3-460b-9ee0-f430f83f9dad';
2296
+ const brokerId = this.safeString(this.options, 'brokerId', applicationId);
2297
+ const isStop = path.indexOf('algo') > -1;
2298
+ if (isStop) {
2299
+ params['brokerId'] = brokerId;
2300
+ }
2301
+ else {
2302
+ params['broker_id'] = brokerId;
2303
+ }
2304
+ }
2305
+ params = this.keysort(params);
2306
+ }
2307
+ let auth = '';
2308
+ const ts = this.nonce().toString();
2309
+ url += pathWithParams;
2310
+ headers = {
2311
+ 'x-api-key': this.apiKey,
2312
+ 'x-api-timestamp': ts,
2313
+ };
2314
+ if (version === 'v3') {
2315
+ auth = ts + method + '/' + version + '/' + pathWithParams;
2316
+ if (method === 'POST' || method === 'PUT' || method === 'DELETE') {
2317
+ body = this.json(params);
2318
+ auth += body;
2319
+ }
2320
+ else {
2321
+ if (Object.keys(params).length) {
2322
+ const query = this.urlencode(params);
2323
+ url += '?' + query;
2324
+ auth += '?' + query;
2325
+ }
2326
+ }
2327
+ headers['content-type'] = 'application/json';
2328
+ }
2329
+ else {
2330
+ auth = this.urlencode(params);
2331
+ if (method === 'POST' || method === 'PUT' || method === 'DELETE') {
2332
+ body = auth;
2333
+ }
2334
+ else {
2335
+ url += '?' + auth;
2336
+ }
2337
+ auth += '|' + ts;
2338
+ headers['content-type'] = 'application/x-www-form-urlencoded';
2339
+ }
2340
+ headers['x-api-signature'] = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256);
2341
+ }
2342
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
2343
+ }
2344
+ handleErrors(httpCode, reason, url, method, headers, body, response, requestHeaders, requestBody) {
2345
+ if (!response) {
2346
+ return undefined; // fallback to default error handler
2347
+ }
2348
+ //
2349
+ // 400 Bad Request {"success":false,"code":-1012,"message":"Amount is required for buy market orders when margin disabled."}
2350
+ //
2351
+ const success = this.safeValue(response, 'success');
2352
+ const errorCode = this.safeString(response, 'code');
2353
+ if (!success) {
2354
+ const feedback = this.id + ' ' + this.json(response);
2355
+ this.throwBroadlyMatchedException(this.exceptions['broad'], body, feedback);
2356
+ this.throwExactlyMatchedException(this.exceptions['exact'], errorCode, feedback);
2357
+ }
2358
+ return undefined;
2359
+ }
2360
+ parseIncome(income, market = undefined) {
2361
+ //
2362
+ // {
2363
+ // "id":666666,
2364
+ // "symbol":"PERP_BTC_USDT",
2365
+ // "funding_rate":0.00001198,
2366
+ // "mark_price":28941.04000000,
2367
+ // "funding_fee":0.00069343,
2368
+ // "payment_type":"Pay",
2369
+ // "status":"COMPLETED",
2370
+ // "created_time":"1653616000.666",
2371
+ // "updated_time":"1653616000.605"
2372
+ // }
2373
+ //
2374
+ const marketId = this.safeString(income, 'symbol');
2375
+ const symbol = this.safeSymbol(marketId, market);
2376
+ const amount = this.safeNumber(income, 'funding_fee');
2377
+ const code = this.safeCurrencyCode('USD');
2378
+ const id = this.safeString(income, 'id');
2379
+ const timestamp = this.safeTimestamp(income, 'updated_time');
2380
+ const rate = this.safeNumber(income, 'funding_rate');
2381
+ return {
2382
+ 'info': income,
2383
+ 'symbol': symbol,
2384
+ 'code': code,
2385
+ 'timestamp': timestamp,
2386
+ 'datetime': this.iso8601(timestamp),
2387
+ 'id': id,
2388
+ 'amount': amount,
2389
+ 'rate': rate,
2390
+ };
2391
+ }
2392
+ async fetchFundingHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2393
+ await this.loadMarkets();
2394
+ const request = {};
2395
+ let market = undefined;
2396
+ if (symbol !== undefined) {
2397
+ market = this.market(symbol);
2398
+ request['symbol'] = market['id'];
2399
+ }
2400
+ if (since !== undefined) {
2401
+ request['start_t'] = since;
2402
+ }
2403
+ const response = await this.v1PrivateGetFundingFeeHistory(this.extend(request, params));
2404
+ //
2405
+ // {
2406
+ // "rows":[
2407
+ // {
2408
+ // "id":666666,
2409
+ // "symbol":"PERP_BTC_USDT",
2410
+ // "funding_rate":0.00001198,
2411
+ // "mark_price":28941.04000000,
2412
+ // "funding_fee":0.00069343,
2413
+ // "payment_type":"Pay",
2414
+ // "status":"COMPLETED",
2415
+ // "created_time":"1653616000.666",
2416
+ // "updated_time":"1653616000.605"
2417
+ // }
2418
+ // ],
2419
+ // "meta":{
2420
+ // "total":235,
2421
+ // "records_per_page":25,
2422
+ // "current_page":1
2423
+ // },
2424
+ // "success":true
2425
+ // }
2426
+ //
2427
+ const result = this.safeValue(response, 'rows', []);
2428
+ return this.parseIncomes(result, market, since, limit);
2429
+ }
2430
+ parseFundingRate(fundingRate, market = undefined) {
2431
+ //
2432
+ // {
2433
+ // "symbol":"PERP_AAVE_USDT",
2434
+ // "est_funding_rate":-0.00003447,
2435
+ // "est_funding_rate_timestamp":1653633959001,
2436
+ // "last_funding_rate":-0.00002094,
2437
+ // "last_funding_rate_timestamp":1653631200000,
2438
+ // "next_funding_time":1653634800000
2439
+ // }
2440
+ //
2441
+ //
2442
+ const symbol = this.safeString(fundingRate, 'symbol');
2443
+ market = this.market(symbol);
2444
+ const nextFundingTimestamp = this.safeInteger(fundingRate, 'next_funding_time');
2445
+ const estFundingRateTimestamp = this.safeInteger(fundingRate, 'est_funding_rate_timestamp');
2446
+ const lastFundingRateTimestamp = this.safeInteger(fundingRate, 'last_funding_rate_timestamp');
2447
+ return {
2448
+ 'info': fundingRate,
2449
+ 'symbol': market['symbol'],
2450
+ 'markPrice': undefined,
2451
+ 'indexPrice': undefined,
2452
+ 'interestRate': this.parseNumber('0'),
2453
+ 'estimatedSettlePrice': undefined,
2454
+ 'timestamp': estFundingRateTimestamp,
2455
+ 'datetime': this.iso8601(estFundingRateTimestamp),
2456
+ 'fundingRate': this.safeNumber(fundingRate, 'est_funding_rate'),
2457
+ 'fundingTimestamp': nextFundingTimestamp,
2458
+ 'fundingDatetime': this.iso8601(nextFundingTimestamp),
2459
+ 'nextFundingRate': undefined,
2460
+ 'nextFundingTimestamp': undefined,
2461
+ 'nextFundingDatetime': undefined,
2462
+ 'previousFundingRate': this.safeNumber(fundingRate, 'last_funding_rate'),
2463
+ 'previousFundingTimestamp': lastFundingRateTimestamp,
2464
+ 'previousFundingDatetime': this.iso8601(lastFundingRateTimestamp),
2465
+ };
2466
+ }
2467
+ async fetchFundingRate(symbol, params = {}) {
2468
+ await this.loadMarkets();
2469
+ const market = this.market(symbol);
2470
+ const request = {
2471
+ 'symbol': market['id'],
2472
+ };
2473
+ const response = await this.v1PublicGetFundingRateSymbol(this.extend(request, params));
2474
+ //
2475
+ // {
2476
+ // "success":true,
2477
+ // "timestamp":1653640572711,
2478
+ // "symbol":"PERP_BTC_USDT",
2479
+ // "est_funding_rate":0.00000738,
2480
+ // "est_funding_rate_timestamp":1653640559003,
2481
+ // "last_funding_rate":0.00000629,
2482
+ // "last_funding_rate_timestamp":1653638400000,
2483
+ // "next_funding_time":1653642000000
2484
+ // }
2485
+ //
2486
+ return this.parseFundingRate(response, market);
2487
+ }
2488
+ async fetchFundingRates(symbols = undefined, params = {}) {
2489
+ await this.loadMarkets();
2490
+ symbols = this.marketSymbols(symbols);
2491
+ const response = await this.v1PublicGetFundingRates(params);
2492
+ //
2493
+ // {
2494
+ // "success":true,
2495
+ // "rows":[
2496
+ // {
2497
+ // "symbol":"PERP_AAVE_USDT",
2498
+ // "est_funding_rate":-0.00003447,
2499
+ // "est_funding_rate_timestamp":1653633959001,
2500
+ // "last_funding_rate":-0.00002094,
2501
+ // "last_funding_rate_timestamp":1653631200000,
2502
+ // "next_funding_time":1653634800000
2503
+ // }
2504
+ // ],
2505
+ // "timestamp":1653633985646
2506
+ // }
2507
+ //
2508
+ const rows = this.safeValue(response, 'rows', {});
2509
+ const result = this.parseFundingRates(rows);
2510
+ return this.filterByArray(result, 'symbol', symbols);
2511
+ }
2512
+ async fetchFundingRateHistory(symbol = undefined, since = undefined, limit = undefined, params = {}) {
2513
+ /**
2514
+ * @method
2515
+ * @name woo#fetchFundingRateHistory
2516
+ * @description fetches historical funding rate prices
2517
+ * @see https://docs.woo.org/#get-funding-rate-history-for-one-market-public
2518
+ * @param {string} symbol unified symbol of the market to fetch the funding rate history for
2519
+ * @param {int} [since] timestamp in ms of the earliest funding rate to fetch
2520
+ * @param {int} [limit] the maximum amount of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure} to fetch
2521
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
2522
+ * @param {int} [params.until] timestamp in ms of the latest funding rate
2523
+ * @param {boolean} [params.paginate] default false, when true will automatically paginate by calling this endpoint multiple times. See in the docs all the [availble parameters](https://github.com/ccxt/ccxt/wiki/Manual#pagination-params)
2524
+ * @returns {object[]} a list of [funding rate structures]{@link https://docs.ccxt.com/#/?id=funding-rate-history-structure}
2525
+ */
2526
+ await this.loadMarkets();
2527
+ let paginate = false;
2528
+ [paginate, params] = this.handleOptionAndParams(params, 'fetchFundingRateHistory', 'paginate');
2529
+ if (paginate) {
2530
+ return await this.fetchPaginatedCallIncremental('fetchFundingRateHistory', symbol, since, limit, params, 'page', 25);
2531
+ }
2532
+ let request = {};
2533
+ if (symbol !== undefined) {
2534
+ const market = this.market(symbol);
2535
+ symbol = market['symbol'];
2536
+ request['symbol'] = market['id'];
2537
+ }
2538
+ if (since !== undefined) {
2539
+ request['start_t'] = this.parseToInt(since / 1000);
2540
+ }
2541
+ [request, params] = this.handleUntilOption('end_t', request, params, 0.001);
2542
+ const response = await this.v1PublicGetFundingRateHistory(this.extend(request, params));
2543
+ //
2544
+ // {
2545
+ // "success":true,
2546
+ // "meta":{
2547
+ // "total":2464,
2548
+ // "records_per_page":25,
2549
+ // "current_page":1
2550
+ // },
2551
+ // "rows":[
2552
+ // {
2553
+ // "symbol":"PERP_BTC_USDT",
2554
+ // "funding_rate":0.00000629,
2555
+ // "funding_rate_timestamp":1653638400000,
2556
+ // "next_funding_time":1653642000000
2557
+ // }
2558
+ // ],
2559
+ // "timestamp":1653640814885
2560
+ // }
2561
+ //
2562
+ const result = this.safeValue(response, 'rows');
2563
+ const rates = [];
2564
+ for (let i = 0; i < result.length; i++) {
2565
+ const entry = result[i];
2566
+ const marketId = this.safeString(entry, 'symbol');
2567
+ const timestamp = this.safeInteger(entry, 'funding_rate_timestamp');
2568
+ rates.push({
2569
+ 'info': entry,
2570
+ 'symbol': this.safeSymbol(marketId),
2571
+ 'fundingRate': this.safeNumber(entry, 'funding_rate'),
2572
+ 'timestamp': timestamp,
2573
+ 'datetime': this.iso8601(timestamp),
2574
+ });
2575
+ }
2576
+ const sorted = this.sortBy(rates, 'timestamp');
2577
+ return this.filterBySymbolSinceLimit(sorted, symbol, since, limit);
2578
+ }
2579
+ async fetchLeverage(symbol, params = {}) {
2580
+ await this.loadMarkets();
2581
+ const response = await this.v3PrivateGetAccountinfo(params);
2582
+ //
2583
+ // {
2584
+ // "success": true,
2585
+ // "data": {
2586
+ // "applicationId": "dsa",
2587
+ // "account": "dsa",
2588
+ // "alias": "haha",
2589
+ // "accountMode": "MARGIN",
2590
+ // "leverage": 1,
2591
+ // "takerFeeRate": 1,
2592
+ // "makerFeeRate": 1,
2593
+ // "interestRate": 1,
2594
+ // "futuresTakerFeeRate": 1,
2595
+ // "futuresMakerFeeRate": 1,
2596
+ // "otpauth": true,
2597
+ // "marginRatio": 1,
2598
+ // "openMarginRatio": 1,
2599
+ // "initialMarginRatio": 1,
2600
+ // "maintenanceMarginRatio": 1,
2601
+ // "totalCollateral": 1,
2602
+ // "freeCollateral": 1,
2603
+ // "totalAccountValue": 1,
2604
+ // "totalVaultValue": 1,
2605
+ // "totalStakingValue": 1
2606
+ // },
2607
+ // "timestamp": 1673323685109
2608
+ // }
2609
+ //
2610
+ const result = this.safeValue(response, 'data');
2611
+ const leverage = this.safeNumber(result, 'leverage');
2612
+ return {
2613
+ 'info': response,
2614
+ 'leverage': leverage,
2615
+ };
2616
+ }
2617
+ async setLeverage(leverage, symbol = undefined, params = {}) {
2618
+ await this.loadMarkets();
2619
+ if ((leverage < 1) || (leverage > 20)) {
2620
+ throw new errors.BadRequest(this.id + ' leverage should be between 1 and 20');
2621
+ }
2622
+ const request = {
2623
+ 'leverage': leverage,
2624
+ };
2625
+ return await this.v1PrivatePostClientLeverage(this.extend(request, params));
2626
+ }
2627
+ async fetchPosition(symbol = undefined, params = {}) {
2628
+ await this.loadMarkets();
2629
+ const market = this.market(symbol);
2630
+ const request = {
2631
+ 'symbol': market['id'],
2632
+ };
2633
+ const response = await this.v1PrivateGetPositionSymbol(this.extend(request, params));
2634
+ //
2635
+ // {
2636
+ // "symbol":"PERP_ETC_USDT",
2637
+ // "holding":0.0,
2638
+ // "pnl_24_h":0,
2639
+ // "settle_price":0.0,
2640
+ // "average_open_price":0,
2641
+ // "success":true,
2642
+ // "mark_price":22.6955,
2643
+ // "pending_short_qty":0.0,
2644
+ // "pending_long_qty":0.0,
2645
+ // "fee_24_h":0,
2646
+ // "timestamp":"1652231044.920"
2647
+ // }
2648
+ //
2649
+ return this.parsePosition(response, market);
2650
+ }
2651
+ async fetchPositions(symbols = undefined, params = {}) {
2652
+ await this.loadMarkets();
2653
+ const response = await this.v3PrivateGetPositions(params);
2654
+ //
2655
+ // {
2656
+ // "success": true,
2657
+ // "data": {
2658
+ // "positions": [
2659
+ // {
2660
+ // "symbol": "0_symbol",
2661
+ // "holding": 1,
2662
+ // "pendingLongQty": 0,
2663
+ // "pendingShortQty": 1,
2664
+ // "settlePrice": 1,
2665
+ // "averageOpenPrice": 1,
2666
+ // "pnl24H": 1,
2667
+ // "fee24H": 1,
2668
+ // "markPrice": 1,
2669
+ // "estLiqPrice": 1,
2670
+ // "timestamp": 12321321
2671
+ // }
2672
+ // ]
2673
+ // },
2674
+ // "timestamp": 1673323880342
2675
+ // }
2676
+ //
2677
+ const result = this.safeValue(response, 'data', {});
2678
+ const positions = this.safeValue(result, 'positions', []);
2679
+ return this.parsePositions(positions, symbols);
2680
+ }
2681
+ parsePosition(position, market = undefined) {
2682
+ //
2683
+ // {
2684
+ // "symbol": "0_symbol",
2685
+ // "holding": 1,
2686
+ // "pendingLongQty": 0,
2687
+ // "pendingShortQty": 1,
2688
+ // "settlePrice": 1,
2689
+ // "averageOpenPrice": 1,
2690
+ // "pnl24H": 1,
2691
+ // "fee24H": 1,
2692
+ // "markPrice": 1,
2693
+ // "estLiqPrice": 1,
2694
+ // "timestamp": 12321321
2695
+ // }
2696
+ //
2697
+ const contract = this.safeString(position, 'symbol');
2698
+ market = this.safeMarket(contract, market);
2699
+ let size = this.safeString(position, 'holding');
2700
+ let side = undefined;
2701
+ if (Precise["default"].stringGt(size, '0')) {
2702
+ side = 'long';
2703
+ }
2704
+ else {
2705
+ side = 'short';
2706
+ }
2707
+ const contractSize = this.safeString(market, 'contractSize');
2708
+ const markPrice = this.safeString(position, 'markPrice');
2709
+ const timestamp = this.safeTimestamp(position, 'timestamp');
2710
+ const entryPrice = this.safeString(position, 'averageOpenPrice');
2711
+ const priceDifference = Precise["default"].stringSub(markPrice, entryPrice);
2712
+ const unrealisedPnl = Precise["default"].stringMul(priceDifference, size);
2713
+ size = Precise["default"].stringAbs(size);
2714
+ const notional = Precise["default"].stringMul(size, markPrice);
2715
+ return this.safePosition({
2716
+ 'info': position,
2717
+ 'id': undefined,
2718
+ 'symbol': this.safeString(market, 'symbol'),
2719
+ 'timestamp': timestamp,
2720
+ 'datetime': this.iso8601(timestamp),
2721
+ 'lastUpdateTimestamp': undefined,
2722
+ 'initialMargin': undefined,
2723
+ 'initialMarginPercentage': undefined,
2724
+ 'maintenanceMargin': undefined,
2725
+ 'maintenanceMarginPercentage': undefined,
2726
+ 'entryPrice': this.parseNumber(entryPrice),
2727
+ 'notional': this.parseNumber(notional),
2728
+ 'leverage': undefined,
2729
+ 'unrealizedPnl': this.parseNumber(unrealisedPnl),
2730
+ 'contracts': this.parseNumber(size),
2731
+ 'contractSize': this.parseNumber(contractSize),
2732
+ 'marginRatio': undefined,
2733
+ 'liquidationPrice': this.safeNumber(position, 'estLiqPrice'),
2734
+ 'markPrice': this.parseNumber(markPrice),
2735
+ 'lastPrice': undefined,
2736
+ 'collateral': undefined,
2737
+ 'marginMode': 'cross',
2738
+ 'marginType': undefined,
2739
+ 'side': side,
2740
+ 'percentage': undefined,
2741
+ 'hedged': undefined,
2742
+ 'stopLossPrice': undefined,
2743
+ 'takeProfitPrice': undefined,
2744
+ });
2745
+ }
2746
+ defaultNetworkCodeForCurrency(code) {
2747
+ const currencyItem = this.currency(code);
2748
+ const networks = currencyItem['networks'];
2749
+ const networkKeys = Object.keys(networks);
2750
+ for (let i = 0; i < networkKeys.length; i++) {
2751
+ const network = networkKeys[i];
2752
+ if (network === 'ETH') {
2753
+ return network;
2754
+ }
2755
+ }
2756
+ // if it was not returned according to above options, then return the first network of currency
2757
+ return this.safeValue(networkKeys, 0);
2758
+ }
2759
+ setSandboxMode(enable) {
2760
+ super.setSandboxMode(enable);
2761
+ this.options['sandboxMode'] = enable;
2762
+ }
2763
+ }
2764
+
2765
+ module.exports = woo;