【发布时间】:2018-01-02 07:25:06
【问题描述】:
我正在尝试通过推送 API 从 Poloniex 获取 Python 2.7.13 中的实时数据。 我阅读了很多帖子(包括How to connect to poloniex.com websocket api using a python library),并得出以下代码:
from autobahn.twisted.wamp import ApplicationSession
from autobahn.twisted.wamp import ApplicationRunner
from twisted.internet.defer import inlineCallbacks
import six
class PoloniexComponent(ApplicationSession):
def onConnect(self):
self.join(self.config.realm)
@inlineCallbacks
def onJoin(self, details):
def onTicker(*args):
print("Ticker event received:", args)
try:
yield self.subscribe(onTicker, 'ticker')
except Exception as e:
print("Could not subscribe to topic:", e)
def main():
runner = ApplicationRunner(six.u("wss://api.poloniex.com"), six.u("realm1"))
runner.run(PoloniexComponent)
if __name__ == "__main__":
main()
现在,当我运行代码时,它看起来运行成功,但我不知道从哪里获取数据。我有两个问题:
如果有人能引导我完成订阅和获取股票数据的过程,我将非常感激,我将在 python 中详细说明,从第 0 步开始:我在 Windows 上的 Spyder 上运行程序。我应该以某种方式激活 Crossbar 吗?
如何退出连接?我只是用
Ctrl+c杀死了这个进程,现在当我尝试再次运行它时,我得到了错误:ReactorNonRestartable。
【问题讨论】:
标签: python wamp autobahn poloniex