Poloniex不会把所有的消息都返回到我的套接字。我用以下代码阅读邮件,有时会得到连续的邮件编号,但有时会丢失10条信息:
from autobahn.asyncio.wamp import ApplicationSession
from autobahn.asyncio.wamp import ApplicationRunner
from asyncio import coroutine
class PoloniexComponent(ApplicationSession):
def onConnect(self):
self.join(self.config.realm)
@coroutine
def onJoin(self, details):
def onTrollbox(*args):
print("type: ", args[0])
print("message_number: ", args[1])
print("user_name: ", args[2])
print("message: ", args[3])
print("reputation: ", args[4])
try:
yield from self.subscribe(onTrollbox, 'trollbox')
except Exception as e:
print("Could not subscribe to topic:", e)
runner = ApplicationRunner("wss://api.poloniex.com", "realm1")
runner.run(PoloniexComponent)
有人知道更好的解决办法吗?我试过这个,但一点也不管用:
^{pr2}$
解决方案如下:
这些丢失的消息有时可能与
WAMP API
一起发生。这是由于路由软件固有的可伸缩性问题,Poloniex正在开发一个pure WebSockets API
(目前由web界面使用,但缺少文档)来代替它。新websocket服务器的url是wss://api2.poloniex.com:443
,要连接到trollbox消息,您需要发送消息:'{"command" : "subscribe", "channel" : 1001}'
。在下面是一个示例代码,它更易于使用:
你可以在这里检查我做的代码:Here。它用了漂亮的汤和干草。它通过进入Poloniex网站并等待一段时间,然后从网站收集数据,在我们的例子中是Trollbox。我也尝试了高速公路,这就是我得到的,但它看起来和你的代码完全一样,所以可能不会有任何改进。在
所以trollbox现在在wampwebsocket上不能正常工作,你得到一个断开连接的原因是由于不活动。在
如果您想检查它,可以查看网站源代码here,并查看第2440行,看到trollbox订阅被注释。在
相关问题 更多 >
编程相关推荐