Files
bybit-api/test/usdc/options/ws.public.test.ts
2023-02-17 14:01:07 +00:00

79 lines
1.9 KiB
TypeScript

/* eslint-disable no-unused-vars */
/* eslint-disable @typescript-eslint/no-unused-vars */
import {
WSClientConfigurableOptions,
WS_KEY_MAP,
WebsocketClient,
} from '../../../src';
import {
WS_OPEN_EVENT_PARTIAL,
getSilentLogger,
logAllEvents,
waitForSocketEvent,
} from '../../ws.util';
describe('Public USDC Option Websocket Client', () => {
let wsClient: WebsocketClient;
const wsClientOptions: WSClientConfigurableOptions = {
market: 'usdcOption',
};
beforeAll(() => {
wsClient = new WebsocketClient(
wsClientOptions,
getSilentLogger('expectSuccessNoAuth')
);
wsClient.connectPublic();
});
afterAll(() => {
wsClient.closeAll(true);
});
it('should open a public ws connection', async () => {
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
try {
expect(await wsOpenPromise).toMatchObject({
event: WS_OPEN_EVENT_PARTIAL,
wsKey: WS_KEY_MAP.usdcOptionPublic,
});
} catch (e) {
expect(e).toBeFalsy();
}
});
it('should subscribe to public trade events', async () => {
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
wsClient.subscribe([
'recenttrades.BTC',
'recenttrades.ETH',
'recenttrades.SOL',
]);
try {
expect(await wsResponsePromise).toMatchObject({
success: true,
data: {
failTopics: [],
successTopics: expect.any(Array),
},
type: 'COMMAND_RESP',
});
} catch (e) {
// sub failed
expect(e).toBeFalsy();
}
// Takes a while to get an event from USDC options - testing this manually for now
// try {
// expect(await wsUpdatePromise).toStrictEqual('asdfasdf');
// } catch (e) {
// // no data
// expect(e).toBeFalsy();
// }
});
});