ccxt 4.3.96 → 4.3.97
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.
- package/README.md +3 -3
- package/dist/ccxt.browser.min.js +2 -2
- package/dist/cjs/ccxt.js +1 -1
- package/dist/cjs/src/binance.js +3 -0
- package/dist/cjs/src/coinex.js +16 -3
- package/dist/cjs/src/pro/gate.js +179 -0
- package/dist/cjs/src/pro/kucoin.js +132 -0
- package/js/ccxt.d.ts +1 -1
- package/js/ccxt.js +1 -1
- package/js/src/binance.js +3 -0
- package/js/src/coinex.js +16 -3
- package/js/src/pro/gate.d.ts +7 -1
- package/js/src/pro/gate.js +180 -1
- package/js/src/pro/kucoin.d.ts +5 -1
- package/js/src/pro/kucoin.js +133 -1
- package/package.json +1 -1
package/js/src/pro/gate.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
import gateRest from '../gate.js';
|
|
9
|
-
import { AuthenticationError, BadRequest, ArgumentsRequired, ChecksumError, ExchangeError, NotSupported } from '../base/errors.js';
|
|
9
|
+
import { AuthenticationError, BadRequest, ArgumentsRequired, ChecksumError, ExchangeError, NotSupported, UnsubscribeError } from '../base/errors.js';
|
|
10
10
|
import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById, ArrayCacheBySymbolBySide } from '../base/ws/Cache.js';
|
|
11
11
|
import { sha512 } from '../static_dependencies/noble-hashes/sha512.js';
|
|
12
12
|
import Precise from '../base/Precise.js';
|
|
@@ -388,6 +388,34 @@ export default class gate extends gateRest {
|
|
|
388
388
|
const orderbook = await this.subscribePublic(url, messageHash, payload, channel, query, subscription);
|
|
389
389
|
return orderbook.limit();
|
|
390
390
|
}
|
|
391
|
+
async unWatchOrderBook(symbol, params = {}) {
|
|
392
|
+
/**
|
|
393
|
+
* @method
|
|
394
|
+
* @name gate#unWatchOrderBook
|
|
395
|
+
* @description unWatches information on open orders with bid (buy) and ask (sell) prices, volumes and other data
|
|
396
|
+
* @param {string} symbol unified symbol of the market to fetch the order book for
|
|
397
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
398
|
+
* @returns {object} A dictionary of [order book structures]{@link https://docs.ccxt.com/#/?id=order-book-structure} indexed by market symbols
|
|
399
|
+
*/
|
|
400
|
+
await this.loadMarkets();
|
|
401
|
+
const market = this.market(symbol);
|
|
402
|
+
symbol = market['symbol'];
|
|
403
|
+
const marketId = market['id'];
|
|
404
|
+
let interval = '100ms';
|
|
405
|
+
[interval, params] = this.handleOptionAndParams(params, 'watchOrderBook', 'interval', interval);
|
|
406
|
+
const messageType = this.getTypeByMarket(market);
|
|
407
|
+
const channel = messageType + '.order_book_update';
|
|
408
|
+
const subMessageHash = 'orderbook' + ':' + symbol;
|
|
409
|
+
const messageHash = 'unsubscribe:orderbook' + ':' + symbol;
|
|
410
|
+
const url = this.getUrlByMarket(market);
|
|
411
|
+
const payload = [marketId, interval];
|
|
412
|
+
const limit = this.safeInteger(params, 'limit', 100);
|
|
413
|
+
if (market['contract']) {
|
|
414
|
+
const stringLimit = limit.toString();
|
|
415
|
+
payload.push(stringLimit);
|
|
416
|
+
}
|
|
417
|
+
return await this.unSubscribePublicMultiple(url, 'orderbook', [symbol], [messageHash], [subMessageHash], payload, channel, params);
|
|
418
|
+
}
|
|
391
419
|
handleOrderBookSubscription(client, message, subscription) {
|
|
392
420
|
const symbol = this.safeString(subscription, 'symbol');
|
|
393
421
|
const limit = this.safeInteger(subscription, 'limit');
|
|
@@ -720,6 +748,42 @@ export default class gate extends gateRest {
|
|
|
720
748
|
}
|
|
721
749
|
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
722
750
|
}
|
|
751
|
+
async unWatchTradesForSymbols(symbols, params = {}) {
|
|
752
|
+
/**
|
|
753
|
+
* @method
|
|
754
|
+
* @name gate#unWatchTradesForSymbols
|
|
755
|
+
* @description get the list of most recent trades for a particular symbol
|
|
756
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
757
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
758
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
759
|
+
*/
|
|
760
|
+
await this.loadMarkets();
|
|
761
|
+
symbols = this.marketSymbols(symbols);
|
|
762
|
+
const marketIds = this.marketIds(symbols);
|
|
763
|
+
const market = this.market(symbols[0]);
|
|
764
|
+
const messageType = this.getTypeByMarket(market);
|
|
765
|
+
const channel = messageType + '.trades';
|
|
766
|
+
const subMessageHashes = [];
|
|
767
|
+
const messageHashes = [];
|
|
768
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
769
|
+
const symbol = symbols[i];
|
|
770
|
+
subMessageHashes.push('trades:' + symbol);
|
|
771
|
+
messageHashes.push('unsubscribe:trades:' + symbol);
|
|
772
|
+
}
|
|
773
|
+
const url = this.getUrlByMarket(market);
|
|
774
|
+
return await this.unSubscribePublicMultiple(url, 'trades', symbols, messageHashes, subMessageHashes, marketIds, channel, params);
|
|
775
|
+
}
|
|
776
|
+
async unWatchTrades(symbol, params = {}) {
|
|
777
|
+
/**
|
|
778
|
+
* @method
|
|
779
|
+
* @name gate#unWatchTrades
|
|
780
|
+
* @description get the list of most recent trades for a particular symbol
|
|
781
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
782
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
783
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
784
|
+
*/
|
|
785
|
+
return await this.unWatchTradesForSymbols([symbol], params);
|
|
786
|
+
}
|
|
723
787
|
handleTrades(client, message) {
|
|
724
788
|
//
|
|
725
789
|
// {
|
|
@@ -1561,6 +1625,96 @@ export default class gate extends gateRest {
|
|
|
1561
1625
|
delete client.subscriptions[id];
|
|
1562
1626
|
}
|
|
1563
1627
|
}
|
|
1628
|
+
handleUnSubscribe(client, message) {
|
|
1629
|
+
//
|
|
1630
|
+
// {
|
|
1631
|
+
// "time":1725534679,
|
|
1632
|
+
// "time_ms":1725534679786,
|
|
1633
|
+
// "id":2,
|
|
1634
|
+
// "conn_id":"fac539b443fd7002",
|
|
1635
|
+
// "trace_id":"efe1d282b630b4aa266b84bee177791a",
|
|
1636
|
+
// "channel":"spot.trades",
|
|
1637
|
+
// "event":"unsubscribe",
|
|
1638
|
+
// "payload":[
|
|
1639
|
+
// "LTC_USDT"
|
|
1640
|
+
// ],
|
|
1641
|
+
// "result":{
|
|
1642
|
+
// "status":"success"
|
|
1643
|
+
// },
|
|
1644
|
+
// "requestId":"efe1d282b630b4aa266b84bee177791a"
|
|
1645
|
+
// }
|
|
1646
|
+
//
|
|
1647
|
+
const id = this.safeString(message, 'id');
|
|
1648
|
+
const keys = Object.keys(client.subscriptions);
|
|
1649
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1650
|
+
const messageHash = keys[i];
|
|
1651
|
+
if (!(messageHash in client.subscriptions)) {
|
|
1652
|
+
continue;
|
|
1653
|
+
// the previous iteration can have deleted the messageHash from the subscriptions
|
|
1654
|
+
}
|
|
1655
|
+
if (messageHash.startsWith('unsubscribe')) {
|
|
1656
|
+
const subscription = client.subscriptions[messageHash];
|
|
1657
|
+
const subId = this.safeString(subscription, 'id');
|
|
1658
|
+
if (id !== subId) {
|
|
1659
|
+
continue;
|
|
1660
|
+
}
|
|
1661
|
+
const messageHashes = this.safeList(subscription, 'messageHashes', []);
|
|
1662
|
+
const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
|
|
1663
|
+
for (let j = 0; j < messageHashes.length; j++) {
|
|
1664
|
+
const unsubHash = messageHashes[j];
|
|
1665
|
+
const subHash = subMessageHashes[j];
|
|
1666
|
+
if (unsubHash in client.subscriptions) {
|
|
1667
|
+
delete client.subscriptions[unsubHash];
|
|
1668
|
+
}
|
|
1669
|
+
if (subHash in client.subscriptions) {
|
|
1670
|
+
delete client.subscriptions[subHash];
|
|
1671
|
+
}
|
|
1672
|
+
const error = new UnsubscribeError(this.id + ' ' + messageHash);
|
|
1673
|
+
client.reject(error, subHash);
|
|
1674
|
+
client.resolve(true, unsubHash);
|
|
1675
|
+
}
|
|
1676
|
+
this.cleanCache(subscription);
|
|
1677
|
+
}
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
cleanCache(subscription) {
|
|
1681
|
+
const topic = this.safeString(subscription, 'topic', '');
|
|
1682
|
+
const symbols = this.safeList(subscription, 'symbols', []);
|
|
1683
|
+
const symbolsLength = symbols.length;
|
|
1684
|
+
if (topic === 'ohlcv') {
|
|
1685
|
+
const symbolsAndTimeFrames = this.safeList(subscription, 'symbolsAndTimeframes', []);
|
|
1686
|
+
for (let i = 0; i < symbolsAndTimeFrames.length; i++) {
|
|
1687
|
+
const symbolAndTimeFrame = symbolsAndTimeFrames[i];
|
|
1688
|
+
const symbol = this.safeString(symbolAndTimeFrame, 0);
|
|
1689
|
+
const timeframe = this.safeString(symbolAndTimeFrame, 1);
|
|
1690
|
+
delete this.ohlcvs[symbol][timeframe];
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
else if (symbolsLength > 0) {
|
|
1694
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
1695
|
+
const symbol = symbols[i];
|
|
1696
|
+
if (topic.endsWith('trades')) {
|
|
1697
|
+
delete this.trades[symbol];
|
|
1698
|
+
}
|
|
1699
|
+
else if (topic === 'orderbook') {
|
|
1700
|
+
delete this.orderbooks[symbol];
|
|
1701
|
+
}
|
|
1702
|
+
else if (topic === 'ticker') {
|
|
1703
|
+
delete this.tickers[symbol];
|
|
1704
|
+
}
|
|
1705
|
+
}
|
|
1706
|
+
}
|
|
1707
|
+
else {
|
|
1708
|
+
if (topic.endsWith('trades')) {
|
|
1709
|
+
// don't reset this.myTrades directly here
|
|
1710
|
+
// because in c# we need to use a different object
|
|
1711
|
+
const keys = Object.keys(this.trades);
|
|
1712
|
+
for (let i = 0; i < keys.length; i++) {
|
|
1713
|
+
delete this.trades[keys[i]];
|
|
1714
|
+
}
|
|
1715
|
+
}
|
|
1716
|
+
}
|
|
1717
|
+
}
|
|
1564
1718
|
handleMessage(client, message) {
|
|
1565
1719
|
//
|
|
1566
1720
|
// subscribe
|
|
@@ -1659,6 +1813,10 @@ export default class gate extends gateRest {
|
|
|
1659
1813
|
this.handleSubscriptionStatus(client, message);
|
|
1660
1814
|
return;
|
|
1661
1815
|
}
|
|
1816
|
+
if (event === 'unsubscribe') {
|
|
1817
|
+
this.handleUnSubscribe(client, message);
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1662
1820
|
const channel = this.safeString(message, 'channel', '');
|
|
1663
1821
|
const channelParts = channel.split('.');
|
|
1664
1822
|
const channelType = this.safeValue(channelParts, 1);
|
|
@@ -1778,6 +1936,27 @@ export default class gate extends gateRest {
|
|
|
1778
1936
|
const message = this.extend(request, params);
|
|
1779
1937
|
return await this.watchMultiple(url, messageHashes, message, messageHashes);
|
|
1780
1938
|
}
|
|
1939
|
+
async unSubscribePublicMultiple(url, topic, symbols, messageHashes, subMessageHashes, payload, channel, params = {}) {
|
|
1940
|
+
const requestId = this.requestId();
|
|
1941
|
+
const time = this.seconds();
|
|
1942
|
+
const request = {
|
|
1943
|
+
'id': requestId,
|
|
1944
|
+
'time': time,
|
|
1945
|
+
'channel': channel,
|
|
1946
|
+
'event': 'unsubscribe',
|
|
1947
|
+
'payload': payload,
|
|
1948
|
+
};
|
|
1949
|
+
const sub = {
|
|
1950
|
+
'id': requestId.toString(),
|
|
1951
|
+
'topic': topic,
|
|
1952
|
+
'unsubscribe': true,
|
|
1953
|
+
'messageHashes': messageHashes,
|
|
1954
|
+
'subMessageHashes': subMessageHashes,
|
|
1955
|
+
'symbols': symbols,
|
|
1956
|
+
};
|
|
1957
|
+
const message = this.extend(request, params);
|
|
1958
|
+
return await this.watchMultiple(url, messageHashes, message, messageHashes, sub);
|
|
1959
|
+
}
|
|
1781
1960
|
async authenticate(url, messageType) {
|
|
1782
1961
|
const channel = messageType + '.login';
|
|
1783
1962
|
const client = this.client(url);
|
package/js/src/pro/kucoin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import kucoinRest from '../kucoin.js';
|
|
2
|
-
import type { Int, Str, Strings, OrderBook, Order, Trade, Ticker, Tickers, OHLCV, Balances } from '../base/types.js';
|
|
2
|
+
import type { Int, Str, Strings, OrderBook, Order, Trade, Ticker, Tickers, OHLCV, Balances, Dict } from '../base/types.js';
|
|
3
3
|
import Client from '../base/ws/Client.js';
|
|
4
4
|
export default class kucoin extends kucoinRest {
|
|
5
5
|
describe(): any;
|
|
@@ -8,6 +8,7 @@ export default class kucoin extends kucoinRest {
|
|
|
8
8
|
requestId(): any;
|
|
9
9
|
subscribe(url: any, messageHash: any, subscriptionHash: any, params?: {}, subscription?: any): Promise<any>;
|
|
10
10
|
subscribeMultiple(url: any, messageHashes: any, topic: any, subscriptionHashes: any, params?: {}, subscription?: any): Promise<any>;
|
|
11
|
+
unSubscribeMultiple(url: any, messageHashes: any, topic: any, subscriptionHashes: any, params?: {}, subscription?: Dict): Promise<any>;
|
|
11
12
|
watchTicker(symbol: string, params?: {}): Promise<Ticker>;
|
|
12
13
|
watchTickers(symbols?: Strings, params?: {}): Promise<Tickers>;
|
|
13
14
|
handleTicker(client: Client, message: any): void;
|
|
@@ -19,6 +20,8 @@ export default class kucoin extends kucoinRest {
|
|
|
19
20
|
handleOHLCV(client: Client, message: any): void;
|
|
20
21
|
watchTrades(symbol: string, since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
|
21
22
|
watchTradesForSymbols(symbols: string[], since?: Int, limit?: Int, params?: {}): Promise<Trade[]>;
|
|
23
|
+
unWatchTradesForSymbols(symbols: string[], params?: {}): Promise<any>;
|
|
24
|
+
unWatchTrades(symbol: string, params?: {}): Promise<any>;
|
|
22
25
|
handleTrade(client: Client, message: any): void;
|
|
23
26
|
watchOrderBook(symbol: string, limit?: Int, params?: {}): Promise<OrderBook>;
|
|
24
27
|
watchOrderBookForSymbols(symbols: string[], limit?: Int, params?: {}): Promise<OrderBook>;
|
|
@@ -28,6 +31,7 @@ export default class kucoin extends kucoinRest {
|
|
|
28
31
|
handleBidAsks(bookSide: any, bidAsks: any): void;
|
|
29
32
|
handleOrderBookSubscription(client: Client, message: any, subscription: any): void;
|
|
30
33
|
handleSubscriptionStatus(client: Client, message: any): void;
|
|
34
|
+
cleanCache(subscription: Dict): void;
|
|
31
35
|
handleSystemStatus(client: Client, message: any): any;
|
|
32
36
|
watchOrders(symbol?: Str, since?: Int, limit?: Int, params?: {}): Promise<Order[]>;
|
|
33
37
|
parseWsOrderStatus(status: any): string;
|
package/js/src/pro/kucoin.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
8
|
import kucoinRest from '../kucoin.js';
|
|
9
|
-
import { ExchangeError, ArgumentsRequired } from '../base/errors.js';
|
|
9
|
+
import { ExchangeError, ArgumentsRequired, UnsubscribeError } from '../base/errors.js';
|
|
10
10
|
import { ArrayCache, ArrayCacheByTimestamp, ArrayCacheBySymbolById } from '../base/ws/Cache.js';
|
|
11
11
|
// ---------------------------------------------------------------------------
|
|
12
12
|
export default class kucoin extends kucoinRest {
|
|
@@ -157,6 +157,27 @@ export default class kucoin extends kucoinRest {
|
|
|
157
157
|
}
|
|
158
158
|
return await this.watchMultiple(url, messageHashes, message, subscriptionHashes, subscription);
|
|
159
159
|
}
|
|
160
|
+
async unSubscribeMultiple(url, messageHashes, topic, subscriptionHashes, params = {}, subscription = undefined) {
|
|
161
|
+
const requestId = this.requestId().toString();
|
|
162
|
+
const request = {
|
|
163
|
+
'id': requestId,
|
|
164
|
+
'type': 'unsubscribe',
|
|
165
|
+
'topic': topic,
|
|
166
|
+
'response': true,
|
|
167
|
+
};
|
|
168
|
+
const message = this.extend(request, params);
|
|
169
|
+
if (subscription !== undefined) {
|
|
170
|
+
subscription[requestId] = requestId;
|
|
171
|
+
}
|
|
172
|
+
const client = this.client(url);
|
|
173
|
+
for (let i = 0; i < subscriptionHashes.length; i++) {
|
|
174
|
+
const subscriptionHash = subscriptionHashes[i];
|
|
175
|
+
if (!(subscriptionHash in client.subscriptions)) {
|
|
176
|
+
client.subscriptions[requestId] = subscriptionHash;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return await this.watchMultiple(url, messageHashes, message, subscriptionHashes, subscription);
|
|
180
|
+
}
|
|
160
181
|
async watchTicker(symbol, params = {}) {
|
|
161
182
|
/**
|
|
162
183
|
* @method
|
|
@@ -510,6 +531,51 @@ export default class kucoin extends kucoinRest {
|
|
|
510
531
|
}
|
|
511
532
|
return this.filterBySinceLimit(trades, since, limit, 'timestamp', true);
|
|
512
533
|
}
|
|
534
|
+
async unWatchTradesForSymbols(symbols, params = {}) {
|
|
535
|
+
/**
|
|
536
|
+
* @method
|
|
537
|
+
* @name kucoin#unWatchTradesForSymbols
|
|
538
|
+
* @description unWatches trades stream
|
|
539
|
+
* @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/match-execution-data
|
|
540
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
541
|
+
* @param {int} [since] timestamp in ms of the earliest trade to fetch
|
|
542
|
+
* @param {int} [limit] the maximum amount of trades to fetch
|
|
543
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
544
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
545
|
+
*/
|
|
546
|
+
await this.loadMarkets();
|
|
547
|
+
symbols = this.marketSymbols(symbols, undefined, false);
|
|
548
|
+
const marketIds = this.marketIds(symbols);
|
|
549
|
+
const url = await this.negotiate(false);
|
|
550
|
+
const messageHashes = [];
|
|
551
|
+
const subscriptionHashes = [];
|
|
552
|
+
const topic = '/market/match:' + marketIds.join(',');
|
|
553
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
554
|
+
const symbol = symbols[i];
|
|
555
|
+
messageHashes.push('unsubscribe:trades:' + symbol);
|
|
556
|
+
subscriptionHashes.push('trades:' + symbol);
|
|
557
|
+
}
|
|
558
|
+
const subscription = {
|
|
559
|
+
'messageHashes': messageHashes,
|
|
560
|
+
'subMessageHashes': subscriptionHashes,
|
|
561
|
+
'topic': 'trades',
|
|
562
|
+
'unsubscribe': true,
|
|
563
|
+
'symbols': symbols,
|
|
564
|
+
};
|
|
565
|
+
return await this.unSubscribeMultiple(url, messageHashes, topic, messageHashes, params, subscription);
|
|
566
|
+
}
|
|
567
|
+
async unWatchTrades(symbol, params = {}) {
|
|
568
|
+
/**
|
|
569
|
+
* @method
|
|
570
|
+
* @name kucoin#unWatchTrades
|
|
571
|
+
* @description unWatches trades stream
|
|
572
|
+
* @see https://www.kucoin.com/docs/websocket/spot-trading/public-channels/match-execution-data
|
|
573
|
+
* @param {string} symbol unified symbol of the market to fetch trades for
|
|
574
|
+
* @param {object} [params] extra parameters specific to the exchange API endpoint
|
|
575
|
+
* @returns {object[]} a list of [trade structures]{@link https://docs.ccxt.com/#/?id=public-trades}
|
|
576
|
+
*/
|
|
577
|
+
return await this.unWatchTradesForSymbols([symbol], params);
|
|
578
|
+
}
|
|
513
579
|
handleTrade(client, message) {
|
|
514
580
|
//
|
|
515
581
|
// {
|
|
@@ -794,6 +860,72 @@ export default class kucoin extends kucoinRest {
|
|
|
794
860
|
if (method !== undefined) {
|
|
795
861
|
method.call(this, client, message, subscription);
|
|
796
862
|
}
|
|
863
|
+
const isUnSub = this.safeBool(subscription, 'unsubscribe', false);
|
|
864
|
+
if (isUnSub) {
|
|
865
|
+
const messageHashes = this.safeList(subscription, 'messageHashes', []);
|
|
866
|
+
const subMessageHashes = this.safeList(subscription, 'subMessageHashes', []);
|
|
867
|
+
for (let i = 0; i < messageHashes.length; i++) {
|
|
868
|
+
const messageHash = messageHashes[i];
|
|
869
|
+
const subHash = subMessageHashes[i];
|
|
870
|
+
if (messageHash in client.subscriptions) {
|
|
871
|
+
delete client.subscriptions[messageHash];
|
|
872
|
+
}
|
|
873
|
+
if (subHash in client.subscriptions) {
|
|
874
|
+
delete client.subscriptions[subHash];
|
|
875
|
+
}
|
|
876
|
+
const error = new UnsubscribeError(this.id + ' ' + subHash);
|
|
877
|
+
client.reject(error, subHash);
|
|
878
|
+
client.resolve(true, messageHash);
|
|
879
|
+
this.cleanCache(subscription);
|
|
880
|
+
}
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
cleanCache(subscription) {
|
|
884
|
+
const topic = this.safeString(subscription, 'topic');
|
|
885
|
+
const symbols = this.safeList(subscription, 'symbols', []);
|
|
886
|
+
const symbolsLength = symbols.length;
|
|
887
|
+
if (symbolsLength > 0) {
|
|
888
|
+
for (let i = 0; i < symbols.length; i++) {
|
|
889
|
+
const symbol = symbols[i];
|
|
890
|
+
if (topic === 'trades') {
|
|
891
|
+
if (symbol in this.trades) {
|
|
892
|
+
delete this.trades[symbol];
|
|
893
|
+
}
|
|
894
|
+
}
|
|
895
|
+
else if (topic === 'orderbook') {
|
|
896
|
+
if (symbol in this.orderbooks) {
|
|
897
|
+
delete this.orderbooks[symbol];
|
|
898
|
+
}
|
|
899
|
+
}
|
|
900
|
+
else if (topic === 'ticker') {
|
|
901
|
+
if (symbol in this.tickers) {
|
|
902
|
+
delete this.tickers[symbol];
|
|
903
|
+
}
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
}
|
|
907
|
+
else {
|
|
908
|
+
if (topic === 'myTrades') {
|
|
909
|
+
// don't reset this.myTrades directly here
|
|
910
|
+
// because in c# we need to use a different object
|
|
911
|
+
const keys = Object.keys(this.myTrades);
|
|
912
|
+
for (let i = 0; i < keys.length; i++) {
|
|
913
|
+
delete this.myTrades[keys[i]];
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
else if (topic === 'orders') {
|
|
917
|
+
const orderSymbols = Object.keys(this.orders);
|
|
918
|
+
for (let i = 0; i < orderSymbols.length; i++) {
|
|
919
|
+
delete this.orders[orderSymbols[i]];
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
else if (topic === 'ticker') {
|
|
923
|
+
const tickerSymbols = Object.keys(this.tickers);
|
|
924
|
+
for (let i = 0; i < tickerSymbols.length; i++) {
|
|
925
|
+
delete this.tickers[tickerSymbols[i]];
|
|
926
|
+
}
|
|
927
|
+
}
|
|
928
|
+
}
|
|
797
929
|
}
|
|
798
930
|
handleSystemStatus(client, message) {
|
|
799
931
|
//
|
package/package.json
CHANGED