Exemple #1
0
class PushApi:
    url = "wss://api.poloniex.com"

    def __init__(self, session):
        self.wamp = WAMPClient(url=self.url, session=session)

    async def start(self):
        await self.wamp.start()

    async def stop(self, force=True):
        if force or not self.is_subscribed:
            await self.wamp.stop()

    @property
    def is_subscribed(self):
        [queue, subscriptions] = self.wamp.subsciptions
        return len(queue) + len(subscriptions) != 0

    def subscribe(self, topic, handler):

        if topic is "trollbox":
            handler = trollbox_wrapper(handler)
            self.wamp.subscribe(topic=topic, handler=handler)

        elif topic is "ticker":
            handler = ticker_wrapper(handler)
            self.wamp.subscribe(topic=topic, handler=handler)

        elif topic in constants.AVAILABLE_SUBSCRIPTIONS:
            self.wamp.subscribe(topic=topic, handler=handler)

        else: # topic in constants.CURRENCY_PAIRS:
            handler = trades_wrapper(topic, handler)
            self.wamp.subscribe(topic=topic, handler=handler)
Exemple #2
0
class PushApi:
    url = "wss://api.poloniex.com"

    def __init__(self, session):
        self.wamp = WAMPClient(url=self.url, session=session)

    async def start(self):
        await self.wamp.start()

    async def stop(self, force=True):
        if force or not self.is_subscribed:
            await self.wamp.stop()

    @property
    def is_subscribed(self):
        [queue, subscriptions] = self.wamp.subsciptions
        return len(queue) + len(subscriptions) != 0

    def subscribe(self, topic, handler):
        if topic in constants.CURRENCY_PAIRS:
            handler = trades_wrapper(topic, handler)
            self.wamp.subscribe(topic=topic, handler=handler)

        elif topic is "trollbox":
            handler = trollbox_wrapper(handler)
            self.wamp.subscribe(topic=topic, handler=handler)

        elif topic is "ticker":
            handler = ticker_wrapper(handler)
            self.wamp.subscribe(topic=topic, handler=handler)

        elif topic in constants.AVAILABLE_SUBSCRIPTIONS:
            self.wamp.subscribe(topic=topic, handler=handler)

        else:
            raise NotImplementedError("Topic not available")
Exemple #3
0
 def __init__(self, session):
     self.wamp = WAMPClient(url=self.url, session=session)
Exemple #4
0
 def __init__(self, session):
     self.wamp = WAMPClient(url=self.url, session=session)