first vibe coding
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
"""
|
||||
db/models.py - SQLite 스키마 생성
|
||||
기획서 v2.1 기준 4개 테이블
|
||||
"""
|
||||
import sqlite3
|
||||
import os
|
||||
|
||||
DB_PATH = os.getenv("DB_PATH", "data/stockbot.db")
|
||||
|
||||
def init_db():
|
||||
os.makedirs(os.path.dirname(DB_PATH), exist_ok=True)
|
||||
conn = sqlite3.connect(DB_PATH)
|
||||
c = conn.cursor()
|
||||
|
||||
# 체결 내역
|
||||
c.execute("""
|
||||
CREATE TABLE IF NOT EXISTS trades (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
date TEXT NOT NULL,
|
||||
ticker TEXT NOT NULL,
|
||||
name TEXT,
|
||||
entry_time TEXT NOT NULL,
|
||||
exit_time TEXT,
|
||||
entry_price REAL NOT NULL,
|
||||
exit_price REAL,
|
||||
quantity INTEGER NOT NULL,
|
||||
side TEXT NOT NULL,
|
||||
exit_reason TEXT,
|
||||
pnl REAL,
|
||||
fee REAL,
|
||||
slippage REAL,
|
||||
strategy TEXT DEFAULT 'VB',
|
||||
ai_boosted INTEGER DEFAULT 0
|
||||
)""")
|
||||
|
||||
# 일일 요약
|
||||
c.execute("""
|
||||
CREATE TABLE IF NOT EXISTS daily_summary (
|
||||
date TEXT PRIMARY KEY,
|
||||
total_trades INTEGER DEFAULT 0,
|
||||
win_trades INTEGER DEFAULT 0,
|
||||
lose_trades INTEGER DEFAULT 0,
|
||||
gross_pnl REAL DEFAULT 0,
|
||||
total_fee REAL DEFAULT 0,
|
||||
net_pnl REAL DEFAULT 0,
|
||||
max_drawdown REAL DEFAULT 0,
|
||||
trading_stopped INTEGER DEFAULT 0
|
||||
)""")
|
||||
|
||||
# 포지션 (장중 현황)
|
||||
c.execute("""
|
||||
CREATE TABLE IF NOT EXISTS positions (
|
||||
ticker TEXT PRIMARY KEY,
|
||||
name TEXT,
|
||||
entry_time TEXT,
|
||||
entry_price REAL,
|
||||
quantity INTEGER,
|
||||
tp1_done INTEGER DEFAULT 0,
|
||||
target_price REAL,
|
||||
stop_price REAL,
|
||||
ai_boosted INTEGER DEFAULT 0
|
||||
)""")
|
||||
|
||||
# AI 판단 이력
|
||||
c.execute("""
|
||||
CREATE TABLE IF NOT EXISTS ai_context_log (
|
||||
date TEXT PRIMARY KEY,
|
||||
generated_at TEXT,
|
||||
trade_allowed INTEGER,
|
||||
market_sentiment TEXT,
|
||||
sentiment_score INTEGER,
|
||||
risk_level TEXT,
|
||||
hot_sectors TEXT,
|
||||
avoid_sectors TEXT,
|
||||
boosted_tickers TEXT,
|
||||
blacklist_tickers TEXT,
|
||||
position_size_mult REAL,
|
||||
reason TEXT,
|
||||
claude_tokens_used INTEGER,
|
||||
api_call_success INTEGER DEFAULT 1
|
||||
)""")
|
||||
|
||||
conn.commit()
|
||||
conn.close()
|
||||
print(f"DB 초기화 완료: {DB_PATH}")
|
||||
|
||||
def get_conn():
|
||||
return sqlite3.connect(DB_PATH)
|
||||
Reference in New Issue
Block a user