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

184 views Asked by At

I am currently building a cryptocurrency trading platform in Python, and using Autobahn for receiving market events. 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. When I make the handler take three arguments, it does not work either. I have tried, in desperation, everything between 0 and 5 arguments.

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. Note, I am using 'none' for the matching criteria. 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)
1

There are 1 answers

0
cassm On BEST ANSWER

Fixed, with the help of a friend of mine. The required signature for marketEvent is as follows:

marketEvent(event, **details)