From 729a3ce8a3817f2ddf00f5970df9f739a243bd8f Mon Sep 17 00:00:00 2001 From: Davide Casale Date: Tue, 22 Nov 2022 19:01:57 +0100 Subject: [PATCH] Add examples/websocket/ticker.py demo. --- examples/websocket/ticker.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 examples/websocket/ticker.py diff --git a/examples/websocket/ticker.py b/examples/websocket/ticker.py new file mode 100644 index 0000000..4e5d8e7 --- /dev/null +++ b/examples/websocket/ticker.py @@ -0,0 +1,19 @@ +import asyncio + +from bfxapi import Client, Constants +from bfxapi.websocket import Channels +from bfxapi.websocket.typings import Subscriptions, TradingPairTicker + +bfx = Client(WSS_HOST=Constants.PUB_WSS_HOST) + +@bfx.wss.on("t_ticker_update") +def on_t_ticker_update(subscription: Subscriptions.TradingPairsTicker, data: TradingPairTicker): + print(f"Subscription channel ID: {subscription['chanId']}") + + print(f"Data: {data}") + +@bfx.wss.once("open") +async def open(): + await bfx.wss.subscribe(Channels.TICKER, symbol="tBTCUSD") + +asyncio.run(bfx.wss.start()) \ No newline at end of file