Hi, I am developing an order book in java, which supports high speed order execution. I had previously developed a simple and messy order book based on two sorted maps, one for bid and one for ask. It is currently working in our project. Now I want to build a proper order book where the order execution is optimal in terms of speed and accuracy of order matching. How should I start building it? Here are the Classes I thought of: OrderBook -> contains map of SYMBOL (String) and Instrument (POJO). Instrument -> contains a linkedlist of Order(POJO), one for BID, one for ASK. Order -> contains orderId( long), quantity ( double), price( double), order type (market , limit), timestamp ( timestamp). OrderBook will have method executeEvent(), it will process 3 events ADD, UPDATE and DELETE. Though the design is still not optimal enough. I do think I can improve this further. How should I enhance this design?
Why do you need a custom order book? You can use currently available solutions and add your own customization. I personally use Ninja Trader (c#), and it has classes/methods to access all levels of the book.
Thanks for the reply. Our whole project is custom made. We just use core java to implement our stuffs. Also I wish to learn about order book and I learn better when I am working on things like this.
You could google for "Lmax disruptor". Theres a bunch of things from them online about high performance java. They also opensourced some of their stuff. Maybe it helps. i.e. http://martinfowler.com/articles/lmax.html
I have read about disruptors before. But are you saying there is some logic that will be useful in developing an order book? I will check out out.
Not very useful with respect to the intrinsics of an orderbook but more to do with the concurrency issues you are running into when listening on multiple feeds and receiving execution responses. Some APIs abstract the cross-thread synchronization away. The disruptor is but one pattern for building a technically lock-free message bus.
Agreed on that. At this point, I want to create the backbone framework of the order book. I will certainly try to optimize concurrency issues. Current priority is the implementation first. Once I get the core structure finalized. I will think of the design aspect.
What I wish to do in this thread is to find a data structure which best suits the business usecase of a typical LOB. I have finalized on of the component that I would need, that is the order book itself which will just execute order requests of all three types: CREATE, UPDATE and REMOVE. I am unable to think of any data structure which will help me in storing the orders based on price and timestamp. Here is a typical order information view: Code: Bid | Ask _________________________________ Quantity | Price | Quantity | Price _________________________________ 50 | 11.4 | 50 | 11.4 __________________________________ 500 | 11.25 | 100 | 11.5 _________________________________ 100 | 11 | 50 | 11.75 __________________________________ 50 | 10.5 | 50 | 12 __________________________________ Any pointer to a suitable data structure would be very helpful.
Why Java? It is very much being depreciated. Without asking questions you probably do not want to answer publicly, why Java?
Not allowed to edit so I will supplement. Its not that Java is being depreciated generally; its just that there are much better options with longer term support that most have already migrated to. What environment?