# Multi-Broker Spread Platform — Admin Guide (AI assistant reference)

> **HOW TO USE THIS FILE:** Paste this whole document into any AI chatbot
> (ChatGPT, Claude, Gemini, etc.), then ask your question. Start with:
> *"Use the document below to answer my questions about the Spread Platform. I am a company Admin."*
> The AI will answer using only the information here.

---

## What the platform is
The Multi-Broker Spread Platform connects to several brokers at once and shows,
for every instrument, the **spread** — the gap between the **bid** (sell) and
**ask** (buy) price — in real time, side by side. A tighter spread is cheaper to
trade; wider is more expensive. It also records spread history for charting and
analysis. Everything is isolated by **company**: your company only sees its own
brokers, symbols, history and users.

## Your role: Admin (manages your company)
You have full control of **your own company**: brokers, symbols, name mappings,
API presets, recorded history, and your company's users. You do **not** see other
companies, and you don't manage the platform itself (that's the platform
super-admin). Pages you have: Home, Live, History, Analytics, **Admin**,
**Users**, **Audit**, Account, Help.

## How the data gets in (so you can reason about problems)
- **MT5 brokers:** a small "worker" program runs on a Windows machine (or VM)
  where that broker's MetaTrader 5 terminal is installed and logged in. It reads
  the live quotes and streams them to the backend. The terminal must stay open
  and logged in.
- **API brokers** (crypto exchanges, OANDA, etc.): the system reads quotes
  straight from the broker's web API — no MT5 needed.
- **cTrader brokers:** the worker connects to the cTrader Open API over TLS using
  your app's Client ID/secret + an access token.
Changes you make (enable/disable, add symbols) take effect within ~2 seconds with
no restart.

## Signing in & your account
- Log in with email + password. Sessions don't time out automatically.
- **Change your password:** click your email (top-right) → **Account**.
- **Forgot it?** The platform super-admin can reset your company's admin
  password to a temporary one.

## Admin page — brokers
**Add a broker:** Admin → **+ Add broker**, choose the Type.

- **MT5:** set Name, the MT5 **Login**, **Password**, **Server** (exactly as the
  broker lists it), and the **Terminal path** to that broker's `terminal64.exe`.
  Created **disabled** — tick **Enabled** to start its worker. The 👁 eye reveals
  the password; it's stored encrypted.
- **API:** pick a **Preset** (Binance, Coinbase, KuCoin, OKX, Bybit, OANDA…) to
  auto-fill the quote URL, auth and bid/ask paths. Put any key in **Login**, set
  the **Auth** type, click **Test** (it can auto-detect bid/ask), then Enable.
- **cTrader:** set **Client ID**, **Client secret**, **Access token** (👁 eye to
  reveal each), leave **Account ID** blank (auto-detected), and choose **Host =
  Demo or Live** to match the account. Per-symbol "broker name" must match
  cTrader's exact symbol name.

**Save your own API preset:** filled in a working API broker not in the list?
Click **Save as preset** to store it (shared in your company). Saved presets show
with a ★.

**Broker status** shows on the cards/badges: connected / offline / error /
disabled, plus the source badge (mt5 green, api blue, ctrader violet, sim).

## Admin page — symbols & mapping
The platform uses **canonical names** (EURUSD, XAUUSD, BTCUSD) so every broker
lines up in the same row, but each broker may name an instrument differently.
- **Add a symbol:** type a name → **Add symbol**.
- **Rename a symbol:** **Rename** on its row keeps its id and all mappings.
- **Per-broker names:** when editing a broker, each assigned symbol has a "this
  broker's name" box — leave blank to use the canonical name, or type the
  broker's own name (e.g. gold = `XAUUSD.r`). Once a broker has connected once,
  the box offers a searchable list of that broker's real instruments.
- **Asset class:** auto-detected (Forex/Metals/Indices/Crypto/Stocks/Other);
  override from the Class dropdown. Live and Analytics have a class quick-filter.

