From 7a9a57e878e1d4bd5b09a03915fb66d1a3eb8266 Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Fri, 7 Apr 2023 00:54:41 +0200 Subject: [PATCH] Edit Subscribing to public channels paragraph in README.md. --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4b5be30..0b574ee 100644 --- a/README.md +++ b/README.md @@ -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. \