Refer to npm for latest releases
For an up to date list of releases and updates, refer to:
- Closed Pull Requests: https://github.com/tiagosiebler/bybit-api/pulls?q=is%3Apr+is%3Aclosed
- NPM: https://www.npmjs.com/package/bybit-api?activeTab=versions
The above links are the best place to stay up to date on the latest releases for this SDK.
Node.js connector for the Bybit APIs and WebSockets:
- Complete integration with all bybit APIs.
- TypeScript support (with type declarations for most API requests & responses).
- Over 300 integration tests making real API calls & WebSocket connections, validating any changes before they reach npm.
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
- Browser support (via webpack bundle - see "Browser Usage" below).
This major release introduces 6 new REST clients and hundreds of integration tests. The bybit-api npm connector now supports all REST API and WebSocket categories, including the very recently added unified margin and copy trading categories.
REST APIs
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 |
|---|---|
| InverseClient | Inverse Perpetual Futures (v2) APIs |
| LinearClient | USDT Perpetual Futures (v2) APIs |
| InverseFuturesClient | Inverse Futures (v2) APIs |
| USDCPerpetualClient | USDC Perpetual APIs |
| USDCOptionClient | USDC Option APIs |
| UnifiedMarginClient | Derivatives (v3) unified margin APIs |
| SpotClientV3 | Spot Market (v3) APIs |
| Spot Market (v1) APIs | |
| AccountAssetClient | Account Asset APIs |
| CopyTradingClient | Copy Trading APIs |
| WebsocketClient | All WebSocket Events (Public & Private for all API categories) |
Examples for using each client can be found in:
- the examples folder.
- the awesome-crypto-examples repository.
If you're missing an example, you're welcome to request one. Priority will be given to github sponsors.
WebSockets
For WebSockets, 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 (for now).
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. |
Check the readme for an example. More examples will be added in the future, and will be found in the following locations:
- the examples folder.
- the awesome-crypto-examples repository (note, these will be updated shortly).
Issues & Discussion
- Issues? Check the issues tab.
- Discuss & collaborate with other node devs? Join our Node.js Algo Traders engineering community on telegram.
Breaking Changes
While I have tried to avoid any breaking changes as much as possible, I have decided to accept some as part of this major release as an opportunity for improvement. If you notice any other breaking changes not listed below, please let me know.
REST Clients
- The
SpotClientis now deprecated in favour of the newSpotClientV3(which uses the newer v3 spot APIs). - The
keyparameter has been moved into the restOptions object. - The
secretparameter has been moved into the restOptions object. - The
useLivenetparameter has been renamed totestnetand moved into the restOptions object. - The REST clients now connect to the live environment by default, unless
testnet: trueis provided inrestOptions.
All REST clients now accept only two parameters:
constructor(
restOptions: RestClientOptions = {},
networkOptions: AxiosRequestConfig = {}
) API credentials are passed into the first parameter.
disable_time_synchas been removed from the rest client options, since time sync is now disabled by default.- To re-enable time sync, use
enable_type_sync: truein the rest options object parameter.
Websocket-Client
- The WS client now connects to the live environment by default, unless
testnet: trueis provided in the ws client options. - The
marketparameter is now required in the ws client config. It tells the websocket client which websocket URL to use, since there's variation between spotv1, spotv3, futures, unified margin and other markets. Check theAPIMarketunion type for a list of possible values (which your IDE should also be able to show, if you're using typescript). - Constant parameters such as
wsKeySpotPublichave been grouped under aWS_KEY_MAPobject.- The WsKey values remain the same, with some new additions.
- If you were using the exported constant (e.g. wsKeySpotPublic), you will need to update your code to use
WS_KEY_MAP.spotPublicinstead. - If you were using the spot market, the
spotv3market is very much recommended (it supports automatic re-subscribe if the connection drops & reconnects)
- The
livenetparameter has been deprecated in favour oftestnet: boolean. - The websocket client now connects to livenet by default. If you want to use testnet, include the parameter
testnet: truein your client options.- This is consistent with my other api connectors, which connect to livenet by default.
- In future, the REST clients will also connect to the live environment by default.