ccxt 4.5.39 → 4.5.41

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 (138) hide show
  1. package/README.md +6 -5
  2. package/dist/ccxt.browser.min.js +18 -18
  3. package/dist/cjs/ccxt.js +6 -1
  4. package/dist/cjs/src/abstract/lighter.js +11 -0
  5. package/dist/cjs/src/ascendex.js +73 -1
  6. package/dist/cjs/src/base/Exchange.js +211 -22
  7. package/dist/cjs/src/base/functions/generic.js +1 -0
  8. package/dist/cjs/src/base/functions/io.js +160 -0
  9. package/dist/cjs/src/base/functions.js +6 -0
  10. package/dist/cjs/src/base/ws/Client.js +1 -0
  11. package/dist/cjs/src/base/ws/WsClient.js +1 -0
  12. package/dist/cjs/src/binance.js +143 -0
  13. package/dist/cjs/src/bingx.js +150 -123
  14. package/dist/cjs/src/bitmart.js +20 -6
  15. package/dist/cjs/src/bitmex.js +436 -0
  16. package/dist/cjs/src/blofin.js +86 -1
  17. package/dist/cjs/src/bybit.js +135 -0
  18. package/dist/cjs/src/coinspot.js +7 -2
  19. package/dist/cjs/src/delta.js +367 -0
  20. package/dist/cjs/src/gate.js +11 -4
  21. package/dist/cjs/src/gemini.js +76 -1
  22. package/dist/cjs/src/htx.js +266 -3
  23. package/dist/cjs/src/hyperliquid.js +20 -7
  24. package/dist/cjs/src/independentreserve.js +7 -7
  25. package/dist/cjs/src/kraken.js +1 -1
  26. package/dist/cjs/src/krakenfutures.js +96 -5
  27. package/dist/cjs/src/kucoin.js +3 -3
  28. package/dist/cjs/src/kucoinfutures.js +121 -0
  29. package/dist/cjs/src/lighter.js +2931 -0
  30. package/dist/cjs/src/mexc.js +9 -2
  31. package/dist/cjs/src/phemex.js +359 -0
  32. package/dist/cjs/src/poloniex.js +5 -0
  33. package/dist/cjs/src/pro/binance.js +2 -2
  34. package/dist/cjs/src/pro/bingx.js +248 -35
  35. package/dist/cjs/src/pro/bitget.js +49 -90
  36. package/dist/cjs/src/pro/bitmart.js +68 -0
  37. package/dist/cjs/src/pro/blofin.js +52 -1
  38. package/dist/cjs/src/pro/coinbaseinternational.js +5 -2
  39. package/dist/cjs/src/pro/defx.js +1 -1
  40. package/dist/cjs/src/pro/kucoinfutures.js +1 -1
  41. package/dist/cjs/src/pro/lighter.js +787 -0
  42. package/dist/cjs/src/pro/mexc.js +73 -1
  43. package/dist/cjs/src/pro/okx.js +7 -4
  44. package/dist/cjs/src/pro/paradex.js +138 -1
  45. package/dist/cjs/src/pro/woo.js +43 -0
  46. package/dist/cjs/src/static_dependencies/ethers/abi-coder.js +1 -0
  47. package/dist/cjs/src/static_dependencies/ethers/address/address.js +1 -0
  48. package/dist/cjs/src/static_dependencies/ethers/coders/abstract-coder.js +1 -0
  49. package/dist/cjs/src/static_dependencies/ethers/coders/address.js +1 -0
  50. package/dist/cjs/src/static_dependencies/ethers/coders/array.js +1 -0
  51. package/dist/cjs/src/static_dependencies/ethers/coders/bytes.js +1 -0
  52. package/dist/cjs/src/static_dependencies/ethers/coders/fixed-bytes.js +1 -0
  53. package/dist/cjs/src/static_dependencies/ethers/coders/number.js +1 -0
  54. package/dist/cjs/src/static_dependencies/ethers/fragments.js +1 -0
  55. package/dist/cjs/src/static_dependencies/ethers/index.js +1 -0
  56. package/dist/cjs/src/static_dependencies/ethers/interface.js +1 -0
  57. package/dist/cjs/src/static_dependencies/ethers/typed.js +1 -0
  58. package/dist/cjs/src/static_dependencies/ethers/utils/index.js +1 -0
  59. package/dist/cjs/src/whitebit.js +118 -16
  60. package/dist/cjs/src/woo.js +103 -3
  61. package/js/ccxt.d.ts +9 -3
  62. package/js/ccxt.js +6 -2
  63. package/js/src/abstract/gemini.d.ts +27 -0
  64. package/js/src/abstract/lighter.d.ts +53 -0
  65. package/js/src/abstract/lighter.js +5 -0
  66. package/js/src/ascendex.d.ts +12 -1
  67. package/js/src/ascendex.js +73 -1
  68. package/js/src/base/Exchange.d.ts +29 -14
  69. package/js/src/base/Exchange.js +216 -23
  70. package/js/src/base/functions/generic.js +1 -0
  71. package/js/src/base/functions/io.d.ts +32 -0
  72. package/js/src/base/functions/io.js +131 -0
  73. package/js/src/base/functions.d.ts +1 -0
  74. package/js/src/base/functions.js +1 -0
  75. package/js/src/base/types.d.ts +9 -0
  76. package/js/src/binance.d.ts +27 -1
  77. package/js/src/binance.js +143 -0
  78. package/js/src/bingx.d.ts +113 -108
  79. package/js/src/bingx.js +150 -123
  80. package/js/src/bitmart.js +20 -6
  81. package/js/src/bitmex.d.ts +50 -1
  82. package/js/src/bitmex.js +436 -0
  83. package/js/src/blofin.d.ts +12 -1
  84. package/js/src/blofin.js +86 -1
  85. package/js/src/bybit.d.ts +12 -1
  86. package/js/src/bybit.js +135 -0
  87. package/js/src/coinspot.js +7 -2
  88. package/js/src/delta.d.ts +12 -1
  89. package/js/src/delta.js +367 -0
  90. package/js/src/gate.d.ts +1 -0
  91. package/js/src/gate.js +11 -4
  92. package/js/src/gemini.d.ts +11 -0
  93. package/js/src/gemini.js +76 -1
  94. package/js/src/htx.d.ts +15 -1
  95. package/js/src/htx.js +266 -3
  96. package/js/src/hyperliquid.js +20 -7
  97. package/js/src/independentreserve.js +7 -7
  98. package/js/src/kraken.js +1 -1
  99. package/js/src/krakenfutures.d.ts +1 -1
  100. package/js/src/krakenfutures.js +96 -5
  101. package/js/src/kucoin.d.ts +3 -3
  102. package/js/src/kucoin.js +3 -3
  103. package/js/src/kucoinfutures.d.ts +12 -1
  104. package/js/src/kucoinfutures.js +121 -0
  105. package/js/src/lighter.d.ts +424 -0
  106. package/js/src/lighter.js +2924 -0
  107. package/js/src/mexc.js +9 -2
  108. package/js/src/phemex.d.ts +16 -1
  109. package/js/src/phemex.js +359 -0
  110. package/js/src/poloniex.js +5 -0
  111. package/js/src/pro/binance.js +2 -2
  112. package/js/src/pro/bingx.d.ts +50 -34
  113. package/js/src/pro/bingx.js +249 -36
  114. package/js/src/pro/bitget.d.ts +6 -6
  115. package/js/src/pro/bitget.js +49 -90
  116. package/js/src/pro/bitmart.d.ts +22 -1
  117. package/js/src/pro/bitmart.js +69 -1
  118. package/js/src/pro/blofin.d.ts +12 -1
  119. package/js/src/pro/blofin.js +52 -1
  120. package/js/src/pro/coinbaseinternational.d.ts +2 -2
  121. package/js/src/pro/coinbaseinternational.js +6 -3
  122. package/js/src/pro/defx.js +1 -1
  123. package/js/src/pro/kucoinfutures.js +1 -1
  124. package/js/src/pro/lighter.d.ts +161 -0
  125. package/js/src/pro/lighter.js +780 -0
  126. package/js/src/pro/mexc.d.ts +22 -1
  127. package/js/src/pro/mexc.js +73 -1
  128. package/js/src/pro/okx.d.ts +4 -4
  129. package/js/src/pro/okx.js +7 -4
  130. package/js/src/pro/paradex.d.ts +23 -1
  131. package/js/src/pro/paradex.js +138 -1
  132. package/js/src/pro/woo.d.ts +12 -1
  133. package/js/src/pro/woo.js +43 -0
  134. package/js/src/whitebit.d.ts +2 -1
  135. package/js/src/whitebit.js +118 -16
  136. package/js/src/woo.d.ts +12 -1
  137. package/js/src/woo.js +103 -3
  138. package/package.json +1 -1
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var bingx$1 = require('../bingx.js');
6
6
  var errors = require('../base/errors.js');
