Coder Social home page Coder Social logo

ridulfo / order-matching-engine Goto Github PK

View Code? Open in Web Editor NEW
50.0 6.0 19.0 21 KB

400k orders per second at a 2.5 μs (avg.) latency order matching engine in python

License: MIT License

Python 100.00%
orderbook matching-engine python pypy engine trade order stockmarket

order-matching-engine's Introduction

Order-Matching-Engine

(work in process)

Single orderbook on one thread:

On average, the engine takes 2.5μs to process an order. This means that the engine can ingest and process 400k orders per second (on 3 GHz Intel Core i7, 16 GB 1600 MHz DDR3) using the pypy interpreter. More benchmarks to come.

Multiple orderbooks, one thread per orderbook:

On average, the engine takes 1.18μs to process an order. This means that the engine can ingest and process 850k orders per second (on 3 GHz Intel Core i7, 16 GB 1600 MHz DDR3) using the pypy interpreter. More benchmarks to come.

order-matching-engine's People

Contributors

dependabot[bot] avatar ridulfo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

order-matching-engine's Issues

have question

Hello
I need an open source maching engine that can process sales orders that are placed in the database through the app, that is, I can finally create something like a binance.
Please advise that this engine of yours can run alongside my app? For example, the membership and wallet sections should be deposited or withdrawn in the my app, and only the trading section should be run in this maching engine?

Use sorted dict for orders

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

sorting problem in orderbook (?)

I'm not sure, but it seems to me something could be wrong with the sorting of orders in the orderbook or with your trade processOrder function. I tried the following exactly in this sequence:

1- limit order (side=sell, size=5, price=105)
2- limit order (side=sell, size=5, price=106)
and then
3- limit order (side=buy, size=1, price=105)
... but no trade took place!

The orderbook just added the lasd buy order to its content!
A trade would takes place, if I buy (for example size=1 and) price=106 and matches with the second order, but the first limit sell order with lower ask price (105) should have priority in this case.

not accumulated volumes

Hi,
thank you for developing and sharing this matching engine.
I tested your engine and noticed that it does not add up the volumes in the order book for orders with the same price. The order book simply lists them one below the other. But usually such orders are registered in the order book as a single order with an accumulated volume.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.