timeseries

Request Interactive Brokers aggregated intraday data

Syntax

  • d = timeseries(ib,ibContract,startdate,enddate,barsize) example
  • d = timeseries(ib,ibContract,startdate,enddate,barsize,ticktype) example

Description

example

d = timeseries(ib,ibContract,startdate,enddate,barsize) requests Interactive Brokers® aggregated intraday data between startdate and enddate with tick aggregation interval barsize for default tick type 'TRADES' over the IB Trader WorkstationSM connection ib using IB Trader Workstation contract object ibContract to signify the instrument. timeseries returns the matrix d with Interactive Brokers aggregated intraday data.

example

d = timeseries(ib,ibContract,startdate,enddate,barsize,ticktype) requests Interactive Brokers aggregated intraday data for a specific type of market data tick ticktype.

Examples

expand all

Request Interactive Brokers Intraday Data Aggregated Every 5 Minutes with TRADES Default Tick Type

To request intraday data, set up a connection ib using ibtws and create an IB Trader Workstation IContract object ibContract as shown in Stream Interactive Brokers Data. An IContract object is an Interactive Brokers object for containing the necessary data about a security to process transactions. See the Interactive Brokers API Reference Guide to learn more about creating this object.

Request intraday data aggregated every 5 minutes using ibContract.

startdate = floor(now);
enddate = now;
barsize = '5 mins';

d = timeseries(ib,ibContract,startdate,enddate,barsize)
d =

     735329.40          6.91          6.91          6.85          6.85        158.00         13.00          6.87             0
     735329.40          6.85          6.87          6.85          6.87         29.00         24.00          6.86             0
     735329.40          6.87          6.89          6.87          6.87         13.00         13.00          6.88             0
...

d returns the aggregated 5-minute data with default tick type 'TRADES'.

Each row in matrix d represents a 5-minute interval. The columns in matrix d are a numeric representation of a date, open price, high price, low price, close price, volume, bar count, weighted average price, and flag indicating if there are gaps in the bar.

Display the open price in matrix d.

d(1,2)
ans =
    6.91

Close the IB Trader Workstation connection.

 close(ib) 

Request Interactive Brokers Intraday Data Aggregated Every 10 Minutes with a BID Tick Type

To request intraday data, set up a connection ib using ibtws and create an IB Trader Workstation IContract object ibContract as shown in Stream Interactive Brokers Data. An IContract object is an Interactive Brokers object for containing the necessary data about a security to process transactions. See Interactive Brokers API Reference Guide to learn more about creating this object.

Request intraday data aggregated every 10 minutes using ibContract and 'BID' tick type.

startdate = floor(now);
enddate = now;
barsize = '10 mins';
ticktype = 'BID';

d = timeseries(ib,ibContract,startdate,enddate,barsize,ticktype) 
d =

     735329.17          6.38          6.38          6.38          6.38         -1.00         -1.00         -1.00             0
     735329.17          6.38          6.38          6.38          6.38         -1.00         -1.00         -1.00             0
     735329.18          6.38          6.38          6.38          6.38         -1.00         -1.00         -1.00             0
...

d returns the aggregated 10-minute data for 'BID' tick type.

Each row in matrix d represents a 10-minute interval. The columns in matrix d are a numeric representation of a date, open price, high price, low price, close price, volume, bar count, weighted average price, and flag indicating if there are gaps in the bar.

Display the high price in matrix d.

d(1,3)
ans =
    6.38

Close the IB Trader Workstation connection.

 close(ib)

Input Arguments

expand all

ib — IB Trader Workstation connectionconnection object

IB Trader Workstation connection, specified as an IB Trader Workstation connection object created using ibtws.

ibContract — IB Trader Workstation contractIContract object

IB Trader Workstation contract, specified as an IB Trader Workstation IContract object. This object is the instrument or security used in the order transaction. This object is created by calling the Interactive Brokers API function createContract. To learn more about createContract and the attributes you can set, see Interactive Brokers API Reference Guide.

startdate — Start datedate string | date scalar

Start date, specified as a starting date string or scalar.

Data Types: double | char

enddate — End datedate string | date scalar

End date, specified as an ending date string or scalar.

Data Types: double | char

barsize — Tick aggregation interval'10 secs' | '15 secs' | '30 secs' | '1 min' | '2 mins' | '3 mins' | ...

Tick aggregation interval, specified as one of the following enumerated strings predetermined by the Interactive Brokers API that denote the size of aggregated bars for collecting data.

  • '10 secs'

  • '15 secs'

  • '30 secs'

  • '1 min'

  • '2 mins'

  • '3 mins'

  • '5 mins'

  • '10 mins'

  • '15 mins'

  • '20 mins'

  • '30 mins'

  • '1 hour'

  • '2 hours'

  • '3 hours'

  • '4 hours'

  • '8 hours'

ticktype — Types of market data ticks'TRADES' (default) | 'MIDPOINT' | 'BID' | 'ASK' | 'BID_ASK' | 'HISTORICAL_VOLATILITY' | 'OPTION_IMPLIED_VOLATILITY'

Types of market data ticks, specified as one of the above enumerated strings predetermined by the Interactive Brokers API that denote tick values to collect.

Output Arguments

expand all

d — Interactive Brokers aggregated intraday datamatrix

Interactive Brokers aggregated intraday data, returned as a matrix with nine columns: a numeric representation of a date, open price, high price, low price, close price, volume, bar count, weighted average price, and flag indicating if there are gaps in the bar.

Was this topic helpful?