IB / TWS Bridge

Interactive Brokers™ main advantages are access to many exchanges, a huge number of supported assets, and relatively low trading costs. The IB bridge allows direct trading with IB, either through IB's Trader Workstation (TWS), or with the IB Gateway. For long-term automated trading the IB Gateway is preferable, since the TWS, a bloated java program, normally stops every 24 hours and interrupts the connection.

For trading with Gateway, select IB API (not FIX CTCI). Open Configuration/API/Settings and make sure that the socket port is set to 4002. Enter an individual number from 1..8 in Zorro's User field for connecting to the Gateway via socket port 4002. The Password field can be left empty.

For trading with the TWS, open File/Global Configuration/API/Settings (see screenshot below) and select Enable ActiveX and Socket Clients. Make sure that the socket port is set to 7496. Deselect Read-Only API when you want to send orders. Enter an individual number from 101..108 in Zorro's User field for connecting to the TWS via socket port 7496. The Password field can be left empty.

Up to 8 Zorros can connect to the same Gateway or to the same TWS, but only a single TWS or a single Gateway per user is supported by IB. The connection will break down when a second Gateway or TWS instance is opened, even on a different PC.

Zorro login fields for IB:

User: 1 .. 8 for the Gateway, 101 .. 108 for the TWS
Password: Empty

Accounts.csv example entries:

Name Broker Account User Pass Assets CCY Real NFA Plugin
IB-TWS-Demo IB 0 101 0 AssetsIB USD 0 14 IB
IB-TWS-Real IB U1234567 101 0 AssetsIB USD 1 14 IB
IB-Gateway IB U1234567 1 0 AssetsIB USD 1 14 IB

Trading with IB

The included plugin supports IB paper trading accounts that begin with the letter "D". A plugin for all accounts is included in Zorro S or available for subscription on the Zorro download page. For opening an account with IB, the normal choice is a RegT Margin account. After opening the account, make sure to withdraw enough from your initial deposit as to not exceed the account size limit of the free Zorro version. If you own Zorro S, consider a Portfolio Margin account with its lower margin costs. IB paper trading accounts are only available after opening a real account.

Due to the high margin and lot size requirements, most Z systems are not really suited for IB, as they would require a large Margin setting for not skipping too many trades, and even then achieve only a fraction of the annual return due to the low leverage. Only exception is Z8 that is especially tailored for IB. The main advantage of IB is that most public financial assets can be traded. This allows many new trade systems that exploit specific inefficiencies, f.i. volatility, or seasonal effects of particular stocks or treasuries.

Historical price data for backtests can not be downloaded from IB, but they are available from many other Internet sources, f.i. from Yahoo™ or Quandl™ by using the Download script or the assetHistory or dataDownload function.

For trading an asset, some prerequisites must be fulfilled:

Trade Permissions

Not all assets can be traded all the time. Index (IND) assets are read only, but you can trade index ETFs, Futures, or CFDs. Some assets, such as specific CFDs, might be not available to US citizens, and require an UK or other account outside the US. The default minimum sizes for currency pairs are in the 20,000 contracts range, but entering a lower minimum size in the asset list is also possible. Orders are then marked as 'odd lot' and cause higher transaction costs. Some stocks (STK) and some other assets can be not shortable temporarily (dependent on market liquidity) or permanently. Short trades for closing a long position are normally accepted.

For setting up the IB asset list and for simulating IB trading in the backtest, margin requirements can be found on https://www.interactivebrokers.com/en/index.php?f=24176. The maintenance or end-of-day margin is often higher than the initial margin.

IB symbols

Any asset you want to trade must be represented by a line in the asset list. Asset symbols (Symbol column) are converted to IB symbols in the following way:

A example file AssetsIB.csv with currencies, CFDs, and stocks is included; we do however not guarantee the accuracy and correctness, so use it at your own risk.

Additional data and commands

The IB bridge supports the following additional data streams:

Multiple IB accounts are supported from Zorro 1.84 on. The account can be set up in the account list.

The IB bridge supports the brokerCommand function with the following additional commands (extra commands can be implemented on user request):

Known IB API issues

See also:

Brokers, Broker plugin, MT4 bridge

► latest version online