5 Historical and intra-day data

Historical data can be retrieved via the 'history' action, subject to your account subscription rights, and IQFeed’s pacing limitations. Several data-types are available, which can be set using the DataType parameter (default: 'day').59

5.1 Daily data

To retrieve historic daily data bars, set DataType to 'd' or 'day' (or just leave this parameter out, since 'day' is the default data type), and set the asset’s Symbol:

>> data = IQML('history', 'symbol','IBM');
>> data = IQML(
'history', 'symbol','IBM', 'dataType','day') %equivalent
data =
100×1 struct array with fields:
Symbol
Datestamp
Datenum
High
Low
Open
Close
PeriodVolume
OpenInterest

We received an array of Matlab structs containing daily bars, one per each of the last N trading days (excluding currently-trading day’s bar for IQFeed clients 6.0 or older; including the current day’s bar for 6.1 or newer). By default, we receive up to N=100 data bars, ordered from oldest to newest. We ran the query above using IQFeed client 5.2 on March 6, 2018 so we received daily data from 2017-10-10 until 2018-03-05:

>> data(1)
ans =
Symbol: 'IBM'
Datestamp: '2017-10-10'
Datenum: 736978
High: 148.95
Low: 147.65
Open: 147.71
Close: 148.5
PeriodVolume: 4032601
OpenInterest: 0

>> data(end)
ans =
Symbol: 'IBM'
Datestamp: '2018-03-05'
Datenum: 737124
High: 157.49
Low: 153.75
Open: 154.12
Close: 156.95
PeriodVolume: 3670630
OpenInterest: 0

You can aggregate the numeric values into Matlab arrays as follows:

dates = {data.Datestamp}; % cell-array of strings
closes = [data.Close]; % array of numeric values

You can then use these arrays for vectorized processing, plotting etc. For example:

dates2 = datetime(dates); % array of datetime objects
[maxVal, maxIdx] = max(closes); % maximal value and location index
[minVal, minIdx] = min(closes);
% minimal value and location index

plot(dates2, closes); hold on;
plot(dates2(maxIdx), maxVal, '^g');
% maximal data point – green ▲
plot(dates2(minIdx), minVal, 'vr');
% minimal data point – red ▼

???

You can change the order at which the data bars are reported, using the DataDirection parameter (1 means oldest-to-newest (default); -1 means newest-to-oldest):

>> data = IQML('history', 'symbol','IBM', 'dataDirection',-1);
>> data(1)
ans =
Symbol: 'IBM'
Datestamp: '2018-03-05'
Datenum: 737124
High: 157.49
Low: 153.75
Open: 154.12
Close: 156.95
PeriodVolume: 3670630
OpenInterest: 0

It is possible that there may be fewer than N=100 daily bars for an asset. For example, the symbol @EMF19 (1-month Euro-Dollar Jan 2019 future on CME) started trading on 2018-01-12, so we only get 35 daily bars when we run the query on 2018-03-06:

>> data = IQML('history', 'symbol','@EMF19');
data =
35×1 struct array with fields:
Symbol
...

You can ask IQFeed to limit the maximal number of data bars (N) using the MaxItems parameter:

>> data = IQML('history', 'symbol','IBM', 'maxItems',20)
data =
20×1 struct array with fields:
Symbol
...

In this example, data(1).Datestamp='2018-02-05', i.e. 20 trading days ago.

Note that the MaxItems parameter only has an effect if the additional data bars actually exist. In other words, it controls the maximum number of returned data bars – the actual number of bars may be less than this value.60

When the number of data bars that IQFeed sends is very large, it could take a while for the information to be sent. In such a case, IQML might time-out on the request and return only partial data. Such a case is detected and reported by IQML:

>> data = IQML('history', 'symbol','IBM', 'maxItems',-1)

Warning: IQML timeout: only partial data is returned: the Timeout parameter should be set to a value larger than 5

data =
1274×1 struct array with fields:
Symbol
...

As suggested by the message, you can set the Timeout parameter to a high value in order to allow IQML more time to gather the data before returning the results:

>> data = IQML('history', 'symbol','IBM', 'maxItems',-1, 'timeout',60) %oldest:1/2/96
data =
5577×1 struct array with fields:
Symbol
...

You can also specify a BeginDate/EndDate interval for the returned data. Dates can be specified in several formats: numeric Matlab datenum (737089), Matlab datetime object, numeric yyyymmdd (20180129), string ('2018/01/29', '2018-01-29', '20180129'). Note that MaxItems takes precedence over BeginDate, regardless of DataDirection. For example, if MaxItems=5, you will only get the 5 latest bars, for any BeginDate.61

You can request historical data for multiple symbols at the same time, in a single IQML command, by specifying a colon-delimited or cell-array list of symbols. For example:

>> data = IQML('history', 'symbol',{'IBM','GOOG','AAPL'}, 'maxItems',20)

>> data = IQML('history', 'symbol','IBM:GOOG:AAPL', 'maxItems',20) %equivalent

The result will be an array of Matlab structs that correspond to the requested symbols (3 symbols with 20 data-points each, in this example):

data =
20×3 struct array with fields:
Symbol
...

>> data(1,2) % 2nd index (column) is the symbol; GOOG data is in data(:,2)
ans =
struct with fields:
Symbol: 'GOOG'
Datestamp: '2018-07-10'
Datenum: 737251
High: 1159.59
Low: 1149.59
Open: 1156.98
Close: 1152.84
PeriodVolume: 798412
OpenInterest: 0

In certain cases, when you request historic data for multiple symbols, you might receive a different number of data bars for different symbols, depending on data availability. In such cases, the result will not be an N-by-M struct array, but a cell array (one cell for each symbol) that contains struct arrays. For example:

data =
1×3 cell array
{77×1 struct} {100×1 struct} {55×1 struct}

IQML queries for multiple symbols or dates (if BeginDate and EndDate are specified) can be parallelized using the UseParallel parameter, if you have a Professional IQML license and Matlab’s Parallel Computing Toolbox (§3.6):

