Giter Club home page Giter Club logo

limit-orderbook-sim's Introduction

wot is it

This is a typescript implementation of a fast limit orderbook exchange primarily in memory. It's inspired by this venerable post which is a great resource for understanding the data structures required to complete standard limit order operations in O(1) time.

why typescript

It's hard to find a way to disregard speed and safety in one language. This is a good example of how to do it.

why is it fast

As the post explains, there are a couple of operations required for a limit orderbook:

Add – O(log M) for the first order at a limit, O(1) for all others Cancel – O(1) Execute – O(1) GetVolumeAtLimit – O(1) GetBestBid/Offer – O(1)

Let's go through them one by one:

Add: Supply an order and the limit price

Traverse the buy tree/sell tree (binary search) to find the correct place to insert the order. The closer the order is to the buy/ask, the more shallow the traversal will be. Alternatively, traverse from the lowestSell or highest buy. Worst case: O(n). Insert a new tail order encapsulated by said limit. O(1).

Cancel: supply an order ID and limit price

Lookup order ID in keyed map. Pop order from parentLimit.

Execute

Whenever the limits lowestBuy and highestSell match, execute. Pop orders off the linked list. O(1).

GetVolumeAtLimit

Find the limit by traversing the buy tree/sell tree. O(n).

GetBestBid/Offer

O(1), stored at the top level.

Thoughts

Pending benchmarks

limit-orderbook-sim's People

Watchers

 avatar

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.