Hi Guys,
I am trying to practice websockets by streaming data from the Bitstamp API (https://www.bitstamp.net/websocket/v2/).
As per the documentation, I have managed to successfully subscribe to the data stream and get the following response from my print(data) function: {"event":"bts:subscription_succeeded","channel":"live_trades_btcusd","data":{}}.
Now that I am subscribed, how do I actually receive/see the bitcoin price data?
import asyncio import websockets import json async def bitstamp_connect(): uri = "wss://ws.bitstamp.net/" subscription = { "event": "bts:subscribe", "data": { "channel": "live_trades_btcusd" } } async with websockets.connect(uri) as websocket: await websocket.send(json.dumps(subscription)) data = await websocket.recv() print(data) asyncio.get_event_loop().run_until_complete(bitstamp_connect())
Thanks!
No comments:
Post a Comment