7
+ var Precise = require('../base/Precise.js');
7
8
  var Cache = require('../base/ws/Cache.js');
8
9
 
9
10
  // ---------------------------------------------------------------------------
@@ -24,12 +25,18 @@ class bingx extends bingx$1["default"] {
24
25
  'watchTicker': true,
25
26
  'watchTickers': false,
26
27
  'watchBalance': true,
28
+ 'watchPositions': true,
27
29
  'unWatchOHLCV': true,
28
30
  'unWatchOrderBook': true,
29
31
  'unWatchTicker': true,
30
32
  'unWatchTrades': true,
31
33
  },
32
34
  'urls': {
35
+ 'test': {
36
+ 'ws': {
37
+ 'linear': 'wss://vst-open-api-ws.bingx.com/swap-market',
38
+ },
39
+ },
33
40
  'api': {
34
41
  'ws': {
35
42
  'spot': 'wss://open-api-ws.bingx.com/market',
@@ -73,7 +80,11 @@ class bingx extends bingx$1["default"] {
73
80
  },
74
81
  'watchBalance': {
75
82
  'fetchBalanceSnapshot': true,
76
- 'awaitBalanceSnapshot': false, // whether to wait for the balance snapshot before providing updates
83
+ 'awaitBalanceSnapshot': true, // whether to wait for the balance snapshot before providing updates
84
+ },
85
+ 'watchPositions': {
86
+ 'fetchPositionsSnapshot': true,
87
+ 'awaitPositionsSnapshot': false,
77
88
  },
78
89
  'watchOrderBook': {
79
90
  'depth': 100, // 5, 10, 20, 50, 100
@@ -129,9 +140,9 @@ class bingx extends bingx$1["default"] {
129
140
  * @method
130
141
  * @name bingx#watchTicker
131
142
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
132
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20to%2024-hour%20Price%20Change
133
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
134
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%2024-Hour%20Price%20Change
143
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20Price%20Change
144
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20price%20changes
145
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%2024-Hour%20Price%20Change
135
146
  * @param {string} symbol unified symbol of the market to fetch the ticker for
136
147
  * @param {object} [params] extra parameters specific to the exchange API endpoint
137
148
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
@@ -170,9 +181,9 @@ class bingx extends bingx$1["default"] {
170
181
  * @method
171
182
  * @name bingx#unWatchTicker
172
183
  * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
173
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20to%2024-hour%20Price%20Change
174
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
175
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%2024-Hour%20Price%20Change
184
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20Price%20Change
185
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20price%20changes
186
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%2024-Hour%20Price%20Change
176
187
  * @param {string} symbol unified symbol of the market to fetch the ticker for
177
188
  * @param {object} [params] extra parameters specific to the exchange API endpoint
178
189
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
@@ -337,9 +348,9 @@ class bingx extends bingx$1["default"] {
337
348
  * @method
338
349
  * @name bingx#watchTrades
339
350
  * @description watches information on multiple trades made in a market
340
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscription%20transaction%20by%20transaction
341
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20the%20Latest%20Trade%20Detail
342
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscription%20transaction%20by%20transaction
351
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
352
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20the%20Latest%20Trade%20Detail
353
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
343
354
  * @param {string} symbol unified market symbol of the market orders were made in
344
355
  * @param {int} [since] the earliest time in ms to fetch orders for
345
356
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -391,9 +402,9 @@ class bingx extends bingx$1["default"] {
391
402
  * @method
392
403
  * @name bingx#unWatchTrades
393
404
  * @description unsubscribes from the trades channel
394
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscription%20transaction%20by%20transaction
395
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20the%20Latest%20Trade%20Detail
396
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscription%20transaction%20by%20transaction
405
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
406
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20the%20Latest%20Trade%20Detail
407
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
397
408
  * @param {string} symbol unified symbol of the market to fetch trades for
398
409
  * @param {object} [params] extra parameters specific to the exchange API endpoint
399
410
  * @param {string} [params.name] the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
@@ -521,9 +532,9 @@ class bingx extends bingx$1["default"] {
521
532
  * @method
522
533
  * @name bingx#watchOrderBook
523
534
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
524
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20Market%20Depth%20Data
525
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20Market%20Depth%20Data
526
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Limited%20Depth
535
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20Market%20Depth%20Data
536
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Partial%20Order%20Book%20Depth
537
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Limited%20Depth
527
538
  * @param {string} symbol unified symbol of the market to fetch the order book for
528
539
  * @param {int} [limit] the maximum amount of order book entries to return
529
540
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -579,9 +590,9 @@ class bingx extends bingx$1["default"] {
579
590
  * @method
580
591
  * @name bingx#unWatchOrderBook
581
592
  * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
582
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20Market%20Depth%20Data
583
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20Market%20Depth%20Data
584
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Limited%20Depth
593
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20Market%20Depth%20Data
594
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Partial%20Order%20Book%20Depth
595
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Limited%20Depth
585
596
  * @param {string} symbol unified symbol of the market
586
597
  * @param {object} [params] extra parameters specific to the exchange API endpoint
587
598
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
@@ -853,9 +864,9 @@ class bingx extends bingx$1["default"] {
853
864
  * @method
854
865
  * @name bingx#watchOHLCV
855
866
  * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
856
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#K-line%20Streams
857
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20K-Line%20Data
858
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
867
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/K-line%20Streamst
868
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20K-Line%20Data
869
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
859
870
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
860
871
  * @param {string} timeframe the length of time each candle represents
861
872
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -910,9 +921,9 @@ class bingx extends bingx$1["default"] {
910
921
  * @method
911
922
  * @name bingx#unWatchOHLCV
912
923
  * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
913
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#K-line%20Streams
914
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20K-Line%20Data
915
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
924
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/K-line%20Streamst
925
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20K-Line%20Data
926
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
916
927
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
917
928
  * @param {string} timeframe the length of time each candle represents
918
929
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -936,9 +947,9 @@ class bingx extends bingx$1["default"] {
936
947
  * @method
937
948
  * @name bingx#watchOrders
938
949
  * @description watches information on multiple orders made by the user
939
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20order%20update%20data
940
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Order%20update%20push
941
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Order%20update%20push
950
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/order%20update%20event
951
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Order%20update%20push
952
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Order%20update%20push
942
953
  * @param {string} [symbol] unified market symbol of the market orders are made in
943
954
  * @param {int} [since] the earliest time in ms to watch orders for
944
955
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -999,9 +1010,9 @@ class bingx extends bingx$1["default"] {
999
1010
  * @method
1000
1011
  * @name bingx#watchMyTrades
1001
1012
  * @description watches information on multiple trades made by the user
1002
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20order%20update%20data
1003
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Order%20update%20push
1004
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Order%20update%20push
1013
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/order%20update%20event
1014
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Order%20update%20push
1015
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Order%20update%20push
1005
1016
  * @param {string} [symbol] unified market symbol of the market the trades are made in
1006
1017
  * @param {int} [since] the earliest time in ms to watch trades for
1007
1018
  * @param {int} [limit] the maximum number of trade structures to retrieve
@@ -1062,9 +1073,9 @@ class bingx extends bingx$1["default"] {
1062
1073
  * @method
1063
1074
  * @name bingx#watchBalance
1064
1075
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
1065
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20account%20balance%20push
1066
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
1067
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Account%20balance%20and%20position%20update%20push
1076
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/Subscription%20account%20balance%20push
1077
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Account%20balance%20and%20position%20update%20push
1078
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Account%20balance%20and%20position%20update%20push
1068
1079
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1069
1080
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
1070
1081
  */
@@ -1140,6 +1151,203 @@ class bingx extends bingx$1["default"] {
1140
1151
  client.resolve(this.balance[type], type + ':balance');
1141
1152
  }
1142
1153
  }
1154
+ /**
1155
+ * @method
1156
+ * @name bingx#watchPositions
1157
+ * @description watch all open positions
1158
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
1159
+ * @param {string[]|undefined} [symbols] list of unified market symbols
1160
+ * @param {int} [since] the earliest time in ms to fetch positions for
1161
+ * @param {int} [limit] the maximum number of position structures to retrieve
1162
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1163
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
1164
+ */
1165
+ async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
1166
+ await this.loadMarkets();
1167
+ await this.authenticate();
1168
+ let market = undefined;
1169
+ let messageHash = '';
1170
+ symbols = this.marketSymbols(symbols);
1171
+ if (!this.isEmpty(symbols)) {
1172
+ market = this.getMarketFromSymbols(symbols);
1173
+ messageHash = '::' + symbols.join(',');
1174
+ }
1175
+ let type = undefined;
1176
+ let subType = undefined;
1177
+ [type, params] = this.handleMarketTypeAndParams('watchPositions', market, params);
1178
+ [subType, params] = this.handleSubTypeAndParams('watchPositions', market, params, 'linear');
1179
+ if (type === 'spot') {
1180
+ throw new errors.NotSupported(this.id + ' watchPositions is not supported for spot markets');
1181
+ }
1182
+ if (subType === 'inverse') {
1183
+ throw new errors.NotSupported(this.id + ' watchPositions is not supported for inverse swap markets yet');
1184
+ }
1185
+ const subscriptionHash = 'swap:private';
1186
+ messageHash = 'swap:positions' + messageHash;
1187
+ const baseUrl = this.safeString(this.urls['api']['ws'], subType);
1188
+ const url = baseUrl + '?listenKey=' + this.options['listenKey'];
1189
+ const client = this.client(url);
1190
+ this.setPositionsCache(client, type, symbols);
1191
+ let fetchPositionsSnapshot = undefined;
1192
+ let awaitPositionsSnapshot = undefined;
1193
+ [fetchPositionsSnapshot, params] = this.handleOptionAndParams(params, 'watchPositions', 'fetchPositionsSnapshot', true);
1194
+ [awaitPositionsSnapshot, params] = this.handleOptionAndParams(params, 'watchPositions', 'awaitPositionsSnapshot', false);
1195
+ const uuid = this.uuid();
1196
+ const subscription = {
1197
+ 'unsubscribe': false,
1198
+ 'id': uuid,
1199
+ };
1200
+ if (fetchPositionsSnapshot && awaitPositionsSnapshot && this.positions === undefined) {
1201
+ const snapshot = await client.future(type + ':fetchPositionsSnapshot');
1202
+ return this.filterBySymbolsSinceLimit(snapshot, symbols, since, limit, true);
1203
+ }
1204
+ const newPositions = await this.watch(url, messageHash, undefined, subscriptionHash, subscription);
1205
+ if (this.newUpdates) {
1206
+ return newPositions;
1207
+ }
1208
+ return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
1209
+ }
1210
+ setPositionsCache(client, type, symbols = undefined) {
1211
+ if (this.positions !== undefined) {
1212
+ return;
1213
+ }
1214
+ const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
1215
+ if (fetchPositionsSnapshot) {
1216
+ const messageHash = type + ':fetchPositionsSnapshot';
1217
+ if (!(messageHash in client.futures)) {
1218
+ client.future(messageHash);
1219
+ this.spawn(this.loadPositionsSnapshot, client, messageHash, type);
1220
+ }
1221
+ }
1222
+ else {
1223
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1224
+ }
1225
+ }
1226
+ async loadPositionsSnapshot(client, messageHash, type) {
1227
+ const positions = await this.fetchPositions(undefined, { 'type': type, 'subType': 'linear' });
1228
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1229
+ const cache = this.positions;
1230
+ for (let i = 0; i < positions.length; i++) {
1231
+ const position = positions[i];
1232
+ const contracts = this.safeNumber(position, 'contracts', 0);
1233
+ if (contracts > 0) {
1234
+ cache.append(position);
1235
+ }
1236
+ }
1237
+ // don't remove the future from the .futures cache
1238
+ if (messageHash in client.futures) {
1239
+ const future = client.futures[messageHash];
1240
+ future.resolve(cache);
1241
+ client.resolve(cache, 'swap:positions');
1242
+ }
1243
+ }
1244
+ parseWsPosition(position, market = undefined) {
1245
+ //
1246
+ // {
1247
+ // "s": "LINK-USDT", // Symbol
1248
+ // "pa": "5.000", // Position Amount
1249
+ // "ep": "11.2345", // Entry Price
1250
+ // "up": "0.5000", // Unrealized PnL
1251
+ // "mt": "isolated", // Margin Type
1252
+ // "iw": "50.00000000", // Isolated Wallet
1253
+ // "ps": "LONG" // Position Side
1254
+ // }
1255
+ //
1256
+ const marketId = this.safeString(position, 's');
1257
+ const contracts = this.safeString(position, 'pa');
1258
+ const contractsAbs = Precise["default"].stringAbs(contracts);
1259
+ let positionSide = this.safeStringLower(position, 'ps');
1260
+ let hedged = true;
1261
+ if (positionSide === 'both') {
1262
+ hedged = false;
1263
+ if (!Precise["default"].stringEq(contracts, '0')) {
1264
+ if (Precise["default"].stringLt(contracts, '0')) {
1265
+ positionSide = 'short';
1266
+ }
1267
+ else {
1268
+ positionSide = 'long';
1269
+ }
1270
+ }
1271
+ }
1272
+ const marginMode = this.safeString(position, 'mt');
1273
+ const collateral = (marginMode === 'isolated') ? this.safeNumber(position, 'iw') : undefined;
1274
+ return this.safePosition({
1275
+ 'info': position,
1276
+ 'id': undefined,
1277
+ 'symbol': this.safeSymbol(marketId, undefined, undefined, 'swap'),
1278
+ 'notional': undefined,
1279
+ 'marginMode': marginMode,
1280
+ 'liquidationPrice': undefined,
1281
+ 'entryPrice': this.safeNumber(position, 'ep'),
1282
+ 'unrealizedPnl': this.safeNumber(position, 'up'),
1283
+ 'percentage': undefined,
1284
+ 'contracts': this.parseNumber(contractsAbs),
1285
+ 'contractSize': undefined,
1286
+ 'markPrice': undefined,
1287
+ 'side': positionSide,
1288
+ 'hedged': hedged,
1289
+ 'timestamp': undefined,
1290
+ 'datetime': undefined,
1291
+ 'maintenanceMargin': undefined,
1292
+ 'maintenanceMarginPercentage': undefined,
1293
+ 'collateral': collateral,
1294
+ 'initialMargin': undefined,
1295
+ 'initialMarginPercentage': undefined,
1296
+ 'leverage': undefined,
1297
+ 'marginRatio': undefined,
1298
+ });
1299
+ }
1300
+ handlePositions(client, message) {
1301
+ //
1302
+ // {
1303
+ // "e": "ACCOUNT_UPDATE",
1304
+ // "E": 1696244249320,
1305
+ // "a": {
1306
+ // "m": "ORDER",
1307
+ // "B": [...],
1308
+ // "P": [
1309
+ // {
1310
+ // "s": "LINK-USDT",
1311
+ // "pa": "5.000",
1312
+ // "ep": "11.2345",
1313
+ // "up": "0.5000",
1314
+ // "mt": "isolated",
1315
+ // "iw": "50.00000000",
1316
+ // "ps": "LONG"
1317
+ // }
1318
+ // ]
1319
+ // }
1320
+ // }
1321
+ //
1322
+ if (this.positions === undefined) {
1323
+ this.positions = new Cache.ArrayCacheBySymbolBySide();
1324
+ }
1325
+ const cache = this.positions;
1326
+ const data = this.safeDict(message, 'a', {});
1327
+ const rawPositions = this.safeList(data, 'P', []);
1328
+ const newPositions = [];
1329
+ for (let i = 0; i < rawPositions.length; i++) {
1330
+ const rawPosition = rawPositions[i];
1331
+ const position = this.parseWsPosition(rawPosition);
1332
+ const timestamp = this.safeInteger(message, 'E');
1333
+ position['timestamp'] = timestamp;
1334
+ position['datetime'] = this.iso8601(timestamp);
1335
+ newPositions.push(position);
1336
+ cache.append(position);
1337
+ }
1338
+ const messageHashes = this.findMessageHashes(client, 'swap:positions::');
1339
+ for (let i = 0; i < messageHashes.length; i++) {
1340
+ const messageHash = messageHashes[i];
1341
+ const parts = messageHash.split('::');
1342
+ const symbolsString = parts[1];
1343
+ const filteredSymbols = symbolsString.split(',');
1344
+ const positions = this.filterByArray(newPositions, 'symbol', filteredSymbols, false);
1345
+ if (!this.isEmpty(positions)) {
1346
+ client.resolve(positions, messageHash);
1347
+ }
1348
+ }
1349
+ client.resolve(newPositions, 'swap:positions');
1350
+ }
1143
1351
  handleErrorMessage(client, message) {
1144
1352
  //
1145
1353
  // { code: 100400, msg: '', timestamp: 1696245808833 }
@@ -1175,7 +1383,11 @@ class bingx extends bingx$1["default"] {
1175
1383
  const types = ['spot', 'linear', 'inverse'];
1176
1384
  for (let i = 0; i < types.length; i++) {
1177
1385
  const type = types[i];
1178
- const url = this.urls['api']['ws'][type] + '?listenKey=' + listenKey;
1386
+ const baseUrl = this.safeString(this.urls['api']['ws'], type);
1387
+ if (baseUrl === undefined) {
1388
+ continue;
1389
+ }
1390
+ const url = baseUrl + '?listenKey=' + listenKey;
1179
1391
  const client = this.client(url);
1180
1392
  const messageHashes = Object.keys(client.futures);
1181
1393
  for (let j = 0; j < messageHashes.length; j++) {
@@ -1505,6 +1717,7 @@ class bingx extends bingx$1["default"] {
1505
1717
  const e = this.safeString(message, 'e');
1506
1718
  if (e === 'ACCOUNT_UPDATE') {
1507
1719
  this.handleBalance(client, message);
1720
+ this.handlePositions(client, message);
1508
1721
  }
1509
1722
  if (e === 'ORDER_TRADE_UPDATE') {
1510
1723
  this.handleOrder(client, message);