"""Slipstream Space config — everything from env (HF Space secrets) + local data. No cross-project paths: the picks snapshot and caches ship inside the Space.""" import os import re from pathlib import Path APP_DIR = Path(__file__).resolve().parent DATA_DIR = APP_DIR / "data" CACHE_DIR = DATA_DIR # picks caches ship here; refreshes rewrite here SNAPSHOT = DATA_DIR / "smart_money_snapshot.parquet" # --- secrets (set these in the HF Space settings) --- ALPACA_API_KEY = os.getenv("ALPACA_API_KEY", "") ALPACA_SECRET_KEY = os.getenv("ALPACA_SECRET_KEY", "") ALPACA_ENDPOINT = re.sub( r"/v2/?$", "", os.getenv("ALPACA_PAPER_ENDPOINT", "https://paper-api.alpaca.markets").rstrip("/") ) ALPACA_ALLOW_LIVE = os.getenv("ALPACA_ALLOW_LIVE", "0") == "1" ALPHAVANTAGE_API_KEY = os.getenv("ALPHAVANTAGE_API_KEY") or os.getenv("ALPHA_VANTAGE_API_KEY", "") OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", "") ANTHROPIC_API_KEY = os.getenv("ANTHROPIC_API_KEY", "") # Gemini is the preferred picks-screener. Flash-Lite is optimal here: this is a well-specified # batched classification (not heavy reasoning), so Lite is fast (~1s), cheap (~$0.10/mo), # quota-generous (the thinking-tier Flash models 429 on free keys), and "-latest" never deprecates. GEMINI_API_KEY = os.getenv("GEMINI_API_KEY") or os.getenv("GOOGLE_API_KEY", "") GEMINI_MODEL = os.getenv("GEMINI_MODEL", "gemini-flash-lite-latest") # rebalance execution guard: the Space only trades when this is set (belt-and-braces # on top of paper-only). Set REBALANCE_TOKEN as a secret to enable the trigger. REBALANCE_TOKEN = os.getenv("REBALANCE_TOKEN", "") PICKS_CACHE_TTL_HOURS = float(os.getenv("PICKS_CACHE_TTL_HOURS", "24")) # executor: size the book off (1 - CASH_BUFFER) x equity, never 100%. A fully-invested target plus # the min-trade deadband (small overweights are never sold) left the paper account on a standing # margin balance; ~1% cash absorbs fill slippage and drift. See alpaca_client.plan_rebalance. CASH_BUFFER = float(os.getenv("SLIPSTREAM_CASH_BUFFER", "0.01")) HTTP_TIMEOUT = 25 USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)" def alpaca_is_paper() -> bool: return "paper-api" in ALPACA_ENDPOINT