Poloniex doesn't return every message to my socket. I read the messages with the following code and sometimes I get continuous message numbers, but sometimes there are like 10 messages missing:
from autobahn.asyncio.wamp import ApplicationSession
from autobahn.asyncio.wamp import ApplicationRunner
from asyncio import coroutine
class PoloniexComponent(ApplicationSession):
def onConnect(self):
self.join(self.config.realm)
@coroutine
def onJoin(self, details):
def onTrollbox(*args):
print("type: ", args[0])
print("message_number: ", args[1])
print("user_name: ", args[2])
print("message: ", args[3])
print("reputation: ", args[4])
try:
yield from self.subscribe(onTrollbox, 'trollbox')
except Exception as e:
print("Could not subscribe to topic:", e)
runner = ApplicationRunner("wss://api.poloniex.com", "realm1")
runner.run(PoloniexComponent)
Does anybody know a better solution? I tried this one, but it doesn't work at all:
from websocket import create_connection
ws = create_connection("wss://api.poloniex.com")
ws.send("trollbox")
result = ws.recv()
print "Received '%s'" % result
ws.close()
Here is the solution:
These missing messages might happen sometimes with the
WAMP API
. It is due to inherent scalability problems with the routing software, and Poloniex is working on apure WebSockets API
(currently used by the web interface, but lacking documentation) to replace it. The url for the new websocket server iswss://api2.poloniex.com:443
and to connect to trollbox messages you would need to send the message:'{"command" : "subscribe", "channel" : 1001}'
.Here is an example code, it is much easier to work with:
so the trollbox is not functioning right now at the wamp web socket, the reason you are getting a disconnections is due to inactivity.
if you want to check it you can look at the website source here and look at line 2440 and see that the trollbox subscription is commented.
You can check this code here i made: Here. It uses Beautiful soup and dryscape. It gets it by getting on Poloniex website and waiting for some time, then gathers data from website, in our case the Trollbox. I also tried with autobahn, and this is what i got, but it looks exactly like your code, so there would probably be no improvement.
Poloniex trollbox is over now ! You can have access to history here