ccxt 4.4.7 → 4.4.8

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,6 +20,8 @@ export default class bitvavo extends bitvavoRest {
20
20
  'watchOrderBook': true,
21
21
  'watchTrades': true,
22
22
  'watchTicker': true,
23
+ 'watchTickers': true,
24
+ 'watchBidsAsks': true,
23
25
  'watchOHLCV': true,
24
26
  'watchOrders': true,
25
27
  'watchMyTrades': true,
@@ -80,17 +82,56 @@ export default class bitvavo extends bitvavoRest {
80
82
  const message = this.extend(request, params);
81
83
  return await this.watch(url, messageHash, message, messageHash);
82
84
  }
85
+ async watchPublicMultiple(methodName, channelName, symbols, params = {}) {
86
+ await this.loadMarkets();
87
+ symbols = this.marketSymbols(symbols);
88
+ const messageHashes = [methodName];
89
+ const args = [];
90
+ for (let i = 0; i < symbols.length; i++) {
91
+ const market = this.market(symbols[i]);
92
+ args.push(market['id']);
93
+ }
94
+ const url = this.urls['api']['ws'];
95
+ const request = {
96
+ 'action': 'subscribe',
97
+ 'channels': [
98
+ {
99
+ 'name': channelName,
100
+ 'markets': args,
101
+ },
102
+ ],
103
+ };
104
+ const message = this.extend(request, params);
105
+ return await this.watchMultiple(url, messageHashes, message, messageHashes);
106
+ }
83
107
  async watchTicker(symbol, params = {}) {
84
108
  /**
85
109
  * @method
86
110
  * @name bitvavo#watchTicker
87
111
  * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
112
+ * @see https://docs.bitvavo.com/#tag/Market-data-subscription-WebSocket/paths/~1subscribeTicker24h/post
88
113
  * @param {string} symbol unified symbol of the market to fetch the ticker for
89
114
  * @param {object} [params] extra parameters specific to the exchange API endpoint
90
115
  * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
91
116
  */
92
117
  return await this.watchPublic('ticker24h', symbol, params);
93
118
  }
119
+ async watchTickers(symbols = undefined, params = {}) {
120
+ /**
121
+ * @method
122
+ * @name bitvavo#watchTickers
123
+ * @description watches a price ticker, a statistical calculation with the information calculated over the past 24 hours for all markets of a specific list
124
+ * @see https://docs.bitvavo.com/#tag/Market-data-subscription-WebSocket/paths/~1subscribeTicker24h/post
125
+ * @param {string[]} [symbols] unified symbol of the market to fetch the ticker for
126
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
127
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
128
+ */
129
+ await this.loadMarkets();
130
+ symbols = this.marketSymbols(symbols, undefined, false);
131
+ const channel = 'ticker24h';
132
+ const tickers = await this.watchPublicMultiple(channel, channel, symbols, params);
133
+ return this.filterByArray(tickers, 'symbol', symbols);
134
+ }
94
135
  handleTicker(client, message) {
95
136
  //
96
137
  // {
@@ -113,8 +154,10 @@ export default class bitvavo extends bitvavoRest {
113
154
  // ]
114
155
  // }
115
156
  //
157
+ this.handleBidAsk(client, message);
116
158
  const event = this.safeString(message, 'event');
117
159
  const tickers = this.safeValue(message, 'data', []);
160
+ const result = [];
118
161
  for (let i = 0; i < tickers.length; i++) {
119
162
  const data = tickers[i];
120
163
  const marketId = this.safeString(data, 'market');
@@ -123,9 +166,57 @@ export default class bitvavo extends bitvavoRest {
123
166
  const ticker = this.parseTicker(data, market);
124
167
  const symbol = ticker['symbol'];
125
168
  this.tickers[symbol] = ticker;
169
+ result.push(ticker);
126
170
  client.resolve(ticker, messageHash);
127
171
  }
128
- return message;
172
+ client.resolve(result, event);
173
+ }
174
+ async watchBidsAsks(symbols = undefined, params = {}) {
175
+ /**
176
+ * @method
177
+ * @name mexc#watchBidsAsks
178
+ * @description watches best bid & ask for symbols
179
+ * @see https://docs.bitvavo.com/#tag/Market-data-subscription-WebSocket/paths/~1subscribeTicker24h/post
180
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
181
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
182
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
183
+ */
184
+ await this.loadMarkets();
185
+ symbols = this.marketSymbols(symbols, undefined, false);
186
+ const channel = 'ticker24h';
187
+ const tickers = await this.watchPublicMultiple('bidask', channel, symbols, params);
188
+ return this.filterByArray(tickers, 'symbol', symbols);
189
+ }
190
+ handleBidAsk(client, message) {
191
+ const event = 'bidask';
192
+ const tickers = this.safeValue(message, 'data', []);
193
+ const result = [];
194
+ for (let i = 0; i < tickers.length; i++) {
195
+ const data = tickers[i];
196
+ const ticker = this.parseWsBidAsk(data);
197
+ const symbol = ticker['symbol'];
198
+ this.bidsasks[symbol] = ticker;
199
+ result.push(ticker);
200
+ const messageHash = event + ':' + symbol;
201
+ client.resolve(ticker, messageHash);
202
+ }
203
+ client.resolve(result, event);
204
+ }
205
+ parseWsBidAsk(ticker, market = undefined) {
206
+ const marketId = this.safeString(ticker, 'market');
207
+ market = this.safeMarket(marketId, undefined, '-');
208
+ const symbol = this.safeString(market, 'symbol');
209
+ const timestamp = this.safeInteger(ticker, 'timestamp');
210
+ return this.safeTicker({
211
+ 'symbol': symbol,
212
+ 'timestamp': timestamp,
213
+ 'datetime': this.iso8601(timestamp),
214
+ 'ask': this.safeNumber(ticker, 'ask'),
215
+ 'askVolume': this.safeNumber(ticker, 'askSize'),
216
+ 'bid': this.safeNumber(ticker, 'bid'),
217
+ 'bidVolume': this.safeNumber(ticker, 'bidSize'),
218
+ 'info': ticker,
219
+ }, market);
129
220
  }
130
221
  async watchTrades(symbol, since = undefined, limit = undefined, params = {}) {
131
222
  /**
@@ -16,6 +16,9 @@ export default class blofin extends blofinRest {
16
16
  watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
17
17
  handleTicker(client: Client, message: any): void;
18
18
  parseWsTicker(ticker: any, market?: Market): Ticker;
19
+ watchBidsAsks(symbols?: Strings, params?: {}): Promise<Tickers>;
20
+ handleBidAsk(client: Client, message: any): void;
21
+ parseWsBidAsk(ticker: any, market?: any): Ticker;
19
22
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
20
23
  watchOHLCVForSymbols(symbolsAndTimeframes: string[][], since?: Int, limit?: Int, params?: {}): Promise<import("../base/types.js").Dictionary<import("../base/types.js").Dictionary<OHLCV[]>>>;
21
24
  handleOHLCV(client: Client, message: any): void;
@@ -21,6 +21,7 @@ export default class blofin extends blofinRest {
21
21
  'watchOrderBookForSymbols': true,
22
22
  'watchTicker': true,
23
23
  'watchTickers': true,
24
+ 'watchBidsAsks': true,
24
25
  'watchOHLCV': true,
25
26
  'watchOHLCVForSymbols': true,
26
27
  'watchOrders': true,
@@ -273,6 +274,7 @@ export default class blofin extends blofinRest {
273
274
  // ],
274
275
  // }
275
276
  //
277
+ this.handleBidAsk(client, message);
276
278
  const arg = this.safeDict(message, 'arg');
277
279
  const channelName = this.safeString(arg, 'channel');
278
280
  const data = this.safeList(message, 'data');
@@ -287,6 +289,68 @@ export default class blofin extends blofinRest {
287
289
  parseWsTicker(ticker, market = undefined) {
288
290
  return this.parseTicker(ticker, market);
289
291
  }
292
+ async watchBidsAsks(symbols = undefined, params = {}) {
293
+ /**
294
+ * @method
295
+ * @name blofin#watchBidsAsks
296
+ * @description watches best bid & ask for symbols
297
+ * @see https://docs.blofin.com/index.html#ws-tickers-channel
298
+ * @param {string[]} symbols unified symbol of the market to fetch the ticker for
299
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
300
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
301
+ */
302
+ await this.loadMarkets();
303
+ symbols = this.marketSymbols(symbols, undefined, false);
304
+ const firstMarket = this.market(symbols[0]);
305
+ const channel = 'tickers';
306
+ let marketType = undefined;
307
+ [marketType, params] = this.handleMarketTypeAndParams('watchBidsAsks', firstMarket, params);
308
+ const url = this.implodeHostname(this.urls['api']['ws'][marketType]['public']);
309
+ const messageHashes = [];
310
+ const args = [];
311
+ for (let i = 0; i < symbols.length; i++) {
312
+ const market = this.market(symbols[i]);
313
+ messageHashes.push('bidask:' + market['symbol']);
314
+ args.push({
315
+ 'channel': channel,
316
+ 'instId': market['id'],
317
+ });
318
+ }
319
+ const request = this.getSubscriptionRequest(args);
320
+ const ticker = await this.watchMultiple(url, messageHashes, this.deepExtend(request, params), messageHashes);
321
+ if (this.newUpdates) {
322
+ const tickers = {};
323
+ tickers[ticker['symbol']] = ticker;
324
+ return tickers;
325
+ }
326
+ return this.filterByArray(this.bidsasks, 'symbol', symbols);
327
+ }
328
+ handleBidAsk(client, message) {
329
+ const data = this.safeList(message, 'data');
330
+ for (let i = 0; i < data.length; i++) {
331
+ const ticker = this.parseWsBidAsk(data[i]);
332
+ const symbol = ticker['symbol'];
333
+ const messageHash = 'bidask:' + symbol;
334
+ this.bidsasks[symbol] = ticker;
335
+ client.resolve(ticker, messageHash);
336
+ }
337
+ }
338
+ parseWsBidAsk(ticker, market = undefined) {
339
+ const marketId = this.safeString(ticker, 'instId');
340
+ market = this.safeMarket(marketId, market, '-');
341
+ const symbol = this.safeString(market, 'symbol');
342
+ const timestamp = this.safeInteger(ticker, 'ts');
343
+ return this.safeTicker({
344
+ 'symbol': symbol,
345
+ 'timestamp': timestamp,
346
+ 'datetime': this.iso8601(timestamp),
347
+ 'ask': this.safeString(ticker, 'askPrice'),
348
+ 'askVolume': this.safeString(ticker, 'askSize'),
349
+ 'bid': this.safeString(ticker, 'bidPrice'),
350
+ 'bidVolume': this.safeString(ticker, 'bidSize'),
351
+ 'info': ticker,
352
+ }, market);
353
+ }
290
354
  async watchOHLCV(symbol, timeframe = '1m', since = undefined, limit = undefined, params = {}) {
291
355
  /**
292
356
  * @method
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.4.7",
3
+ "version": "4.4.8",
4
4
  "description": "A JavaScript / TypeScript / Python / C# / PHP cryptocurrency trading library with support for 100+ exchanges",
5
5
  "unpkg": "dist/ccxt.browser.min.js",
6
6
  "type": "module",