Documentation

This is machine translation

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

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

getdata

Request current Interactive Brokers data

Syntax

d = getdata(ib,ibContract)
d = getdata(ib,ibContract,eventhandler)

Description

example

d = getdata(ib,ibContract) requests Interactive Brokers® current data over the IB Trader WorkstationSM connection ib using the IB Trader Workstation IContract object ibContract to signify the instrument.

example

d = getdata(ib,ibContract,eventhandler) requests Interactive Brokers current 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 Interactive Brokers current 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 current data using ib and ibContract.

d = getdata(ib,ibContract)
d = 

    LAST_PRICE: 6.85
     LAST_SIZE: 1.00
        VOLUME: 187.00
     BID_PRICE: 6.84
      BID_SIZE: 14.00
     ASK_PRICE: 6.86
      ASK_SIZE: 13.00

d contains these fields:

  • Last price

  • Last size

  • Volume

  • Bid price

  • Bid size

  • Ask price

  • Ask size

Display the data in the BID_PRICE field of d.

d.BID_PRICE
ans =
    6.84

Close the IB Trader Workstation connection.

 close(ib) 

To request Interactive Brokers current 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 current data using ib, ibContract, and sample event handler function ibExampleEventHandler. Use ibExampleEventHandler or write a custom event handler function.

d = getdata(ib,ibContract,@ibExampleEventHandler)
d =

       1418.00

  Columns 1 through 5

    [1x1 COM.TWS_TwsCtrl_1]    [2.00]    [1418.00]    [0]    [5.00]

  Columns 6 through 7

    [1x1 struct]    'tickSize'
  ...

d is the request identifier.

After d, ibExampleEventHandler streams current data to the Command Window. Each column set is a type of tick.

For a size tick, the columns are:

  • Interactive Brokers ActiveX® object

  • Event identifier

  • Request identifier

  • Tick type

  • Size

  • Structure that repeats the contents of the columns

  • Event type

Close the IB Trader Workstation connection.

 close(ib) 

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.

Event handler, specified as a function handle, character vector, or string scalar 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 | string

Output Arguments

collapse all

Interactive Brokers current data, returned as a structure containing these tick types:

  • Last price

  • Last size

  • Volume

  • Bid price

  • Bid size

  • Ask price

  • Ask size

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

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?