我目前正在使用Python构建加密货币交易平台,并使用Autobahn接收市场事件。我遇到使用订阅选项的问题。
当我仅使用(处理程序,主题)参数创建订阅,并使处理程序采用单个参数时,一切正常。但是,当我使用(handler,topic,options)参数创建订阅,并使处理程序采用两个参数时,不会调用处理程序。在文档中,它声明处理程序在这种情况下应该有三个参数,args,kwargs和details。当我使处理程序采用三个参数时,它也不起作用。我绝望地尝试了0到5个参数之间的所有内容。
简而言之,当我没有使用订阅选项并给处理程序一个参数时,它工作正常。当我使用订阅选项时,无论我使用多少个参数,处理程序都不会被触发。
我已经尝试打印出这对,它是一个有效的字符串,我尝试打印出选项,它是一个有效的subscriptionsoptions对象。注意,我使用'none'作为匹配条件。我仍然收到订阅确认,没有错误。
任何建议都会深表感谢。
代码如下。
def onJoin(self, details):
print("{} client session ready".format(self.exchange))
def marketEvent(args, kwargs, details):
print("marketEvent called")
# Read in configuration files
try:
pairs = [line.strip() for line in open("conf/" + self.exchange + ".conf")]
except:
print("Configuration file not found for {}!".format(self.exchange))
sys.exit(1)
# Subscribe to each currency pair / topic in the conf file
for pair in pairs:
try:
# provide currency pair name to handler
options = SubscribeOptions(details_arg = pair)
yield from self.subscribe(marketEvent, pair, options)
print("subscribed to {} on {}".format(pair, self.exchange))
except Exception as e:
print("could not subscribe to {} on {}: {}".format(pair, exchange, e))
sys.exit(1)
答案 0 :(得分:0)
修复,在我的一个朋友的帮助下。 marketEvent所需的签名如下:
marketEvent(事件,**详细信息)