Bybit Api Versions Save

Node.js SDK for the Bybit APIs and WebSockets, with TypeScript & browser support.

v3.0.1

1 year ago

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.

v2.1.0

2 years ago

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

  • Fix inversed secondary URLs (#106)
  • Add support for Spot APIs (#99)

v2.0.5

2 years ago

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.

v2.0.3

3 years ago

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 client setTradingStop().

v2.0.1

3 years ago

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]

v2.0.0

3 years ago

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 to InverseClient. Implementation remains unchanged.

Breaking Changes

This release only has one major change affecting existing usage.

  • Rename dexported RestClient to InverseClient. 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.

v1.3.2

3 years ago

Small fix to the error handler when API requests fail.

v1.3.1

3 years ago

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.

v1.2.0

3 years ago

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

Screenshot 2020-10-14 at 09 57 39

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.
  • bump websocket connectivity dependency to latest version.
  • validated #12 is not an issue.
  • misc refactoring & cleaning.