INNER CODE UNIT · Python
require_key
codedpro/mt5-trade-split-manager · server.py:200
def require_key(x_api_key: Optional[str] = Header(default=None)):
"""Enforce the API key on trading endpoints when one is configured."""
if API_KEY and x_api_key != API_KEY:
raise HTTPException(status_code=401, detail="Invalid or missing API key")
def send_command_to_mt5(command: dict, timeout: int = REQUEST_TIMEOUT) -> dict:
"""Queue a command and wait for its own response. On timeout the command is
abandoned so it will not be executed by the EA on a later poll."""
env = Envelope(command)
command_queue.put(env)
if env.event.wait(timeout):
return env.result
# Timed out: prevent this command from firing late.
env.abandoned = True
raise HTTPException(status_code=504, detail="MT5 timeout - EA not connecting")