tests for unified margin WS
This commit is contained in:
@@ -23,7 +23,6 @@ describe('Public Linear Perps Websocket Client', () => {
|
|||||||
|
|
||||||
afterAll(() => {
|
afterAll(() => {
|
||||||
wsClient.closeAll();
|
wsClient.closeAll();
|
||||||
wsClient.removeAllListeners();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should open a public ws connection', async () => {
|
it('should open a public ws connection', async () => {
|
||||||
@@ -65,31 +64,4 @@ describe('Public Linear Perps Websocket Client', () => {
|
|||||||
console.error(`Wait for "${wsTopic}" event exception: `, e);
|
console.error(`Wait for "${wsTopic}" event exception: `, e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail to subscribe to private events (no keys)', async () => {
|
|
||||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
|
||||||
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
|
||||||
|
|
||||||
const wsTopic = 'wallet';
|
|
||||||
|
|
||||||
// No easy way to trigger a private event (other than executing trades)
|
|
||||||
// expect(wsUpdatePromise).resolves.toMatchObject({
|
|
||||||
// topic: wsTopic,
|
|
||||||
// data: expect.any(Array),
|
|
||||||
// });
|
|
||||||
|
|
||||||
wsClient.subscribe(wsTopic);
|
|
||||||
|
|
||||||
try {
|
|
||||||
expect(await wsResponsePromise).toBeFalsy();
|
|
||||||
} catch (e) {
|
|
||||||
expect(e).toMatchObject({
|
|
||||||
request: {
|
|
||||||
args: [wsTopic],
|
|
||||||
op: 'subscribe',
|
|
||||||
},
|
|
||||||
success: false,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
77
test/unified-margin/ws.private.test.ts
Normal file
77
test/unified-margin/ws.private.test.ts
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
import {
|
||||||
|
WebsocketClient,
|
||||||
|
WSClientConfigurableOptions,
|
||||||
|
WS_KEY_MAP,
|
||||||
|
} from '../../src';
|
||||||
|
import {
|
||||||
|
logAllEvents,
|
||||||
|
getSilentLogger,
|
||||||
|
waitForSocketEvent,
|
||||||
|
WS_OPEN_EVENT_PARTIAL,
|
||||||
|
fullLogger,
|
||||||
|
} from '../ws.util';
|
||||||
|
|
||||||
|
describe('Private Unified Margin Websocket Client', () => {
|
||||||
|
let wsClient: WebsocketClient;
|
||||||
|
|
||||||
|
const wsClientOptions: WSClientConfigurableOptions = {
|
||||||
|
market: 'unifiedPerp',
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
wsClient = new WebsocketClient(
|
||||||
|
wsClientOptions,
|
||||||
|
getSilentLogger('expectSuccessNoAuth')
|
||||||
|
// fullLogger
|
||||||
|
);
|
||||||
|
// logAllEvents(wsClient);
|
||||||
|
wsClient.connectPrivate();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
wsClient.closeAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
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.unifiedPrivate,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
expect(e).toBeFalsy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Should work, but don't have unified margin activated - needs extra testing
|
||||||
|
// {"conn_id": "064443fffef10442-0000798d-0000a9f6-ba32aeee49712540-1752c4f4", "ret_msg": "3303001", "success": false, "type": "COMMAND_RESP", "wsKey": "unifiedPrivate"}
|
||||||
|
|
||||||
|
it.skip('should subscribe to public private unified account events', async () => {
|
||||||
|
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||||
|
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||||
|
|
||||||
|
// USDT should be detected and automatically routed through the USDT connection
|
||||||
|
const topic = 'user.position.unifiedAccount';
|
||||||
|
wsClient.subscribe(topic);
|
||||||
|
|
||||||
|
try {
|
||||||
|
expect(await wsResponsePromise).toMatchObject({
|
||||||
|
op: 'subscribe',
|
||||||
|
req_id: topic,
|
||||||
|
success: true,
|
||||||
|
wsKey: WS_KEY_MAP.unifiedPrivate,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// sub failed
|
||||||
|
expect(e).toBeFalsy();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
expect(await wsUpdatePromise).toStrictEqual('');
|
||||||
|
} catch (e) {
|
||||||
|
// no data
|
||||||
|
expect(e).toBeFalsy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -41,7 +41,7 @@ describe('Public Unified Margin Websocket Client (Options)', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should subscribe to public trade events', async () => {
|
it('should subscribe to public orderbook events', async () => {
|
||||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||||
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
// const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||||
|
|
||||||
|
|||||||
85
test/unified-margin/ws.public.perp.usdc.test.ts
Normal file
85
test/unified-margin/ws.public.perp.usdc.test.ts
Normal file
@@ -0,0 +1,85 @@
|
|||||||
|
import {
|
||||||
|
WebsocketClient,
|
||||||
|
WSClientConfigurableOptions,
|
||||||
|
WS_KEY_MAP,
|
||||||
|
} from '../../src';
|
||||||
|
import {
|
||||||
|
logAllEvents,
|
||||||
|
getSilentLogger,
|
||||||
|
waitForSocketEvent,
|
||||||
|
WS_OPEN_EVENT_PARTIAL,
|
||||||
|
fullLogger,
|
||||||
|
} from '../ws.util';
|
||||||
|
|
||||||
|
describe('Public Unified Margin Websocket Client (Perps - USDC)', () => {
|
||||||
|
let wsClient: WebsocketClient;
|
||||||
|
|
||||||
|
const wsClientOptions: WSClientConfigurableOptions = {
|
||||||
|
market: 'unifiedPerp',
|
||||||
|
};
|
||||||
|
|
||||||
|
beforeAll(() => {
|
||||||
|
wsClient = new WebsocketClient(
|
||||||
|
wsClientOptions,
|
||||||
|
getSilentLogger('expectSuccessNoAuth')
|
||||||
|
// fullLogger
|
||||||
|
);
|
||||||
|
// logAllEvents(wsClient);
|
||||||
|
wsClient.connectPublic();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterAll(() => {
|
||||||
|
wsClient.closeAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should open a public ws connection', async () => {
|
||||||
|
const wsOpenPromise = waitForSocketEvent(wsClient, 'open');
|
||||||
|
try {
|
||||||
|
expect(await wsOpenPromise).toMatchObject({
|
||||||
|
event: WS_OPEN_EVENT_PARTIAL,
|
||||||
|
wsKey: expect.stringContaining('unifiedPerpUSD'),
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
expect(e).toBeFalsy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: are there USDC topics? This doesn't seem to work
|
||||||
|
it.skip('should subscribe to public orderbook events through USDC connection', async () => {
|
||||||
|
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||||
|
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||||
|
|
||||||
|
// USDT should be detected and automatically routed through the USDT connection
|
||||||
|
wsClient.subscribe('orderbook.25.BTCUSDC');
|
||||||
|
|
||||||
|
try {
|
||||||
|
expect(await wsResponsePromise).toMatchObject({
|
||||||
|
op: 'subscribe',
|
||||||
|
req_id: 'orderbook.25.BTCUSDC',
|
||||||
|
success: true,
|
||||||
|
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// sub failed
|
||||||
|
expect(e).toBeFalsy();
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
expect(await wsUpdatePromise).toMatchObject({
|
||||||
|
data: {
|
||||||
|
a: expect.any(Array),
|
||||||
|
b: expect.any(Array),
|
||||||
|
s: 'BTCUSDT',
|
||||||
|
u: expect.any(Number),
|
||||||
|
},
|
||||||
|
topic: 'orderbook.25.BTCUSDC',
|
||||||
|
ts: expect.any(Number),
|
||||||
|
type: 'snapshot',
|
||||||
|
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
|
// no data
|
||||||
|
expect(e).toBeFalsy();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -44,16 +44,18 @@ describe('Public Unified Margin Websocket Client (Perps - USDT)', () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should subscribe to public trade events through USDT topic', async () => {
|
it('should subscribe to public orderbook events through USDT connection', async () => {
|
||||||
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
const wsResponsePromise = waitForSocketEvent(wsClient, 'response');
|
||||||
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
const wsUpdatePromise = waitForSocketEvent(wsClient, 'update');
|
||||||
|
|
||||||
wsClient.subscribe('orderbook.25.BTCUSDT');
|
// USDT should be detected and automatically routed through the USDT connection
|
||||||
|
const topic = 'orderbook.25.BTCUSDT';
|
||||||
|
wsClient.subscribe(topic);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
expect(await wsResponsePromise).toMatchObject({
|
expect(await wsResponsePromise).toMatchObject({
|
||||||
op: 'subscribe',
|
op: 'subscribe',
|
||||||
req_id: 'orderbook.25.BTCUSDT',
|
req_id: topic,
|
||||||
success: true,
|
success: true,
|
||||||
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
||||||
});
|
});
|
||||||
@@ -70,7 +72,7 @@ describe('Public Unified Margin Websocket Client (Perps - USDT)', () => {
|
|||||||
s: 'BTCUSDT',
|
s: 'BTCUSDT',
|
||||||
u: expect.any(Number),
|
u: expect.any(Number),
|
||||||
},
|
},
|
||||||
topic: 'orderbook.25.BTCUSDT',
|
topic: topic,
|
||||||
ts: expect.any(Number),
|
ts: expect.any(Number),
|
||||||
type: 'snapshot',
|
type: 'snapshot',
|
||||||
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
wsKey: WS_KEY_MAP.unifiedPerpUSDTPublic,
|
||||||
|
|||||||
Reference in New Issue
Block a user