Trading Evolution

Markets are never wrong - opinions often are

Command line tool for Interactive Brokers

Many times in the past I came across people who needed quick and simple way to send orders to Interactive Brokers. I decided to share command line tool that I use to send orders to TWS and IB Gateway from command line. It can be used in automated trading systems or scripts.


Few simple examples: 

Buy 100 shares of Facebook at Market

IbCmd.exe /s:FB /pe:Nasdaq

Buy 250 shares of Google at $752.5

IbCmd.exe /s:GOOG /pe:Nasdaq /q:250 /p:752.5

Sell 1 ES (E-Mini S&P 500) at Market

IbCmd.exe /s:ES /e:Globex /t:Future /a:Sell

Full list of parameters for IbCmd 

/ServerIp:<string> IP address of copumter that hosts TWS or TWS Gateway. Default value:'' (short form /srv)

/ServerPort:<int> Port number. Default value:'7496' (short form /port)

/ClientId:<int> API client id. Default value:'10' (short form /cid)

/Action:{Buy|Sell} Buy or sell. Default value:'Buy' (short form /a)

/Symbol:<string> Symbol of the underlying asset. (short form /s)

/SecurityType:{Stock|Future} Security type. (short form /t)

/Exchange:<string> The order destination, such as SMART. Default value:'SMART' (short form /e)

/PrimaryExchange:<string> To clarify any ambiguity for Smart-routed contracts, include the primary exchange, along with the Smart designation. (short form /pe)

/Quantity:<int> The order quantity. Default is 100 for stocks and 1 for futures. Default value:'0' (short form /q)

/OrderType:{Market|Limit} The order type. Default value:'Market' (short form /ot)

/Price:<decimal>  The price for limit orders. (short form /p)


Download historical Forex data from Interactive Brokers

I added few more arguments to IbCmd tool for historical data download. For example to download last 10 days of Open, High, Low, Close data for EUR/USD pair use following list of parameters:

IbCmd.exe /s:EUR /t:Cash /e:IDEALPRO /f:EURUSD.csv /d:10

The tool will output EURUSD.csv file which can be opened in Excel or any other spreadsheet editor.

12/15/2015 12:00:00 AM,1.099625,1.105975,1.090475,1.093025
12/16/2015 12:00:00 AM,1.0925,1.101175,1.0888,1.091275
12/17/2015 12:00:00 AM,1.0909,1.09145,1.080275,1.0826
12/18/2015 12:00:00 AM,1.083425,1.08745,1.080525,1.0864
12/21/2015 12:00:00 AM,1.085975,1.0939,1.084825,1.09145
12/22/2015 12:00:00 AM,1.091375,1.098425,1.090225,1.09565
12/23/2015 12:00:00 AM,1.095225,1.0957,1.087025,1.091175
12/24/2015 12:00:00 AM,1.090975,1.096775,1.090425,1.096375
12/28/2015 12:00:00 AM,1.0964,1.099275,1.095625,1.09685
12/29/2015 12:00:00 AM,1.0967,1.098025,1.096625,1.097925

If you want 10 days of 5 minute bars then add /b:FiveMins


IbCmd.exe /s:EUR /t:Cash /e:IDEALPRO /f:EURUSD.csv /d:10 /b:FiveMins

Interactive Brokers Limitations

When you use this tool you need to be familiar with Interactive Brokers historical data download limitations. The following table lists the valid duration and bar size settings for historical data requests. Requesting the same historical data in a short period of time can cause pacing violations from Interactive Brokers.

More details can be found here: Historical Data Limitations

People are losing interest in stock trading

According to latest data from Google Trends interest in stock trading is in decline. May be it is because Generation X got tired of volatility when stocks declined significantly twice during their life times. Once in 2000/2001 after dot com bust and once in 2008 during great recession as some call it. Generation Y still didn't make enough money to trade stocks and also watched their parents lose money twice. Some people may not even have an interest in trading or investing within the financial markets, but social pressures induce them to trade or invest anyway. A decade ago it was common when large numbers of people were talking about investing in the markets during the final phase of last bull market. People felt pressured to conform by their social circle. Thus they invested so as not to disrespect or disregard others' beliefs or feel left out. This time around the market is much quieter and there is not much discussion between friends about investments and trading.