add example and test for private contract v3 websocket topics

This commit is contained in:
tiagosiebler
2022-11-12 13:29:12 +00:00
parent 750db0232c
commit 9d464be3b2
5 changed files with 103 additions and 2 deletions

View File

@@ -13,10 +13,13 @@ import { WebsocketClient, WS_KEY_MAP, DefaultLogger } from '../src';
const secret = process.env.API_SECRET;
// USDT Perps:
const market = 'linear';
// const market = 'linear';
// Inverse Perp
// const market = 'inverse';
// const market = 'spotv3';
// Contract v3
const market = 'contractUSDT';
// const market = 'contractInverse';
// Note: the WebsocketClient defaults to testnet. Set `livenet: true` to use live markets.
const wsClient = new WebsocketClient(
@@ -48,8 +51,19 @@ import { WebsocketClient, WS_KEY_MAP, DefaultLogger } from '../src';
wsClient.on('reconnected', (data) => {
console.log('ws has reconnected ', data?.wsKey);
});
wsClient.on('error', (data) => {
console.error('ws exception: ', data);
});
// subscribe to private endpoints
// check the api docs in your api category to see the available topics
wsClient.subscribe(['position', 'execution', 'order', 'wallet']);
// wsClient.subscribe(['position', 'execution', 'order', 'wallet']);
// Contract v3
wsClient.subscribe([
'user.position.contractAccount',
'user.execution.contractAccount',
'user.order.contractAccount',
'user.wallet.contractAccount',
]);
})();

View File

@@ -51,6 +51,9 @@ import { DefaultLogger, WS_KEY_MAP, WebsocketClient } from '../src';
wsClient.on('reconnected', (data) => {
console.log('ws has reconnected ', data?.wsKey);
});
// wsClient.on('error', (data) => {
// console.error('ws exception: ', data);
// });
// Inverse
// wsClient.subscribe('trade');