# Yahoo Finance Stock Price Patterns

## Fetching Live Prices (No API Key)

```python
import urllib.request
import json

url = f"https://query1.finance.yahoo.com/v8/finance/chart/{ticker}"
req = urllib.request.Request(url, headers={"User-Agent": "Mozilla/5.0"})
with urllib.request.urlopen(req, timeout=15) as resp:
    data = json.loads(resp.read().decode())
    result = data["chart"]["result"][0]
    price = result["meta"].get("regularMarketPrice") or result["meta"].get("previousClose")
```

## Threshold Alert Tracking (Stateful)

Use a JSON state file to avoid firing duplicate alerts:

```python
from pathlib import Path
import json

STATE_FILE = Path("/home/user/.hermes/scripts/stock_monitor_state.json")

THRESHOLDS = [50, 75, 100, 125, 150, 175, 200, 225, 250, 275, 300]

def load_state():
    return json.loads(STATE_FILE.read_text()) if STATE_FILE.exists() else {}

def save_state(state):
    STATE_FILE.write_text(json.dumps(state, indent=2))

# Per-ticker state: {last_price, triggered_below: [], triggered_above: []}
```

Alert when price crosses a threshold and the crossing hasn't been recorded yet. Reset state entries when price moves far enough away to allow re-alerting later.

## Tickers Used in Production

- TSLA — Tesla
- SPCX — SpaceX (private, proxy via secondary market if available)
- NVDA — NVIDIA
- AAPL — Apple
- AMD — AMD
- MSFT — Microsoft
- GOOGL — Alphabet
- META — Meta
- AMZN — Amazon
- BTC-USD — Bitcoin USD

## Briefing Integration

Call `fetch_price()` inside the morning briefing script, format results as a simple bulleted list, and insert between news and compliments sections.

## No External Dependencies

The Yahoo Finance endpoint works with Python stdlib only (`urllib`, `json`). No `yfinance`, `requests`, or other packages required.
