I'm new to websockets and using web APIs and have been a bit confused as to how to extract real time information from the coinbase pro websocket.
Here is my code for creating a new websocket and subscribing to the ticker channel, I have already authenticated with my account and API key:
wsClient = cb.WebsocketClient(url="wss://ws-feed.pro.coinbase.com",
products=ticker,
channels=["ticker"])
But then, I'm not really sure what to do. Is there a function I call to print the information I want? I have tried indexing with ['price']
or using .__getattribute()
but have been unsuccessful. The closest other post I have found is this one. But it seems like my websocket doesnt have a .on()
function. The coinbase pro docs simply list the data returned by the subscription, but I'm unsure as to how to actually access and print it.
Any help is appreciated! Thanks!
Edit:
I have figured out that cb.WebsocketClient.start(wsClient)
starts printing the results in JSON to console. Am I able to put this into a file and then parse it? Is there a faster way than writing to a JSON file and parsing it?