Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

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
  • d = timeseries(ib,ibContract,startdate,enddate,barsize,ticktype,tradehours)
    example
  • d = timeseries(ib,ibContract,startdate,enddate,barsize,ticktype,tradehours,eventhandler)
    example

Description

example

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

example

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

example

d = timeseries(ib,ibContract,startdate,enddate,barsize,ticktype,tradehours) requests Interactive Brokers aggregated intraday data using the flag tradehours to include all data or only data within regular trading hours.

example

d = timeseries(ib,ibContract,startdate,enddate,barsize,ticktype,tradehours,eventhandler) requests Interactive Brokers aggregated intraday data using an event handler function eventhandler. Use the sample event handler ibExampleEventHandler or write a custom event handler function.

Examples

collapse all

To request intraday data, set up the IB Trader Workstation connection ib using ibtws. Create an IB Trader Workstation IContract object ibContract as shown in Request Interactive Brokers Real-Time Data. An IContract object is an Interactive Brokers object for containing the data about a security to process transactions. For details about creating this object, see Interactive Brokers API Reference Guide.

Request intraday data aggregated every 5 minutes using ib and 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:

  • Numeric representation of a date

  • Open price

  • High price

  • Low price

  • Close price

  • Volume

  • Bar count

  • Weighted average price

  • Flag indicating if there are gaps in the bar

Display the open price for the most recent bar in matrix d.

d(1,2)
ans =
    6.91

Close the IB Trader Workstation connection.

 close(ib) 

To request intraday data, set up the IB Trader Workstation connection ib using ibtws. Create an IB Trader Workstation IContract object ibContract as shown in Request Interactive Brokers Real-Time Data. An IContract object is an Interactive Brokers object for containing the data about a security to process transactions. For details about creating this object, see Interactive Brokers API Reference Guide.

Request intraday data aggregated every 10 minutes using ib, 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:

  • Numeric representation of a date

  • Open price

  • High price

  • Low price

  • Close price

  • Volume

  • Bar count

  • Weighted average price

  • Flag indicating if there are gaps in the bar

Display the high price for the most recent bar in matrix d.

d(1,3)
ans =
    6.38

Close the IB Trader Workstation connection.

 close(ib)

To request intraday data, set up the IB Trader Workstation connection ib using ibtws. Create an IB Trader Workstation IContract object ibContract as shown in Request Interactive Brokers Real-Time Data. An IContract object is an Interactive Brokers object for containing the data about a security to process transactions. For details about creating this object, see Interactive Brokers API Reference Guide.

Request intraday data using ib, ibContract, and these arguments:

  • Start date is this morning.

  • End date is the current moment.

  • Aggregated every 10 minutes.

  • Tick type is 'BID'.

  • Within regular trading hours.

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

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

  Columns 1 through 5

     735852.40        580.70        582.12        580.12        580.27
     735852.40        580.27        580.75        579.70        579.80
     735852.40        579.80        579.88        578.33        579.44
     ...
  
  Columns 6 through 9

         -1.00         -1.00         -1.00             0
         -1.00         -1.00         -1.00             0
         -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:

  • Numeric representation of a date

  • Open price

  • High price

  • Low price

  • Close price

  • Volume

  • Bar count

  • Weighted average price

  • Flag indicating if there are gaps in the bar

Display the high price for the most recent bar in matrix d.

d(1,3)
ans =
    582.12

Close the IB Trader Workstation connection.

 close(ib)

To request intraday data, set up the IB Trader Workstation connection ib using ibtws. Create an IB Trader Workstation IContract object ibContract as shown in Request Interactive Brokers Real-Time Data. An IContract object is an Interactive Brokers object for containing the data about a security to process transactions. For details about creating this object, see Interactive Brokers API Reference Guide.

Request intraday data using ib, ibContract, and these arguments:

  • Start date is this morning.

  • End date is the current moment.

  • Aggregated every 10 minutes.

  • Tick type is 'BID'.

  • Within regular trading hours.

  • Sample event handler function ibExampleEventHandler.

Use ibExampleEventHandler or write a custom event handler function.

startdate = floor(now);
enddate = now;
barsize = '10 mins';
ticktype = 'BID';
tradehours = true;
eventhandler = 'ibExampleEventHandler';

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

       4853.00

  Columns 1 through 3

    [1x1 COM.TWS_TwsCtrl_1]    [22.00]    [4853.00]

  Columns 4 through 7

    '20140909  15:55:00'    [580.20]    [581.40]    [580.09]

  Columns 8 through 13

    [581.01]    [-1.00]    [-1.00]    [-1.00]    [0]    [1x1 struct]

  Column 14

    'historicalData'
...

d is the request identifier.

After d, ibExampleEventHandler streams intraday data to the Command Window. The columns are:

  • Interactive Brokers ActiveX® object

  • Event identifier

  • Request identifier

  • Date

  • Open price

  • High price

  • Low price

  • Close price

  • Volume

  • Bar count

  • Weighted average price

  • Flag indicating if there are gaps in the bar

  • Structure that repeats the contents of the columns

  • Event type

Close the IB Trader Workstation connection.

 close(ib)

Related Examples

Input Arguments

collapse all

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

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

Start date, specified as a starting date character vector or scalar.

Data Types: double | char

End date, specified as an ending date character vector or scalar.

Data Types: double | char

Tick aggregation interval, specified as one of the following values predetermined by the Interactive Brokers API that denotes 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'

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

Trading hours, specified as the logical true or false. When this flag is set to true, this function returns data only within regular trading hours. Otherwise, this function returns all data.

Data Types: logical

Event handler, specified as a function handle or a character vector to identify an event handler function that processes the returned data. Use the sample event handler or write a custom event handler function. For details, see Writing and Running Custom Event Handler Functions with Interactive Brokers.

Example: @eventhandler

Data Types: function_handle | char

Output Arguments

collapse all

Interactive Brokers aggregated intraday data, returned as a matrix with these columns:

  • Numeric representation of a date

  • Open price

  • High price

  • Low price

  • Close price

  • Volume

  • Bar count

  • Weighted average price

  • Flag indicating if there are gaps in the bar

When using an event handler function, d is a double denoting the request identifier.

More About

collapse all

Tips

  • ibBuiltInErrMsg appears in the MATLAB® workspace. Check the status of connection and function execution by displaying the contents of this variable. ibBuiltInErrMsg contains messages related to:

    • Connection

    • Information resulting from executing functions

    • Errors

Introduced in R2013b

Was this topic helpful?