Confused about reqHistoricalData() and historicalData()

Discussion in 'Interactive Brokers' started by lime, Jun 15, 2024.

  1. lime

    lime

    Reading the docs on getting historical data, requesting by [reqHistoricalData](https://ibkrcampus.com/ibkr-api-page/twsapi-doc/#requesting-historical-bars) and receiving by [historicalData](https://ibkrcampus.com/ibkr-api-page/twsapi-doc/#receiving-historical-bars).

    I took me a while to realise `reqHistoricalData()` is void and the result goes to `historicalData()` marked by `historicalDataEnd()`. I find it a wee confusing. Why not just return a Collection (array of arrays), then I can define a Callable<double[][]> and Future.get() to process the data?
     
  2. DaveV

    DaveV

    Because everything in the IB API is asynchronous. In order to return the data as a Collection or Array, the IB API would have to suspend all other events until the the historical data is returned.

    In a typical IB API usage, with quotes, trades, etc., there are more than a hundred events occurring every second.
     
  3. lime

    lime

    I understand it is async, so I wrap the request in a Callable and executor.submit(req) and wait for its result, just like using promise or async await in Javascript. Why do I have to define two other functions is something I can't comprehend.
     
    DaveV likes this.
  4. traider

    traider

    IB initial api is old and they implemented their own async await/ CEP