IB API C# request HistoricalData

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
 
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.
 
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
 
Back
Top