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.2
Supply Chain
99.6
Quality
75.6
Maintenance
50
Vulnerability
100
License
v3.0.1: Complete integration for all REST API & WebSocket Groups
Published on 19 Sept 2022
Spot clients for REST & Websockets
Published on 15 Aug 2021
Reduced webpack bundle & missing inverse APIs.
Published on 12 Jun 2021
Inverse Futures Support
Published on 06 Mar 2021
Fix custom base URL parameter
Published on 18 Feb 2021
Linear USDT Support
Published on 16 Feb 2021
TypeScript (98.88%)
JavaScript (1.12%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
264 Stars
973 Commits
84 Forks
9 Watching
2 Branches
24 Contributors
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%
0
Compared to previous day
Last week
0%
0
Compared to previous week
Last month
0%
0
Compared to previous month
Last year
0%
0
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.
Reason
30 commit(s) and 12 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
Found 9/10 approved changesets -- score normalized to 9
Reason
1 existing vulnerabilities detected
Details
Reason
dependency not pinned by hash detected -- score normalized to 6
Details
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-01-06
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More