Releases: tiagosiebler/bybit-api
v3.0.1: Complete integration for all REST API & WebSocket Groups
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
SpotClient
is now deprecated in favour of the newSpotClientV3
(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 totestnet
and moved into the restOptions object. - The REST clients now connect to the live environment by default, unless
testnet: true
is 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_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 theAPIMarket
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_KE...
Spot clients for REST & Websockets
Summary
This expands the library to support the spot REST & Websocket APIs.
npm install [email protected]
Deprecation Notices
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.
Changelog
Reduced webpack bundle & missing inverse APIs.
Summary
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]
Changelog
- Add API to set position mode (hedge)
- Add API to set SL/TP partial/full mode.
- Add API to set margin type.
- Significant reduction in webpack bundle size.
Inverse Futures Support
Summary
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]
Changelog
- Introduce a new REST client:
InverseFuturesClient
. Resolves #82. - Update & clean readme.
- Add missing
trailing_stop
parameter for inverse clientsetTradingStop()
.
Fix custom base URL parameter
Changelog
See #80 for details. This fixes a pass-through parameter to pass a custom base URL in the REST constructors.
npm install [email protected]
Linear USDT Support
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]
Changelog
Summary
- Introduced LinearClient as the abstraction for all available Linear USDT Rest APIs.
- Enhanced WebSocket Client to support multiple linear websockets (public & private).
- To use linear websockets make a new instance of the Websocket-Client, passing the constructor option "linear: true".
- Removed deprecated API methods abandoned in December 2020.
- Renamed exported
RestClient
toInverseClient
. Implementation remains unchanged.
Breaking Changes
This release only has one major change affecting existing usage.
- Rename dexported
RestClient
toInverseClient
. Implementation remains unchanged.
Simply rename any existing RestClient
import to continue using Inverse Rest APIs.
Behavioural Changes
The following are not expected to cause any issues but are a notable change in behaviour:
- Previously the Websocket Client automatically opens a websocket connection as soon as it is instanced.
- As of version
2.0.0
(this release), websocket connections are automatically opened as soon as any topics are subscribed to. - If needed, manually trigger websocket connection attempts before subscribing to a topic using the
websocketClient.connectAll()
method. See Websocket-Client.ts for details.
- As of version
Fix error handler for failed API requests
Small fix to the error handler when API requests fail.
TypeScript, browser support, loose types
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:
Changelog
Summary
- Introduce typescript declarations. API methods are typed including optional parameters. Resolves #18.
- Introduce webpack, although not published to npm yet. TODO: log issue to trim bundle size.
- Deprecate
assert()
calls. This caused a nuisance when API parameter requirements changed. - Fix browser websocket support. Resolves #33.
- Organise API methods per API documentation, including the categories also used in official documentation.
- Mark deprecated API methods.
Breaking Changes
These changes were enforced by bybit:
- getActiveOrder() uses deprecated endpoint. Use getActiveOrderList() instead.
- Requires symbol param. Otherwise it's the same.
- getPositions() uses deprecated endpoint. Use getPosition() instead.
Deprecations
These are a consequence of module improvements:
- getPublicTradingRecords() deprecated. Use getTrades() instead.
- Same params & response.
- getPublicLiquidations() deprecated. Use getLiquidations() instead.
- Same params & response.
- getLatestInformation() deprecated. Use getTickers() instead.
- Same params & response.
- changeUserLeverage() deprecated. Use setUserLeverage() instead.
- Same params & response.
Replace deprecated HTTP request library with modern standard. Proxy support.
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.
Difference in dependency baggage
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.
Action Required to Upgrade
None
Summary
- replace the deprecated npm request module with the much lighter axios module. Resolves #4.
- huge reduction in module footprint (see step to 1.2.0): https://bundlephobia.com/[email protected]
- expose request options in constructor, allowing proxy support (among other settings)
- bump websocket connectivity dependency to latest version.
- validated #12 is not an issue.
- misc refactoring & cleaning.