44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
from sqlalchemy import create_engine, Column, Integer, String, Float, DateTime, Text
|
|
from sqlalchemy.orm import declarative_base, sessionmaker
|
|
from datetime import datetime
|
|
from config import settings
|
|
|
|
Base = declarative_base()
|
|
engine = create_engine(settings.db_path, echo=False)
|
|
SessionLocal = sessionmaker(bind=engine)
|
|
|
|
class BotDecision(Base):
|
|
__tablename__ = "decisions"
|
|
id = Column(Integer, primary_key=True)
|
|
ts = Column(DateTime, default=datetime.utcnow)
|
|
symbol = Column(String(16), index=True)
|
|
action = Column(String(16)) # buy/sell/hold
|
|
confidence = Column(Float)
|
|
reason = Column(Text)
|
|
market_context = Column(Text)
|
|
order_usd = Column(Float)
|
|
status = Column(String(32), default="planned")
|
|
|
|
class TradeExecution(Base):
|
|
__tablename__ = "trades"
|
|
id = Column(Integer, primary_key=True)
|
|
ts = Column(DateTime, default=datetime.utcnow)
|
|
symbol = Column(String(16), index=True)
|
|
side = Column(String(8))
|
|
qty = Column(Float)
|
|
notional = Column(Float)
|
|
alpaca_order_id = Column(String(128))
|
|
raw = Column(Text)
|
|
|
|
class CuratedInsight(Base):
|
|
__tablename__ = "insights"
|
|
id = Column(Integer, primary_key=True)
|
|
ts = Column(DateTime, default=datetime.utcnow)
|
|
symbol = Column(String(16), index=True)
|
|
summary = Column(Text)
|
|
sources = Column(Text)
|
|
|
|
|
|
def init_db():
|
|
Base.metadata.create_all(bind=engine)
|