Compare commits
5
Commits
620a8f0d91
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c43865cc9c | ||
|
|
987b32d2ff | ||
|
|
e1d1c70d59 | ||
|
|
4f021511fa | ||
|
|
6bde9d2726 |
@@ -99,8 +99,8 @@ services:
|
|||||||
port: 8000
|
port: 8000
|
||||||
secrets: [stonks-core-secrets, stonks-broker-secrets, stonks-gmail-secrets]
|
secrets: [stonks-core-secrets, stonks-broker-secrets, stonks-gmail-secrets]
|
||||||
resources:
|
resources:
|
||||||
requests: { cpu: 100m, memory: 256Mi }
|
requests: { cpu: 100m, memory: 512Mi }
|
||||||
limits: { cpu: 500m, memory: 512Mi }
|
limits: { cpu: 1000m, memory: 1024Mi }
|
||||||
probes:
|
probes:
|
||||||
readiness: { path: /ready, port: 8000, initialDelay: 5, period: 10 }
|
readiness: { path: /ready, port: 8000, initialDelay: 5, period: 10 }
|
||||||
liveness: { path: /health, port: 8000, initialDelay: 10, period: 30 }
|
liveness: { path: /health, port: 8000, initialDelay: 10, period: 30 }
|
||||||
|
|||||||
@@ -159,6 +159,7 @@ class TradingEngine:
|
|||||||
asyncio.create_task(self._performance_loop(), name="performance_loop"),
|
asyncio.create_task(self._performance_loop(), name="performance_loop"),
|
||||||
asyncio.create_task(self._risk_tier_scheduler(), name="risk_tier_scheduler"),
|
asyncio.create_task(self._risk_tier_scheduler(), name="risk_tier_scheduler"),
|
||||||
asyncio.create_task(self._rebalance_scheduler(), name="rebalance_scheduler"),
|
asyncio.create_task(self._rebalance_scheduler(), name="rebalance_scheduler"),
|
||||||
|
asyncio.create_task(self._correlation_startup(), name="correlation_startup"),
|
||||||
]
|
]
|
||||||
logger.info("Trading engine started with %d worker tasks", len(self._tasks))
|
logger.info("Trading engine started with %d worker tasks", len(self._tasks))
|
||||||
|
|
||||||
@@ -598,8 +599,9 @@ class TradingEngine:
|
|||||||
initial_capital, invested, available, reserve_balance, open_count,
|
initial_capital, invested, available, reserve_balance, open_count,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Compute initial correlation matrix from market data
|
# Compute initial correlation matrix from market data (non-blocking)
|
||||||
await self._compute_correlation_matrix()
|
# Launched as a background task in start() to avoid blocking uvicorn startup
|
||||||
|
self._pending_corr_task = True
|
||||||
|
|
||||||
async def _decision_loop(self) -> None:
|
async def _decision_loop(self) -> None:
|
||||||
"""Poll recommendations and evaluate them in a continuous loop.
|
"""Poll recommendations and evaluate them in a continuous loop.
|
||||||
@@ -1340,6 +1342,13 @@ class TradingEngine:
|
|||||||
# Correlation matrix computation
|
# Correlation matrix computation
|
||||||
# ------------------------------------------------------------------
|
# ------------------------------------------------------------------
|
||||||
|
|
||||||
|
async def _correlation_startup(self) -> None:
|
||||||
|
"""Compute correlation matrix in background so uvicorn can start serving."""
|
||||||
|
try:
|
||||||
|
await self._compute_correlation_matrix()
|
||||||
|
except Exception:
|
||||||
|
logger.exception("Background correlation matrix computation failed")
|
||||||
|
|
||||||
async def _compute_correlation_matrix(self) -> None:
|
async def _compute_correlation_matrix(self) -> None:
|
||||||
"""Compute pairwise price correlations from market_snapshots and load into self.correlation_matrix.
|
"""Compute pairwise price correlations from market_snapshots and load into self.correlation_matrix.
|
||||||
|
|
||||||
@@ -1354,7 +1363,7 @@ class TradingEngine:
|
|||||||
rows = await self.pool.fetch(
|
rows = await self.pool.fetch(
|
||||||
"SELECT ticker, captured_at::date AS dt, (data->>'c')::float AS close "
|
"SELECT ticker, captured_at::date AS dt, (data->>'c')::float AS close "
|
||||||
"FROM market_snapshots "
|
"FROM market_snapshots "
|
||||||
"WHERE snapshot_type = 'bar' AND captured_at > NOW() - INTERVAL '30 days' "
|
"WHERE snapshot_type = 'bar' AND captured_at > NOW() - INTERVAL '7 days' "
|
||||||
"ORDER BY ticker, captured_at"
|
"ORDER BY ticker, captured_at"
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
|
|||||||
Reference in New Issue
Block a user