Install
openclaw skills install ibkr-auto-tradeAutonomous paper trading research agent for Interactive Brokers (IBKR). Use this skill whenever the user wants to connect to IBKR, execute trades, manage positions, analyze strategies, run paper trading workflows, backtest signals, or build any automated trading system with TWS or IBKR Gateway. Triggers on: "trade", "IBKR", "Interactive Brokers", "paper trading", "order execution", "position management", "quant strategy", "bracket order", "stop loss", "ib_insync", or any mention of automated trading. Always use this skill for trading-related tasks — even exploratory ones.
openclaw skills install ibkr-auto-tradeA modular, safe, self-improving paper trading agent for Interactive Brokers.
⚠️ Safety First:
ENABLE_LIVE_TRADINGdefaults toFalse. The agent operates in paper trading mode unless explicitly toggled and confirmed. Never flip this flag without user confirmation.
pip install ib_insync pandas numpy pyyaml loguru
# Ensure TWS or IB Gateway is running with API enabled on port 7497 (paper)
python skills/ibkr-autonomous-trader/scripts/trader.py
| File | Purpose |
|---|---|
scripts/trader.py | Main trading loop — entry point |
scripts/strategy_engine.py | Signal generation, indicator logic |
scripts/risk_manager.py | Position sizing, kill switch, daily loss limit |
scripts/execution_engine.py | Order placement, modification, cancellation |
scripts/performance.py | Trade logging, PnL, Sharpe, self-improvement |
config/settings.yaml | All tunable parameters |
memory/trades.json | Full trade history |
memory/strategies.json | Strategy parameter versions |
memory/performance.json | Rolling performance metrics |
1. Connect to IBKR
2. Load config + memory
3. Fetch market data (bars + live quotes)
4. Scan watchlist assets
5. Run strategy_engine → generate signals
6. Run risk_manager → validate each signal
7. Size position
8. Execute order via execution_engine (bracket with stop loss)
9. Monitor open positions
10. Log trade details to memory/trades.json
11. Periodically: run performance.py → evaluate + tune parameters
12. Sleep → repeat
ENABLE_LIVE_TRADING = False in config/settings.yaml — paper only by defaultMAX_DAILY_LOSS_PCTMAX_POSITIONSrisk_manager.py before submissionloguruexecute_trade(signal) — Places bracket order with auto stop lossclose_trade(position) — Market-closes an open positionadjust_stop(position, new_stop) — Modifies trailing stopcancel_trade(order_id) — Cancels a pending orderget_positions() — Returns all open positionsget_open_orders() — Returns all pending ordersvalidate_signal(signal, portfolio_state) — Returns (approved: bool, reason: str)size_position(signal, account_value) — Returns share quantitycheck_kill_switch(daily_pnl, account_value) — Halts trading if threshold breachedgenerate_signals(bars_dict) — Returns list of Signal objectscompute_indicators(bars) — RSI, MACD, ATR, EMAscore_signal(signal) — Confidence 0–1log_trade(trade) — Appends to trades.jsonevaluate_performance() — Returns stats dict (win rate, Sharpe, drawdown, profit factor)suggest_improvements(stats) — Returns parameter adjustment recommendationsapply_improvements(recommendations) — Updates strategies.jsonWhen implementing or modifying any module, read the corresponding reference:
references/ibkr_connection.mdreferences/order_types.mdreferences/indicators.mdreferences/self_improvement.mdstrategy_<name>(bars) -> list[Signal] in strategy_engine.pyconfig/settings.yaml under strategies.enabledstrategies.params.<name>To add OCO (One-Cancels-Other) or trailing stops, see references/order_types.md.
execution_engine.py is structured to accept any ib_insync Order object.
Two new modules extend the base skill with multi-factor decision making.
fetch_all() → list of NewsItem (cached for 5 min)get_market_sentiment(items) → aggregate score dict used by decision engineget_symbol_sentiment(symbol, items) → float score for a specific tickerevaluate_news_utility() → learns which news types predict trade outcomesmemory/news_log.jsontechnical (default 50%) — strategy_engine confidencenews (default 25%) — directional alignment with sentimentrisk (default 15%) — inverse portfolio exposurevolatility (default 10%) — ATR/price regime penaltyDecision with: action, confidence, position_size_modifier, stop_modifierrisk_event news → REDUCE_RISK, no new entriesNO_TRADEmin_trades_for_weight_update closed trades1. Fetch market data
2. Fetch + analyze news → market_sentiment
3. Generate technical signals
4. For each signal:
a. risk_manager.validate_signal()
b. news_engine.get_symbol_sentiment()
c. decision_engine.decide() → Decision
d. Apply position_size_modifier + stop_modifier
e. execution_engine.execute_trade()
5. Monitor positions
6. Periodic eval → parameter tuning + news utility learning
| Event | Response |
|---|---|
risk_event in news | REDUCE_RISK — no new entries, stops tightened |
high_impact news | Position size × 0.6, stops × 0.85 |
| News opposes signal AND tech < 0.8 | NO_TRADE |
| Final confidence < 0.45 | NO_TRADE |
| Extreme volatility regime | Volatility score = 0.20 |
pip install feedparser # Only new dependency