Beispiel #1
0
    def __init__(self, pairs=None, channels=None, callbacks=None, **kwargs):
        if pairs:
            LOG.error("Poloniex does not support pairs")
            raise ValueError("Poloniex does not support pairs")

        self.pair_mapping = poloniex_id_pair_mapping()

        super().__init__('wss://api2.poloniex.com',
                         channels=channels,
                         callbacks=callbacks,
                         **kwargs)
        self.__reset()
Beispiel #2
0
    def __init__(self,
                 pairs=None,
                 channels=None,
                 callbacks=None,
                 config=None,
                 **kwargs):
        self.pair_mapping = poloniex_id_pair_mapping()
        super().__init__('wss://api2.poloniex.com',
                         pairs=pairs,
                         channels=channels,
                         callbacks=callbacks,
                         config=config,
                         **kwargs)
        """
        Due to the way poloniex subcriptions work, need to do some
        ugly manipulation of the config/channels,pairs to create a list
        of channels to subscribe to for poloniex as well as a callback map
        that we can use to determine if an update should be delivered to the
        end client or not
        """
        p_ticker = feed_to_exchange(self.id, TICKER)
        p_volume = feed_to_exchange(self.id, VOLUME)

        if channels:
            self.channels = self.pairs
            check = channels
            self.callback_map = {
                channel: set(pairs)
                for channel in channels if channel not in {p_ticker, p_volume}
            }
        elif config:
            self.channels = []
            for c, v in self.config.items():
                if c not in {p_ticker, p_volume}:
                    self.channels.extend(v)
            check = config
            self.callback_map = {
                key: set(value)
                for key, value in config.items()
            }

        if TICKER in check:
            self.channels.append(p_ticker)
        if VOLUME in check:
            self.channels.append(p_volume)
        # channels = pairs = cannot have duplicates
        self.channels = list(set(self.channels))

        self.__reset()