diff --git a/src/types/websockets/ws-api.ts b/src/types/websockets/ws-api.ts index ffbfed9..f6de45f 100644 --- a/src/types/websockets/ws-api.ts +++ b/src/types/websockets/ws-api.ts @@ -65,6 +65,7 @@ export interface WSAPIRequest< export interface WSAPIResponse< TResponseData extends object = object, TOperation extends WSAPIOperation = WSAPIOperation, + TResponseExtInfo = {}, // added as optional for batch calls > { wsKey: WsKey; /** Auto-generated */ @@ -73,6 +74,7 @@ export interface WSAPIResponse< retMsg: 'OK' | string; op: TOperation; data: TResponseData; + retExtInfo: TResponseExtInfo; header?: { 'X-Bapi-Limit': string; 'X-Bapi-Limit-Status': string; diff --git a/src/websocket-api-client.ts b/src/websocket-api-client.ts index 4e97ab0..d08037a 100644 --- a/src/websocket-api-client.ts +++ b/src/websocket-api-client.ts @@ -1,4 +1,16 @@ -import { OrderParamsV5, OrderResultV5 } from './types'; +import { + AmendOrderParamsV5, + BatchAmendOrderParamsV5, + BatchAmendOrderResultV5, + BatchCancelOrderParamsV5, + BatchCancelOrderResultV5, + BatchCreateOrderResultV5, + BatchOrderParamsV5, + BatchOrdersRetExtInfoV5, + CancelOrderParamsV5, + OrderParamsV5, + OrderResultV5, +} from './types'; import { WSAPIResponse } from './types/websockets/ws-api'; import { WSClientConfigurableOptions } from './types/websockets/ws-general'; import { DefaultLogger } from './util'; @@ -90,6 +102,122 @@ export class WebsocketAPIClient { ); } + /** + * Amend an order + * + * @param params + * @returns + */ + amendOrder( + params: AmendOrderParamsV5, + ): Promise> { + return this.wsClient.sendWSAPIRequest( + WS_KEY_MAP.v5PrivateTrade, + 'order.amend', + params, + ); + } + + /** + * Cancel an order + * + * @param params + * @returns + */ + cancelOrder( + params: CancelOrderParamsV5, + ): Promise> { + return this.wsClient.sendWSAPIRequest( + WS_KEY_MAP.v5PrivateTrade, + 'order.cancel', + params, + ); + } + + /** + * Batch submit orders + * + * @param params + * @returns + */ + batchSubmitOrders( + category: 'option' | 'linear', + orders: BatchOrderParamsV5[], + ): Promise< + WSAPIResponse< + { + list: BatchCreateOrderResultV5[]; + }, + 'order.create-batch', + BatchOrdersRetExtInfoV5 + > + > { + return this.wsClient.sendWSAPIRequest( + WS_KEY_MAP.v5PrivateTrade, + 'order.create-batch', + { + category, + request: orders, + }, + ); + } + + /** + * Batch amend orders + * + * @param params + * @returns + */ + batchAmendOrder( + category: 'option' | 'linear', + orders: BatchAmendOrderParamsV5[], + ): Promise< + WSAPIResponse< + { + list: BatchAmendOrderResultV5[]; + }, + 'order.amend-batch', + BatchOrdersRetExtInfoV5 + > + > { + return this.wsClient.sendWSAPIRequest( + WS_KEY_MAP.v5PrivateTrade, + 'order.amend-batch', + { + category, + request: orders, + }, + ); + } + + /** + * Batch cancel orders + * + * @param params + * @returns + */ + batchCancelOrder( + category: 'option' | 'linear', + orders: BatchCancelOrderParamsV5[], + ): Promise< + WSAPIResponse< + { + list: BatchCancelOrderResultV5[]; + }, + 'order.cancel-batch', + BatchOrdersRetExtInfoV5 + > + > { + return this.wsClient.sendWSAPIRequest( + WS_KEY_MAP.v5PrivateTrade, + 'order.cancel-batch', + { + category, + request: orders, + }, + ); + } + /** * *