batch subscribe for spot v3

This commit is contained in:
tiagosiebler
2022-09-28 10:11:29 +01:00
parent 7fa82e099a
commit 1f19306477
3 changed files with 146 additions and 20 deletions

View File

@@ -16,10 +16,10 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// market: 'linear',
// market: 'inverse',
// market: 'spot',
// market: 'spotv3',
market: 'spotv3',
// market: 'usdcOption',
// market: 'usdcPerp',
market: 'unifiedPerp',
// market: 'unifiedPerp',
// market: 'unifiedOption',
},
logger
@@ -59,9 +59,73 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// wsClient.subscribe('trade.BTCUSDT');
// Spot V3
// wsClient.subscribe('trade.BTCUSDT');
wsClient.subscribe('trade.BTCUSDT');
// Or an array of topics
// wsClient.subscribe(['trade.BTCUSDT', 'trade.LTCUSDT']);
// wsClient.subscribe([
// 'orderbook.40.BTCUSDT',
// 'orderbook.40.BTCUSDC',
// 'orderbook.40.USDCUSDT',
// 'orderbook.40.BTCDAI',
// 'orderbook.40.DAIUSDT',
// 'orderbook.40.ETHUSDT',
// 'orderbook.40.ETHUSDC',
// 'orderbook.40.ETHDAI',
// 'orderbook.40.XRPUSDT',
// 'orderbook.40.XRPUSDC',
// 'orderbook.40.EOSUSDT',
// 'orderbook.40.EOSUSDC',
// 'orderbook.40.DOTUSDT',
// 'orderbook.40.DOTUSDC',
// 'orderbook.40.XLMUSDT',
// 'orderbook.40.XLMUSDC',
// 'orderbook.40.LTCUSDT',
// 'orderbook.40.LTCUSDC',
// 'orderbook.40.DOGEUSDT',
// 'orderbook.40.DOGEUSDC',
// 'orderbook.40.BITUSDT',
// 'orderbook.40.BITUSDC',
// 'orderbook.40.BITDAI',
// 'orderbook.40.CHZUSDT',
// 'orderbook.40.CHZUSDC',
// 'orderbook.40.MANAUSDT',
// 'orderbook.40.MANAUSDC',
// 'orderbook.40.LINKUSDT',
// 'orderbook.40.LINKUSDC',
// 'orderbook.40.ICPUSDT',
// 'orderbook.40.ICPUSDC',
// 'orderbook.40.ADAUSDT',
// 'orderbook.40.ADAUSDC',
// 'orderbook.40.SOLUSDC',
// 'orderbook.40.SOLUSDT',
// 'orderbook.40.MATICUSDC',
// 'orderbook.40.MATICUSDT',
// 'orderbook.40.SANDUSDC',
// 'orderbook.40.SANDUSDT',
// 'orderbook.40.LUNCUSDC',
// 'orderbook.40.LUNCUSDT',
// 'orderbook.40.SLGUSDC',
// 'orderbook.40.SLGUSDT',
// 'orderbook.40.AVAXUSDC',
// 'orderbook.40.AVAXUSDT',
// 'orderbook.40.OPUSDC',
// 'orderbook.40.OPUSDT',
// 'orderbook.40.OKSEUSDC',
// 'orderbook.40.OKSEUSDT',
// 'orderbook.40.APEXUSDC',
// 'orderbook.40.APEXUSDT',
// 'orderbook.40.TRXUSDC',
// 'orderbook.40.TRXUSDT',
// 'orderbook.40.GMTUSDC',
// 'orderbook.40.GMTUSDT',
// 'orderbook.40.SHIBUSDC',
// 'orderbook.40.SHIBUSDT',
// 'orderbook.40.LDOUSDC',
// 'orderbook.40.LDOUSDT',
// 'orderbook.40.APEUSDC',
// 'orderbook.40.APEUSDT',
// 'orderbook.40.FILUSDC',
// 'orderbook.40.FILUSDT',
// ]);
// usdc options
// wsClient.subscribe([
@@ -74,28 +138,30 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// wsClient.subscribe('trade.BTCPERP');
// unified perps
wsClient.subscribe('publicTrade.BTCUSDT');
// wsClient.subscribe('publicTrade.BTCUSDT');
// For spot v1 (the old, deprecated client), request public connection first then send required topics on 'open'
// Not necessary for spot v3
// wsClient.connectPublic();
// To unsubscribe from topics:
// To unsubscribe from topics (after a 5 second delay, in this example):
// setTimeout(() => {
// console.log('unsubscribing');
// wsClient.unsubscribe('trade.BTCUSDT');
// }, 5 * 1000);
// Topics are tracked per websocket type
// Get a list of subscribed topics (e.g. for public v3 spot topics)
const publicSpotTopics = wsClient
.getWsStore()
.getTopics(WS_KEY_MAP.spotV3Public);
// Get a list of subscribed topics (e.g. for public v3 spot topics) (after a 5 second delay)
setTimeout(() => {
const publicSpotTopics = wsClient
.getWsStore()
.getTopics(WS_KEY_MAP.spotV3Public);
console.log('public spot topics: ', publicSpotTopics);
console.log('public spot topics: ', publicSpotTopics);
const privateSpotTopics = wsClient
.getWsStore()
.getTopics(WS_KEY_MAP.spotV3Private);
console.log('private spot topics: ', publicSpotTopics);
const privateSpotTopics = wsClient
.getWsStore()
.getTopics(WS_KEY_MAP.spotV3Private);
console.log('private spot topics: ', privateSpotTopics);
}, 5 * 1000);
})();