From 84b71f5c13e3aa86c02a7682251e9f2576658c22 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Tue, 29 Nov 2022 08:59:16 +0000 Subject: [PATCH] v3.3.4: fix optional param in contract client, add js/ts samples for contract client, fix e2e open interest limit test, update readme --- README.md | 1 + examples/rest-contract-public.js | 21 +++++++++++++++++++++ examples/rest-contract-public.ts | 20 ++++++++++++++++++++ package.json | 2 +- src/contract-client.ts | 2 +- src/websocket-client.ts | 1 + test/contract/private.read.test.ts | 8 ++++---- test/response.util.ts | 1 + 8 files changed, 50 insertions(+), 6 deletions(-) create mode 100644 examples/rest-contract-public.js create mode 100644 examples/rest-contract-public.ts diff --git a/README.md b/README.md index bdd1b25..51aa637 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,7 @@ Check out my related projects: - [binance](https://www.npmjs.com/package/binance) - [bybit-api](https://www.npmjs.com/package/bybit-api) - [okx-api](https://www.npmjs.com/package/okx-api) + - [bitget-api](https://www.npmjs.com/package/bitget-api) - [ftx-api](https://www.npmjs.com/package/ftx-api) - Try my misc utilities: - [orderbooks](https://www.npmjs.com/package/orderbooks) diff --git a/examples/rest-contract-public.js b/examples/rest-contract-public.js new file mode 100644 index 0000000..d973b47 --- /dev/null +++ b/examples/rest-contract-public.js @@ -0,0 +1,21 @@ +/** + * This is the pure javascript version of the `rest-contract-public.ts` sample + */ + +// To use a local build (testing with the repo directly), make sure to `npm run build` first from the repo root +// const { ContractClient } = require('../dist'); + +// or, use the version installed with npm +const { ContractClient } = require('bybit-api'); + +(async () => { + const client = new ContractClient(); + + try { + const orderbookResult = await client.getOrderBook('BTCUSDT', 'linear'); + console.log('orderbook result: ', orderbookResult); + } catch (e) { + console.error('request failed: ', e); + } + +})(); diff --git a/examples/rest-contract-public.ts b/examples/rest-contract-public.ts new file mode 100644 index 0000000..99b3a0e --- /dev/null +++ b/examples/rest-contract-public.ts @@ -0,0 +1,20 @@ +/** + * This is the TypeScript version of the `rest-contract-public.js` sample. + */ + +// For testing with the repo directly, import from the src folder +import { ContractClient } from '../src'; + +// or, use the version installed with npm +// import { ContractClient } from 'bybit-api'; + +(async () => { + const client = new ContractClient(); + + try { + const orderbookResult = await client.getOrderBook('BTCUSDT', 'linear'); + console.log('orderbook result: ', orderbookResult); + } catch (e) { + console.error('request failed: ', e); + } +})(); diff --git a/package.json b/package.json index 4405c8b..b3c687a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "bybit-api", - "version": "3.3.3", + "version": "3.3.4", "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/contract-client.ts b/src/contract-client.ts index 94ffe78..465b6c6 100644 --- a/src/contract-client.ts +++ b/src/contract-client.ts @@ -50,7 +50,7 @@ export class ContractClient extends BaseRestClient { /** Query order book info. Each side has a depth of 25 orders. */ getOrderBook( symbol: string, - category: string, + category?: string, limit?: number ): Promise> { return this.get('/derivatives/v3/public/order-book/L2', { diff --git a/src/websocket-client.ts b/src/websocket-client.ts index 2d63d46..bfe430c 100644 --- a/src/websocket-client.ts +++ b/src/websocket-client.ts @@ -544,6 +544,7 @@ export class WebsocketClient extends EventEmitter { private reconnectWithDelay(wsKey: WsKey, connectionDelayMs: number) { this.clearTimers(wsKey); + if ( this.wsStore.getConnectionState(wsKey) !== WsConnectionStateEnum.CONNECTING diff --git a/test/contract/private.read.test.ts b/test/contract/private.read.test.ts index db75eae..9ab08d8 100644 --- a/test/contract/private.read.test.ts +++ b/test/contract/private.read.test.ts @@ -71,11 +71,11 @@ describe('Private Contract REST API GET Endpoints', () => { ); }); - // Doesn't work on e2e test account, something about account state. Investigating with bybit. - it.skip('getOpenInterestLimitInfo()', async () => { + // Doesn't work on e2e test account. This endpoint throws this error if the account never opened a position before. + it('getOpenInterestLimitInfo()', async () => { expect(await api.getOpenInterestLimitInfo('ETHUSDT')).toMatchObject({ - ...successResponseObjectV3(), - retMsg: 'ok', + retCode: API_ERROR_CODE.PARAMS_MISSING_OR_WRONG, + retMsg: expect.stringMatching(/OI group don't exist/gim), }); }); diff --git a/test/response.util.ts b/test/response.util.ts index 1044b09..8ff4623 100644 --- a/test/response.util.ts +++ b/test/response.util.ts @@ -31,6 +31,7 @@ export function successResponseObjectV3() { return { result: expect.any(Object), ...successEmptyResponseObjectV3(), + // retMsg: 'ok', }; }