Skip to content

Commit

Permalink
chore(): readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosiebler committed Jan 23, 2025
1 parent df35725 commit 9524c99
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -387,27 +387,26 @@ ws.on('reconnected', (data) => {
#### 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)
- [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.
##### 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:
Note: as of January 2024, the demo trading environment does not support the WebSocket API.
There are two ways to use the WS API, depending on individual preference:
- event-driven:
- 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)`
- See example for more details: [examples/ws-api-events.ts](./examples/ws-api-events.ts)
- promise-driven:
- send requests via `const result = await client.sendWSAPIRequest(wsKey, operation, params)`, which returns a promise
- await each call
- 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.
For more detailed examples, refer to the [examples](./examples/) folder (e.g the [examples/ws-api-promises.ts](./examples/ws-api-promises.ts) example).
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.
```javascript
const { WS_KEY_MAP, WebsocketClient } = require('bybit-api');
Expand All @@ -428,6 +427,7 @@ const wsClient = new WebsocketClient(
// This example is wrapped in an async function, so "await" can be used
async function main() {
// 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();

try {
Expand Down

0 comments on commit 9524c99

Please sign in to comment.