feat(): added bybit wsapi client all functions

This commit is contained in:
JJ-Cro
2025-05-20 13:16:21 +02:00
parent 910f80a55b
commit 93a9165fb3
2 changed files with 119 additions and 6 deletions

View File

@@ -65,6 +65,7 @@ export interface WSAPIRequest<
export interface WSAPIResponse< export interface WSAPIResponse<
TResponseData extends object = object, TResponseData extends object = object,
TOperation extends WSAPIOperation = WSAPIOperation, TOperation extends WSAPIOperation = WSAPIOperation,
TResponseExtInfo = {}, // added as optional for batch calls
> { > {
wsKey: WsKey; wsKey: WsKey;
/** Auto-generated */ /** Auto-generated */
@@ -73,6 +74,7 @@ export interface WSAPIResponse<
retMsg: 'OK' | string; retMsg: 'OK' | string;
op: TOperation; op: TOperation;
data: TResponseData; data: TResponseData;
retExtInfo: TResponseExtInfo;
header?: { header?: {
'X-Bapi-Limit': string; 'X-Bapi-Limit': string;
'X-Bapi-Limit-Status': string; 'X-Bapi-Limit-Status': string;

View File

@@ -1,4 +1,15 @@
import { OrderParamsV5, OrderResultV5 } from './types'; import {
AmendOrderParamsV5,
BatchAmendOrderParamsV5,
BatchAmendOrderResultV5,
BatchCancelOrderParamsV5,
BatchCancelOrderResultV5,
BatchCreateOrderResultV5,
BatchOrderParamsV5,
BatchOrdersRetExtInfoV5,
CancelOrderParamsV5,
OrderResultV5,
} from './types';
import { WSAPIResponse } from './types/websockets/ws-api'; import { WSAPIResponse } from './types/websockets/ws-api';
import { WSClientConfigurableOptions } from './types/websockets/ws-general'; import { WSClientConfigurableOptions } from './types/websockets/ws-general';
import { DefaultLogger } from './util'; import { DefaultLogger } from './util';
@@ -75,21 +86,121 @@ export class WebsocketAPIClient {
*/ */
/** /**
* Submit a new order * Amend an order
* *
* @param params * @param params
* @returns * @returns
*/ */
submitNewOrder( amendOrder(
params: OrderParamsV5, params: AmendOrderParamsV5,
): Promise<WSAPIResponse<OrderResultV5, 'order.create'>> { ): Promise<WSAPIResponse<OrderResultV5, 'order.amend'>> {
return this.wsClient.sendWSAPIRequest( return this.wsClient.sendWSAPIRequest(
WS_KEY_MAP.v5PrivateTrade, WS_KEY_MAP.v5PrivateTrade,
'order.create', 'order.amend',
params, params,
); );
} }
/**
* Cancel an order
*
* @param params
* @returns
*/
cancelOrder(
params: CancelOrderParamsV5,
): Promise<WSAPIResponse<OrderResultV5, 'order.cancel'>> {
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,
},
);
}
/** /**
* *
* *