IB Bridge / TWS Bridge

The Interactive Brokers™ bridge allows direct trading with IB, either through IB's Trader Workstation (TWS), or with the IB Gateway. IB's main advantages are access to many exchanges, a huge number of supported assets, and relatively low trading costs. On the downside, their API is functionally limited in some ways.

For long-term automated trading the IB Gateway is preferable, since the TWS, a bloated java program, breaks down once per day and interrupts the connection. After starting the Gateway, select IB API (not FIX CTCI). Open Configuration/API/Settings and make sure that the socket port is set to 4002.

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. Up to 8 Zorros can connect to the same Gateway or to the same TWS. Enter an individual number in Zorro's User field. Numbers 1..8 connect to the Gateway via socket port 4002, numbers 101..108 connect to the TWS via socket port 7496. The Password field can be left empty.

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. Be aware that you have to pay interest for CFDs, so they are no equivalent to ETFs. Some assets, such as CFDs and gold/silver commodities, are not available to US citizens. For getting permission to trade them you have to open 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.

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.

Extra data

The IB bridge supports the following additional data streams:

Extra broker commands

The IB plugin supports the brokerCommand function with the following additional commands:

More broker commands, f.i. for market depth data or news messages, can be implemented on user request.

Known IB API issues

In comparison to other broker APIs, the IB API has several limitations that must be worked around in the script, and can make an IB trading script a bit more complicated:

On the other hand, the IB API offers many interesting features that are not available in Forex broker APIs, such as volume data, market depth data, options and futures trading, and news messages. Especially market depth is of interest for HFT strategies since it gives insight in short-term trends. If you need additional features for your automated trading strategy, please contact us. But be aware that those additional data are mostly unavailable in historical data and thus can not be easily used for simulations and backtests.

See also:

Brokers, Broker plugin, MT4 bridge

► latest version online