>> data = IQML('history', 'UseParallel',true, 'symbol',symbols) %multi-symbols

>> data = IQML('history', 'UseParallel',true, 'symbol','IBM',...
'BeginDate',19900102, 'EndDate',20181028) %date range

The following parameters affect daily history data queries:

Parameter

Data type

Default

Description

Symbol or Symbols 62

colon or comma-delimited string or cell-array of strings

(none)

Limits query to specified symbol(s). Examples:

'@VX#'

'IBM:AAPL:GOOG'

'IBM,AAPL,GOOG'

{'IBM', 'AAPL', 'GOOG'}

This parameter must be set to valid symbol name(s). Multiple symbols can be parallelized using the UseParallel parameter (see below).

DataDirection

integer

1
meaning oldest first, newest last

Sets the order of data bars in the returned struct array. One of the following values:

1 means oldest-to-newest (default)

-1 means newest-to-oldest

MaxItems

integer

100

Returns up to the specified number of data bars (if available). -1 means all available.

BeginDate

integer or string or datetime object

'1900/01/01' (i.e., from as early as data is available)

Earliest bar date. Examples:

737089 (Matlab datenum format)

datetime('Jan 29, 2018')

20180129 (yyyymmdd format)

'20180129'

'2018/01/29'

'2018-01-29'

Note: MaxItems has precedence over BeginDate: If there are more data points than MaxItems between BeginDateEndDate, only the last MaxItems data points (from EndDate backward) will be returned, regardless of BeginDate.

EndDate

integer or string or datetime

'2099/12/31' (i.e., until now)

Latest bar date.

See BeginDate parameter above for details.

Timeout

number

5.0

Max # of seconds to wait for incoming data (0-9000, where 0 means infinite)

UseParallel

logical (true/false)

false

If set to true or 1, and if Parallel Computing Toolbox is installed, then querying multiple symbols or dates will be done in parallel (see §3.6; Professional IQML license only).

5.2 Weekly data

To retrieve historic weekly data bars, set DataType to 'w' or 'week':

>> data = IQML('history', 'symbol','FB', 'dataType','week')
data =
100×1 struct array with fields:
Symbol
Datestamp
Datenum
High
Low
Open
Close
PeriodVolume
OpenInterest

As with the daily bars, we received an array of Matlab structs containing weekly bars, one per each of the last N weeks (excluding currently-trading day for IQFeed clients 6.0 or older; including the current day for 6.1 or newer). By default we receive up to N=100 data bars (~2 years), ordered from oldest to newest. We ran the query above on Tuesday March 6, 2018 using IQFeed client 5.2 so we received weekly data from Friday 2016-04-15 (the data bar for April 11-15, 2016) until 2018-03-05 (the data bar for Monday March 5, 2018 only, excluding March 6). Each bar’s Datestamp indicates the end-date of the bar. Note that all data bars except for the latest have a Friday date.

As with the daily bars, you can change the data bars order, using the DataDirection parameter (1 means oldest-to-newest (default); -1 means newest-to-oldest).

>> data = IQML('history', 'symbol','FB', 'dataType','week', 'dataDirection',-1);

As with the daily bars, you can ask IQFeed to limit the maximal number of data bars (N) using the MaxItems parameter:

>> data = IQML('history', 'symbol','FB', 'dataType','week', 'maxItems',20);

In this example, data(1).Datestamp='2017-10-27', i.e. the Friday 20 weeks ago.

As with the daily bars, you can set the Timeout parameter to a high value in order to allow IQML more time to gather data before returning the results. This is typically not necessary for weekly data requests, because of the relatively small amount of data.

You can also specify a BeginDate for the returned data. Dates can be specified in various formats: as a numeric Matlab datenum (737089), a Matlab datetime object, numeric yyyymmdd (20180129), or as a string ('2018/01/29', '2018-01-29', '20180129').63

For example, if we a query with a BeginDate of Monday Jan 29, 2018, we will receive data bars starting on Friday Feb 2, 2018 (which includes the weekly data of Jan 29):

>> data = IQML('history','symbol','FB','dataType','week','BeginDate',20180129);

warningNote: unlike daily data requests, you cannot specify EndDate in a request for historic weekly data bars. All weekly data bars up to yesterday/today64 will be returned.

Also note that MaxItems has precedence over BeginDate, regardless of DataDirection. For example, if MaxItems=5, we’ll only get the 5 latest bars, regardless of BeginDate.

As with daily data requests, you can request historical data for multiple symbols at the same time, in a single IQML command, by specifying a colon-delimited or cell-array list of symbols. For example:

>> data = IQML('history', 'symbol',{'IBM','GOOG','AAPL'}, ...
'dataType','week', 'maxItems',20)

>> data = IQML('history', 'symbol','IBM:GOOG:AAPL', ...
'dataType','week', 'maxItems',20) %equivalent

The result will be an array of Matlab structs that correspond to the requested symbols (3 symbols with 20 data-points each, in this example):

data =
20×3 struct array with fields:
Symbol
Datestamp
...

In certain cases, when you request historic data for multiple symbols, you might receive a different number of data bars for different symbols, depending on data availability. In such cases, the result will not be an N-by-M struct array, but a cell array (one cell for each symbol) that contains struct arrays. For example:

data =
1×3 cell array
{77×1 struct} {100×1 struct} {55×1 struct}

IQML queries for multiple symbols can be parallelized using the UseParallel parameter, if you have a Professional IQML license and Matlab’s Parallel Computing Toolbox (§3.6):

>> data = IQML('history', 'symbol',symbols, 'UseParallel',true, ...
'dataType','week', 'maxItems',20)

The following parameters affect weekly history data queries:

Parameter

Data type

Default

Description

Symbol or Symbols 65

colon or comma-delimited string or cell-array of strings

(none)

Limits the query to the specified symbol(s). Examples:

'@VX#'

'IBM:AAPL:GOOG'

'IBM,AAPL,GOOG'

