close

Close IB Trader Workstation connection

Syntax

Description

example

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

Examples

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.

ib.Handle
ans =

	COM.TWS_TwsCtrl_1

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';
ibContract.exchange = '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.

d.BID_PRICE
ans =

  160.1900

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.

Introduced in R2013b