v3.2.1: add another UM response type.
This commit is contained in:
44
examples/rest-unified-margin-private-cursor.ts
Normal file
44
examples/rest-unified-margin-private-cursor.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { UnifiedMarginClient } from '../src/index';
|
||||
|
||||
// or
|
||||
// import { UnifiedMarginClient } from 'bybit-api';
|
||||
|
||||
const key = process.env.API_KEY_COM;
|
||||
const secret = process.env.API_SECRET_COM;
|
||||
|
||||
const client = new UnifiedMarginClient({
|
||||
key,
|
||||
secret,
|
||||
strict_param_validation: true,
|
||||
});
|
||||
|
||||
(async () => {
|
||||
try {
|
||||
// page 1
|
||||
const historicOrders1 = await client.getHistoricOrders({
|
||||
category: 'linear',
|
||||
limit: 1,
|
||||
// cursor,
|
||||
});
|
||||
console.log('page 1:', JSON.stringify(historicOrders1, null, 2));
|
||||
|
||||
// page 2
|
||||
const historicOrders2 = await client.getHistoricOrders({
|
||||
category: 'linear',
|
||||
limit: 1,
|
||||
cursor: historicOrders1.result.nextPageCursor,
|
||||
});
|
||||
console.log('page 2:', JSON.stringify(historicOrders2, null, 2));
|
||||
|
||||
const historicOrdersBoth = await client.getHistoricOrders({
|
||||
category: 'linear',
|
||||
limit: 2,
|
||||
});
|
||||
console.log(
|
||||
'both to compare:',
|
||||
JSON.stringify(historicOrdersBoth, null, 2)
|
||||
);
|
||||
} catch (e) {
|
||||
console.error('request failed: ', e);
|
||||
}
|
||||
})();
|
||||
@@ -1,3 +1,9 @@
|
||||
export interface UMPaginatedResult<List = any> {
|
||||
nextPageCursor: string;
|
||||
category: string;
|
||||
list: List[];
|
||||
}
|
||||
|
||||
export interface UMLeverageFilter {
|
||||
minLeverage: string;
|
||||
maxLeverage: string;
|
||||
@@ -31,8 +37,34 @@ export interface UMInstrumentInfo {
|
||||
lotSizeFilter: UMLotSizeFilter;
|
||||
}
|
||||
|
||||
export interface UMInstrumentInfoResult {
|
||||
category: string;
|
||||
list: UMInstrumentInfo[];
|
||||
nextPageCursor: string;
|
||||
export interface UMHistoricOrder {
|
||||
symbol: string;
|
||||
orderType: string;
|
||||
orderLinkId: string;
|
||||
orderId: string;
|
||||
stopOrderType: string;
|
||||
orderStatus: string;
|
||||
takeProfit: string;
|
||||
cumExecValue: string;
|
||||
blockTradeId: string;
|
||||
rejectReason: string;
|
||||
price: string;
|
||||
createdTime: number;
|
||||
tpTriggerBy: string;
|
||||
timeInForce: string;
|
||||
basePrice: string;
|
||||
leavesValue: string;
|
||||
updatedTime: number;
|
||||
side: string;
|
||||
triggerPrice: string;
|
||||
cumExecFee: string;
|
||||
slTriggerBy: string;
|
||||
leavesQty: string;
|
||||
closeOnTrigger: boolean;
|
||||
cumExecQty: string;
|
||||
reduceOnly: boolean;
|
||||
qty: string;
|
||||
stopLoss: string;
|
||||
triggerBy: string;
|
||||
orderIM: string;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,9 @@ import {
|
||||
InternalTransferRequest,
|
||||
UMExchangeCoinsRequest,
|
||||
UMBorrowHistoryRequest,
|
||||
UMInstrumentInfoResult,
|
||||
UMPaginatedResult,
|
||||
UMHistoricOrder,
|
||||
UMInstrumentInfo,
|
||||
} from './types';
|
||||
import { REST_CLIENT_TYPE_ENUM } from './util';
|
||||
import BaseRestClient from './util/BaseRestClient';
|
||||
@@ -79,7 +81,7 @@ export class UnifiedMarginClient extends BaseRestClient {
|
||||
/** Get trading rules per symbol/contract, incl price/amount/value/leverage filters */
|
||||
getInstrumentInfo(
|
||||
params: UMInstrumentInfoRequest
|
||||
): Promise<APIResponseV3<UMInstrumentInfoResult>> {
|
||||
): Promise<APIResponseV3<UMPaginatedResult<UMInstrumentInfo>>> {
|
||||
return this.get('/derivatives/v3/public/instruments-info', params);
|
||||
}
|
||||
|
||||
@@ -168,7 +170,7 @@ export class UnifiedMarginClient extends BaseRestClient {
|
||||
/** Query order history. As order creation/cancellation is asynchronous, the data returned from the interface may be delayed. To access order information in real-time, call getActiveOrders() */
|
||||
getHistoricOrders(
|
||||
params: UMHistoricOrdersRequest
|
||||
): Promise<APIResponseV3<any>> {
|
||||
): Promise<APIResponseV3<UMPaginatedResult<UMHistoricOrder>>> {
|
||||
return this.getPrivate('/unified/v3/private/order/list', params);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,6 +133,7 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => {
|
||||
})
|
||||
).toMatchObject({
|
||||
ret_code: API_ERROR_CODE.ORDER_NOT_FOUND_OR_TOO_LATE,
|
||||
// ret_msg: expect.stringMatching(/OK/gim),
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -31,6 +31,15 @@ describe('Private Unified Margin REST API GET Endpoints', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('getHistoricOrders() with cursor', async () => {
|
||||
const cursor =
|
||||
'fb56c285-02ac-424e-a6b1-d10413b65fab%3A1668178953132%2Cfb56c285-02ac-424e-a6b1-d10413b65fab%3A1668178953132';
|
||||
expect(await api.getHistoricOrders({ category, cursor })).toMatchObject({
|
||||
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||
retMsg: expect.stringMatching(/not.*unified margin/gim),
|
||||
});
|
||||
});
|
||||
|
||||
it('getPositions()', async () => {
|
||||
expect(await api.getPositions({ category })).toMatchObject({
|
||||
retCode: API_ERROR_CODE.ACCOUNT_NOT_UNIFIED,
|
||||
|
||||
Reference in New Issue
Block a user