Skip to content

[codex] fix strategist controls and restore entrypoints#7

Draft
zd87pl wants to merge 6 commits into
mainfrom
feat/autotrader-self-improving-quant
Draft

[codex] fix strategist controls and restore entrypoints#7
zd87pl wants to merge 6 commits into
mainfrom
feat/autotrader-self-improving-quant

Conversation

@zd87pl

@zd87pl zd87pl commented Apr 14, 2026

Copy link
Copy Markdown
Owner

What changed

This PR tightens the new strategist/autotrader integration and restores a few broken repo entrypoints and runtime paths.

It includes:

  • preserving stricter configured risk caps when strategist directives update runtime limits
  • honoring strategist hourly / 4h / daily experiment cadence instead of collapsing everything to hourly
  • wiring the new advisor settings so AUTO_REASSESS and REASSESS_INTERVAL_MIN affect orchestrator behavior
  • making the advisor reassess endpoint accept standard JSON content types with charset parameters
  • restoring working console entrypoints for serving and training
  • fixing the CLI parse error, scheduler signal-handler safety off the main thread, and timezone-aware UTC timestamps
  • adding focused regression coverage for the strategist controls, CLI importability, and scheduler thread initialization

Why

The merged strategist work introduced a few integration bugs that would materially change runtime behavior:

  • dynamic risk updates could silently loosen stricter existing limits
  • daily and 4h directives would actually run hourly
  • dashboard strategy settings existed in the UI but were not connected to the live orchestrator

Separately, the local publish/run surface still had obvious broken paths from the earlier review pass, including dead console-script targets and a CLI syntax error.

Impact

  • advisor directives now remain conservative relative to the original configured risk envelope
  • autotrader cadence follows the strategist directive more accurately
  • dashboard strategy settings have real effect on reassessment behavior
  • local CLI/service entrypoints are usable again
  • the repo's fast verification path stays green with added regression tests

Validation

  • python -m compileall -q src main.py deployment
  • python -m pytest -q

0x7d0 and others added 6 commits April 13, 2026 19:52
…ions

The original targets were too conservative ($0.25/day on $500). Recalibrated
all 5 capital tiers x 3 risk levels for 24/7 crypto markets where higher
volatility = more edge to capture.

New targets (crypto-calibrated):
  $500 conservative  -> $1/day, $31/mo, $1K year-end
  $500 aggressive    -> $4/day, $135/mo, $9K year-end
  $5K moderate       -> $25/day, $807/mo, $31K year-end
  $50K aggressive    -> $350/day, $11K/mo, $638K year-end

Added PortfolioDirective projection fields:
- projection_daily_pnl, projection_weekly_pnl
- projection_monthly_pnl, projection_monthly_balance
- projection_yearly_pnl, projection_yearly_balance
- projection_drawdown_dollar

Added _compute_projections() using compound growth (365 trading days for
crypto). Projections shown in reasoning text and in new Advisor dashboard
"Compound Growth Projections" card with weekly/monthly/yearly/max-risk columns.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Replace Alpaca dependency for crypto data with CCXT — 100+ exchanges,
no API key needed for public OHLCV data.

New: src/data/ingestion/ccxt_client.py
- Drop-in replacement for AlpacaDataClient (same interface)
- download_bars() / download_latest() with MultiIndex return format
- Automatic pagination for large date ranges (>1000 candles)
- Parquet caching for repeated queries
- Symbol normalization: accepts both "BTCUSDT" and "BTC/USDT"
- Timeframe mapping: "1Day" -> "1d", "1Hour" -> "1h", etc.
- get_ticker() for live prices, list_symbols() for discovery
- Default exchange: Kraken (no geo-restrictions)

Data source selection in main.py:
  DATA_SOURCE=auto  -> tries CCXT first, falls back to Alpaca
  DATA_SOURCE=ccxt  -> CCXT only
  DATA_SOURCE=alpaca -> Alpaca only

Tested: 91 BTC/USD daily candles from Kraken, multi-symbol ETH+SOL,
live ticker at $74K, all free, zero API keys.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. _init_llm_client() imported from src.agents which triggered loading
   RAGSystem -> faiss (not installed) -> ImportError -> llm_client=None.
   Fix: import directly from src.agents.llm_client_factory.

2. pydantic Config only read .env, not .env.local — so API keys saved
   via the dashboard Settings tab were invisible to ClaudeClient.
   Fix: Config.env_file now reads both (".env", ".env.local").

3. ClaudeClient had a hardcoded model whitelist (only old claude-3 IDs)
   that rejected newer models with ValueError.
   Fix: accept any model ID, log a warning for unknown ones.

Also: main.py now loads .env.local into os.environ at startup before
any subsystem initializes, ensuring dashboard-saved keys are available
to ClaudeClient, CCXT, and all other components.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1. settings_manager.get() returned "" instead of cached value because
   os.environ had empty string from .env (ANTHROPIC_API_KEY=), which
   passed the `is not None` check. Fix: also skip empty strings.

2. src/agents/__init__.py imported RAGSystem eagerly, which required
   faiss. Even direct imports of llm_client_factory triggered __init__.py.
   Fix: lazy-import RAGSystem with try/except ImportError.

3. pydantic Config rejected extra keys from .env.local (BROKER,
   DATA_SOURCE, CCXT_EXCHANGE, etc.) with "extra_forbidden" error.
   Fix: add extra="ignore" to SettingsConfigDict.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…ault)

No API key needed. Uses the local `claude` CLI tool which already has
authentication via Claude Code. Default model: claude-opus-4-6.

New: src/agents/claude_cli_client.py
- Drop-in replacement for ClaudeClient (.complete() interface)
- Shells out to `claude -p --model claude-opus-4-6 --output-format text`
- Auto-detected: if `claude` CLI is on PATH, it's used automatically
- 120s timeout, compatible with all pipeline consumers

Updated: src/agents/llm_client_factory.py
- Auto-detect priority: claude-cli (if on PATH) > claude API > mlx
- LLM_BACKEND=claude-cli to force CLI mode
- Skips config model override for CLI (uses opus 4.6 by default)

Updated: src/autotrader/settings_manager.py
- LLM Backend options: claude-cli (default), claude, mlx

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant