Merge pull request #445 from JJ-Cro/wsapiclienExamples

feat(): added bybit wsapi client all functions
This commit is contained in:
Tiago
2025-05-20 14:57:05 +01:00
committed by GitHub
2 changed files with 131 additions and 1 deletions

View File

@@ -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;

View File

@@ -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<WSAPIResponse<OrderResultV5, 'order.amend'>> {
return this.wsClient.sendWSAPIRequest(
WS_KEY_MAP.v5PrivateTrade,
'order.amend',
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,
},
);
}
/**
*
*