ccxt 4.3.95 → 4.3.96

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 (45) hide show
  1. package/README.md +4 -4
  2. package/dist/ccxt.browser.min.js +3 -3
  3. package/dist/cjs/ccxt.js +1 -7
  4. package/dist/cjs/src/base/Exchange.js +0 -4
  5. package/dist/cjs/src/bingx.js +2 -1
  6. package/dist/cjs/src/blofin.js +0 -1
  7. package/dist/cjs/src/bybit.js +8 -2
  8. package/dist/cjs/src/hyperliquid.js +262 -32
  9. package/dist/cjs/src/kucoin.js +12 -12
  10. package/dist/cjs/src/mexc.js +6 -0
  11. package/dist/cjs/src/okx.js +0 -1
  12. package/dist/cjs/src/p2b.js +0 -1
  13. package/dist/cjs/src/pro/binance.js +100 -2
  14. package/dist/cjs/src/pro/bybit.js +65 -4
  15. package/dist/cjs/src/pro/cryptocom.js +224 -0
  16. package/dist/cjs/src/pro/okx.js +264 -35
  17. package/dist/cjs/src/tradeogre.js +0 -1
  18. package/js/ccxt.d.ts +2 -8
  19. package/js/ccxt.js +2 -6
  20. package/js/src/base/Exchange.d.ts +0 -2
  21. package/js/src/base/Exchange.js +0 -4
  22. package/js/src/bingx.js +2 -1
  23. package/js/src/blofin.js +0 -1
  24. package/js/src/bybit.js +8 -2
  25. package/js/src/hyperliquid.d.ts +22 -0
  26. package/js/src/hyperliquid.js +262 -32
  27. package/js/src/kucoin.d.ts +1 -1
  28. package/js/src/kucoin.js +12 -12
  29. package/js/src/mexc.js +6 -0
  30. package/js/src/okx.js +0 -1
  31. package/js/src/p2b.js +0 -1
  32. package/js/src/pro/binance.d.ts +2 -0
  33. package/js/src/pro/binance.js +100 -2
  34. package/js/src/pro/bybit.d.ts +3 -1
  35. package/js/src/pro/bybit.js +65 -4
  36. package/js/src/pro/cryptocom.d.ts +10 -1
  37. package/js/src/pro/cryptocom.js +225 -1
  38. package/js/src/pro/okx.d.ts +10 -1
  39. package/js/src/pro/okx.js +264 -35
  40. package/js/src/tradeogre.js +0 -1
  41. package/package.json +1 -1
  42. package/js/src/abstract/bitbay.d.ts +0 -56
  43. package/js/src/abstract/bitbay.js +0 -11
  44. package/js/src/abstract/hitbtc3.d.ts +0 -118
  45. package/js/src/abstract/hitbtc3.js +0 -11
@@ -1035,14 +1035,25 @@ export default class binance extends binanceRest {
1035
1035
  const error = new UnsubscribeError(this.id + ' ' + subHash);
1036
1036
  client.reject(error, subHash);
1037
1037
  client.resolve(true, unsubHash);
1038
- this.cleanCache(subscription);
1039
1038
  }
1039
+ this.cleanCache(subscription);
1040
1040
  }
