77 lines
1.8 KiB
TypeScript
77 lines
1.8 KiB
TypeScript
import {
|
|
WSClientConfigurableOptions,
|
|
WS_KEY_MAP,
|
|
WebsocketClient,
|
|
} from '../../../src';
|
|
import {
|
|
WS_OPEN_EVENT_PARTIAL,
|
|
getSilentLogger,
|
|
waitForSocketEvent,
|
|
} from '../../ws.util';
|
|
|
|
describe.skip('Public USDC Perp Websocket Client', () => {
|
|
let wsClient: WebsocketClient;
|
|
|
|
const wsClientOptions: WSClientConfigurableOptions = {
|
|
market: 'usdcPerp',
|
|
};
|
|
|
|
beforeAll(() => {
|
|
wsClient = new WebsocketClient(
|
|
wsClientOptions,
|
|
getSilentLogger('expectSuccessNoAuth'),
|
|
);
|
|
wsClient.connectPublic();
|
|
// logAllEvents(wsClient);
|
|
});
|
|
|
|
afterAll(() => {
|
|
wsClient.closeAll(true);
|
|
});
|
|
|
|
it('should open a public ws connection', async () => {
|
|
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
|
|
|
expect(await wsOpenPromise).toMatchObject({
|
|
event: WS_OPEN_EVENT_PARTIAL,
|
|
wsKey: WS_KEY_MAP.usdcPerpPublic,
|
|
});
|
|
});
|
|
|
|
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).toMatchObject({
|
|
crossSeq: expect.any(String),
|
|
data: { orderBook: expect.any(Array) },
|
|
timestampE6: expect.any(String),
|
|
topic: topic,
|
|
type: 'snapshot',
|
|
});
|
|
} catch (e) {
|
|
console.error('usdc perp ws public error: ', e);
|
|
// no data
|
|
expect(e).toBeFalsy();
|
|
}
|
|
});
|
|
});
|