ccxt 4.2.25 → 4.2.26

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.
@@ -20,7 +20,7 @@ export default class bingx extends bingxRest {
20
20
  'watchOHLCV': true,
21
21
  'watchOrders': true,
22
22
  'watchMyTrades': true,
23
- 'watchTicker': false,
23
+ 'watchTicker': true,
24
24
  'watchTickers': false,
25
25
  'watchBalance': true,
26
26
  },
@@ -75,6 +75,151 @@ export default class bingx extends bingxRest {
75
75
  },
76
76
  });
77
77
  }
78
+ async watchTicker(symbol, params = {}) {
79
+ /**
80
+ * @method
81
+ * @name bingx#watchTicker
82
+ * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
83
+ * @see https://bingx-api.github.io/docs/#/en-us/swapV2/socket/market.html#Subscribe%20to%2024-hour%20price%20changes
84
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
85
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
86
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
87
+ */
88
+ await this.loadMarkets();
89
+ const market = this.market(symbol);
90
+ const [marketType, query] = this.handleMarketTypeAndParams('watchTrades', market, params);
91
+ const url = this.safeValue(this.urls['api']['ws'], marketType);
92
+ if (url === undefined) {
93
+ throw new BadRequest(this.id + ' watchTrades is not supported for ' + marketType + ' markets.');
94
+ }
95
+ const messageHash = market['id'] + '@ticker';
96
+ const uuid = this.uuid();
97
+ const request = {
98
+ 'id': uuid,
99
+ 'dataType': messageHash,
100
+ };
101
+ if (marketType === 'swap') {
102
+ request['reqType'] = 'sub';
103
+ }
104
+ return await this.watch(url, messageHash, this.extend(request, query), messageHash);
105
+ }
106
+ handleTicker(client, message) {
107
+ //
108
+ // swap
109
+ //
110
+ // {
111
+ // "code": 0,
112
+ // "dataType": "BTC-USDT@ticker",
113
+ // "data": {
114
+ // "e": "24hTicker",
115
+ // "E": 1706498923556,
116
+ // "s": "BTC-USDT",
117
+ // "p": "346.4",
118
+ // "P": "0.82",
119
+ // "c": "42432.5",
120
+ // "L": "0.0529",
121
+ // "h": "42855.4",
122
+ // "l": "41578.3",
123
+ // "v": "64310.9754",
124
+ // "q": "2728360284.15",
125
+ // "o": "42086.1",
126
+ // "O": 1706498922655,
127
+ // "C": 1706498883023,
128
+ // "A": "42437.8",
129
+ // "a": "1.4160",
130
+ // "B": "42437.1",
131
+ // "b": "2.5747"
132
+ // }
133
+ // }
134
+ //
135
+ // spot
136
+ //
137
+ // {
138
+ // "code": 0,
139
+ // "timestamp": 1706506795473,
140
+ // "data": {
141
+ // "e": "24hTicker",
142
+ // "E": 1706506795472,
143
+ // "s": "BTC-USDT",
144
+ // "p": -372.12,
145
+ // "P": "-0.87%",
146
+ // "o": 42548.95,
147
+ // "h": 42696.1,
148
+ // "l": 41621.29,
149
+ // "c": 42176.83,
150
+ // "v": 4943.33,
151
+ // "q": 208842236.5,
152
+ // "O": 1706420395472,
153
+ // "C": 1706506795472,
154
+ // "A": 42177.23,
155
+ // "a": 5.14484,
156
+ // "B": 42176.38,
157
+ // "b": 5.36117
158
+ // }
159
+ // }
160
+ //
161
+ const data = this.safeValue(message, 'data', {});
162
+ const marketId = this.safeString(data, 's');
163
+ // const marketId = messageHash.split('@')[0];
164
+ const isSwap = client.url.indexOf('swap') >= 0;
165
+ const marketType = isSwap ? 'swap' : 'spot';
166
+ const market = this.safeMarket(marketId, undefined, undefined, marketType);
167
+ const symbol = market['symbol'];
168
+ const ticker = this.parseWsTicker(data, market);
169
+ this.tickers[symbol] = ticker;
170
+ const messageHash = market['id'] + '@ticker';
171
+ client.resolve(ticker, messageHash);
172
+ }
173
+ parseWsTicker(message, market = undefined) {
174
+ //
175
+ // {
176
+ // "e": "24hTicker",
177
+ // "E": 1706498923556,
178
+ // "s": "BTC-USDT",
179
+ // "p": "346.4",
180
+ // "P": "0.82",
181
+ // "c": "42432.5",
182
+ // "L": "0.0529",
183
+ // "h": "42855.4",
184
+ // "l": "41578.3",
185
+ // "v": "64310.9754",
186
+ // "q": "2728360284.15",
187
+ // "o": "42086.1",
188
+ // "O": 1706498922655,
189
+ // "C": 1706498883023,
190
+ // "A": "42437.8",
191
+ // "a": "1.4160",
192
+ // "B": "42437.1",
193
+ // "b": "2.5747"
194
+ // }
195
+ //
196
+ const timestamp = this.safeInteger(message, 'ts');
197
+ const marketId = this.safeString(message, 's');
198
+ market = this.safeMarket(marketId, market);
199
+ const close = this.safeString(message, 'c');
200
+ return this.safeTicker({
201
+ 'symbol': market['symbol'],
202
+ 'timestamp': timestamp,
203
+ 'datetime': this.iso8601(timestamp),
204
+ 'high': this.safeString(message, 'h'),
205
+ 'low': this.safeString(message, 'l'),
206
+ 'bid': this.safeString(message, 'B'),
207
+ 'bidVolume': this.safeString(message, 'b'),
208
+ 'ask': this.safeString(message, 'A'),
209
+ 'askVolume': this.safeString(message, 'a'),
210
+ 'vwap': undefined,
211
+ 'open': this.safeString(message, 'o'),
212
+ 'close': close,
213
+ 'last': close,
214
+ 'previousClose': undefined,
215
+ 'change': this.safeString(message, 'p'),
216
+ 'percentage': undefined,
217
+ 'average': undefined,
218
+ 'baseVolume': this.safeString(message, 'v'),
219
+ 'quoteVolume': this.safeString(message, 'q'),
220
+ 'info': message,
221
+ }, market);
222
+ }
78
223
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
79
224
  /**
80
225
  * @method
@@ -911,6 +1056,10 @@ export default class bingx extends bingxRest {
911
1056
  this.handleOrderBook(client, message);
912
1057
  return;
913
1058
  }
1059
+ if (dataType.indexOf('@ticker') >= 0) {
1060
+ this.handleTicker(client, message);
1061
+ return;
1062
+ }
914
1063
  if (dataType.indexOf('@trade') >= 0) {
915
1064
  this.handleTrades(client, message);
916
1065
  return;
@@ -941,5 +1090,10 @@ export default class bingx extends bingxRest {
941
1090
  this.handleMyTrades(client, message);
942
1091
  }
943
1092
  }
1093
+ const msgData = this.safeValue(message, 'data');
1094
+ const msgEvent = this.safeString(msgData, 'e');
1095
+ if (msgEvent === '24hTicker') {
1096
+ this.handleTicker(client, message);
1097
+ }
944
1098
  }
945
1099
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.2.25",
3
+ "version": "4.2.26",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.js",
6
6
  "type": "module",