Home  Search  Register  Login  Recent Posts

Information on DTN's Industries:
DTN Oil & Gas | DTN Trading | DTN Agriculture | DTN Weather
Follow DTNMarkets on Twitter
DTN.IQ/IQFeed on Twitter
DTN News and Analysis on Twitter
»Forums Index »Archive (2017 and earlier) »IQFeed Developer Support »Question about days to query for historical
Author Topic: Question about days to query for historical (3 messages, Page 1 of 1)

brandon
-Interested User-
Posts: 19
Joined: Jan 4, 2006


Posted: Jan 8, 2006 02:34 PM          Msg. 1 of 3
I have written a function to return the amount of days for which to query the historical server given a number of trading days. For instance, if today is Monday and the market has been open or is open, and you want the past two days of data, it will return 4, as it will skip over weekends. Otherwise, if the market is NOT open, it will return 5, as it will only be able to retrieve Friday and Thursday.

This has been integrated with a holiday schedule checker (MarketOpen() function) to determine whether or not the market was closed on that day (Christmas, Easter, etc).

The function is below. I ask DTN developers to please let me know if this logic is correct:

* If day is a weekend, increase the number of days to query by 1.
* If the time of the CURRENT DAY is prior to the market opening (9:30 am), then increase the number of days to query by 1.

Is this correct? Please note the function below, and take a look at the TODO comments.


/*
* Get the actual amount of days to query the IQConnect server for 'days' trading days.
*/
int GetQueryDays(int days)
{
struct tm l_tm;
int cur_hour, cur_min, cur_day, cur_mon, cur_year, cur_wday;
time_t l_time = time(NULL);
int num_days = 0;
int i;

if (!days)
return 1;

localtime_r(&l_time, &l_tm);

cur_min = l_tm.tm_min;
cur_hour = l_tm.tm_hour;
cur_day = l_tm.tm_mday;
cur_mon = l_tm.tm_mon;
cur_year = l_tm.tm_year;
cur_wday = l_tm.tm_wday;

num_days = days;
i = 1;

/* First, check if we're in a trading day, and the request is only for one day. */
if (days == 1)
{
if (cur_wday != 0 && cur_wday != 6 && cur_hour <= 23 && cur_min <= 59)
{
if (cur_hour > 8)
{
/* TODO: > 30 may be buggy? It depends on when they roll-over for 1 minute bars. Check this later. */
if (cur_hour == 9 && cur_min > 30)
return 1; /* Just one day is needed. */
}
}
}

while (i <= days)
{
if (cur_wday == 0)
cur_wday = 6;
else
cur_wday -= 1;

if (cur_day == 1)
{
if (cur_mon == 0)
{
/* First day of January; we have to scroll-back a year. */
cur_year -= 1;
cur_mon = 11;
}
else
{
cur_mon -= 1;
}

cur_day = NumberOfDaysInMonth(cur_mon, cur_year);
}
else
cur_day -= 1;

if (Market_Open(cur_mon, cur_day, cur_wday, 11, 30))
i++;
else
num_days++;
}

/* If today is a weekend, or it's past midnight but before the market open, then add another day to the total. */
if (l_tm.tm_wday == 0 || l_tm.tm_wday == 6)
num_days++;
else if (l_tm.tm_hour >= 0 && l_tm.tm_hour <= 8)
num_days++;
else if (l_tm.tm_hour == 9 && l_tm.tm_min <= 30)
{
/* TODO: <= 30 may be buggy? It depends on when they roll-over for 1 minute bars. Check this later. */
num_days++;
}

return num_days;
}



Thanks in advance!

Brandon
Edited by brandon on Jan 8, 2006 at 02:35 PM

DTN_Steve_S
-DTN Guru-
Posts: 2096
Joined: Nov 21, 2005


Posted: Jan 9, 2006 03:39 PM          Msg. 2 of 3
/* TODO: <= 30 may be buggy? It depends on when they roll-over for 1 minute bars. Check this later. */ 

The History lookup is based on calendar days. So the rollover would be at midnight.

for example:
HT,MSFT,1; will return no data until MSFT trades on the current day.
This is true for tic and minute data (HT and HM requests)

Daily Data (HD requests) behave slightly different because the EOD files are processed in the evening and will contain the current day's data as soon as the process is completed (usually around 7PM CST) until this time, it will return the previous day's data.

brandon
-Interested User-
Posts: 19
Joined: Jan 4, 2006


Posted: Jan 10, 2006 01:15 PM          Msg. 3 of 3
Thank you!

- Brandon
 

 

Time: Sat July 5, 2025 2:15 PM CFBB v1.2.0 8 ms.
© AderSoftware 2002-2003