detect pong for unified ws

This commit is contained in:
tiagosiebler
2022-09-17 11:13:48 +01:00
parent 08674ab2fa
commit 34884b236f
4 changed files with 20 additions and 7 deletions

View File

@@ -147,7 +147,7 @@ client.getOrderBook({ symbol: 'BTCUSD' })
``` ```
## WebSockets ## 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: 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 | | 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 // 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: 'linear' // market: 'inverse',
// market: 'spot' // 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 // how long to wait (in ms) before deciding the connection should be terminated & reconnected
// pongTimeout: 1000, // pongTimeout: 1000,

View File

@@ -18,8 +18,8 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// market: 'spot', // market: 'spot',
// market: 'spotv3', // market: 'spotv3',
// market: 'usdcOption', // market: 'usdcOption',
market: 'usdcPerp', // market: 'usdcPerp',
// market: 'unifiedPerp', market: 'unifiedPerp',
// market: 'unifiedOption', // market: 'unifiedOption',
}, },
logger logger
@@ -69,9 +69,10 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
// ]); // ]);
// usdc perps // usdc perps
wsClient.subscribe('trade.BTCPERP'); // wsClient.subscribe('trade.BTCPERP');
// unified perps // unified perps
wsClient.subscribe('publicTrade.BTCUSDT');
// setTimeout(() => { // setTimeout(() => {
// console.log('unsubscribing'); // console.log('unsubscribing');

View File

@@ -73,6 +73,10 @@ export function isWsPong(msg: any): boolean {
return true; return true;
} }
if (msg['ret_msg'] === 'pong') {
return true;
}
return ( return (
msg.request && msg.request &&
msg.request.op === 'ping' && msg.request.op === 'ping' &&

View File

@@ -153,6 +153,9 @@ export const PUBLIC_WS_KEYS = [
WS_KEY_MAP.spotV3Public, WS_KEY_MAP.spotV3Public,
WS_KEY_MAP.usdcOptionPublic, WS_KEY_MAP.usdcOptionPublic,
WS_KEY_MAP.usdcPerpPublic, WS_KEY_MAP.usdcPerpPublic,
WS_KEY_MAP.unifiedOptionPublic,
WS_KEY_MAP.unifiedPerpUSDTPublic,
WS_KEY_MAP.unifiedPerpUSDCPublic,
] as string[]; ] as string[];
/** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */ /** Used to automatically determine if a sub request should be to the public or private ws (when there's two) */