¿ªÔÆÌåÓý

ctrl + shift + ? for shortcuts
© 2025 Groups.io

C++ Multi-Threaded System Order Book & Historical Data Monitoring


 

Hi,

I am thinking of having 2 separate threads to handle order book and historical data monitoring. Main reason, I want to send aggressive orders when stops are hit rather than have passive orders on the book as soon as I enter a trade. Is this worth adding another thread over? Anyone else try this?

Thanks


 

It worth it. You can even do both (safer but require strong discipline) Stop is just another order.

But be careful about that if dealing with instrument with low liquidity vs your order volume. Use LII depth to evaluate the risk of not being filled in time.
In general IB will do faster than you can do if need to do balancing order across venues)

If I properly suspect what you want to do, you must be careful with "order efficiency" (~how frequently you just do a modification to an order or cancel a non filled order) IB monitor that.


 

Thanks for the tip Gordon. Currently, I am just doing "reqMktDepth()" in my main loop that also every xth minute submits a "reqHistoricalData()". In this loop, I am still building and storing the order book in a data structure, but I feel it is probably more efficient to just pop both these tasks into their own threads. That way in the order book thread, if I am in a position, I can be monitoring strictly for my stop being hit. Right now, I don't really have to worry too much about liquidity, but hopefully as my account grows I can add that logic. My thought process was if I keep positions under 5 contracts on NQ I should not really have an issue getting filled, no? I guess you never know though, the book can get extremely thin and pretty wide prior to economic announcements.?


 

Suggestion, look at the average volume over 50 days to get an idea of where you stand as risk for liquidity.
Your question have no safe answer and it depend also if you trade RTH only or aside of RTH. NQ or not, quit a few NQ stocks have zero vol during even a full minutes, in pre RTH, others have so small volume that this more garbage collection than trend (which is interesting to see anyway)

MarketDeepth need a constant monitoring to be of use. Otherwise better stay with monitoring bid/ask. L2 is close to "of no use" if you look at it every minutes,
you should look at it real time for a bout a minute then compute the trend/risk IB API is pretty well made to help doing that
This imply that you have it already running (unlikely you can wait a minute to finalize decision on your orders)
I don't know how to give advice on "loop" oriented coding, you typically should have "scenario" that unwind once triggered by a condition, like arrival of a tick (or any relevant event)
rogers