diff --git a/README.md b/README.md index 4594f5a..a834bb2 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ client.getOrderBook({ symbol: 'BTCUSD' }) ``` ## WebSockets -All API groups can be used via a shared `WebsocketClient`. However, make sure to make one instance of the WebsocketClient per API group (spot vs inverse vs linear vs linearfutures etc): +All API groups can be used via a shared `WebsocketClient`. However, to listen to multiple API groups at once, you will need to make one WebsocketClient instance per API group. The WebsocketClient can be configured to a specific API group using the market parameter. These are the currently available API groups: | API Category | Market | Description | @@ -182,9 +182,14 @@ const wsConfig = { // NOTE: to listen to multiple markets (spot vs inverse vs linear vs linearfutures) at once, make one WebsocketClient instance per market - // market: 'inverse' - // market: 'linear' - // market: 'spot' + market: 'linear', + // market: 'inverse', + // market: 'spot', + // market: 'spotv3', + // market: 'usdcOption', + // market: 'usdcPerp', + // market: 'unifiedPerp', + // market: 'unifiedOption', // how long to wait (in ms) before deciding the connection should be terminated & reconnected // pongTimeout: 1000, diff --git a/examples/ws-public.ts b/examples/ws-public.ts index 6f2ae90..8834d5a 100644 --- a/examples/ws-public.ts +++ b/examples/ws-public.ts @@ -18,8 +18,8 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src'; // market: 'spot', // market: 'spotv3', // market: 'usdcOption', - market: 'usdcPerp', - // market: 'unifiedPerp', + // market: 'usdcPerp', + market: 'unifiedPerp', // market: 'unifiedOption', }, logger @@ -69,9 +69,10 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src'; // ]); // usdc perps - wsClient.subscribe('trade.BTCPERP'); + // wsClient.subscribe('trade.BTCPERP'); // unified perps + wsClient.subscribe('publicTrade.BTCUSDT'); // setTimeout(() => { // console.log('unsubscribing'); diff --git a/src/util/requestUtils.ts b/src/util/requestUtils.ts index a17f752..fa52e5b 100644 --- a/src/util/requestUtils.ts +++ b/src/util/requestUtils.ts @@ -73,6 +73,10 @@ export function isWsPong(msg: any): boolean { return true; } + if (msg['ret_msg'] === 'pong') { + return true; + } + return ( msg.request && msg.request.op === 'ping' && diff --git a/src/util/websocket-util.ts b/src/util/websocket-util.ts index f4f2219..714aa6d 100644 --- a/src/util/websocket-util.ts +++ b/src/util/websocket-util.ts @@ -153,6 +153,9 @@ export const PUBLIC_WS_KEYS = [ WS_KEY_MAP.spotV3Public, WS_KEY_MAP.usdcOptionPublic, WS_KEY_MAP.usdcPerpPublic, + WS_KEY_MAP.unifiedOptionPublic, + WS_KEY_MAP.unifiedPerpUSDTPublic, + WS_KEY_MAP.unifiedPerpUSDCPublic, ] as string[]; /** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */