Giter Club home page Giter Club logo

Comments (6)

deepbrook avatar deepbrook commented on August 29, 2024

Hey @kjgd ,
The only documentation available is indeed only provided as doc strings.
As for the query method, you will have to implement this yourself (or submit a PR to add this!) - the implementation itself is just meant as a means to store, update and remove orders.

The project isn't done yet, of course, so I may add this later on. However, the C implementation takes precedence for me.

best,
Nils

from hft-orderbook.

kjgd avatar kjgd commented on August 29, 2024

Yes, I can appreciate that the C implementation takes precedence, but I don't know C so I will have to hope you (or someone else) end up implementing the query method there :)

Regarding the Python version, I have to admit I am entirely unsure how to even begin querying a binary tree in order to implement a GetVolumeAtLimit type method.

from hft-orderbook.

deepbrook avatar deepbrook commented on August 29, 2024

Hey @kjgd,
If you look at the implementation, you can see that all limits are stored in a dictionary. You would just have to turn it's keys into a sorted list, and then iterate over the dictionary to get each limits size and price. You can, in theory, even allow level 3 order books this way, by simply iterating over the limit's orders attribute.

Best,

Nils

from hft-orderbook.

kjgd avatar kjgd commented on August 29, 2024

Maybe I'm confused by the existence of a LimitLevel class which is marked as being a BST.

What is stored in the binary tree then, if not for the limits?

from hft-orderbook.

deepbrook avatar deepbrook commented on August 29, 2024

The LimitLevels are stored in a balanced binary tree (AVL tree).
Additionally, a reference to all orders is kept in a separated dictionary, as well as to all limit levels.
This ensures that accessing any limit and any order is O(1), as well as deleting and updating. Only inserting a new limit level will take longer.

Take a look at the blog post by WK Selph, upon which this implementation is based.

from hft-orderbook.

kjgd avatar kjgd commented on August 29, 2024

Ok, let's consider the following book:

import lob as LOB
lob = LOB.LimitOrderBook()
orders = [
    LOB.Order(uid=1, is_bid=True, size=5, price=100),
    LOB.Order(uid=2, is_bid=True, size=5, price=95),
    LOB.Order(uid=3, is_bid=True, size=5, price=90),
    LOB.Order(uid=4, is_bid=False, size=5, price=200),
    LOB.Order(uid=5, is_bid=False, size=5, price=205),
    LOB.Order(uid=6, is_bid=False, size=5, price=210),
    ]
for order in orders:
     lob.process(order)

I'm looking at the limit level dictionary:
lob._price_levels
Since no limit level is aware of whether it is a bid or an ask level, it looks like determining this means querying:
lob._price_levels[100].orders.head.is_bid
(for an order book containing a price level of 100)

And therefore it looks like the only way to separate out bids and asks is:

bids = []
asks = []
for k, level in lob._price_levels.items():
    if level.orders.head.is_bid:
        bids.append(level)
    else:
        asks.append(level)

Now, since the query function should also be O(1), I would like to avoid iterating through every price level in the book where this is not necessary -- a book may have 1000 levels but only the first 100 may be relevant.

Is there any way to do this?

from hft-orderbook.

Related Issues (16)

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.