From a7d4f630b3cc5ae260c648709da2c1bb84fe549b Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sun, 23 Oct 2022 10:59:37 +0100 Subject: [PATCH 1/2] feat(#187, v3.1.2): add support for new orderCategory param for spotv3 --- README.md | 12 +++++++++--- examples/ws-private.ts | 3 ++- package.json | 2 +- src/spot-client-v3.ts | 7 +++++-- src/types/request/spot.ts | 2 ++ src/types/request/unified-margin.ts | 2 +- 6 files changed, 20 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1ea50fb..c9da03f 100644 --- a/README.md +++ b/README.md @@ -53,14 +53,20 @@ The version on npm is the output from the `build` command and can be used in pro Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups: | Class | Description | |:------------------------------------------------------------------: |:----------------------------------------------------------------------------------------------------------------------------: | +| [ **Derivatives v3** ] | The Derivatves v3 APIs (successor to the Futures V2 APIs) | +| [UnifiedMarginClient](src/unified-margin-client.ts) | [Derivatives (v3) Unified Margin APIs](https://bybit-exchange.github.io/docs/derivativesV3/unified_margin/#t-introduction) | +| [ContractClient](src/contract-client.ts) | [Derivatives (v3) Contract APIs](https://bybit-exchange.github.io/docs/derivativesV3/contract). | +| [ **Futures v2** ] | The Futures v2 APIs | | [InverseClient](src/inverse-client.ts) | [Inverse Perpetual Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/inverse/) | | [LinearClient](src/linear-client.ts) | [USDT Perpetual Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/linear/#t-introduction) | | [InverseFuturesClient](src/inverse-futures-client.ts) | [Inverse Futures (v2) APIs](https://bybit-exchange.github.io/docs/futuresV2/inverse_futures/#t-introduction) | +| [ **Spot** ] | The spot APIs | +| [SpotClientV3](src/spot-client-v3.ts) | [Spot Market (v3) APIs](https://bybit-exchange.github.io/docs/spot/v3/#t-introduction) | +| [~SpotClient~](src/spot-client.ts) (deprecated, SpotClientV3 recommended)| [Spot Market (v1) APIs](https://bybit-exchange.github.io/docs/spot/v1/#t-introduction) | +| [ **USDC Contract** ] | The USDC Contract APIs | | [USDCPerpetualClient](src/usdc-perpetual-client.ts) | [USDC Perpetual APIs](https://bybit-exchange.github.io/docs/usdc/option/?console#t-querydeliverylog) | | [USDCOptionClient](src/usdc-option-client.ts) | [USDC Option APIs](https://bybit-exchange.github.io/docs/usdc/option/#t-introduction) | -| [UnifiedMarginClient](src/unified-margin-client.ts) | [Derivatives (v3) unified margin APIs](https://bybit-exchange.github.io/docs/derivativesV3/unified_margin/#t-introduction) | -| [SpotClientV3](src/spot-client-v3.ts) | [Spot Market (v3) APIs](https://bybit-exchange.github.io/docs/spot/v3/#t-introduction) | -| [~SpotClient~](src/spot-client.ts) (deprecated, v3 client recommended)| [Spot Market (v1) APIs](https://bybit-exchange.github.io/docs/spot/v1/#t-introduction) | +| [ **Other** ] | Other standalone API groups | | [AccountAssetClient](src/account-asset-client.ts) | [Account Asset APIs](https://bybit-exchange.github.io/docs/account_asset/#t-introduction) | | [CopyTradingClient](src/copy-trading-client.ts) | [Copy Trading APIs](https://bybit-exchange.github.io/docs/copy_trading/#t-introduction) | | [WebsocketClient](src/websocket-client.ts) | All WebSocket Events (Public & Private for all API categories) | diff --git a/examples/ws-private.ts b/examples/ws-private.ts index 14bd950..30fa731 100644 --- a/examples/ws-private.ts +++ b/examples/ws-private.ts @@ -16,7 +16,7 @@ import { WebsocketClient, WS_KEY_MAP, DefaultLogger } from '../src'; const market = 'linear'; // Inverse Perp // const market = 'inverse'; - // const market = 'spot'; + // const market = 'spotv3'; // Note: the WebsocketClient defaults to testnet. Set `livenet: true` to use live markets. const wsClient = new WebsocketClient( @@ -50,5 +50,6 @@ import { WebsocketClient, WS_KEY_MAP, DefaultLogger } from '../src'; }); // subscribe to private endpoints + // check the api docs in your api category to see the available topics wsClient.subscribe(['position', 'execution', 'order', 'wallet']); })(); diff --git a/package.json b/package.json index 42be513..7b7e1dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "3.1.1", + "version": "3.1.2", "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/spot-client-v3.ts b/src/spot-client-v3.ts index 7624204..cc81075 100644 --- a/src/spot-client-v3.ts +++ b/src/spot-client-v3.ts @@ -145,12 +145,14 @@ export class SpotClientV3 extends BaseRestClient { getOpenOrders( symbol?: string, orderId?: string, - limit?: number + limit?: number, + orderCategory?: 0 | 1 ): Promise> { return this.getPrivate('/spot/v3/private/open-orders', { symbol, orderId, limit, + orderCategory, }); } @@ -158,7 +160,8 @@ export class SpotClientV3 extends BaseRestClient { getPastOrders( symbol?: string, orderId?: string, - limit?: number + limit?: number, + orderCategory?: 0 | 1 ): Promise> { return this.getPrivate('/spot/v3/private/history-orders', { symbol, diff --git a/src/types/request/spot.ts b/src/types/request/spot.ts index 3c0c20f..cfeeae5 100644 --- a/src/types/request/spot.ts +++ b/src/types/request/spot.ts @@ -29,11 +29,13 @@ export interface SpotCancelOrderBatchRequest { symbol: string; side?: OrderSide; orderTypes: OrderTypeSpot[]; + orderCategory?: 0 | 1; } export interface SpotOrderQueryById { orderId?: string; orderLinkId?: string; + orderCategory?: 0 | 1; } export interface SpotSymbolInfo { diff --git a/src/types/request/unified-margin.ts b/src/types/request/unified-margin.ts index 85eb3b3..7546597 100644 --- a/src/types/request/unified-margin.ts +++ b/src/types/request/unified-margin.ts @@ -60,7 +60,7 @@ export interface UMOrderRequest { category: UMCategory; symbol: string; side: OrderSide; - positionIdx?: '0'; + positionIdx?: '0' | '1' | '2'; orderType: UMOrderType; qty: string; price?: string; From c9aaf18c3ac23b235a11902c9868d83e4e961de9 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Sun, 23 Oct 2022 11:06:49 +0100 Subject: [PATCH 2/2] fix for volatile test --- test/inverse-futures/private.write.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/inverse-futures/private.write.test.ts b/test/inverse-futures/private.write.test.ts index b1de1c6..b327aaa 100644 --- a/test/inverse-futures/private.write.test.ts +++ b/test/inverse-futures/private.write.test.ts @@ -154,7 +154,8 @@ describe('Private Inverse-Futures REST API POST Endpoints', () => { take_profit: 50000, }) ).toMatchObject({ - ret_code: API_ERROR_CODE.POSITION_STATUS_NOT_NORMAL, + // seems to fluctuate between POSITION_STATUS_NOT_NORMAL and POSITION_IDX_NOT_MATCH_POSITION_MODE + ret_code: /^30013|30041$/, }); });