cleaning around tests
This commit is contained in:
58
test/spot/ws.private.v1.test.ts
Normal file
58
test/spot/ws.private.v1.test.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
import {
|
||||
WebsocketClient,
|
||||
WSClientConfigurableOptions,
|
||||
WS_KEY_MAP,
|
||||
} from '../../src';
|
||||
import {
|
||||
logAllEvents,
|
||||
promiseSleep,
|
||||
silentLogger,
|
||||
waitForSocketEvent,
|
||||
WS_OPEN_EVENT_PARTIAL,
|
||||
} from '../ws.util';
|
||||
|
||||
describe('Private Spot V1 Websocket Client', () => {
|
||||
let wsClient: WebsocketClient;
|
||||
const API_KEY = process.env.API_KEY_COM;
|
||||
const API_SECRET = process.env.API_SECRET_COM;
|
||||
|
||||
it('should have api credentials to test with', () => {
|
||||
expect(API_KEY).toStrictEqual(expect.any(String));
|
||||
expect(API_SECRET).toStrictEqual(expect.any(String));
|
||||
});
|
||||
|
||||
const wsClientOptions: WSClientConfigurableOptions = {
|
||||
market: 'spot',
|
||||
key: API_KEY,
|
||||
secret: API_SECRET,
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
wsClient = new WebsocketClient(wsClientOptions, silentLogger);
|
||||
logAllEvents(wsClient);
|
||||
});
|
||||
|
||||
afterAll(() => {
|
||||
wsClient.closeAll();
|
||||
});
|
||||
|
||||
// TODO: how to detect if auth failed for the v1 spot ws
|
||||
it('should open a private ws connection', async () => {
|
||||
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
wsClient.connectPrivate();
|
||||
|
||||
expect(wsOpenPromise).resolves.toMatchObject({
|
||||
event: WS_OPEN_EVENT_PARTIAL,
|
||||
wsKey: WS_KEY_MAP.spotPrivate,
|
||||
});
|
||||
// expect(wsUpdatePromise).resolves.toMatchObject({
|
||||
// topic: 'wsTopic',
|
||||
// data: expect.any(Array),
|
||||
// });
|
||||
await Promise.all([wsOpenPromise]);
|
||||
// await Promise.all([wsUpdatePromise]);
|
||||
// await promiseSleep(4000);
|
||||
});
|
||||
});
|
||||
64
test/spot/ws.public.v1.test.ts
Normal file
64
test/spot/ws.public.v1.test.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import {
|
||||
WebsocketClient,
|
||||
WSClientConfigurableOptions,
|
||||
WS_KEY_MAP,
|
||||
} from '../../src';
|
||||
import {
|
||||
logAllEvents,
|
||||
silentLogger,
|
||||
waitForSocketEvent,
|
||||
WS_OPEN_EVENT_PARTIAL,
|
||||
} from '../ws.util';
|
||||
|
||||
describe('Public Spot V1 Websocket Client', () => {
|
||||
let wsClient: WebsocketClient;
|
||||
|
||||
const wsClientOptions: WSClientConfigurableOptions = {
|
||||
market: 'spot',
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
wsClient = new WebsocketClient(wsClientOptions, silentLogger);
|
||||
wsClient.connectPublic();
|
||||
// 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.spotPublic,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
});
|
||||
|
||||
it('should subscribe to public orderbook events', async () => {
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
const symbol = 'BTCUSDT';
|
||||
expect(wsUpdatePromise).resolves.toMatchObject({
|
||||
symbol: symbol,
|
||||
symbolName: symbol,
|
||||
topic: 'diffDepth',
|
||||
params: {
|
||||
realtimeInterval: '24h',
|
||||
binary: 'false',
|
||||
},
|
||||
data: expect.any(Array),
|
||||
});
|
||||
|
||||
wsClient.subscribePublicSpotOrderbook(symbol, 'delta');
|
||||
|
||||
try {
|
||||
await wsUpdatePromise;
|
||||
} catch (e) {
|
||||
console.error(`Wait for spot v1 orderbook event exception: `, e);
|
||||
}
|
||||
});
|
||||
});
|
||||
72
test/spot/ws.public.v3.test.ts
Normal file
72
test/spot/ws.public.v3.test.ts
Normal file
@@ -0,0 +1,72 @@
|
||||
import {
|
||||
WebsocketClient,
|
||||
WSClientConfigurableOptions,
|
||||
WS_KEY_MAP,
|
||||
} from '../../src';
|
||||
import {
|
||||
logAllEvents,
|
||||
silentLogger,
|
||||
waitForSocketEvent,
|
||||
WS_OPEN_EVENT_PARTIAL,
|
||||
} from '../ws.util';
|
||||
|
||||
describe('Public Spot V3 Websocket Client', () => {
|
||||
let wsClient: WebsocketClient;
|
||||
|
||||
const wsClientOptions: WSClientConfigurableOptions = {
|
||||
market: 'spotV3',
|
||||
};
|
||||
|
||||
beforeAll(() => {
|
||||
wsClient = new WebsocketClient(wsClientOptions, silentLogger);
|
||||
wsClient.connectPublic();
|
||||
// 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.spotV3Public,
|
||||
});
|
||||
|
||||
await Promise.all([wsOpenPromise]);
|
||||
});
|
||||
|
||||
it('should subscribe to public orderbook events', async () => {
|
||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||
|
||||
const wsTopic = 'orderbook.40.BTCUSDT';
|
||||
expect(wsResponsePromise).resolves.toMatchObject({
|
||||
request: {
|
||||
args: [wsTopic],
|
||||
op: 'subscribe',
|
||||
},
|
||||
success: true,
|
||||
});
|
||||
expect(wsUpdatePromise).resolves.toStrictEqual('');
|
||||
|
||||
wsClient.subscribe(wsTopic);
|
||||
|
||||
try {
|
||||
await wsResponsePromise;
|
||||
} catch (e) {
|
||||
console.error(
|
||||
`Wait for "${wsTopic}" subscription response exception: `,
|
||||
e
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
await wsUpdatePromise;
|
||||
} catch (e) {
|
||||
console.error(`Wait for "${wsTopic}" event exception: `, e);
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user