Poloniex push api:停止发送通道1002的数据

时间:2018-01-31 07:28:45

标签: python-3.x websocket poloniex

我使用python从wss://api2.poloniex.com获取实时数据:443并且它可以正常工作。
但有时服务器将停止发送通道1002的数据(勾选实时信息) 但仍然有心跳[1010] 这是我的代码

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() 

当程序工作时就像那个enter image description here

当服务器停止发送通道1002的数据时 enter image description here

有什么想法吗?

1 个答案:

答案 0 :(得分:0)

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