This is the JHU Quant Trading Teams's code to stream market data into a local database. IBKR's API does not limit the number of data lines IBKR sends to a user per second.
This component is part of a much larger automated trading engine. This code pulls data from IBKR into a local database for use in automated trading. More specifically, the program receives trade, quote, and fundamental data from IBKR and subsequently saves the data to a local database. The program also checks for inconsistencies and corrects any errors or gaps in IBKR data.
IBKR's main program is a trading platform called Trader Workstation (TWS). Any IBKR user can use TWS to trade on the financial markets. TWS controls user authentication and connecting to IBKR's servers to provide financial data that a user is subscribed to. IBKR provides an API for 3rd party software to access financial data and IBKR services. IBKR provides another program called IB Gateway for its API to connect to and handle user authentication. IB Gateway is a stripped down version of TWS that does not have any GUI for trading and only handles user authentication and connecting to IBKR's servers.
IBKR API's documentation can be found at https://interactivebrokers.github.io/tws-api/index.html. Error codes can be found at the same link.
This repository includes the IBKR API and the samples that come along with them. To run the samples, simply go into the respective samples folder in the API directory. To properly run the C++ samples, the following is required:
- C++ compiler above C++ 11
- IB Gateway [Most Recent] (https://www.interactivebrokers.com/en/index.php?f=5041).
- An IB account
To compile the sample code, run the following:
cd IBJts/samples/Cpp/TestCppClient/
make
To run the program:
./TestCppClient
IB Gateway uses a specific port (Live Trading - 4001, Paper Trading - 4002) to communicate with any programming using the API. [Never run the API in development on a Live Trading port or account. The reason for this is straightforward: to not lose money via accidental trades.] This is designated in the Main.cpp file and can be changed to whatever IB Gateway is set to use in the IB Gateway settings.
In the file TestCppClient.cpp, m_state
is determines what functionality the C++ sample will showcase. m_state
is determined in the TestCppClient::nextValidId(OrderId orderId)
function.
The main purpose of this program is to stream financial data (trades, prices, and fundamental) into a local database for use in an automated trading environment.
- Data: Research best and easiest way to store financial data.
- Data: Implement a program to stream financial data from IBKR API
- Data: Create a database(s) to store financial data (time series, fundamental, etc.)
- Execution: Create a program to submit orders given a target portfolio.
- Optional: Create a dashboard to monitor and control all programs.
- Optional: Determine how to use LIMIT orders to minimize cost.
- Optional: Look into stop loss orders.
- Optional: Look into manual routing instead of using IBKR SMART routing.
We will start with the simplest target portfolio technique: find the difference between the target and current portfolios and submit MARKET orders to correct for difference.