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.

contractdetails

Request Interactive Brokers contract details

Syntax

[d,reqid] = contractdetails(ib,ibContract)
[d,reqid] = contractdetails(ib,ibContract,eventhandler)

Description

example

[d,reqid] = contractdetails(ib,ibContract) requests Interactive Brokers® contract details using IB Trader WorkstationSM connection ib and IB Trader Workstation IContract object ibContract.

example

[d,reqid] = contractdetails(ib,ibContract,eventhandler) requests Interactive Brokers contract details using an event handler function eventhandler. Use the sample event handler ibExampleEventHandler or write a custom event handler function.

Examples

collapse all

Create the IB Trader Workstation℠ connection ib on the local machine using port number 7496.

ib = ibtws('',7496);

Create the IB Trader Workstation℠ IContract object ibContract. This object describes a security with these property values:

  • Google® symbol

  • Stock security type

  • Aggregate exchange

  • Primary exchange

  • USD currency

IEX is a sample primary exchange name. Substitute your primary exchange name for ibContract.primaryExchange.

ibContract = ib.Handle.createContract;
ibContract.symbol = 'GOOG';
ibContract.secType = 'STK';
ibContract.exchange = 'SMART';
ibContract.primaryExchange = 'IEX';
ibContract.currency = 'USD';

For details about the IContract object, see the Interactive Brokers® API Reference Guide.

Request contract details data using ib and ibContract.

[d,reqid] = contractdetails(ib,ibContract);

d is a structure containing the contract details data. For details about this data, see the Interactive Brokers® API Reference Guide.

reqid is a number that Interactive Brokers® uses to track this contract details data request.

Display the market name from the contract details data.

d.marketName
ans =

  1×3 char array

NMS

Display the request identifier.

reqid
reqid =

        8147

Close the IB Trader Workstation℠ connection.

close(ib)

Create the IB Trader Workstation connection ib on the local machine using port number 7496.

 ib = ibtws('',7496); 

Create the IB Trader Workstation IContract object ibContract. Here, this object describes a security with these property values:

  • Google® symbol

  • Stock security type

  • Aggregate exchange

  • Primary exchange

  • USD currency

EX is a sample primary exchange name. Substitute your primary exchange name in ibContract.primaryExchange.

ibContract = ib.Handle.createContract; 
ibContract.symbol = 'GOOG'; 
ibContract.secType = 'STK';
ibContract.exchange = 'SMART';
ibContract.primaryExchange = 'EX';
ibContract.currency = 'USD';

For details about the IContract object, see Interactive Brokers API Reference Guide.

Request contract details data using ib, ibContract, and sample event handler function ibExampleEventHandler. Use ibExampleEventHandler or write a custom event handler function.

[d,reqid] = contractdetails(ib,ibContract,@ibExampleEventHandler)
d =

        1269

reqid =

        1269

  Columns 1 through 4

    [1x1 COM.TWS_TwsCtrl_1]    [100]    [1269]    [1x1 Interface.Tws_ActiveX_Control_module.IContractDetails]

  Columns 5 through 6

    [1x1 struct]    'contractDetailsEx'

d and reqid return a number that Interactive Brokers uses to track this contract details data request.

After these variables, ibExampleEventHandler returns contract details data to the Command Window. The columns are:

  • Interactive Brokers ActiveX® object

  • Event identifier

  • Request identifier

  • Contract details ActiveX object

  • Structure that repeats the contents of the columns

  • Request type

For details about this data, see Interactive Brokers API Reference Guide.

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 contract details data, returned as a structure. When using an event handler function, d is a numeric scalar that denotes the contract detail data request identifier.

Contract detail data request identifier, returned as a numeric scalar. Interactive Brokers uses this number to match responses to the correct data request when multiple data requests are present.

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 R2015a

Was this topic helpful?