How to use AmiBroker with Interactive Brokers TWS

Note: the most recent version of this document can be found at: http://www.amibroker.com/ib.html . Please check this page for updates.

IB PLUGIN FEATURES SUMMARY:

INSTRUCTIONS:

NOTE: Interactive Brokers TWS is CPU-hungry application, therefore for best results we recommend using machine with 1GHz processor or faster.

NOTE 2: There is a VIDEO tutorial showing how to set it up at http://www.amibroker.com/video/ib.html


To use Interactive Brokers data plugin with AmiBroker you need to:

  1. run web-based TWS or download standalone TWS

  2. In TWS, select Configure -> API -> Enable Active X and Socket clients
    Also enter 127.0.0.1 in TWS, Configure->API->Trusted IP addresses menu to prevent "Allow incoming connection?" dialog.

  3. Run AmiBroker and create new database with Interactive Brokers plugin as a data source, following these steps:

From now on your AmiBroker reads quotes directly from the Interactive Brokers.




HOW TO USE BACKFILL FEATURE

Backfill feature in plugin 1.3.7 allows to download 24 intraday historical data to fill-in the gaps that may have occurred when AmiBroker / TWS is not running.

IB Backfill feature is configurable from File->Database Settings, Configure :

Two main backfill-related settings are:

1. request length
2. automatic backfill

When request length is considered, as explained in TWS API Release Notes at: http://www.interactivebrokers.com/en/software/apiReleaseNotes/apiBetanotes.php currently IB backfill feature is limited to some fixed duration / bar interval ranges. For example you can get maximum 2000 1-second ticks, maximum 10000 seconds in 5-second interval (2000 bars), maximum 30000 seconds in 15-second interval (also 2000 bars) and maximum of 5 DAYS of 1-minute bars.

By default AmiBroker uses maximum allowable amounts.

As for "automatic backfill on first data access" - when it is checked AmiBroker attempts to backfill symbol when you display a chart for given symbol (or perform backtest or scan). Please note that TWS API currently allows only one backfill at a time so when there is a backfill already running in the background, automatic backfill request for next symbol will be ignored, until previous backfill is complete.

It is convenient to have this option turned on, however it can cause additional load on your internet connection because of data needed to be downloaded during backfill process.

If you switch "automatic backfill on first data access" option off, you will still be able to backfill data for current symbol or all symbols in real-time quote window list usign appropriate menu options from plugin status menu.

Backfill Current option allows to force backfill of currently selected symbol, while Backfill All RT quote window symbols allow to force backfill of all symbols listed in Real-Time Quote window. Backfill of multiple symbols is performed sequentially (one at a time) due to limitations of TWS.

Backfill length submenu allows to select desired backfill length.

During backfilling a tooltip pops up informing the user about symbol being currently backfilled and plugin status color changes to light blue (turquoise) as shown below:


BACKFILLING ALL SYMBOLS AT ONCE

To backfill all symbols at once do the following:

1. Open Realtime Quote window ( by selecting Window->Realtime Quote menu )

2. Right click on the Realtime Quote window and choose Add symbol / Add watch list / Type-in symbol to add any symbols you want to backfill.

3. Right-click on the plugin Status indicator and select desired Backfill length

4. Choose Backfill All RT quote window symbols option from the same menu.

Since Interactive Brokers severely limits number of backfills that customer may request within given time it is advised to use backfill length as short as possible, like 1-day or 5-day and avoid long ranges like 30-days.


SYMBOLOGY

Symbol format now uses the symbol mode of TWS, not the underlying mode. The symbol mode in TWS can be seen in the 'View->Symbol Mode' menu option in TWS.

The format is: SYMBOL-EXCHANGE-TYPE

where

SYMBOL is the same as the symbol column as displayed in TWS while under symbol mode

EXCHANGE (optional) is the exchange d in TWS while under symbol mode

TYPE (optional) is one the following:

STK - stocks, FUT - futures, FOP - options on futures, OPT - options, IND - indexes, CASH -cash (ideal FX)
Note that for stocks only the EXCHANGE and TYPE fields are optional. The exchange will be set to BEST (SMART) and the TYPE will be set to STK.

Please take special care when typing symbols as some of them (futures) have MULTIPLE SPACES in the symbol name. You have to type EXACTLY THE SAME number of spaces as provided in the examples below
(see the dashes below symbol name that make it easier to see the number of characters)

Examples:

IB SYMBOL Type Description
CSCO
Stock Cisco Corporation, Nasdaq
GE
Stock General Electric, NYSE
VOD-LSE
Stock VODAFONE GROUP, London Stock Exchange
ESM4-GLOBEX-FUT

Future

Emini ES Jun04 futures, Globex
QQQFJ-CBOE-OPT
Option Jun 04, 36.0 CALL option QQQFJ
INDU-NYSE-IND
Index Dow Jones Industrials Index
YM   JUN 04-ECBOT-FUT
  ---   -  
Future YM Jun 04 future, ECBOT
(note 3 spaces between symbol and month and 1 space between month and year)
QMN5-NYMEX-FUT
Future QM (Crude) June 2005 future contract, NYMEX
XAUUSD-SMART-CMDTY
Commodity London Gold Spot
IBUS500-SMART-CFD-USD
         
CFD (contract for difference) IB US500 contract for difference
EUR.USD-IDEAL-CASH
EUR.USD-IDEALPRO-CASH
Cash Forex EURUSD currency pair, IDEAL
EURUSD currency pair, IDEALPRO

Again:

ECBOT futures symbols have length of 21 characters with 3 spaces between contract symbol and month name and one space between month and 2 digit year

Contract 3 spaces Month spa
ce
Year - E C B O T - F U T
Z B       J U N   0 4 - E C B O T - F U T
Z F       J U N   0 4 - E C B O T - F U T
Z N       J U N   0 4 - E C B O T - F U T
Y M       J U N   0 4 - E C B O T - F U T

NOTES ON IB API LIMITATIONS:

1. Backfill is available for REAL IB accounts only (not on demo)

2. Open price is NOT provided by IB. For that reason Open field is empty in real time quote window

3. The data from IB does not include a timestamp on the trades. The current system time is used to timestamp each tick.

4. IB TWS streaming data are NOT tick-by-tick, but rather 0.2-0.3 second snapshots, read this for details: http://www.interactivebrokers.com/cgi-bin/discus/board-auth.pl?file=/2/37364.html