-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
75 lines (62 loc) · 3.22 KB
/
Copy pathmodels.py
File metadata and controls
75 lines (62 loc) · 3.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import datetime
from sqlalchemy import Column, Integer, String, Float, DateTime, JSON
from database import Base
class PredictionRecord(Base):
__tablename__ = "prediction_records"
id = Column(Integer, primary_key=True, index=True)
asset = Column(String, index=True) # "BTC" or "ETH"
timestamp = Column(DateTime, default=datetime.datetime.utcnow, index=True)
current_price = Column(Float, nullable=False)
# Prediction market details from Polymarket and Kalshi
polymarket_info = Column(JSON, nullable=True) # Market details, title, Yes/No contracts
kalshi_info = Column(JSON, nullable=True) # Market details, ticker, odds
# Preprocessed indicators from Data Collection Agent
technical_indicators = Column(JSON, nullable=True) # EMA, RSI, MACD
# Prediction details from Prediction Agent (Kronos)
predicted_direction = Column(String, nullable=False) # "UP" or "DOWN"
probability = Column(Float, nullable=False) # Probability/Confidence (e.g. 0.58)
# Risk parameters from Risk Agent
kelly_fraction = Column(Float, nullable=False) # Pure Kelly fraction
bet_size = Column(Float, nullable=False) # Actual sized bet fraction (e.g. Quarter Kelly)
# Resolution details for the Feedback Loop
status = Column(String, default="PENDING") # "PENDING", "RESOLVED", "FAILED"
actual_direction = Column(String, nullable=True) # "UP" or "DOWN" at check time
actual_close = Column(Float, nullable=True) # Actual price at resolution
profit_loss = Column(Float, nullable=True) # Theoretical PnL based on sized bet
resolved_at = Column(DateTime, nullable=True)
error_message = Column(String, nullable=True)
def to_dict(self):
return {
"id": self.id,
"asset": self.asset,
"timestamp": self.timestamp.isoformat() if self.timestamp else None,
"current_price": self.current_price,
"polymarket_info": self.polymarket_info,
"kalshi_info": self.kalshi_info,
"technical_indicators": self.technical_indicators,
"predicted_direction": self.predicted_direction,
"probability": self.probability,
"kelly_fraction": self.kelly_fraction,
"bet_size": self.bet_size,
"status": self.status,
"actual_direction": self.actual_direction,
"actual_close": self.actual_close,
"profit_loss": self.profit_loss,
"resolved_at": self.resolved_at.isoformat() if self.resolved_at else None,
"error_message": self.error_message
}
class AgentLog(Base):
__tablename__ = "agent_logs"
id = Column(Integer, primary_key=True, index=True)
timestamp = Column(DateTime, default=datetime.datetime.utcnow, index=True)
agent_name = Column(String, index=True)
level = Column(String, default="INFO")
message = Column(String, nullable=False)
def to_dict(self):
return {
"id": self.id,
"timestamp": self.timestamp.isoformat() if self.timestamp else None,
"agent_name": self.agent_name,
"level": self.level,
"message": self.message
}