Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use sorted dict for orders #1

Open
ridulfo opened this issue Mar 24, 2020 · 0 comments
Open

Use sorted dict for orders #1

ridulfo opened this issue Mar 24, 2020 · 0 comments
Labels
enhancement New feature or request

Comments

@ridulfo
Copy link
Owner

ridulfo commented Mar 24, 2020

By using a sorted dictionary the same sorted quality would exist, but with the added benefit of being able to cancel an order in O(log(n)) (sortedcontainers have that time complexity for deletion for some reason...)
From http://www.grantjenks.com/docs/sortedcontainers/_modules/sortedcontainers/sorteddict.html

def __delitem__(self, key):
        """Remove item from sorted dict identified by `key`.

        ``sd.__delitem__(key)`` <==> ``del sd[key]``

        Runtime complexity: `O(log(n))` -- approximate.

        >>> sd = SortedDict({'a': 1, 'b': 2, 'c': 3})
        >>> del sd['b']
        >>> sd
        SortedDict({'a': 1, 'c': 3})
        >>> del sd['z']
        Traceback (most recent call last):
          ...
        KeyError: 'z'

        :param key: `key` for item lookup
        :raises KeyError: if key not found

        """
        self._dict_delitem(key)
        self._list_remove(key)

Currently I believe it is O(nLog(n)):

for order in self.bids:
   if incomingOrder.order_id == order.order_id:
      self.bids.discard(order)
      break
@ridulfo ridulfo added the enhancement New feature or request label Mar 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant