- Command-per-file Plugin System: Refactored commands out of the single 8,000 line
lang.pyfile into individualicli/cmds/[CATEGORY]/[cmd].pyfiles. - Style / Structure Cleanup:
poetry run ruff check --fixwith Python 3.12 feature levels. - Prettier Documetnation: just ran
prettier -won all markdown files. - Passes mypy Clean:
poetry run mypy icli/{cli,cmds/*/*,helpers,orders,instrumentdb,__main__,calc}.py
This update introduces new automation capabilities, significant stability improvements, fixes, and improvements for correctness and performance written over thousands of hours from the past ten months all in one giant update.
- Automated Trading with Predicate Engine: A powerful new
ifthenengine for creating complex, data-driven trading rules in real-time. - Guaranteed Price Compliance: A new
instrumentdbensures all orders use correct price increments, eliminating rejections from incorrect price ticks. - Massive
buyCommand Overhaul: Thebuycommand is now a full-fledged order parser with support for brackets, trailing stops, and scale/ladder orders. - Enhanced Stability and Performance: Major refactoring for better caching, error handling, and responsiveness.
- mypy clean: Guaranteed mypy clean using: poetry run mypy icli/{cli,lang,helpers,orders,instrumentdb,main,calc}.py
-
Instrument Database (
instrumentdb):- Automatically fetches and caches market rules for price increments, decimals, and valid exchanges.
- Ensures all orders are compliant with exchange rules, preventing rejections due to incorrect price ticks.
- e.g. equities trade in $0.01 increments, but options can be $0.01 or $0.05 or $0.10 or $0.25 increments, while some futures are $0.001 or $0.002 or $0.25 or $5 or 0.00390625 or 0.03125 (and more!) increments, etc.
- Have you ever had an order rejected because the price was "wrong?" Well, never again!
- Provides a centralized
complyAPI for automatically rounding prices up, down, or to the nearest valid price increment for any trading instrument. - Though, it's your fault if your instruments are trading a prices like
110.625000 ±0.015625so the interface may break columns in weird ways.
-
Predicate Engine (
ifthen):- Create complex, conditional trading logic using a simple
if...then...syntax.if AAPL bid <= AAPL low: buy AAPL 100 LMT— if AAPL hits the LOD, buy 100 shares at the current price.if AAPL { bid <= ask }: say AAPL price at AAPL.bid— use factored symbols for cleaner syntax.if AAPL ask >= AAPL high - 0.75: say AAPL near HOD again— supports arbitrary math against live valuesif :23 delta >= 0.50: say delta going up— use positional quote aliases.if AAPL last >= (AAPL high + AAPL low) / 2: say AAPL is over half way between high and low— supports arbitrary math.if :23 { bid >= low + 5% }: say row 23 is 5% higher than the low again— supports percentage-based math.if :23 { ema:delta 300 > ema:delta 900 }: say 5 minute delta rising over 15 minute delta- trigger events on EMA of deltas (or ema:price, ema:iv too)- symbols can also be "factored out" like
if AAPL { bid <= ask }: say AAPL price at AAPL.bid- avoids repeatingif AAPL bid <= AAPL ask: say doneetc
- Conditions are evaluated in real-time on every ticker update.
- An
ifthenstatement remains live until its condition matches, then the result executes and the statement is removed from live updates. - You can create an algo system by running
ifthenstatements in a loop using theifgroup :load <filename>command where filename is anifthenDSL for defining an initial start predicate, then when it matches, _another _ predicate is scheduled, and these can be placed in arbitrary tree (OTO) or peer (OCO) groups. - the fields available are: high, low, open, close, last, mid/midpoint/live, atr, vwap, iv, delta, theta, gamma
- Can consume external data from WebSocket feeds via the new Algo Binder.
- Manage predicates with
iflist,ifrm,ifclear, andifgroupcommands.
- Create complex, conditional trading logic using a simple
-
Order Manager (
ordermgr):- New local system for tracking executed positions and trades.
- Provides a foundation for advanced portfolio analysis and reporting (
reportcommand).
-
Background Task & Scheduling System (
bgtask):- Replaced ad-hoc scheduler with a robust
BGTasksystem. - Manage scheduled commands with
sched-add,sched-list,sched-cancel. - Manage background tasks with
tasklist,taskcancel.
- Replaced ad-hoc scheduler with a robust
-
Algo Binder:
- New module to consume external data feeds via WebSockets.
- Integrates external algorithmic signals directly into the
ifthenpredicate engine.
-
Paper Trading Log:
- A new
papercommand for session-based paper trading simulation.
- A new
-
buyCommand:- Rewritten to use a full order language parser (
orderlang), allowing for flexible syntax.buycommand input is now a full parser (orderlangin tradeapis) instead of just 3 command fields — we have much more flexibility for parameter order, types of information (attached take-profit, stop-loss either one or both and optional algo overrides for each attached order), and config options now (trailing stop orders with initial stop, trail, limit prices all in thebuycommand).
- Now supports complex orders with attached brackets (take-profit/stop-loss), trailing stops, and scale/ladder orders.
- Added support for more IBKR order types, including
TRAIL LIMITandSNAPorders. - Price-following logic is now event-driven for faster, more responsive fills.
- Enhanced
buy ... previewoutput with detailed margin impact, commission estimates, and risk/reward analysis.
- Rewritten to use a full order language parser (
-
straddleCommand:- Now a powerful spread creation tool, not just for orders but for adding quotes.
- Supports straddles, strangles, vertical spreads, and iron-condor-like structures with a flexible syntax.
- Example:
straddle /ES v c 10 20 v p -10 -20creates a complex spread quote. - Automatically flips legs when selling a long-defined spread.
straddle /ES 20would add a quote for a straddle (long call, long put) ±20 points from live /ES ATMstraddle /ES 0would give you an ATM stranglestraddle /ES vertical put -10 -20would give you a vertical put with the long leg -10 points from ATM and the short leg -20 points from ATM (e.g. /ES 5000 with vertical put -10 -20 would add a quote for BUY PUT 4980, SELL PUT 4960)straddle /ES vertical call 10 20creates a spread quote for buy call +10 ATM and sell call +20 ATM.- You can also combine the syntax in any combination (also with shorthand):
straddle /ES v c 10 20 v p -10 -20would create a quote for (BUY CALL +10 ATM, SELL CALL +20 ATM, BUY PUT -10 ATM, SELL PUT -20 ATM) all as a single spread.
-
clearCommand:- New subcommands for cleaning up the quote list:
today,expired,unused,options,noquote. clear todayfor removing all quotes expiring today or olderclear expiredfor removing all quotes older than todayclear unusedfor removing all single leg option quotes not used by spread quotesclear optionsfor removing all options quotes
- New subcommands for cleaning up the quote list:
-
alignCommand:- New command to generate a family of related spread quotes at once (e.g., ATM strangle, straddle, and vertical spreads).
align /ESby default gives you: ATM strangle, 10 point wide straddle, call spread +10 ATM 20 points wide, put spread -10 ATM 20 points wide.- The ATM point offset and width offset can be adjusted as parameters.
-
set/unsetCommands:set dtenow accepts day names (e.g.,thursday) to automatically calculate days to expiration.- contract discovery commands, by default, use the nearest contract expiration, but you can alter how far the automatic quotes expire with a global setting of
set dte NwhereNis days away from today.set dtecan also accept a day name as a word (set dte thursday) and it will figure out how many days away to use forN
-
infoCommand:- Output is now significantly more detailed, including live stats, EMAs, ATRs, greeks analysis, and quote flow metrics.
-
positionsCommand:- Improved display with better formatting and PnL per share.
- Now identifies and groups potential spreads.
-
ordersCommand:- Improved display with more details and better sorting.
-
executionsCommand:- Now groups executions by trading day for clearer daily P&L analysis.
-
daydumperCommand:- New command to generate real time price alerts when crossing historical points of interest and saves historical bar data for a symbol to disk.
-
colorset/colorsload:- New commands to manage and persist UI color themes.
-
reportCommand:- New command for advanced portfolio analysis and reporting, powered by
ordermgr.
- New command for advanced portfolio analysis and reporting, powered by
-
Price & Math Precision:
- All internal price calculations now use Python's
Decimaltype for arbitrary precision, eliminating floating-point errors.
- All internal price calculations now use Python's
-
Data Caching & Qualification:
- The
qualifymethod for contracts is now much more robust, with better caching, corruption checks, and batching to avoid API rate limits. - Contract cache expiration is now smarter (e.g., 5 days for futures, 90 for others).
- Option chains can be fetched from Tradier (if API key is provided) for a massive speedup over IBKR's API.
- The
-
Quote & Toolbar Display:
- Quote logic is now encapsulated in a new
ITickerclass, which augments per-instrument price history with extra live data: EMAs, ATRs, greeks, and more. - Quote sorting in the toolbar is improved to handle more security types and sort bags more intelligently.
- The toolbar now shows more PnL percentage breakdowns (
RealizedPnL%,UnrealizedPnL%,TotalPnL%). - The toolbar refresh count now distinguishes between total updates and updates since the last reconnect.
- Toolbar now displays correct digit resolution for all instruments using
instrumentdb
- Quote logic is now encapsulated in a new
-
Error Handling:
- A new
DuplicateMessageHandlersuppresses repeated API error messages for a cleaner console. - Text-to-speech error logging is now throttled to prevent log spam.
- A new
-
Code Quality & Dependencies:
- Major refactoring into new modules like
helpers.py,utils.py, andinstrumentdb.py. - The codebase now passes
mypytype checks, improving reliability. - Replaced the unmaintained
pendulumlibrary withwheneverandpytzfor robust timezone handling. - Now uses
python-dotenvto load.env.icliintoos.environat startup.
- Major refactoring into new modules like
-
Logging:
- Log files are now organized by date (
runlogs/YEAR/MONTH/). - Log filenames include client ID and a full timestamp for easier debugging.
- Log files are now organized by date (
- Calculator: Fixed
roundfunction to correctly handle its arguments. Fixedpositionlookupto handleNonefor bid/ask prices. Addedac(average cost) andabs(absolute value) functions. - Order Modification: Fixed a critical bug where modifying an order could be rejected by IBKR due to auto-populated fields (e.g.,
orderType="IBALGO"). The newsafeModifyhelper prevents this. - Futures Options Sorting: Corrected sorting for futures options to use the full contract month date.
- Contract Cache: Added checks to prevent and detect corrupted contract data in the cache.