Interactive brokers - API - HistoricalDataEventArgs!?

Discussion in 'Programming' started by bluematrix, Aug 19, 2012.

  1. Can someone help me figure how to read back the data request through the IB API?

    the historicaldata event fires HistoricalDataEventArgs - I can read this i.e. .high or .low so it has data in it.. but it's suppose to have all the historical for the chosen date range - and doesn't have getenumerator..

    so question is: how do you convert this into meaningful bars/ticks - do you implement some class yourself? any examples anywhere? what needs to be done?

    appreciate any input.

  2. vicirek


    IB is event driven and returns 1 bar per event and the date/time field is how you can put it into desired series of bars. Usually it would be collection or array of OHLC structures or class instances or any other database design of your choice. You can index it as well because they come in order but it is always safer to check yourself by date and time if your request came back in order and complete. So when you request your bars in a separate request IB API will return all the requested bars in sequence (now up to 2000 bars per request ) one by one through the event. Then you process it there one by one.
  3. ok thanks - but when I request the bar through assigning client.HistoricalData to a event handler - I'm only getting 1 data point - even thought I've requested 5 days worth of daily data? What am I missing? thanks

    edit: here is a quick example - using the c# wrapper - when I request my historical data I expect multiple events to fire in sequence (if you say it's all event based?) or may e had some array structure. but neither is correct. I only get the first element of the sequence and nothing else.. any thoughts?

    void client_HistoricalData(object sender, HistoricalDataEventArgs e)


    throw new NotImplementedException();
  4. vicirek


    First please check how you request your bars and start with just one day 1 or 5 minute bars to see if your request and handler are wired properly. IB Demo may not return historical data properly and same might apply to paper account so you have to watch for that. Weekends are also not the best time to try because some servers are off.
  5. I'm simply using client.RequestHistoricalData from another method.. and it seems to be working fine - as e.RecordTotal returns the correct number of elements as I change the date range for the historical data.. yet I only can read one element through a.close etc..
  6. vicirek


    By the way is string so you have to split it into date format. tostring will return object I guess. But in any case You should get multiple message boxes with this code if the rest is correct.
  7. vicirek


    Also check your error message event queue. The request is for historicalbars and such request has limitations. In general no more requests than 1 per 10 seconds and no more than 2000 bars per request. Data base goes back one year or 6 months for bars less than 1 min. Otherwise you get error - most common is pacing violation. Limits are posted on their web and they change occasionally - latest was 6 month limit for less than 1 min bar. If IB sends you an error for your query then you will not get any data.
  8. vicirek


    You already implemented it so this might also be an issue. By the way how do you connect to IB with c#? Is this activex?
  9. 2rosy


    i use python but you need to specify the bar size in the request. then the data comes back in the call back ... historicalData()

    tickerId = cid,
    durationStr='10 D',
    barSizeSetting='15 mins',