diff --git a/examples/ws-private-spot-wsapi.ts b/examples/ws-private-spot-wsapi.ts index 00eca78..8cc851c 100644 --- a/examples/ws-private-spot-wsapi.ts +++ b/examples/ws-private-spot-wsapi.ts @@ -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', diff --git a/src/index.ts b/src/index.ts index e4486ac..32f7590 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; diff --git a/src/types/websockets/wsAPI.ts b/src/types/websockets/wsAPI.ts index 1db18cc..bf38646 100644 --- a/src/types/websockets/wsAPI.ts +++ b/src/types/websockets/wsAPI.ts @@ -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' @@ -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 { /** String timestamp as ms */ response_time: string;