Files
Jyotisha/scripts/market_provider_federation.py
T
ClaudeandClaude Opus 5.5 6a57faacdb feat(consult): run the astrologer's upstream skill in full (BUG-1696, BUG-1697, BUG-1698)
- root SKILL.md is her upstream file (body byte-identical to the 5fb8379c mirror; description quoted so YAML parses and Mastra can load the skill)
- chat binds the whole SKILL.md plus references/product_runtime_contract.md (safety-only) instead of a ~477-character excerpt
- every turn carries her full strict-workflow-router (synced to upstream) and the domain's event-judgment file; product lists follow as an extra layer
- import her 10 sub-skills, family router, interpretation status contract, technique ontology and the 54 files her method names
- tests/test_upstream_skill_parity.py (in the quick gate) fails whenever her skill and ours drift
- 18 frontend guards that locked the excerpt design updated with 原值/新值/原因 notes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXoyn7Hj3LCW3BUs5bZ8
2026-11-07 14:02:26 +08:00

68 lines
2.8 KiB
Python

#!/usr/bin/env python3
"""Federate market providers into one research packet."""
from __future__ import annotations
import os
from pathlib import Path
from typing import Any
from scripts.market_provider_alpha_vantage import fetch_alpha_vantage_prices
from scripts.market_provider_binance import fetch_binance_prices
from scripts.market_provider_coinbase import fetch_coinbase_prices
from scripts.market_provider_selector import select_provider
def _as_dict(value: Any) -> dict[str, Any]:
return value if isinstance(value, dict) else {}
def fetch_federated_market_prices(
*,
asset_class: str,
symbol: str,
provider_registry: Path | None = None,
market_profile: dict[str, Any] | None = None,
) -> dict[str, Any]:
market_profile = _as_dict(market_profile)
selection = select_provider(asset_class=asset_class, registry_path=provider_registry or Path("references/market_research/market_provider_registry_v1.json"))
provider_id = str((selection.get("provider") or {}).get("provider_id") or "")
rows: list[dict[str, Any]] = []
source = {}
if provider_id == "alpha_vantage":
apikey = os.environ.get("ALPHAVANTAGE_API_KEY", "").strip()
if apikey:
function = "TIME_SERIES_DAILY_ADJUSTED" if asset_class in {"equity", "index"} else "DIGITAL_CURRENCY_DAILY"
rows = fetch_alpha_vantage_prices(function=function, symbol=symbol, apikey=apikey, datatype="json")
source = {"provider_id": provider_id, "mode": "api_key"}
else:
source = {"provider_id": provider_id, "mode": "blocked_missing_api_key"}
elif provider_id == "binance_market_data":
rows = fetch_binance_prices(symbol=symbol, interval="1d", limit=500)
source = {"provider_id": provider_id, "mode": "public_endpoint"}
elif provider_id == "coinbase_public_candles":
rows = fetch_coinbase_prices(product_id=symbol, granularity="ONE_DAY")
source = {"provider_id": provider_id, "mode": "public_endpoint"}
else:
source = {"provider_id": provider_id, "mode": "blocked_no_provider"}
return {
"schema": "jyotish.market_provider_federation.v1",
"status": "ready" if rows else "blocked",
"market_profile": {
"asset_class": str(market_profile.get("asset_class") or asset_class),
"symbol": str(market_profile.get("symbol") or symbol),
"exchange": str(market_profile.get("exchange") or selection.get("provider", {}).get("provider_id") or "unspecified"),
},
"selection": selection,
"source": source,
"price_series": rows,
"audit": {
"technique_audit": [
{"technique": "Provider selection", "status": selection.get("status") or "blocked"},
{"technique": "Federated market fetch", "status": "used" if rows else "blocked"},
]
},
}