{'IBM', 'AAPL', 'GOOG'}

This parameter must be set to valid symbol name(s). Multiple symbols can be parallelized using the UseParallel parameter (see below).

DataDirection

integer

1
meaning oldest bar is first, newest is last

Sets the order of data bars in the returned struct array. One of the following values:

1 means oldest-to-newest (default)

-1 means newest-to-oldest

MaxItems

integer

100

Returns up to the specified number of data bars (if available). -1 means all available.

BeginDate

integer or string or datetime object

'1900/01/01' (i.e., from as early as data is available)

Earliest bar that includes a date. Examples:

737089 (Matlab datenum format)

datetime('Jan 29, 2018')

20180129 (yyyymmdd format)

'20180129'

'2018/01/29'

'2018-01-29'

Note: MaxItems has precedence over BeginDate: If there are more data points than MaxItems between BeginDate and yesterday/today66, only the last MaxItems data points (from yesterday/today backward) will be returned, regardless of BeginDate.

Timeout

number

5.0

Max number of seconds to wait for incoming data (0-9000, where 0 means infinite)

UseParallel

logical (true/false)

false

If set to true or 1, and if Parallel Computing Toolbox is installed, then querying multiple symbols will be done in parallel (see §3.6; Professional IQML license only).

5.3 Monthly data

To retrieve historic monthly data bars, set DataType to 'm' or 'month':

>> data = IQML('history', 'symbol','FB', 'dataType','month')
data =
100×1 struct array with fields:
Symbol
Datestamp
Datenum
High
Low
Open
Close
PeriodVolume
OpenInterest

As with the daily bars, we received an array of Matlab structs containing monthly bars, one per each of the last N months (excluding currently-trading day for IQFeed clients 6.0 or older; including the current day for IQFeed clients 6.1 or newer). By default we receive up to N=100 data bars (~8 years), ordered from oldest to newest. We ran the example query above on March 6, 2018 using IQFeed client 5.2 so we received monthly data from 2009-12-31 (the data bar for 12/2009) until 2018-03-05 (the data bar for March 2018 up to March 5, 2018, excluding data from March 6).

As with the daily bars, you can change the data bars order, using the DataDirection parameter (1 means oldest-to-newest (default); -1 means newest-to-oldest).

>> data = IQML('history', 'symbol','FB', 'dataType','month', ...
'dataDirection',-1);

As with the daily bars, you can ask IQFeed to limit the maximal number of data bars (N) using the MaxItems parameter:

>> data = IQML('history', 'symbol','FB', 'dataType','month', 'maxItems',20);

In this example, data(1).Datestamp='2016-08-31', i.e. 20 months ago.

As with the daily bars, you can set the Timeout parameter to a high value in order to allow IQML more time to gather data before returning the results. This is typically not necessary for monthly data requests, because of the relatively small amount of data.

You can also specify a BeginDate for the returned data. Dates can be specified in various formats: as a numeric Matlab datenum (737089), a Matlab datetime object, numeric yyyymmdd (20180129), or as a string ('2018/01/29', '2018-01-29', '20180129').

For example, if we a query with a BeginDate of Jan 29, 2018, we will receive data bars starting on Jan 31, 2018 (which includes the monthly data of Jan 29):

>> data = IQML('history','symbol','FB','dataType','month','BeginDate',20180129);

warningNote: unlike daily data requests, you cannot specify EndDate in a request for historic monthly data bars. All monthly data bars up to yesterday/today67 will be returned.

Also note that MaxItems has precedence over BeginDate, regardless of DataDirection. For example, if MaxItems=5, we’ll only get the 5 latest bars, regardless of BeginDate.68

As with daily data requests, you can request historical data for multiple symbols at the same time, in a single IQML command, by specifying a colon-delimited or cell-array list of symbols. For example:

>> data = IQML('history', 'symbol',{'IBM','GOOG','AAPL'}, ...
'dataType','month', 'maxItems',20)

>> data = IQML('history', 'symbol','IBM:GOOG:AAPL', ...
'dataType','month', 'maxItems',20) %equivalent

The result will be an array of Matlab structs that correspond to the requested symbols (3 symbols with 20 data-points each, in this example):

data =
20×3 struct array with fields:
Symbol
Datestamp
...

In certain cases, when you request historic data for multiple symbols, you might receive a different number of data bars for different symbols, depending on data availability. In such cases, the result will not be an N-by-M struct array, but a cell array (one cell for each symbol) that contains struct arrays. For example:

data =
1×3 cell array
{77×1 struct} {100×1 struct} {55×1 struct}

IQML queries for multiple symbols can be parallelized using the UseParallel parameter, if you have a Professional IQML license and Matlab’s Parallel Computing Toolbox (§3.6):

>> data = IQML('history', 'symbol',symbols, 'UseParallel',true, ...
'dataType','month', 'maxItems',20)

The following parameters affect monthly history data queries:

Parameter

Data type

Default

Description

Symbol or Symbols 69

colon or comma-delimited string or cell-array of strings

(none)

Limits the query to the specified symbol(s). Examples:

'@VX#'

'IBM:AAPL:GOOG'

'IBM,AAPL,GOOG'

{'IBM', 'AAPL', 'GOOG'}

This parameter must be set to valid symbol name(s). Multiple symbols can be parallelized using the UseParallel parameter (see below).

DataDirection

integer

1
meaning oldest bar is first, newest is last

Sets the order of data bars in the returned struct array. One of the following values:

1 means oldest-to-newest (default)

-1 means newest-to-oldest

MaxItems

integer

100

Returns up to the specified number of data bars (if available). -1 means all available.

BeginDate

integer or string or datetime object

'1900/01/01' (i.e., from as early as data is available)

Earliest bar that includes a date. Examples:

737089 (Matlab datenum format)

datetime('Jan 29, 2018')

20180129 (yyyymmdd format)

'20180129'

'2018/01/29'

'2018-01-29'

