[request for help] Handler not getting called when I initialise subscription with options

175 views
Skip to first unread message

Cass M

unread,
Nov 17, 2014, 3:59:04 PM11/17/14
to autob...@googlegroups.com
Hi all,

I am having an issue whereby my subscriptions work fine without the options argument (handler gets called), but the handler is not called when I provide options. I have checked that the options are a valid SubcriptionOption object, and that I am using 'none' for the match type. I have tried giving the handler 1, 2, and 3 arguments, as the documentation states that three are required, but I could not see what the other one would be (working in python, so no types), and it just isn't working. Would it be possible for somebody to look over my code, and see whether they can see anything obviously dumb?

Any input would be greatly appreciated. Thank you for your time.

--Cass

Code follows. This is the beginnings of a cryptocurrency trading platform.

from autobahn.asyncio.wamp import ApplicationSession
from autobahn.asyncio.wamp import ApplicationRunner
from autobahn.wamp.types  import SubscribeOptions
from asyncio import coroutine
import sys
import json
from io import StringIO

poloniex_URL = "wss://api.poloniex.com"   

class TradeClient(ApplicationSession):

    exchange = "NULL"

    def eventProcessor(self, event):
        print("eventProcessor called")
        print("market event received: {}".format(event))

    def onJoin(self, details):
        print("{} client session ready".format(self.exchange))

        def marketEvent(args, kwargs, details):
            print("marketEvent called")#: {}".format(pair))
           
        # 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)
       
class PoloniexClient(TradeClient):
    exchange = "poloniex"

poloniex_runner = ApplicationRunner(url = poloniex_URL, realm = "realm1")
poloniex_runner.run(PoloniexClient)

Cass M

unread,
Nov 17, 2014, 8:12:11 PM11/17/14
to autob...@googlegroups.com
Fixed it. Required ** before the second of two arguments to marketEvent.

So the correct signature is marketEvent(event, **details)

Tobias Oberstein

unread,
Nov 20, 2014, 4:07:20 AM11/20/14
to autob...@googlegroups.com
Am 17.11.2014 21:59, schrieb Cass M:

When you use

options = SubscribeOptions(details_arg = pair)
yield from self.subscribe(marketEvent, pair, options)

and you publish events like (AutobahnJS)

session.publish("com.myapp.topic1", [val1])

the handler should have the following signature:

def marketEvent(val1, details = pair):
...

==

Are you proficient with Python fun signature/call styles?

Check out:


def foo1(val1, pair = None):
print val1, pair

def foo2(val1, pair = None, **kwargs):
print val1, pair, kwargs

def foo3(*args, **kwargs):
print args, kwargs

foo1(123, pair = "foo")
foo2(123, pair = "foo", bla = "blub")
foo3(123, 789, pair = "foo", bla = "blub")

and

https://github.com/tavendo/AutobahnPython/blob/master/examples/twisted/wamp/basic/pubsub/options/frontend.py


Cheers,
/Tobias
> --
> You received this message because you are subscribed to the Google
> Groups "Autobahn" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to autobahnws+...@googlegroups.com
> <mailto:autobahnws+...@googlegroups.com>.
> To post to this group, send email to autob...@googlegroups.com
> <mailto:autob...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/autobahnws/e323cadf-155c-493a-b6b5-882ffbd6671a%40googlegroups.com
> <https://groups.google.com/d/msgid/autobahnws/e323cadf-155c-493a-b6b5-882ffbd6671a%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages