Esempio n. 1
0
    async def subscribe(self, conn: AsyncConnection):
        self.__reset()

        symbol_channels = list(self.get_channel_symbol_combinations())
        LOG.info("%s: Got %r combinations of pairs and channels", self.id, len(symbol_channels))

        if len(symbol_channels) == 0:
            LOG.info("%s: No websocket subscription", self.id)
            return False

        # Avoid error "Max frame length of 65536 has been exceeded" by limiting requests to some args
        for chunk in split.list_by_max_items(symbol_channels, 33):
            LOG.info("%s: Subscribe to %s args from %r to %r", self.id, len(chunk), chunk[0], chunk[-1])
            request = {"op": "subscribe", "args": chunk}
            await conn.send(json.dumps(request))
Esempio n. 2
0
    def connect(self) -> List[Tuple[AsyncConnection, Callable[[None], None], Callable[[str, float], None]]]:
        """
        Per Kraken Tech Support, subscribing to more than 20 symbols in a single request can lead
        to data loss. Furthermore, too many symbols on a single connection can cause data loss as well.
        """
        self.__reset()
        ret = []

        def build(options: list):
            subscribe = partial(self.subscribe, options=options)
            conn = WSAsyncConn(self.address, self.id, **self.ws_defaults)
            return conn, subscribe, self.message_handler

        for chan in set(self.channels or self.subscription):
            symbols = list(set(self.symbols or self.subscription[chan]))
            for subset in list_by_max_items(symbols, 20):
                ret.append(build((chan, subset)))

        return ret