Note: MaxItems has precedence over BeginDate: If there are more data points than MaxItems between BeginDate and yesterday/today70, only the last MaxItems data points (from yesterday/today backward) will be returned, regardless of BeginDate.

Timeout

number

5.0

Max number of seconds to wait for incoming data (0-9000, where 0 means infinite)

UseParallel

logical (true/false)

false

If set to true or 1, and if Parallel Computing Toolbox is installed, then querying multiple symbols will be done in parallel (see §3.6; Professional IQML license only).

5.4 Interval data

To retrieve historic data bars having a custom width, possibly as short as a single second, set DataType to 'i' or 'interval', and set the asset’s Symbol:

>> data = IQML('history', 'symbol','FB', 'dataType','interval')
data =
100×1 struct array with fields:
Symbol
Timestamp
Datenum
High
Low
Open
Close
TotalVolume
PeriodVolume
NumberOfTrades

>> data(end)
ans =
Symbol: 'IBM'
Timestamp: '2018-03-07 09:43:00'
Datenum: 737126.404861111
High: 156.97
Low: 156.77
Open: 156.83
Close: 156.77
TotalVolume: 215082
PeriodVolume: 16080
NumberOfTrades: 0

The returned data struct here is similar to the struct returned by the daily, weekly and monthly historical data queries. Unlike those queries, interval-query result does not include an OpenInterest field, but does include two new fields: TotalVolume (which indicates the total daily volume up to that bar), and NumberOfTrades. Also note that we get a Timestamp field (US Eastern time-zone), not Datestamp as with the other queries.

Bars that had no trading action are not reported. In the example query above, we see the following Timestamp values, where we clearly see a gap during non-trading hours:

>> {data.Timestamp}'
ans =
100×1 cell array
{'2018-03-06 14:59:00'}
{'2018-03-06 15:00:00'}
{'2018-03-06 15:01:00'}
...
% contiguous data bars
{'2018-03-06 15:59:00'}
{'2018-03-06 16:00:00'}
{'2018-03-06 16:03:00'}
{'2018-03-06 16:11:00'}
...
{'2018-03-07 08:45:00'}
{'2018-03-07 09:22:00'}
{'2018-03-07 09:31:00'}
{'2018-03-07 09:32:00'}
...
% contiguous data bars
{'2018-03-07 09:43:00'}
{'2018-03-07 09:44:00'}

As with the other queries, the current (partial) interval bar is never reported, nor bars that have no data (e.g., 16:04-16:10, 8:34-8:44, 8:46-9:21 in the example above).

The default interval size is 60 secs (aligned on the full-minute mark). You can specify different interval sizes using the IntervalSize parameter. For example, a 15-sec interval:

>> data=IQML('history','symbol','FB','dataType','interval','intervalSize',15);

IQFeed is smart enough to automatically align data bars to full minutes/hours when the requested IntervalSize enables this (as is the case for 15 or 60-sec intervals). For example, with 15-sec IntervalSize we may get bars for 10:04:30, 10:04:45, 10:05:00. When such alignment is not possible, you will get non-aligned bars. For example, with a 13-sec IntervalSize: 09:59:18, 09:59:31, 09:59:57, 10:00:10.

By default, IntervalSize specifies the interval’s size in seconds and all the bars have this same duration. You can change this by setting the IntervalType parameter (default: 'secs') to 'volume' or 'ticks'/'trades'. Naturally, if you change IntervalType, the data bars will now have non-equal durations.

>> data = IQML('history', 'symbol','FB', 'dataType','interval', ...
'intervalType','ticks');

The IntervalType (default: 'secs') and IntervalSize (default: 60) parameters should typically be specified together. Note that IntervalSize must be a positive integer value (i.e. its value cannot be 4.5 or 0). If IntervalType is 'ticks'/'trades', IntervalSize must be 2 or higher; If IntervalType is 'volume', IntervalSize must be 100 or higher; If IntervalType is 'secs', IntervalSize must be between 1 and 86400 (1 day).71

By default, IQML reports data in intervals whose labels are set at the end of the interval. For example, a data item at 11:12:34 with IntervalSize=60 (1 minute) will be included in the interval labeled ‘11:13:00’. You can modify this default behavior by setting the LabelAtBeginning parameter to 1 (or true), so that the labels are set at the beginning. In this example, the data item will be reported in the ‘11:12:00’ interval. Note: using LabelAtBeginning parameter requires IQFeed client version 6.0 or newer.

By default, IQML only reports interval data from today. You can ask to see additional (older) calendar days by specifying a positive Days parameter value. If you set Days to -1, then all available information will be reported, subject to the other filter criteria.

In addition, you can specify a daily time-window: only bars between BeginFilterTime and EndFilterTime in each day (US Eastern time-zone) will be reported. This could be useful, for example, to limit the results only to the regular trading hours.

Similarly, you can specify a date/time window for all the data bars: only bars between the specified BeginDateTime and EndDateTime (US Eastern time) will be reported.

Note: queries having UseParallel=true are only parallelized if BeginDateTime is specified, or if multiple Symbols are specified (see below). Single-Symbol queries that have an empty (unspecified) BeginDateTime are not parallelizable.

As with the daily bars, you can change the data bars order, using the DataDirection parameter (1 means oldest-to-newest (default); -1 means newest-to-oldest).

>> data=IQML('history','symbol','FB','dataType','interval','dataDirection',-1);

As with the daily bars, you can ask IQFeed to limit the maximal number of data bars (N) using the MaxItems parameter:

>> data = IQML('history', 'symbol','FB', 'dataType','interval', 'maxItems',20);

Note that MaxItems takes precedence over BeginDateTime, regardless of DataDirection. For example, if MaxItems=5, you will only get the 5 latest bars (before EndDateTime), regardless of the specified BeginDateTime.

As with the daily bars, you can set the Timeout parameter to a high value in order to allow IQML more time to gather data before returning the results.

As with daily data requests, you can request historical data for multiple symbols at the same time, in a single IQML command, by specifying a colon-delimited or cell-array list of symbols. For example:

