SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Fri Sep 21, 2018 9:32 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Mon Feb 23, 2015 9:15 pm 
Offline

Joined: Thu Jan 22, 2015 6:23 pm
Posts: 11
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?


Top
 Profile  
 
PostPosted: Mon Feb 23, 2015 11:13 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
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.

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Thu Feb 26, 2015 2:22 pm 
Offline

Joined: Thu Jan 22, 2015 6:23 pm
Posts: 11
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.


Top
 Profile  
 
PostPosted: Thu Feb 26, 2015 2:45 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
OK, I understood it, will check.

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Thu Feb 26, 2015 3:50 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
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' ?

_________________
SmartQuant Development Team


Top
 Profile  
 
PostPosted: Thu Feb 26, 2015 4:01 pm 
Offline
Site Admin

Joined: Thu Jul 17, 2003 10:39 am
Posts: 1478
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.

_________________
SmartQuant Development Team


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group