Gathering detailed insights and metrics for bybit-api-node
Gathering detailed insights and metrics for bybit-api-node
Gathering detailed insights and metrics for bybit-api-node
Gathering detailed insights and metrics for bybit-api-node
bybit-api
Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.
bybit-node-api
An unofficial node.js lowlevel wrapper for the Bybit Cryptocurrency Derivative exchange API
bybit-api-gnome
Forked for Lick Hunter, Complete & robust node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.
@zz554952942/bybit-api
Node.js connector for Bybit's REST APIs and WebSockets, with TypeScript & integration tests.
npm install bybit-api-node
Typescript
Module System
Node Version
NPM Version
72.2
Supply Chain
98.7
Quality
75.3
Maintenance
50
Vulnerability
100
License
Total Downloads
1,779
Last Day
6
Last Week
9
Last Month
21
Last Year
866
Minified
Minified + Gzipped
Latest Version
1.0.3
Package Id
bybit-api-node@1.0.3
Unpacked Size
500.75 kB
Size
91.84 kB
File Count
189
NPM Version
9.1.2
Node Version
18.12.1
Publised On
27 Feb 2023
Cumulative downloads
Total Downloads
Last day
500%
6
Compared to previous day
Last week
80%
9
Compared to previous week
Last month
-71.6%
21
Compared to previous month
Last year
-5.1%
866
Compared to previous year
Node.js Rest & WS client for the Bybit:
npm install --save bybit-api-node
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).
This connector is fully compatible with both TypeScript and pure JavaScript projects, while the connector is written in TypeScript. A pure JavaScript version can be built using npm run build
, which is also the version published to npm.
The version on npm is the output from the build
command and can be used in projects without TypeScript (although TypeScript is definitely recommended).
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 |
---|---|
[ 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. |
RestClientV5 | Coming soon... Unified V5 all-in-one REST client for all V5 REST APIs |
[ Derivatives v3 ] | The Derivatives v3 APIs (successor to the Futures V2 APIs) |
UnifiedMarginClient | Derivatives (v3) Unified Margin APIs |
ContractClient | Derivatives (v3) Contract APIs. |
[ Futures v2 ] | The Futures v2 APIs |
InverseClient | Inverse Perpetual Futures (v2) APIs |
LinearClient | USDT Perpetual Futures (v2) APIs |
InverseFuturesClient | Inverse Futures (v2) APIs |
[ Spot ] | The spot APIs |
SpotClientV3 | Spot Market (v3) APIs |
Spot Market (v1) APIs | |
[ USDC Contract ] | The USDC Contract APIs |
USDCPerpetualClient | USDC Perpetual APIs |
USDCOptionClient | USDC Option APIs |
[ Other ] | Other standalone API groups |
CopyTradingClient | Copy Trading APIs |
AccountAssetClientV3 | Account Asset V3 APIs |
Account Asset V1 APIs | |
WebsocketClient | All WebSocket Events (Public & Private for all API categories) |
Examples for using each client can be found in:
If you're missing an example, you're welcome to request one. Priority will be given to github sponsors.
Create API credentials on Bybit's website:
All REST clients have can be used in a similar way. However, method names, parameters and responses may vary depending on the API category you're using!
Not sure which function to call or which parameters to use? Click the class name in the table above to look at all the function names (they are in the same order as the official API docs), and check the API docs for a list of endpoints/paramters/responses.
1const { 2 InverseClient, 3 LinearClient, 4 InverseFuturesClient, 5 SpotClient, 6 SpotClientV3, 7 UnifiedMarginClient, 8 USDCOptionClient, 9 USDCPerpetualClient, 10 AccountAssetClient, 11 CopyTradingClient, 12} = require('bybit-api-node'); 13 14const restClientOptions = { 15 /** Your API key. Optional, if you plan on making private api calls */ 16 key?: string; 17 18 /** Your API secret. Optional, if you plan on making private api calls */ 19 secret?: string; 20 21 /** Set to `true` to connect to testnet. Uses the live environment by default. */ 22 testnet?: boolean; 23 24 /** Override the max size of the request window (in ms) */ 25 recv_window?: number; 26 27 /** Disabled by default. This can help on machines with consistent latency problems. */ 28 enable_time_sync?: boolean; 29 30 /** How often to sync time drift with bybit servers */ 31 sync_interval_ms?: number | string; 32 33 /** Default: false. If true, we'll throw errors if any params are undefined */ 34 strict_param_validation?: boolean; 35 36 /** 37 * Optionally override API protocol + domain 38 * e.g baseUrl: 'https://api.bytick.com' 39 **/ 40 baseUrl?: string; 41 42 /** Default: true. whether to try and post-process request exceptions. */ 43 parse_exceptions?: boolean; 44}; 45 46const API_KEY = 'xxx'; 47const API_SECRET = 'yyy'; 48const useTestnet = false; 49 50const client = new InverseClient({ 51 key: API_KEY, 52 secret: API_SECRET, 53 testnet: useTestnet 54}, 55 // requestLibraryOptions 56); 57 58// For public-only API calls, simply don't provide a key & secret or set them to undefined 59// const client = new InverseClient({}); 60 61client.getApiKeyInfo() 62 .then(result => { 63 console.log("getApiKeyInfo result: ", result); 64 }) 65 .catch(err => { 66 console.error("getApiKeyInfo error: ", err); 67 }); 68 69client.getOrderBook({ symbol: 'BTCUSD' }) 70 .then(result => { 71 console.log("getOrderBook result: ", result); 72 }) 73 .catch(err => { 74 console.error("getOrderBook error: ", err); 75 });
All API groups can be used via a shared WebsocketClient
. However, to listen to multiple API groups at once, you will need to make one WebsocketClient instance per API group.
The WebsocketClient can be configured to a specific API group using the market parameter. These are the currently available API groups:
API Category | Market | Description |
---|---|---|
Unified Margin - Options | market: 'unifiedOption' | The derivatives v3 category for unified margin. Note: public topics only support options topics. If you need USDC/USDT perps, use unifiedPerp instead. |
Unified Margin - Perps | market: 'unifiedPerp' | The derivatives v3 category for unified margin. Note: public topics only support USDT/USDC perpetual topics - use unifiedOption if you need public options topics. |
Futures v2 - Inverse Perps | market: 'inverse' | The inverse v2 perps category. |
Futures v2 - USDT Perps | market: 'linear' | The USDT/linear v2 perps category. |
Futures v2 - Inverse Futures | market: 'inverse' | The inverse futures v2 category uses the same market as inverse perps. |
Spot v3 | market: 'spotv3' | The spot v3 category. |
Spot v1 | market: 'spot' | The older spot v1 category. Use the spotv3 market if possible, as the v1 category does not have automatic re-subscribe if reconnected. |
Copy Trading | market: 'linear' | The copy trading category. Use the linear market to listen to all copy trading topics. |
USDC Perps | market: 'usdcPerp | The USDC perps category. |
USDC Options | market: 'usdcOption' | The USDC options category. |
Contract v3 USDT | market: 'contractUSDT' | The Contract V3 category (USDT perps) |
Contract v3 Inverse | market: 'contractInverse' | The Contract V3 category (inverse perps) |
1const { WebsocketClient } = require('bybit-api-node') 2 3const API_KEY = 'xxx' 4const PRIVATE_KEY = 'yyy' 5 6const wsConfig = { 7 key: API_KEY, 8 secret: PRIVATE_KEY, 9 10 /* 11 The following parameters are optional: 12 */ 13 14 // defaults to true == livenet 15 // testnet: false 16 17 // NOTE: to listen to multiple markets (spot vs inverse vs linear vs linearfutures) at once, make one WebsocketClient instance per market 18 19 market: 'linear', 20 // market: 'inverse', 21 // market: 'spot', 22 // market: 'spotv3', 23 // market: 'usdcOption', 24 // market: 'usdcPerp', 25 // market: 'unifiedPerp', 26 // market: 'unifiedOption', 27 28 // how long to wait (in ms) before deciding the connection should be terminated & reconnected 29 // pongTimeout: 1000, 30 31 // how often to check (in ms) that WS connection is still alive 32 // pingInterval: 10000, 33 34 // how long to wait before attempting to reconnect (in ms) after connection is closed 35 // reconnectTimeout: 500, 36 37 // config options sent to RestClient (used for time sync). See RestClient docs. 38 // restOptions: { }, 39 40 // config for axios used for HTTP requests. E.g for proxy support 41 // requestOptions: { } 42 43 // override which URL to use for websocket connections 44 // wsUrl: 'wss://stream.bytick.com/realtime' 45} 46 47const ws = new WebsocketClient(wsConfig) 48 49// subscribe to multiple topics at once 50ws.subscribe(['position', 'execution', 'trade']) 51 52// and/or subscribe to individual topics on demand 53ws.subscribe('kline.BTCUSD.1m') 54 55// Listen to events coming from websockets. This is the primary data source 56ws.on('update', (data) => { 57 console.log('update', data) 58}) 59 60// Optional: Listen to websocket connection open event (automatic after subscribing to one or more topics) 61ws.on('open', ({ wsKey, event }) => { 62 console.log('connection open for websocket with ID: ' + wsKey) 63}) 64 65// Optional: Listen to responses to websocket queries (e.g. the response after subscribing to a topic) 66ws.on('response', (response) => { 67 console.log('response', response) 68}) 69 70// Optional: Listen to connection close event. Unexpected connection closes are automatically reconnected. 71ws.on('close', () => { 72 console.log('connection closed') 73}) 74 75// Optional: Listen to raw error events. Recommended. 76ws.on('error', (err) => { 77 console.error('error', err) 78})
See websocket-client.ts for further information.
Pass a custom logger which supports the log methods silly
, debug
, notice
, info
, warning
and error
, or override methods from the default logger as desired.
1const { WebsocketClient, DefaultLogger } = require('bybit-api-node') 2 3// Disable all logging on the silly level 4const customLogger = { 5 ...DefaultLogger, 6 silly: () => {}, 7} 8 9const ws = new WebsocketClient({ key: 'xxx', secret: 'yyy' }, customLogger)
Build a bundle using webpack:
npm install
npm build
npm pack
No vulnerabilities found.
No security vulnerabilities found.