fix: smart fallback playbook with BUY conditions on Gemini failure (#145) #146

Closed
agentson wants to merge 0 commits from feature/issue-145-smart-fallback-playbook into main
Collaborator

Summary

  • 근본 원인: gemini-2.5-flash 무료 티어 일일 쿼터(20 RPD) 초과 시 _defensive_playbook() 사용 → SELL stop-loss 조건만 있고 BUY 조건 없음 → 항상 HOLD → 거래 0건
  • 수정: Gemini 실패 시 _smart_fallback_playbook() 사용 — 스캐너 신호 기반 BUY 조건 포함
    • signal=momentumvolume_ratio_above=VOL_MULTIPLIER BUY 시나리오
    • signal=oversoldrsi_below=RSI_OVERSOLD_THRESHOLD BUY 시나리오
    • 모든 후보: stop-loss SELL 시나리오 유지

DB 증거 (2026-02-17)

CHOW (US_AMEX): volume_ratio=13.64, RSI=100 → HOLD (No scenario conditions met)
SIF  (US_AMEX): volume_ratio=9.025,  RSI=100 → HOLD (No scenario conditions met)
playbooks: token_count=0, gemini_model='' → defensive fallback 확인

Test plan

  • 47개 테스트 통과 (pre_market_planner)
  • 607개 전체 테스트 통과
  • 커버리지 93% (pre_market_planner.py), 전체 76%
  • 모멘텀 후보 → BUY volume_ratio 조건 테스트
  • 과매도 후보 → BUY RSI 조건 테스트
  • 설정값(VOL_MULTIPLIER, RSI_OVERSOLD_THRESHOLD) 반영 테스트
  • generate_playbook() Gemini 실패 시 smart fallback 사용 확인

Closes #145

🤖 Generated with Claude Code

## Summary - **근본 원인**: `gemini-2.5-flash` 무료 티어 일일 쿼터(20 RPD) 초과 시 `_defensive_playbook()` 사용 → SELL stop-loss 조건만 있고 **BUY 조건 없음** → 항상 HOLD → 거래 0건 - **수정**: Gemini 실패 시 `_smart_fallback_playbook()` 사용 — 스캐너 신호 기반 BUY 조건 포함 - `signal=momentum` → `volume_ratio_above=VOL_MULTIPLIER` BUY 시나리오 - `signal=oversold` → `rsi_below=RSI_OVERSOLD_THRESHOLD` BUY 시나리오 - 모든 후보: stop-loss SELL 시나리오 유지 ## DB 증거 (2026-02-17) ``` CHOW (US_AMEX): volume_ratio=13.64, RSI=100 → HOLD (No scenario conditions met) SIF (US_AMEX): volume_ratio=9.025, RSI=100 → HOLD (No scenario conditions met) playbooks: token_count=0, gemini_model='' → defensive fallback 확인 ``` ## Test plan - [x] 47개 테스트 통과 (pre_market_planner) - [x] 607개 전체 테스트 통과 - [x] 커버리지 93% (pre_market_planner.py), 전체 76% - [x] 모멘텀 후보 → BUY volume_ratio 조건 테스트 - [x] 과매도 후보 → BUY RSI 조건 테스트 - [x] 설정값(VOL_MULTIPLIER, RSI_OVERSOLD_THRESHOLD) 반영 테스트 - [x] generate_playbook() Gemini 실패 시 smart fallback 사용 확인 Closes #145 🤖 Generated with [Claude Code](https://claude.com/claude-code)
agentson added 1 commit 2026-02-18 22:24:18 +09:00
fix: use smart rule-based fallback playbook when Gemini fails (issue #145)
Some checks failed
CI / test (pull_request) Has been cancelled
96e2ad4f1f
When gemini-2.5-flash quota is exhausted (20 RPD free tier), generate_playbook()
fell back to _defensive_playbook() which only had price_change_pct_below: -3.0 SELL
conditions — no BUY conditions — causing zero trades on US market despite scanner
finding strong momentum/oversold candidates.

Changes:
- Add _smart_fallback_playbook() that uses scanner signals to build BUY conditions:
  - momentum signal: BUY when volume_ratio_above=VOL_MULTIPLIER
  - oversold signal: BUY when rsi_below=RSI_OVERSOLD_THRESHOLD
  - always: SELL stop-loss at price_change_pct_below=-3.0
- Use _smart_fallback_playbook() instead of _defensive_playbook() on Gemini failure
- Add 10 new tests for _smart_fallback_playbook() covering momentum/oversold/empty cases
- Update existing test_gemini_failure_returns_defensive to match new behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
agentson closed this pull request 2026-02-19 05:44:47 +09:00
Some checks failed
CI / test (pull_request) Has been cancelled

Pull request closed

Sign in to join this conversation.
No Reviewers
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: jihoson/The-Ouroboros#146