public usdc perp ws test

This commit is contained in:
tiagosiebler
2022-09-16 13:25:25 +01:00
parent d2ba5d3e01
commit 9b673f08d5
6 changed files with 139 additions and 12 deletions

View File

@@ -0,0 +1,82 @@
import {
WebsocketClient,
WSClientConfigurableOptions,
WS_KEY_MAP,
} from '../../../src';
import {
logAllEvents,
getSilentLogger,
waitForSocketEvent,
WS_OPEN_EVENT_PARTIAL,
} from '../../ws.util';
describe('Public USDC Perp Websocket Client', () => {
let wsClient: WebsocketClient;
const wsClientOptions: WSClientConfigurableOptions = {
market: 'usdcPerp',
};
beforeAll(() => {
wsClient = new WebsocketClient(
wsClientOptions,
getSilentLogger('expectSuccessNoAuth')
);
// logAllEvents(wsClient);
});
beforeEach(() => {
wsClient.removeAllListeners();
// logAllEvents(wsClient);
});
afterAll(() => {
wsClient.closeAll();
});
it('should open a public ws connection', async () => {
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
expect(wsOpenPromise).resolves.toMatchObject({
event: WS_OPEN_EVENT_PARTIAL,
wsKey: WS_KEY_MAP.usdcPerpPublic,
});
await Promise.all([wsOpenPromise]);
});
it('should subscribe to public trade events', async () => {
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
const topic = 'orderBook_200.100ms.BTCPERP';
wsClient.subscribe(topic);
try {
expect(await wsResponsePromise).toMatchObject({
success: true,
ret_msg: '',
request: {
op: 'subscribe',
args: [topic],
},
});
} catch (e) {
// sub failed
expect(e).toBeFalsy();
}
try {
expect(await wsUpdatePromise).toMatchSnapshot({
crossSeq: expect.any(String),
data: { orderBook: expect.any(Array) },
timestampE6: expect.any(String),
topic: topic,
type: 'snapshot',
});
} catch (e) {
// no data
expect(e).toBeFalsy();
}
});
});