Skip to content

Commit

Permalink
feat(): added WSAPI futures examples
Browse files Browse the repository at this point in the history
  • Loading branch information
JJ-Cro committed Jun 8, 2024
1 parent 40504d2 commit 399707d
Showing 1 changed file with 108 additions and 4 deletions.
112 changes: 108 additions & 4 deletions examples/ws-private-perp-futures-wsapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,16 +111,120 @@ async function start() {
* Note that internal parameters such as "signature" etc are all handled automatically by the SDK.
*
*/
console.log(new Date(), 'try get order status');
const orderStatus = await client.sendWSAPIRequest(

/**
* Submit futures order
*/

console.log(new Date(), 'Sending futures order:');
const submitOrder = await client.sendWSAPIRequest(
'perpFuturesUSDTV4',
'futures.order_place',
{
contract: 'BTC_USDT',
size: 20, // positive for long, negative for short
price: '0',
tif: 'ioc',
},
);

console.log(new Date(), 'Result: ', submitOrder);

/**
* Submit batch futures order
*/

console.log(new Date(), 'Sending batch futures order!');
const submitBatchOrder = await client.sendWSAPIRequest(
'perpFuturesUSDTV4',
'futures.order_batch_place',
[
{
contract: 'ETH_USDT',
size: 10, // positive for long, negative for short
price: '0',
tif: 'ioc',
},
{
contract: 'BTC_USDT',
size: 10, // positive for long, negative for short
price: '0',
tif: 'ioc',
},
],
);

console.log(new Date(), 'Result: ', submitBatchOrder);

/**
* Cancel futures order
*/
console.log(new Date(), 'Cancelling futures order!');
const cancelOrder = await client.sendWSAPIRequest(
'perpFuturesUSDTV4',
'futures.order_cancel',
{ order_id: 'orderIDHere' },
);

console.log(new Date(), 'Result: ', cancelOrder);

/**
* Cancel all futures orders
*/
console.log(new Date(), 'Cancelling all futures orders!');
const cancelAllOrders = await client.sendWSAPIRequest(
'perpFuturesUSDTV4',
'futures.order_cancel_cp',
{ contract: 'BTC_USDT' },
);

console.log(new Date(), 'Result: ', cancelAllOrders);

/**
* Update/Amend Futures order
*/
console.log(new Date(), 'Updating futures order!');
const updateOrder = await client.sendWSAPIRequest(
'perpFuturesUSDTV4',
'futures.order_amend',
{
order_id: 'orderIdHere',
price: '31303.180000',
},
);

console.log(new Date(), 'Result: ', updateOrder);

/**
* Get orders list
*/

console.log(new Date(), 'Getting futures orders!');
const getList = await client.sendWSAPIRequest(
'perpFuturesUSDTV4',
'futures.order_list',
{
status: 'finished',
contract: 'BTC_USDT',
status: 'open',
},
);

console.log(new Date(), 'Result: ', getList);

/**
* Get order status
*/

console.log(new Date(), 'Getting order status!');
const getStatus = await client.sendWSAPIRequest(
'perpFuturesUSDTV4',
'futures.order_status',
{
order_id: '74046543',
},
);

console.log(new Date(), 'orderStatus result!', orderStatus);
console.log(new Date(), 'Result: ', getStatus);
} catch (e) {
console.error(`WS API Error: `, e);
}
Expand Down

0 comments on commit 399707d

Please sign in to comment.