Edit Subscribing to public channels paragraph in README.md.

This commit is contained in:
Davide Casale
2023-04-07 00:54:41 +02:00
parent 2d0fabde20
commit 7a9a57e878

View File

@@ -128,7 +128,7 @@ Users can close the connection with the WebSocket server using `BfxWebSocketClie
await bfx.wss.close()
```
A custom [close code number](https://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number) (along with a verbose reason) can be given as a parameter:
A custom [close code number](https://www.iana.org/assignments/websocket/websocket.xhtml#close-code-number), along with a verbose reason, can be given as parameters:
```python
await bfx.wss.close(code=1001, reason="Going Away")
```
@@ -147,6 +147,14 @@ Users can subscribe to public channels using `BfxWebSocketClient::subscribe`:
await bfx.wss.subscribe("ticker", symbol="tBTCUSD")
```
On each successful subscription, the client will emit the `subscribed` event:
```python
@bfx.wss.on("subscribed")
def on_subscribed(subscription: subscriptions.Subscription):
if subscription["channel"] == "ticker":
print(f"{subscription['symbol']}: {subscription['subId']}") # tBTCUSD: f2757df2-7e11-4244-9bb7-a53b7343bef8
```
### Setting a custom `sub_id`
The client generates a random `sub_id` for each subscription. \