Display TWS contract details in Matlab

The Trading Toolbox function to display Interactive Brokers TWS contract details in Matlab is called contractdetails and has the following syntax:

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

Again, please be aware that for this function Trading Toolbox 2.2 or above is requested. Below I will show you an example where I will retrieve the contract details for a random US stock*.

After having linked Matlab to IB TWS, we must connect the two stations between them by running the following command:

ib = ibtws('',7496);

Once connected, the next step is to define the IB contract which details we would like to request. We will build the contract by using the minimum required information which is the contract symbol, security type, currency and routing destination.

ibContract = ib.Handle.createContract;
ibContract.symbol = 'AAPL';
ibContract.secType = 'STK';
ibContract.exchange = 'SMART';
ibContract.currency = 'USD';

Then run the script below which will export the contract details (d) and the request identifier reqid for the ibContract using the Interactive Brokers TWS (ib) connection.

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

The output in your Matlab work-space will be then the following:

Contract Details IBTWS - Matlab CMD Window

Contract Details IBTWS - Matlab struct
* The tickers shown in examples are random, for exercising purposes only and do not represent any advise to invest in them nor any other kind of advertising.

Laisser un commentaire