0

I use python to get the real time data from wss://api2.poloniex.com:443 and it's work.
But sometime server will stop sending the data of the channel 1002 (tick real time information) but there is still heartbeat [1010]
and here is my code

from threading import Thread

import websocket

'''
Message format
[
    1002,                             Channel
    null,                             Unknown
    [
        121,                          CurrencyPairID
        "10777.56054438",             Last
        "10800.00000000",             lowestAsk
        "10789.20000001",             highestBid
        "-0.00860373",                percentChange
        "72542984.79776118",          baseVolume
        "6792.60163706",              quoteVolume
        0,                            isForzen
        "11400.00000000",             high24hr
        "9880.00000009"               low24hr
    ]
]
'''


class Ticker:



    def on_open(self, ws):
        ws.send(json.dumps({'command': 'subscribe', 'channel': 1002}))

    def on_message(self, ws, message):
        message = json.loads(message)
        print(message)

    def on_close(self, ws ):
        self.isReady = False
        logging.warning('Poloniex Ticker----------------------------CLOSE WebSocket-----------------------')
        logging.warning('Close Time : ' + timestampToDate(int(time.mktime(time.localtime())), True))
        time.sleep(1)
        logging.info('Restart Poloniex Ticker Socket')
        self.start()

    def start(self):
        logging.info('poloniex tick start')
        self.ws = websocket.WebSocketApp('wss://api2.poloniex.com:443', on_open=self.on_open, on_message=self.on_message,
                                         on_close=self.on_close, on_error=self.on_error)
        self.thread = Thread(target=self.ws.run_forever)
        self.thread.start() 

When the program is work is like thatenter image description here

When the server stop sending data of channel 1002
enter image description here

Any idea?

4

1 回答 1

0

Poloniex 的 websocket 似乎不稳定服务器繁忙时它会停止向客户端发送数据 2 分钟,即使您使用网络浏览器

于 2018-02-07T01:48:55.347 回答