>> data = IQML('history', 'symbol',{'IBM','GOOG','AAPL'}, ...
'dataType','interval', 'maxItems',20)

>> data = IQML('history', 'symbol','IBM:GOOG:AAPL', ...
'dataType','interval', 'maxItems',20) %equivalent

The result will be an array of Matlab structs that correspond to the requested symbols (3 symbols with 20 data-points each, in this example):

data =
20×3 struct array with fields:
Symbol
Datestamp
...

In certain cases, when you request historic data for multiple symbols, you might receive a different number of data bars for different symbols, depending on data availability. In such cases, the result will not be an N-by-M struct array, but a cell array (one cell for each symbol) that contains struct arrays. For example:

data =
1×3 cell array
{77×1 struct} {100×1 struct} {55×1 struct}

IQML queries for multiple symbols or a date/time range (i.e., if BeginDateTime is specified) can be parallelized using the UseParallel parameter, if you have a Professional IQML license and Matlab’s Parallel Computing Toolbox (see §3.6):

>> data = IQML('history', 'dataType','interval', 'UseParallel',true, ...
'symbol',symbols) % multiple symbols parallelized

>> data = IQML('history', 'dataType','interval', 'UseParallel',true, ...
'symbol','IBM' ,... % single-symbol date-range parallelized
'BeginDateTime',20181026100000, ...
'EndDateTime', 20181026110000)

In some cases, users may be tempted to use the historical data mechanism to retrieve real-time data. This is relatively easy to set-up. For example, using an endless Matlab loop that sleeps for 60 seconds, requests the latest historical data for the past minute and then goes to sleep again, or using a periodic timer object that wakes up every minute. In such cases, consider using streaming rather than historical queries (see §6).

Some software vendors make a distinction between intra-day and historical information. However, as far as IQFeed and IQML are concerned, this is merely a semantic difference and there is no practical difference.

Note: IQFeed limits interval data to the past 180 calendar days if you make the request outside trading hours, but just past 8 days for requests during US trading hours (9:30-16:30 US Eastern time, Mon-Fri). So, if you request month-old data during trading hours you will get empty results, even if the request was just for a single hour.72

The only exception to the 8/180-day limitation are interval bars of full minutes (IntervalType='secs' and IntervalSize a multiple of 60), since these bars are pre-computed and have a lesser impact on IQFeed’s servers. The other interval types are computed on-the-fly from tick data, and so are limited in duration in order not to overload IQFeed’s servers, especially during trading hours when server load is high.

IQFeed imposes other limitations based on interval size: minute data is only available since 2005-2007;73 longer intervals (daily/weekly/monthly) can access up to 15+ years.74

IQFeed subscriptions for daily and intra-day data are different. If you only subscribed for daily data, you will receive a run-time error when fetching intra-day interval data:

IQML historic data query (EURGBP.FXCM) error: Unauthorized user ID (your IQFeed account is not authorized for this data)

Also note that IQFeed’s interval data typically exclude irregular “O” trades (see §5.5).

Finally, note that whereas sub-daily data may report data from non-trading days (e.g., Sunday night, when ES starts trading), these are typically added to the following trading day’s bar with daily/weekly/monthly bars.75

The following parameters affect interval history data queries:

Parameter

Data type

Default

Description

Symbol or Symbols 76

colon or comma-delimited string or cell-array of strings

(none)

Limits the query to the specified symbol(s). Examples:

'@VX#'

'IBM:AAPL:GOOG'

'IBM,AAPL,GOOG'

{'IBM', 'AAPL', 'GOOG'}

This parameter must be set to valid symbol name(s). Multiple symbols can be parallelized using the UseParallel parameter (see below).

DataDirection

integer

1, meaning oldest bar is first, newest is last

Sets the order of data bars in the returned struct array. One of the following values:

1 means oldest-to-newest (default)

-1 means newest-to-oldest

LabelAtBeginning

integer

0

0: data at 11:17:41 is reported as ‘11:18’

1: same data is reported as ‘11:17’

MaxItems

integer

100

Returns up to the specified number of data bars (if available). -1 means all available.

Days

integer

1
meaning today only

Number of preceding calendar days to process. -1 means unlimited (all available data, subject to the other criteria), 1 means today, 2 means today & yesterday, etc.

IntervalType

string

'secs'

Sets the type of interval size. One of the following values:

's' or 'secs' – time [seconds] (default)

'v' or 'volume' – traded volume

't', 'trades' or 'ticks' – number of ticks

IntervalSize

integer

60

Size of bars in IntervalType units. Must be ≥1 for secs, ≥2 for ticks, ≥100 for volume bars

BeginFilterTime

string

'00:00:00'

Only return bars that begin after this time of day (US Eastern time-zone). Only relevant when Days>0 or BeginDateTime is not ''.
Format: hhmm, hh:mm, hhmmss or hh:mm:ss

EndFilterTime

string

'23:59:59'

Only return bars that end before this time of day (US Eastern time-zone). Only relevant when Days>0 or BeginDateTime is not ''.
Format: hhmm, hh:mm, hhmmss or hh:mm:ss

BeginDateTime

integer or string or datetime object

''
(empty string) meaning from as early as data is available

Only return bars that begin after this date/time (US Eastern time-zone).
Only relevant when Days<0.
Format: Matlab datenum, ‘yyyymmdd hhmmss’ or ‘yyyy-mm-dd hh:mm:ss’.

Note: MaxItems has precedence over BeginDateTime: If there are more data points than MaxItems between Begin/ EndDateTime, only the last MaxItems data points (from EndDateTime backward) are returned, regardless of BeginDateTime.

EndDateTime

integer or string or datetime object

''
(empty string) meaning now

Only return bars that end before this date/time (US Eastern time-zone)
Only relevant when Days<0.
Format: Matlab datenum, ‘yyyymmdd hhmmss’ or ‘yyyy-mm-dd hh:mm:ss’.

Timeout

number

5.0

Max number of seconds to wait for incoming data (0-9000, where 0 means infinite)

