add spot websocket client (#99)

This commit is contained in:
tiagosiebler
2021-08-13 17:28:31 +01:00
parent e81b35b025
commit 4d7886ff72
2 changed files with 77 additions and 20 deletions

View File

@@ -42,7 +42,7 @@ There are three REST API modules as there are some differences in each contract
3. `LinearClient` for linear perpetual
### REST Inverse
<details><summary>To use the inverse REST APIs, import the `InverseClient`. Click here to expand and see full sample:</summary>
To use the inverse REST APIs, import the `InverseClient`:
```javascript
const { InverseClient } = require('bybit-api');
@@ -100,12 +100,11 @@ client.getOrderBook({ symbol: 'BTCUSD' })
});
```
</details>
See [inverse-client.ts](./src/inverse-client.ts) for further information.
### REST Inverse Futures
<details><summary>To use the inverse futures REST APIs, import the `InverseFuturesClient`. Click here to expand and see full sample:</summary>
To use the inverse futures REST APIs, import the `InverseFuturesClient`:
```javascript
const { InverseFuturesClient } = require('bybit-api');
@@ -142,12 +141,10 @@ client.getOrderBook({ symbol: 'BTCUSDH21' })
});
```
</details>
See [inverse-futures-client.ts](./src/inverse-futures-client.ts) for further information.
### REST Linear
<details><summary>To use the Linear (USDT) REST APIs, import the `LinearClient`. Click here to expand and see full sample:</summary>
To use the Linear (USDT) REST APIs, import the `LinearClient`:
```javascript
const { LinearClient } = require('bybit-api');
@@ -184,10 +181,8 @@ client.getOrderBook({ symbol: 'BTCUSDT' })
});
```
</details>
## WebSockets
<details><summary>Inverse & linear WebSockets can be used via a shared `WebsocketClient`. Click here to expand and see full sample:</summary>
Inverse, linear & spot WebSockets can be used via a shared `WebsocketClient`. However, make sure to make one instance of WebsocketClient per market type (spot vs inverse vs linear vs linearfutures):
```javascript
const { WebsocketClient } = require('bybit-api');
@@ -206,9 +201,14 @@ const wsConfig = {
// defaults to false == testnet. Set to true for livenet.
// livenet: true
// NOTE: to listen to multiple markets (spot vs inverse vs linear vs linearfutures) at once, make one WebsocketClient instance per market
// defaults to false == inverse. Set to true for linear (USDT) trading.
// linear: true
// defaults to false == inverse. Set to true for spot trading. These booleans will be changed into a single setting in future.
// spot: true
// how long to wait (in ms) before deciding the connection should be terminated & reconnected
// pongTimeout: 1000,
@@ -263,7 +263,6 @@ ws.on('error', err => {
});
```
</details>
See [websocket-client.ts](./src/websocket-client.ts) for further information.
@@ -274,8 +273,6 @@ Note: for linear websockets, pass `linear: true` in the constructor options when
## Customise Logging
Pass a custom logger which supports the log methods `silly`, `debug`, `notice`, `info`, `warning` and `error`, or override methods from the default logger as desired.
<details><summary>Click here to expand and see full sample:</summary>
```javascript
const { WebsocketClient, DefaultLogger } = require('bybit-api');
@@ -288,8 +285,6 @@ const ws = new WebsocketClient(
);
```
</details>
## Browser Usage
Build a bundle using webpack:
- `npm install`