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

前端 未结 4 1497
一生所求
一生所求 2021-01-21 17:50

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

相关标签:
4条回答
  • 2021-01-21 18:19

    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()
    
    0 讨论(0)
  • 2021-01-21 18:19

    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")
    
    0 讨论(0)
  • 2021-01-21 18:34

    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.

    0 讨论(0)
  • 2021-01-21 18:41

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

    0 讨论(0)
提交回复
热议问题