v3.2.1: add instrument info response type. add cursor example with unified margin request

This commit is contained in:
tiagosiebler
2022-11-15 15:26:57 +00:00
parent 42a9ef10d7
commit c46645713e
5 changed files with 78 additions and 2 deletions

View File

@@ -0,0 +1,36 @@
import { UnifiedMarginClient } from '../src/index';
// or
// import { UnifiedMarginClient } from 'bybit-api';
const client = new UnifiedMarginClient({
strict_param_validation: true,
});
(async () => {
try {
// page 1
const historicOrders1 = await client.getInstrumentInfo({
category: 'linear',
limit: '2',
});
console.log('page 1:', JSON.stringify(historicOrders1, null, 2));
// page 2
const historicOrders2 = await client.getInstrumentInfo({
category: 'linear',
limit: '2',
cursor: historicOrders1.result.nextPageCursor,
});
console.log('page 2:', JSON.stringify(historicOrders2, null, 2));
// page 1 & 2 in one request (for comparison)
const historicOrdersBoth = await client.getInstrumentInfo({
category: 'linear',
limit: '4',
});
console.log('both pages', JSON.stringify(historicOrdersBoth, null, 2));
} catch (e) {
console.error('request failed: ', e);
}
})();

View File

@@ -1,6 +1,6 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "3.2.0", "version": "3.2.1",
"description": "Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.", "description": "Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",

View File

@@ -1,3 +1,4 @@
export * from './shared'; export * from './shared';
export * from './spot'; export * from './spot';
export * from './usdt-perp'; export * from './usdt-perp';
export * from './unified-margin';

View File

@@ -0,0 +1,38 @@
export interface UMLeverageFilter {
minLeverage: string;
maxLeverage: string;
leverageStep: string;
}
export interface UMPriceFilter {
minPrice: string;
maxPrice: string;
tickSize: string;
}
export interface UMLotSizeFilter {
maxTradingQty: string;
minTradingQty: string;
qtyStep: string;
}
export interface UMInstrumentInfo {
symbol: string;
contractType: string;
status: string;
baseCoin: string;
quoteCoin: string;
launchTime: string;
deliveryTime: string;
deliveryFeeRate: string;
priceScale: string;
leverageFilter: UMLeverageFilter;
priceFilter: UMPriceFilter;
lotSizeFilter: UMLotSizeFilter;
}
export interface UMInstrumentInfoResult {
category: string;
list: UMInstrumentInfo[];
nextPageCursor: string;
}

View File

@@ -26,6 +26,7 @@ import {
InternalTransferRequest, InternalTransferRequest,
UMExchangeCoinsRequest, UMExchangeCoinsRequest,
UMBorrowHistoryRequest, UMBorrowHistoryRequest,
UMInstrumentInfoResult,
} from './types'; } from './types';
import { REST_CLIENT_TYPE_ENUM } from './util'; import { REST_CLIENT_TYPE_ENUM } from './util';
import BaseRestClient from './util/BaseRestClient'; import BaseRestClient from './util/BaseRestClient';
@@ -78,7 +79,7 @@ export class UnifiedMarginClient extends BaseRestClient {
/** Get trading rules per symbol/contract, incl price/amount/value/leverage filters */ /** Get trading rules per symbol/contract, incl price/amount/value/leverage filters */
getInstrumentInfo( getInstrumentInfo(
params: UMInstrumentInfoRequest params: UMInstrumentInfoRequest
): Promise<APIResponseV3<any>> { ): Promise<APIResponseV3<UMInstrumentInfoResult>> {
return this.get('/derivatives/v3/public/instruments-info', params); return this.get('/derivatives/v3/public/instruments-info', params);
} }