Creating and managing orderbook

I currently manage the orderbook in MySQL and written entire logic in Java from scratch. The orderbook is suppose to store only top 10 orders grouped by price (quantity added by price) on each side for all trading pairs supported by the platforms. The logic works in most of the test cases, but when it comes to flash sell through market price, the logic fails and creates duplicate orders in MySQL.

I am currently using TimeScale for OHLCV and so far it’s extremely stable. I was wondering if there is ready-to-use out of the box solution for my use case ? It’s really hard and time consuming re-invent the wheel using MySQL

Welcome, @Kunal_Barchha. Interesting use case. Do you want a tool to integrate with your stuff or something to replace what you already have in place?


I am looking to replace my entire Java logic with a DB, as of now I am exploring stored procedures with MySQL, because it is basically Create, Update, and Delete functions with little logic.

It’s 300 lines of code in Java to do it. So I am looking for something that is easy to replace my Java code with DB functions directly. Making it fast, robust, and reliable. So far I am already using TimeScale for OHLCV and I have millions of records, and there’s no reason to complain about, very happy with it. So my first preference was if Timescale has any such feature or tool…

I am not a DB expert, but I see that TimeScale does have extensive continuous aggregation APIs, the orderbook in my understanding is sort of continuous aggregation. Add quantity to existing order if price exists, else create new record, remove quantity from order on execution or cancellation, and things like that.

What I am thinking is to send newly placed order, cancelled order, and executed orders to TimeScale, and it automatically performs the logic whether to create, update or delete the record.

Very good! It seems continuous aggregates can be a good fit for it. If you need a hand to build it, you can also announce in the #conversation-community:jobs

I surely need two hands on it… Not much experience with continuous aggregation.