Add opportunity detection and storage functionality with async processing
- Introduced OpportunityEvent class for structured opportunity data. - Enhanced IncrementalCycleDetector to generate opportunities based on updated pairs. - Implemented AsyncOpportunityWriter for persisting opportunities to the database. - Updated MarketDataFeed to handle opportunity detection and execution in both paper and live trading modes. - Added unit tests for opportunity detection and persistence.
This commit is contained in:
@@ -18,6 +18,16 @@ class MarketSnapshotRecord:
|
||||
latency_ms: float | None
|
||||
|
||||
|
||||
@dataclass(slots=True)
|
||||
class OpportunityRecord:
|
||||
detected_at: datetime
|
||||
cycle: str
|
||||
gross_pct: float
|
||||
net_pct: float
|
||||
est_profit: float
|
||||
executed: bool = False
|
||||
|
||||
|
||||
class MarketSnapshotRepository:
|
||||
def __init__(self, store: DuckDBStore) -> None:
|
||||
self._store = store
|
||||
@@ -37,3 +47,32 @@ class MarketSnapshotRepository:
|
||||
record.latency_ms,
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class OpportunityRepository:
|
||||
def __init__(self, store: DuckDBStore) -> None:
|
||||
self._store = store
|
||||
|
||||
def insert(self, record: OpportunityRecord) -> None:
|
||||
with self._store.connect() as conn:
|
||||
conn.execute(
|
||||
"""
|
||||
INSERT INTO opportunities (
|
||||
detected_at,
|
||||
cycle,
|
||||
gross_pct,
|
||||
net_pct,
|
||||
est_profit,
|
||||
executed
|
||||
)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
""",
|
||||
[
|
||||
record.detected_at,
|
||||
record.cycle,
|
||||
record.gross_pct,
|
||||
record.net_pct,
|
||||
record.est_profit,
|
||||
record.executed,
|
||||
],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user