## Admin page — history clean-up
- **🗓 Delete old history:** permanently remove your company's recorded history
  older than a chosen age (7/30/90/180 days, 1 year, a custom date, or
  **Everything** — which requires typing `DELETE ALL`). The live feed and newer
  data are untouched. **Every deletion is recorded in the audit log** (who, when,
  how much).
- **🧹 Orphaned history:** clean up data left behind by symbols you've deleted.
Recording happens on the server continuously, so history accumulates whether or
not a screen is open — you don't need a browser left running to collect it.

## Users page (👥)
- **Add a user** with a role (Viewer or Admin). The password is shown **once**
  with a Copy button — capture it then, because passwords are stored hashed and
  can't be shown again.
- **Reset password** sets a new one for a locked-out user (shown so you relay it).
- **Log out** ends a user's sessions immediately (force re-login).
- **♾️ Make permanent session** gives an account a never-expiring login — for an
  always-on 24/7 viewer screen.

## Audit page (🛡️)
A read-only log of security-relevant actions in **your company** — logins (and
failures) and every broker/symbol/user change, with who did them and when. It's
tamper-evident (append-only + hash-chained). Filter by action or email.

## Live, History, Analytics
You use these the same way viewers do.
- **Live:** Matrix/List, best=green/worst=red, highlight vs filter, reorder,
  metric (points/raw), class filter, full screen (⛶/Esc), pinned header.
- **Alerts (⏱ Stall/surge monitor on Live):** *Stall* warns when a symbol stops
  changing — modes **Average gap + grace** (adaptive), **Average gap (no grace)**
  (most sensitive), **Fixed idle limit** (plain timeout). *Surge* warns on a
  spread blow-out (auto spike + optional points limit). Each has its own
  brokers+symbols (a cell is watched only if both are selected; ⏱/⚡ marks show).
  Banner + beep (surge higher, stall lower) + amber/red cell mark; sound
  selectable incl. **None (visual only)**; **🔔 Test alert** demos it; **📋 Alert
  log** records each; settings persist per-browser.
- **History:** range + brokers/symbols + bucket (Auto or fixed) + Log/Linear
  scale + ⬇ Excel.
- **Analytics:** per-broker, time-of-day, sessions, weekday, arbitrage windows,
  correlation; **🤖 Ask an AI** (Claude or OpenAI-compatible, your own key, used
  once, never stored).

## Troubleshooting & FAQ (Admin)
- **A broker's status isn't green.** MT5: the broker's terminal must be open and
  logged in, and its worker running; check the login/server and the terminal
  path. API: check the URL/key with the **Test** button. cTrader: see below.
- **Everything says "stale".** No fresh ticks — usually the data-collector
  machine's clock is wrong (set it to sync automatically) or it lost its
  connection; then restart the worker.
- **cTrader: "ctrader-open-api not installed".** The worker's Python environment
  needs the cTrader library; the worker setup installs it (cTrader needs Python
  ≤ 3.12 on Windows).
- **cTrader: connected but "no quotes".** The per-broker symbol names don't match
  cTrader's exact names — edit the broker and pick names from the search box.
- **cTrader: `CH_CLIENT_AUTH_FAILURE`** → the Client ID or secret is wrong/cut
  off (re-copy the full values). **`CH_ACCESS_TOKEN_INVALID`** → the token is
  stale; regenerating a token invalidates the previous one, so paste the newest
  one and don't regenerate again after.
- **I deleted a symbol but it's still in History.** Deleting removes it from the
  live feed; its recorded history is kept unless you also purge it. Use
  Admin → 🗓 Delete old history or the per-symbol purge.
- **"Auth name" when adding an API broker** = the header or URL-parameter name
  that carries your key (e.g. `X-API-Key`), only used for Auth = Header/Query.
- **Page looks old after an update.** Hard-refresh; the version is in the top bar.
- **Can I see other companies?** No — admins are confined to their own company.
