This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
# Run the bot
python -m src.main
# Install dependencies
pip install -r requirements.txt
# Run tests
python3 -m pytest tests/ -v
# Deploy to server (from repo root)
sudo ./scripts/update.shCRITICAL: All tests must pass. Always. No exceptions.
- Run the full test suite:
python3 -m pytest tests/ -v - If any test fails, fix it immediately before proceeding
- Never create a PR with failing tests
- Never ignore failing tests - they indicate real bugs that must be fixed
- If your changes break existing tests, fix the tests or fix your code
The 12 Coinbase integration test "errors" are expected - they refuse to run without test credentials (security feature). These are not failures.
Trading Bot supporting Coinbase and Kraken exchanges with multi-indicator confluence strategy.
src/main.py → src/daemon/runner.py (main loop) → Exchange client + Strategy + Safety systems
All exchange clients implement ExchangeClient protocol (src/api/exchange_protocol.py):
coinbase_client.py,kraken_client.py,paper_client.py- Factory pattern in
exchange_factory.pyselects client based on config - Trading pairs normalized to
BASE-QUOTEformat (e.g.,BTC-USD)
- KillSwitch: File-based or signal-based halt, requires manual reset
- CircuitBreaker: Multi-level (GREEN→YELLOW→RED→BLACK) with auto-cooldown
- LossLimiter: Daily/hourly loss limits with progressive throttling
- Validator: Aggregates all safety checks, provides position multiplier
src/strategy/signal_scorer.py combines RSI, MACD, Bollinger, EMA, Volume into -100 to +100 score. Trade when |score| ≥ threshold.
All database operations MUST support both PAPER and ACTUAL (live) trading modes. They MUST be kept completely separate:
- Every table with trading data has
is_papercolumn - All queries MUST filter by
is_paperparameter - Paper and live data must NEVER mix
- Both modes must be independently functional
- Test with paper trading before enabling live trading
This project uses Base.metadata.create_all() instead of Alembic for simplicity:
- New tables: Automatically created on startup - no migration needed
- Schema changes to existing tables: Use
_run_migrations()indatabase.py - SQLite handles this well:
create_all()is idempotent (creates missing tables, skips existing)
Do NOT suggest Alembic migrations for new tables - they are unnecessary in this codebase.
This project uses Conventional Commits for automatic semantic versioning.
<type>(<scope>): <description>
[optional body]
[optional footer]
| Type | Version Bump | Description |
|---|---|---|
feat |
MINOR | New feature |
fix |
PATCH | Bug fix |
perf |
PATCH | Performance improvement |
refactor |
PATCH | Code refactoring |
docs |
none | Documentation only |
style |
none | Formatting, no code change |
test |
none | Adding/updating tests |
chore |
none | Maintenance tasks |
ci |
none | CI/CD changes |
build |
none | Build system changes |
Add ! after type or include BREAKING CHANGE: in footer for MAJOR version bump:
feat!: remove deprecated API endpoint
feat(strategy): add momentum indicator
fix(api): handle rate limit errors
perf(db): optimize trade query
docs: update README setup instructions
chore(deps): update pandas to 2.0Do NOT manually edit src/version.py.
Versions are automatically bumped when PRs merge to main based on commit types.
When creating new configuration parameters:
- Add the field to
config/settings.pywith proper Field validation - MUST update
.env.examplewith the recommended default and documentation - Use descriptive comments explaining the parameter's purpose and valid range
main: Production branch (deployed to server)develop: Development/integration branchfeature/*: Feature branches (e.g.,feature/add-stop-loss)fix/*: Bug fix branches (e.g.,fix/telegram-timeout)
- Create feature/fix branch from
develop - Make changes and commit using conventional commit format
- Push and create PR to
develop - After review, merge to
develop - When ready for release, create PR from
developtomain
Before creating a PR from develop to main:
git fetch origin main
git rebase origin/main # Ensure develop is up-to-date with main
git push --force-with-lease # Update remote develop
git log origin/main..develop --oneline # See actual new commitsThis ensures the PR only shows commits that are actually new.
- All merges to
mainmust be done via pull requests - Direct commits to
mainare not allowed - NEVER delete the
developbranch - feature branches depend on it. Do NOT use--delete-branchwhen merging PRs from develop to main. - ALWAYS check that a PR is still OPEN before pushing commits to it - use
gh pr view {NUMBER} --json state
This is a FINANCIAL TRADING SYSTEM. All PR review comments MUST be fetched and thoroughly analyzed before merging.
| Priority | Symbol | Action Required |
|---|---|---|
| Critical | 🔴 | MUST fix before merge - blocks deployment |
| High | 🟡 | MUST fix before merge - financial system requirement |
| Low | 🟢 | Fix if straightforward, otherwise document and create issue |
Both 🔴 Critical AND 🟡 High priority issues trigger automatic fix workflows.
# Get all comments on a PR (includes bot reviews)
gh api repos/Byte-Ventures/claude-trader/issues/{PR_NUMBER}/comments
# Get code review comments (inline)
gh api repos/Byte-Ventures/claude-trader/pulls/{PR_NUMBER}/comments
# View PR with all details
gh pr view {PR_NUMBER} --commentsUse gh api instead of gh pr edit to avoid GitHub Projects Classic deprecation errors:
# Update PR title
gh api repos/Byte-Ventures/claude-trader/pulls/{PR_NUMBER} -X PATCH -f title="new title"
# Update PR body
gh api repos/Byte-Ventures/claude-trader/pulls/{PR_NUMBER} -X PATCH -f body="new body"
# Get PR info
gh api repos/Byte-Ventures/claude-trader/pulls/{PR_NUMBER} --jq '.title, .state'- Critical issues (🔴) - MUST fix before merge
- High priority issues (🟡) - MUST fix before merge (financial system)
- Low priority issues (🟢) - Fix if straightforward, or create GitHub issue
- Security concerns require immediate attention
- After fixes, push new commit and re-request review if needed
The claude[bot] automatically reviews PRs. Its comments appear under /issues/{PR_NUMBER}/comments. Always read these thoroughly - they may identify:
- Type errors
- Security vulnerabilities
- Missing error handling
- API compatibility issues
All issues identified in PR reviews MUST be handled. Do NOT ignore or dismiss issues.
This is a financial trading system. Every identified issue could affect money or data integrity. Ignoring issues is unacceptable.
First, verify the issue - Check if the issue actually exists in the code (bot reviews can be wrong).
Then, do ONE of the following:
- Fix it - Commit a fix addressing the issue
- Document why it's not an issue - Add a code comment explaining why the concern doesn't apply
- Defer to GitHub issue - Create a GitHub issue to track the fix for a future PR (use
gh issue create) - Explicitly decline - Document in PR comments why the suggestion won't be implemented
No issue should be left unacknowledged. When summarizing PR reviews, create a checklist showing how each issue was handled.
Priority levels:
- 🔴 Critical - MUST fix before merge
- 🟡 High/Medium - MUST fix before merge (financial system requirement)
- 🟢 Low - Fix if straightforward, otherwise create GitHub issue
Any PR review issue that is not fixed in the current PR MUST have a GitHub issue created.
This ensures:
- Nothing falls through the cracks
- Issues are tracked and searchable
- Future work is documented with full context
When creating issues for deferred PR review items:
gh issue create --title "Brief description" --body "## Summary
...
## Context
From PR #XX review (bot review, YYYY-MM-DD)
## Priority
Low/Medium/High"When making changes to this codebase:
- Read first, code second - Understand the codebase before making changes
- Verify, don't invent - Check that APIs/methods exist before using them
- Minimal changes - Fix only what's needed, don't refactor or "improve"
- Follow patterns - Check similar files for existing conventions
- No new dependencies - Unless the issue explicitly requires them
- Stay focused - Don't modify unrelated code
- Test both modes - Run tests that cover paper and live trading
- Note uncertainties - If the issue is ambiguous, document assumptions in PR
These paths affect money and safety - changes require extra verification:
src/safety/- Circuit breaker, kill switch, loss limitersrc/api/*_client.py- Exchange integration (order execution)config/settings.py- Core configuration
These labels must exist for automation to work:
| Label | Purpose |
|---|---|
auto-fix |
Triggers automatic issue fixing via Claude |
fix-in-progress |
Applied when auto-fix is working on an issue |
post-mortem |
Marks issues derived from post-mortem analysis |
review-retry-N |
Created automatically (N=1,2,3) to track fix attempts |
Create a post-mortems discussion category with:
- Format: Announcement (restricts creation to maintainers)
- Purpose: Post-mortem analysis from
tools/postmortem.py
Post-mortem discussion created
↓
claude-postmortem-review.yml analyzes fixes
↓
Issue created with 'auto-fix' label
↓
claude-auto-fix.yml implements fix
↓
PR created to develop
↓
claude[bot] reviews PR
↓
If 🔴 critical OR 🟡 high priority issues:
claude-address-review.yml fixes them (max 3 retries)
↓
Human reviews and merges PR
↓
close-linked-issues.yml closes referenced issues
↓
semantic-release.yml bumps version on main
To manually trigger auto-fix on any issue:
- Ensure you have write access to the repo
- Add the
auto-fixlabel to the issue - Monitor the Actions tab for progress