1041
1041
  cleanCache(subscription) {
1042
1042
  const topic = this.safeString(subscription, 'topic');
1043
1043
  const symbols = this.safeList(subscription, 'symbols', []);
1044
1044
  const symbolsLength = symbols.length;
1045
- if (symbolsLength > 0) {
1045
+ if (topic === 'ohlcv') {
1046
+ const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
1047
+ for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
1048
+ const symbolAndTimeFrame = symbolsAndTimeFrames[i];
1049
+ const symbol = this.safeString(symbolAndTimeFrame, 0);
1050
+ const timeframe = this.safeString(symbolAndTimeFrame, 1);
1051
+ if (timeframe in this.ohlcvs[symbol]) {
1052
+ delete this.ohlcvs[symbol][timeframe];
1053
+ }
1054
+ }
1055
+ }
1056
+ else if (symbolsLength > 0) {
1046
1057
  for (let i = 0; i < symbols.length; i++) {
1047
1058
  const symbol = symbols[i];
1048
1059
  if (topic === 'trade') {
@@ -1510,6 +1521,93 @@ export default class binance extends binanceRest {
1510
1521
  const filtered = this.filterBySinceLimit(candles, since, limit, 0, true);
1511
1522
  return this.createOHLCVObject(symbol, timeframe, filtered);
1512
1523
  }
1524
+ async unWatchOHLCVForSymbols(symbolsAndTimeframes, params = {}) {
1525
+ /**
1526
+ * @method
1527
+ * @name binance#unWatchOHLCVForSymbols
1528
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1529
+ * @see https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-data
1530
+ * @see https://binance-docs.github.io/apidocs/futures/en/#kline-candlestick-data
1531
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#kline-candlestick-data
1532
+ * @param {string[][]} symbolsAndTimeframes array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
1533
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1534
+ * @param {object} [params.timezone] if provided, kline intervals are interpreted in that timezone instead of UTC, example '+08:00'
1535
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1536
+ */
1537
+ await this.loadMarkets();
1538
+ let klineType = undefined;
1539
+ [klineType, params] = this.handleParamString2(params, 'channel', 'name', 'kline');
1540
+ const symbols = this.getListFromObjectValues(symbolsAndTimeframes, 0);
1541
+ const marketSymbols = this.marketSymbols(symbols, undefined, false, false, true);
1542
+ const firstMarket = this.market(marketSymbols[0]);
1543
+ let type = firstMarket['type'];
1544
+ if (firstMarket['contract']) {
1545
+ type = firstMarket['linear'] ? 'future' : 'delivery';
1546
+ }
1547
+ const isSpot = (type === 'spot');
1548
+ let timezone = undefined;
1549
+ [timezone, params] = this.handleParamString(params, 'timezone', undefined);
1550
+ const isUtc8 = (timezone !== undefined) && ((timezone === '+08:00') || Precise.stringEq(timezone, '8'));
1551
+ const rawHashes = [];
1552
+ const subMessageHashes = [];
1553
+ const messageHashes = [];
1554
+ for (let i = 0; i < symbolsAndTimeframes.length; i++) {
1555
+ const symAndTf = symbolsAndTimeframes[i];
1556
+ const symbolString = symAndTf[0];
1557
+ const timeframeString = symAndTf[1];
1558
+ const interval = this.safeString(this.timeframes, timeframeString, timeframeString);
1559
+ const market = this.market(symbolString);
1560
+ let marketId = market['lowercaseId'];
1561
+ if (klineType === 'indexPriceKline') {
1562
+ // weird behavior for index price kline we can't use the perp suffix
1563
+ marketId = marketId.replace('_perp', '');
1564
+ }
1565
+ const shouldUseUTC8 = (isUtc8 && isSpot);
1566
+ const suffix = '@+08:00';
1567
+ const utcSuffix = shouldUseUTC8 ? suffix : '';
1568
+ rawHashes.push(marketId + '@' + klineType + '_' + interval + utcSuffix);
1569
+ subMessageHashes.push('ohlcv::' + market['symbol'] + '::' + timeframeString);
1570
+ messageHashes.push('unsubscribe::ohlcv::' + market['symbol'] + '::' + timeframeString);
1571
+ }
1572
+ const url = this.urls['api']['ws'][type] + '/' + this.stream(type, 'multipleOHLCV');
1573
+ const requestId = this.requestId(url);
1574
+ const request = {
1575
+ 'method': 'UNSUBSCRIBE',
1576
+ 'params': rawHashes,
1577
+ 'id': requestId,
1578
+ };
1579
+ const subscribe = {
1580
+ 'unsubscribe': true,
1581
+ 'id': requestId.toString(),
1582
+ 'symbols': symbols,
1583
+ 'symbolsAndTimeframes': symbolsAndTimeframes,
1584
+ 'subMessageHashes': subMessageHashes,
1585
+ 'messageHashes': messageHashes,
1586
+ 'topic': 'ohlcv',
1587
+ };
1588
+ params = this.omit(params, 'callerMethodName');
1589
+ return await this.watchMultiple(url, messageHashes, this.extend(request, params), messageHashes, subscribe);
1590
+ }
1591
+ async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
1592
+ /**
1593
+ * @method
1594
+ * @name binance#unWatchOHLCV
1595
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
1596
+ * @see https://binance-docs.github.io/apidocs/spot/en/#kline-candlestick-data
1597
+ * @see https://binance-docs.github.io/apidocs/futures/en/#kline-candlestick-data
1598
+ * @see https://binance-docs.github.io/apidocs/delivery/en/#kline-candlestick-data
1599
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
1600
+ * @param {string} timeframe the length of time each candle represents
1601
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
1602
+ * @param {object} [params.timezone] if provided, kline intervals are interpreted in that timezone instead of UTC, example '+08:00'
1603
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
1604
+ */
1605
+ await this.loadMarkets();
1606
+ const market = this.market(symbol);
1607
+ symbol = market['symbol'];
1608
+ params['callerMethodName'] = 'watchOHLCV';
1609
+ return await this.unWatchOHLCVForSymbols([[symbol, timeframe]], params);
1610
+ }
1513
1611
  handleOHLCV(client, message) {
1514
1612
  //
1515
1613
  // {
@@ -16,6 +16,8 @@ export default class bybit extends bybitRest {
16
16
  handleTicker(client: Client, message: any): void;
17
17
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
18
18
  watchOHLCVForSymbols(symbolsAndTimeframes: string[][], since?: Int, limit?: Int, params?: {}): Promise<import("../base/types.js").Dictionary<import("../base/types.js").Dictionary<OHLCV[]>>>;
19
+ unWatchOHLCVForSymbols(symbolsAndTimeframes: string[][], params?: {}): Promise<any>;
20
+ unWatchOHLCV(symbol: string, timeframe?: string, params?: {}): Promise<any>;
19
21
  handleOHLCV(client: Client, message: any): void;
20
22
  parseWsOHLCV(ohlcv: any, market?: any): OHLCV;
21
23
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
@@ -51,7 +53,7 @@ export default class bybit extends bybitRest {
51
53
  handleBalance(client: Client, message: any): void;
52
54
  parseWsBalance(balance: any, accountType?: any): void;
53
55
  watchTopics(url: any, messageHashes: any, topics: any, params?: {}): Promise<any>;
54
- unWatchTopics(url: string, topic: string, symbols: string[], messageHashes: string[], subMessageHashes: string[], topics: any, params?: {}): Promise<any>;
56
+ unWatchTopics(url: string, topic: string, symbols: string[], messageHashes: string[], subMessageHashes: string[], topics: any, params?: {}, subExtension?: {}): Promise<any>;
55
57
  authenticate(url: any, params?: {}): Promise<any>;
56
58
  handleErrorMessage(client: Client, message: any): boolean;
57
59
  handleMessage(client: Client, message: any): void;
@@ -636,6 +636,58 @@ export default class bybit extends bybitRest {
636
636
  const filtered = this.filterBySinceLimit(stored, since, limit, 0, true);
637
637
  return this.createOHLCVObject(symbol, timeframe, filtered);
638
638
  }
639
+ async unWatchOHLCVForSymbols(symbolsAndTimeframes, params = {}) {
640
+ /**
641
+ * @method
642
+ * @name bybit#unWatchOHLCVForSymbols
643
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
644
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/kline
645
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/etp-kline
646
+ * @param {string[][]} symbolsAndTimeframes array of arrays containing unified symbols and timeframes to fetch OHLCV data for, example [['BTC/USDT', '1m'], ['LTC/USDT', '5m']]
647
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
648
+ * @returns {object} A list of candles ordered as timestamp, open, high, low, close, volume
649
+ */
650
+ await this.loadMarkets();
651
+ const symbols = this.getListFromObjectValues(symbolsAndTimeframes, 0);
652
+ const marketSymbols = this.marketSymbols(symbols, undefined, false, true, true);
653
+ const firstSymbol = marketSymbols[0];
654
+ const url = await this.getUrlByMarketType(firstSymbol, false, 'watchOHLCVForSymbols', params);
655
+ const rawHashes = [];
656
+ const subMessageHashes = [];
657
+ const messageHashes = [];
658
+ for (let i = 0; i < symbolsAndTimeframes.length; i++) {
659
+ const data = symbolsAndTimeframes[i];
660
+ let symbolString = this.safeString(data, 0);
661
+ const market = this.market(symbolString);
662
+ symbolString = market['symbol'];
663
+ const unfiedTimeframe = this.safeString(data, 1);
664
+ const timeframeId = this.safeString(this.timeframes, unfiedTimeframe, unfiedTimeframe);
665
+ rawHashes.push('kline.' + timeframeId + '.' + market['id']);
666
+ subMessageHashes.push('ohlcv::' + symbolString + '::' + unfiedTimeframe);
667
+ messageHashes.push('unsubscribe::ohlcv::' + symbolString + '::' + unfiedTimeframe);
668
+ }
669
+ const subExtension = {
670
+ 'symbolsAndTimeframes': symbolsAndTimeframes,
671
+ };
672
+ return await this.unWatchTopics(url, 'ohlcv', symbols, messageHashes, subMessageHashes, rawHashes, params, subExtension);
673
+ }
674
+ async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
675
+ /**
676
+ * @method
677
+ * @name bybit#unWatchOHLCV
678
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
679
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/kline
680
+ * @see https://bybit-exchange.github.io/docs/v5/websocket/public/etp-kline
681
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
682
+ * @param {string} timeframe the length of time each candle represents
683
+ * @param {int} [since] timestamp in ms of the earliest candle to fetch
684
+ * @param {int} [limit] the maximum amount of candles to fetch
685
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
686
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
687
+ */
688
+ params['callerMethodName'] = 'watchOHLCV';
689
+ return await this.unWatchOHLCVForSymbols([[symbol, timeframe]], params);
690
+ }
639
691
  handleOHLCV(client, message) {
640
692
  //
641
693
  // {
@@ -2145,7 +2197,7 @@ export default class bybit extends bybitRest {
2145
2197
  const message = this.extend(request, params);
2146
2198
  return await this.watchMultiple(url, messageHashes, message, messageHashes);
2147
2199
  }
2148
- async unWatchTopics(url, topic, symbols, messageHashes, subMessageHashes, topics, params = {}) {
2200
+ async unWatchTopics(url, topic, symbols, messageHashes, subMessageHashes, topics, params = {}, subExtension = {}) {
2149
2201
  const reqId = this.requestId();
2150
2202
  const request = {
2151
2203
  'op': 'unsubscribe',
@@ -2160,7 +2212,7 @@ export default class bybit extends bybitRest {
2160
2212
  'symbols': symbols,
2161
2213
  };
2162
2214
  const message = this.extend(request, params);
2163
- return await this.watchMultiple(url, messageHashes, message, messageHashes, subscription);
2215
+ return await this.watchMultiple(url, messageHashes, message, messageHashes, this.extend(subscription, subExtension));
2164
2216
  }
2165
2217
  async authenticate(url, params = {}) {
2166
2218
  this.checkRequiredCredentials();
@@ -2443,8 +2495,8 @@ export default class bybit extends bybitRest {
2443
2495
  const error = new UnsubscribeError(this.id + ' ' + messageHash);
2444
2496
  client.reject(error, subHash);
2445
2497
  client.resolve(true, unsubHash);
2446
- this.cleanCache(subscription);
2447
2498
  }
2499
+ this.cleanCache(subscription);
2448
2500
  }
2449
2501
  }
2450
2502
  return message;
@@ -2453,7 +2505,16 @@ export default class bybit extends bybitRest {
2453
2505
  const topic = this.safeString(subscription, 'topic');
2454
2506
  const symbols = this.safeList(subscription, 'symbols', []);
2455
2507
  const symbolsLength = symbols.length;
2456
- if (symbolsLength > 0) {
2508
+ if (topic === 'ohlcv') {
2509
+ const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
2510
+ for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
2511
+ const symbolAndTimeFrame = symbolsAndTimeFrames[i];
2512
+ const symbol = this.safeString(symbolAndTimeFrame, 0);
2513
+ const timeframe = this.safeString(symbolAndTimeFrame, 1);
2514
+ delete this.ohlcvs[symbol][timeframe];
2515
+ }
2516
+ }
2517
+ else if (symbolsLength > 0) {
2457
2518
  for (let i = 0; i < symbols.length; i++) {
2458
2519
  const symbol = symbols[i];
2459
2520
  if (topic === 'trade') {
@@ -1,21 +1,27 @@
1
1
  import cryptocomRest from '../cryptocom.js';
2
- import type { Int, OrderSide, OrderType, Str, Strings, OrderBook, Order, Trade, Ticker, OHLCV, Position, Balances, Num } from '../base/types.js';
2
+ import type { Int, OrderSide, OrderType, Str, Strings, OrderBook, Order, Trade, Ticker, OHLCV, Position, Balances, Num, Dict } from '../base/types.js';
3
3
  import Client from '../base/ws/Client.js';
4
4
  export default class cryptocom extends cryptocomRest {
5
5
  describe(): any;
6
6
  pong(client: any, message: any): Promise<void>;
7
7
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
8
+ unWatchOrderBook(symbol: string, params?: {}): Promise<any>;
8
9
  watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
10
+ unWatchOrderBookForSymbols(symbols: string[], params?: {}): Promise<OrderBook>;
9
11
  handleDelta(bookside: any, delta: any): void;
10
12
  handleDeltas(bookside: any, deltas: any): void;
11
13
  handleOrderBook(client: Client, message: any): void;
12
14
  watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
15
+ unWatchTrades(symbol: string, params?: {}): Promise<Trade[]>;
13
16
  watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
17
+ unWatchTradesForSymbols(symbols: string[], params?: {}): Promise<any>;
14
18
  handleTrades(client: Client, message: any): void;
15
19
  watchMyTrades(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
16
20
  watchTicker(symbol: string, params?: {}): Promise<Ticker>;
21
+ unWatchTicker(symbol: string, params?: {}): Promise<any>;
17
22
  handleTicker(client: Client, message: any): void;
18
23
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
24
+ unWatchOHLCV(symbol: string, timeframe?: string, params?: {}): Promise<any>;
19
25
  handleOHLCV(client: Client, message: any): void;
20
26
  watchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
21
27
  handleOrders(client: Client, message: any, subscription?: any): void;
@@ -32,6 +38,7 @@ export default class cryptocom extends cryptocomRest {
32
38
  handleCancelAllOrders(client: Client, message: any): void;
33
39
  watchPublic(messageHash: any, params?: {}): Promise<any>;
34
40
  watchPublicMultiple(messageHashes: any, topics: any, params?: {}): Promise<any>;
41
+ unWatchPublicMultiple(topic: string, symbols: string[], messageHashes: string[], subMessageHashes: string[], topics: string[], params?: {}, subExtend?: {}): Promise<any>;
35
42
  watchPrivateRequest(nonce: any, params?: {}): Promise<any>;
36
43
  watchPrivateSubscribe(messageHash: any, params?: {}): Promise<any>;
37
44
  handleErrorMessage(client: Client, message: any): boolean;
@@ -40,4 +47,6 @@ export default class cryptocom extends cryptocomRest {
40
47
  authenticate(params?: {}): Promise<any>;
41
48
  handlePing(client: Client, message: any): void;
42
49
  handleAuthenticate(client: Client, message: any): void;
50
+ handleUnsubscribe(client: Client, message: any): void;
51
+ cleanCache(subscription: Dict): void;
43
52
  }
@@ -6,7 +6,7 @@
6
6
 
7
7
  // ---------------------------------------------------------------------------
8
8
  import cryptocomRest from '../cryptocom.js';
9
- import { AuthenticationError, ChecksumError, ExchangeError, NetworkError } from '../base/errors.js';
9
+ import { AuthenticationError, ChecksumError, ExchangeError, NetworkError, UnsubscribeError } 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
  // ---------------------------------------------------------------------------
@@ -83,6 +83,20 @@ export default class cryptocom extends cryptocomRest {
83
83
  */
84
84
  return await this.watchOrderBookForSymbols([symbol], limit, params);
85
85
  }
86
+ async unWatchOrderBook(symbol, params = {}) {
87
+ /**
88
+ * @method
89
+ * @name cryptocom#unWatchOrderBook
90
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
91
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#book-instrument_name
92
+ * @param {string} symbol unified symbol of the market to fetch the order book for
93
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
94
+ * @param {string} [params.bookSubscriptionType] The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
95
+ * @param {int} [params.bookUpdateFrequency] Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
96
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
97
+ */
98
+ return await this.unWatchOrderBookForSymbols([symbol], params);
99
+ }
86
100
  async watchOrderBookForSymbols(symbols, limit = undefined, params = {}) {
87
101
  /**
88
102
  * @method
@@ -130,6 +144,52 @@ export default class cryptocom extends cryptocomRest {
130
144
  const orderbook = await this.watchPublicMultiple(messageHashes, topics, params);
131
145
  return orderbook.limit();
132
146
  }
147
+ async unWatchOrderBookForSymbols(symbols, params = {}) {
148
+ /**
149
+ * @method
150
+ * @name cryptocom#unWatchOrderBookForSymbols
151
+ * @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
152
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#book-instrument_name
153
+ * @param {string[]} symbols unified array of symbols
154
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
155
+ * @param {int} [params.limit] orderbook limit, default is 50
156
+ * @param {string} [params.bookSubscriptionType] The subscription type. Allowed values: SNAPSHOT full snapshot. This is the default if not specified. SNAPSHOT_AND_UPDATE delta updates
157
+ * @param {int} [params.bookUpdateFrequency] Book update interval in ms. Allowed values: 100 for snapshot subscription 10 for delta subscription
158
+ * @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
159
+ */
160
+ await this.loadMarkets();
161
+ symbols = this.marketSymbols(symbols);
162
+ const topics = [];
163
+ const subMessageHashes = [];
164
+ const messageHashes = [];
165
+ const limit = this.safeInteger(params, 'limit', 50);
166
+ const topicParams = this.safeValue(params, 'params');
167
+ if (topicParams === undefined) {
168
+ params['params'] = {};
169
+ }
170
+ let bookSubscriptionType = undefined;
171
+ let bookSubscriptionType2 = undefined;
172
+ [bookSubscriptionType, params] = this.handleOptionAndParams(params, 'watchOrderBook', 'bookSubscriptionType', 'SNAPSHOT_AND_UPDATE');
173
+ [bookSubscriptionType2, params] = this.handleOptionAndParams(params, 'watchOrderBookForSymbols', 'bookSubscriptionType', bookSubscriptionType);
174
+ params['params']['bookSubscriptionType'] = bookSubscriptionType2;
175
+ let bookUpdateFrequency = undefined;
176
+ let bookUpdateFrequency2 = undefined;
177
+ [bookUpdateFrequency, params] = this.handleOptionAndParams(params, 'watchOrderBook', 'bookUpdateFrequency');
178
+ [bookUpdateFrequency2, params] = this.handleOptionAndParams(params, 'watchOrderBookForSymbols', 'bookUpdateFrequency', bookUpdateFrequency);
179
+ if (bookUpdateFrequency2 !== undefined) {
180
+ params['params']['bookSubscriptionType'] = bookUpdateFrequency2;
181
+ }
182
+ for (let i = 0; i < symbols.length; i++) {
183
+ const symbol = symbols[i];
184
+ const market = this.market(symbol);
185
+ const currentTopic = 'book' + '.' + market['id'] + '.' + limit.toString();
186
+ const messageHash = 'orderbook:' + market['symbol'];
187
+ subMessageHashes.push(messageHash);
188
+ messageHashes.push('unsubscribe:' + messageHash);
189
+ topics.push(currentTopic);
190
+ }
191
+ return await this.unWatchPublicMultiple('orderbook', symbols, messageHashes, subMessageHashes, topics, params);
192
+ }
133
193
  handleDelta(bookside, delta) {
134
194
  const price = this.safeFloat(delta, 0);
135
195
  const amount = this.safeFloat(delta, 1);
@@ -250,6 +310,20 @@ export default class cryptocom extends cryptocomRest {
250
310
  */
251
311
  return await this.watchTradesForSymbols([symbol], since, limit, params);
252
312
  }
313
+ async unWatchTrades(symbol, params = {}) {
314
+ /**
315
+ * @method
316
+ * @name cryptocom#unWatchTrades
317
+ * @description get the list of most recent trades for a particular symbol
318
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#trade-instrument_name
319
+ * @param {string} symbol unified symbol of the market to fetch trades for
320
+ * @param {int} [since] timestamp in ms of the earliest trade to fetch
321
+ * @param {int} [limit] the maximum amount of trades to fetch
322
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
323
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
324
+ */
325
+ return await this.unWatchTradesForSymbols([symbol], params);
326
+ }
253
327
  async watchTradesForSymbols(symbols, since = undefined, limit = undefined, params = {}) {
254
328
  /**
255
329
  * @method
@@ -279,6 +353,29 @@ export default class cryptocom extends cryptocomRest {
279
353
  }
280
354
  return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
281
355
  }
356
+ async unWatchTradesForSymbols(symbols, params = {}) {
357
+ /**
358
+ * @method
359
+ * @name cryptocom#unWatchTradesForSymbols
360
+ * @description get the list of most recent trades for a particular symbol
361
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#trade-instrument_name
362
+ * @param {string} symbol unified symbol of the market to fetch trades for
363
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
364
+ * @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
365
+ */
366
+ await this.loadMarkets();
367
+ symbols = this.marketSymbols(symbols);
368
+ const topics = [];
369
+ const messageHashes = [];
370
+ for (let i = 0; i < symbols.length; i++) {
371
+ const symbol = symbols[i];
372
+ const market = this.market(symbol);
373
+ const currentTopic = 'trade' + '.' + market['id'];
374
+ messageHashes.push('unsubscribe:trades:' + market['symbol']);
375
+ topics.push(currentTopic);
376
+ }
377
+ return await this.unWatchPublicMultiple('trade', symbols, messageHashes, topics, topics, params);
378
+ }
282
379
  handleTrades(client, message) {
283
380
  //
284
381
  // {
@@ -367,6 +464,22 @@ export default class cryptocom extends cryptocomRest {
367
464
  const messageHash = 'ticker' + '.' + market['id'];
368
465
  return await this.watchPublic(messageHash, params);
369
466
  }
467
+ async unWatchTicker(symbol, params = {}) {
468
+ /**
469
+ * @method
470
+ * @name cryptocom#unWatchTicker
471
+ * @description unWatches a price ticker, a statistical calculation with the information calculated over the past 24 hours for a specific market
472
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#ticker-instrument_name
473
+ * @param {string} symbol unified symbol of the market to fetch the ticker for
474
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
475
+ * @returns {object} a [ticker structure]{@link https://docs.ccxt.com/#/?id=ticker-structure}
476
+ */
477
+ await this.loadMarkets();
478
+ const market = this.market(symbol);
479
+ const subMessageHash = 'ticker' + '.' + market['id'];
480
+ const messageHash = 'unsubscribe:ticker:' + market['symbol'];
481
+ return await this.unWatchPublicMultiple('ticker', [market['symbol']], [messageHash], [subMessageHash], [subMessageHash], params);
482
+ }
370
483
  handleTicker(client, message) {
371
484
  //
372
485
  // {
@@ -426,6 +539,28 @@ export default class cryptocom extends cryptocomRest {
426
539
  }
427
540
  return this.filterBySinceLimit(ohlcv, since, limit, 0, true);
428
541
  }
542
+ async unWatchOHLCV(symbol, timeframe = '1m', params = {}) {
543
+ /**
544
+ * @method
545
+ * @name cryptocom#unWatchOHLCV
546
+ * @description unWatches historical candlestick data containing the open, high, low, and close price, and the volume of a market
547
+ * @see https://exchange-docs.crypto.com/exchange/v1/rest-ws/index.html#candlestick-time_frame-instrument_name
548
+ * @param {string} symbol unified symbol of the market to fetch OHLCV data for
549
+ * @param {string} timeframe the length of time each candle represents
550
+ * @param {object} [params] extra parameters specific to the exchange API endpoint
551
+ * @returns {int[][]} A list of candles ordered as timestamp, open, high, low, close, volume
552
+ */
553
+ await this.loadMarkets();
554
+ const market = this.market(symbol);
555
+ symbol = market['symbol'];
556
+ const interval = this.safeString(this.timeframes, timeframe, timeframe);
557
+ const subMessageHash = 'candlestick' + '.' + interval + '.' + market['id'];
558
+ const messageHash = 'unsubscribe:ohlcv:' + market['symbol'] + ':' + timeframe;
559
+ const subExtend = {
560
+ 'symbolsAndTimeframes': [[market['symbol'], timeframe]],
561
+ };
562
+ return await this.unWatchPublicMultiple('ohlcv', [market['symbol']], [messageHash], [subMessageHash], [subMessageHash], params, subExtend);
563
+ }
429
564
  handleOHLCV(client, message) {
430
565
  //
431
566
  // {
@@ -856,6 +991,27 @@ export default class cryptocom extends cryptocomRest {
856
991
  const message = this.deepExtend(request, params);
857
992
  return await this.watchMultiple(url, messageHashes, message, messageHashes);
858
993
  }
994
+ async unWatchPublicMultiple(topic, symbols, messageHashes, subMessageHashes, topics, params = {}, subExtend = {}) {
995
+ const url = this.urls['api']['ws']['public'];
996
+ const id = this.nonce();
997
+ const request = {
998
+ 'method': 'unsubscribe',
999
+ 'params': {
1000
+ 'channels': topics,
1001
+ },
1002
+ 'nonce': id,
1003
+ 'id': id.toString(),
1004
+ };
1005
+ const subscription = {
1006
+ 'id': id.toString(),
1007
+ 'topic': topic,
1008
+ 'symbols': symbols,
1009
+ 'subMessageHashes': subMessageHashes,
1010
+ 'messageHashes': messageHashes,
1011
+ };
1012
+ const message = this.deepExtend(request, params);
1013
+ return await this.watchMultiple(url, messageHashes, message, messageHashes, this.extend(subscription, subExtend));
1014
+ }
859
1015
  async watchPrivateRequest(nonce, params = {}) {
860
1016
  await this.authenticate();
861
1017
  const url = this.urls['api']['ws']['private'];
@@ -975,6 +1131,9 @@ export default class cryptocom extends cryptocomRest {
975
1131
  // "channel":"ticker",
976
1132
  // "data":[ { } ]
977
1133
  //
1134
+ // handle unsubscribe
1135
+ // {"id":1725448572836,"method":"unsubscribe","code":0}
1136
+ //
978
1137
  if (this.handleErrorMessage(client, message)) {
979
1138
  return;
980
1139
  }
@@ -988,6 +1147,7 @@ export default class cryptocom extends cryptocomRest {
988
1147
  'private/cancel-all-orders': this.handleCancelAllOrders,
989
1148
  'private/close-position': this.handleOrder,
990
1149
  'subscribe': this.handleSubscribe,
1150
+ 'unsubscribe': this.handleUnsubscribe,
991
1151
  };
992
1152
  const callMethod = this.safeValue(methods, method);
993
1153
  if (callMethod !== undefined) {
@@ -1028,4 +1188,68 @@ export default class cryptocom extends cryptocomRest {
1028
1188
  const future = this.safeValue(client.futures, 'authenticated');
1029
1189
  future.resolve(true);
1030
1190
  }
1191
+ handleUnsubscribe(client, message) {
1192
+ const id = this.safeString(message, 'id');
1193
+ const keys = Object.keys(client.subscriptions);
1194
+ for (let i = 0; i < keys.length; i++) {
1195
+ const messageHash = keys[i];
1196
+ if (!(messageHash in client.subscriptions)) {
1197
+ continue;
1198
+ // the previous iteration can have deleted the messageHash from the subscriptions
1199
+ }
1200
+ if (messageHash.startsWith('unsubscribe')) {
1201
+ const subscription = client.subscriptions[messageHash];
1202
+ const subId = this.safeString(subscription, 'id');
1203
+ if (id !== subId) {
1204
+ continue;
1205
+ }
1206
+ const messageHashes = this.safeList(subscription, 'messageHashes', []);
1207
+ const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
1208
+ for (let j = 0; j < messageHashes.length; j++) {
1209
+ const unsubHash = messageHashes[j];
1210
+ const subHash = subMessageHashes[j];
1211
+ if (unsubHash in client.subscriptions) {
1212
+ delete client.subscriptions[unsubHash];
1213
+ }
1214
+ if (subHash in client.subscriptions) {
1215
+ delete client.subscriptions[subHash];
1216
+ }
1217
+ const error = new UnsubscribeError(this.id + ' ' + subHash);
1218
+ client.reject(error, subHash);
1219
+ client.resolve(true, unsubHash);
1220
+ }
1221
+ this.cleanCache(subscription);
1222
+ }
1223
+ }
1224
+ }
1225
+ cleanCache(subscription) {
1226
+ const topic = this.safeString(subscription, 'topic');
1227
+ const symbols = this.safeList(subscription, 'symbols', []);
1228
+ const symbolsLength = symbols.length;
1229
+ if (topic === 'ohlcv') {
1230
+ const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
1231
+ for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
1232
+ const symbolAndTimeFrame = symbolsAndTimeFrames[i];
1233
+ const symbol = this.safeString(symbolAndTimeFrame, 0);
1234
+ const timeframe = this.safeString(symbolAndTimeFrame, 1);
1235
+ if (timeframe in this.ohlcvs[symbol]) {
1236
+ delete this.ohlcvs[symbol][timeframe];
1237
+ }
1238
+ }
1239
+ }
1240
+ else if (symbolsLength > 0) {
1241
+ for (let i = 0; i < symbols.length; i++) {
1242
+ const symbol = symbols[i];
1243
+ if (topic === 'trade') {
1244
+ delete this.trades[symbol];
1245
+ }
1246
+ else if (topic === 'orderbook') {
1247
+ delete this.orderbooks[symbol];
1248
+ }
1249
+ else if (topic === 'ticker') {
1250
+ delete this.tickers[symbol];
1251
+ }
1252
+ }
1253
+ }
1254
+ }
1031
1255
  }
@@ -15,8 +15,13 @@ export default class okx extends okxRest {
15
15
  watchFundingRates(symbols: string[], params?: {}): Promise<FundingRates>;
16
16
  handleFundingRate(client: Client, message: any): void;
17
17
  watchTicker(symbol: string, params?: {}): Promise<Ticker>;
18
+ unWatchTicker(symbol: string, params?: {}): Promise<any>;
18
19
  watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
19
- handleTicker(client: Client, message: any): any;
20
+ unWatchTickers(symbols?: Strings, params?: {}): Promise<any>;
21
+ handleTicker(client: Client, message: any): void;
22
+ watchBidsAsks(symbols?: Strings, params?: {}): Promise<Tickers>;
23
+ handleBidAsk(client: Client, message: any): void;
24
+ parseWsBidAsk(ticker: any, market?: any): Ticker;
20
25
  watchLiquidationsForSymbols(symbols?: string[], since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
21
26
  handleLiquidation(client: Client, message: any): void;
22
27
  watchMyLiquidationsForSymbols(symbols?: string[], since?: Int, limit?: Int, params?: {}): Promise<Liquidation[]>;
@@ -24,7 +29,9 @@ export default class okx extends okxRest {
24
29
  parseWsMyLiquidation(liquidation: any, market?: any): Liquidation;
25
30
  parseWsLiquidation(liquidation: any, market?: any): Liquidation;
26
31
  watchOHLCV(symbol: string, timeframe?: string, since?: Int, limit?: Int, params?: {}): Promise<OHLCV[]>;
32
+ unWatchOHLCV(symbol: string, timeframe?: string, params?: {}): Promise<any>;
27
33
  watchOHLCVForSymbols(symbolsAndTimeframes: string[][], since?: Int, limit?: Int, params?: {}): Promise<import("../base/types.js").Dictionary<import("../base/types.js").Dictionary<OHLCV[]>>>;
34
+ unWatchOHLCVForSymbols(symbolsAndTimeframes: string[][], params?: {}): Promise<any>;
28
35
  handleOHLCV(client: Client, message: any): void;
29
36
  watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
30
37
  watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
@@ -60,5 +67,7 @@ export default class okx extends okxRest {
60
67
  handleMessage(client: Client, message: any): void;
61
68
  handleUnSubscriptionTrades(client: Client, symbol: string): void;
62
69
  handleUnsubscriptionOrderBook(client: Client, symbol: string, channel: string): void;
70
+ handleUnsubscriptionOHLCV(client: Client, symbol: string, channel: string): void;
71
+ handleUnsubscriptionTicker(client: Client, symbol: string, channel: any): void;
63
72
  handleUnsubscription(client: Client, message: any): void;
64
73
  }