How to use the sortedcontainers.sorteddict.SortedDict function in sortedcontainers

To help you get started, we’ve selected a few sortedcontainers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bmoscon / cryptofeed / cryptofeed / rest / kraken.py View on Github external
def l2_book(self, symbol: str, retry=None, retry_wait=0):
        sym = pair_std_to_exchange(symbol, self.ID + 'REST')
        data = self._post_public("/public/Depth", {'pair': sym, 'count': 200}, retry=retry, retry_wait=retry_wait)
        for _, val in data['result'].items():
            return {
                BID: sd({
                    Decimal(u[0]): Decimal(u[1])
                    for u in val['bids']
                }),
                ASK: sd({
                    Decimal(u[0]): Decimal(u[1])
                    for u in val['asks']
                })
github bmoscon / cryptofeed / cryptofeed / rest / coinbase.py View on Github external
def l3_book(self, symbol: str, retry=None, retry_wait=10):
        orders = self._book(symbol, 3, retry, retry_wait)
        ret = {BID: sd({}), ASK: sd({})}
        for side in (BID, ASK):
            for price, size, order_id in orders[side + 's']:
                price = Decimal(price)
                size = Decimal(size)
                if price in ret[side]:
                    ret[side][price][order_id] = size
                else:
                    ret[side][price] = {order_id: size}
        return ret
github bmoscon / cryptofeed / cryptofeed / rest / gemini.py View on Github external
def l2_book(self, symbol: str, retry=None, retry_wait=0):
        sym = pair_std_to_exchange(symbol, self.ID)
        data = self._get(f"/v1/book/{sym}", retry, retry_wait)
        return {
            BID: sd({
                Decimal(u['price']): Decimal(u['amount'])
                for u in data['bids']
            }),
            ASK: sd({
                Decimal(u['price']): Decimal(u['amount'])
                for u in data['asks']
            })
github bmoscon / cryptofeed / cryptofeed / rest / ftx.py View on Github external
def l2_book(self, symbol: str, retry=None, retry_wait=0):
        sym = pair_std_to_exchange(symbol, self.ID)
        data = self._get(f"/markets/{sym}/orderbook", {'depth': 100}, retry=retry, retry_wait=retry_wait)
        return {
            BID: sd({
                u[0]: u[1]
                for u in data['result']['bids']
            }),
            ASK: sd({
                u[0]: u[1]
                for u in data['result']['asks']
            })
github bmoscon / cryptofeed / cryptofeed / rest / coinbase.py View on Github external
def l2_book(self, symbol: str, retry=None, retry_wait=10):
        data = self._book(symbol, 2, retry, retry_wait)
        return {
            BID: sd({
                Decimal(u[0]): Decimal(u[1])
                for u in data['bids']
            }),
            ASK: sd({
                Decimal(u[0]): Decimal(u[1])
                for u in data['asks']
            })
github grantjenks / python-sortedcontainers / sortedcontainers / sorteddict.py View on Github external
>>> SortedDict(alpha=1, beta=2) == d
        True

        """
        if args and (args[0] is None or callable(args[0])):
            _key = self._key = args[0]
            args = args[1:]
        else:
            _key = self._key = None

        self._list = SortedList(key=_key)

        # Calls to super() are expensive so cache references to dict methods on
        # sorted dict instances.

        _dict = super(SortedDict, self)
        self._dict_clear = _dict.clear
        self._dict_delitem = _dict.__delitem__
        self._dict_iter = _dict.__iter__
        self._dict_pop = _dict.pop
        self._dict_setitem = _dict.__setitem__
        self._dict_update = _dict.update

        # Reaching through ``self._list`` repeatedly adds unnecessary overhead
        # so cache references to sorted list methods.

        _list = self._list
        self._list_add = _list.add
        self._list_clear = _list.clear
        self._list_iter = _list.__iter__
        self._list_reversed = _list.__reversed__
        self._list_pop = _list.pop
github bmoscon / cryptofeed / cryptofeed / rest / poloniex.py View on Github external
def l2_book(self, symbol: str, retry=None, retry_wait=0):
        sym = pair_std_to_exchange(symbol, self.ID)
        data = self._get("returnOrderBook", {'currencyPair': sym}, retry=retry, retry_wait=retry_wait)
        return {
            BID: sd({
                    Decimal(u[0]): Decimal(u[1])
                    for u in data['bids']
                    }),
            ASK: sd({
                    Decimal(u[0]): Decimal(u[1])
                    for u in data['asks']
                    })