Skip to content

Commit

Permalink
chore(): update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagosiebler committed Jan 23, 2025
1 parent 44839f6 commit df35725
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ ws.on('reconnected', (data) => {
});
```
#### Websocket API - Sending orders over WS
#### Websocket API - Sending orders via WebSockets
Bybit supports sending, amending and cancelling orders over a WebSocket connection. Links for reference:
- [Bybit WebSocket API Documentation](https://bybit-exchange.github.io/docs/v5/websocket/trade/guideline)
Expand All @@ -398,22 +398,24 @@ Note: as of January 2024, the demo trading environment does not support the Webs
The [WebsocketClient](./src/WebsocketClient.ts) supports this Bybit's Websocket API. There are two ways to use the WS API, depending on individual preference:
- event-driven:
- send requests via `client.sendWSAPIRequest(wsKey, channel, 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)`
- promise-driven:
- send requests via `const result = await client.sendWSAPIRequest(wsKey, channel, params)`, which returns a promise
- 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
The below example demonstrates the promise-driven approach, which behaves similar to a REST API. 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.
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
const { WS_KEY_MAP, WebsocketClient } = require('bybit-api');

// or
// import { WS_KEY_MAP, WebsocketClient } from 'bybit-api';

// Create an instance of the WebsocketClient
// Create an instance of the WebsocketClient. This will automatically handle connectivity and authentication for you.
const wsClient = new WebsocketClient(
{
key: 'yourApiKeyHere',
Expand Down Expand Up @@ -459,14 +461,10 @@ main();

```
See [websocket-client.ts](./src/websocket-client.ts) for further information.
See the [examples/ws-api-promises.ts](./examples/ws-api-promises.ts) example for a more detailed explanation.
---
### Specifying other markets
The WebsocketClient can be configured to a specific API group using the market parameter. These are the currently available API groups:
Expand Down

0 comments on commit df35725

Please sign in to comment.