Skip to content

v3.0.1: Complete integration for all REST API & WebSocket Groups

Latest
Compare
Choose a tag to compare
@tiagosiebler tiagosiebler released this 19 Sep 23:37
· 316 commits to master since this release
2971dd7

connector logo

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
SpotClient (deprecated, v3 client recommended) 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:

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:

Issues & Discussion

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 SpotClient is now deprecated in favour of the new SpotClientV3 (which uses the newer v3 spot APIs).
  • The key parameter has been moved into the restOptions object.
  • The secret parameter has been moved into the restOptions object.
  • The useLivenet parameter has been renamed to testnet and moved into the restOptions object.
  • The REST clients now connect to the live environment by default, unless testnet: true is provided in restOptions.

All REST clients now accept only two parameters:

  constructor(
    restOptions: RestClientOptions = {},
    networkOptions: AxiosRequestConfig = {}
  ) 

API credentials are passed into the first parameter.

  • disable_time_sync has been removed from the rest client options, since time sync is now disabled by default.
  • To re-enable time sync, use enable_type_sync: true in the rest options object parameter.

Websocket-Client

  • The WS client now connects to the live environment by default, unless testnet: true is provided in the ws client options.
  • The market parameter 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 the APIMarket union 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 wsKeySpotPublic have been grouped under a WS_KEY_MAP object.
    • 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.spotPublic instead.
    • If you were using the spot market, the spotv3 market is very much recommended (it supports automatic re-subscribe if the connection drops & reconnects)
  • The livenet parameter has been deprecated in favour of testnet: boolean.
  • The websocket client now connects to livenet by default. If you want to use testnet, include the parameter testnet: true in 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.