Skip to content

Commit

Permalink
feat(): Added all WSAPI examples, added WSAPI request types, added al…
Browse files Browse the repository at this point in the history
…l exports in index.js
  • Loading branch information
JJ-Cro committed Jun 8, 2024
1 parent 399707d commit ea0ae7b
Show file tree
Hide file tree
Showing 3 changed files with 151 additions and 3 deletions.
83 changes: 82 additions & 1 deletion examples/ws-private-spot-wsapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,88 @@ 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');

/**
* Submit spot order
*/

console.log(new Date(), 'Submitting spot order!');
const newOrder = await client.sendWSAPIRequest(
'spotV4',
'spot.order_place',
{
text: 't-my-custom-id',
currency_pair: 'BTC_USDT',
type: 'limit',
account: 'spot',
side: 'buy',
amount: '0.001',
price: '45000',
},
);

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

/**
* Cancel spot order
*/

console.log(new Date(), 'Cancelling spot order!');
const cancelOrder = await client.sendWSAPIRequest(
'spotV4',
'spot.order_cancel',
{
order_id: 'yourIdHere',
currency_pair: 'BTC_USDT',
},
);

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

/**
* Batch cancel spot order
*/

console.log(new Date(), 'Cancelling spot orders!');
const cancelOrders = await client.sendWSAPIRequest(
'spotV4',
'spot.order_cancel_ids',
[
{
order_id: 'yourIdHere',
currency_pair: 'BTC_USDT',
},
{
order_id: 'yourIdHere',
currency_pair: 'ETH_USDT',
},
],
);

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

/**
* Amend/Update spot order
*/

console.log(new Date(), 'Updating spot order!');
const updateOrder = await client.sendWSAPIRequest(
'spotV4',
'spot.order_amend',
{
order_id: 'yourIdHere',
currency_pair: 'BTC_USDT',
price: '50000',
},
);

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

/**
* Get spot order status
*/

console.log(new Date(), 'Getting order status');
const orderStatus = await client.sendWSAPIRequest(
'spotV4',
'spot.order_status',
Expand Down
43 changes: 41 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,49 @@
export * from './lib/logger.js';
export * from './RestClient.js';
export * from './WebsocketClient.js';

// Request Types
export * from './types/request/account.js';
export * from './types/request/collateralLoan.js';
export * from './types/request/delivery.js';
export * from './types/request/earn.js';
export * from './types/request/earnuni.js';
export * from './types/request/flashswap.js';
export * from './types/request/futures.js';
export * from './types/request/margin.js';
export * from './types/request/marginuni.js';
export * from './types/request/multicollateralLoan.js';
export * from './types/request/options.js';
export * from './types/request/rebate.js';
export * from './types/request/spot.js';
export * from './types/request/subaccount.js';
export * from './types/request/unified.js';
export * from './types/request/wallet.js';
export * from './types/request/withdrawal.js';

// Response Types
export * from './types/response/account.js';
export * from './types/shared.js';
export * from './types/response/collateralloan.js';
export * from './types/response/delivery.js';
export * from './types/response/earn.js';
export * from './types/response/earnuni.js';
export * from './types/response/flashswap.js';
export * from './types/response/futures.js';
export * from './types/response/margin.js';
export * from './types/response/marginuni.js';
export * from './types/response/multicollateralLoan.js';
export * from './types/response/options.js';
export * from './types/response/rebate.js';
export * from './types/response/spot.js';
export * from './types/response/subaccount.js';
export * from './types/response/unified.js';
export * from './types/response/wallet.js';

// Websockets Types
export * from './types/websockets/client.js';
export * from './types/websockets/events.js';
export * from './types/websockets/requests.js';
export * from './types/websockets/wsAPI.js';
export * from './WebsocketClient.js';

// Shared Types
export * from './types/shared.js';
28 changes: 28 additions & 0 deletions src/types/websockets/wsAPI.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { WsKey } from '../../lib/websocket/websocket-util';
import { GetFuturesOrdersReq, SubmitFuturesOrderReq } from '../request/futures';
import { DeleteSpotOrderReq, SubmitSpotOrderReq } from '../request/spot';
import { CancelBatchOrder, Order } from '../shared';

export type SpotWSAPITopic =
| 'spot.login'
Expand Down Expand Up @@ -31,6 +34,31 @@ export interface WsAPIWsKeyTopicMap {
// announcementsV4: never;
}

export interface WsAPIRequestsTopicMap {
'spot.login': never;
'spot.order_place': SubmitSpotOrderReq;
'spot.order_cancel': DeleteSpotOrderReq;
'spot.order_cancel_ids': CancelBatchOrder[];
'spot.order_cancel_cp': DeleteSpotOrderReq[];
'spot.order_amend': Order;
'spot.order_status': any;
'futures.login': never;
'futures.order_place': SubmitFuturesOrderReq;
'futures.order_batch_place': SubmitFuturesOrderReq[];
'futures.order_cancel': {
order_id: string;
};
'futures.order_cancel_cp': {
contract: string;
side?: 'ask' | 'bid';
};
'futures.order_amend': any;
'futures.order_list': GetFuturesOrdersReq;
'futures.order_status': {
order_id: string;
};
}

export interface WSAPIResponseHeader<TChannel extends WSAPITopic> {
/** String timestamp as ms */
response_time: string;
Expand Down

0 comments on commit ea0ae7b

Please sign in to comment.