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,1733 @@
1
+ 'use strict';
2
+
3
+ var bitget$1 = require('../bitget.js');
4
+ var errors = require('../base/errors.js');
5
+ var Precise = require('../base/Precise.js');
6
+ var Cache = require('../base/ws/Cache.js');
7
+ var sha256 = require('../static_dependencies/noble-hashes/sha256.js');
8
+
9
+ // ---------------------------------------------------------------------------
10
+ // ---------------------------------------------------------------------------
11
+ /**
12
+ * @class bitget
13
+ * @augments Exchange
14
+ * @description watching delivery future markets is not yet implemented (perpertual future / swap is implemented)
15
+ */
16
+ class bitget extends bitget$1 {
17
+ describe() {
18
+ return this.deepExtend(super.describe(), {
19
+ 'has': {
20
+ 'ws': true,
21
+ 'createOrderWs': false,
22
+ 'editOrderWs': false,
23
+ 'fetchOpenOrdersWs': false,
24
+ 'fetchOrderWs': false,
25
+ 'cancelOrderWs': false,
26
+ 'cancelOrdersWs': false,
27
+ 'cancelAllOrdersWs': false,
28
+ 'watchBalance': true,
29
+ 'watchMyTrades': true,
30
+ 'watchOHLCV': true,
31
+ 'watchOHLCVForSymbols': false,
32
+ 'watchOrderBook': true,
33
+ 'watchOrderBookForSymbols': true,
34
+ 'watchOrders': true,
35
+ 'watchTicker': true,
36
+ 'watchTickers': true,
37
+ 'watchTrades': true,
38
+ 'watchTradesForSymbols': true,
39
+ 'watchPositions': true,
40
+ },
41
+ 'urls': {
42
+ 'api': {
43
+ 'ws': {
44
+ 'public': 'wss://ws.bitget.com/v2/ws/public',
45
+ 'private': 'wss://ws.bitget.com/v2/ws/private',
46
+ },
47
+ },
48
+ },
49
+ 'options': {
50
+ 'tradesLimit': 1000,
51
+ 'OHLCVLimit': 1000,
52
+ // WS timeframes differ from REST timeframes
53
+ 'timeframes': {
54
+ '1m': '1m',
55
+ '5m': '5m',
56
+ '15m': '15m',
57
+ '30m': '30m',
58
+ '1h': '1H',
59
+ '4h': '4H',
60
+ '6h': '6H',
61
+ '12h': '12H',
62
+ '1d': '1D',
63
+ '1w': '1W',
64
+ },
65
+ },
66
+ 'streaming': {
67
+ 'ping': this.ping,
68
+ },
69
+ 'exceptions': {
70
+ 'ws': {
71
+ 'exact': {
72
+ '30001': errors.BadRequest,
73
+ '30002': errors.AuthenticationError,
74
+ '30003': errors.BadRequest,
75
+ '30004': errors.AuthenticationError,
76
+ '30005': errors.AuthenticationError,
77
+ '30006': errors.RateLimitExceeded,
78
+ '30007': errors.RateLimitExceeded,
79
+ '30011': errors.AuthenticationError,
80
+ '30012': errors.AuthenticationError,
81
+ '30013': errors.AuthenticationError,
82
+ '30014': errors.BadRequest,
83
+ '30015': errors.AuthenticationError,
84
+ '30016': errors.BadRequest, // { event: 'error', code: 30016, msg: 'Param error' }
85
+ },
86
+ },
87
+ },
88
+ });
89
+ }
90
+ getInstType(market, params = {}) {
91
+ let instType = undefined;
92
+ if ((market['swap']) || (market['future'])) {
93
+ [instType, params] = this.handleProductTypeAndParams(market, params);
94
+ }
95
+ else {
96
+ instType = 'SPOT';
97
+ }
98
+ [instType, params] = this.handleOptionAndParams(params, 'getInstType', 'instType', instType);
99
+ return [instType, params];
100
+ }
101
+ async watchTicker(symbol, params = {}) {
102
+ /**
103
+ * @method
104
+ * @name bitget#watchTicker
105
+ * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
106
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
107
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
108
+ * @param {string} symbol unified symbol of the market to watch the ticker for
109
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
110
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
111
+ */
112
+ await this.loadMarkets();
113
+ const market = this.market(symbol);
114
+ symbol = market['symbol'];
115
+ const messageHash = 'ticker:' + symbol;
116
+ let instType = undefined;
117
+ [instType, params] = this.getInstType(market, params);
118
+ const args = {
119
+ 'instType': instType,
120
+ 'channel': 'ticker',
121
+ 'instId': market['id'],
122
+ };
123
+ return await this.watchPublic(messageHash, args, params);
124
+ }
125
+ async watchTickers(symbols = undefined, params = {}) {
126
+ /**
127
+ * @method
128
+ * @name bitget#watchTickers
129
+ * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
130
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Tickers-Channel
131
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/Tickers-Channel
132
+ * @param {string[]} symbols unified symbol of the market to watch the tickers for
133
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
134
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
135
+ */
136
+ await this.loadMarkets();
137
+ symbols = this.marketSymbols(symbols, undefined, false);
138
+ const market = this.market(symbols[0]);
139
+ let instType = undefined;
140
+ [instType, params] = this.getInstType(market, params);
141
+ const topics = [];
142
+ const messageHashes = [];
143
+ for (let i = 0; i < symbols.length; i++) {
144
+ const symbol = symbols[i];
145
+ const marketInner = this.market(symbol);
146
+ const args = {
147
+ 'instType': instType,
148
+ 'channel': 'ticker',
149
+ 'instId': marketInner['id'],
150
+ };
151
+ topics.push(args);
152
+ messageHashes.push('ticker:' + symbol);
153
+ }
154
+ const tickers = await this.watchPublicMultiple(messageHashes, topics, params);
155
+ if (this.newUpdates) {
156
+ const result = {};
157
+ result[tickers['symbol']] = tickers;
158
+ return result;
159
+ }
160
+ return this.filterByArray(this.tickers, 'symbol', symbols);
161
+ }
162
+ handleTicker(client, message) {
163
+ //
164
+ // {
165
+ // "action": "snapshot",
166
+ // "arg": {
167
+ // "instType": "SPOT",
168
+ // "channel": "ticker",
169
+ // "instId": "BTCUSDT"
170
+ // },
171
+ // "data": [
172
+ // {
173
+ // "instId": "BTCUSDT",
174
+ // "lastPr": "43528.19",
175
+ // "open24h": "42267.78",
176
+ // "high24h": "44490.00",
177
+ // "low24h": "41401.53",
178
+ // "change24h": "0.03879",
179
+ // "bidPr": "43528",
180
+ // "askPr": "43528.01",
181
+ // "bidSz": "0.0334",
182
+ // "askSz": "0.1917",
183
+ // "baseVolume": "15002.4216",
184
+ // "quoteVolume": "648006446.7164",
185
+ // "openUtc": "44071.18",
186
+ // "changeUtc24h": "-0.01232",
187
+ // "ts": "1701842994338"
188
+ // }
189
+ // ],
190
+ // "ts": 1701842994341
191
+ // }
192
+ //
193
+ const ticker = this.parseWsTicker(message);
194
+ const symbol = ticker['symbol'];
195
+ this.tickers[symbol] = ticker;
196
+ const messageHash = 'ticker:' + symbol;
197
+ client.resolve(ticker, messageHash);
198
+ }
199
+ parseWsTicker(message, market = undefined) {
200
+ //
201
+ // spot
202
+ //
203
+ // {
204
+ // "action": "snapshot",
205
+ // "arg": {
206
+ // "instType": "SPOT",
207
+ // "channel": "ticker",
208
+ // "instId": "BTCUSDT"
209
+ // },
210
+ // "data": [
211
+ // {
212
+ // "instId": "BTCUSDT",
213
+ // "lastPr": "43528.19",
214
+ // "open24h": "42267.78",
215
+ // "high24h": "44490.00",
216
+ // "low24h": "41401.53",
217
+ // "change24h": "0.03879",
218
+ // "bidPr": "43528",
219
+ // "askPr": "43528.01",
220
+ // "bidSz": "0.0334",
221
+ // "askSz": "0.1917",
222
+ // "baseVolume": "15002.4216",
223
+ // "quoteVolume": "648006446.7164",
224
+ // "openUtc": "44071.18",
225
+ // "changeUtc24h": "-0.01232",
226
+ // "ts": "1701842994338"
227
+ // }
228
+ // ],
229
+ // "ts": 1701842994341
230
+ // }
231
+ //
232
+ // contract
233
+ //
234
+ // {
235
+ // "action": "snapshot",
236
+ // "arg": {
237
+ // "instType": "USDT-FUTURES",
238
+ // "channel": "ticker",
239
+ // "instId": "BTCUSDT"
240
+ // },
241
+ // "data": [
242
+ // {
243
+ // "instId": "BTCUSDT",
244
+ // "lastPr": "43480.4",
245
+ // "bidPr": "43476.3",
246
+ // "askPr": "43476.8",
247
+ // "bidSz": "0.1",
248
+ // "askSz": "3.055",
249
+ // "open24h": "42252.3",
250
+ // "high24h": "44518.2",
251
+ // "low24h": "41387.0",
252
+ // "change24h": "0.03875",
253
+ // "fundingRate": "0.000096",
254
+ // "nextFundingTime": "1701849600000",
255
+ // "markPrice": "43476.4",
256
+ // "indexPrice": "43478.4",
257
+ // "holdingAmount": "50670.787",
258
+ // "baseVolume": "120187.104",
259
+ // "quoteVolume": "5167385048.693",
260
+ // "openUtc": "44071.4",
261
+ // "symbolType": "1",
262
+ // "symbol": "BTCUSDT",
263
+ // "deliveryPrice": "0",
264
+ // "ts": "1701843962811"
265
+ // }
266
+ // ],
267
+ // "ts": 1701843962812
268
+ // }
269
+ //
270
+ const arg = this.safeValue(message, 'arg', {});
271
+ const data = this.safeValue(message, 'data', []);
272
+ const ticker = this.safeValue(data, 0, {});
273
+ const timestamp = this.safeInteger(ticker, 'ts');
274
+ const instType = this.safeString(arg, 'instType');
275
+ const marketType = (instType === 'SPOT') ? 'spot' : 'contract';
276
+ const marketId = this.safeString(ticker, 'instId');
277
+ market = this.safeMarket(marketId, market, undefined, marketType);
278
+ const close = this.safeString(ticker, 'lastPr');
279
+ const changeDecimal = this.safeString(ticker, 'change24h');
280
+ const change = Precise["default"].stringMul(changeDecimal, '100');
281
+ return this.safeTicker({
282
+ 'symbol': market['symbol'],
283
+ 'timestamp': timestamp,
284
+ 'datetime': this.iso8601(timestamp),
285
+ 'high': this.safeString(ticker, 'high24h'),
286
+ 'low': this.safeString(ticker, 'low24h'),
287
+ 'bid': this.safeString(ticker, 'bidPr'),
288
+ 'bidVolume': this.safeString(ticker, 'bidSz'),
289
+ 'ask': this.safeString(ticker, 'askPr'),
290
+ 'askVolume': this.safeString(ticker, 'askSz'),
291
+ 'vwap': undefined,
292
+ 'open': this.safeString(ticker, 'open24h'),
293
+ 'close': close,
294
+ 'last': close,
295
+ 'previousClose': undefined,
296
+ 'change': undefined,
297
+ 'percentage': change,
298
+ 'average': undefined,
299
+ 'baseVolume': this.safeString(ticker, 'baseVolume'),
300
+ 'quoteVolume': this.safeString(ticker, 'quoteVolume'),
301
+ 'info': ticker,
302
+ }, market);
303
+ }
304
+ async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
305
+ /**
306
+ * @method
307
+ * @name bitget#watchOHLCV
308
+ * @description watches historical candlestick data containing the open, high, low, close price, and the volume of a market
309
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Candlesticks-Channel
310
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/Candlesticks-Channel
311
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
312
+ * @param {string} timeframe the length of time each candle represents
313
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
314
+ * @param {int} [limit] the maximum amount of candles to fetch
315
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
316
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
317
+ */
318
+ await this.loadMarkets();
319
+ const market = this.market(symbol);
320
+ symbol = market['symbol'];
321
+ const timeframes = this.safeValue(this.options, 'timeframes');
322
+ const interval = this.safeString(timeframes, timeframe);
323
+ const messageHash = 'candles:' + timeframe + ':' + symbol;
324
+ let instType = undefined;
325
+ [instType, params] = this.getInstType(market, params);
326
+ const args = {
327
+ 'instType': instType,
328
+ 'channel': 'candle' + interval,
329
+ 'instId': market['id'],
330
+ };
331
+ const ohlcv = await this.watchPublic(messageHash, args, params);
332
+ if (this.newUpdates) {
333
+ limit = ohlcv.getLimit(symbol, limit);
334
+ }
335
+ return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
336
+ }
337
+ handleOHLCV(client, message) {
338
+ //
339
+ // {
340
+ // "action": "snapshot",
341
+ // "arg": {
342
+ // "instType": "SPOT",
343
+ // "channel": "candle1m",
344
+ // "instId": "BTCUSDT"
345
+ // },
346
+ // "data": [
347
+ // [
348
+ // "1701871620000",
349
+ // "44080.23",
350
+ // "44080.23",
351
+ // "44028.5",
352
+ // "44028.51",
353
+ // "9.9287",
354
+ // "437404.105512",
355
+ // "437404.105512"
356
+ // ],
357
+ // [
358
+ // "1701871680000",
359
+ // "44028.51",
360
+ // "44108.11",
361
+ // "44028.5",
362
+ // "44108.11",
363
+ // "17.139",
364
+ // "755436.870643",
365
+ // "755436.870643"
366
+ // ],
367
+ // ],
368
+ // "ts": 1701901610417
369
+ // }
370
+ //
371
+ const arg = this.safeValue(message, 'arg', {});
372
+ const instType = this.safeString(arg, 'instType');
373
+ const marketType = (instType === 'SPOT') ? 'spot' : 'contract';
374
+ const marketId = this.safeString(arg, 'instId');
375
+ const market = this.safeMarket(marketId, undefined, undefined, marketType);
376
+ const symbol = market['symbol'];
377
+ this.ohlcvs[symbol] = this.safeValue(this.ohlcvs, symbol, {});
378
+ const channel = this.safeString(arg, 'channel');
379
+ const interval = channel.replace('candle', '');
380
+ const timeframes = this.safeValue(this.options, 'timeframes');
381
+ const timeframe = this.findTimeframe(interval, timeframes);
382
+ let stored = this.safeValue(this.ohlcvs[symbol], timeframe);
383
+ if (stored === undefined) {
384
+ const limit = this.safeInteger(this.options, 'OHLCVLimit', 1000);
385
+ stored = new Cache.ArrayCacheByTimestamp(limit);
386
+ this.ohlcvs[symbol][timeframe] = stored;
387
+ }
388
+ const data = this.safeValue(message, 'data', []);
389
+ for (let i = 0; i < data.length; i++) {
390
+ const parsed = this.parseWsOHLCV(data[i], market);
391
+ stored.append(parsed);
392
+ }
393
+ const messageHash = 'candles:' + timeframe + ':' + symbol;
394
+ client.resolve(stored, messageHash);
395
+ }
396
+ parseWsOHLCV(ohlcv, market = undefined) {
397
+ //
398
+ // [
399
+ // "1701871620000", // timestamp
400
+ // "44080.23", // open
401
+ // "44080.23", // high
402
+ // "44028.5", // low
403
+ // "44028.51", // close
404
+ // "9.9287", // base volume
405
+ // "437404.105512", // quote volume
406
+ // "437404.105512" // USDT volume
407
+ // ]
408
+ //
409
+ const volumeIndex = (market['inverse']) ? 6 : 5;
410
+ return [
411
+ this.safeInteger(ohlcv, 0),
412
+ this.safeNumber(ohlcv, 1),
413
+ this.safeNumber(ohlcv, 2),
414
+ this.safeNumber(ohlcv, 3),
415
+ this.safeNumber(ohlcv, 4),
416
+ this.safeNumber(ohlcv, volumeIndex),
417
+ ];
418
+ }
419
+ async watchOrderBook(symbol, limit = undefined, params = {}) {
420
+ /**
421
+ * @method
422
+ * @name bitget#watchOrderBook
423
+ * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
424
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
425
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
426
+ * @param {string} symbol unified symbol of the market to fetch the order book for
427
+ * @param {int} [limit] the maximum amount of order book entries to return
428
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
429
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
430
+ */
431
+ return await this.watchOrderBookForSymbols([symbol], limit, params);
432
+ }
433
+ async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
434
+ /**
435
+ * @method
436
+ * @name bitget#watchOrderBookForSymbols
437
+ * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
438
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Depth-Channel
439
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/Order-Book-Channel
440
+ * @param {string[]} symbols unified array of symbols
441
+ * @param {int} [limit] the maximum amount of order book entries to return
442
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
443
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
444
+ */
445
+ await this.loadMarkets();
446
+ symbols = this.marketSymbols(symbols);
447
+ let channel = 'books';
448
+ let incrementalFeed = true;
449
+ if ((limit === 5) || (limit === 15)) {
450
+ channel += limit.toString();
451
+ incrementalFeed = false;
452
+ }
453
+ const topics = [];
454
+ const messageHashes = [];
455
+ for (let i = 0; i < symbols.length; i++) {
456
+ const symbol = symbols[i];
457
+ const market = this.market(symbol);
458
+ let instType = undefined;
459
+ [instType, params] = this.getInstType(market, params);
460
+ const args = {
461
+ 'instType': instType,
462
+ 'channel': channel,
463
+ 'instId': market['id'],
464
+ };
465
+ topics.push(args);
466
+ messageHashes.push('orderbook:' + symbol);
467
+ }
468
+ const orderbook = await this.watchPublicMultiple(messageHashes, topics, params);
469
+ if (incrementalFeed) {
470
+ return orderbook.limit();
471
+ }
472
+ else {
473
+ return orderbook;
474
+ }
475
+ }
476
+ handleOrderBook(client, message) {
477
+ //
478
+ // {
479
+ // "action":"snapshot",
480
+ // "arg":{
481
+ // "instType":"SPOT",
482
+ // "channel":"books5",
483
+ // "instId":"BTCUSDT"
484
+ // },
485
+ // "data":[
486
+ // {
487
+ // "asks":[
488
+ // ["21041.11","0.0445"],
489
+ // ["21041.16","0.0411"],
490
+ // ["21041.21","0.0421"],
491
+ // ["21041.26","0.0811"],
492
+ // ["21041.65","1.9465"]
493
+ // ],
494
+ // "bids":[
495
+ // ["21040.76","0.0417"],
496
+ // ["21040.71","0.0434"],
497
+ // ["21040.66","0.1141"],
498
+ // ["21040.61","0.3004"],
499
+ // ["21040.60","1.3357"]
500
+ // ],
501
+ // "checksum": -1367582038,
502
+ // "ts":"1656413855484"
503
+ // }
504
+ // ]
505
+ // }
506
+ //
507
+ const arg = this.safeValue(message, 'arg');
508
+ const channel = this.safeString(arg, 'channel');
509
+ const instType = this.safeString(arg, 'instType');
510
+ const marketType = (instType === 'SPOT') ? 'spot' : 'contract';
511
+ const marketId = this.safeString(arg, 'instId');
512
+ const market = this.safeMarket(marketId, undefined, undefined, marketType);
513
+ const symbol = market['symbol'];
514
+ const messageHash = 'orderbook:' + symbol;
515
+ const data = this.safeValue(message, 'data');
516
+ const rawOrderBook = this.safeValue(data, 0);
517
+ const timestamp = this.safeInteger(rawOrderBook, 'ts');
518
+ const incrementalBook = channel === 'books';
519
+ let storedOrderBook = undefined;
520
+ if (incrementalBook) {
521
+ storedOrderBook = this.safeValue(this.orderbooks, symbol);
522
+ if (storedOrderBook === undefined) {
523
+ storedOrderBook = this.countedOrderBook({});
524
+ storedOrderBook['symbol'] = symbol;
525
+ }
526
+ const asks = this.safeValue(rawOrderBook, 'asks', []);
527
+ const bids = this.safeValue(rawOrderBook, 'bids', []);
528
+ this.handleDeltas(storedOrderBook['asks'], asks);
529
+ this.handleDeltas(storedOrderBook['bids'], bids);
530
+ storedOrderBook['timestamp'] = timestamp;
531
+ storedOrderBook['datetime'] = this.iso8601(timestamp);
532
+ const checksum = this.safeValue(this.options, 'checksum', true);
533
+ const isSnapshot = this.safeString(message, 'action') === 'snapshot'; // snapshot does not have a checksum
534
+ if (!isSnapshot && checksum) {
535
+ const storedAsks = storedOrderBook['asks'];
536
+ const storedBids = storedOrderBook['bids'];
537
+ const asksLength = storedAsks.length;
538
+ const bidsLength = storedBids.length;
539
+ const payloadArray = [];
540
+ for (let i = 0; i < 25; i++) {
541
+ if (i < bidsLength) {
542
+ payloadArray.push(storedBids[i][2][0]);
543
+ payloadArray.push(storedBids[i][2][1]);
544
+ }
545
+ if (i < asksLength) {
546
+ payloadArray.push(storedAsks[i][2][0]);
547
+ payloadArray.push(storedAsks[i][2][1]);
548
+ }
549
+ }
550
+ const payload = payloadArray.join(':');
551
+ const calculatedChecksum = this.crc32(payload, true);
552
+ const responseChecksum = this.safeInteger(rawOrderBook, 'checksum');
553
+ if (calculatedChecksum !== responseChecksum) {
554
+ const error = new errors.InvalidNonce(this.id + ' invalid checksum');
555
+ client.reject(error, messageHash);
556
+ }
557
+ }
558
+ }
559
+ else {
560
+ storedOrderBook = this.parseOrderBook(rawOrderBook, symbol, timestamp);
561
+ }
562
+ this.orderbooks[symbol] = storedOrderBook;
563
+ client.resolve(storedOrderBook, messageHash);
564
+ }
565
+ handleDelta(bookside, delta) {
566
+ const bidAsk = this.parseBidAsk(delta, 0, 1);
567
+ // we store the string representations in the orderbook for checksum calculation
568
+ // this simplifies the code for generating checksums as we do not need to do any complex number transformations
569
+ bidAsk.push(delta);
570
+ bookside.storeArray(bidAsk);
571
+ }
572
+ handleDeltas(bookside, deltas) {
573
+ for (let i = 0; i < deltas.length; i++) {
574
+ this.handleDelta(bookside, deltas[i]);
575
+ }
576
+ }
577
+ async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
578
+ /**
579
+ * @method
580
+ * @name bitget#watchTrades
581
+ * @description get the list of most recent trades for a particular symbol
582
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
583
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
584
+ * @param {string} symbol unified symbol of the market to fetch trades for
585
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
586
+ * @param {int} [limit] the maximum amount of trades to fetch
587
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
588
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
589
+ */
590
+ return await this.watchTradesForSymbols([symbol], since, limit, params);
591
+ }
592
+ async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
593
+ /**
594
+ * @method
595
+ * @name bitget#watchTradesForSymbols
596
+ * @description get the list of most recent trades for a particular symbol
597
+ * @see https://www.bitget.com/api-doc/spot/websocket/public/Trades-Channel
598
+ * @see https://www.bitget.com/api-doc/contract/websocket/public/New-Trades-Channel
599
+ * @param {string} symbol unified symbol of the market to fetch trades for
600
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
601
+ * @param {int} [limit] the maximum amount of trades to fetch
602
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
603
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
604
+ */
605
+ const symbolsLength = symbols.length;
606
+ if (symbolsLength === 0) {
607
+ throw new errors.ArgumentsRequired(this.id + ' watchTradesForSymbols() requires a non-empty array of symbols');
608
+ }
609
+ await this.loadMarkets();
610
+ symbols = this.marketSymbols(symbols);
611
+ const topics = [];
612
+ const messageHashes = [];
613
+ for (let i = 0; i < symbols.length; i++) {
614
+ const symbol = symbols[i];
615
+ const market = this.market(symbol);
616
+ let instType = undefined;
617
+ [instType, params] = this.getInstType(market, params);
618
+ const args = {
619
+ 'instType': instType,
620
+ 'channel': 'trade',
621
+ 'instId': market['id'],
622
+ };
623
+ topics.push(args);
624
+ messageHashes.push('trade:' + symbol);
625
+ }
626
+ const trades = await this.watchPublicMultiple(messageHashes, topics, params);
627
+ if (this.newUpdates) {
628
+ const first = this.safeValue(trades, 0);
629
+ const tradeSymbol = this.safeString(first, 'symbol');
630
+ limit = trades.getLimit(tradeSymbol, limit);
631
+ }
632
+ return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
633
+ }
634
+ handleTrades(client, message) {
635
+ //
636
+ // {
637
+ // "action": "snapshot",
638
+ // "arg": { "instType": "SPOT", "channel": "trade", "instId": "BTCUSDT" },
639
+ // "data": [
640
+ // {
641
+ // "ts": "1701910980366",
642
+ // "price": "43854.01",
643
+ // "size": "0.0535",
644
+ // "side": "buy",
645
+ // "tradeId": "1116461060594286593"
646
+ // },
647
+ // ],
648
+ // "ts": 1701910980730
649
+ // }
650
+ //
651
+ const arg = this.safeValue(message, 'arg', {});
652
+ const instType = this.safeString(arg, 'instType');
653
+ const marketType = (instType === 'SPOT') ? 'spot' : 'contract';
654
+ const marketId = this.safeString(arg, 'instId');
655
+ const market = this.safeMarket(marketId, undefined, undefined, marketType);
656
+ const symbol = market['symbol'];
657
+ let stored = this.safeValue(this.trades, symbol);
658
+ if (stored === undefined) {
659
+ const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
660
+ stored = new Cache.ArrayCache(limit);
661
+ this.trades[symbol] = stored;
662
+ }
663
+ const data = this.safeValue(message, 'data', []);
664
+ for (let j = 0; j < data.length; j++) {
665
+ const rawTrade = data[j];
666
+ const parsed = this.parseWsTrade(rawTrade, market);
667
+ stored.append(parsed);
668
+ }
669
+ const messageHash = 'trade:' + symbol;
670
+ client.resolve(stored, messageHash);
671
+ }
672
+ parseWsTrade(trade, market = undefined) {
673
+ //
674
+ // {
675
+ // "ts": "1701910980366",
676
+ // "price": "43854.01",
677
+ // "size": "0.0535",
678
+ // "side": "buy",
679
+ // "tradeId": "1116461060594286593"
680
+ // }
681
+ //
682
+ market = this.safeMarket(undefined, market);
683
+ const timestamp = this.safeInteger(trade, 'ts');
684
+ return this.safeTrade({
685
+ 'info': trade,
686
+ 'id': this.safeString(trade, 'tradeId'),
687
+ 'order': undefined,
688
+ 'timestamp': timestamp,
689
+ 'datetime': this.iso8601(timestamp),
690
+ 'symbol': market['symbol'],
691
+ 'type': undefined,
692
+ 'side': this.safeString(trade, 'side'),
693
+ 'takerOrMaker': undefined,
694
+ 'price': this.safeString(trade, 'price'),
695
+ 'amount': this.safeString(trade, 'size'),
696
+ 'cost': undefined,
697
+ 'fee': undefined,
698
+ }, market);
699
+ }
700
+ async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
701
+ /**
702
+ * @method
703
+ * @name bitget#watchPositions
704
+ * @description watch all open positions
705
+ * @see https://www.bitget.com/api-doc/contract/websocket/private/Positions-Channel
706
+ * @param {string[]|undefined} symbols list of unified market symbols
707
+ * @param {object} params extra parameters specific to the exchange API endpoint
708
+ * @param {string} [params.instType] one of 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES', default is 'USDT-FUTURES'
709
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
710
+ */
711
+ await this.loadMarkets();
712
+ let market = undefined;
713
+ let messageHash = '';
714
+ const subscriptionHash = 'positions';
715
+ let instType = 'USDT-FUTURES';
716
+ symbols = this.marketSymbols(symbols);
717
+ if (!this.isEmpty(symbols)) {
718
+ market = this.getMarketFromSymbols(symbols);
719
+ [instType, params] = this.getInstType(market, params);
720
+ }
721
+ messageHash = instType + ':positions' + messageHash;
722
+ const args = {
723
+ 'instType': instType,
724
+ 'channel': 'positions',
725
+ 'instId': 'default',
726
+ };
727
+ const newPositions = await this.watchPrivate(messageHash, subscriptionHash, args, params);
728
+ if (this.newUpdates) {
729
+ return newPositions;
730
+ }
731
+ return this.filterBySymbolsSinceLimit(newPositions, symbols, since, limit, true);
732
+ }
733
+ handlePositions(client, message) {
734
+ //
735
+ // {
736
+ // "action": "snapshot",
737
+ // "arg": {
738
+ // "instType": "USDT-FUTURES",
739
+ // "channel": "positions",
740
+ // "instId": "default"
741
+ // },
742
+ // "data": [
743
+ // {
744
+ // "posId": "926036334386778112",
745
+ // "instId": "BTCUSDT",
746
+ // "marginCoin": "USDT",
747
+ // "marginSize": "2.19245",
748
+ // "marginMode": "crossed",
749
+ // "holdSide": "long",
750
+ // "posMode": "hedge_mode",
751
+ // "total": "0.001",
752
+ // "available": "0.001",
753
+ // "frozen": "0",
754
+ // "openPriceAvg": "43849",
755
+ // "leverage": 20,
756
+ // "achievedProfits": "0",
757
+ // "unrealizedPL": "-0.0032",
758
+ // "unrealizedPLR": "-0.00145955438",
759
+ // "liquidationPrice": "17629.684814834",
760
+ // "keepMarginRate": "0.004",
761
+ // "marginRate": "0.007634649185",
762
+ // "cTime": "1652331666985",
763
+ // "uTime": "1701913016923",
764
+ // "autoMargin": "off"
765
+ // },
766
+ // ...
767
+ // ]
768
+ // "ts": 1701913043767
769
+ // }
770
+ //
771
+ const arg = this.safeValue(message, 'arg', {});
772
+ const instType = this.safeString(arg, 'instType', '');
773
+ if (this.positions === undefined) {
774
+ this.positions = {};
775
+ }
776
+ if (!(instType in this.positions)) {
777
+ this.positions[instType] = new Cache.ArrayCacheBySymbolBySide();
778
+ }
779
+ const cache = this.positions[instType];
780
+ const rawPositions = this.safeValue(message, 'data', []);
781
+ const dataLength = rawPositions.length;
782
+ if (dataLength === 0) {
783
+ return;
784
+ }
785
+ const newPositions = [];
786
+ for (let i = 0; i < rawPositions.length; i++) {
787
+ const rawPosition = rawPositions[i];
788
+ const marketId = this.safeString(rawPosition, 'instId');
789
+ const market = this.safeMarket(marketId, undefined, undefined, 'contract');
790
+ const position = this.parseWsPosition(rawPosition, market);
791
+ newPositions.push(position);
792
+ cache.append(position);
793
+ }
794
+ const messageHashes = this.findMessageHashes(client, instType + ':positions::');
795
+ for (let i = 0; i < messageHashes.length; i++) {
796
+ const messageHash = messageHashes[i];
797
+ const parts = messageHash.split('::');
798
+ const symbolsString = parts[1];
799
+ const symbols = symbolsString.split(',');
800
+ const positions = this.filterByArray(newPositions, 'symbol', symbols, false);
801
+ if (!this.isEmpty(positions)) {
802
+ client.resolve(positions, messageHash);
803
+ }
804
+ }
805
+ client.resolve(newPositions, instType + ':positions');
806
+ }
807
+ parseWsPosition(position, market = undefined) {
808
+ //
809
+ // {
810
+ // "posId": "926036334386778112",
811
+ // "instId": "BTCUSDT",
812
+ // "marginCoin": "USDT",
813
+ // "marginSize": "2.19245",
814
+ // "marginMode": "crossed",
815
+ // "holdSide": "long",
816
+ // "posMode": "hedge_mode",
817
+ // "total": "0.001",
818
+ // "available": "0.001",
819
+ // "frozen": "0",
820
+ // "openPriceAvg": "43849",
821
+ // "leverage": 20,
822
+ // "achievedProfits": "0",
823
+ // "unrealizedPL": "-0.0032",
824
+ // "unrealizedPLR": "-0.00145955438",
825
+ // "liquidationPrice": "17629.684814834",
826
+ // "keepMarginRate": "0.004",
827
+ // "marginRate": "0.007634649185",
828
+ // "cTime": "1652331666985",
829
+ // "uTime": "1701913016923",
830
+ // "autoMargin": "off"
831
+ // }
832
+ //
833
+ const marketId = this.safeString(position, 'instId');
834
+ const marginModeId = this.safeString(position, 'marginMode');
835
+ const marginMode = this.getSupportedMapping(marginModeId, {
836
+ 'crossed': 'cross',
837
+ 'isolated': 'isolated',
838
+ });
839
+ const hedgedId = this.safeString(position, 'posMode');
840
+ const hedged = (hedgedId === 'hedge_mode') ? true : false;
841
+ const timestamp = this.safeInteger2(position, 'uTime', 'cTime');
842
+ const percentageDecimal = this.safeString(position, 'unrealizedPLR');
843
+ const percentage = Precise["default"].stringMul(percentageDecimal, '100');
844
+ let contractSize = undefined;
845
+ if (market !== undefined) {
846
+ contractSize = market['contractSize'];
847
+ }
848
+ return this.safePosition({
849
+ 'info': position,
850
+ 'id': this.safeString(position, 'posId'),
851
+ 'symbol': this.safeSymbol(marketId, market, undefined, 'contract'),
852
+ 'notional': undefined,
853
+ 'marginMode': marginMode,
854
+ 'liquidationPrice': this.safeNumber(position, 'liquidationPrice'),
855
+ 'entryPrice': this.safeNumber(position, 'openPriceAvg'),
856
+ 'unrealizedPnl': this.safeNumber(position, 'unrealizedPL'),
857
+ 'percentage': this.parseNumber(percentage),
858
+ 'contracts': this.safeNumber(position, 'total'),
859
+ 'contractSize': contractSize,
860
+ 'markPrice': undefined,
861
+ 'side': this.safeString(position, 'holdSide'),
862
+ 'hedged': hedged,
863
+ 'timestamp': timestamp,
864
+ 'datetime': this.iso8601(timestamp),
865
+ 'maintenanceMargin': undefined,
866
+ 'maintenanceMarginPercentage': this.safeNumber(position, 'keepMarginRate'),
867
+ 'collateral': undefined,
868
+ 'initialMargin': undefined,
869
+ 'initialMarginPercentage': undefined,
870
+ 'leverage': this.safeNumber(position, 'leverage'),
871
+ 'marginRatio': this.safeNumber(position, 'marginRate'),
872
+ });
873
+ }
874
+ async watchOrders(symbol = undefined, since = undefined, limit = undefined, params = {}) {
875
+ /**
876
+ * @method
877
+ * @name bitget#watchOrders
878
+ * @description watches information on multiple orders made by the user
879
+ * @see https://www.bitget.com/api-doc/spot/websocket/private/Order-Channel
880
+ * @see https://www.bitget.com/api-doc/contract/websocket/private/Order-Channel
881
+ * @see https://www.bitget.com/api-doc/contract/websocket/private/Plan-Order-Channel
882
+ * @see https://www.bitget.com/api-doc/margin/cross/websocket/private/Cross-Orders
883
+ * @see https://www.bitget.com/api-doc/margin/isolated/websocket/private/Isolate-Orders
884
+ * @param {string} symbol unified market symbol of the market orders were made in
885
+ * @param {int} [since] the earliest time in ms to fetch orders for
886
+ * @param {int} [limit] the maximum number of order structures to retrieve
887
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
888
+ * @param {boolean} [params.stop] *contract only* set to true for watching trigger orders
889
+ * @param {string} [params.marginMode] 'isolated' or 'cross' for watching spot margin orders
890
+ * @returns {object[]} a list of [order structures]{@link https://docs.ccxt.com/#/?id=order-structure
891
+ */
892
+ await this.loadMarkets();
893
+ let market = undefined;
894
+ let marketId = undefined;
895
+ const isStop = this.safeValue(params, 'stop', false);
896
+ params = this.omit(params, 'stop');
897
+ let messageHash = (isStop) ? 'triggerOrder' : 'order';
898
+ let subscriptionHash = 'order:trades';
899
+ if (symbol !== undefined) {
900
+ market = this.market(symbol);
901
+ symbol = market['symbol'];
902
+ marketId = market['id'];
903
+ messageHash = messageHash + ':' + symbol;
904
+ }
905
+ let type = undefined;
906
+ [type, params] = this.handleMarketTypeAndParams('watchOrders', market, params);
907
+ if ((type === 'spot') && (symbol === undefined)) {
908
+ throw new errors.ArgumentsRequired(this.id + ' watchOrders requires a symbol argument for ' + type + ' markets.');
909
+ }
910
+ if (isStop && type === 'spot') {
911
+ throw new errors.NotSupported(this.id + ' watchOrders does not support stop orders for ' + type + ' markets.');
912
+ }
913
+ let instType = undefined;
914
+ [instType, params] = this.getInstType(market, params);
915
+ if (type === 'spot') {
916
+ subscriptionHash = subscriptionHash + ':' + symbol;
917
+ }
918
+ if (isStop) {
919
+ subscriptionHash = subscriptionHash + ':stop'; // we don't want to re-use the same subscription hash for stop orders
920
+ }
921
+ const instId = (type === 'spot') ? marketId : 'default'; // different from other streams here the 'rest' id is required for spot markets, contract markets require default here
922
+ let channel = isStop ? 'orders-algo' : 'orders';
923
+ let marginMode = undefined;
924
+ [marginMode, params] = this.handleMarginModeAndParams('watchOrders', params);
925
+ if (marginMode !== undefined) {
926
+ instType = 'MARGIN';
927
+ if (marginMode === 'isolated') {
928
+ channel = 'orders-isolated';
929
+ }
930
+ else {
931
+ channel = 'orders-crossed';
932
+ }
933
+ }
934
+ const args = {
935
+ 'instType': instType,
936
+ 'channel': channel,
937
+ 'instId': instId,
938
+ };
939
+ const orders = await this.watchPrivate(messageHash, subscriptionHash, args, params);
940
+ if (this.newUpdates) {
941
+ limit = orders.getLimit(symbol, limit);
942
+ }
943
+ return this.filterBySymbolSinceLimit(orders, symbol, since, limit, true);
944
+ }
945
+ handleOrder(client, message, subscription = undefined) {
946
+ //
947
+ // spot
948
+ //
949
+ // {
950
+ // "action": "snapshot",
951
+ // "arg": { "instType": "SPOT", "channel": "orders", "instId": "BTCUSDT" },
952
+ // "data": [
953
+ // {
954
+ // "instId": "BTCUSDT",
955
+ // "orderId": "1116512721422422017",
956
+ // "clientOid": "798d1425-d31d-4ada-a51b-ec701e00a1d9",
957
+ // "price": "35000.00",
958
+ // "size": "7.0000",
959
+ // "notional": "7.000000",
960
+ // "orderType": "limit",
961
+ // "force": "gtc",
962
+ // "side": "buy",
963
+ // "accBaseVolume": "0.0000",
964
+ // "priceAvg": "0.00",
965
+ // "status": "live",
966
+ // "cTime": "1701923297267",
967
+ // "uTime": "1701923297267",
968
+ // "feeDetail": [],
969
+ // "enterPointSource": "WEB"
970
+ // }
971
+ // ],
972
+ // "ts": 1701923297285
973
+ // }
974
+ //
975
+ // contract
976
+ //
977
+ // {
978
+ // "action": "snapshot",
979
+ // "arg": { "instType": "USDT-FUTURES", "channel": "orders", "instId": "default" },
980
+ // "data": [
981
+ // {
982
+ // "accBaseVolume": "0",
983
+ // "cTime": "1701920553759",
984
+ // "clientOid": "1116501214318198793",
985
+ // "enterPointSource": "WEB",
986
+ // "feeDetail": [{
987
+ // "feeCoin": "USDT",
988
+ // "fee": "-0.162003"
989
+ // }],
990
+ // "force": "gtc",
991
+ // "instId": "BTCUSDT",
992
+ // "leverage": "20",
993
+ // "marginCoin": "USDT",
994
+ // "marginMode": "isolated",
995
+ // "notionalUsd": "105",
996
+ // "orderId": "1116501214293032964",
997
+ // "orderType": "limit",
998
+ // "posMode": "hedge_mode",
999
+ // "posSide": "long",
1000
+ // "price": "35000",
1001
+ // "reduceOnly": "no",
1002
+ // "side": "buy",
1003
+ // "size": "0.003",
1004
+ // "status": "canceled",
1005
+ // "tradeSide": "open",
1006
+ // "uTime": "1701920595866"
1007
+ // }
1008
+ // ],
1009
+ // "ts": 1701920595879
1010
+ // }
1011
+ //
1012
+ // trigger
1013
+ //
1014
+ // {
1015
+ // "action": "snapshot",
1016
+ // "arg": {
1017
+ // "instType": "USDT-FUTURES",
1018
+ // "channel": "orders-algo",
1019
+ // "instId": "default"
1020
+ // },
1021
+ // "data": [
1022
+ // {
1023
+ // "instId": "BTCUSDT",
1024
+ // "orderId": "1116508960750899201",
1025
+ // "clientOid": "1116508960750899200",
1026
+ // "triggerPrice": "35000.000000000",
1027
+ // "triggerType": "mark_price",
1028
+ // "triggerTime": "1701922464373",
1029
+ // "planType": "pl",
1030
+ // "price": "35000.000000000",
1031
+ // "size": "0.001000000",
1032
+ // "actualSize": "0.000000000",
1033
+ // "orderType": "limit",
1034
+ // "side": "buy",
1035
+ // "tradeSide": "open",
1036
+ // "posSide": "long",
1037
+ // "marginCoin": "USDT",
1038
+ // "status": "cancelled",
1039
+ // "posMode": "hedge_mode",
1040
+ // "enterPointSource": "api",
1041
+ // "stopSurplusTriggerType": "fill_price",
1042
+ // "stopLossTriggerType": "fill_price",
1043
+ // "cTime": "1701922400653",
1044
+ // "uTime": "1701922464373"
1045
+ // }
1046
+ // ],
1047
+ // "ts": 1701922464417
1048
+ // }
1049
+ //
1050
+ // isolated and cross margin
1051
+ //
1052
+ // {
1053
+ // "action": "snapshot",
1054
+ // "arg": { "instType": "MARGIN", "channel": "orders-crossed", "instId": "BTCUSDT" },
1055
+ // "data": [
1056
+ // {
1057
+ // "enterPointSource": "web",
1058
+ // "force": "gtc",
1059
+ // "orderType": "limit",
1060
+ // "price": "35000.000000000",
1061
+ // "quoteSize": "10.500000000",
1062
+ // "side": "buy",
1063
+ // "status": "live",
1064
+ // "baseSize": "0.000300000",
1065
+ // "cTime": "1701923982427",
1066
+ // "clientOid": "4902047879864dc980c4840e9906db4e",
1067
+ // "fillPrice": "0.000000000",
1068
+ // "baseVolume": "0.000000000",
1069
+ // "fillTotalAmount": "0.000000000",
1070
+ // "loanType": "auto-loan-and-repay",
1071
+ // "orderId": "1116515595178356737"
1072
+ // }
1073
+ // ],
1074
+ // "ts": 1701923982497
1075
+ // }
1076
+ //
1077
+ const arg = this.safeValue(message, 'arg', {});
1078
+ const channel = this.safeString(arg, 'channel');
1079
+ const instType = this.safeString(arg, 'instType');
1080
+ let marketType = undefined;
1081
+ if (instType === 'SPOT') {
1082
+ marketType = 'spot';
1083
+ }
1084
+ else if (instType === 'MARGIN') {
1085
+ marketType = 'spot';
1086
+ }
1087
+ else {
1088
+ marketType = 'contract';
1089
+ }
1090
+ const data = this.safeValue(message, 'data', []);
1091
+ if (this.orders === undefined) {
1092
+ const limit = this.safeInteger(this.options, 'ordersLimit', 1000);
1093
+ this.orders = new Cache.ArrayCacheBySymbolById(limit);
1094
+ this.triggerOrders = new Cache.ArrayCacheBySymbolById(limit);
1095
+ }
1096
+ const stored = (channel === 'ordersAlgo') ? this.triggerOrders : this.orders;
1097
+ const messageHash = (channel === 'ordersAlgo') ? 'triggerOrder' : 'order';
1098
+ const marketSymbols = {};
1099
+ for (let i = 0; i < data.length; i++) {
1100
+ const order = data[i];
1101
+ const marketId = this.safeString(order, 'instId');
1102
+ const market = this.safeMarket(marketId, undefined, undefined, marketType);
1103
+ const parsed = this.parseWsOrder(order, market);
1104
+ stored.append(parsed);
1105
+ const symbol = parsed['symbol'];
1106
+ marketSymbols[symbol] = true;
1107
+ }
1108
+ const keys = Object.keys(marketSymbols);
1109
+ for (let i = 0; i < keys.length; i++) {
1110
+ const symbol = keys[i];
1111
+ const innerMessageHash = messageHash + ':' + symbol;
1112
+ client.resolve(stored, innerMessageHash);
1113
+ }
1114
+ client.resolve(stored, messageHash);
1115
+ }
1116
+ parseWsOrder(order, market = undefined) {
1117
+ //
1118
+ // spot
1119
+ //
1120
+ // {
1121
+ // "instId": "BTCUSDT",
1122
+ // "orderId": "1116512721422422017",
1123
+ // "clientOid": "798d1425-d31d-4ada-a51b-ec701e00a1d9",
1124
+ // "price": "35000.00",
1125
+ // "size": "7.0000",
1126
+ // "notional": "7.000000",
1127
+ // "orderType": "limit",
1128
+ // "force": "gtc",
1129
+ // "side": "buy",
1130
+ // "accBaseVolume": "0.0000",
1131
+ // "priceAvg": "0.00",
1132
+ // "status": "live",
1133
+ // "cTime": "1701923297267",
1134
+ // "uTime": "1701923297267",
1135
+ // "feeDetail": [],
1136
+ // "enterPointSource": "WEB"
1137
+ // }
1138
+ //
1139
+ // contract
1140
+ //
1141
+ // {
1142
+ // "accBaseVolume": "0",
1143
+ // "cTime": "1701920553759",
1144
+ // "clientOid": "1116501214318198793",
1145
+ // "enterPointSource": "WEB",
1146
+ // "feeDetail": [{
1147
+ // "feeCoin": "USDT",
1148
+ // "fee": "-0.162003"
1149
+ // }],
1150
+ // "force": "gtc",
1151
+ // "instId": "BTCUSDT",
1152
+ // "leverage": "20",
1153
+ // "marginCoin": "USDT",
1154
+ // "marginMode": "isolated",
1155
+ // "notionalUsd": "105",
1156
+ // "orderId": "1116501214293032964",
1157
+ // "orderType": "limit",
1158
+ // "posMode": "hedge_mode",
1159
+ // "posSide": "long",
1160
+ // "price": "35000",
1161
+ // "reduceOnly": "no",
1162
+ // "side": "buy",
1163
+ // "size": "0.003",
1164
+ // "status": "canceled",
1165
+ // "tradeSide": "open",
1166
+ // "uTime": "1701920595866"
1167
+ // }
1168
+ //
1169
+ // trigger
1170
+ //
1171
+ // {
1172
+ // "instId": "BTCUSDT",
1173
+ // "orderId": "1116508960750899201",
1174
+ // "clientOid": "1116508960750899200",
1175
+ // "triggerPrice": "35000.000000000",
1176
+ // "triggerType": "mark_price",
1177
+ // "triggerTime": "1701922464373",
1178
+ // "planType": "pl",
1179
+ // "price": "35000.000000000",
1180
+ // "size": "0.001000000",
1181
+ // "actualSize": "0.000000000",
1182
+ // "orderType": "limit",
1183
+ // "side": "buy",
1184
+ // "tradeSide": "open",
1185
+ // "posSide": "long",
1186
+ // "marginCoin": "USDT",
1187
+ // "status": "cancelled",
1188
+ // "posMode": "hedge_mode",
1189
+ // "enterPointSource": "api",
1190
+ // "stopSurplusTriggerType": "fill_price",
1191
+ // "stopLossTriggerType": "fill_price",
1192
+ // "cTime": "1701922400653",
1193
+ // "uTime": "1701922464373"
1194
+ // }
1195
+ //
1196
+ // isolated and cross margin
1197
+ //
1198
+ // {
1199
+ // "enterPointSource": "web",
1200
+ // "force": "gtc",
1201
+ // "orderType": "limit",
1202
+ // "price": "35000.000000000",
1203
+ // "quoteSize": "10.500000000",
1204
+ // "side": "buy",
1205
+ // "status": "live",
1206
+ // "baseSize": "0.000300000",
1207
+ // "cTime": "1701923982427",
1208
+ // "clientOid": "4902047879864dc980c4840e9906db4e",
1209
+ // "fillPrice": "0.000000000",
1210
+ // "baseVolume": "0.000000000",
1211
+ // "fillTotalAmount": "0.000000000",
1212
+ // "loanType": "auto-loan-and-repay",
1213
+ // "orderId": "1116515595178356737"
1214
+ // }
1215
+ //
1216
+ const marketId = this.safeString(order, 'instId');
1217
+ market = this.safeMarket(marketId, market);
1218
+ const timestamp = this.safeInteger(order, 'cTime');
1219
+ const symbol = market['symbol'];
1220
+ const rawStatus = this.safeString(order, 'status');
1221
+ const orderFee = this.safeValue(order, 'feeDetail', []);
1222
+ const fee = this.safeValue(orderFee, 0);
1223
+ const feeAmount = this.safeString(fee, 'fee');
1224
+ let feeObject = undefined;
1225
+ if (feeAmount !== undefined) {
1226
+ const feeCurrency = this.safeString(fee, 'feeCoin');
1227
+ feeObject = {
1228
+ 'cost': Precise["default"].stringAbs(feeAmount),
1229
+ 'currency': this.safeCurrencyCode(feeCurrency),
1230
+ };
1231
+ }
1232
+ const triggerPrice = this.safeNumber(order, 'triggerPrice');
1233
+ return this.safeOrder({
1234
+ 'info': order,
1235
+ 'symbol': symbol,
1236
+ 'id': this.safeString(order, 'orderId'),
1237
+ 'clientOrderId': this.safeString(order, 'clientOid'),
1238
+ 'timestamp': timestamp,
1239
+ 'datetime': this.iso8601(timestamp),
1240
+ 'lastTradeTimestamp': this.safeInteger(order, 'uTime'),
1241
+ 'type': this.safeString(order, 'orderType'),
1242
+ 'timeInForce': this.safeStringUpper(order, 'force'),
1243
+ 'postOnly': undefined,
1244
+ 'side': this.safeString(order, 'side'),
1245
+ 'price': this.safeString(order, 'price'),
1246
+ 'stopPrice': triggerPrice,
1247
+ 'triggerPrice': triggerPrice,
1248
+ 'amount': this.safeString2(order, 'size', 'baseSize'),
1249
+ 'cost': this.safeStringN(order, ['notional', 'notionalUsd', 'quoteSize']),
1250
+ 'average': this.omitZero(this.safeString2(order, 'priceAvg', 'fillPrice')),
1251
+ 'filled': this.safeString2(order, 'accBaseVolume', 'baseVolume'),
1252
+ 'remaining': undefined,
1253
+ 'status': this.parseWsOrderStatus(rawStatus),
1254
+ 'fee': feeObject,
1255
+ 'trades': undefined,
1256
+ }, market);
1257
+ }
1258
+ parseWsOrderStatus(status) {
1259
+ const statuses = {
1260
+ 'live': 'open',
1261
+ 'partially_filled': 'open',
1262
+ 'filled': 'closed',
1263
+ 'cancelled': 'canceled',
1264
+ 'not_trigger': 'open',
1265
+ };
1266
+ return this.safeString(statuses, status, status);
1267
+ }
1268
+ async watchMyTrades(symbol = undefined, since = undefined, limit = undefined, params = {}) {
1269
+ /**
1270
+ * @method
1271
+ * @name bitget#watchMyTrades
1272
+ * @description watches trades made by the user
1273
+ * @see https://www.bitget.com/api-doc/contract/websocket/private/Order-Channel
1274
+ * @param {str} symbol unified market symbol
1275
+ * @param {int} [since] the earliest time in ms to fetch trades for
1276
+ * @param {int} [limit] the maximum number of trades structures to retrieve
1277
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1278
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=trade-structure}
1279
+ */
1280
+ // only contracts stream provides the trade info consistently in between order updates
1281
+ // the spot stream only provides on limit orders updates so we can't support it for spot
1282
+ await this.loadMarkets();
1283
+ let market = undefined;
1284
+ let messageHash = 'myTrades';
1285
+ if (symbol !== undefined) {
1286
+ market = this.market(symbol);
1287
+ symbol = market['symbol'];
1288
+ messageHash = messageHash + ':' + symbol;
1289
+ }
1290
+ let type = undefined;
1291
+ [type, params] = this.handleMarketTypeAndParams('watchMyTrades', market, params);
1292
+ if (type === 'spot') {
1293
+ throw new errors.NotSupported(this.id + ' watchMyTrades is not supported for ' + type + ' markets.');
1294
+ }
1295
+ let instType = undefined;
1296
+ [instType, params] = this.getInstType(market, params);
1297
+ const subscriptionHash = 'order:trades';
1298
+ const args = {
1299
+ 'instType': instType,
1300
+ 'channel': 'orders',
1301
+ 'instId': 'default',
1302
+ };
1303
+ const trades = await this.watchPrivate(messageHash, subscriptionHash, args, params);
1304
+ if (this.newUpdates) {
1305
+ limit = trades.getLimit(symbol, limit);
1306
+ }
1307
+ return this.filterBySymbolSinceLimit(trades, symbol, since, limit, true);
1308
+ }
1309
+ handleMyTrades(client, message) {
1310
+ //
1311
+ // order and trade mixin (contract)
1312
+ //
1313
+ // {
1314
+ // "accBaseVolume": "0",
1315
+ // "cTime": "1701920553759",
1316
+ // "clientOid": "1116501214318198793",
1317
+ // "enterPointSource": "WEB",
1318
+ // "feeDetail": [{
1319
+ // "feeCoin": "USDT",
1320
+ // "fee": "-0.162003"
1321
+ // }],
1322
+ // "force": "gtc",
1323
+ // "instId": "BTCUSDT",
1324
+ // "leverage": "20",
1325
+ // "marginCoin": "USDT",
1326
+ // "marginMode": "isolated",
1327
+ // "notionalUsd": "105",
1328
+ // "orderId": "1116501214293032964",
1329
+ // "orderType": "limit",
1330
+ // "posMode": "hedge_mode",
1331
+ // "posSide": "long",
1332
+ // "price": "35000",
1333
+ // "reduceOnly": "no",
1334
+ // "side": "buy",
1335
+ // "size": "0.003",
1336
+ // "status": "canceled",
1337
+ // "tradeSide": "open",
1338
+ // "uTime": "1701920595866"
1339
+ // }
1340
+ //
1341
+ if (this.myTrades === undefined) {
1342
+ const limit = this.safeInteger(this.options, 'tradesLimit', 1000);
1343
+ this.myTrades = new Cache.ArrayCache(limit);
1344
+ }
1345
+ const stored = this.myTrades;
1346
+ const parsed = this.parseWsMyTrade(message);
1347
+ stored.append(parsed);
1348
+ const symbol = parsed['symbol'];
1349
+ const messageHash = 'myTrades';
1350
+ client.resolve(stored, messageHash);
1351
+ const symbolSpecificMessageHash = 'myTrades:' + symbol;
1352
+ client.resolve(stored, symbolSpecificMessageHash);
1353
+ }
1354
+ parseWsMyTrade(trade, market = undefined) {
1355
+ //
1356
+ // order and trade mixin (contract)
1357
+ //
1358
+ // {
1359
+ // "accBaseVolume": "0",
1360
+ // "cTime": "1701920553759",
1361
+ // "clientOid": "1116501214318198793",
1362
+ // "enterPointSource": "WEB",
1363
+ // "feeDetail": [{
1364
+ // "feeCoin": "USDT",
1365
+ // "fee": "-0.162003"
1366
+ // }],
1367
+ // "force": "gtc",
1368
+ // "instId": "BTCUSDT",
1369
+ // "leverage": "20",
1370
+ // "marginCoin": "USDT",
1371
+ // "marginMode": "isolated",
1372
+ // "notionalUsd": "105",
1373
+ // "orderId": "1116501214293032964",
1374
+ // "orderType": "limit",
1375
+ // "posMode": "hedge_mode",
1376
+ // "posSide": "long",
1377
+ // "price": "35000",
1378
+ // "reduceOnly": "no",
1379
+ // "side": "buy",
1380
+ // "size": "0.003",
1381
+ // "status": "canceled",
1382
+ // "tradeSide": "open",
1383
+ // "uTime": "1701920595866"
1384
+ // }
1385
+ //
1386
+ const marketId = this.safeString(trade, 'instId');
1387
+ market = this.safeMarket(marketId, market, undefined, 'contract');
1388
+ const timestamp = this.safeInteger2(trade, 'uTime', 'cTime');
1389
+ const orderFee = this.safeValue(trade, 'feeDetail', []);
1390
+ const fee = this.safeValue(orderFee, 0);
1391
+ const feeAmount = this.safeString(fee, 'fee');
1392
+ let feeObject = undefined;
1393
+ if (feeAmount !== undefined) {
1394
+ const feeCurrency = this.safeString(fee, 'feeCoin');
1395
+ feeObject = {
1396
+ 'cost': Precise["default"].stringAbs(feeAmount),
1397
+ 'currency': this.safeCurrencyCode(feeCurrency),
1398
+ };
1399
+ }
1400
+ return this.safeTrade({
1401
+ 'info': trade,
1402
+ 'id': undefined,
1403
+ 'order': this.safeString(trade, 'orderId'),
1404
+ 'timestamp': timestamp,
1405
+ 'datetime': this.iso8601(timestamp),
1406
+ 'symbol': market['symbol'],
1407
+ 'type': this.safeString(trade, 'orderType'),
1408
+ 'side': this.safeString(trade, 'side'),
1409
+ 'takerOrMaker': undefined,
1410
+ 'price': this.safeString(trade, 'price'),
1411
+ 'amount': this.safeString(trade, 'size'),
1412
+ 'cost': this.safeString(trade, 'notionalUsd'),
1413
+ 'fee': feeObject,
1414
+ }, market);
1415
+ }
1416
+ async watchBalance(params = {}) {
1417
+ /**
1418
+ * @method
1419
+ * @name bitget#watchBalance
1420
+ * @description watch balance and get the amount of funds available for trading or funds locked in orders
1421
+ * @see https://www.bitget.com/api-doc/spot/websocket/private/Account-Channel
1422
+ * @see https://www.bitget.com/api-doc/contract/websocket/private/Account-Channel
1423
+ * @see https://www.bitget.com/api-doc/margin/cross/websocket/private/Margin-Cross-Account-Assets
1424
+ * @see https://www.bitget.com/api-doc/margin/isolated/websocket/private/Margin-isolated-account-assets
1425
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1426
+ * @param {str} [params.type] spot or contract if not provided this.options['defaultType'] is used
1427
+ * @param {string} [params.instType] one of 'SPOT', 'MARGIN', 'USDT-FUTURES', 'USDC-FUTURES', 'COIN-FUTURES', 'SUSDT-FUTURES', 'SUSDC-FUTURES' or 'SCOIN-FUTURES'
1428
+ * @param {string} [params.marginMode] 'isolated' or 'cross' for watching spot margin balances
1429
+ * @returns {object} a [balance structure]{@link https://docs.ccxt.com/#/?id=balance-structure}
1430
+ */
1431
+ let type = undefined;
1432
+ [type, params] = this.handleMarketTypeAndParams('watchBalance', undefined, params);
1433
+ let marginMode = undefined;
1434
+ [marginMode, params] = this.handleMarginModeAndParams('watchBalance', params);
1435
+ let instType = undefined;
1436
+ let channel = 'account';
1437
+ if ((type === 'swap') || (type === 'future')) {
1438
+ instType = 'USDT-FUTURES';
1439
+ }
1440
+ else if (marginMode !== undefined) {
1441
+ instType = 'MARGIN';
1442
+ if (marginMode === 'isolated') {
1443
+ channel = 'account-isolated';
1444
+ }
1445
+ else {
1446
+ channel = 'account-crossed';
1447
+ }
1448
+ }
1449
+ else {
1450
+ instType = 'SPOT';
1451
+ }
1452
+ [instType, params] = this.handleOptionAndParams(params, 'watchBalance', 'instType', instType);
1453
+ const args = {
1454
+ 'instType': instType,
1455
+ 'channel': channel,
1456
+ 'coin': 'default',
1457
+ };
1458
+ const messageHash = 'balance:' + instType.toLowerCase();
1459
+ return await this.watchPrivate(messageHash, messageHash, args, params);
1460
+ }
1461
+ handleBalance(client, message) {
1462
+ //
1463
+ // spot
1464
+ //
1465
+ // {
1466
+ // "action": "snapshot",
1467
+ // "arg": { "instType": "SPOT", "channel": "account", "coin": "default" },
1468
+ // "data": [
1469
+ // {
1470
+ // "coin": "USDT",
1471
+ // "available": "19.1430952856087",
1472
+ // "frozen": "7",
1473
+ // "locked": "0",
1474
+ // "limitAvailable": "0",
1475
+ // "uTime": "1701931970487"
1476
+ // },
1477
+ // ],
1478
+ // "ts": 1701931970487
1479
+ // }
1480
+ //
1481
+ // swap
1482
+ //
1483
+ // {
1484
+ // "action": "snapshot",
1485
+ // "arg": { "instType": "USDT-FUTURES", "channel": "account", "coin": "default" },
1486
+ // "data": [
1487
+ // {
1488
+ // "marginCoin": "USDT",
1489
+ // "frozen": "5.36581500",
1490
+ // "available": "26.14309528",
1491
+ // "maxOpenPosAvailable": "20.77728028",
1492
+ // "maxTransferOut": "20.77728028",
1493
+ // "equity": "26.14309528",
1494
+ // "usdtEquity": "26.143095285166"
1495
+ // }
1496
+ // ],
1497
+ // "ts": 1701932570822
1498
+ // }
1499
+ //
1500
+ // margin
1501
+ //
1502
+ // {
1503
+ // "action": "snapshot",
1504
+ // "arg": { "instType": "MARGIN", "channel": "account-crossed", "coin": "default" },
1505
+ // "data": [
1506
+ // {
1507
+ // "uTime": "1701933110544",
1508
+ // "id": "1096916799926710272",
1509
+ // "coin": "USDT",
1510
+ // "available": "16.24309528",
1511
+ // "borrow": "0.00000000",
1512
+ // "frozen": "9.90000000",
1513
+ // "interest": "0.00000000",
1514
+ // "coupon": "0.00000000"
1515
+ // }
1516
+ // ],
1517
+ // "ts": 1701933110544
1518
+ // }
1519
+ //
1520
+ const data = this.safeValue(message, 'data', []);
1521
+ for (let i = 0; i < data.length; i++) {
1522
+ const rawBalance = data[i];
1523
+ const currencyId = this.safeString2(rawBalance, 'coin', 'marginCoin');
1524
+ const code = this.safeCurrencyCode(currencyId);
1525
+ const account = (code in this.balance) ? this.balance[code] : this.account();
1526
+ const borrow = this.safeString(rawBalance, 'borrow');
1527
+ if (borrow !== undefined) {
1528
+ const interest = this.safeString(rawBalance, 'interest');
1529
+ account['debt'] = Precise["default"].stringAdd(borrow, interest);
1530
+ }
1531
+ const freeQuery = ('maxTransferOut' in rawBalance) ? 'maxTransferOut' : 'available';
1532
+ account['free'] = this.safeString(rawBalance, freeQuery);
1533
+ account['total'] = this.safeString(rawBalance, 'equity');
1534
+ account['used'] = this.safeString(rawBalance, 'frozen');
1535
+ this.balance[code] = account;
1536
+ }
1537
+ this.balance = this.safeBalance(this.balance);
1538
+ const arg = this.safeValue(message, 'arg');
1539
+ const instType = this.safeStringLower(arg, 'instType');
1540
+ const messageHash = 'balance:' + instType;
1541
+ client.resolve(this.balance, messageHash);
1542
+ }
1543
+ async watchPublic(messageHash, args, params = {}) {
1544
+ const url = this.urls['api']['ws']['public'];
1545
+ const request = {
1546
+ 'op': 'subscribe',
1547
+ 'args': [args],
1548
+ };
1549
+ const message = this.extend(request, params);
1550
+ return await this.watch(url, messageHash, message, messageHash);
1551
+ }
1552
+ async watchPublicMultiple(messageHashes, argsArray, params = {}) {
1553
+ const url = this.urls['api']['ws']['public'];
1554
+ const request = {
1555
+ 'op': 'subscribe',
1556
+ 'args': argsArray,
1557
+ };
1558
+ const message = this.extend(request, params);
1559
+ return await this.watchMultiple(url, messageHashes, message, messageHashes);
1560
+ }
1561
+ async authenticate(params = {}) {
1562
+ this.checkRequiredCredentials();
1563
+ const url = this.urls['api']['ws']['private'];
1564
+ const client = this.client(url);
1565
+ const messageHash = 'authenticated';
1566
+ const future = client.future(messageHash);
1567
+ const authenticated = this.safeValue(client.subscriptions, messageHash);
1568
+ if (authenticated === undefined) {
1569
+ const timestamp = this.seconds().toString();
1570
+ const auth = timestamp + 'GET' + '/user/verify';
1571
+ const signature = this.hmac(this.encode(auth), this.encode(this.secret), sha256.sha256, 'base64');
1572
+ const operation = 'login';
1573
+ const request = {
1574
+ 'op': operation,
1575
+ 'args': [
1576
+ {
1577
+ 'apiKey': this.apiKey,
1578
+ 'passphrase': this.password,
1579
+ 'timestamp': timestamp,
1580
+ 'sign': signature,
1581
+ },
1582
+ ],
1583
+ };
1584
+ const message = this.extend(request, params);
1585
+ this.watch(url, messageHash, message, messageHash);
1586
+ }
1587
+ return future;
1588
+ }
1589
+ async watchPrivate(messageHash, subscriptionHash, args, params = {}) {
1590
+ await this.authenticate();
1591
+ const url = this.urls['api']['ws']['private'];
1592
+ const request = {
1593
+ 'op': 'subscribe',
1594
+ 'args': [args],
1595
+ };
1596
+ const message = this.extend(request, params);
1597
+ return await this.watch(url, messageHash, message, subscriptionHash);
1598
+ }
1599
+ handleAuthenticate(client, message) {
1600
+ //
1601
+ // { event: "login", code: 0 }
1602
+ //
1603
+ const messageHash = 'authenticated';
1604
+ const future = this.safeValue(client.futures, messageHash);
1605
+ future.resolve(true);
1606
+ }
1607
+ handleErrorMessage(client, message) {
1608
+ //
1609
+ // { event: "error", code: 30015, msg: "Invalid sign" }
1610
+ //
1611
+ const event = this.safeString(message, 'event');
1612
+ try {
1613
+ if (event === 'error') {
1614
+ const code = this.safeString(message, 'code');
1615
+ const feedback = this.id + ' ' + this.json(message);
1616
+ this.throwExactlyMatchedException(this.exceptions['ws']['exact'], code, feedback);
1617
+ const msg = this.safeString(message, 'msg', '');
1618
+ this.throwBroadlyMatchedException(this.exceptions['ws']['broad'], msg, feedback);
1619
+ throw new errors.ExchangeError(feedback);
1620
+ }
1621
+ return false;
1622
+ }
1623
+ catch (e) {
1624
+ if (e instanceof errors.AuthenticationError) {
1625
+ const messageHash = 'authenticated';
1626
+ client.reject(e, messageHash);
1627
+ if (messageHash in client.subscriptions) {
1628
+ delete client.subscriptions[messageHash];
1629
+ }
1630
+ }
1631
+ else {
1632
+ // Note: if error happens on a subscribe event, user will have to close exchange to resubscribe. Issue #19041
1633
+ client.reject(e);
1634
+ }
1635
+ return true;
1636
+ }
1637
+ }
1638
+ handleMessage(client, message) {
1639
+ //
1640
+ // {
1641
+ // "action": "snapshot",
1642
+ // "arg": { instType: 'SPOT', channel: "ticker", instId: "BTCUSDT" },
1643
+ // "data": [
1644
+ // {
1645
+ // "instId": "BTCUSDT",
1646
+ // "last": "21150.53",
1647
+ // "open24h": "20759.65",
1648
+ // "high24h": "21202.29",
1649
+ // "low24h": "20518.82",
1650
+ // "bestBid": "21150.500000",
1651
+ // "bestAsk": "21150.600000",
1652
+ // "baseVolume": "25402.1961",
1653
+ // "quoteVolume": "530452554.2156",
1654
+ // "ts": 1656408934044,
1655
+ // "labeId": 0
1656
+ // }
1657
+ // ]
1658
+ // }
1659
+ // pong message
1660
+ // "pong"
1661
+ //
1662
+ // login
1663
+ //
1664
+ // { event: "login", code: 0 }
1665
+ //
1666
+ // subscribe
1667
+ //
1668
+ // {
1669
+ // "event": "subscribe",
1670
+ // "arg": { instType: 'SPOT', channel: "account", instId: "default" }
1671
+ // }
1672
+ //
1673
+ if (this.handleErrorMessage(client, message)) {
1674
+ return;
1675
+ }
1676
+ const content = this.safeString(message, 'message');
1677
+ if (content === 'pong') {
1678
+ this.handlePong(client, message);
1679
+ return;
1680
+ }
1681
+ if (message === 'pong') {
1682
+ this.handlePong(client, message);
1683
+ return;
1684
+ }
1685
+ const event = this.safeString(message, 'event');
1686
+ if (event === 'login') {
1687
+ this.handleAuthenticate(client, message);
1688
+ return;
1689
+ }
1690
+ if (event === 'subscribe') {
1691
+ this.handleSubscriptionStatus(client, message);
1692
+ return;
1693
+ }
1694
+ const methods = {
1695
+ 'ticker': this.handleTicker,
1696
+ 'trade': this.handleTrades,
1697
+ 'orders': this.handleOrder,
1698
+ 'ordersAlgo': this.handleOrder,
1699
+ 'account': this.handleBalance,
1700
+ 'positions': this.handlePositions,
1701
+ };
1702
+ const arg = this.safeValue(message, 'arg', {});
1703
+ const topic = this.safeValue(arg, 'channel', '');
1704
+ const method = this.safeValue(methods, topic);
1705
+ if (method !== undefined) {
1706
+ method.call(this, client, message);
1707
+ }
1708
+ if (topic.indexOf('candle') >= 0) {
1709
+ this.handleOHLCV(client, message);
1710
+ }
1711
+ if (topic.indexOf('books') >= 0) {
1712
+ this.handleOrderBook(client, message);
1713
+ }
1714
+ }
1715
+ ping(client) {
1716
+ return 'ping';
1717
+ }
1718
+ handlePong(client, message) {
1719
+ client.lastPong = this.milliseconds();
1720
+ return message;
1721
+ }
1722
+ handleSubscriptionStatus(client, message) {
1723
+ //
1724
+ // {
1725
+ // "event": "subscribe",
1726
+ // "arg": { instType: 'SPOT', channel: "account", instId: "default" }
1727
+ // }
1728
+ //
1729
+ return message;
1730
+ }
1731
+ }
1732
+
1733
+ module.exports = bitget;