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.

accounts

Retrieve Interactive Brokers account information

Syntax

d = accounts(ib,acctno)
d = accounts(ib,acctno,eventhandler)

Description

example

d = accounts(ib,acctno) retrieves account information using Interactive Brokers® connection ib and account number acctno.

example

d = accounts(ib,acctno,eventhandler) retrieves account information 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);

Retrieve account information for account number acctno using ib.

acctno = 'AB123456';

d = accounts(ib,acctno);

d is a structure with fields containing the account information.

Display the account code.

d.AccountCode
ans =

  1×7 char array

DU15066

For details about this data and the other fields, see the Interactive Brokers® API Reference Guide.

Close the IB Trader Workstation℠ connection.

close(ib)

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

 ib = ibtws('',7496); 

Retrieve account information for account number acctno using ib. Use the sample event handler ibExampleEventHandler to display the IB Trader Workstation account information in the Command Window. Use ibExampleEventHandler or write a custom event handler function.

acctno = 'AB123456';

d = accounts(ib,acctno,@ibExampleEventHandler)
d =

     []

  Columns 1 through 7

    [1x1 COM.TWS_TwsCtrl_1]    [7]    'AccountCode'    'AB123456'    ''    'AB123456'    [1x1 struct]

  Column 8

    'updateAccountValue'
  ...

d is an empty double.

The sample event handler ibExampleEventHandler displays the account information in the Command Window. The columns are:

  • Interactive Brokers ActiveX® object

  • Event identifier

  • Account code

  • Event key

  • Currency

  • Account name

  • 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.

Account number, specified as a character vector or string scalar that identifies the Interactive Brokers account number.

Data Types: char | string

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

Account information, returned as a structure containing fields with the Interactive Brokers account information. When using an event handler function, d is an empty double.

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?