Node.js SDK for the Bybit APIs and WebSockets, with TypeScript & browser support.
Node.js connector for the Bybit APIs and WebSockets:
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.
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.
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:
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.
SpotClient
is now deprecated in favour of the new SpotClientV3
(which uses the newer v3 spot APIs).key
parameter has been moved into the restOptions object.secret
parameter has been moved into the restOptions object.useLivenet
parameter has been renamed to testnet
and moved into the restOptions object.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.enable_type_sync: true
in the rest options object parameter.testnet: true
is provided in the ws client options.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).wsKeySpotPublic
have been grouped under a WS_KEY_MAP
object.
WS_KEY_MAP.spotPublic
instead.spotv3
market is very much recommended (it supports automatic re-subscribe if the connection drops & reconnects)livenet
parameter has been deprecated in favour of testnet: boolean
.testnet: true
in your client options.
This expands the library to support the spot REST & Websocket APIs.
npm install [email protected]
The WebSocket client now accepts a new parameter for market
.
This should be used instead of the boolean linear
parameter, which will be removed in a future release. Check the readme for examples.
This adds the missing mode/switch APIs for the inverse client, see #98 for details. This also significantly reduces the size of the webpack bundle for use in web browsers, see #59 for details.
npm install [email protected]
See #83 for details. This adds support for Inverse Futures REST endpoints, currently only available for quarterly BTC futures on testnet.
npm install [email protected]
InverseFuturesClient
. Resolves #82.trailing_stop
parameter for inverse client setTradingStop()
.See #80 for details. This fixes a pass-through parameter to pass a custom base URL in the REST constructors.
npm install [email protected]
See #75 for details. This primarily introduces support for the Linear USDT APIs and WebSockets, although two minimal changes were introduced to how the existing inverse client (previously RestClient) is imported and when websockets start connecting.
npm install [email protected]
RestClient
to InverseClient
. Implementation remains unchanged.This release only has one major change affecting existing usage.
RestClient
to InverseClient
. Implementation remains unchanged.Simply rename any existing RestClient
import to continue using Inverse Rest APIs.
The following are not expected to cause any issues but are a notable change in behaviour:
2.0.0
(this release), websocket connections are automatically opened as soon as any topics are subscribed to.websocketClient.connectAll()
method. See Websocket-Client.ts for details.Small fix to the error handler when API requests fail.
See #45 for details. This was a major transition from a pureJS library into one that is loosely typed, at least as a first iteration.
npm install [email protected]
Copied from the pull request:
assert()
calls. This caused a nuisance when API parameter requirements changed.These changes were enforced by bybit:
These are a consequence of module improvements:
The primary goal was to transition to axios, since the npm module request is both deprecated and carries a ton of dependency baggage. This version does not change any high level functionality, ensuring no integration changes are required to upgrade to this release.
As well as a smaller memory footprint, an additional bonus of this adoption of axios
is support for proxied requests as well as other customizations to how HTTP requests are made by the library. See the axios request config for a detailed list of options.
None