Gathering detailed insights and metrics for @zz554952942/bybit-api
Gathering detailed insights and metrics for @zz554952942/bybit-api
Gathering detailed insights and metrics for @zz554952942/bybit-api
Gathering detailed insights and metrics for @zz554952942/bybit-api
Node.js SDK for the Bybit APIs and WebSockets, with TypeScript & browser support.
npm install @zz554952942/bybit-api
Typescript
Module System
Node Version
NPM Version
74
Supply Chain
99.6
Quality
75.6
Maintenance
50
Vulnerability
100
License
v4.2.7: WS subscribe requests are now batched into groups of max 500 topics
Updated on Aug 25, 2025
v4.2.6: fix deduping workflow for websockets introduced in 4.2.5
Updated on Aug 25, 2025
v4.2.5: automatically dedupe subscribe requests
Updated on Aug 25, 2025
v4.2.4: Add full support for RFQ endpoints
Updated on Aug 13, 2025
v4.2.3: Introduce modern token-less publishing workflow
Updated on Aug 12, 2025
Refer to npm for latest releases
Updated on Sep 19, 2022
TypeScript (99.21%)
JavaScript (0.79%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
302 Stars
1,194 Commits
100 Forks
12 Watchers
2 Branches
28 Contributors
Updated on Aug 29, 2025
Latest Version
2.1.15
Package Id
@zz554952942/bybit-api@2.1.15
Unpacked Size
170.91 kB
Size
32.20 kB
File Count
55
NPM Version
8.1.2
Node Version
16.13.1
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Node.js connector for the Bybit APIs and WebSockets, with TypeScript & browser support.
npm install --save bybit-api
Most methods accept JS objects. These can be populated using parameters specified by Bybit's API documentation.
This project uses typescript. Resources are stored in 3 key structures:
Create API credentials at Bybit
There are three REST API modules as there are some differences in each contract type.
InverseClient
for inverse perpetualInverseFuturesClient
for inverse futuresLinearClient
for linear perpetualTo use the inverse REST APIs, import the InverseClient
:
1const { InverseClient } = require('bybit-api'); 2 3const restClientOptions = { 4 // override the max size of the request window (in ms) 5 recv_window?: number; 6 7 // how often to sync time drift with bybit servers 8 sync_interval_ms?: number | string; 9 10 // Default: false. Disable above sync mechanism if true. 11 disable_time_sync?: boolean; 12 13 // Default: false. If true, we'll throw errors if any params are undefined 14 strict_param_validation?: boolean; 15 16 // Optionally override API protocol + domain 17 // e.g 'https://api.bytick.com' 18 baseUrl?: string; 19 20 // Default: true. whether to try and post-process request exceptions. 21 parse_exceptions?: boolean; 22}; 23 24const API_KEY = 'xxx'; 25const PRIVATE_KEY = 'yyy'; 26const useLivenet = false; 27 28const client = new InverseClient( 29 API_KEY, 30 PRIVATE_KEY, 31 32 // optional, uses testnet by default. Set to 'true' to use livenet. 33 useLivenet, 34 35 // restClientOptions, 36 // requestLibraryOptions 37); 38 39client.getApiKeyInfo() 40 .then(result => { 41 console.log("apiKey result: ", result); 42 }) 43 .catch(err => { 44 console.error("apiKey error: ", err); 45 }); 46 47client.getOrderBook({ symbol: 'BTCUSD' }) 48 .then(result => { 49 console.log("getOrderBook inverse result: ", result); 50 }) 51 .catch(err => { 52 console.error("getOrderBook inverse error: ", err); 53 });
See inverse-client.ts for further information.
To use the inverse futures REST APIs, import the InverseFuturesClient
:
1const { InverseFuturesClient } = require('bybit-api'); 2 3const API_KEY = 'xxx'; 4const PRIVATE_KEY = 'yyy'; 5const useLivenet = false; 6 7const client = new InverseFuturesClient( 8 API_KEY, 9 PRIVATE_KEY, 10 11 // optional, uses testnet by default. Set to 'true' to use livenet. 12 useLivenet, 13 14 // restClientOptions, 15 // requestLibraryOptions 16); 17 18client.getApiKeyInfo() 19 .then(result => { 20 console.log("apiKey result: ", result); 21 }) 22 .catch(err => { 23 console.error("apiKey error: ", err); 24 }); 25 26client.getOrderBook({ symbol: 'BTCUSDH21' }) 27 .then(result => { 28 console.log("getOrderBook inverse futures result: ", result); 29 }) 30 .catch(err => { 31 console.error("getOrderBook inverse futures error: ", err); 32 });
See inverse-futures-client.ts for further information.
To use the Linear (USDT) REST APIs, import the LinearClient
:
1const { LinearClient } = require('bybit-api'); 2 3const API_KEY = 'xxx'; 4const PRIVATE_KEY = 'yyy'; 5const useLivenet = false; 6 7const client = new LinearClient( 8 API_KEY, 9 PRIVATE_KEY, 10 11 // optional, uses testnet by default. Set to 'true' to use livenet. 12 useLivenet, 13 14 // restClientOptions, 15 // requestLibraryOptions 16); 17 18client.getApiKeyInfo() 19 .then(result => { 20 console.log(result); 21 }) 22 .catch(err => { 23 console.error(err); 24 }); 25 26client.getOrderBook({ symbol: 'BTCUSDT' }) 27 .then(result => { 28 console.log("getOrderBook linear result: ", result); 29 }) 30 .catch(err => { 31 console.error("getOrderBook linear error: ", err); 32 });
See linear-client.ts for further information.
To use the Spot REST APIs, import the SpotClient
:
1const { SpotClient } = require('bybit-api'); 2 3const API_KEY = 'xxx'; 4const PRIVATE_KEY = 'yyy'; 5const useLivenet = false; 6 7const client = new SpotClient( 8 API_KEY, 9 PRIVATE_KEY, 10 11 // optional, uses testnet by default. Set to 'true' to use livenet. 12 useLivenet, 13 14 // restClientOptions, 15 // requestLibraryOptions 16); 17 18client.getSymbols() 19 .then(result => { 20 console.log(result); 21 }) 22 .catch(err => { 23 console.error(err); 24 }); 25 26client.getBalances() 27 .then(result => { 28 console.log("getBalances result: ", result); 29 }) 30 .catch(err => { 31 console.error("getBalances error: ", err); 32 });
See spot-client.ts for further information.
Inverse, linear & spot WebSockets can be used via a shared WebsocketClient
. However, make sure to make one instance of WebsocketClient per market type (spot vs inverse vs linear vs linearfutures):
1const { WebsocketClient } = require('bybit-api'); 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 false == testnet. Set to true for livenet. 15 // livenet: true 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 // defaults to inverse: 20 // market: 'inverse' 21 // market: 'linear' 22 // market: 'spot' 23 24 // how long to wait (in ms) before deciding the connection should be terminated & reconnected 25 // pongTimeout: 1000, 26 27 // how often to check (in ms) that WS connection is still alive 28 // pingInterval: 10000, 29 30 // how long to wait before attempting to reconnect (in ms) after connection is closed 31 // reconnectTimeout: 500, 32 33 // config options sent to RestClient (used for time sync). See RestClient docs. 34 // restOptions: { }, 35 36 // config for axios used for HTTP requests. E.g for proxy support 37 // requestOptions: { } 38 39 // override which URL to use for websocket connections 40 // wsUrl: 'wss://stream.bytick.com/realtime' 41}; 42 43const ws = new WebsocketClient(wsConfig); 44 45// subscribe to multiple topics at once 46ws.subscribe(['position', 'execution', 'trade']); 47 48// and/or subscribe to individual topics on demand 49ws.subscribe('kline.BTCUSD.1m'); 50 51// Listen to events coming from websockets. This is the primary data source 52ws.on('update', data => { 53 console.log('update', data); 54}); 55 56// Optional: Listen to websocket connection open event (automatic after subscribing to one or more topics) 57ws.on('open', ({ wsKey, event }) => { 58 console.log('connection open for websocket with ID: ' + wsKey); 59}); 60 61// Optional: Listen to responses to websocket queries (e.g. the response after subscribing to a topic) 62ws.on('response', response => { 63 console.log('response', response); 64}); 65 66// Optional: Listen to connection close event. Unexpected connection closes are automatically reconnected. 67ws.on('close', () => { 68 console.log('connection closed'); 69}); 70 71// Optional: Listen to raw error events. 72// Note: responses to invalid topics are currently only sent in the "response" event. 73ws.on('error', err => { 74 console.error('ERR', err); 75});
See websocket-client.ts for further information.
Note: for linear websockets, pass linear: true
in the constructor options when instancing the WebsocketClient
. To connect to both linear and inverse websockets, make two instances of the WebsocketClient.
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'); 2 3// Disable all logging on the silly level 4DefaultLogger.silly = () => {}; 5 6const ws = new WebsocketClient( 7 { key: 'xxx', secret: 'yyy' }, 8 DefaultLogger 9);
Build a bundle using webpack:
npm install
npm build
npm pack
The bundle can be found in dist/
. Altough usage should be largely consistent, smaller differences will exist. Documentation is still TODO.
However, note that browser usage will lead to CORS errors due Bybit. See issue #79 for more information & alternative suggestions.
If you found this project interesting or useful, create accounts with my referral links:
Or buy me a coffee using any of these:
1C6GWZL1XW3jrjpPTS863XtZiXL1aTK7Jk
0xd773d8e6a50758e1ada699bb6c4f98bb4abf82da
The original library was started by @pixtron. If this library helps you to trade better on bybit, feel free to donate a coffee to @pixtron:
1Fh1158pXXudfM6ZrPJJMR7Y5SgZUz4EdF
0x21aEdeC53ab7593b77C9558942f0c9E78131e8d7
LNdHSVtG6UWsriMYLJR3qLdfVNKwJ6GSLF
Contributions are encouraged, I will review any incoming pull requests. See the issues tab for todo items.
No vulnerabilities found.