-
Notifications
You must be signed in to change notification settings - Fork 89
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
35 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,52 @@ | ||
# InteractiveBrokers-Algo-System | ||
Java/MySQL example of Interactive Brokers API for algorithmic trading. Includes live price feed, handling ib price quote limits, order tracking system, margin tracking system, order handling, option chain information request, and kill switch | ||
- Requires either TWS or IB Gateway and IB Java API 9.71. The API scripts initiate a live socket connection to the desktop TWS/IB Gateway application, which routes requests | ||
- Requires US Securities Snapshot and Futures Value Bundle ($10/month), US Equity and Options Add-On Streaming Bundle ($4.95/month) | ||
- I simultaneously run the price feed/other reading processes on IB Gateway paper trading (port 4002) and the trading strategy/other writing processes to TWS (port 7496) | ||
This Java/MySQL framework implements the Interactive Brokers API for algorithmic trading. Included are all essential components to support a basic trading execution system: live price feed, handling for IB price quote limits, order tracking system, margin tracking system, handling for order submission and execution, option chain information request, and kill switches. A system based on this framework, with additional custom modules and proprietary strategies is currently being used to profitably trade US equities and equity options | ||
- Requires either TWS or IB Gateway (desktop applications provided by IB) and IB Java API 9.71 (API library package). The API scripts initiate a live socket connection to the desktop TWS and IB Gateway application, which routes requests | ||
- Requires US Securities Snapshot and Futures Value Bundle ($10/month), US Equity and Options Add-On Streaming Bundle ($4.95/month) for live price streams. If solely using the framework for executing orders, then these add on costs are not necessary; it is possible to use another data source for live price streams such as IEX, which is free | ||
- It's recommended to simultaneously run price feed and solely reading processes on an IB Gateway paper trading instance (port 4002 in the example) and trade execution/other writing processes on a TWS instance (port 7496 in the example) | ||
- API function documentation: http://interactivebrokers.github.io/tws-api/ | ||
|
||
![Flowchart](https://github.com/rediar/InteractiveBrokers-Algo-System/blob/master/IB%20Algo%20Flowchart.png) | ||
|
||
# Setup instructions | ||
### Set up MySQL database ### | ||
Set up the following tables: | ||
|
||
# Set up MySQL database | ||
- set up the following tables | ||
Price: | ||
- IBAlgoSystem.price: symbol (VARCHAR(10)), secType (VARCHAR(10)), currency (VARCHAR(3)), expiry (VARCHAR(8)), strike (DOUBLE), callorput (VARCHAR(1)), multiplier (VARCHAR(10)), bid (DOUBLE), ask (DOUBLE), last (DOUBLE), close (DOUBLE), bugCounter (INT), updateTime (BIGINT) | ||
|
||
Option details: | ||
- IBAlgoSystem.MasterChainList: entry (INT), active (VARCHAR(1)), symbol (VARCHAR(10)), secType (VARCHAR(10)), exchange (VARCHAR(20)), currency (VARCHAR(3)), expiry (VARCHAR(8)), strike (DOUBLE), callorput (VARCHAR(1)), multiplier (VARCHAR(10)), pennyPilot (VARCHAR(1)), moneyness (VARCHAR(3)) | ||
|
||
Orders: | ||
- IBAlgoSystem.orderTracking: orderID (INT), status (VARCHAR(20)), filled (INT), remaining (INT), avgFillPrice (DOUBLE) | ||
|
||
Execution failure retry counter: | ||
- IBAlgoSystem.counter: counterID (INT) | ||
|
||
Cash, margin and risk balance: | ||
- IBAlgoSystem.margin: AccruedCash (DOUBLE), AvailableFunds (DOUBLE), BuyingPower (DOUBLE), Cushion (DOUBLE), EquityWithLoanValue (DOUBLE), ExcessLiquidity (DOUBLE), FullAvailableFunds (DOUBLE), FullExcessLiquidity (DOUBLE), FullInitMarginReq (DOUBLE), FullMaintMarginReq (DOUBLE), GrossPositionValue (DOUBLE), InitMarginReq (DOUBLE), LookAheadAvailableFunds (DOUBLE), LookAheadExcessLiquidity (DOUBLE), LookAheadInitMarginReq (DOUBLE), LookAheadMaintMarginReq (DOUBLE), LookAheadNextChange (DOUBLE), MaintMarginReq (DOUBLE), NetLiquidation (DOUBLE), TotalCashValue (DOUBLE) | ||
|
||
# SimplePriceFeed | ||
- Read in TickerList.csv - a list of contracts to receive live price streams from | ||
# Module descriptions | ||
|
||
### SimplePriceFeed ### | ||
Read in TickerList.csv - a presaved list of contracts to receive live price streams from. Here, a contract is defined as either a specific option, or stock | ||
- TickerList.csv fields: Active (T/F) | symbol | secType | exchange | currency | expiry | strike | right | multiplier | ||
- Output prices to IBAlgoSystem.price | ||
- Output prices to the IBAlgoSystem.price MySQL table | ||
|
||
# LargePriceFeed | ||
- Read in IBAlgoSystem.MasterChainList - a list of options contracts to receive live price streams from | ||
- The number of entries may exceed ib's feed limit (FEED_LIMIT) | ||
- This script divides the entries into smaller batches to submit to ib | ||
- Output prices to IBAlgoSystem.price | ||
### LargePriceFeed ### | ||
Read in IBAlgoSystem.MasterChainList - a list of options contracts to receive live price streams from | ||
- The number of entries may exceed IB's feed limit (FEED_LIMIT). In that case, this script divides the entries into smaller batches to submit to IB | ||
- Output prices to IBAlgoSystem.price MySQL table | ||
|
||
# FetchOptionsChain | ||
- Read in TickerList.csv, a list of contracts to generate options chains from | ||
### FetchOptionsChain ### | ||
Read in TickerList.csv, a presaved list of contracts to receive live price streams from. Here, a contract is defined as either a specific option, or stock | ||
- TickerList.csv fields: Active (T/F) | symbol | secType | exchange | currency | expiry | strike | right | multiplier | ||
- Read in PennyPilot.csv, a list of Penny Pilot tickers | ||
- Output option chain to IBAlgoSystem.MasterChainList | ||
Read in PennyPilot.csv, a presaved list of Penny Pilot tickers | ||
- Output option chain to IBAlgoSystem.MasterChainList MySQL table | ||
|
||
# TradeStrategy | ||
- Template to implement trade strategies | ||
- Output order management to IBAlgoSystem.orderTracking | ||
- Output margin management to IBAlgoSystem.margin | ||
### TradeStrategy ### | ||
Template to implement trade strategies - call price stream, submit order execution requests, manage orders and risk | ||
- Output order management to IBAlgoSystem.orderTracking MySQL table | ||
- Output margin management to IBAlgoSystem.margin MySQL table | ||
|
||
# KillSwitch | ||
- kills all active orders | ||
### KillSwitch ### | ||
Kills all active orders |