v2.2.1: fix ws & rest authentication issues caused by time-sync mechanism

This commit is contained in:
tiagosiebler
2022-05-28 20:39:37 +01:00
parent 9eda2f2bd9
commit 18977499f8
5 changed files with 70 additions and 4 deletions

6
examples/README.md Normal file
View File

@@ -0,0 +1,6 @@
# Examples
These samples can be executed using `ts-node`:
```
ts-node ./examples/rest-spot-public.ts
```

55
examples/ws-private.ts Normal file
View File

@@ -0,0 +1,55 @@
import { DefaultLogger } from '../src';
import { WebsocketClient, wsKeySpotPublic } from '../src/websocket-client';
// or
// import { DefaultLogger, WebsocketClient } from 'bybit-api';
(async () => {
const logger = {
...DefaultLogger,
// silly: () => {},
};
const key = process.env.API_KEY;
const secret = process.env.API_SECRET;
// USDT Perps:
const market = 'linear';
// Inverse Perp
// const market = 'inverse';
// const market = 'spot';
// Note: the WebsocketClient defaults to testnet. Set `livenet: true` to use live markets.
const wsClient = new WebsocketClient(
{
key: key,
secret: secret,
market: market,
livenet: true,
restOptions: {
// disable_time_sync: true,
},
},
logger
);
wsClient.on('update', (data) => {
console.log('raw message received ', JSON.stringify(data, null, 2));
});
wsClient.on('open', (data) => {
console.log('connection opened open:', data.wsKey);
});
wsClient.on('response', (data) => {
console.log('ws response: ', JSON.stringify(data, null, 2));
});
wsClient.on('reconnect', ({ wsKey }) => {
console.log('ws automatically reconnecting.... ', wsKey);
});
wsClient.on('reconnected', (data) => {
console.log('ws has reconnected ', data?.wsKey);
});
// subscribe to private endpoints
wsClient.subscribe(['position', 'execution', 'order', 'wallet']);
})();