UseParallel

logical (true/false)

false

If true or 1, and Parallel Computing Toolbox is installed, then querying multiple symbols or a date/time range will be done in parallel (see §3.6; Professional IQML license only).

5.5 Tick data

Unlike data bars, which aggregate ticks and provide summary information, it is also possible to retrieve historic individual trades (“ticks”). To retrieve this data, set DataType to 't' or 'ticks', and set the asset’s Symbol:

>> data = IQML('history', 'symbol','AAPL', 'dataType','ticks')
data =
100×1 struct array with fields:
Symbol
Timestamp
Datenum
Last
LastSize
TotalVolume
Bid
Ask
TickID
BasisForLast
TradeMarketCenter
TradeConditions
TradeAggressorCode
DayOfMonth
BasisDescription
TradeMarketName
TradeDescription
AggressorDescription

>> data(end)
ans =
Symbol: 'AAPL'
Timestamp: '2019-10-04 09:45:03.862626'
Datenum: 737702.406294699
Last: 224.67
LastSize: 100
TotalVolume: 5226196
Bid: 224.66
Ask: 224.68
TickID: 7432
BasisForLast: 'C'
TradeMarketCenter: 19
TradeConditions: '01'
TradeAggressorCode: 0
DayOfMonth: 4
BasisDescription: 'Last qualified trade'
TradeMarketName: 'Nasdaq Trade Reporting Facility (NTRF)'
TradeDescription: 'Normal Trade'
AggressorDescription: 'Unknown/unsupported'

The data struct here is quite different than the historical bar queries above. Notice the Timestamp field, specified in micro-second precision (US Eastern time-zone). See a discussion of the time resolution in the next page. The DayOfMonth, TradeAggressorCode and AggressorDescription fields only appear if you use IQFeed client 6.1 or newer.

Note that the textual Description fields depend on the MsgParsingLevel parameter having a value of 2 or higher (see §3.2 and §8)

Also note that only trade ticks are provided, along with the Bid and Ask prices at the time of the trade. IQFeed does not report historic non-trading ticks (i.e., Bid/Ask changes that occurred between the trades).

The Last and LastSize fields typically refer to the last trade. The type (“basis”) of data in these fields is determined according to the BasisForLast field, which is explained in the BasisDescription field for convenience.77 Possible basis values are:78

C – Last qualified trade.

E – Extended trade = form T trade.

O – Other trade = any trade not accounted for by C or E.

S – Settle = daily settle (only applicable to commodities).

In general, algo-trading should rely only on “C” trades, and potentially also “E” trades. “O” trades often have wide price swings (i.e. large variation from mainstream trading prices); this adds noise to charts and may confuse data analytics.79 IQFeed’s interval data (§5.4) typically exclude such irregular “O” trades.

Note that TickID values are not always increasing, and almost never contiguous. They are generally provided by the exchange as unique trade identifiers and so should not be used as an indicator of missing data, and their order is not quarantined. Instead, it is better to rely on the Timestamp or Datenum fields.

