Esempio n. 1
0
    def __init__(
            self,
            symbol: str,
            client=None,
            limit: int = DEFAULT_DEPTH_LIMIT,
            retry_policy: Optional[RetryPolicy] = DEFAULT_RETRY_POLICY
    ) -> None:
        self.asks = SequencedList()
        self.bids = SequencedList()

        self._symbol = normalize_symbol(symbol, True)
        self._client = None

        self._last_update_id = 0
        # The queue to save messages that are not continuous
        self._unsolved_queue = []
        self._onchange_callbacks = None
        self._updated_future = asyncio.Future()

        # Whether we are still fetching the depth snapshot
        self._fetching = False

        self.set_retry_policy(retry_policy)
        self.set_limit(limit)
        self.set_client(client)
    def orderbook(
        self,
        symbol: str
    ) -> OrderBook:
        """Gets the orderbook for a certain symbol. If you get a certain orderbook, don't forget to subscribe to the orderbook stream of `symbol`::

            await client.subscribe(SubType.ORDER_BOOK, 'BTCUSDT')

        Args:
            symbol (str): The symbol name.

        Returns:
            OrderBook: The orderbook.
        """
        symbol = normalize_symbol(symbol)

        if symbol in self._orderbooks:
            return self._orderbooks[symbol]

        orderbook = OrderBook(symbol,
                              limit=self._limit,
                              retry_policy=self._retry_policy
                              )

        if self._client:
            orderbook.set_client(self._client)
        else:
            self._uninit_orderbooks.append(orderbook)

        self._orderbooks[symbol] = orderbook

        return orderbook