ccxt 4.4.1 → 4.4.2

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 (48) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -1
  4. package/dist/cjs/src/base/Exchange.js +69 -0
  5. package/dist/cjs/src/binance.js +78 -8
  6. package/dist/cjs/src/cryptocom.js +1 -1
  7. package/dist/cjs/src/currencycom.js +1 -2
  8. package/dist/cjs/src/htx.js +1 -1
  9. package/dist/cjs/src/mexc.js +69 -1
  10. package/dist/cjs/src/pro/binance.js +3 -63
  11. package/dist/cjs/src/pro/bitget.js +1 -9
  12. package/dist/cjs/src/pro/bitmex.js +11 -1
  13. package/dist/cjs/src/pro/bybit.js +2 -54
  14. package/dist/cjs/src/pro/cryptocom.js +2 -40
  15. package/dist/cjs/src/pro/gate.js +1 -9
  16. package/dist/cjs/src/pro/hyperliquid.js +4 -36
  17. package/dist/cjs/src/pro/kucoin.js +2 -59
  18. package/dist/cjs/src/pro/kucoinfutures.js +139 -1
  19. package/dist/cjs/src/pro/okx.js +8 -36
  20. package/dist/cjs/src/xt.js +1 -1
  21. package/examples/js/cli.js +8 -4
  22. package/js/ccxt.d.ts +3 -3
  23. package/js/ccxt.js +1 -1
  24. package/js/src/base/Exchange.d.ts +2 -0
  25. package/js/src/base/Exchange.js +70 -1
  26. package/js/src/base/types.d.ts +5 -4
  27. package/js/src/binance.js +78 -8
  28. package/js/src/cryptocom.js +1 -1
  29. package/js/src/currencycom.js +1 -2
  30. package/js/src/htx.js +1 -1
  31. package/js/src/mexc.js +69 -1
  32. package/js/src/pro/binance.d.ts +0 -1
  33. package/js/src/pro/binance.js +4 -64
  34. package/js/src/pro/bitget.js +1 -9
  35. package/js/src/pro/bitmex.js +11 -1
  36. package/js/src/pro/bybit.d.ts +1 -2
  37. package/js/src/pro/bybit.js +3 -55
  38. package/js/src/pro/cryptocom.d.ts +1 -2
  39. package/js/src/pro/cryptocom.js +3 -41
  40. package/js/src/pro/gate.js +2 -10
  41. package/js/src/pro/hyperliquid.js +5 -37
  42. package/js/src/pro/kucoin.d.ts +0 -1
  43. package/js/src/pro/kucoin.js +3 -60
  44. package/js/src/pro/kucoinfutures.d.ts +7 -1
  45. package/js/src/pro/kucoinfutures.js +139 -1
  46. package/js/src/pro/okx.js +9 -37
  47. package/js/src/xt.js +1 -1
  48. package/package.json +1 -1
@@ -178,6 +178,27 @@ export default class kucoinfutures extends kucoinfuturesRest {
178
178
  };
179
179
  return await this.watchMultiple(url, messageHashes, this.extend(request, params), subscriptionHashes, subscriptionArgs);
180
180
  }
