Skip to content

Commit 5a513ea

Browse files
author
tiagosiebler
committed
feat(v4.0.0): WebSocket API, WebsocketClient upgrades, decommission deprecated v1-v3 API groups
1 parent d8f4b1e commit 5a513ea

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

README.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,23 @@
1919

2020
[1]: https://www.npmjs.com/package/bybit-api
2121

22-
Node.js, JavaScript & TypeScript SDK for the Bybit REST APIs and WebSockets:
22+
Professional Node.js, JavaScript & TypeScript SDK for the Bybit REST APIs and WebSockets:
2323

2424
- Complete integration with all Bybit REST APIs & WebSockets, including the WebSocket API.
2525
- Actively maintained with a modern, promise-driven interface.
26-
- TypeScript support (with type declarations for most API requests & responses).
27-
- Thorough end-to-end tests making real API calls & WebSocket connections, validating any changes before they reach npm.
26+
- TypeScript support (thorough type declarations for most API requests & responses, including WS API).
27+
- JavaScript support (TypeScript not required but definitely recommended).
28+
- Thorough & automatic end-to-end tests making real API calls & WebSocket connections, validating any changes before they reach npm.
2829
- Proxy support via axios integration.
29-
- Robust WebSocket integration with configurable connection heartbeats & automatic reconnect then resubscribe workflows.
30-
- Event driven messaging.
30+
- Robust WebSocket consumer integration with configurable heartbeats & automatic reconnect then resubscribe workflows.
31+
- Event driven messaging
3132
- Smart websocket persistence
3233
- Automatically handle silent websocket disconnections through timed heartbeats, including the scheduled 24hr disconnect.
33-
- Automatically handle listenKey persistence and expiration/refresh.
34+
- Automatically handle authentication.
3435
- Emit `reconnected` event when dropped connection is restored.
3536
- WebSocket API integration, with two design patterns to choose from:
3637
- Asynchronous promise-driven responses:
37-
- This behaves very much like a REST API. No need to subscribe to asynchronous events.
38+
- Make requests like a REST API, using the WebSocket API. No need to subscribe to asynchronous events.
3839
- Send commands with the await sendWSAPIRequest(...) method.
3940
- Await responses to commands directly in the fully typed sendWSAPIRequest() call.
4041
- The method directly returns a promise. Use a try/catch block for convenient error handling without the complexity of asynchronous WebSockets.
@@ -124,7 +125,7 @@ The SDK is written in TypeScript, but fully compatible with both TypeScript and
124125

125126

126127
- [src](./src) - the complete SDK written in TypeScript.
127-
- [lib](./lib) - the JavaScript version of the project (built from TypeScript). This should not be edited directly, as it will be overwritten with each release.
128+
- [lib](./lib) - the JavaScript version of the project (built from TypeScript) that is published to npm. This should not be edited directly, as it will be overwritten with each release.
128129
- [examples](./examples) - examples & demonstrations. Contributions are welcome!
129130
- [test](./test) - automated end-to-end tests that run before every release, making real API calls.
130131

@@ -149,7 +150,7 @@ Here are the available REST clients and the corresponding API groups described i
149150
| :----------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------------: |
150151
| [ **V5 API** ] | The new unified V5 APIs (successor to previously fragmented APIs for all API groups). |
151152
| [RestClientV5](src/rest-client-v5.ts) | Unified V5 all-in-one REST client for all [V5 REST APIs](https://bybit-exchange.github.io/docs/v5/intro) |
152-
| [WebsocketClient](src/websocket-client.ts) | All WebSocket Events (Public & Private for all API categories) |
153+
| [WebsocketClient](src/websocket-client.ts) | All WebSocket features (Public & Private consumers for all API categories & the WebSocket API) |
153154

154155

155156
## REST API Usage
@@ -181,7 +182,9 @@ const restClientOptions = {
181182
* Set to `true` to use Bybit's V5 demo trading:
182183
* https://bybit-exchange.github.io/docs/v5/demo
183184
*
184-
* Note: to use demo trading, you should have `testnet` disabled
185+
* Note: to use demo trading, you should have `testnet` disabled.
186+
*
187+
* You can find a detailed demoTrading example in the examples folder on GitHub.
185188
*/
186189
// demoTrading: true,
187190

@@ -227,6 +230,7 @@ const client = new RestClientV5({
227230
key: API_KEY,
228231
secret: API_SECRET,
229232
// demoTrading: true,
233+
230234
// Optional: enable to try parsing rate limit values from responses
231235
// parseAPIRateLimits: true
232236
},
@@ -295,7 +299,7 @@ const wsConfig = {
295299
* Set to `true` to connect to Bybit's V5 demo trading:
296300
* https://bybit-exchange.github.io/docs/v5/demo
297301
*
298-
* Only the "V5" "market" is supported here.
302+
* Refer to the examples folder on GitHub for a more detailed demonstration.
299303
*/
300304
// demoTrading; true;
301305

@@ -392,17 +396,17 @@ ws.on('reconnected', (data) => {
392396
393397
## Websocket API - Sending orders via WebSockets
394398
395-
Bybit supports sending, amending and cancelling orders over a WebSocket connection. The [WebsocketClient](./src/WebsocketClient.ts) fully supports Bybit's WebSocket API.
399+
Bybit supports sending, amending and cancelling orders over a WebSocket connection. The [WebsocketClient](./src/WebsocketClient.ts) fully supports Bybit's WebSocket API via the `sendWSAPIRequest(...)` method.
396400
397401
Links for reference:
398402
- [Bybit WebSocket API Documentation](https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline)
399403
- [WebSocket API Example Node.js/TypeScript/JavaScript](./examples/ws-api-promises.ts).
400404
401-
Note: as of January 2024, the demo trading environment does not support the WebSocket API.
405+
Note: as of January 2025, the demo trading environment does not support the WebSocket API.
402406
403407
There are two ways to use the WS API, depending on individual preference:
404408
- event-driven:
405-
- send requests via `client.sendWSAPIRequest(wsKey, operation, params)`, fire and forget, don't use await
409+
- send requests via `client.sendWSAPIRequest(wsKey, operation, params)`, fire and forget
406410
- handle async replies via event handlers on `client.on('exception', cb)` and `client.on('response', cb)`
407411
- See example for more details: [examples/ws-api-events.ts](./examples/ws-api-events.ts)
408412
- promise-driven:

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bybit-api",
3-
"version": "4.0.0-beta.9",
3+
"version": "4.0.0",
44
"description": "Complete & robust Node.js SDK for Bybit's REST APIs and WebSockets, with TypeScript & strong end to end tests.",
55
"main": "lib/index.js",
66
"types": "lib/index.d.ts",

0 commit comments

Comments
 (0)