Add complete Ouroboros trading system with TDD test suite
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:
2026-02-04 02:08:48 +09:00
parent 9d9945822a
commit d1750af80f
27 changed files with 1842 additions and 0 deletions

59
src/db.py Normal file
View File

@@ -0,0 +1,59 @@
"""Database layer for trade logging."""
from __future__ import annotations
import sqlite3
from datetime import datetime, timezone
from typing import Any
def init_db(db_path: str) -> sqlite3.Connection:
"""Initialize the trade logs database and return a connection."""
conn = sqlite3.connect(db_path)
conn.execute(
"""
CREATE TABLE IF NOT EXISTS trades (
id INTEGER PRIMARY KEY AUTOINCREMENT,
timestamp TEXT NOT NULL,
stock_code TEXT NOT NULL,
action TEXT NOT NULL,
confidence INTEGER NOT NULL,
rationale TEXT,
quantity INTEGER,
price REAL,
pnl REAL DEFAULT 0.0
)
"""
)
conn.commit()
return conn
def log_trade(
conn: sqlite3.Connection,
stock_code: str,
action: str,
confidence: int,
rationale: str,
quantity: int = 0,
price: float = 0.0,
pnl: float = 0.0,
) -> None:
"""Insert a trade record into the database."""
conn.execute(
"""
INSERT INTO trades (timestamp, stock_code, action, confidence, rationale, quantity, price, pnl)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
""",
(
datetime.now(timezone.utc).isoformat(),
stock_code,
action,
confidence,
rationale,
quantity,
price,
pnl,
),
)
conn.commit()