File size: 949 Bytes
048f186 | 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 | """
Shared physical and market constants (troy oz ↔ grams, config keys).
"""
import os
from typing import Final
# Troy ounce (XAU convention in this project) to grams, per user / pricing spec
GRAMS_PER_TROY_OZ: Final[float] = 31.1035
def troy_oz_to_grams(oz: float) -> float:
return round(oz * GRAMS_PER_TROY_OZ, 6)
def grams_to_troy_oz(grams: float) -> float:
if GRAMS_PER_TROY_OZ <= 0:
return 0.0
return round(grams / GRAMS_PER_TROY_OZ, 8)
def get_market_mode() -> str:
"""'real' uses live GC=F + DB; 'synthetic' uses legacy random market (for offline tests)."""
return (os.environ.get("SHOPMANAGER_MARKET_MODE", "real") or "real").lower().strip()
def get_sqlite_path() -> str:
return os.environ.get("SHOPMANAGER_SQLITE_PATH", "").strip() or ""
def default_sqlite_path() -> str:
from pathlib import Path
here = Path(__file__).resolve().parent
return str(here / "data" / "shop_manager.db")
|