Add complete Ouroboros trading system with TDD test suite
Some checks failed
CI / test (push) Has been cancelled
Some checks failed
CI / test (push) Has been cancelled
Implement the full autonomous trading agent architecture: - KIS broker with async API, token refresh, leaky bucket rate limiter, and hash key signing - Gemini-powered decision engine with JSON parsing and confidence threshold enforcement - Risk manager with circuit breaker (-3% P&L) and fat finger protection (30% cap) - Evolution engine for self-improving strategy generation via failure analysis - 35 passing tests written TDD-first covering risk, broker, and brain modules - CI/CD pipeline, Docker multi-stage build, and AI agent context docs Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
58
docs/agents.md
Normal file
58
docs/agents.md
Normal file
@@ -0,0 +1,58 @@
|
||||
# The Ouroboros - Agent Persona Definition
|
||||
|
||||
## Role: The Guardian
|
||||
|
||||
You are **The Guardian**, the primary AI agent responsible for maintaining and evolving
|
||||
The Ouroboros trading system. Your mandate is to ensure system integrity, safety, and
|
||||
continuous improvement.
|
||||
|
||||
## Prime Directives
|
||||
|
||||
1. **NEVER disable, bypass, or weaken `core/risk_manager.py`.**
|
||||
The risk manager is the last line of defense against catastrophic loss.
|
||||
Any code change that reduces risk controls MUST be rejected.
|
||||
|
||||
2. **All code changes require a passing test.**
|
||||
No module may be modified or created without a corresponding test in `tests/`.
|
||||
Run `pytest -v --cov=src` before proposing any merge.
|
||||
|
||||
3. **Preserve the Circuit Breaker.**
|
||||
The daily P&L circuit breaker (-3.0% threshold) is non-negotiable.
|
||||
It may only be made *stricter*, never relaxed.
|
||||
|
||||
4. **Fat Finger Protection is sacred.**
|
||||
The 30% max-order-size rule must remain enforced at all times.
|
||||
|
||||
## Decision Framework
|
||||
|
||||
When modifying code, follow this priority order:
|
||||
|
||||
1. **Safety** - Will this change increase risk exposure? If yes, reject.
|
||||
2. **Correctness** - Is the logic provably correct? Verify with tests.
|
||||
3. **Performance** - Only optimize after safety and correctness are guaranteed.
|
||||
4. **Readability** - Code must be understandable by future agents and humans.
|
||||
|
||||
## File Ownership
|
||||
|
||||
| Module | Guardian Rule |
|
||||
|---|---|
|
||||
| `core/risk_manager.py` | READ-ONLY. Changes require human approval + 2 passing test suites. |
|
||||
| `broker/kis_api.py` | Rate limiter must never be removed. Token refresh must remain automatic. |
|
||||
| `brain/gemini_client.py` | Confidence < 80 MUST force HOLD. This rule cannot be weakened. |
|
||||
| `evolution/optimizer.py` | Generated strategies must pass ALL tests before activation. |
|
||||
| `strategies/*` | New strategies are welcome but must inherit `BaseStrategy`. |
|
||||
|
||||
## Prohibited Actions
|
||||
|
||||
- Removing or commenting out `assert` statements in tests
|
||||
- Hardcoding API keys or secrets in source files
|
||||
- Disabling rate limiting on broker API calls
|
||||
- Allowing orders when the circuit breaker has tripped
|
||||
- Merging code with test coverage below 80%
|
||||
|
||||
## Context for Collaboration
|
||||
|
||||
When working with other AI agents (Cursor, Cline, etc.):
|
||||
- Share this document as the system constitution
|
||||
- All agents must acknowledge these rules before making changes
|
||||
- Conflicts are resolved by defaulting to the *safer* option
|
||||
109
docs/skills.md
Normal file
109
docs/skills.md
Normal file
@@ -0,0 +1,109 @@
|
||||
# The Ouroboros - Available Skills & Tools
|
||||
|
||||
## Development Tools
|
||||
|
||||
### Run Tests
|
||||
```bash
|
||||
pytest -v --cov=src --cov-report=term-missing
|
||||
```
|
||||
Run the full test suite with coverage reporting. **Must pass before any merge.**
|
||||
|
||||
### Run Specific Test Module
|
||||
```bash
|
||||
pytest tests/test_risk.py -v
|
||||
pytest tests/test_broker.py -v
|
||||
pytest tests/test_brain.py -v
|
||||
```
|
||||
|
||||
### Type Checking
|
||||
```bash
|
||||
python -m mypy src/ --strict
|
||||
```
|
||||
|
||||
### Linting
|
||||
```bash
|
||||
ruff check src/ tests/
|
||||
ruff format src/ tests/
|
||||
```
|
||||
|
||||
## Operational Tools
|
||||
|
||||
### Start Trading Agent (Development)
|
||||
```bash
|
||||
python -m src.main --mode=paper
|
||||
```
|
||||
Runs the agent in paper-trading mode (no real orders).
|
||||
|
||||
### Start Trading Agent (Production)
|
||||
```bash
|
||||
docker compose up -d ouroboros
|
||||
```
|
||||
Runs the full system via Docker Compose with all safety checks enabled.
|
||||
|
||||
### View Logs
|
||||
```bash
|
||||
docker compose logs -f ouroboros
|
||||
```
|
||||
Stream JSON-formatted structured logs.
|
||||
|
||||
### Run Backtester
|
||||
```bash
|
||||
python -m src.evolution.optimizer --backtest --days=30
|
||||
```
|
||||
Analyze the last 30 days of trade logs and generate performance metrics.
|
||||
|
||||
## Evolution Tools
|
||||
|
||||
### Generate New Strategy
|
||||
```bash
|
||||
python -m src.evolution.optimizer --evolve
|
||||
```
|
||||
Triggers the evolution engine to:
|
||||
1. Analyze `trade_logs.db` for failing patterns
|
||||
2. Ask Gemini to generate a new strategy
|
||||
3. Run tests on the new strategy
|
||||
4. Create a PR if tests pass
|
||||
|
||||
### Validate Strategy
|
||||
```bash
|
||||
pytest tests/ -k "strategy" -v
|
||||
```
|
||||
Run only strategy-related tests to validate a new strategy file.
|
||||
|
||||
## Deployment Tools
|
||||
|
||||
### Build Docker Image
|
||||
```bash
|
||||
docker build -t ouroboros:latest .
|
||||
```
|
||||
|
||||
### Deploy with Docker Compose
|
||||
```bash
|
||||
docker compose up -d
|
||||
```
|
||||
|
||||
### Health Check
|
||||
```bash
|
||||
curl http://localhost:8080/health
|
||||
```
|
||||
|
||||
## Database Tools
|
||||
|
||||
### View Trade Logs
|
||||
```bash
|
||||
sqlite3 data/trade_logs.db "SELECT * FROM trades ORDER BY timestamp DESC LIMIT 20;"
|
||||
```
|
||||
|
||||
### Export Trade History
|
||||
```bash
|
||||
sqlite3 -header -csv data/trade_logs.db "SELECT * FROM trades;" > trades_export.csv
|
||||
```
|
||||
|
||||
## Safety Checklist (Pre-Deploy)
|
||||
|
||||
- [ ] `pytest -v --cov=src` passes with >= 80% coverage
|
||||
- [ ] `ruff check src/ tests/` reports no errors
|
||||
- [ ] `.env` file contains valid KIS and Gemini API keys
|
||||
- [ ] Circuit breaker threshold is set to -3.0% or stricter
|
||||
- [ ] Rate limiter is configured for KIS API limits
|
||||
- [ ] Docker health check endpoint responds 200
|
||||
Reference in New Issue
Block a user