IB API C# request HistoricalData

Discussion in 'App Development' started by BrazilForever, Mar 2, 2015.

  1. Hello Everyone,

    I am trying to request historical option data. Here is my code below:


    Code:
    Samples.EWrapperImpl ibClient = new Samples.EWrapperImpl();
                ibClient.ClientSocket.eConnect("", 7496, 0);
               
                Contract contract1 = new Contract();
                contract1.ConId = 119571812;
                contract1.Symbol = "SPX";
                contract1.SecType = "OPT";
                contract1.Exchange = "SMART";
                contract1.Right = "P";
                contract1.Strike = 1125;
                contract1.Expiry = "20151217";
    
                List<TagValue> BogusmktDataOptions = new List<TagValue>();
    
                ibClient.ClientSocket.reqHistoricalData(2, contract1, "20150225 17:11:11 GMT",
     "2 D", "1 hour", "BID_ASK", 1, 1, BogusmktDataOptions);
              
                Console.ReadKey();
                ibClient.ClientSocket.cancelHistoricalData(2);
                ibClient.ClientSocket.eDisconnect();
    
    As a response I get error message: "Starting time must occur before ending time"

    What am I doing wrong?

    Regards,
    BrazilForever
     
  2. Might want to download the demo test app and then submit the same request to see if it passes on the demo. If it passes, you've probably missed setting up some parameter. If that's the case, just set a breakpoint before the testclient submits the request and see what you are missing.

    TWS can be kind of cryptic in its messages.
     
  3. Thank you for the reply, TheGoonior.

    I am actually working in demo environment (I am choosing among different brokers with API offerings).

    I tried to simplify my example:
    Code:
    Samples.EWrapperImpl ibClient = new Samples.EWrapperImpl();
                ibClient.ClientSocket.eConnect("", 7496, 0);
    
                Contract contract = new Contract();
                contract.Symbol = "IBM";
                contract.SecType = "STK";
                contract.Exchange = "SMART";
                contract.Currency = "USD";
    
                List<TagValue> BogusmktDataOptions = new List<TagValue>();
    
                ibClient.ClientSocket.reqHistoricalData(2, contract, "20150225 17:11:11 GMT", "2 D", "1 hour", "BID_ASK", 1, 1, BogusmktDataOptions);
    
                Console.ReadKey();
    
    
                ibClient.ClientSocket.cancelHistoricalData(2);
                ibClient.ClientSocket.eDisconnect();
    
    I put a break point at
    Code:
    ibClient.ClientSocket.cancelHistoricalData(2); 
    And got the same output (see screenshot).

    Too bad I don't have access to their forum.

    Regards,
    BrazilForever Capture.PNG
     
  4. Yahoo actually had a pretty good sized forum...probably as good or better than the IB one.
    Also, the demo environment can be an issue to work with some times. Maybe try one bar of a single day.

    https://groups.yahoo.com/neo/groups/TWSAPI/info
     
    BrazilForever likes this.
  5. MD99

    MD99

    Try changing the time zone to EST instead of GMT. I don't know why but EST works for me but not GMT.
     
    BrazilForever likes this.
  6. @TheGoonior

    Thank you, I tried to join the group. I clicked "Join", then I was prompted to create public profile, and upon clicking on it I was redirected to yahoo home page. Are there special instructions to join?

    Recently, I have been noticing some small annoying bugs on Yahoo web-site.

     
  7. Both CST and EST produced the same negative result. I will try to contact IB API support.