INNER CODE UNIT · Python

verify_api_key

flukelaster/ai-trading-agent · mt5_bridge/main.py:43

async def verify_api_key(x_bridge_key: str = Header(...)):
    if not BRIDGE_API_KEY:
        raise HTTPException(status_code=503, detail="Bridge API key not configured")
    if not hmac.compare_digest(x_bridge_key, BRIDGE_API_KEY):
        raise HTTPException(status_code=401, detail="Invalid API key")


# --- MT5 connection helpers ---
def ensure_connected() -> bool:
    if mt5.terminal_info() is not None:
        return True
    logger.warning("MT5 disconnected, attempting reconnect...")
    if not mt5.initialize(MT5_PATH):
        logger.error(f"MT5 initialize failed: {mt5.last_error()}")
        return False
    if MT5_LOGIN and not mt5.login(MT5_LOGIN, password=MT5_PASSWORD, server=MT5_SERVER):
        logger.error(f"MT5 login failed: {mt5.last_error()}")
        return False

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…