The IB API reqHistoricalData()
method offers a whatToShow
argument which can take values to denote you seek data on TRADES, MIDPOINT, BID, ASK etc...
However, the API's historicalData
callback, provided to asynchronously receive the requested historical data, doesn't return the relevant whatToShow
making it impossible to ascertain what one is looking at. Is it the line for the TRADES, the BIDS or the ASKS I requested???
I get around this the obvious way, namely by requesting TRADES first, waiting for the entirety of the messages to come back and then requesting BIDS then wait again and request ASKS.
Does anyone have a better solution?
Please use the tickerId field properly which is the first parameter in reqHistoricalData() method. When you get the historical data with callbacks, you will be receiving this id back as the first parameter with historicalData().
You just need to keep track which tickerId is associated with which kind of data (bid, ask or trade) to identify that on the callback.
Example:
While requesting:
reqHistoricalData(1, ..whatToShow = Bid,...);
reqHistoricalData(2, ..whatToShow = Ask,...);
Callback handling:
historicalData(int reqId,....)
if(reqId == 1)
//This is the data built of bids as per request1
else if(reqId == 2)
//This is the data built of asks as per request2