181
+ async unSubscribeMultiple(url, messageHashes, topic, subscriptionHashes, params = {}, subscription = undefined) {
182
+ const requestId = this.requestId().toString();
183
+ const request = {
184
+ 'id': requestId,
185
+ 'type': 'unsubscribe',
186
+ 'topic': topic,
187
+ 'response': true,
188
+ };
189
+ const message = this.extend(request, params);
190
+ if (subscription !== undefined) {
191
+ subscription[requestId] = requestId;
192
+ }
193
+ const client = this.client(url);
194
+ for (let i = 0; i < subscriptionHashes.length; i++) {
195
+ const subscriptionHash = subscriptionHashes[i];
196
+ if (!(subscriptionHash in client.subscriptions)) {
197
+ client.subscriptions[requestId] = subscriptionHash;
198
+ }
199
+ }
200
+ return await this.watchMultiple(url, messageHashes, message, subscriptionHashes, subscription);
201
+ }
181
202
  async watchTicker(symbol, params = {}) {
182
203
  /**
183
204
  * @method
@@ -521,7 +542,7 @@ export default class kucoinfutures extends kucoinfuturesRest {
521
542
  async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
522
543
  /**
523
544
  * @method
524
- * @name kucoinfutures#watchTrades
545
+ * @name kucoinfutures#watchTradesForSymbols
525
546
  * @description get the list of most recent trades for a particular symbol
526
547
  * @param {string} symbol unified symbol of the market to fetch trades for
527
548
  * @param {int} [since] timestamp in ms of the earliest trade to fetch
@@ -555,6 +576,49 @@ export default class kucoinfutures extends kucoinfuturesRest {
555
576
  }
556
577
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
557
578
  }
579
+ async unWatchTrades(symbol, params = {}) {
580
+ /**
581
+ * @method
582
+ * @name kucoinfutures#unWatchTrades
583
+ * @description unWatches trades stream
584
+ * @see https://docs.kucoin.com/futures/#execution-data
585
+ * @param {string} symbol unified symbol of the market to fetch trades for
586
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
587
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
588
+ */
589
+ return await this.unWatchTradesForSymbols([symbol], params);
590
+ }
591
+ async unWatchTradesForSymbols(symbols, params = {}) {
592
+ /**
593
+ * @method
594
+ * @name kucoinfutures#unWatchTradesForSymbols
595
+ * @description get the list of most recent trades for a particular symbol
596
+ * @param {string} symbol unified symbol of the market to fetch trades for
597
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
598
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
599
+ */
600
+ await this.loadMarkets();
601
+ symbols = this.marketSymbols(symbols, undefined, false);
602
+ const url = await this.negotiate(false);
603
+ symbols = this.marketSymbols(symbols);
604
+ const marketIds = this.marketIds(symbols);
605
+ const topic = '/contractMarket/execution:' + marketIds.join(',');
606
+ const subscriptionHashes = [];
607
+ const messageHashes = [];
608
+ for (let i = 0; i < symbols.length; i++) {
609
+ const symbol = symbols[i];
610
+ messageHashes.push('unsubscribe:trades:' + symbol);
611
+ subscriptionHashes.push('trades:' + symbol);
612
+ }
613
+ const subscription = {
614
+ 'messageHashes': messageHashes,
615
+ 'subMessageHashes': subscriptionHashes,
616
+ 'topic': 'trades',
617
+ 'unsubscribe': true,
618
+ 'symbols': symbols,
619
+ };
620
+ return await this.unSubscribeMultiple(url, messageHashes, topic, messageHashes, params, subscription);
621
+ }
558
622
  handleTrade(client, message) {
559
623
  //
560
624
  // {
@@ -689,6 +753,7 @@ export default class kucoinfutures extends kucoinfuturesRest {
689
753
  * @method
690
754
  * @name kucoinfutures#watchOrderBookForSymbols
691
755
  * @description watches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
756
+ * @see https://docs.kucoin.com/futures/#level-2-market-data
692
757
  * @param {string[]} symbols unified array of symbols
693
758
  * @param {int} [limit] the maximum amount of order book entries to return
694
759
  * @param {object} [params] extra parameters specific to the exchange API endpoint
@@ -722,6 +787,48 @@ export default class kucoinfutures extends kucoinfuturesRest {
722
787
  const orderbook = await this.subscribeMultiple(url, messageHashes, topic, subscriptionHashes, subscriptionArgs, params);
723
788
  return orderbook.limit();
724
789
  }
790
+ async unWatchOrderBook(symbol, params = {}) {
791
+ /**
792
+ * @method
793
+ * @name kucoinfutures#unWatchOrderBook
794
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
795
+ * @see https://docs.kucoin.com/futures/#level-2-market-data
796
+ * @param {string} symbol unified symbol of the market to fetch the order book for
797
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
798
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
799
+ */
800
+ return await this.unWatchOrderBookForSymbols([symbol], params);
801
+ }
802
+ async unWatchOrderBookForSymbols(symbols, params = {}) {
803
+ /**
804
+ * @method
805
+ * @name kucoinfutures#unWatchOrderBookForSymbols
806
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
807
+ * @param {string[]} symbols unified array of symbols
808
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
809
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
810
+ */
811
+ await this.loadMarkets();
812
+ symbols = this.marketSymbols(symbols);
813
+ const marketIds = this.marketIds(symbols);
814
+ const url = await this.negotiate(false);
815
+ const topic = '/contractMarket/level2:' + marketIds.join(',');
816
+ const subscriptionHashes = [];
817
+ const messageHashes = [];
818
+ for (let i = 0; i < symbols.length; i++) {
819
+ const symbol = symbols[i];
820
+ messageHashes.push('unsubscribe:orderbook:' + symbol);
821
+ subscriptionHashes.push('orderbook:' + symbol);
822
+ }
823
+ const subscription = {
824
+ 'messageHashes': messageHashes,
825
+ 'symbols': symbols,
826
+ 'unsubscribe': true,
827
+ 'topic': 'orderbook',
828
+ 'subMessageHashes': subscriptionHashes,
829
+ };
830
+ return await this.unSubscribeMultiple(url, messageHashes, topic, messageHashes, params, subscription);
831
+ }
725
832
  handleDelta(orderbook, delta) {
726
833
  orderbook['nonce'] = this.safeInteger(delta, 'sequence');
727
834
  const timestamp = this.safeInteger(delta, 'timestamp');
@@ -1139,6 +1246,36 @@ export default class kucoinfutures extends kucoinfuturesRest {
1139
1246
  }
1140
1247
  this.handleErrors(undefined, undefined, client.url, undefined, undefined, data, message, undefined, undefined);
1141
1248
  }
1249
+ handleSubscriptionStatus(client, message) {
1250
+ //
1251
+ // {
1252
+ // "id": "1578090438322",
1253
+ // "type": "ack"
1254
+ // }
1255
+ //
1256
+ const id = this.safeString(message, 'id');
1257
+ if (!(id in client.subscriptions)) {
1258
+ return;
1259
+ }
1260
+ const subscriptionHash = this.safeString(client.subscriptions, id);
1261
+ const subscription = this.safeValue(client.subscriptions, subscriptionHash);
1262
+ delete client.subscriptions[id];
1263
+ const method = this.safeValue(subscription, 'method');
1264
+ if (method !== undefined) {
1265
+ method.call(this, client, message, subscription);
1266
+ }
1267
+ const isUnSub = this.safeBool(subscription, 'unsubscribe', false);
1268
+ if (isUnSub) {
1269
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
1270
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
1271
+ for (let i = 0; i < messageHashes.length; i++) {
1272
+ const messageHash = messageHashes[i];
1273
+ const subHash = subMessageHashes[i];
1274
+ this.cleanUnsubscription(client, subHash, messageHash);
1275
+ }
1276
+ this.cleanCache(subscription);
1277
+ }
1278
+ }
1142
1279
  handleMessage(client, message) {
1143
1280
  const type = this.safeString(message, 'type');
1144
1281
  const methods = {
@@ -1147,6 +1284,7 @@ export default class kucoinfutures extends kucoinfuturesRest {
1147
1284
  'message': this.handleSubject,
1148
1285
  'pong': this.handlePong,
1149
1286
  'error': this.handleErrorMessage,
1287
+ 'ack': this.handleSubscriptionStatus,
1150
1288
  };
1151
1289
  const method = this.safeValue(methods, type);
1152
1290
  if (method !== undefined) {
package/js/src/pro/okx.js CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import okxRest from '../okx.js';
9
- import { ArgumentsRequired, BadRequest, ExchangeError, ChecksumError, AuthenticationError, InvalidNonce, UnsubscribeError } from '../base/errors.js';
9
+ import { ArgumentsRequired, BadRequest, ExchangeError, ChecksumError, AuthenticationError, InvalidNonce } from '../base/errors.js';
10
10
  import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide } from '../base/ws/Cache.js';
11
11
  import { sha256 } from '../static_dependencies/noble-hashes/sha256.js';
12
12
  // ---------------------------------------------------------------------------
@@ -2336,64 +2336,36 @@ export default class okx extends okxRest {
2336
2336
  handleUnSubscriptionTrades(client, symbol) {
2337
2337
  const subMessageHash = 'trades:' + symbol;
2338
2338
  const messageHash = 'unsubscribe:trades:' + symbol;
2339
- if (subMessageHash in client.subscriptions) {
2340
- delete client.subscriptions[subMessageHash];
2339
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2340
+ if (symbol in this.trades) {
2341
+ delete this.trades[symbol];
2341
2342
  }
2342
- if (messageHash in client.subscriptions) {
2343
- delete client.subscriptions[messageHash];
2344
- }
2345
- delete this.trades[symbol];
2346
- const error = new UnsubscribeError(this.id + ' ' + subMessageHash);
2347
- client.reject(error, subMessageHash);
2348
- client.resolve(true, messageHash);
2349
2343
  }
2350
2344
  handleUnsubscriptionOrderBook(client, symbol, channel) {
2351
2345
  const subMessageHash = channel + ':' + symbol;
2352
2346
  const messageHash = 'unsubscribe:orderbook:' + symbol;
2353
- if (subMessageHash in client.subscriptions) {
2354
- delete client.subscriptions[subMessageHash];
2355
- }
2356
- if (messageHash in client.subscriptions) {
2357
- delete client.subscriptions[messageHash];
2347
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2348
+ if (symbol in this.orderbooks) {
2349
+ delete this.orderbooks[symbol];
2358
2350
  }
2359
- delete this.orderbooks[symbol];
2360
- const error = new UnsubscribeError(this.id + ' ' + subMessageHash);
2361
- client.reject(error, subMessageHash);
2362
- client.resolve(true, messageHash);
2363
2351
  }
2364
2352
  handleUnsubscriptionOHLCV(client, symbol, channel) {
2365
2353
  const tf = channel.replace('candle', '');
2366
2354
  const timeframe = this.findTimeframe(tf);
2367
2355
  const subMessageHash = 'multi:' + channel + ':' + symbol;
2368
2356
  const messageHash = 'unsubscribe:' + subMessageHash;
2369
- if (subMessageHash in client.subscriptions) {
2370
- delete client.subscriptions[subMessageHash];
2371
- }
2372
- if (messageHash in client.subscriptions) {
2373
- delete client.subscriptions[messageHash];
2374
- }
2357
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2375
2358
  if (timeframe in this.ohlcvs[symbol]) {
2376
2359
  delete this.ohlcvs[symbol][timeframe];
2377
2360
  }
2378
- const error = new UnsubscribeError(this.id + ' ' + subMessageHash);
2379
- client.reject(error, subMessageHash);
2380
- client.resolve(true, messageHash);
2381
2361
  }
2382
2362
  handleUnsubscriptionTicker(client, symbol, channel) {
2383
2363
  const subMessageHash = channel + '::' + symbol;
2384
2364
  const messageHash = 'unsubscribe:ticker:' + symbol;
2385
- if (subMessageHash in client.subscriptions) {
2386
- delete client.subscriptions[subMessageHash];
2387
- }
2388
- if (messageHash in client.subscriptions) {
2389
- delete client.subscriptions[messageHash];
2390
- }
2365
+ this.cleanUnsubscription(client, subMessageHash, messageHash);
2391
2366
  if (symbol in this.tickers) {
2392
2367
  delete this.tickers[symbol];
2393
2368
  }
2394
- const error = new UnsubscribeError(this.id + ' ' + subMessageHash);
2395
- client.reject(error, subMessageHash);
2396
- client.resolve(true, messageHash);
2397
2369
  }
2398
2370
  handleUnsubscription(client, message) {
2399
2371
  //
package/js/src/xt.js CHANGED
@@ -1375,7 +1375,7 @@ export default class xt extends Exchange {
1375
1375
  this.safeNumber(ohlcv, 'h'),
1376
1376
  this.safeNumber(ohlcv, 'l'),
1377
1377
  this.safeNumber(ohlcv, 'c'),
1378
- this.safeNumber2(ohlcv, volumeIndex, 'v'),
1378
+ this.safeNumber2(ohlcv, 'q', volumeIndex),
1379
1379
  ];
1380
1380
  }
1381
1381
  async fetchOrderBook(symbol, limit = undefined, params = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ccxt",
3
- "version": "4.4.1",
3
+ "version": "4.4.2",
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",