Poloniex APIからデータを取得しています。ウェブソケットAPIを使用しています。私はAutoBahn Python websocket libraryを使用しています。オートバンを使用してwebsocketに再接続する
現在、次のコードを使用して、チケットデータが利用可能になった時点で印刷しています。これはうまくいきますが、長期間ではありません。毎回12〜36時間ごとに出力が停止します(Poloniexがサーバーを再起動したときに思っています)。
ApplicationRunner
がまだ接続されているかどうかを確認し、接続が解除された場合は再起動する方法はありますか? onDisconnect
はトリガーしていません。スクリプトを実行すると、ソケットがデータの受信を停止したときにプロセスが終了しないので、イベントループが停止したとは思わない。
from autobahn.asyncio.wamp import ApplicationSession
from autobahn.asyncio.wamp import ApplicationRunner
from asyncio import coroutine
import asyncio
from datetime import datetime
class PoloniexComponent(ApplicationSession):
def onConnect(self):
self.join(self.config.realm)
@coroutine
def onJoin(self, details):
def onTicker(*args):
print("{}: {}".format(datetime.utcnow(), str(args)))
try:
yield from self.subscribe(onTicker, 'ticker')
except Exception as e:
print("Could not subscribe to topic:", e)
def onDisconnect(self):
asyncio.get_event_loop().stop()
def main():
runner = ApplicationRunner("wss://api.poloniex.com:443", "realm1")
runner.run(PoloniexComponent)
if __name__ == "__main__":
main()
ポロでの取引のためにwebsocket python3バージョンを共有するのはとても涼しいです:-)私はずっと前に、短く明確なバージョンを探していました。どうもありがとうございます –