fix: dashboard broker badge reflects BROKER env (PAPER · TRADIER etc.)
Badge text was hardcoded to ALPACA; _broker_block now reports the active broker name and derives paper/live from the Tradier sandbox host when BROKER=tradier, keeping the base-URL-truth rule from plan 007. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
154e44e8d5
commit
52144241b4
2 files changed
+14
-3
No files matched your search
+12
-2
@@ -86,12 +86,22 @@ def _command_bus_enabled() -> bool:
|
||||
def _broker_block() -> dict:
|
||||
"""Broker truth for the LIVE badge, derived from the base URL the services
|
||||
already have (not the execution_mode literal, which lied). Alpaca's paper host
|
||||
is ``paper-api.alpaca.markets``; anything else is live money."""
|
||||
is ``paper-api.alpaca.markets``; Tradier's sandbox host starts with
|
||||
``sandbox.``; anything else is live money."""
|
||||
from urllib.parse import urlparse as _urlparse
|
||||
|
||||
if os.environ.get("BROKER", "alpaca").strip().lower() == "tradier":
|
||||
url = os.environ.get("TRADIER_BASE_URL") or (
|
||||
"https://api.tradier.com/v1"
|
||||
if os.environ.get("TRADIER_ENV", "sandbox").strip().lower() == "live"
|
||||
else "https://sandbox.tradier.com/v1")
|
||||
host = _urlparse(url).hostname or url
|
||||
return {"name": "TRADIER", "base_url_host": host,
|
||||
"is_paper": host.startswith("sandbox.")}
|
||||
url = os.environ.get("ALPACA_BASE_URL") or "https://paper-api.alpaca.markets"
|
||||
host = _urlparse(url).hostname or url
|
||||
return {"base_url_host": host, "is_paper": host.startswith("paper-api")}
|
||||
return {"name": "ALPACA", "base_url_host": host,
|
||||
"is_paper": host.startswith("paper-api")}
|
||||
|
||||
|
||||
def _eastern_session_date():
|
||||
|
||||
@@ -1422,7 +1422,8 @@ function render(d) {
|
||||
const broker = d.broker || {};
|
||||
const isPaper = broker.is_paper !== false; // default to paper when unknown
|
||||
const badge = $("mode-badge");
|
||||
badge.textContent = isPaper ? "PAPER · ALPACA" : "LIVE · ALPACA";
|
||||
const brokerName = broker.name || "ALPACA";
|
||||
badge.textContent = (isPaper ? "PAPER · " : "LIVE · ") + brokerName;
|
||||
badge.className = "badge " + (isPaper ? "paper" : "live");
|
||||
const acct0 = (d.accounts || [])[0] || {};
|
||||
badge.title = (broker.base_url_host || "") + (acct0.account_id ? " · " + acct0.account_id : "");
|
||||
|
||||
Reference in new issue
Block a user