Connecting to Interactive Brokers (IB) from Seer
Trading Platform Software for backtesting & auto trading, for stock, futures and forex trading systems › Forums › Tutorials › Connecting to Interactive Brokers (IB) from Seer
June 17, 2013 at 9:38 am #2900
Seer connects to your Interactive Brokers (IB) account via IB’s Traders Workstation (TWS) and TWS must be installed on your machine. To install TWS follow the instructions in the following link (you may need to install Java):
Once TWS is installed and running, it must be configured to except connections to from Seer. To do this follow the steps below:
Start TWS by click on it’s icon, then open the TWS API configuration options window (main menu->Configure->API->All API Settings):
Ensure that the Enable ActiveX and Socket Clients check box is ticked. This will allow Seer to connect to IB.
To connect to IB from within Seer, select the Interactive Brokers icon within the Brokers folder in the main tree view. Ensure that the socket port number is the same in both Seer and IB, then click on connect.
Connecting using the IB demo account
IB provides a demo account that can be used to learn TWS. It is also useful for testing connectivity between Seer and IB. The details are:
User Name: edemo
Using the demo account is useful in ensuring the mapping between Seer, IB and datafeed symbols are correct (see below).
Symbol mapping between IB symbols and datafeed symbols
All datafeeds and brokers use slightly different symbol mapping to uniquely identity a tradeable instrument on an exchange. A symbol within Seer is simply a human readable unique string (often the ticker or symbol identifier) which in turn is mapped to the underlying data feed symbol and IB’s symbol. When dealing with Forex or US stocks, Seer knows enough about the IB’s symbol rules to do the mapping automatically (assuming that you want to trade US stocks through SMART). In cases where an automatic mapping can’t be done, the mapping has to be done manually. Four fields within the datastore symbols window have the following meaning:
- Broker Symbol: The symbol that IB uses
- Broker Exchange: The exchange that the instrument trades on
- Broker Local Symbol: The expiry of the contract (if a future)
- Broker Currency: The ISO currency code that the instrument trades in.
Future mapping is a little more complicated as exchange, currency code and expiry all need to be set manually. For example, say you want to trade ES (S&P E-mini). Your Seer symbol would be mapped to @ES# (in the case of a DTN IQfeed) and it would have the following datastore symbol settings:
- Broker Symbol: ES
- Broker Exchange: GLOBEX
- Broker Local Symbol: 20110318
- Broker Currency: USD
The Broker Local Symbol is the expiry of the contract (format being YYYYMMDD).
The easiest way to ensure that you are mapping to the correct instrument is to enter an order in TWS for the instrument that you want to trade (use the demo account or paper trade account!). When the order is filled, Seer will then create a new instrument within the datastore with the correct mapping back to IB.
Supported IB Order Types
Seer supports the following basic IB order types:
- Market (Buy and Sell)
- Limit (Buy and Sell)
- Stop (Buy and Sell)
- StopLimit (Buy and Sell)
All order types can be manually entered via Overseer GUI or via the web interface. Orders placed from within Seer (via the Place Order functions) are automatically mapped to the correct order type. All orders (manual and scripted) are submitted as Day orders (will stay active until the end of the trading session. Orders (such as limit orders) can be changed manually via the Overseer GUI or via a script. Orders can be cancelled via the Overseer GUI, web interface and via a script.
Each order submitted to IB can have options specified (such as an explicit OCA group or time in force). See the PlaceOrder function for more details on this option.
IB Order Status Descriptions
At any specific point in time an order will have a specific status. Any change to an orders status (or any other aspect of the order) is recorded within the Order History object under the Interactive broker icon within the main tree view. As an order flows from Seer to IB, then to an exchange it’s status can and will change. The status of an order is shown with the Overseer GUI, the web interface and is also available within the scripting environment. Once an order has been Filled or Cancelled it will disappear from the GUI displays after 60 seconds. The following is a list of possible order statuses:
Pending Connection – indicates that you have transmitted the order, but have not yet received confirmation that it has been accepted by the order destination. For an active order that has been cancelled you may still receive an execution while your cancellation request is pending.
PreSubmitted – indicates that a simulated order type has been accepted by the system and that this order has yet to be elected. The order is held in the system until the election criteria are met. At that time the order is transmitted to the order destination as specified.
Submitted – indicates that your order has been accepted at the order destination and is working.
Cancelled – indicates that the balance of your order has been confirmed canceled by the system. This could occur unexpectedly when the destination has rejected your order.
Filled – indicates that the order has been completely filled.
PartFilled – indicates that the order is being filled. The order could still be fully filled or cancelled.
Inactive – indicates that the order has been accepted by the system (simulated orders) or an exchange (native orders) but that currently the order is inactive due to system, exchange or other issues.
Rejected – indicates that the order was rejected by system or exchange.
Error messages associated with the order are passed to the GUI and are also saved within the Order History object.
Automatically starting TWS and managing TWS without human interaction
When TWS is started a user name and password needs to be entered and as a result TWS isn’t suitable for standalone automated trading. The best solution to managing TWS is to use the (free) open source application IBController.
IBController is a robust application which handles all TWS human interaction such as entering user name/password and dismissing TWS dialogue boxes.
IBController’s home page is:
The application can be downloaded using the following link:
If you have a key card to log into your account you will need to contact IB for options on how to login without using this device.
Configuring IBController to work with Seer
IBController has several configuration options which are contained in the file IBController.ini. See the readme.txt file within the IBController folder for more details. The initial settings in this file do not need to be changed but you are encouraged to read this file to understand what the options do.
One key consideration is whether to encrypt the password that is used to login into TWS. This encryption is only suitable for protecting the password from casual browsing on the local machine, but is something that you should consider doing. The steps below assume that the password is not encrypted and the machine has measures in place to stop this kind of casual browsing. These steps also assume that you are able to start TWS and login manually.
Once IBController has been downloaded from sourceforge, unzip it to:
Browse to the above folder and copy the file sampleIBControllerStart.bat to SeerIBControllerStart.bat
Open SeerIBControllerStart.bat in a text editor such as Notepad and change the user name and password to match your personal details. Assuming that you have installed TWS and IBController in the default folders you can now save the changes. If you have installed TWS or IBController in other folders, change the paths then save.
Double clicking on SeerIBControllerStart.bat will now start TWS and connect using your account details. SeerIBControllerStart.bat can also be set up as a scheduled task which will ensure that TWS is started automatically.June 19, 2014 at 5:26 pm #4486
Can Seer with Interactive Brokers trading forex pairs be used in the USA?June 23, 2014 at 3:14 pm #4488
Can Seer with Interactive Brokers trading forex pairs be used in the USA?
In theory, yes. In practise…
IB’s own data feed is sampled (which is why we use IQFeed for our real-time feed). With FX the price feed is ‘different’ between brokers and liquidity providers so it would be ‘impossible’ to get an FX feed via IQFeed (from Barclays or other providers) that would match the quotes you are being offered at IB. Feel free to drop an email to email@example.com to discuss the various issues and potential solutions.
You must be logged in to reply to this topic.