Files
Krikorios 48e60d015f feat: Add Phase 4 advanced metrics and components
- Add advanced metrics dashboard with trade analytics
- Add new trading components (EntryTypeAnalysis, MultiDayPositionTracker, NewsEventTracker, etc.)
- Add strategy mode selector and trend confirmation
- Add risk automation panel and slippage correlation analysis
- Add daily trading plan enhancements with modal components
- Add custom hooks (useApi, useLocalStorage, useAdvancedTradeMetrics)
- Add broker service integration and trading API
- Add test setup and vitest configuration
- Include parquet data files for live market data
- Add comprehensive documentation in docs/ folder
2025-11-27 10:23:58 +02:00

38 lines
1.1 KiB
Python

from __future__ import annotations
from typing import Optional
import httpx
GOLDPRICE_URL_TEMPLATE = "https://data-asg.goldprice.org/dbXRates/{currency}"
DEFAULT_CURRENCY = "USD"
HEADERS = {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0 Safari/537.36",
"Accept": "application/json",
}
async def fetch_goldprice_quote(currency: str = DEFAULT_CURRENCY) -> Optional[dict]:
url = GOLDPRICE_URL_TEMPLATE.format(currency=currency.upper())
async with httpx.AsyncClient(timeout=10.0, headers=HEADERS) as client:
response = await client.get(url)
response.raise_for_status()
data = response.json()
items = data.get("items") or []
if not items:
return None
quote = items[0]
xau_price = quote.get("xauPrice")
if xau_price is None:
return None
return {
"price": float(xau_price),
"change": float(quote.get("chgXau") or 0.0),
"change_percent": float(quote.get("pcXau") or 0.0),
"previous_close": float(quote.get("xauClose") or 0.0),
"timestamp_ms": int(data.get("ts") or 0),
}