Reading Messages on Poloniex Trollbox with Python autbahn or other socket module?

我是研究僧i 提交于 2019-12-01 21:27:52

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 a pure WebSockets API (currently used by the web interface, but lacking documentation) to replace it. The url for the new websocket server is wss://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:

from websocket import create_connection
import json

ws = create_connection("wss://api2.poloniex.com:443")
ws.send('{"command" : "subscribe", "channel" : 1001}')

while True:
    result = ws.recv()
    json_result = json.loads(result)
    if len(json_result) >= 3:
        print(json_result)

ws.close()

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.

from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.wamp import ApplicationSession,ApplicationRunner

#prints recieved message
def tamperMessage(message):
       print message



class MyComponent(ApplicationSession):

@inlineCallbacks
def onJoin(self, details):
    print("session joined")
    #gets message and calls tamperMessage function
    def gotMessage(type, messageNumber, username, message, reputation):
        tamperMessage(message)

    # 1. subscribe to a topic so we receive events
    try:
        yield self.subscribe(gotMessage,u'trollbox')
   except Exception as e:
       print("could not subscribe to topic:")

runner = ApplicationRunner(url=u"wss://api.poloniex.com", realm=u"realm1")

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.

Poloniex trollbox is over now ! You can have access to history here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!