Skip to content

Commit

Permalink
update examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
talrasha007 committed Nov 10, 2023
1 parent 8bf8962 commit feb4935
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples/v5/ws.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const { wsApi } = require('./api');

console.log(await wsApi.subscribePublic([{
"channel" : "tickers",
"instId": "ETH-USD-210625"
"instId": "ETH-USD-240329"
}, {
"channel" : "tickers",
"instId": "ETH-USD-SWAP"
Expand Down
47 changes: 47 additions & 0 deletions examples/v5/ws_order.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { wsApi } = require('./api');

async function main() {
if (!wsApi.loggedIn) {
await new Promise(resolve => wsApi.once('login', resolve));
}

wsApi.subscribePrivate([
{
channel: 'account',
ccy: 'BTC'
}, {
channel: 'account',
ccy: 'ETH'
}, {
channel: 'account',
ccy: 'USDT'
}, {
channel: 'positions',
instType: 'ANY'
}, {
channel: 'orders',
instType: 'ANY'
}
], true);

const orders = await wsApi.batchOrder([
wsApi.toOrder('ETH-USDT-SWAP', 'buy', 'long', 'market', 1),
wsApi.toOrder('ETH-USDT-240329', 'sell', 'short', 'market', 1)
]).catch(console.error);

const [longOrder, shortOrder] = await wsApi.waitForOrders(orders);
if (longOrder.sCode != 0 || shortOrder.sCode != 0) {
console.log(longOrder)
console.log(shortOrder)
console.error(longOrder.sMsg || shortOrder.sMsg);
this.disabled = true;
diff = -1;
} else {
console.log('longOrder:', longOrder);
console.log('shortOrder:', shortOrder);
diff = shortOrder.avgPx / longOrder.avgPx - 1;
console.log('diff:', diff)
}
}

main().catch(e => console.error(e.stack));

0 comments on commit feb4935

Please sign in to comment.