chore(): readme updates

This commit is contained in:
tiagosiebler
2025-01-23 12:51:48 +00:00
parent df35725027
commit 9524c995fc

View File

@@ -387,27 +387,26 @@ ws.on('reconnected', (data) => {
#### Websocket API - Sending orders via WebSockets #### Websocket API - Sending orders via WebSockets
Bybit supports sending, amending and cancelling orders over a WebSocket connection. Links for reference: Bybit supports sending, amending and cancelling orders over a WebSocket connection. The [WebsocketClient](./src/WebsocketClient.ts) fully supports Bybit's WebSocket API.
Links for reference:
- [Bybit WebSocket API Documentation](https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline) - [Bybit WebSocket API Documentation](https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline)
- [WebSocket API Example Node.js/TypeScript/JavaScript](./examples/ws-api-promises.ts). - [WebSocket API Example Node.js/TypeScript/JavaScript](./examples/ws-api-promises.ts).
Note: as of January 2024, the demo trading environment does not support the Websocket API. Note: as of January 2024, the demo trading environment does not support the WebSocket API.
##### Usage
The [WebsocketClient](./src/WebsocketClient.ts) supports this Bybit's Websocket API. There are two ways to use the WS API, depending on individual preference:
There are two ways to use the WS API, depending on individual preference:
- event-driven: - event-driven:
- send requests via `client.sendWSAPIRequest(wsKey, operation, params)`, fire and forget, don't use await - send requests via `client.sendWSAPIRequest(wsKey, operation, params)`, fire and forget, don't use await
- handle async replies via event handlers on `client.on('exception', cb)` and `client.on('response', cb)` - handle async replies via event handlers on `client.on('exception', cb)` and `client.on('response', cb)`
- See example for more details: [examples/ws-api-events.ts](./examples/ws-api-events.ts)
- promise-driven: - promise-driven:
- send requests via `const result = await client.sendWSAPIRequest(wsKey, operation, params)`, which returns a promise - send requests via `const result = await client.sendWSAPIRequest(wsKey, operation, params)`, which returns a promise
- await each call - await each call
- use try/catch blocks to handle promise rejections - use try/catch blocks to handle promise rejections
- See example for more details: [examples/ws-api-promises.ts](./examples/ws-api-promises.ts)
The below example demonstrates the promise-driven approach, which behaves similar to a REST API. The WebSocket API even accepts the same parameters as the corresponding REST API endpoints, so this approach should be compatible with existing REST implementations. The below example demonstrates the promise-driven approach, which behaves similar to a REST API. The WebSocket API even accepts the same parameters as the corresponding REST API endpoints, so this approach should be compatible with existing REST implementations. Connectivity, authentication, and processing requests wrapped in promises - these are all handled automatically by the WebsocketClient without additional configuration.
For more detailed examples, refer to the [examples](./examples/) folder (e.g the [examples/ws-api-promises.ts](./examples/ws-api-promises.ts) example).
```javascript ```javascript
const { WS_KEY_MAP, WebsocketClient } = require('bybit-api'); const { WS_KEY_MAP, WebsocketClient } = require('bybit-api');
@@ -428,6 +427,7 @@ const wsClient = new WebsocketClient(
// This example is wrapped in an async function, so "await" can be used // This example is wrapped in an async function, so "await" can be used
async function main() { async function main() {
// Optional. Can be used to prepare a connection before sending commands (e.g. as part of your startup process) // Optional. Can be used to prepare a connection before sending commands (e.g. as part of your startup process)
// This is not necessary and will happen automatically when sending a command, if you aren't connected/authenticated yet
// await wsClient.connectWSAPI(); // await wsClient.connectWSAPI();
try { try {