-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdaily.py
More file actions
35 lines (26 loc) · 1.15 KB
/
daily.py
File metadata and controls
35 lines (26 loc) · 1.15 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
"""Daily asynchronous workflow for capturing market scores."""
from __future__ import annotations
import asyncio
import logging
from typing import List, Tuple
from data_fetcher import RawFinancialData, fetch_raw
from db import get_connection, get_portfolio, insert_daily_analysis
from evaluator import evaluate
LOGGER = logging.getLogger(__name__)
async def run_daily() -> None:
"""Fetch scores for the current portfolio and persist them."""
async with await get_connection() as conn:
portfolio = await get_portfolio(conn)
analyses: List[Tuple[str, float, str, float]] = []
for position in portfolio:
raw: RawFinancialData | None = fetch_raw(position["ticker"])
if raw is None:
LOGGER.warning("Skipping %s due to missing market data", position["ticker"])
continue
score, decision = evaluate(raw)
price = float(raw.get("price") or 0)
analyses.append((position["ticker"], score, decision, price))
await insert_daily_analysis(conn, analyses)
if __name__ == "__main__":
logging.basicConfig(level=logging.INFO)
asyncio.run(run_daily())