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
@@ -1,5 +1,5 @@
1
1
  import bingxRest from '../bingx.js';
2
- import type { Int, Market, OHLCV, Str, OrderBook, Order, Trade, Balances, Ticker, Dict } from '../base/types.js';
2
+ import type { Int, Market, OHLCV, Str, Strings, OrderBook, Order, Trade, Balances, Ticker, Position, Dict } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class bingx extends bingxRest {
5
5
  describe(): any;
@@ -8,9 +8,9 @@ export default class bingx extends bingxRest {
8
8
  * @method
9
9
  * @name bingx#watchTicker
10
10
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
11
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20to%2024-hour%20Price%20Change
12
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
13
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%2024-Hour%20Price%20Change
11
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20Price%20Change
12
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20price%20changes
13
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%2024-Hour%20Price%20Change
14
14
  * @param {string} symbol unified symbol of the market to fetch the ticker for
15
15
  * @param {object} [params] extra parameters specific to the exchange API endpoint
16
16
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
@@ -20,9 +20,9 @@ export default class bingx extends bingxRest {
20
20
  * @method
21
21
  * @name bingx#unWatchTicker
22
22
  * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
23
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20to%2024-hour%20Price%20Change
24
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
25
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%2024-Hour%20Price%20Change
23
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20Price%20Change
24
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20price%20changes
25
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%2024-Hour%20Price%20Change
26
26
  * @param {string} symbol unified symbol of the market to fetch the ticker for
27
27
  * @param {object} [params] extra parameters specific to the exchange API endpoint
28
28
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
@@ -36,9 +36,9 @@ export default class bingx extends bingxRest {
36
36
  * @method
37
37
  * @name bingx#watchTrades
38
38
  * @description watches information on multiple trades made in a market
39
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscription%20transaction%20by%20transaction
40
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20the%20Latest%20Trade%20Detail
41
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscription%20transaction%20by%20transaction
39
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
40
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20the%20Latest%20Trade%20Detail
41
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
42
42
  * @param {string} symbol unified market symbol of the market orders were made in
43
43
  * @param {int} [since] the earliest time in ms to fetch orders for
44
44
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -50,9 +50,9 @@ export default class bingx extends bingxRest {
50
50
  * @method
51
51
  * @name bingx#unWatchTrades
52
52
  * @description unsubscribes from the trades channel
53
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscription%20transaction%20by%20transaction
54
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20the%20Latest%20Trade%20Detail
55
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscription%20transaction%20by%20transaction
53
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
54
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20the%20Latest%20Trade%20Detail
55
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
56
56
  * @param {string} symbol unified symbol of the market to fetch trades for
57
57
  * @param {object} [params] extra parameters specific to the exchange API endpoint
58
58
  * @param {string} [params.name] the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
@@ -64,9 +64,9 @@ export default class bingx extends bingxRest {
64
64
  * @method
65
65
  * @name bingx#watchOrderBook
66
66
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
67
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20Market%20Depth%20Data
68
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20Market%20Depth%20Data
69
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Limited%20Depth
67
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20Market%20Depth%20Data
68
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Partial%20Order%20Book%20Depth
69
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Limited%20Depth
70
70
  * @param {string} symbol unified symbol of the market to fetch the order book for
71
71
  * @param {int} [limit] the maximum amount of order book entries to return
72
72
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -77,9 +77,9 @@ export default class bingx extends bingxRest {
77
77
  * @method
78
78
  * @name bingx#unWatchOrderBook
79
79
  * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
80
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20Market%20Depth%20Data
81
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20Market%20Depth%20Data
82
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Limited%20Depth
80
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20Market%20Depth%20Data
81
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Partial%20Order%20Book%20Depth
82
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Limited%20Depth
83
83
  * @param {string} symbol unified symbol of the market
84
84
  * @param {object} [params] extra parameters specific to the exchange API endpoint
85
85
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
@@ -93,9 +93,9 @@ export default class bingx extends bingxRest {
93
93
  * @method
94
94
  * @name bingx#watchOHLCV
95
95
  * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
96
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#K-line%20Streams
97
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20K-Line%20Data
98
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
96
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/K-line%20Streamst
97
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20K-Line%20Data
98
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
99
99
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
100
100
  * @param {string} timeframe the length of time each candle represents
101
101
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -108,9 +108,9 @@ export default class bingx extends bingxRest {
108
108
  * @method
109
109
  * @name bingx#unWatchOHLCV
110
110
  * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
111
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#K-line%20Streams
112
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20K-Line%20Data
113
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
111
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/K-line%20Streamst
112
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20K-Line%20Data
113
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
114
114
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
115
115
  * @param {string} timeframe the length of time each candle represents
116
116
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -121,9 +121,9 @@ export default class bingx extends bingxRest {
121
121
  * @method
122
122
  * @name bingx#watchOrders
123
123
  * @description watches information on multiple orders made by the user
124
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20order%20update%20data
125
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Order%20update%20push
126
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Order%20update%20push
124
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/order%20update%20event
125
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Order%20update%20push
126
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Order%20update%20push
127
127
  * @param {string} [symbol] unified market symbol of the market orders are made in
128
128
  * @param {int} [since] the earliest time in ms to watch orders for
129
129
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -135,9 +135,9 @@ export default class bingx extends bingxRest {
135
135
  * @method
136
136
  * @name bingx#watchMyTrades
137
137
  * @description watches information on multiple trades made by the user
138
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20order%20update%20data
139
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Order%20update%20push
140
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Order%20update%20push
138
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/order%20update%20event
139
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Order%20update%20push
140
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Order%20update%20push
141
141
  * @param {string} [symbol] unified market symbol of the market the trades are made in
142
142
  * @param {int} [since] the earliest time in ms to watch trades for
143
143
  * @param {int} [limit] the maximum number of trade structures to retrieve
@@ -149,15 +149,31 @@ export default class bingx extends bingxRest {
149
149
  * @method
150
150
  * @name bingx#watchBalance
151
151
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
152
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20account%20balance%20push
153
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
154
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Account%20balance%20and%20position%20update%20push
152
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/Subscription%20account%20balance%20push
153
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Account%20balance%20and%20position%20update%20push
154
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Account%20balance%20and%20position%20update%20push
155
155
  * @param {object} [params] extra parameters specific to the exchange API endpoint
156
156
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
157
157
  */
158
158
  watchBalance(params?: {}): Promise<Balances>;
159
159
  setBalanceCache(client: Client, type: any, subType: any, subscriptionHash: any, params: any): void;
160
160
  loadBalanceSnapshot(client: any, messageHash: any, type: any, subType: any): Promise<void>;
161
+ /**
162
+ * @method
163
+ * @name bingx#watchPositions
164
+ * @description watch all open positions
165
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
166
+ * @param {string[]|undefined} [symbols] list of unified market symbols
167
+ * @param {int} [since] the earliest time in ms to fetch positions for
168
+ * @param {int} [limit] the maximum number of position structures to retrieve
169
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
170
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
171
+ */
172
+ watchPositions(symbols?: Strings, since?: Int, limit?: Int, params?: {}): Promise<Position[]>;
173
+ setPositionsCache(client: Client, type: any, symbols?: Strings): void;
174
+ loadPositionsSnapshot(client: any, messageHash: any, type: any): Promise<void>;
175
+ parseWsPosition(position: any, market?: any): Position;
176
+ handlePositions(client: Client, message: any): void;
161
177
  handleErrorMessage(client: any, message: any): boolean;
162
178
  keepAliveListenKey(params?: {}): Promise<void>;
163
179
  authenticate(params?: {}): Promise<void>;
@@ -1,7 +1,8 @@
1
1
  // ---------------------------------------------------------------------------
2
2
  import bingxRest from '../bingx.js';
3
3
  import { BadRequest, NetworkError, NotSupported } from '../base/errors.js';
4
- import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById } from '../base/ws/Cache.js';
4
+ import { Precise } from '../base/Precise.js';
5
+ import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide } from '../base/ws/Cache.js';
5
6
  // ---------------------------------------------------------------------------
6
7
  export default class bingx extends bingxRest {
7
8
  describe() {
@@ -19,12 +20,18 @@ export default class bingx extends bingxRest {
19
20
  'watchTicker': true,
20
21
  'watchTickers': false,
21
22
  'watchBalance': true,
23
+ 'watchPositions': true,
22
24
  'unWatchOHLCV': true,
23
25
  'unWatchOrderBook': true,
24
26
  'unWatchTicker': true,
25
27
  'unWatchTrades': true,
26
28
  },
27
29
  'urls': {
30
+ 'test': {
31
+ 'ws': {
32
+ 'linear': 'wss://vst-open-api-ws.bingx.com/swap-market',
33
+ },
34
+ },
28
35
  'api': {
29
36
  'ws': {
30
37
  'spot': 'wss://open-api-ws.bingx.com/market',
@@ -68,7 +75,11 @@ export default class bingx extends bingxRest {
68
75
  },
69
76
  'watchBalance': {
70
77
  'fetchBalanceSnapshot': true,
71
- 'awaitBalanceSnapshot': false, // whether to wait for the balance snapshot before providing updates
78
+ 'awaitBalanceSnapshot': true, // whether to wait for the balance snapshot before providing updates
79
+ },
80
+ 'watchPositions': {
81
+ 'fetchPositionsSnapshot': true,
82
+ 'awaitPositionsSnapshot': false,
72
83
  },
73
84
  'watchOrderBook': {
74
85
  'depth': 100, // 5, 10, 20, 50, 100
@@ -124,9 +135,9 @@ export default class bingx extends bingxRest {
124
135
  * @method
125
136
  * @name bingx#watchTicker
126
137
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
127
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20to%2024-hour%20Price%20Change
128
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
129
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%2024-Hour%20Price%20Change
138
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20Price%20Change
139
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20price%20changes
140
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%2024-Hour%20Price%20Change
130
141
  * @param {string} symbol unified symbol of the market to fetch the ticker for
131
142
  * @param {object} [params] extra parameters specific to the exchange API endpoint
132
143
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
@@ -165,9 +176,9 @@ export default class bingx extends bingxRest {
165
176
  * @method
166
177
  * @name bingx#unWatchTicker
167
178
  * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
168
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20to%2024-hour%20Price%20Change
169
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
170
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%2024-Hour%20Price%20Change
179
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20Price%20Change
180
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20to%2024-hour%20price%20changes
181
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%2024-Hour%20Price%20Change
171
182
  * @param {string} symbol unified symbol of the market to fetch the ticker for
172
183
  * @param {object} [params] extra parameters specific to the exchange API endpoint
173
184
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/?id=ticker-structure}
@@ -332,9 +343,9 @@ export default class bingx extends bingxRest {
332
343
  * @method
333
344
  * @name bingx#watchTrades
334
345
  * @description watches information on multiple trades made in a market
335
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscription%20transaction%20by%20transaction
336
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20the%20Latest%20Trade%20Detail
337
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscription%20transaction%20by%20transaction
346
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
347
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20the%20Latest%20Trade%20Detail
348
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
338
349
  * @param {string} symbol unified market symbol of the market orders were made in
339
350
  * @param {int} [since] the earliest time in ms to fetch orders for
340
351
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -386,9 +397,9 @@ export default class bingx extends bingxRest {
386
397
  * @method
387
398
  * @name bingx#unWatchTrades
388
399
  * @description unsubscribes from the trades channel
389
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscription%20transaction%20by%20transaction
390
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20the%20Latest%20Trade%20Detail
391
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscription%20transaction%20by%20transaction
400
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
401
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20the%20Latest%20Trade%20Detail
402
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscription%20transaction%20by%20transaction
392
403
  * @param {string} symbol unified symbol of the market to fetch trades for
393
404
  * @param {object} [params] extra parameters specific to the exchange API endpoint
394
405
  * @param {string} [params.name] the name of the method to call, 'trade' or 'aggTrade', default is 'trade'
@@ -516,9 +527,9 @@ export default class bingx extends bingxRest {
516
527
  * @method
517
528
  * @name bingx#watchOrderBook
518
529
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
519
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20Market%20Depth%20Data
520
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20Market%20Depth%20Data
521
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Limited%20Depth
530
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20Market%20Depth%20Data
531
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Partial%20Order%20Book%20Depth
532
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Limited%20Depth
522
533
  * @param {string} symbol unified symbol of the market to fetch the order book for
523
534
  * @param {int} [limit] the maximum amount of order book entries to return
524
535
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -574,9 +585,9 @@ export default class bingx extends bingxRest {
574
585
  * @method
575
586
  * @name bingx#unWatchOrderBook
576
587
  * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
577
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#Subscribe%20Market%20Depth%20Data
578
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20Market%20Depth%20Data
579
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Limited%20Depth
588
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/Subscribe%20Market%20Depth%20Data
589
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Partial%20Order%20Book%20Depth
590
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Limited%20Depth
580
591
  * @param {string} symbol unified symbol of the market
581
592
  * @param {object} [params] extra parameters specific to the exchange API endpoint
582
593
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
@@ -848,9 +859,9 @@ export default class bingx extends bingxRest {
848
859
  * @method
849
860
  * @name bingx#watchOHLCV
850
861
  * @description watches historical candlestick data containing the open, high, low, and close price, and the volume of a market
851
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#K-line%20Streams
852
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20K-Line%20Data
853
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
862
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/K-line%20Streamst
863
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20K-Line%20Data
864
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
854
865
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
855
866
  * @param {string} timeframe the length of time each candle represents
856
867
  * @param {int} [since] timestamp in ms of the earliest candle to fetch
@@ -905,9 +916,9 @@ export default class bingx extends bingxRest {
905
916
  * @method
906
917
  * @name bingx#unWatchOHLCV
907
918
  * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
908
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/market.html#K-line%20Streams
909
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20K-Line%20Data
910
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/market.html#Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
919
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Market%20Data/K-line%20Streamst
920
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Market%20Data/Subscribe%20K-Line%20Data
921
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Market%20Data/Subscribe%20to%20Latest%20Trading%20Pair%20K-Line
911
922
  * @param {string} symbol unified symbol of the market to fetch OHLCV data for
912
923
  * @param {string} timeframe the length of time each candle represents
913
924
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -931,9 +942,9 @@ export default class bingx extends bingxRest {
931
942
  * @method
932
943
  * @name bingx#watchOrders
933
944
  * @description watches information on multiple orders made by the user
934
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20order%20update%20data
935
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Order%20update%20push
936
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Order%20update%20push
945
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/order%20update%20event
946
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Order%20update%20push
947
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Order%20update%20push
937
948
  * @param {string} [symbol] unified market symbol of the market orders are made in
938
949
  * @param {int} [since] the earliest time in ms to watch orders for
939
950
  * @param {int} [limit] the maximum number of order structures to retrieve
@@ -994,9 +1005,9 @@ export default class bingx extends bingxRest {
994
1005
  * @method
995
1006
  * @name bingx#watchMyTrades
996
1007
  * @description watches information on multiple trades made by the user
997
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20order%20update%20data
998
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Order%20update%20push
999
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Order%20update%20push
1008
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/order%20update%20event
1009
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Order%20update%20push
1010
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Order%20update%20push
1000
1011
  * @param {string} [symbol] unified market symbol of the market the trades are made in
1001
1012
  * @param {int} [since] the earliest time in ms to watch trades for
1002
1013
  * @param {int} [limit] the maximum number of trade structures to retrieve
@@ -1057,9 +1068,9 @@ export default class bingx extends bingxRest {
1057
1068
  * @method
1058
1069
  * @name bingx#watchBalance
1059
1070
  * @description query for balance and get the amount of funds available for trading or funds locked in orders
1060
- * @see https://bingx-api.github.io/docs/#/en-us/spot/socket/account.html#Subscription%20account%20balance%20push
1061
- * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
1062
- * @see https://bingx-api.github.io/docs/#/en-us/cswap/socket/account.html#Account%20balance%20and%20position%20update%20push
1071
+ * @see https://bingx-api.github.io/docs-v3/#/en/Spot/Websocket%20Account%20Data/Subscription%20account%20balance%20push
1072
+ * @see https://bingx-api.github.io/docs-v3/#/en/Swap/Websocket%20Account%20Data/Account%20balance%20and%20position%20update%20push
1073
+ * @see https://bingx-api.github.io/docs-v3/#/en/Coin-M%20Futures/Websocket%20Account%20Data/Account%20balance%20and%20position%20update%20push
1063
1074
  * @param {object} [params] extra parameters specific to the exchange API endpoint
1064
1075
  * @returns {object} a [balance structure]{@link https://docs.ccxt.com/?id=balance-structure}
1065
1076
  */
@@ -1135,6 +1146,203 @@ export default class bingx extends bingxRest {
1135
1146
  client.resolve(this.balance[type], type + ':balance');
1136
1147
  }
1137
1148
  }
1149
+ /**
1150
+ * @method
1151
+ * @name bingx#watchPositions
1152
+ * @description watch all open positions
1153
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/account.html#Account%20balance%20and%20position%20update%20push
1154
+ * @param {string[]|undefined} [symbols] list of unified market symbols
1155
+ * @param {int} [since] the earliest time in ms to fetch positions for
1156
+ * @param {int} [limit] the maximum number of position structures to retrieve
1157
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1158
+ * @returns {object[]} a list of [position structure]{@link https://docs.ccxt.com/en/latest/manual.html#position-structure}
1159
+ */
1160
+ async watchPositions(symbols = undefined, since = undefined, limit = undefined, params = {}) {
1161
+ await this.loadMarkets();
1162
+ await this.authenticate();
1163
+ let market = undefined;
1164
+ let messageHash = '';
1165
+ symbols = this.marketSymbols(symbols);
1166
+ if (!this.isEmpty(symbols)) {
1167
+ market = this.getMarketFromSymbols(symbols);
1168
+ messageHash = '::' + symbols.join(',');
1169
+ }
1170
+ let type = undefined;
1171
+ let subType = undefined;
1172
+ [type, params] = this.handleMarketTypeAndParams('watchPositions', market, params);
1173
+ [subType, params] = this.handleSubTypeAndParams('watchPositions', market, params, 'linear');
1174
+ if (type === 'spot') {
1175
+ throw new NotSupported(this.id + ' watchPositions is not supported for spot markets');
1176
+ }
1177
+ if (subType === 'inverse') {
1178
+ throw new NotSupported(this.id + ' watchPositions is not supported for inverse swap markets yet');
1179
+ }
1180
+ const subscriptionHash = 'swap:private';
1181
+ messageHash = 'swap:positions' + messageHash;
1182
+ const baseUrl = this.safeString(this.urls['api']['ws'], subType);
1183
+ const url = baseUrl + '?listenKey=' + this.options['listenKey'];
1184
+ const client = this.client(url);
1185
+ this.setPositionsCache(client, type, symbols);
1186
+ let fetchPositionsSnapshot = undefined;
1187
+ let awaitPositionsSnapshot = undefined;
1188
+ [fetchPositionsSnapshot, params] = this.handleOptionAndParams(params, 'watchPositions', 'fetchPositionsSnapshot', true);
1189
+ [awaitPositionsSnapshot, params] = this.handleOptionAndParams(params, 'watchPositions', 'awaitPositionsSnapshot', false);
1190
+ const uuid = this.uuid();
1191
+ const subscription = {
1192
+ 'unsubscribe': false,
1193
+ 'id': uuid,
1194
+ };
1195
+ if (fetchPositionsSnapshot && awaitPositionsSnapshot && this.positions === undefined) {
1196
+ const snapshot = await client.future(type + ':fetchPositionsSnapshot');
1197
+ return this.filterBySymbolsSinceLimit(snapshot, symbols, since, limit, true);
1198
+ }
1199
+ const newPositions = await this.watch(url, messageHash, undefined, subscriptionHash, subscription);
1200
+ if (this.newUpdates) {
1201
+ return newPositions;
1202
+ }
1203
+ return this.filterBySymbolsSinceLimit(this.positions, symbols, since, limit, true);
1204
+ }
1205
+ setPositionsCache(client, type, symbols = undefined) {
1206
+ if (this.positions !== undefined) {
1207
+ return;
1208
+ }
1209
+ const fetchPositionsSnapshot = this.handleOption('watchPositions', 'fetchPositionsSnapshot', true);
1210
+ if (fetchPositionsSnapshot) {
1211
+ const messageHash = type + ':fetchPositionsSnapshot';
1212
+ if (!(messageHash in client.futures)) {
1213
+ client.future(messageHash);
1214
+ this.spawn(this.loadPositionsSnapshot, client, messageHash, type);
1215
+ }
1216
+ }
1217
+ else {
1218
+ this.positions = new ArrayCacheBySymbolBySide();
1219
+ }
1220
+ }
1221
+ async loadPositionsSnapshot(client, messageHash, type) {
1222
+ const positions = await this.fetchPositions(undefined, { 'type': type, 'subType': 'linear' });
1223
+ this.positions = new ArrayCacheBySymbolBySide();
1224
+ const cache = this.positions;
1225
+ for (let i = 0; i < positions.length; i++) {
1226
+ const position = positions[i];
1227
+ const contracts = this.safeNumber(position, 'contracts', 0);
1228
+ if (contracts > 0) {
1229
+ cache.append(position);
1230
+ }
1231
+ }
1232
+ // don't remove the future from the .futures cache
1233
+ if (messageHash in client.futures) {
1234
+ const future = client.futures[messageHash];
1235
+ future.resolve(cache);
1236
+ client.resolve(cache, 'swap:positions');
1237
+ }
1238
+ }
1239
+ parseWsPosition(position, market = undefined) {
1240
+ //
1241
+ // {
1242
+ // "s": "LINK-USDT", // Symbol
1243
+ // "pa": "5.000", // Position Amount
1244
+ // "ep": "11.2345", // Entry Price
1245
+ // "up": "0.5000", // Unrealized PnL
1246
+ // "mt": "isolated", // Margin Type
1247
+ // "iw": "50.00000000", // Isolated Wallet
1248
+ // "ps": "LONG" // Position Side
1249
+ // }
1250
+ //
1251
+ const marketId = this.safeString(position, 's');
1252
+ const contracts = this.safeString(position, 'pa');
1253
+ const contractsAbs = Precise.stringAbs(contracts);
1254
+ let positionSide = this.safeStringLower(position, 'ps');
1255
+ let hedged = true;
1256
+ if (positionSide === 'both') {
1257
+ hedged = false;
1258
+ if (!Precise.stringEq(contracts, '0')) {
1259
+ if (Precise.stringLt(contracts, '0')) {
1260
+ positionSide = 'short';
1261
+ }
1262
+ else {
1263
+ positionSide = 'long';
1264
+ }
1265
+ }
1266
+ }
1267
+ const marginMode = this.safeString(position, 'mt');
1268
+ const collateral = (marginMode === 'isolated') ? this.safeNumber(position, 'iw') : undefined;
1269
+ return this.safePosition({
1270
+ 'info': position,
1271
+ 'id': undefined,
1272
+ 'symbol': this.safeSymbol(marketId, undefined, undefined, 'swap'),
1273
+ 'notional': undefined,
1274
+ 'marginMode': marginMode,
1275
+ 'liquidationPrice': undefined,
1276
+ 'entryPrice': this.safeNumber(position, 'ep'),
1277
+ 'unrealizedPnl': this.safeNumber(position, 'up'),
1278
+ 'percentage': undefined,
1279
+ 'contracts': this.parseNumber(contractsAbs),
1280
+ 'contractSize': undefined,
1281
+ 'markPrice': undefined,
1282
+ 'side': positionSide,
1283
+ 'hedged': hedged,
1284
+ 'timestamp': undefined,
1285
+ 'datetime': undefined,
1286
+ 'maintenanceMargin': undefined,
1287
+ 'maintenanceMarginPercentage': undefined,
1288
+ 'collateral': collateral,
1289
+ 'initialMargin': undefined,
1290
+ 'initialMarginPercentage': undefined,
1291
+ 'leverage': undefined,
1292
+ 'marginRatio': undefined,
1293
+ });
1294
+ }
1295
+ handlePositions(client, message) {
1296
+ //
1297
+ // {
1298
+ // "e": "ACCOUNT_UPDATE",
1299
+ // "E": 1696244249320,
1300
+ // "a": {
1301
+ // "m": "ORDER",
1302
+ // "B": [...],
1303
+ // "P": [
1304
+ // {
1305
+ // "s": "LINK-USDT",
1306
+ // "pa": "5.000",
1307
+ // "ep": "11.2345",
1308
+ // "up": "0.5000",
1309
+ // "mt": "isolated",
1310
+ // "iw": "50.00000000",
1311
+ // "ps": "LONG"
1312
+ // }
1313
+ // ]
1314
+ // }
1315
+ // }
1316
+ //
1317
+ if (this.positions === undefined) {
1318
+ this.positions = new ArrayCacheBySymbolBySide();
1319
+ }
1320
+ const cache = this.positions;
1321
+ const data = this.safeDict(message, 'a', {});
1322
+ const rawPositions = this.safeList(data, 'P', []);
1323
+ const newPositions = [];
1324
+ for (let i = 0; i < rawPositions.length; i++) {
1325
+ const rawPosition = rawPositions[i];
1326
+ const position = this.parseWsPosition(rawPosition);
1327
+ const timestamp = this.safeInteger(message, 'E');
1328
+ position['timestamp'] = timestamp;
1329
+ position['datetime'] = this.iso8601(timestamp);
1330
+ newPositions.push(position);
1331
+ cache.append(position);
1332
+ }
1333
+ const messageHashes = this.findMessageHashes(client, 'swap:positions::');
1334
+ for (let i = 0; i < messageHashes.length; i++) {
1335
+ const messageHash = messageHashes[i];
1336
+ const parts = messageHash.split('::');
1337
+ const symbolsString = parts[1];
1338
+ const filteredSymbols = symbolsString.split(',');
1339
+ const positions = this.filterByArray(newPositions, 'symbol', filteredSymbols, false);
1340
+ if (!this.isEmpty(positions)) {
1341
+ client.resolve(positions, messageHash);
1342
+ }
1343
+ }
1344
+ client.resolve(newPositions, 'swap:positions');
1345
+ }
1138
1346
  handleErrorMessage(client, message) {
1139
1347
  //
1140
1348
  // { code: 100400, msg: '', timestamp: 1696245808833 }
@@ -1170,7 +1378,11 @@ export default class bingx extends bingxRest {
1170
1378
  const types = ['spot', 'linear', 'inverse'];
1171
1379
  for (let i = 0; i < types.length; i++) {
1172
1380
  const type = types[i];
1173
- const url = this.urls['api']['ws'][type] + '?listenKey=' + listenKey;
1381
+ const baseUrl = this.safeString(this.urls['api']['ws'], type);
1382
+ if (baseUrl === undefined) {
1383
+ continue;
1384
+ }
1385
+ const url = baseUrl + '?listenKey=' + listenKey;
1174
1386
  const client = this.client(url);
1175
1387
  const messageHashes = Object.keys(client.futures);
1176
1388
  for (let j = 0; j < messageHashes.length; j++) {
@@ -1500,6 +1712,7 @@ export default class bingx extends bingxRest {
1500
1712
  const e = this.safeString(message, 'e');
1501
1713
  if (e === 'ACCOUNT_UPDATE') {
1502
1714
  this.handleBalance(client, message);
1715
+ this.handlePositions(client, message);
1503
1716
  }
1504
1717
  if (e === 'ORDER_TRADE_UPDATE') {
1505
1718
  this.handleOrder(client, message);
@@ -8,7 +8,7 @@ import Client from '../base/ws/Client.js';
8
8
  */
9
9
  export default class bitget extends bitgetRest {
10
10
  describe(): any;
11
- getInstType(market: any, uta?: boolean, params?: {}): any[];
11
+ getInstType(methodName: any, market: any, uta?: boolean, params?: {}): any[];
12
12
  /**
13
13
  * @method
14
14
  * @name bitget#watchTicker
@@ -123,7 +123,7 @@ export default class bitget extends bitgetRest {
123
123
  * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/?id=order-book-structure} indexed by market symbols
124
124
  */
125
125
  unWatchOrderBook(symbol: string, params?: {}): Promise<any>;
126
- unWatchChannel(symbol: string, channel: string, messageHashTopic: string, params?: {}): Promise<any>;
126
+ unWatchChannel(symbol: string, channel: string, messageHashTopic: string, methodName: string, params?: {}): Promise<any>;
127
127
  /**
128
128
  * @method
129
129
  * @name bitget#watchOrderBookForSymbols
@@ -263,11 +263,11 @@ export default class bitget extends bitgetRest {
263
263
  */
264
264
  watchBalance(params?: {}): Promise<Balances>;
265
265
  handleBalance(client: Client, message: any): void;
266
- watchPublic(messageHash: any, args: any, params?: {}): Promise<any>;
267
- unWatchPublic(messageHash: any, args: any, params?: {}): Promise<any>;
268
- watchPublicMultiple(messageHashes: any, argsArray: any, params?: {}): Promise<any>;
266
+ watchPublic(uta: any, messageHash: any, args: any, params?: {}): Promise<any>;
267
+ unWatchPublic(uta: any, messageHash: any, args: any, params?: {}): Promise<any>;
268
+ watchPublicMultiple(uta: any, messageHashes: any, argsArray: any, params?: {}): Promise<any>;
269
269
  authenticate(params?: {}): Promise<any>;
270
- watchPrivate(messageHash: any, subscriptionHash: any, args: any, params?: {}): Promise<any>;
270
+ watchPrivate(uta: any, messageHash: any, subscriptionHash: any, args: any, params?: {}): Promise<any>;
271
271
  handleAuthenticate(client: Client, message: any): void;
272
272
  handleErrorMessage(client: Client, message: any): Bool;
273
273
  handleMessage(client: Client, message: any): void;