Repository navigation
Simplify README, implement real Claude API, add tests - #6
Merged
Merged
Conversation
LLMInterface now creates a real anthropic.Anthropic client when ANTHROPIC_API_KEY (or ANTHROPIC_AUTH_TOKEN / config api_key) is set and falls back to MockLLMClient otherwise, or when use_mock is true. Default model is claude-opus-5-5 with a configurable effort level and server-side refusal fallback. Refusals and API errors surface as clear messages. Adds tests that exercise the request shape without network. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rhcFXLJHUCwo4mn74RAHy
Backtester: - "hold" no longer closes positions. SuperTrend emits buy/sell only on the flip bar, so every trade was closed after exactly one bar. - Trailing stop is ratcheted after the exit check, so a bar's close can no longer tighten the stop that bar's low is tested against. - Stops/targets hit by a gap fill at the bar open instead of the level. Metrics/indicators: - Sortino downside deviation is averaged over all periods. - calculate_adx is a real Wilder ADX (was ATR * 0.5, price-scale dependent). - calculate_atr / calculate_rsi handle series that are too short. Engine/integration: - get_signals always returned [] (StrategySignal has no .symbol); strategy signals are now converted to TradingSignal with ATR stop/target, and the LLM prompt gets a market summary instead of the full OHLCV dump. - execute_with_validation approved trades from a heuristic score and ignored the model's answer; it now parses DECISION/CONFIDENCE and fails closed. - Position sizing returned notional labelled as size; it now returns notional (capped at balance) and units. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rhcFXLJHUCwo4mn74RAHy
Replace the aspirational architecture (agents/, rag/, nlp/, api/ etc. that do not exist) with a status table of what is implemented, what is a mock (market data, RAG) and what is a placeholder (multi-factor, RL, REST API). Document the Claude configuration and mock fallback, the backtester's fill and exit rules, and the working `python -m` entry points. Mark docs/API.md as an unimplemented design spec. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015rhcFXLJHUCwo4mn74RAHy
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Gap ordering, sequence handling, cache keys, and sizing validation contain unresolved correctness issues.
Review effort: Balanced
Findings: 1
Open (3)
What changed in this PR
Adds real Anthropic integration, improves trading calculations and backtesting behavior, aligns documentation with implemented functionality, and expands tests.
Changes:
- Implements Anthropic API calls, caching, trade gating, and position sizing.
- Improves indicators, signal conversion, backtest exits, and performance metrics.
- Rewrites documentation and adds comprehensive tests.
| File | Description |
|---|---|
ClaudeTrader/README.md |
Documents current capabilities and limitations. |
ClaudeTrader/configs/default_config.yaml |
Adds current Anthropic options. |
ClaudeTrader/core/engine.py |
Converts strategy signals and computes exits. |
ClaudeTrader/docs/API.md |
Marks the API as unimplemented. |
ClaudeTrader/docs/README.md |
Updates documentation links and scope. |
ClaudeTrader/integrations/supertrend_bot_integration.py |
Adds strict trade gating and sizing. |
ClaudeTrader/models/llm_interface.py |
Implements Anthropic requests and fallback behavior. |
ClaudeTrader/requirements.txt |
Enables the Anthropic dependency. |
ClaudeTrader/setup.py |
Updates the optional Anthropic dependency. |
ClaudeTrader/tests/test_backtest.py |
Tests hold, gap, and trailing-stop behavior. |
ClaudeTrader/tests/test_engine.py |
Tests signal conversion and exit levels. |
ClaudeTrader/tests/test_indicators.py |
Tests indicator edge cases. |
ClaudeTrader/tests/test_integration.py |
Tests gating and sizing. |
ClaudeTrader/tests/test_llm_interface.py |
Tests LLM requests and fallback behavior. |
ClaudeTrader/tests/test_performance.py |
Tests Sortino downside deviation. |
ClaudeTrader/utils/backtest.py |
Revises signal and gap execution semantics. |
ClaudeTrader/utils/indicators.py |
Improves RSI, ATR, and ADX behavior. |
ClaudeTrader/utils/performance.py |
Corrects Sortino downside deviation. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+156
to
+157
| has_open = bool(ohlcv.get("open")) | ||
| open_ = [float(x) for x in ohlcv["open"]] if has_open else list(close) |
Comment on lines
+176
to
+179
| risk_amount = account_balance * risk_per_trade | ||
| stop_loss_pct = signal.get('stop_loss_pct', 0.02) | ||
| position_size = risk_amount / stop_loss_pct | ||
| notional = min(risk_amount / stop_loss_pct, account_balance) if stop_loss_pct > 0 else 0.0 | ||
| price = signal.get('price') |
| ) -> str: | ||
| """Generate cache key for a prompt""" | ||
| cache_input = f"{prompt}|{system_prompt}|{temperature}|{self.model}" | ||
| cache_input = f"{prompt}|{system_prompt}|{temperature}|{self.model}|{self.effort}" |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Summary
This PR significantly streamlines the ClaudeTrader documentation and implementation to reflect what actually works today, while adding real Anthropic Claude API integration with a mock fallback, comprehensive test coverage, and bug fixes.
Key Changes
Documentation & Scope
Claude LLM Integration (
models/llm_interface.py)anthropicSDK (1.11.0+)beta.messages.create()for extended thinking supportlow,medium,high,xhigh,max) viaoutput_configfallbacks: "default")ANTHROPIC_API_KEYis not set oranthropicpackage is missingclaude-opus-5-5and max tokens to 16000Trade Validation & Sizing (
integrations/supertrend_bot_integration.py)execute_with_validation(): trades execute only when Claude explicitly answersDECISION: EXECUTEwithCONFIDENCE >= threshold_parse_decision()static method using regex to extract decision and confidence from free-form textEngine & Signal Generation (
core/engine.py)_to_trading_signal()to convert strategy signals to engineTradingSignalobjectscompute_exit_levels()claude-opus-5-5andeffort: mediumBacktester Fixes (
utils/backtest.py)openfield in OHLCV data (falls back toclose)holdnow means "no new signal" (position stays open), not "close position"Indicator Robustness (
utils/indicators.py)Test Coverage
test_llm_interface.py(83 lines): mock fallback, API key detection, Anthropic request shape, refusal handlingtest_engine.py(35 lines): signal generation, ATR exit level computationtest_integration.py(35 lines): trade gating decision parsing, position sizingtest_indicators.py(33 lines): ADX edge cases, RSI neutrality, ATR single-bartest_backtest.pyadditions: hold signal semantics, gap fillshttps://claude.ai/code/session_015rhcFXLJHUCwo4mn74RAHy