expose ws store

This commit is contained in:
tiagosiebler
2022-09-28 09:55:48 +01:00
parent 2971dd7f2b
commit 7fa82e099a
3 changed files with 25 additions and 3 deletions

View File

@@ -60,6 +60,8 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// Spot V3 // Spot V3
// wsClient.subscribe('trade.BTCUSDT'); // wsClient.subscribe('trade.BTCUSDT');
// Or an array of topics
// wsClient.subscribe(['trade.BTCUSDT', 'trade.LTCUSDT']);
// usdc options // usdc options
// wsClient.subscribe([ // wsClient.subscribe([
@@ -74,11 +76,26 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// unified perps // 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:
// setTimeout(() => { // setTimeout(() => {
// console.log('unsubscribing'); // console.log('unsubscribing');
// wsClient.unsubscribe('trade.BTCUSDT'); // wsClient.unsubscribe('trade.BTCUSDT');
// }, 5 * 1000); // }, 5 * 1000);
// For spot, request public connection first then send required topics on 'open' // Topics are tracked per websocket type
// wsClient.connectPublic(); // Get a list of subscribed topics (e.g. for public v3 spot topics)
const publicSpotTopics = wsClient
.getWsStore()
.getTopics(WS_KEY_MAP.spotV3Public);
console.log('public spot topics: ', publicSpotTopics);
const privateSpotTopics = wsClient
.getWsStore()
.getTopics(WS_KEY_MAP.spotV3Private);
console.log('private spot topics: ', publicSpotTopics);
})(); })();

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "3.0.1", "version": "3.0.2",
"description": "Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.", "description": "Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -174,6 +174,11 @@ export class WebsocketClient extends EventEmitter {
} }
} }
/** Get the WsStore that tracks websockets & topics */
public getWsStore(): WsStore {
return this.wsStore;
}
public isTestnet(): boolean { public isTestnet(): boolean {
return this.options.testnet === true; return this.options.testnet === true;
} }