detect pong for unified ws
This commit is contained in:
13
README.md
13
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,
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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' &&
|
||||
|
||||
@@ -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) */
|
||||
|
||||
Reference in New Issue
Block a user