Good resources to learn how to use websocket push api in python
I am trying to connect to wss://api.poloniex.com and subscribe to ticker. I can’t find any working example in python. I have tried to use autobahn/twisted and websocket-client 0.32.0.
The purpose of this is to get real time ticker data and store it in a mysql database.
What you are trying to accomplish can be done by using WAMP, specifically by using the WAMP modules of the autobahn library (that you are already trying to use).
After following their docs, I managed to set-up a simple example using autobahn and asyncio. The following example subscribes to the ‘ticker’ feed and prints the received values:
from autobahn.asyncio.wamp import ApplicationSession
from autobahn.asyncio.wamp import ApplicationRunner
from asyncio import coroutine
def onJoin(self, details):
print("Ticker event received:", args)
yield from self.subscribe(onTicker, 'ticker')
except Exception as e:
print("Could not subscribe to topic:", e)
runner = ApplicationRunner(u"wss://api.poloniex.com:443", "realm1")
if __name__ == "__main__":
We have install the necessary python packages:
pip install autobahn
pip install autobahn[twisted]
pip install autobahn[twisted,accelerate,compress,serialization]