mirror of
https://github.com/aljazceru/bitfinex-api-py.git
synced 2025-12-19 06:44:22 +01:00
Add examples/websocket/ticker.py demo.
This commit is contained in:
19
examples/websocket/ticker.py
Normal file
19
examples/websocket/ticker.py
Normal file
@@ -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())
|
||||
Reference in New Issue
Block a user