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,1670 @@
1
+ 'use strict';
2
+
3
+ var bitfinex$1 = require('./abstract/bitfinex.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 sha512 = require('./static_dependencies/noble-hashes/sha512.js');
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * @class bitfinex
13
+ * @augments Exchange
14
+ */
15
+ class bitfinex extends bitfinex$1 {
16
+ describe() {
17
+ return this.deepExtend(super.describe(), {
18
+ 'id': 'bitfinex',
19
+ 'name': 'Bitfinex',
20
+ 'countries': ['VG'],
21
+ 'version': 'v1',
22
+ // cheapest is 90 requests a minute = 1.5 requests per second on average => ( 1000ms / 1.5) = 666.666 ms between requests on average
23
+ 'rateLimit': 666.666,
24
+ 'pro': true,
25
+ // new metainfo interface
26
+ 'has': {
27
+ 'CORS': undefined,
28
+ 'spot': true,
29
+ 'margin': undefined,
30
+ 'swap': undefined,
31
+ 'future': undefined,
32
+ 'option': undefined,
33
+ 'cancelAllOrders': true,
34
+ 'cancelOrder': true,
35
+ 'createDepositAddress': true,
36
+ 'createOrder': true,
37
+ 'editOrder': true,
38
+ 'fetchBalance': true,
39
+ 'fetchClosedOrders': true,
40
+ 'fetchDepositAddress': true,
41
+ 'fetchDeposits': false,
42
+ 'fetchDepositsWithdrawals': true,
43
+ 'fetchDepositWithdrawFee': 'emulated',
44
+ 'fetchDepositWithdrawFees': true,
45
+ 'fetchIndexOHLCV': false,
46
+ 'fetchLeverageTiers': false,
47
+ 'fetchMarginMode': false,
48
+ 'fetchMarkets': true,
49
+ 'fetchMarkOHLCV': false,
50
+ 'fetchMyTrades': true,
51
+ 'fetchOHLCV': true,
52
+ 'fetchOpenOrders': true,
53
+ 'fetchOrder': true,
54
+ 'fetchOrderBook': true,
55
+ 'fetchPositionMode': false,
56
+ 'fetchPositions': true,
57
+ 'fetchPremiumIndexOHLCV': false,
58
+ 'fetchTicker': true,
59
+ 'fetchTickers': true,
60
+ 'fetchTime': false,
61
+ 'fetchTrades': true,
62
+ 'fetchTradingFee': false,
63
+ 'fetchTradingFees': true,
64
+ 'fetchTransactionFees': true,
65
+ 'fetchTransactions': 'emulated',
66
+ 'transfer': true,
67
+ 'withdraw': true,
68
+ },
69
+ 'timeframes': {
70
+ '1m': '1m',
71
+ '5m': '5m',
72
+ '15m': '15m',
73
+ '30m': '30m',
74
+ '1h': '1h',
75
+ '3h': '3h',
76
+ '4h': '4h',
77
+ '6h': '6h',
78
+ '12h': '12h',
79
+ '1d': '1D',
80
+ '1w': '7D',
81
+ '2w': '14D',
82
+ '1M': '1M',
83
+ },
84
+ 'urls': {
85
+ 'logo': 'https://user-images.githubusercontent.com/1294454/27766244-e328a50c-5ed2-11e7-947b-041416579bb3.jpg',
86
+ 'api': {
87
+ 'v2': 'https://api-pub.bitfinex.com',
88
+ 'public': 'https://api.bitfinex.com',
89
+ 'private': 'https://api.bitfinex.com',
90
+ },
91
+ 'www': 'https://www.bitfinex.com',
92
+ 'referral': 'https://www.bitfinex.com/?refcode=P61eYxFL',
93
+ 'doc': [
94
+ 'https://docs.bitfinex.com/v1/docs',
95
+ 'https://github.com/bitfinexcom/bitfinex-api-node',
96
+ ],
97
+ },
98
+ 'api': {
99
+ // v2 symbol ids require a 't' prefix
100
+ // just the public part of it (use bitfinex2 for everything else)
101
+ 'v2': {
102
+ 'get': {
103
+ 'platform/status': 3,
104
+ 'tickers': 1,
105
+ 'ticker/{symbol}': 1,
106
+ 'tickers/hist': 1,
107
+ 'trades/{symbol}/hist': 1,
108
+ 'book/{symbol}/{precision}': 0.375,
109
+ 'book/{symbol}/P0': 0.375,
110
+ 'book/{symbol}/P1': 0.375,
111
+ 'book/{symbol}/P2': 0.375,
112
+ 'book/{symbol}/P3': 0.375,
113
+ 'book/{symbol}/R0': 0.375,
114
+ 'stats1/{key}:{size}:{symbol}:{side}/{section}': 1,
115
+ 'stats1/{key}:{size}:{symbol}/{section}': 1,
116
+ 'stats1/{key}:{size}:{symbol}:long/last': 1,
117
+ 'stats1/{key}:{size}:{symbol}:long/hist': 1,
118
+ 'stats1/{key}:{size}:{symbol}:short/last': 1,
119
+ 'stats1/{key}:{size}:{symbol}:short/hist': 1,
120
+ 'candles/trade:{timeframe}:{symbol}/{section}': 1,
121
+ 'candles/trade:{timeframe}:{symbol}/last': 1,
122
+ 'candles/trade:{timeframe}:{symbol}/hist': 1,
123
+ },
124
+ },
125
+ 'public': {
126
+ 'get': {
127
+ 'book/{symbol}': 1,
128
+ // 'candles/{symbol}':0,
129
+ 'lendbook/{currency}': 6,
130
+ 'lends/{currency}': 3,
131
+ 'pubticker/{symbol}': 3,
132
+ 'stats/{symbol}': 6,
133
+ 'symbols': 18,
134
+ 'symbols_details': 18,
135
+ 'tickers': 1,
136
+ 'trades/{symbol}': 3, // 60 requests a minute = 1 request per second => (1000ms / rateLimit) / 1 = 1.5 ... but only works if set to 3
137
+ },
138
+ },
139
+ 'private': {
140
+ 'post': {
141
+ 'account_fees': 18,
142
+ 'account_infos': 6,
143
+ 'balances': 9.036,
144
+ 'basket_manage': 6,
145
+ 'credits': 6,
146
+ 'deposit/new': 18,
147
+ 'funding/close': 6,
148
+ 'history': 6,
149
+ 'history/movements': 6,
150
+ 'key_info': 6,
151
+ 'margin_infos': 3,
152
+ 'mytrades': 3,
153
+ 'mytrades_funding': 6,
154
+ 'offer/cancel': 6,
155
+ 'offer/new': 6,
156
+ 'offer/status': 6,
157
+ 'offers': 6,
158
+ 'offers/hist': 90.03,
159
+ 'order/cancel': 0.2,
160
+ 'order/cancel/all': 0.2,
161
+ 'order/cancel/multi': 0.2,
162
+ 'order/cancel/replace': 0.2,
163
+ 'order/new': 0.2,
164
+ 'order/new/multi': 0.2,
165
+ 'order/status': 0.2,
166
+ 'orders': 0.2,
167
+ 'orders/hist': 90.03,
168
+ 'position/claim': 18,
169
+ 'position/close': 18,
170
+ 'positions': 18,
171
+ 'summary': 18,
172
+ 'taken_funds': 6,
173
+ 'total_taken_funds': 6,
174
+ 'transfer': 18,
175
+ 'unused_taken_funds': 6,
176
+ 'withdraw': 18,
177
+ },
178
+ },
179
+ },
180
+ 'fees': {
181
+ 'trading': {
182
+ 'feeSide': 'get',
183
+ 'tierBased': true,
184
+ 'percentage': true,
185
+ 'maker': this.parseNumber('0.001'),
186
+ 'taker': this.parseNumber('0.002'),
187
+ 'tiers': {
188
+ 'taker': [
189
+ [this.parseNumber('0'), this.parseNumber('0.002')],
190
+ [this.parseNumber('500000'), this.parseNumber('0.002')],
191
+ [this.parseNumber('1000000'), this.parseNumber('0.002')],
192
+ [this.parseNumber('2500000'), this.parseNumber('0.002')],
193
+ [this.parseNumber('5000000'), this.parseNumber('0.002')],
194
+ [this.parseNumber('7500000'), this.parseNumber('0.002')],
195
+ [this.parseNumber('10000000'), this.parseNumber('0.0018')],
196
+ [this.parseNumber('15000000'), this.parseNumber('0.0016')],
197
+ [this.parseNumber('20000000'), this.parseNumber('0.0014')],
198
+ [this.parseNumber('25000000'), this.parseNumber('0.0012')],
199
+ [this.parseNumber('30000000'), this.parseNumber('0.001')],
200
+ ],
201
+ 'maker': [
202
+ [this.parseNumber('0'), this.parseNumber('0.001')],
203
+ [this.parseNumber('500000'), this.parseNumber('0.0008')],
204
+ [this.parseNumber('1000000'), this.parseNumber('0.0006')],
205
+ [this.parseNumber('2500000'), this.parseNumber('0.0004')],
206
+ [this.parseNumber('5000000'), this.parseNumber('0.0002')],
207
+ [this.parseNumber('7500000'), this.parseNumber('0')],
208
+ [this.parseNumber('10000000'), this.parseNumber('0')],
209
+ [this.parseNumber('15000000'), this.parseNumber('0')],
210
+ [this.parseNumber('20000000'), this.parseNumber('0')],
211
+ [this.parseNumber('25000000'), this.parseNumber('0')],
212
+ [this.parseNumber('30000000'), this.parseNumber('0')],
213
+ ],
214
+ },
215
+ },
216
+ 'funding': {
217
+ 'tierBased': false,
218
+ 'percentage': false,
219
+ // Actually deposit fees are free for larger deposits (> $1000 USD equivalent)
220
+ // these values below are deprecated, we should not hardcode fees and limits anymore
221
+ // to be reimplemented with bitfinex funding fees from their API or web endpoints
222
+ 'deposit': {},
223
+ 'withdraw': {},
224
+ },
225
+ },
226
+ // todo rewrite for https://api-pub.bitfinex.com//v2/conf/pub:map:tx:method
227
+ 'commonCurrencies': {
228
+ 'ALG': 'ALGO',
229
+ 'AMP': 'AMPL',
230
+ 'ATO': 'ATOM',
231
+ 'BCHABC': 'XEC',
232
+ 'BCHN': 'BCH',
233
+ 'DAT': 'DATA',
234
+ 'DOG': 'MDOGE',
235
+ 'DSH': 'DASH',
236
+ // https://github.com/ccxt/ccxt/issues/7399
237
+ // https://coinmarketcap.com/currencies/pnetwork/
238
+ // https://en.cryptonomist.ch/blog/eidoo/the-edo-to-pnt-upgrade-what-you-need-to-know-updated/
239
+ 'EDO': 'PNT',
240
+ 'EUS': 'EURS',
241
+ 'EUT': 'EURT',
242
+ 'IDX': 'ID',
243
+ 'IOT': 'IOTA',
244
+ 'IQX': 'IQ',
245
+ 'LUNA': 'LUNC',
246
+ 'LUNA2': 'LUNA',
247
+ 'MNA': 'MANA',
248
+ 'ORS': 'ORS Group',
249
+ 'PAS': 'PASS',
250
+ 'QSH': 'QASH',
251
+ 'QTM': 'QTUM',
252
+ 'RBT': 'RBTC',
253
+ 'SNG': 'SNGLS',
254
+ 'STJ': 'STORJ',
255
+ 'TERRAUST': 'USTC',
256
+ 'TSD': 'TUSD',
257
+ 'YGG': 'YEED',
258
+ 'YYW': 'YOYOW',
259
+ 'UDC': 'USDC',
260
+ 'UST': 'USDT',
261
+ 'VSY': 'VSYS',
262
+ 'WAX': 'WAXP',
263
+ 'XCH': 'XCHF',
264
+ 'ZBT': 'ZB',
265
+ },
266
+ 'exceptions': {
267
+ 'exact': {
268
+ 'temporarily_unavailable': errors.ExchangeNotAvailable,
269
+ 'Order could not be cancelled.': errors.OrderNotFound,
270
+ 'No such order found.': errors.OrderNotFound,
271
+ 'Order price must be positive.': errors.InvalidOrder,
272
+ 'Could not find a key matching the given X-BFX-APIKEY.': errors.AuthenticationError,
273
+ 'Key price should be a decimal number, e.g. "123.456"': errors.InvalidOrder,
274
+ 'Key amount should be a decimal number, e.g. "123.456"': errors.InvalidOrder,
275
+ 'ERR_RATE_LIMIT': errors.RateLimitExceeded,
276
+ 'Ratelimit': errors.RateLimitExceeded,
277
+ 'Nonce is too small.': errors.InvalidNonce,
278
+ 'No summary found.': errors.ExchangeError,
279
+ 'Cannot evaluate your available balance, please try again': errors.ExchangeNotAvailable,
280
+ 'Unknown symbol': errors.BadSymbol,
281
+ 'Cannot complete transfer. Exchange balance insufficient.': errors.InsufficientFunds,
282
+ 'Momentary balance check. Please wait few seconds and try the transfer again.': errors.ExchangeError,
283
+ },
284
+ 'broad': {
285
+ 'Invalid X-BFX-SIGNATURE': errors.AuthenticationError,
286
+ 'This API key does not have permission': errors.PermissionDenied,
287
+ 'not enough exchange balance for ': errors.InsufficientFunds,
288
+ 'minimum size for ': errors.InvalidOrder,
289
+ 'Invalid order': errors.InvalidOrder,
290
+ 'The available balance is only': errors.InsufficientFunds, // {"status":"error","message":"Cannot withdraw 1.0027 ETH from your exchange wallet. The available balance is only 0.0 ETH. If you have limit orders, open positions, unused or active margin funding, this will decrease your available balance. To increase it, you can cancel limit orders or reduce/close your positions.","withdrawal_id":0,"fees":"0.0027"}
291
+ },
292
+ },
293
+ 'precisionMode': number.SIGNIFICANT_DIGITS,
294
+ 'options': {
295
+ 'currencyNames': {
296
+ 'AGI': 'agi',
297
+ 'AID': 'aid',
298
+ 'AIO': 'aio',
299
+ 'ANT': 'ant',
300
+ 'AVT': 'aventus',
301
+ 'BAT': 'bat',
302
+ // https://github.com/ccxt/ccxt/issues/5833
303
+ 'BCH': 'bab',
304
+ // 'BCH': 'bcash', // undocumented
305
+ 'BCI': 'bci',
306
+ 'BFT': 'bft',
307
+ 'BSV': 'bsv',
308
+ 'BTC': 'bitcoin',
309
+ 'BTG': 'bgold',
310
+ 'CFI': 'cfi',
311
+ 'COMP': 'comp',
312
+ 'DAI': 'dai',
313
+ 'DADI': 'dad',
314
+ 'DASH': 'dash',
315
+ 'DATA': 'datacoin',
316
+ 'DTH': 'dth',
317
+ 'EDO': 'eidoo',
318
+ 'ELF': 'elf',
319
+ 'EOS': 'eos',
320
+ 'ETC': 'ethereumc',
321
+ 'ETH': 'ethereum',
322
+ 'ETP': 'metaverse',
323
+ 'FUN': 'fun',
324
+ 'GNT': 'golem',
325
+ 'IOST': 'ios',
326
+ 'IOTA': 'iota',
327
+ // https://github.com/ccxt/ccxt/issues/5833
328
+ 'LEO': 'let',
329
+ // 'LEO': 'les', // EOS chain
330
+ 'LINK': 'link',
331
+ 'LRC': 'lrc',
332
+ 'LTC': 'litecoin',
333
+ 'LYM': 'lym',
334
+ 'MANA': 'mna',
335
+ 'MIT': 'mit',
336
+ 'MKR': 'mkr',
337
+ 'MTN': 'mtn',
338
+ 'NEO': 'neo',
339
+ 'ODE': 'ode',
340
+ 'OMG': 'omisego',
341
+ 'OMNI': 'mastercoin',
342
+ 'QASH': 'qash',
343
+ 'QTUM': 'qtum',
344
+ 'RCN': 'rcn',
345
+ 'RDN': 'rdn',
346
+ 'REP': 'rep',
347
+ 'REQ': 'req',
348
+ 'RLC': 'rlc',
349
+ 'SAN': 'santiment',
350
+ 'SNGLS': 'sng',
351
+ 'SNT': 'status',
352
+ 'SPANK': 'spk',
353
+ 'STORJ': 'stj',
354
+ 'TNB': 'tnb',
355
+ 'TRX': 'trx',
356
+ 'TUSD': 'tsd',
357
+ 'USD': 'wire',
358
+ 'USDC': 'udc',
359
+ 'UTK': 'utk',
360
+ 'USDT': 'tetheruso',
361
+ // 'USDT': 'tetheruse', // Tether on ERC20
362
+ // 'USDT': 'tetherusl', // Tether on Liquid
363
+ // 'USDT': 'tetherusx', // Tether on Tron
364
+ // 'USDT': 'tetheruss', // Tether on EOS
365
+ 'VEE': 'vee',
366
+ 'WAX': 'wax',
367
+ 'XLM': 'xlm',
368
+ 'XMR': 'monero',
369
+ 'XRP': 'ripple',
370
+ 'XVG': 'xvg',
371
+ 'YOYOW': 'yoyow',
372
+ 'ZEC': 'zcash',
373
+ 'ZRX': 'zrx',
374
+ 'XTZ': 'xtz',
375
+ },
376
+ 'orderTypes': {
377
+ 'limit': 'exchange limit',
378
+ 'market': 'exchange market',
379
+ },
380
+ 'fiat': {
381
+ 'USD': 'USD',
382
+ 'EUR': 'EUR',
383
+ 'JPY': 'JPY',
384
+ 'GBP': 'GBP',
385
+ 'CNH': 'CNH',
386
+ },
387
+ 'accountsByType': {
388
+ 'spot': 'exchange',
389
+ 'margin': 'trading',
390
+ 'funding': 'deposit',
391
+ 'swap': 'trading',
392
+ },
393
+ },
394
+ });
395
+ }
396
+ async fetchTransactionFees(codes = undefined, params = {}) {
397
+ /**
398
+ * @method
399
+ * @name bitfinex#fetchTransactionFees
400
+ * @deprecated
401
+ * @description please use fetchDepositWithdrawFees instead
402
+ * @see https://docs.bitfinex.com/v1/reference/rest-auth-fees
403
+ * @param {string[]|undefined} codes list of unified currency codes
404
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
405
+ * @returns {object[]} a list of [fees structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
406
+ */
407
+ await this.loadMarkets();
408
+ const result = {};
409
+ const response = await this.privatePostAccountFees(params);
410
+ //
411
+ // {
412
+ // "withdraw": {
413
+ // "BTC": "0.0004",
414
+ // }
415
+ // }
416
+ //
417
+ const fees = this.safeValue(response, 'withdraw');
418
+ const ids = Object.keys(fees);
419
+ for (let i = 0; i < ids.length; i++) {
420
+ const id = ids[i];
421
+ const code = this.safeCurrencyCode(id);
422
+ if ((codes !== undefined) && !this.inArray(code, codes)) {
423
+ continue;
424
+ }
425
+ result[code] = {
426
+ 'withdraw': this.safeNumber(fees, id),
427
+ 'deposit': {},
428
+ 'info': this.safeNumber(fees, id),
429
+ };
430
+ }
431
+ return result;
432
+ }
433
+ async fetchDepositWithdrawFees(codes = undefined, params = {}) {
434
+ /**
435
+ * @method
436
+ * @name bitfinex#fetchDepositWithdrawFees
437
+ * @description fetch deposit and withdraw fees
438
+ * @see https://docs.bitfinex.com/v1/reference/rest-auth-fees
439
+ * @param {string[]|undefined} codes list of unified currency codes
440
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
441
+ * @returns {object[]} a list of [fees structures]{@link https://docs.ccxt.com/#/?id=fee-structure}
442
+ */
443
+ await this.loadMarkets();
444
+ const response = await this.privatePostAccountFees(params);
445
+ //
446
+ // {
447
+ // "withdraw": {
448
+ // "BTC": "0.0004",
449
+ // ...
450
+ // }
451
+ // }
452
+ //
453
+ const withdraw = this.safeValue(response, 'withdraw');
454
+ return this.parseDepositWithdrawFees(withdraw, codes);
455
+ }
456
+ parseDepositWithdrawFee(fee, currency = undefined) {
457
+ //
458
+ // '0.0004'
459
+ //
460
+ return {
461
+ 'withdraw': {
462
+ 'fee': this.parseNumber(fee),
463
+ 'percentage': undefined,
464
+ },
465
+ 'deposit': {
466
+ 'fee': undefined,
467
+ 'percentage': undefined,
468
+ },
469
+ 'networks': {},
470
+ 'info': fee,
471
+ };
472
+ }
473
+ async fetchTradingFees(params = {}) {
474
+ /**
475
+ * @method
476
+ * @name bitfinex#fetchTradingFees
477
+ * @description fetch the trading fees for multiple markets
478
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
479
+ * @returns {object} a dictionary of [fee structures]{@link https://docs.ccxt.com/#/?id=fee-structure} indexed by market symbols
480
+ */
481
+ await this.loadMarkets();
482
+ const response = await this.privatePostSummary(params);
483
+ //
484
+ // {
485
+ // "time": "2022-02-23T16:05:47.659000Z",
486
+ // "status": { resid_hint: null, login_last: "2022-02-23T16:05:48Z" },
487
+ // "is_locked": false,
488
+ // "leo_lev": "0",
489
+ // "leo_amount_avg": "0.0",
490
+ // "trade_vol_30d": [
491
+ // {
492
+ // "curr": "Total (USD)",
493
+ // "vol": "0.0",
494
+ // "vol_safe": "0.0",
495
+ // "vol_maker": "0.0",
496
+ // "vol_BFX": "0.0",
497
+ // "vol_BFX_safe": "0.0",
498
+ // "vol_BFX_maker": "0.0"
499
+ // }
500
+ // ],
501
+ // "fees_funding_30d": {},
502
+ // "fees_funding_total_30d": "0",
503
+ // "fees_trading_30d": {},
504
+ // "fees_trading_total_30d": "0",
505
+ // "rebates_trading_30d": {},
506
+ // "rebates_trading_total_30d": "0",
507
+ // "maker_fee": "0.001",
508
+ // "taker_fee": "0.002",
509
+ // "maker_fee_2crypto": "0.001",
510
+ // "maker_fee_2stablecoin": "0.001",
511
+ // "maker_fee_2fiat": "0.001",
512
+ // "maker_fee_2deriv": "0.0002",
513
+ // "taker_fee_2crypto": "0.002",
514
+ // "taker_fee_2stablecoin": "0.002",
515
+ // "taker_fee_2fiat": "0.002",
516
+ // "taker_fee_2deriv": "0.00065",
517
+ // "deriv_maker_rebate": "0.0002",
518
+ // "deriv_taker_fee": "0.00065",
519
+ // "trade_last": null
520
+ // }
521
+ //
522
+ const result = {};
523
+ const fiat = this.safeValue(this.options, 'fiat', {});
524
+ const makerFee = this.safeNumber(response, 'maker_fee');
525
+ const takerFee = this.safeNumber(response, 'taker_fee');
526
+ const makerFee2Fiat = this.safeNumber(response, 'maker_fee_2fiat');
527
+ const takerFee2Fiat = this.safeNumber(response, 'taker_fee_2fiat');
528
+ const makerFee2Deriv = this.safeNumber(response, 'maker_fee_2deriv');
529
+ const takerFee2Deriv = this.safeNumber(response, 'taker_fee_2deriv');
530
+ for (let i = 0; i < this.symbols.length; i++) {
531
+ const symbol = this.symbols[i];
532
+ const market = this.market(symbol);
533
+ const fee = {
534
+ 'info': response,
535
+ 'symbol': symbol,
536
+ 'percentage': true,
537
+ 'tierBased': true,
538
+ };
539
+ if (market['quote'] in fiat) {
540
+ fee['maker'] = makerFee2Fiat;
541
+ fee['taker'] = takerFee2Fiat;
542
+ }
543
+ else if (market['contract']) {
544
+ fee['maker'] = makerFee2Deriv;
545
+ fee['taker'] = takerFee2Deriv;
546
+ }
547
+ else {
548
+ fee['maker'] = makerFee;
549
+ fee['taker'] = takerFee;
550
+ }
551
+ result[symbol] = fee;
552
+ }
553
+ return result;
554
+ }
555
+ async fetchMarkets(params = {}) {
556
+ /**
557
+ * @method
558
+ * @name bitfinex#fetchMarkets
559
+ * @description retrieves data on all markets for bitfinex
560
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
561
+ * @returns {object[]} an array of objects representing market data
562
+ */
563
+ const ids = await this.publicGetSymbols();
564
+ //
565
+ // [ "btcusd", "ltcusd", "ltcbtc" ]
566
+ //
567
+ const details = await this.publicGetSymbolsDetails();
568
+ //
569
+ // [
570
+ // {
571
+ // "pair":"btcusd",
572
+ // "price_precision":5,
573
+ // "initial_margin":"10.0",
574
+ // "minimum_margin":"5.0",
575
+ // "maximum_order_size":"2000.0",
576
+ // "minimum_order_size":"0.0002",
577
+ // "expiration":"NA",
578
+ // "margin":true
579
+ // },
580
+ // ]
581
+ //
582
+ const result = [];
583
+ for (let i = 0; i < details.length; i++) {
584
+ const market = details[i];
585
+ let id = this.safeString(market, 'pair');
586
+ if (!this.inArray(id, ids)) {
587
+ continue;
588
+ }
589
+ id = id.toUpperCase();
590
+ let baseId = undefined;
591
+ let quoteId = undefined;
592
+ if (id.indexOf(':') >= 0) {
593
+ const parts = id.split(':');
594
+ baseId = parts[0];
595
+ quoteId = parts[1];
596
+ }
597
+ else {
598
+ baseId = id.slice(0, 3);
599
+ quoteId = id.slice(3, 6);
600
+ }
601
+ const base = this.safeCurrencyCode(baseId);
602
+ const quote = this.safeCurrencyCode(quoteId);
603
+ const symbol = base + '/' + quote;
604
+ let type = 'spot';
605
+ if (id.indexOf('F0') > -1) {
606
+ type = 'swap';
607
+ }
608
+ result.push({
609
+ 'id': id,
610
+ 'symbol': symbol,
611
+ 'base': base,
612
+ 'quote': quote,
613
+ 'settle': undefined,
614
+ 'baseId': baseId,
615
+ 'quoteId': quoteId,
616
+ 'settleId': undefined,
617
+ 'type': type,
618
+ 'spot': (type === 'spot'),
619
+ 'margin': this.safeValue(market, 'margin'),
620
+ 'swap': (type === 'swap'),
621
+ 'future': false,
622
+ 'option': false,
623
+ 'active': true,
624
+ 'contract': (type === 'swap'),
625
+ 'linear': undefined,
626
+ 'inverse': undefined,
627
+ 'contractSize': undefined,
628
+ 'expiry': undefined,
629
+ 'expiryDatetime': undefined,
630
+ 'strike': undefined,
631
+ 'optionType': undefined,
632
+ 'precision': {
633
+ // https://docs.bitfinex.com/docs/introduction#amount-precision
634
+ // The amount field allows up to 8 decimals.
635
+ // Anything exceeding this will be rounded to the 8th decimal.
636
+ 'amount': parseInt('8'),
637
+ 'price': this.safeInteger(market, 'price_precision'),
638
+ },
639
+ 'limits': {
640
+ 'leverage': {
641
+ 'min': undefined,
642
+ 'max': undefined,
643
+ },
644
+ 'amount': {
645
+ 'min': this.safeNumber(market, 'minimum_order_size'),
646
+ 'max': this.safeNumber(market, 'maximum_order_size'),
647
+ },
648
+ 'price': {
649
+ 'min': this.parseNumber('1e-8'),
650
+ 'max': undefined,
651
+ },
652
+ 'cost': {
653
+ 'min': undefined,
654
+ 'max': undefined,
655
+ },
656
+ },
657
+ 'created': undefined,
658
+ 'info': market,
659
+ });
660
+ }
661
+ return result;
662
+ }
663
+ amountToPrecision(symbol, amount) {
664
+ // https://docs.bitfinex.com/docs/introduction#amount-precision
665
+ // The amount field allows up to 8 decimals.
666
+ // Anything exceeding this will be rounded to the 8th decimal.
667
+ symbol = this.safeSymbol(symbol);
668
+ return this.decimalToPrecision(amount, number.TRUNCATE, this.markets[symbol]['precision']['amount'], number.DECIMAL_PLACES);
669
+ }
670
+ priceToPrecision(symbol, price) {
671
+ symbol = this.safeSymbol(symbol);
672
+ price = this.decimalToPrecision(price, number.ROUND, this.markets[symbol]['precision']['price'], this.precisionMode);
673
+ // https://docs.bitfinex.com/docs/introduction#price-precision
674
+ // The precision level of all trading prices is based on significant figures.
675
+ // All pairs on Bitfinex use up to 5 significant digits and up to 8 decimals (e.g. 1.2345, 123.45, 1234.5, 0.00012345).
676
+ // Prices submit with a precision larger than 5 will be cut by the API.
677
+ return this.decimalToPrecision(price, number.TRUNCATE, 8, number.DECIMAL_PLACES);
678
+ }
679
+ async fetchBalance(params = {}) {
680
+ /**
681
+ * @method
682
+ * @name bitfinex#fetchBalance
683
+ * @description query for balance and get the amount of funds available for trading or funds locked in orders
684
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
685
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
686
+ */
687
+ await this.loadMarkets();
688
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
689
+ const requestedType = this.safeString(params, 'type', 'exchange');
690
+ const accountType = this.safeString(accountsByType, requestedType, requestedType);
691
+ if (accountType === undefined) {
692
+ const keys = Object.keys(accountsByType);
693
+ throw new errors.ExchangeError(this.id + ' fetchBalance() type parameter must be one of ' + keys.join(', '));
694
+ }
695
+ const query = this.omit(params, 'type');
696
+ const response = await this.privatePostBalances(query);
697
+ // [ { type: "deposit",
698
+ // "currency": "btc",
699
+ // "amount": "0.00116721",
700
+ // "available": "0.00116721" },
701
+ // { type: "exchange",
702
+ // "currency": "ust",
703
+ // "amount": "0.0000002",
704
+ // "available": "0.0000002" },
705
+ // { type: "trading",
706
+ // "currency": "btc",
707
+ // "amount": "0.0005",
708
+ // "available": "0.0005" } ],
709
+ const result = { 'info': response };
710
+ const isDerivative = requestedType === 'derivatives';
711
+ for (let i = 0; i < response.length; i++) {
712
+ const balance = response[i];
713
+ const type = this.safeString(balance, 'type');
714
+ const currencyId = this.safeStringLower(balance, 'currency', '');
715
+ const start = currencyId.length - 2;
716
+ const isDerivativeCode = currencyId.slice(start) === 'f0';
717
+ // this will only filter the derivative codes if the requestedType is 'derivatives'
718
+ const derivativeCondition = (!isDerivative || isDerivativeCode);
719
+ if ((accountType === type) && derivativeCondition) {
720
+ const code = this.safeCurrencyCode(currencyId);
721
+ // bitfinex had BCH previously, now it's BAB, but the old
722
+ // BCH symbol is kept for backward-compatibility
723
+ // we need a workaround here so that the old BCH balance
724
+ // would not override the new BAB balance (BAB is unified to BCH)
725
+ // https://github.com/ccxt/ccxt/issues/4989
726
+ if (!(code in result)) {
727
+ const account = this.account();
728
+ account['free'] = this.safeString(balance, 'available');
729
+ account['total'] = this.safeString(balance, 'amount');
730
+ result[code] = account;
731
+ }
732
+ }
733
+ }
734
+ return this.safeBalance(result);
735
+ }
736
+ async transfer(code, amount, fromAccount, toAccount, params = {}) {
737
+ /**
738
+ * @method
739
+ * @name bitfinex#transfer
740
+ * @description transfer currency internally between wallets on the same account
741
+ * @param {string} code unified currency code
742
+ * @param {float} amount amount to transfer
743
+ * @param {string} fromAccount account to transfer from
744
+ * @param {string} toAccount account to transfer to
745
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
746
+ * @returns {object} a [transfer structure]{@link https://docs.ccxt.com/#/?id=transfer-structure}
747
+ */
748
+ // transferring between derivatives wallet and regular wallet is not documented in their API
749
+ // however we support it in CCXT (from just looking at web inspector)
750
+ await this.loadMarkets();
751
+ const accountsByType = this.safeValue(this.options, 'accountsByType', {});
752
+ const fromId = this.safeString(accountsByType, fromAccount, fromAccount);
753
+ const toId = this.safeString(accountsByType, toAccount, toAccount);
754
+ const currency = this.currency(code);
755
+ const fromCurrencyId = this.convertDerivativesId(currency['id'], fromAccount);
756
+ const toCurrencyId = this.convertDerivativesId(currency['id'], toAccount);
757
+ const requestedAmount = this.currencyToPrecision(code, amount);
758
+ const request = {
759
+ 'amount': requestedAmount,
760
+ 'currency': fromCurrencyId,
761
+ 'currency_to': toCurrencyId,
762
+ 'walletfrom': fromId,
763
+ 'walletto': toId,
764
+ };
765
+ const response = await this.privatePostTransfer(this.extend(request, params));
766
+ //
767
+ // [
768
+ // {
769
+ // "status": "success",
770
+ // "message": "0.0001 Bitcoin transfered from Margin to Exchange"
771
+ // }
772
+ // ]
773
+ //
774
+ const result = this.safeValue(response, 0);
775
+ const message = this.safeString(result, 'message');
776
+ if (message === undefined) {
777
+ throw new errors.ExchangeError(this.id + ' transfer failed');
778
+ }
779
+ return this.extend(this.parseTransfer(result, currency), {
780
+ 'fromAccount': fromAccount,
781
+ 'toAccount': toAccount,
782
+ 'amount': this.parseNumber(requestedAmount),
783
+ });
784
+ }
785
+ parseTransfer(transfer, currency = undefined) {
786
+ //
787
+ // {
788
+ // "status": "success",
789
+ // "message": "0.0001 Bitcoin transfered from Margin to Exchange"
790
+ // }
791
+ //
792
+ return {
793
+ 'info': transfer,
794
+ 'id': undefined,
795
+ 'timestamp': undefined,
796
+ 'datetime': undefined,
797
+ 'currency': this.safeCurrencyCode(undefined, currency),
798
+ 'amount': undefined,
799
+ 'fromAccount': undefined,
800
+ 'toAccount': undefined,
801
+ 'status': this.parseTransferStatus(this.safeString(transfer, 'status')),
802
+ };
803
+ }
804
+ parseTransferStatus(status) {
805
+ const statuses = {
806
+ 'SUCCESS': 'ok',
807
+ };
808
+ return this.safeString(statuses, status, status);
809
+ }
810
+ convertDerivativesId(currencyId, type) {
811
+ const start = currencyId.length - 2;
812
+ const isDerivativeCode = currencyId.slice(start) === 'F0';
813
+ if ((type !== 'derivatives' && type !== 'trading' && type !== 'margin') && isDerivativeCode) {
814
+ currencyId = currencyId.slice(0, start);
815
+ }
816
+ else if (type === 'derivatives' && !isDerivativeCode) {
817
+ currencyId = currencyId + 'F0';
818
+ }
819
+ return currencyId;
820
+ }
821
+ async fetchOrderBook(symbol, limit = undefined, params = {}) {
822
+ /**
823
+ * @method
824
+ * @name bitfinex#fetchOrderBook
825
+ * @description fetches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
826
+ * @param {string} symbol unified symbol of the market to fetch the order book for
827
+ * @param {int} [limit] the maximum amount of order book entries to return
828
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
829
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
830
+ */
831
+ await this.loadMarkets();
832
+ const market = this.market(symbol);
833
+ const request = {
834
+ 'symbol': market['id'],
835
+ };
836
+ if (limit !== undefined) {
837
+ request['limit_bids'] = limit;
838
+ request['limit_asks'] = limit;
839
+ }
840
+ const response = await this.publicGetBookSymbol(this.extend(request, params));
841
+ return this.parseOrderBook(response, market['symbol'], undefined, 'bids', 'asks', 'price', 'amount');
842
+ }
843
+ async fetchTickers(symbols = undefined, params = {}) {
844
+ /**
845
+ * @method
846
+ * @name bitfinex#fetchTickers
847
+ * @description fetches price tickers for multiple markets, statistical information calculated over the past 24 hours for each market
848
+ * @param {string[]|undefined} symbols unified symbols of the markets to fetch the ticker for, all market tickers are returned if not assigned
849
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
850
+ * @returns {object} a dictionary of [ticker structures]{@link https://docs.ccxt.com/#/?id=ticker-structure}
851
+ */
852
+ await this.loadMarkets();
853
+ symbols = this.marketSymbols(symbols);
854
+ const response = await this.publicGetTickers(params);
855
+ const result = {};
856
+ for (let i = 0; i < response.length; i++) {
857
+ const ticker = this.parseTicker(response[i]);
858
+ const symbol = ticker['symbol'];
859
+ result[symbol] = ticker;
860
+ }
861
+ return this.filterByArrayTickers(result, 'symbol', symbols);
862
+ }
863
+ async fetchTicker(symbol, params = {}) {
864
+ /**
865
+ * @method
866
+ * @name bitfinex#fetchTicker
867
+ * @description fetches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
868
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
869
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
870
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
871
+ */
872
+ await this.loadMarkets();
873
+ const market = this.market(symbol);
874
+ const request = {
875
+ 'symbol': market['id'],
876
+ };
877
+ const ticker = await this.publicGetPubtickerSymbol(this.extend(request, params));
878
+ return this.parseTicker(ticker, market);
879
+ }
880
+ parseTicker(ticker, market = undefined) {
881
+ const timestamp = this.safeTimestamp(ticker, 'timestamp');
882
+ const marketId = this.safeString(ticker, 'pair');
883
+ market = this.safeMarket(marketId, market);
884
+ const symbol = market['symbol'];
885
+ const last = this.safeString(ticker, 'last_price');
886
+ return this.safeTicker({
887
+ 'symbol': symbol,
888
+ 'timestamp': timestamp,
889
+ 'datetime': this.iso8601(timestamp),
890
+ 'high': this.safeString(ticker, 'high'),
891
+ 'low': this.safeString(ticker, 'low'),
892
+ 'bid': this.safeString(ticker, 'bid'),
893
+ 'bidVolume': undefined,
894
+ 'ask': this.safeString(ticker, 'ask'),
895
+ 'askVolume': undefined,
896
+ 'vwap': undefined,
897
+ 'open': undefined,
898
+ 'close': last,
899
+ 'last': last,
900
+ 'previousClose': undefined,
901
+ 'change': undefined,
902
+ 'percentage': undefined,
903
+ 'average': this.safeString(ticker, 'mid'),
904
+ 'baseVolume': this.safeString(ticker, 'volume'),
905
+ 'quoteVolume': undefined,
906
+ 'info': ticker,
907
+ }, market);
908
+ }
909
+ parseTrade(trade, market = undefined) {
910
+ //
911
+ // fetchTrades (public) v1
912
+ //
913
+ // {
914
+ // "timestamp":1637258380,
915
+ // "tid":894452833,
916
+ // "price":"0.99941",
917
+ // "amount":"261.38",
918
+ // "exchange":"bitfinex",
919
+ // "type":"sell"
920
+ // }
921
+ //
922
+ // fetchMyTrades (private) v1
923
+ //
924
+ // {
925
+ // "price":"0.99941",
926
+ // "amount":"261.38",
927
+ // "timestamp":"1637258380.0",
928
+ // "type":"Sell",
929
+ // "fee_currency":"UST",
930
+ // "fee_amount":"-0.52245157",
931
+ // "tid":894452833,
932
+ // "order_id":78819731373
933
+ // }
934
+ //
935
+ // {
936
+ // "price":"0.99958",
937
+ // "amount":"261.90514",
938
+ // "timestamp":"1637258238.0",
939
+ // "type":"Buy",
940
+ // "fee_currency":"UDC",
941
+ // "fee_amount":"-0.52381028",
942
+ // "tid":894452800,
943
+ // "order_id":78819504838
944
+ // }
945
+ //
946
+ const id = this.safeString(trade, 'tid');
947
+ const timestamp = this.safeTimestamp(trade, 'timestamp');
948
+ const type = undefined;
949
+ const side = this.safeStringLower(trade, 'type');
950
+ const orderId = this.safeString(trade, 'order_id');
951
+ const priceString = this.safeString(trade, 'price');
952
+ const amountString = this.safeString(trade, 'amount');
953
+ let fee = undefined;
954
+ if ('fee_amount' in trade) {
955
+ const feeCostString = Precise["default"].stringNeg(this.safeString(trade, 'fee_amount'));
956
+ const feeCurrencyId = this.safeString(trade, 'fee_currency');
957
+ const feeCurrencyCode = this.safeCurrencyCode(feeCurrencyId);
958
+ fee = {
959
+ 'cost': feeCostString,
960
+ 'currency': feeCurrencyCode,
961
+ };
962
+ }
963
+ return this.safeTrade({
964
+ 'id': id,
965
+ 'info': trade,
966
+ 'timestamp': timestamp,
967
+ 'datetime': this.iso8601(timestamp),
968
+ 'symbol': market['symbol'],
969
+ 'type': type,
970
+ 'order': orderId,
971
+ 'side': side,
972
+ 'takerOrMaker': undefined,
973
+ 'price': priceString,
974
+ 'amount': amountString,
975
+ 'cost': undefined,
976
+ 'fee': fee,
977
+ }, market);
978
+ }
979
+ async fetchTrades(symbol, since = undefined, limit = 50, params = {}) {
980
+ /**
981
+ * @method
982
+ * @name bitfinex#fetchTrades
983
+ * @description get the list of most recent trades for a particular symbol
984
+ * @param {string} symbol unified symbol of the market to fetch trades for
985
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
986
+ * @param {int} [limit] the maximum amount of trades to fetch
987
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
988
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
989
+ */
990
+ await this.loadMarkets();
991
+ const market = this.market(symbol);
992
+ const request = {
993
+ 'symbol': market['id'],
994
+ 'limit_trades': limit,
995
+ };
996
+ if (since !== undefined) {
997
+ request['timestamp'] = this.parseToInt(since / 1000);
998
+ }
999
+ const response = await this.publicGetTradesSymbol(this.extend(request, params));
1000
+ //
1001
+ // [
1002
+ // {
1003
+ // "timestamp": "1694284565",
1004
+ // "tid": "1415415034",
1005
+ // "price": "25862.0",
1006
+ // "amount": "0.00020685",
1007
+ // "exchange": "bitfinex",
1008
+ // "type": "buy"
1009
+ // },
1010
+ // ]
1011
+ //
1012
+ return this.parseTrades(response, market, since, limit);
1013
+ }
1014
+ async fetchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1015
+ /**
1016
+ * @method
1017
+ * @name bitfinex#fetchMyTrades
1018
+ * @description fetch all trades made by the user
1019
+ * @param {string} symbol unified market symbol
1020
+ * @param {int} [since] the earliest time in ms to fetch trades for
1021
+ * @param {int} [limit] the maximum number of trades structures to retrieve
1022
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1023
+ * @returns {Trade[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1024
+ */
1025
+ if (symbol === undefined) {
1026
+ throw new errors.ArgumentsRequired(this.id + ' fetchMyTrades() requires a symbol argument');
1027
+ }
1028
+ await this.loadMarkets();
1029
+ const market = this.market(symbol);
1030
+ const request = {
1031
+ 'symbol': market['id'],
1032
+ };
1033
+ if (limit !== undefined) {
1034
+ request['limit_trades'] = limit;
1035
+ }
1036
+ if (since !== undefined) {
1037
+ request['timestamp'] = this.parseToInt(since / 1000);
1038
+ }
1039
+ const response = await this.privatePostMytrades(this.extend(request, params));
1040
+ return this.parseTrades(response, market, since, limit);
1041
+ }
1042
+ async createOrder(symbol, type, side, amount, price = undefined, params = {}) {
1043
+ /**
1044
+ * @method
1045
+ * @name bitfinex#createOrder
1046
+ * @description create a trade order
1047
+ * @param {string} symbol unified symbol of the market to create an order in
1048
+ * @param {string} type 'market' or 'limit'
1049
+ * @param {string} side 'buy' or 'sell'
1050
+ * @param {float} amount how much of currency you want to trade in units of base currency
1051
+ * @param {float} [price] the price at which the order is to be fullfilled, in units of the quote currency, ignored in market orders
1052
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1053
+ * @returns {object} an [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1054
+ */
1055
+ await this.loadMarkets();
1056
+ const market = this.market(symbol);
1057
+ const postOnly = this.safeValue(params, 'postOnly', false);
1058
+ type = type.toLowerCase();
1059
+ params = this.omit(params, ['postOnly']);
1060
+ if (market['spot']) {
1061
+ // although they claim that type needs to be 'exchange limit' or 'exchange market'
1062
+ // in fact that's not the case for swap markets
1063
+ type = this.safeStringLower(this.options['orderTypes'], type, type);
1064
+ }
1065
+ const request = {
1066
+ 'symbol': market['id'],
1067
+ 'side': side,
1068
+ 'amount': this.amountToPrecision(symbol, amount),
1069
+ 'type': type,
1070
+ 'ocoorder': false,
1071
+ 'buy_price_oco': 0,
1072
+ 'sell_price_oco': 0,
1073
+ };
1074
+ if (type.indexOf('market') > -1) {
1075
+ request['price'] = this.nonce().toString();
1076
+ }
1077
+ else {
1078
+ request['price'] = this.priceToPrecision(symbol, price);
1079
+ }
1080
+ if (postOnly) {
1081
+ request['is_postonly'] = true;
1082
+ }
1083
+ const response = await this.privatePostOrderNew(this.extend(request, params));
1084
+ return this.parseOrder(response, market);
1085
+ }
1086
+ async editOrder(id, symbol, type, side, amount = undefined, price = undefined, params = {}) {
1087
+ await this.loadMarkets();
1088
+ const order = {
1089
+ 'order_id': parseInt(id),
1090
+ };
1091
+ if (price !== undefined) {
1092
+ order['price'] = this.priceToPrecision(symbol, price);
1093
+ }
1094
+ if (amount !== undefined) {
1095
+ order['amount'] = this.numberToString(amount);
1096
+ }
1097
+ if (symbol !== undefined) {
1098
+ order['symbol'] = this.marketId(symbol);
1099
+ }
1100
+ if (side !== undefined) {
1101
+ order['side'] = side;
1102
+ }
1103
+ if (type !== undefined) {
1104
+ order['type'] = this.safeString(this.options['orderTypes'], type, type);
1105
+ }
1106
+ const response = await this.privatePostOrderCancelReplace(this.extend(order, params));
1107
+ return this.parseOrder(response);
1108
+ }
1109
+ async cancelOrder(id, symbol = undefined, params = {}) {
1110
+ /**
1111
+ * @method
1112
+ * @name bitfinex#cancelOrder
1113
+ * @description cancels an open order
1114
+ * @param {string} id order id
1115
+ * @param {string} symbol not used by bitfinex cancelOrder ()
1116
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1117
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1118
+ */
1119
+ await this.loadMarkets();
1120
+ const request = {
1121
+ 'order_id': parseInt(id),
1122
+ };
1123
+ return await this.privatePostOrderCancel(this.extend(request, params));
1124
+ }
1125
+ async cancelAllOrders(symbol = undefined, params = {}) {
1126
+ /**
1127
+ * @method
1128
+ * @name bitfinex#cancelAllOrders
1129
+ * @description cancel all open orders
1130
+ * @param {string} symbol unified market symbol, only orders in the market of this symbol are cancelled when symbol is not undefined
1131
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1132
+ * @returns {object} response from exchange
1133
+ */
1134
+ return await this.privatePostOrderCancelAll(params);
1135
+ }
1136
+ parseOrder(order, market = undefined) {
1137
+ //
1138
+ // {
1139
+ // "id": 57334010955,
1140
+ // "cid": 1611584840966,
1141
+ // "cid_date": null,
1142
+ // "gid": null,
1143
+ // "symbol": "ltcbtc",
1144
+ // "exchange": null,
1145
+ // "price": "0.0042125",
1146
+ // "avg_execution_price": "0.0042097",
1147
+ // "side": "sell",
1148
+ // "type": "exchange market",
1149
+ // "timestamp": "1611584841.0",
1150
+ // "is_live": false,
1151
+ // "is_cancelled": false,
1152
+ // "is_hidden": 0,
1153
+ // "oco_order": 0,
1154
+ // "was_forced": false,
1155
+ // "original_amount": "0.205176",
1156
+ // "remaining_amount": "0.0",
1157
+ // "executed_amount": "0.205176",
1158
+ // "src": "web"
1159
+ // }
1160
+ //
1161
+ const side = this.safeString(order, 'side');
1162
+ const open = this.safeValue(order, 'is_live');
1163
+ const canceled = this.safeValue(order, 'is_cancelled');
1164
+ let status = undefined;
1165
+ if (open) {
1166
+ status = 'open';
1167
+ }
1168
+ else if (canceled) {
1169
+ status = 'canceled';
1170
+ }
1171
+ else {
1172
+ status = 'closed';
1173
+ }
1174
+ const marketId = this.safeStringUpper(order, 'symbol');
1175
+ const symbol = this.safeSymbol(marketId, market);
1176
+ let orderType = this.safeString(order, 'type', '');
1177
+ const exchange = orderType.indexOf('exchange ') >= 0;
1178
+ if (exchange) {
1179
+ const parts = order['type'].split(' ');
1180
+ orderType = parts[1];
1181
+ }
1182
+ const timestamp = this.safeTimestamp(order, 'timestamp');
1183
+ const id = this.safeString(order, 'id');
1184
+ return this.safeOrder({
1185
+ 'info': order,
1186
+ 'id': id,
1187
+ 'clientOrderId': undefined,
1188
+ 'timestamp': timestamp,
1189
+ 'datetime': this.iso8601(timestamp),
1190
+ 'lastTradeTimestamp': undefined,
1191
+ 'symbol': symbol,
1192
+ 'type': orderType,
1193
+ 'timeInForce': undefined,
1194
+ 'postOnly': undefined,
1195
+ 'side': side,
1196
+ 'price': this.safeString(order, 'price'),
1197
+ 'stopPrice': undefined,
1198
+ 'triggerPrice': undefined,
1199
+ 'average': this.safeString(order, 'avg_execution_price'),
1200
+ 'amount': this.safeString(order, 'original_amount'),
1201
+ 'remaining': this.safeString(order, 'remaining_amount'),
1202
+ 'filled': this.safeString(order, 'executed_amount'),
1203
+ 'status': status,
1204
+ 'fee': undefined,
1205
+ 'cost': undefined,
1206
+ 'trades': undefined,
1207
+ }, market);
1208
+ }
1209
+ async fetchOpenOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1210
+ /**
1211
+ * @method
1212
+ * @name bitfinex#fetchOpenOrders
1213
+ * @description fetch all unfilled currently open orders
1214
+ * @param {string} symbol unified market symbol
1215
+ * @param {int} [since] the earliest time in ms to fetch open orders for
1216
+ * @param {int} [limit] the maximum number of open orders structures to retrieve
1217
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1218
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1219
+ */
1220
+ await this.loadMarkets();
1221
+ if (symbol !== undefined) {
1222
+ if (!(symbol in this.markets)) {
1223
+ throw new errors.ExchangeError(this.id + ' has no symbol ' + symbol);
1224
+ }
1225
+ }
1226
+ const response = await this.privatePostOrders(params);
1227
+ let orders = this.parseOrders(response, undefined, since, limit);
1228
+ if (symbol !== undefined) {
1229
+ orders = this.filterBy(orders, 'symbol', symbol);
1230
+ }
1231
+ return orders;
1232
+ }
1233
+ async fetchClosedOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1234
+ /**
1235
+ * @method
1236
+ * @name bitfinex#fetchClosedOrders
1237
+ * @description fetches information on multiple closed orders made by the user
1238
+ * @param {string} symbol unified market symbol of the market orders were made in
1239
+ * @param {int} [since] the earliest time in ms to fetch orders for
1240
+ * @param {int} [limit] the maximum number of order structures to retrieve
1241
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1242
+ * @returns {Order[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure}
1243
+ */
1244
+ await this.loadMarkets();
1245
+ symbol = this.symbol(symbol);
1246
+ const request = {};
1247
+ if (limit !== undefined) {
1248
+ request['limit'] = limit;
1249
+ }
1250
+ const response = await this.privatePostOrdersHist(this.extend(request, params));
1251
+ let orders = this.parseOrders(response, undefined, since, limit);
1252
+ if (symbol !== undefined) {
1253
+ orders = this.filterBy(orders, 'symbol', symbol);
1254
+ }
1255
+ orders = this.filterByArray(orders, 'status', ['closed', 'canceled'], false);
1256
+ return orders;
1257
+ }
1258
+ async fetchOrder(id, symbol = undefined, params = {}) {
1259
+ /**
1260
+ * @method
1261
+ * @name bitfinex#fetchOrder
1262
+ * @description fetches information on an order made by the user
1263
+ * @param {string} symbol not used by bitfinex fetchOrder
1264
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1265
+ * @returns {object} An [order structure]{@link https://docs.ccxt.com/#/?id=order-structure}
1266
+ */
1267
+ await this.loadMarkets();
1268
+ const request = {
1269
+ 'order_id': parseInt(id),
1270
+ };
1271
+ const response = await this.privatePostOrderStatus(this.extend(request, params));
1272
+ return this.parseOrder(response);
1273
+ }
1274
+ parseOHLCV(ohlcv, market = undefined) {
1275
+ //
1276
+ // [
1277
+ // 1457539800000,
1278
+ // 0.02594,
1279
+ // 0.02594,
1280
+ // 0.02594,
1281
+ // 0.02594,
1282
+ // 0.1
1283
+ // ]
1284
+ //
1285
+ return [
1286
+ this.safeInteger(ohlcv, 0),
1287
+ this.safeNumber(ohlcv, 1),
1288
+ this.safeNumber(ohlcv, 3),
1289
+ this.safeNumber(ohlcv, 4),
1290
+ this.safeNumber(ohlcv, 2),
1291
+ this.safeNumber(ohlcv, 5),
1292
+ ];
1293
+ }
1294
+ async fetchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
1295
+ /**
1296
+ * @method
1297
+ * @name bitfinex#fetchOHLCV
1298
+ * @description fetches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1299
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1300
+ * @param {string} timeframe the length of time each candle represents
1301
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
1302
+ * @param {int} [limit] the maximum amount of candles to fetch
1303
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1304
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1305
+ */
1306
+ await this.loadMarkets();
1307
+ if (limit === undefined) {
1308
+ limit = 100;
1309
+ }
1310
+ const market = this.market(symbol);
1311
+ const v2id = 't' + market['id'];
1312
+ const request = {
1313
+ 'symbol': v2id,
1314
+ 'timeframe': this.safeString(this.timeframes, timeframe, timeframe),
1315
+ 'sort': 1,
1316
+ 'limit': limit,
1317
+ };
1318
+ if (since !== undefined) {
1319
+ request['start'] = since;
1320
+ }
1321
+ const response = await this.v2GetCandlesTradeTimeframeSymbolHist(this.extend(request, params));
1322
+ //
1323
+ // [
1324
+ // [1457539800000,0.02594,0.02594,0.02594,0.02594,0.1],
1325
+ // [1457547300000,0.02577,0.02577,0.02577,0.02577,0.01],
1326
+ // [1457550240000,0.0255,0.0253,0.0255,0.0252,3.2640000000000002],
1327
+ // ]
1328
+ //
1329
+ return this.parseOHLCVs(response, market, timeframe, since, limit);
1330
+ }
1331
+ getCurrencyName(code) {
1332
+ // todo rewrite for https://api-pub.bitfinex.com//v2/conf/pub:map:tx:method
1333
+ if (code in this.options['currencyNames']) {
1334
+ return this.options['currencyNames'][code];
1335
+ }
1336
+ throw new errors.NotSupported(this.id + ' ' + code + ' not supported for withdrawal');
1337
+ }
1338
+ async createDepositAddress(code, params = {}) {
1339
+ /**
1340
+ * @method
1341
+ * @name bitfinex#createDepositAddress
1342
+ * @description create a currency deposit address
1343
+ * @param {string} code unified currency code of the currency for the deposit address
1344
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1345
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1346
+ */
1347
+ await this.loadMarkets();
1348
+ const request = {
1349
+ 'renew': 1,
1350
+ };
1351
+ return await this.fetchDepositAddress(code, this.extend(request, params));
1352
+ }
1353
+ async fetchDepositAddress(code, params = {}) {
1354
+ /**
1355
+ * @method
1356
+ * @name bitfinex#fetchDepositAddress
1357
+ * @description fetch the deposit address for a currency associated with this account
1358
+ * @param {string} code unified currency code
1359
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1360
+ * @returns {object} an [address structure]{@link https://docs.ccxt.com/#/?id=address-structure}
1361
+ */
1362
+ await this.loadMarkets();
1363
+ // todo rewrite for https://api-pub.bitfinex.com//v2/conf/pub:map:tx:method
1364
+ const name = this.getCurrencyName(code);
1365
+ const request = {
1366
+ 'method': name,
1367
+ 'wallet_name': 'exchange',
1368
+ 'renew': 0, // a value of 1 will generate a new address
1369
+ };
1370
+ const response = await this.privatePostDepositNew(this.extend(request, params));
1371
+ let address = this.safeValue(response, 'address');
1372
+ let tag = undefined;
1373
+ if ('address_pool' in response) {
1374
+ tag = address;
1375
+ address = response['address_pool'];
1376
+ }
1377
+ this.checkAddress(address);
1378
+ return {
1379
+ 'currency': code,
1380
+ 'address': address,
1381
+ 'tag': tag,
1382
+ 'network': undefined,
1383
+ 'info': response,
1384
+ };
1385
+ }
1386
+ async fetchDepositsWithdrawals(code = undefined, since = undefined, limit = undefined, params = {}) {
1387
+ /**
1388
+ * @method
1389
+ * @name bitfinex#fetchDepositsWithdrawals
1390
+ * @description fetch history of deposits and withdrawals
1391
+ * @param {string} code unified currency code for the currency of the deposit/withdrawals
1392
+ * @param {int} [since] timestamp in ms of the earliest deposit/withdrawal, default is undefined
1393
+ * @param {int} [limit] max number of deposit/withdrawals to return, default is undefined
1394
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1395
+ * @returns {object} a list of [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1396
+ */
1397
+ await this.loadMarkets();
1398
+ let currencyId = this.safeString(params, 'currency');
1399
+ const query = this.omit(params, 'currency');
1400
+ let currency = undefined;
1401
+ if (currencyId === undefined) {
1402
+ if (code === undefined) {
1403
+ throw new errors.ArgumentsRequired(this.id + ' fetchDepositsWithdrawals() requires a currency `code` argument or a `currency` parameter');
1404
+ }
1405
+ else {
1406
+ currency = this.currency(code);
1407
+ currencyId = currency['id'];
1408
+ }
1409
+ }
1410
+ query['currency'] = currencyId;
1411
+ if (since !== undefined) {
1412
+ query['since'] = this.parseToInt(since / 1000);
1413
+ }
1414
+ const response = await this.privatePostHistoryMovements(this.extend(query, params));
1415
+ //
1416
+ // [
1417
+ // {
1418
+ // "id": 581183,
1419
+ // "txid": 123456,
1420
+ // "currency": "BTC",
1421
+ // "method": "BITCOIN",
1422
+ // "type": "WITHDRAWAL",
1423
+ // "amount": ".01",
1424
+ // "description": "3QXYWgRGX2BPYBpUDBssGbeWEa5zq6snBZ, offchain transfer ",
1425
+ // "address": "3QXYWgRGX2BPYBpUDBssGbeWEa5zq6snBZ",
1426
+ // "status": "COMPLETED",
1427
+ // "timestamp": "1443833327.0",
1428
+ // "timestamp_created": "1443833327.1",
1429
+ // "fee": 0.1,
1430
+ // }
1431
+ // ]
1432
+ //
1433
+ return this.parseTransactions(response, currency, since, limit);
1434
+ }
1435
+ parseTransaction(transaction, currency = undefined) {
1436
+ //
1437
+ // crypto
1438
+ //
1439
+ // {
1440
+ // "id": 12042490,
1441
+ // "fee": "-0.02",
1442
+ // "txid": "EA5B5A66000B66855865EFF2494D7C8D1921FCBE996482157EBD749F2C85E13D",
1443
+ // "type": "DEPOSIT",
1444
+ // "amount": "2099.849999",
1445
+ // "method": "RIPPLE",
1446
+ // "status": "COMPLETED",
1447
+ // "address": "2505189261",
1448
+ // "currency": "XRP",
1449
+ // "timestamp": "1551730524.0",
1450
+ // "description": "EA5B5A66000B66855865EFF2494D7C8D1921FCBE996482157EBD749F2C85E13D",
1451
+ // "timestamp_created": "1551730523.0"
1452
+ // }
1453
+ //
1454
+ // fiat
1455
+ //
1456
+ // {
1457
+ // "id": 12725095,
1458
+ // "fee": "-60.0",
1459
+ // "txid": null,
1460
+ // "type": "WITHDRAWAL",
1461
+ // "amount": "9943.0",
1462
+ // "method": "WIRE",
1463
+ // "status": "SENDING",
1464
+ // "address": null,
1465
+ // "currency": "EUR",
1466
+ // "timestamp": "1561802484.0",
1467
+ // "description": "Name: bob, AccountAddress: some address, Account: someaccountno, Bank: bank address, SWIFT: foo, Country: UK, Details of Payment: withdrawal name, Intermediary Bank Name: , Intermediary Bank Address: , Intermediary Bank City: , Intermediary Bank Country: , Intermediary Bank Account: , Intermediary Bank SWIFT: , Fee: -60.0",
1468
+ // "timestamp_created": "1561716066.0"
1469
+ // }
1470
+ //
1471
+ // withdraw
1472
+ //
1473
+ // {
1474
+ // "status": "success",
1475
+ // "message": "Your withdrawal request has been successfully submitted.",
1476
+ // "withdrawal_id": 586829
1477
+ // }
1478
+ //
1479
+ const timestamp = this.safeTimestamp(transaction, 'timestamp_created');
1480
+ const currencyId = this.safeString(transaction, 'currency');
1481
+ const code = this.safeCurrencyCode(currencyId, currency);
1482
+ let feeCost = this.safeString(transaction, 'fee');
1483
+ if (feeCost !== undefined) {
1484
+ feeCost = Precise["default"].stringAbs(feeCost);
1485
+ }
1486
+ return {
1487
+ 'info': transaction,
1488
+ 'id': this.safeString2(transaction, 'id', 'withdrawal_id'),
1489
+ 'txid': this.safeString(transaction, 'txid'),
1490
+ 'type': this.safeStringLower(transaction, 'type'),
1491
+ 'currency': code,
1492
+ 'network': undefined,
1493
+ 'amount': this.safeNumber(transaction, 'amount'),
1494
+ 'status': this.parseTransactionStatus(this.safeString(transaction, 'status')),
1495
+ 'timestamp': timestamp,
1496
+ 'datetime': this.iso8601(timestamp),
1497
+ 'address': this.safeString(transaction, 'address'),
1498
+ 'addressFrom': undefined,
1499
+ 'addressTo': undefined,
1500
+ 'tag': this.safeString(transaction, 'description'),
1501
+ 'tagFrom': undefined,
1502
+ 'tagTo': undefined,
1503
+ 'updated': this.safeTimestamp(transaction, 'timestamp'),
1504
+ 'comment': undefined,
1505
+ 'internal': undefined,
1506
+ 'fee': {
1507
+ 'currency': code,
1508
+ 'cost': this.parseNumber(feeCost),
1509
+ 'rate': undefined,
1510
+ },
1511
+ };
1512
+ }
1513
+ parseTransactionStatus(status) {
1514
+ const statuses = {
1515
+ 'SENDING': 'pending',
1516
+ 'CANCELED': 'canceled',
1517
+ 'ZEROCONFIRMED': 'failed',
1518
+ 'COMPLETED': 'ok',
1519
+ };
1520
+ return this.safeString(statuses, status, status);
1521
+ }
1522
+ async withdraw(code, amount, address, tag = undefined, params = {}) {
1523
+ /**
1524
+ * @method
1525
+ * @name bitfinex#withdraw
1526
+ * @description make a withdrawal
1527
+ * @param {string} code unified currency code
1528
+ * @param {float} amount the amount to withdraw
1529
+ * @param {string} address the address to withdraw to
1530
+ * @param {string} tag
1531
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1532
+ * @returns {object} a [transaction structure]{@link https://docs.ccxt.com/#/?id=transaction-structure}
1533
+ */
1534
+ [tag, params] = this.handleWithdrawTagAndParams(tag, params);
1535
+ this.checkAddress(address);
1536
+ await this.loadMarkets();
1537
+ // todo rewrite for https://api-pub.bitfinex.com//v2/conf/pub:map:tx:method
1538
+ const name = this.getCurrencyName(code);
1539
+ const currency = this.currency(code);
1540
+ const request = {
1541
+ 'withdraw_type': name,
1542
+ 'walletselected': 'exchange',
1543
+ 'amount': this.numberToString(amount),
1544
+ 'address': address,
1545
+ };
1546
+ if (tag !== undefined) {
1547
+ request['payment_id'] = tag;
1548
+ }
1549
+ const responses = await this.privatePostWithdraw(this.extend(request, params));
1550
+ //
1551
+ // [
1552
+ // {
1553
+ // "status":"success",
1554
+ // "message":"Your withdrawal request has been successfully submitted.",
1555
+ // "withdrawal_id":586829
1556
+ // }
1557
+ // ]
1558
+ //
1559
+ const response = this.safeValue(responses, 0, {});
1560
+ const id = this.safeNumber(response, 'withdrawal_id');
1561
+ const message = this.safeString(response, 'message');
1562
+ const errorMessage = this.findBroadlyMatchedKey(this.exceptions['broad'], message);
1563
+ if (id === 0) {
1564
+ if (errorMessage !== undefined) {
1565
+ const ExceptionClass = this.exceptions['broad'][errorMessage];
1566
+ throw new ExceptionClass(this.id + ' ' + message);
1567
+ }
1568
+ throw new errors.ExchangeError(this.id + ' withdraw returned an id of zero: ' + this.json(response));
1569
+ }
1570
+ return this.parseTransaction(response, currency);
1571
+ }
1572
+ async fetchPositions(symbols = undefined, params = {}) {
1573
+ /**
1574
+ * @method
1575
+ * @name bitfinex#fetchPositions
1576
+ * @description fetch all open positions
1577
+ * @param {string[]|undefined} symbols list of unified market symbols
1578
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1579
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/#/?id=position-structure}
1580
+ */
1581
+ await this.loadMarkets();
1582
+ const response = await this.privatePostPositions(params);
1583
+ //
1584
+ // [
1585
+ // {
1586
+ // "id":943715,
1587
+ // "symbol":"btcusd",
1588
+ // "status":"ACTIVE",
1589
+ // "base":"246.94",
1590
+ // "amount":"1.0",
1591
+ // "timestamp":"1444141857.0",
1592
+ // "swap":"0.0",
1593
+ // "pl":"-2.22042"
1594
+ // }
1595
+ // ]
1596
+ //
1597
+ // todo unify parsePosition/parsePositions
1598
+ return response;
1599
+ }
1600
+ nonce() {
1601
+ return this.milliseconds();
1602
+ }
1603
+ sign(path, api = 'public', method = 'GET', params = {}, headers = undefined, body = undefined) {
1604
+ let request = '/' + this.implodeParams(path, params);
1605
+ if (api === 'v2') {
1606
+ request = '/' + api + request;
1607
+ }
1608
+ else {
1609
+ request = '/' + this.version + request;
1610
+ }
1611
+ let query = this.omit(params, this.extractParams(path));
1612
+ let url = this.urls['api'][api] + request;
1613
+ if ((api === 'public') || (path.indexOf('/hist') >= 0)) {
1614
+ if (Object.keys(query).length) {
1615
+ const suffix = '?' + this.urlencode(query);
1616
+ url += suffix;
1617
+ request += suffix;
1618
+ }
1619
+ }
1620
+ if (api === 'private') {
1621
+ this.checkRequiredCredentials();
1622
+ const nonce = this.nonce();
1623
+ query = this.extend({
1624
+ 'nonce': nonce.toString(),
1625
+ 'request': request,
1626
+ }, query);
1627
+ body = this.json(query);
1628
+ const payload = this.stringToBase64(body);
1629
+ const secret = this.encode(this.secret);
1630
+ const signature = this.hmac(this.encode(payload), secret, sha512.sha384);
1631
+ headers = {
1632
+ 'X-BFX-APIKEY': this.apiKey,
1633
+ 'X-BFX-PAYLOAD': payload,
1634
+ 'X-BFX-SIGNATURE': signature,
1635
+ 'Content-Type': 'application/json',
1636
+ };
1637
+ }
1638
+ return { 'url': url, 'method': method, 'body': body, 'headers': headers };
1639
+ }
1640
+ handleErrors(code, reason, url, method, headers, body, response, requestHeaders, requestBody) {
1641
+ if (response === undefined) {
1642
+ return undefined;
1643
+ }
1644
+ let throwError = false;
1645
+ if (code >= 400) {
1646
+ if (body[0] === '{') {
1647
+ throwError = true;
1648
+ }
1649
+ }
1650
+ else {
1651
+ // json response with error, i.e:
1652
+ // [{"status":"error","message":"Momentary balance check. Please wait few seconds and try the transfer again."}]
1653
+ const responseObject = this.safeValue(response, 0, {});
1654
+ const status = this.safeString(responseObject, 'status', '');
1655
+ if (status === 'error') {
1656
+ throwError = true;
1657
+ }
1658
+ }
1659
+ if (throwError) {
1660
+ const feedback = this.id + ' ' + body;
1661
+ const message = this.safeString2(response, 'message', 'error');
1662
+ this.throwExactlyMatchedException(this.exceptions['exact'], message, feedback);
1663
+ this.throwBroadlyMatchedException(this.exceptions['broad'], message, feedback);
1664
+ throw new errors.ExchangeError(feedback); // unknown message
1665
+ }
1666
+ return undefined;
1667
+ }
1668
+ }
1669
+
1670
+ module.exports = bitfinex;