SmartQuant Discussion
http://www.smartquant.com/forums/

Error while getting IB daily bars
http://www.smartquant.com/forums/viewtopic.php?f=44&t=10910
Page 1 of 1

Author:  shomen [ Mon Feb 23, 2015 9:15 pm ]
Post subject:  Error while getting IB daily bars

Hi,
I'm using the GetHistoricalBars(..) twice, once to get historical data for the last 30 days -

in OnStrategyStart()-
DateTime start = Clock.Now.Date.AddDays(-30);
DateTime end = Clock.Now.Date;
var dailyBarsSeries = GetHistoricalBars("IB", this.Instrument, start, end, 86400);

and second each bar closed to get the current daily bar state -
var dailyBarsSeries = GetHistoricalBars("IB", Clock.Now.Date, Clock.Now.Date.AddDays(1), 86400);

Both of the requests worked and returns data but not on the same execution, i.e. when the first one returns records from IB the second one is not and vice verse.
I looked on the errors in API log -

when data returns the request to IB (for example getting the current daily bar) is -
20-4-3-AAPL-STK--0---SMART--USD--0-20150224 00:00:00-1 DAY-1 D-1-TRADES-1-

but when the request fails, again, the same function and the same parameters it looks like -
20-4-1-AAPL-STK--0---SMART--USD--0-20150223 00:00:00-1 DAY-180 D-1-TRADES-1-
and sometimes the request is sent as -
20-4-1-AAPL-STK--0---SMART--USD--0-20150223 00:00:00-1 DAY--15552000 S-1-TRADES-1-
even though i'm clearly not requesting seconds bar...

and those requests returns with the following errors -
4-2-1-162-Historical Market Data Service error message:Time length exceed max-
or
4-2-1-321-Error validating request:-'vd' : cause - When specifying a unit, historical data request duration format is integer{SPACE}unit (S|D|W|M|Y).-

I've tried all variations of GetHistoricalBars(..) and keep getting the same result - Not able to get both historical and current daily bar data at the same run or not able to get both of them at all.

I'm running on OQ v3.13
Can you please help?

Author:  Alexei Kurov [ Mon Feb 23, 2015 11:13 pm ]
Post subject:  Re: Error while getting IB daily bars

Hi,

TWS API does not support historical data requests from 'begin' to 'end' dates exactly.
It allows to request N units (years, days or seconds) back from the 'end' date.
In other words, IB plugin requests these N units (end - start) from the 'end' date,
so the following request
Code:
var dailyBarsSeries = GetHistoricalBars("IB", Clock.Now.Date, Clock.Now.Date.AddDays(1), 86400);
may be incorrect, because the end date is newer than now.

Author:  shomen [ Thu Feb 26, 2015 2:22 pm ]
Post subject:  Re: Error while getting IB daily bars

Hi Alexei,
I see, but it doesn't answer why when i'm sending -

DateTime start = Clock.Now.Date.AddDays(-180);
DateTime end = Clock.Now.Date;
var dailyBarsSeries = GetHistoricalBars("IB", this.Instrument, start, end, 86400);

you, in back end translate it to seconds request as shown in TWS Log-
20-4-1-AAPL-STK--0---SMART--USD--0-20150223 00:00:00-1 DAY--15552000 S-1-TRADES-1-

which should be something like -
20-4-1-AAPL-STK--0---SMART--USD--0-20150223 00:00:00-1 DAY-180 D-1-TRADES-1-

Also the following code DOES work and appears correct -
var dailyBarsSeries = GetHistoricalBars("IB", Clock.Now.Date, Clock.Now.Date.AddDays(1), 86400);

so again, i can't understand why the same code sometimes "parsed" correctly and brings data from IB and sometimes doesn't.

Author:  Alexei Kurov [ Thu Feb 26, 2015 2:45 pm ]
Post subject:  Re: Error while getting IB daily bars

OK, I understood it, will check.

Author:  Alexei Kurov [ Thu Feb 26, 2015 3:50 pm ]
Post subject:  Re: Error while getting IB daily bars

Hi,

I have checked the issue using your code sample and always get the following line
15:45:01:770 <- 20-4-4-AAPL-STK--0---SMART--USD--0-20150226 00:00:00-1 DAY-180 D-1-TRADES-1-

Could you exactly describe the situation when IB plugin sends '15552000 S' instead of '180 D' ?

Author:  Alexei Kurov [ Thu Feb 26, 2015 4:01 pm ]
Post subject:  Re: Error while getting IB daily bars

It seems that I know what happens. Please, look onto '15552000 S' value. It has negative sign, '-15552000 S'
It means that the start date greater than the end date by 180 days, so we have negative time duration.

Page 1 of 1 All times are UTC + 3 hours
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/