v3.5.0: release V5 REST client for bybit

This commit is contained in:
tiagosiebler
2023-02-23 12:07:54 +00:00
parent 00a45e4cd0
commit a786da23e3
3 changed files with 63 additions and 12 deletions

View File

@@ -43,9 +43,9 @@ Check out my related projects:
## Documentation ## 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 ## 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 ## 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 | | 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). | | [ **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, InverseClient,
LinearClient, LinearClient,
InverseFuturesClient, InverseFuturesClient,
SpotClient,
SpotClientV3, SpotClientV3,
UnifiedMarginClient, UnifiedMarginClient,
USDCOptionClient, USDCOptionClient,
USDCPerpetualClient, USDCPerpetualClient,
AccountAssetClient, AccountAssetClient,
CopyTradingClient, CopyTradingClient,
RestClientV5,
} = require('bybit-api'); } = require('bybit-api');
const restClientOptions = { const restClientOptions = {
@@ -155,7 +159,7 @@ const API_KEY = 'xxx';
const API_SECRET = 'yyy'; const API_SECRET = 'yyy';
const useTestnet = false; const useTestnet = false;
const client = new InverseClient({ const client = new RestClientV5({
key: API_KEY, key: API_KEY,
secret: API_SECRET, secret: API_SECRET,
testnet: useTestnet 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 // 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 => { .then(result => {
console.log("getApiKeyInfo result: ", result); console.log("getAccountInfo result: ", result);
}) })
.catch(err => { .catch(err => {
console.error("getApiKeyInfo error: ", err); console.error("getAccountInfo error: ", err);
}); });
client.getOrderBook({ symbol: 'BTCUSD' }) client.getOrderbook({ category: 'linear', symbol: 'BTCUSD' })
.then(result => { .then(result => {
console.log("getOrderBook result: ", 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. | | 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 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) | | 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 ```javascript
const { WebsocketClient } = require('bybit-api'); const { WebsocketClient } = require('bybit-api');

46
examples/rest-v5-all.ts Normal file
View File

@@ -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);
}
})();

View File

@@ -1,7 +1,7 @@
{ {
"name": "bybit-api", "name": "bybit-api",
"version": "3.5.0-beta.0", "version": "3.5.0",
"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 & strong end to end tests.",
"main": "lib/index.js", "main": "lib/index.js",
"types": "lib/index.d.ts", "types": "lib/index.d.ts",
"files": [ "files": [