Click or drag to resize

Interactive Brokers Connection

This section describes how to configure the Interactive Brokers connection.

Requirements

Please make sure you meet the below requirements to connect to Interactive Brokers.

Note: If you want to submit orders you need to register ArthaChitra. Please click here to know how to register ArthaChitra.

Configuring TWS/IB Gateway

Please configure TWS/IB Gateway as below

  • In TWS/IB Gateway menu bar goto Edit > Global Configuration... (Or File > Global Configuration)
    TWSConfiguration
  • In the Configuration dialog view click on the API > Settings node and configure the options as below:
    • Check on the option "Enable ActiveX and Socket Client" (this option is not available in IB Gateway)
    • Uncheck the option "Read-only API"
    • Check the option "Include FX position when sending portfolio"
    • Set the option "Socket port" to 7497 (4002 in case of IB Gateway)
    TWSSettings
Configuring IB Connection Settings

Once you have configured the TWS/IB Gateway settings, you need to set up the Interactive Brokers Connection in ArthaChitra. Please follow the below steps to configure the Interactive Brokers Connection settings:

  • In the "Main View" goto Connection > Add Edit Connection
  • In the Add Edit connection view click on the Add button
  • In the "New Connection View" select 'Interactive Brokers' as the Connection Type and set the settings as
    • Name - Append a suitable name of the connection in the Name textBox
    • IP address - Append a host value (default value is 127.0.0.1)
    • Port - Append the port value (as set in TWSGateway configuration settings)
    • IB client id - Set an appropriate 'Client Id' (default and recommended value is 0 (zero))
    • Default exchange - Set a default exchange for instruments in Smart Order Routing. If ArthaChitra is unable to determine the exchange it will use this user defined exchange
    • Is account name formatted - Check if you want to format the account name with the connection name
    • Is smart depth - Is market depth (Level-II data) has smart depth
    • Option computation type - Greek values to be calculated from the chosen price points
    • Order tags - Advanced order rejection override tag. Default value is 'SURVEILLANCE'. For more details please refer to the section Advanced order rejection
  • Click on the Close button and exit the Add Edit connection view

Now you will be able to connect to the newly created Interactive Brokers connection from, in Main View menu bar goto Connection > Available Connections > {name of the IB connection}

IBSettings
Advanced order rejection

An order may need additional confirmation due to various reasons like, additional surveillance measures imposed by the exchange etc. Such orders when placed via TWS needs further confirmation by user via a order confirmation dialog. Any such orders when placed via IB API/ArthaChitra gets rejected. Please find below a sample rejection message:

|Exception|InteractiveBrokersAdapter.error : id=2413, errorTime=1741152946000 errorCode=201, errorMsg=Order rejected - reason:Security is under Surveillance Measure - EPS based on previous 4 trailing quarters in the scrip is zero.<br><br><br>Would you like to continue?., json={"rejects":[{"buttons":[{"options":[{"fixstr":"8229=SURVEILLANCE","text":"Yes, transmit the order."}],"style":"chk"}],"id":11,"text":"Security is under Surveillance Measure - EPS based on previous 4 trailing quarters in the scrip is zero. <br><br>Would you like to continue?","textsep":"119"}],"version":"1.0"}

So that user can seamlessly place such order via ArthaChitra, the IB Connection option has an 'Order tag' parameter where user can specify the FIX rejection string value to place the order. For example in the above example, the order got rejected as the exchange has imposed additional surveillance measure. If user append the order tag with the fix string 'SURVEILLANCE' as highlighted in bold and then place the order, the same will be duly placed. Multiple tags can be appended separated by a comma. For more details please refer here.

Disclaimer

Before connecting to Interactive Brokers please refer to the below scenarios for a proper understanding on how ArthaChita works with Interactive Brokers. Please do note the below list is not exhaustive. There may be scenarios in addition to what listed below

  • If you encounter the error message "No connection could be made because the target machine actively refused it" then please make sure TWS or IB Gateway is running and you have configure TWS and IB Connection settings as described above.
  • ArthaChitra supports Indices, Stocks, Forex, Futures and Options.
  • ArthaChitra supports DAY, IOC, GTC, GTD, AON, DTC and OPG TimeInForce
  • For forex, the bid price is appended as the last price.
  • 'Trades' data is pulled when historical data is requested, except for forex, for which 'Midpoint' data is pulled.
  • Interactive Brokers supports only three 'Level II' requests at any time. If additional requests are made then ArthaChitra will unsubscribe the previous requests (on FIFO basis) to accommodate the new requests.
  • Orders submitted by a Managed automated strategy, the OCO simulation for the stop and target order is simulated locally. However the orders submitted by an Unmanaged automated strategy, Order Template (Bracket orders) and 'OCO' orders the OCO Simulation is handled by the server.
  • IB supports trading for exchanges around the globe. While we have tested the popular instruments some instruments may need additional configurations. Please send an email to support@arthachitra.com in case you need any assistance while configuring the symbols of your choice.
  • IB has an order and data throttle policy. Please refer to the below links to know more about it
  • To know more about TWS order status colors please click here
  • In case real-time quotes are not streaming for any instrument and you are getting an error message like error : id = 1073741837, errorCode = 354, errorMsg = Requested market data is not subscribed.Delayed market data is not available.RELINFRA NSE/TOP/ALL then please make sure you have subscribed real-time quotes for the said instrument. In case you are connected to the paper trading account then please make sure you have shared the 'Market data subscription'. Please click here to know more
  • Forex (IdealPro) orders are rounded to nearest 5 * tick-size to conform round-off policy of IB.