This is machine translation

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

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Close IB Trader Workstation connection





close(ib) closes the IB Trader WorkstationSM connection ib.


collapse all

Create an IB Trader Workstation℠ connection on the local machine, request current data for a security, and close the connection.

Connect to the IB Trader Workstation℠ using port number 7496.

ib = ibtws('',7496)
ib = 

  ibtws with properties:

    ClientId: 0
      Handle: [1×1 COM.TWS_TwsCtrl_1]
        Host: ''
        Port: 7496

MATLAB® returns ib as the IB Trader Workstation℠ connection with the Interactive Brokers® ActiveX® object, the local host, and the specified port number.

Display the Handle property of ib.

ans =


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

  • Security symbol

  • Stock security type

  • Aggregate exchange

  • Primary exchange

  • USD currency

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

Request current data using ibContract.

d = getdata(ib,ibContract)
d = 

  struct with fields:

     BID_PRICE: 160.1900
      BID_SIZE: 2
     ASK_PRICE: 160.2500
      ASK_SIZE: 2
    LAST_PRICE: 160.2200
     LAST_SIZE: 1
        VOLUME: 2877

d is a structure containing these fields:

  • BID_PRICE -- Bid price

  • BID_SIZE -- Bid size

  • ASK_PRICE -- Ask price

  • ASK_SIZE -- Ask size

  • LAST_PRICE -- Last price

  • LAST_SIZE -- Last size

  • VOLUME -- Volume

Display the data in the BID_PRICE field of d.

ans =


Close the IB Trader Workstation℠ connection.


Input Arguments

collapse all

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

Introduced in R2013b