In some cases, implied (rather than normal trade) ticks are reported. For example, the following tick was retrieved for the VIX index continuous future (@VX#):

>> data = IQML('history', 'symbol','@VX#', 'dataType','ticks');
>> data(1)
ans =
Symbol: '@VX#'
Timestamp: '2019-10-04 09:42:41.499000'
Datenum: 737702.404646979
Last: 18.68
LastSize: 1
TotalVolume: 16711
Bid: 18.65
Ask: 18.7
TickID: 6118279
BasisForLast: 'O'
TradeMarketCenter: 32
TradeConditions: '4D'
TradeAggressorCode: 0
DayOfMonth: 4
BasisDescription: 'Other trade = any trade not accounted for by C or E'
TradeMarketName: 'CBOE Futures Exchange (CFE)'
TradeDescription: 'Implied'
AggressorDescription: 'Unknown/unsupported'

Note that in the case of @VX# on CBOE, the ticks are only reported in millisecond resolution, not microseconds as for IBM. In this case, Timestamp still shows 6 digits after the seconds decimal, but they always end in 000 (…:57.899000). The actual time resolution of reported ticks depends on the specific exchange and security type.80

You can limit the data that is returned, as with the historical-bars queries above:

By default, IQML only reports ticks data from today. You can ask to see additional (older) calendar days by specifying a positive Days parameter value. If you set Days to -1, then all available information will be reported, subject to the other filter criteria.

In addition, you can specify a daily time-window: only ticks between BeginFilterTime and EndFilterTime in each day (US Eastern time-zone) will be reported. This could be useful, for example, to limit the results only to the regular trading hours.

Similarly, you can specify a date/time window for all the data bars: only bars between the specified BeginDateTime and EndDateTime (both of them US Eastern time-zone) will be reported.

Note: queries having UseParallel=true are only parallelized if BeginDateTime is specified, or if multiple Symbols are specified (see below). Single-Symbol queries that have an empty (unspecified) BeginDateTime are not parallelizable.

You can also limit the maximal number of ticks using the MaxItems parameter.

Note: by default IQFeed limits ticks data to the past 180 calendar days if you make the request outside trading hours, but just past 8 days for requests during US trading hours (9:30-16:30 US Eastern time).81 This means that if during trading hours you request historic data from a month ago, you will get none (empty results), even if the request was just for a single hour of data.82

You can change the order of the reported ticks, using the DataDirection parameter (1 means oldest-to-newest (default); -1 means newest-to-oldest). MaxItems has precedence over BeginDateTime, regardless of DataDirection. For example, if MaxItems=5, we’ll only get the 5 latest ticks (before EndDateTime), regardless of BeginDateTime.

As with daily data requests, you can request historical data for multiple symbols at the same time, in a single IQML command, by specifying a colon-delimited or cell-array list of symbols. For example:

>> data = IQML('history', 'symbol',{'IBM','GOOG','AAPL'}, ...
'dataType','ticks', 'maxItems',20)

>> data = IQML('history', 'symbol','IBM:GOOG:AAPL', ...
'dataType','ticks', 'maxItems',20) %equivalent

The result will be an array of Matlab structs that correspond to the requested symbols (3 symbols with 20 data-points each, in this example):

data =
20×3 struct array with fields:
Symbol
Datestamp
...

In certain cases, when you request historic data for multiple symbols, you might receive a different number of data bars for different symbols, depending on data availability. In such cases, the result will not be an N-by-M struct array, but a cell array (one cell for each symbol) that contains struct arrays. For example:

data =
1×3 cell array
{77×1 struct} {100×1 struct} {55×1 struct}

IQML queries for multiple symbols or a date/time range (i.e., if BeginDateTime is specified) can be parallelized using the UseParallel parameter, if you have a Professional IQML license and Matlab’s Parallel Computing Toolbox (see §3.6):

>> data = IQML('history', 'dataType','ticks', 'UseParallel',true, ...
'symbol',symbols) % multiple symbols parallelized

>> data = IQML('history', 'dataType','ticks', 'UseParallel',true, ...
'symbol','IBM' ,... % single-symbol date-range parallelized
'BeginDateTime',20181026100000, ...
'EndDateTime', 20181026110000)

Finally, as with other IQML commands, you can set the Timeout parameter to a high value in order to allow IQML more time to gather data before returning the results.

The following parameters affect ticks history data queries:

Parameter

Data type

Default

Description

Symbol or Symbols 83

colon or comma-delimited string or cell-array of strings

(none)

Limits the query to the specified symbol(s). Examples:

'@VX#'

'IBM:AAPL:GOOG'

'IBM,AAPL,GOOG'

{'IBM', 'AAPL', 'GOOG'}

This parameter must be set to valid symbol name(s). Multiple symbols can be parallelized using the UseParallel parameter (see below).

DataDirection

integer

1
meaning oldest tick is first, newest last

Sets the order of ticks in the returned struct array. One of the following values:

1 means oldest-to-newest (default)

-1 means newest-to-oldest

MaxItems

integer

100

Returns up to the specified number of ticks (if available). -1 means all available.

Days

integer

1
meaning today only

Number of preceding calendar days to process. -1 means unlimited (all available data, subject to the other criteria), 1 means today, 2 means today & yesterday, etc.

BeginFilterTime

string

'00:00:00'

Only return ticks that begin after this time of day (US Eastern). Only relevant when Days>0 or BeginDateTime is not ''. Format: ‘hhmm’, ‘hh:mm’, ‘hhmmss’ or ‘hh:mm:ss’.

EndFilterTime

string

'23:59:59'

Only return ticks that end before this time of day (US Eastern). Only relevant when Days>0 or BeginDateTime is not ''. Format: ‘hhmm’, ‘hh:mm’, ‘hhmmss’ or ‘hh:mm:ss’.

BeginDateTime

integer or string or datetime object

''
(empty string) meaning from as early as data is available

Only return ticks that begin after this date/time (US Eastern time-zone).
Only relevant when Days<0.

Format: Matlab datenum, ‘yyyymmdd hhmmss’ or ‘yyyy-mm-dd hh:mm:ss’.

Note: MaxItems has precedence over BeginDateTime: If there are more data points than MaxItems between BeginDateTimeEndDateTime, only the last MaxItems data points (from EndDateTime backward) will be returned, regardless of BeginDateTime.

EndDateTime

integer or string or datetime object

''
(empty string) meaning now

Only return ticks that end before this date/time (US Eastern time-zone)
Only relevant when Days<0.

Format: Matlab datenum, ‘yyyymmdd hhmmss’ or ‘yyyy-mm-dd hh:mm:ss’.

Timeout

number

5.0

Max number of seconds to wait for incoming data (0-9000, where 0 means infinite)

UseParallel

logical (true/false)

false

If set to true or 1, and if Parallel Computing Toolbox is installed, then querying multiple symbols or a date/time range will be done in parallel (see §3.6; Professional IQML license only).

5.6 Market summary data and scanner

All the queries described so far in this chapter return historic data for individually-specified Symbols. We can retrieve historic end-of-day market state (quotes/trades and fundamental data) of all traded securities as-of a single historic date (May 20, 2018 or later), using a 'summary' query (see §4.6) with a non-default Date parameter:

>> data = IQML('summary', 'Date',20190110) %all NYSE equities on Jan 10, 2019
data =
4706×1 struct array with fields:
Symbol
Exchange
Type
Last
...
(total of 28 data fields)

>> data(1)
ans =
struct with fields:
Symbol: 'A'
Exchange: 7
Type: 1
Last: 69.9
TradeSize: 3350
TradedMarket: 7
TradeDate: 20190110
TradeTime: 180131
Open: 69.05
High: 69.95
Low: 68.6
Close: 69.25
Bid: 50
BidMarket: 11
BidSize: 400
Ask: 69.9
AskMarket: 11
AskSize: 100
Volume: 1080882
PDayVolume: 2442291
UpVolume: 413506
DownVolume: 231604
NeutralVolume: 435772
TradeCount: 10340
UpTrades: 3070
DownTrades: 2819
NeutralTrades: 4447
VWAP: 69.5782

This query shows that 4706 equities were traded on NYSE on Jan 10, 2019. The data may change over time, as DTN retroactively fixes its historic records.

The default DataType parameter value ('snapshot') fetches end-of-day trading data. To fetch end-of-day fundamental data, set DataType='fundamental':84

>> data = IQML('summary', 'Date',20190110, 'DataType','fundamental');

Note that there is no Symbol parameter in a 'summary' query – data for all the symbols that match the specified SecType (default: 'equity'), Exchange (default: 'NYSE') and/or Date (default: now/latest) is returned. For historic snapshot trading data of specific symbols, use one of the other query types (§5.1-§5.5). Unfortunately, there is no corresponding alternative for historic fundamental data of specific symbols.

We can filter the returned data for various criteria using the Filter parameter (see §4.6), effectively serving as a market scanner for the requested historic date.

Using end-of-day historic summary query enables fetching the data for expired contracts and delisted securities, which are no longer traded. Fetching historic data for such non-trading symbols using any other query type is not possible.85

Note: Market summaries are only available with IQFeed client 6.1 or newer, and only if you are subscribed to the requested data at DTN and there is a relevant history for download (data is only available since May 20, 2018, and only for some combinations of SecType/Exchange). In all other cases, you may receive an error such as one of these:

The 'summary' query is only supported by IQFeed client 6.1 or newer; you are using version 6.0.

IQML market summary query error: Code: 50004 - User not authorized for market summary file requested.

IQML market summary query error: Code: 50007 - No file available.

The following parameters affect historic market summary queries (see §4.6 for details):

Parameter

Data type

Default

Description

DataType

string

'snapshot'

Either 'snapshot' or 'fundamental' (not 'top')

Exchange

string

'NYSE'

One of the markets listed in §8.3

SecType

string

'Equity'

One of the security types listed in §8.4

Date

integer or string or datetime object

now

(latest available data)

Date for which to fetch the end-of-day data. Examples:

737089 (Matlab datenum format)

datetime('Jan 29, 2018')

20180129 (yyyymmdd format)

'20180129'

'2018/01/29'

'2018-01-29'

ReportEmptyFields

logical

false or 0

If true, then irrelevant data fields (which contain empty [] values for all securities) are reported; if false (default), they are not

Filter

string or cell-array of strings

{}

Zero or more filter criteria (condition strings) – Matlab expression(s) involving the reported data fields, which result in a logical (true/false) value. Examples:

'MaturityDate > 20241231'

'MarketCap > 5000 & PeRatio < 9'

{'MarketCap > 5000', 'Beta >= 1.2'}

Timeout

number

300

Max number of seconds to wait for incoming data (0-9000, where 0 means infinite)

warningNote: market summary functionality is only available in the Professional IQML license


59 http://iqfeed.net/dev/api/docs/HistoricalviaTCPIP.cfm

60 For example, IQFeed’s trial account is limited to 1-year of daily data points; IQFeed automatically trims trial-account queries down to this limit: http://forums.dtn.com/index.cfm?page=topic&topicID=5535

61 Note: Regular IQFeed accounts have access to 15+ years of daily data, but IQFeed limits its trial account to just 365 days of historical daily data – see https://help.dtniq.com/support-faqs

62 In IQML, the Symbol and Symbols parameters are synonymous – you can use either of them, in any capitalization

63 Note: Regular IQFeed accounts can access 15+ years of historic data, but IQFeed limits trial accounts to just one year – see https://help.dtniq.com/support-faqs. Also note that in some cases, depending on current day-of-week compared to the requested BeginDate, an addidional (older) bar might be returned that includes the week that was prior to the requested BeginDate.

64 Yesterday if using IQFeed client 6.0 or earlier; today if using IQFeed client 6.1 or newer

65 In IQML, the Symbol and Symbols parameters are synonymous – you can use either of them, in any capitalization

66 Yesterday if using IQFeed client 6.0 or earlier; today if using IQFeed client 6.1 or newer

67 Yesterday if using IQFeed client 6.0 or earlier; today if using IQFeed client 6.1 or newer

68 Note: Regular IQFeed accounts can access 15+ years of historic data, but IQFeed limits trial accounts to just one year – see https://help.dtniq.com/support-faqs

69 In IQML, the Symbol and Symbols parameters are synonymous – you can use either of them, in any capitalization

70 Yesterday if using IQFeed client 6.0 or earlier; today if using IQFeed client 6.1 or newer

71 Note that IQFeed’s limitations on live 'secs' interval bars (§4.3, §6.3) are stricter than the limitations on historical interval bars: http://forums.dtn.com/index.cfm?page=topic&topicID=5529

72 The above is true for IQFeed regular accounts; IQFeed trial accounts are limited to only 4 days of intraday data and just one year of daily data (see https://help.dtniq.com/support-faqs)

73 Specifically for minute (60 sec) intervals, IQFeed’s developer FAQ indicates that “Minute interval data dating back to mid 2005 for select contracts and mid 2007 for all others [is available]”.

74 Again, these values are for regular IQFeed accounts; IQFeed limits trial accounts (see note #72 above)

75 http://forums.dtn.com/index.cfm?page=topic&topicID=5608

76 In IQML, the Symbol and Symbols parameters are synonymous – you can use either of them, in any capitalization

77 Note that the textual Description fields depend on the MsgParsingLevel parameter having a value of 2 or higher (see §3.2)

78 Additional basis codes may be added by IQFeed in the future.

79 http://forums.iqfeed.net/index.cfm?page=topic&topicID=3898

80 Micro-second resolution is only available with IQFeed client 5.2 or newer, and only in certain setups (e.g. CMEGroup and equity markets). Contact IQFeed support if you are unsure about the resolution provided by a certain setup configuration.

81 Historic ticks older than 180 days can be purchased from DTN http://forums.iqfeed.net/index.cfm?page=topic&topicID=4376

82 The above is true for IQFeed regular accounts; IQFeed trial accounts are limited to only 4 days of intraday data (see https://help.dtniq.com/support-faqs)

83 In IQML, the Symbol and Symbols parameters are synonymous – you can use either of them, in any capitalization

84 Note that we only receive 4705 securities in the fundamental query compared to 4706 securities for the snapshot query (ASXw has snapshot data but no fundamentals) this is a data error. With NYSE bonds on the same date we see a similar phenomemon: three symbols (CVS.24.CB, DUK.46B.CB, TXT27.CB) have snapshot data but no fundamentals. All of these are data errors.

85 A [huge] static text file containing a [very long] list of expired symbols is available for download from DTN’s FTP site (ftp://www.dtniq.com/beta/IEOPTION.zip; see http://forums.iqfeed.net/index.cfm?page=topic&topicID=3326 for details). Note that this file is not actively maintained, so it is better to use the API functionality via IQML.