From a786da23e3d34e11816e8dd941264fc103796259 Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Thu, 23 Feb 2023 12:07:54 +0000 Subject: [PATCH] v3.5.0: release V5 REST client for bybit --- README.md | 25 +++++++++++++--------- examples/rest-v5-all.ts | 46 +++++++++++++++++++++++++++++++++++++++++ package.json | 4 ++-- 3 files changed, 63 insertions(+), 12 deletions(-) create mode 100644 examples/rest-v5-all.ts diff --git a/README.md b/README.md index 035831d..b4f3b95 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,9 @@ Check out my related projects: ## Documentation -Most methods accept JS objects. These can be populated using parameters specified by Bybit's API documentation, or check the type definition in each class within this repository (see table below for convenient links to each class). +Most methods accept JS objects. These can be populated using parameters specified by Bybit's API documentation, or check the type definition in each class within the github repository (see table below for convenient links to each class). -- [Bybit API Docs (choose API category from the tabs at the top)](https://bybit-exchange.github.io/docs/futuresV2/inverse/#t-introduction). +- [Bybit API Docs (choose API category from the tabs at the top)](https://bybit-exchange.github.io/docs/v5/intro). ## Structure @@ -62,7 +62,11 @@ The version on npm is the output from the `build` command and can be used in pro ## REST API Clients -Each REST API group has a dedicated REST client. To avoid confusion, here are the available REST clients and the corresponding API groups: +Bybit has several API groups (originally one per product). Each generation is labelled with the version number (e.g. v1/v2/v3/v5). Some of the newer API groups can only be used by upgrading your account to the unified account, but doing so will prevent you from using the V1 and V2 APIs. + +Refer to the [V5 upgrade guide](https://bybit-exchange.github.io/docs/v5/upgrade-guide) for more information on requirements to use each API group. If you have a choice, you should use the newest generation that is available (e.g. use the V5 instead of the V3 APIs if you can). + +Here are the available REST clients and the corresponding API groups described in the documentation: | Class | Description | |:------------------------------------------------------------------: |:----------------------------------------------------------------------------------------------------------------------------: | | [ **V5 API** ] | The new unified V5 APIs (successor to previously fragmented APIs for all API groups). To learn more about the V5 API, please read the [V5 upgrade guideline](https://bybit-exchange.github.io/docs/v5/upgrade-guide). | @@ -110,13 +114,13 @@ const { InverseClient, LinearClient, InverseFuturesClient, - SpotClient, SpotClientV3, UnifiedMarginClient, USDCOptionClient, USDCPerpetualClient, AccountAssetClient, CopyTradingClient, + RestClientV5, } = require('bybit-api'); const restClientOptions = { @@ -155,7 +159,7 @@ const API_KEY = 'xxx'; const API_SECRET = 'yyy'; const useTestnet = false; -const client = new InverseClient({ +const client = new RestClientV5({ key: API_KEY, secret: API_SECRET, testnet: useTestnet @@ -164,17 +168,17 @@ const client = new InverseClient({ ); // For public-only API calls, simply don't provide a key & secret or set them to undefined -// const client = new InverseClient({}); +// const client = new RestClientV5({}); -client.getApiKeyInfo() +client.getAccountInfo() .then(result => { - console.log("getApiKeyInfo result: ", result); + console.log("getAccountInfo result: ", result); }) .catch(err => { - console.error("getApiKeyInfo error: ", err); + console.error("getAccountInfo error: ", err); }); -client.getOrderBook({ symbol: 'BTCUSD' }) +client.getOrderbook({ category: 'linear', symbol: 'BTCUSD' }) .then(result => { console.log("getOrderBook result: ", result); }) @@ -202,6 +206,7 @@ The WebsocketClient can be configured to a specific API group using the market p | USDC Options | `market: 'usdcOption'`| The [USDC options](https://bybit-exchange.github.io/docs/usdc/option/#t-websocket) category. | | Contract v3 USDT | `market: 'contractUSDT'`| The [Contract V3](https://bybit-exchange.github.io/docs/derivativesV3/contract/#t-websocket) category (USDT perps) | | Contract v3 Inverse | `market: 'contractInverse'`| The [Contract V3](https://bybit-exchange.github.io/docs/derivativesV3/contract/#t-websocket) category (inverse perps) | +| V5 Subscriptions | Coming soon | The [v5](https://bybit-exchange.github.io/docs/v5/ws/connect) websockets will be supported in the next release. | ```javascript const { WebsocketClient } = require('bybit-api'); diff --git a/examples/rest-v5-all.ts b/examples/rest-v5-all.ts new file mode 100644 index 0000000..a64d178 --- /dev/null +++ b/examples/rest-v5-all.ts @@ -0,0 +1,46 @@ +import { RestClientV5 } from '../src/index'; + +// or +// import { RestClientV5 } from 'bybit-api'; + +const key = process.env.API_KEY_COM; +const secret = process.env.API_SECRET_COM; + +const client = new RestClientV5({ + key: key, + secret: secret, +}); + +/** + * If you don't plan on making any private api calls, + * you can instance the REST client without any parameters: + * + * const client = new RestClientV5(); + */ + +(async () => { + try { + const klineResult = await client.getKline({ + category: 'linear', + interval: '15', + symbol: 'BTCUSDT', + }); + console.log('klineResult: ', klineResult); + + const markPriceKlineResult = await client.getMarkPriceKline({ + category: 'linear', + interval: '15', + symbol: 'BTCUSDT', + }); + console.log('markPriceKlineResult: ', markPriceKlineResult); + + const indexPriceKline = await client.getIndexPriceKline({ + category: 'linear', + interval: '15', + symbol: 'BTCUSDT', + }); + console.log('indexPriceKline: ', indexPriceKline); + } catch (e) { + console.error('request failed: ', e); + } +})(); diff --git a/package.json b/package.json index 25bad6c..e5089fb 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "bybit-api", - "version": "3.5.0-beta.0", - "description": "Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.", + "version": "3.5.0", + "description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.", "main": "lib/index.js", "types": "lib/index.d.ts", "files": [