简体   繁体   English

高速公路| Python:提供SubscriptionOptions时,订阅不再触发处理程序

[英]Autobahn | Python: Subscription no longer triggering handler when SubscriptionOptions are provided

I am currently building a cryptocurrency trading platform in Python, and using Autobahn for receiving market events. 我目前正在用Python构建一个加密货币交易平台,并使用高速公路来接收市场事件。 I am experiencing an issue with using subscription options. 我在使用订阅选项时遇到问题。

When I create a subscription with just the (handler, topic) arguments, and make the handler take a single argument, everything works fine. 当我仅使用(处理程序,主题)参数创建预订,并使处理程序采用单个参数时,一切正常。 However, when I create the subscription using the (handler, topic, options) arguments, and make the handler take two arguments, the handler does not get called. 但是,当我使用(处理程序,主题,选项)参数创建预订,并使处理程序带有两个参数时,不会调用处理程序。 In the documentation, it states that the handler should, in this case, have three arguments, args, kwargs, and details. 在文档中,它指出在这种情况下,处理程序应具有三个参数args,kwargs和details。 When I make the handler take three arguments, it does not work either. 当我使处理程序接受三个参数时,它也不起作用。 I have tried, in desperation, everything between 0 and 5 arguments. 我无奈地尝试了0到5个参数之间的所有内容。

In short, when I use no subscription options and give the handler one argument, it works fine. 简而言之,当我不使用任何订阅选项并为处理程序提供一个参数时,它可以正常工作。 When I use subscription options, the handler does not get triggered regardless of how many arguments I use . 使用订阅选项时, 无论使用多少参数 ,都不会触发处理程序。

I have tried printing out the pair, and it is a valid string, and I have tried printing out the options, and it is a valid subscriptionsoptions object. 我尝试打印出该对,并且它是有效的字符串,并且尝试打印出这些选项,并且它是有效的subscriptionsoptions对象。 Note, I am using 'none' for the matching criteria. 注意,我将“ none”用作匹配条件。 I am still getting subscriptions confirmations, and no errors. 我仍然收到订阅确认,没有错误。

Any suggestions would be deeply appreciated. 任何建议将不胜感激。

Code follows. 代码如下。

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)

Fixed, with the help of a friend of mine. 已修复,在我的一个朋友的帮助下。 The required signature for marketEvent is as follows: marketEvent所需的签名如下:

marketEvent(event, **details) marketEvent(事件,**详细信息)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM