From c46645713e85968244e95a1802df2a2535795452 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Tue, 15 Nov 2022 15:26:57 +0000 Subject: [PATCH] v3.2.1: add instrument info response type. add cursor example with unified margin request --- examples/rest-unified-margin-public-cursor.ts | 36 ++++++++++++++++++ package.json | 2 +- src/types/response/index.ts | 1 + src/types/response/unified-margin.ts | 38 +++++++++++++++++++ src/unified-margin-client.ts | 3 +- 5 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 examples/rest-unified-margin-public-cursor.ts create mode 100644 src/types/response/unified-margin.ts diff --git a/examples/rest-unified-margin-public-cursor.ts b/examples/rest-unified-margin-public-cursor.ts new file mode 100644 index 0000000..8d8aab6 --- /dev/null +++ b/examples/rest-unified-margin-public-cursor.ts @@ -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); + } +})(); diff --git a/package.json b/package.json index 418972e..ef52a83 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "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.", "main": "lib/index.js", "types": "lib/index.d.ts", diff --git a/src/types/response/index.ts b/src/types/response/index.ts index 23d9753..390e4da 100644 --- a/src/types/response/index.ts +++ b/src/types/response/index.ts @@ -1,3 +1,4 @@ export * from './shared'; export * from './spot'; export * from './usdt-perp'; +export * from './unified-margin'; diff --git a/src/types/response/unified-margin.ts b/src/types/response/unified-margin.ts new file mode 100644 index 0000000..bd0cf12 --- /dev/null +++ b/src/types/response/unified-margin.ts @@ -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; +} diff --git a/src/unified-margin-client.ts b/src/unified-margin-client.ts index 6ce1201..ca4e733 100644 --- a/src/unified-margin-client.ts +++ b/src/unified-margin-client.ts @@ -26,6 +26,7 @@ import { InternalTransferRequest, UMExchangeCoinsRequest, UMBorrowHistoryRequest, + UMInstrumentInfoResult, } from './types'; import { REST_CLIENT_TYPE_ENUM } from './util'; 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 */ getInstrumentInfo( params: UMInstrumentInfoRequest - ): Promise> { + ): Promise> { return this.get('/derivatives/v3/public/instruments-info', params); }