# Trade Desk

**trade-desk.infinity-sdg.com** — order management with pre-trade risk controls: limits checked before an order leaves, restricted instruments blocked, kill switches, and four-eyes overrides.

```
trader → book (desk) → exposure limits (max order notional, max position, daily loss)
instrument (tradable, or on the restricted list with the reason)
ticket: draft → release → released → filled | canceled | expired
  release runs the pre-trade checks:
    · no kill switch engaged for the firm or the ticket's desk
    · the instrument isn't restricted
    · notional within the book's max-order limit, or an override approved by risk
override: requested by the trader → approved or rejected by a different risk officer
kill switch: engaged (firm / desk / book) → released by a different person
fills: append-only executions against released tickets
daily at the close: released day orders that didn't fill expire
```

## What it enforces

| Rule | Why |
|---|---|
| Nothing is released while a kill switch is engaged for the firm or the desk | One switch stops new orders everywhere it covers |
| Restricted instruments can't be released | Compliance's restricted list holds at the order level |
| A ticket over its book's max-order limit needs an approved override | Limits are checked before the order leaves, not after |
| Whoever requested an override can't approve it | Four eyes on every limit breach |
| The person who engaged a kill switch can't release it | Independent sign-off to resume |
| Fills attach only to released tickets; a ticket is marked filled only with fills on record | The blotter matches the executions |
| Every cancel states its reason; a restricted instrument states why | Nothing disappears silently |

Every resource is audited. Tickets and kill switches keep a readable history.

## Resources, views, roles

- **Resources:** trader, book, exposurelimit, instrument, ticket, override, killswitch, fill
- **Views:** `blotter`, `overridesPending`, `engagedKillSwitches`
- **Roles:**
  - `trader`: enters, releases and cancels tickets; requests overrides
  - `risk`: limits, overrides, kill switches, cancels
  - `ops`: fills, completion, expiry, reference data
  - `admin`

## Demo data

The demo has 12 books across five desks: equities, rates, FX, crypto and commodities. Each book has a max-order limit and a position limit, and one position limit is suspended.

The 58 tickets cover every state:

- 25 filled, including 5 that were over their limit and were released under an override a different risk officer approved
- 16 working:
  - 14 partly filled
  - 1 over its limit under an approved override, partly filled
  - 1 not yet executed
- 7 canceled:
  - 3 by the client
  - 3 after risk rejected the override
  - 1 on the restricted instrument
- 4 day orders expired at the close
- 6 drafts, including 2 over their limit and waiting on an override, and 1 on the restricted instrument

Nine past kill switches were each engaged and released by different people: a stale feed, a runaway strategy, an exchange halt and others. One is **engaged right now** on the crypto desk, so no crypto ticket can be released until risk lifts it.

Every decision is made by the demo user who would make it (`trader1`–`trader3`, `risk1`, `risk2`, `ops1`), with that user's own roles. That needs Kalos seeder 1.2.0 or later.

Instruments, prices, venues and people are all invented. To regenerate the data, run `python3 seeds/gen_seed.py`.

## Front end

- **`frontend/index.html`**: the home page. It shows live counts, follows one over-limit order from entry to fill, lists the seven rules, and has a **Try it** button for each that sends the forbidden action to the live server and shows its refusal.
- **`frontend/app/`**: the desk, with one console for each of the trader, risk and operations roles. It has the blotter, tickets with their pre-trade checks and history, overrides, kill switches, limits and the restricted list. Every button calls the API, and every refusal is shown in the server's words.
- **`frontend/exposure/`**: every working order against its book's limit, in 3D (three.js) or as a flat chart when WebGL is missing or reduced motion is set. A smaller version is the home page's hero.
- **`frontend/kit.json`**: one forbidden action per rule, using the seed's fixed ids. The home page uses it, and so will the shared demo kit (datajango/kalos#2139).
- **`docs/research/`**: the audience, palette, type and mark the pages follow.

Dependencies:
- three.js 0.187.0 (MIT), vendored as one minified module at `frontend/vendor/three/`. Rebuild it with `scripts/vendor/build-three.sh`.
- Nothing else. There is no build step: `democtl.py landing` publishes `frontend/` exactly as it is.

```bash
scripts/serve.py                                      # serves frontend/ and proxies /api to kalosd on :9221, like Caddy
scripts/check-assets.sh pages http://127.0.0.1:8321   # pages, API paths, and the seven refusals
scripts/check-assets.sh scene http://127.0.0.1:8321   # the 3D scene against the live data, headless
```

## Run it

```bash
scripts/kalos.sh validate    # static checks
scripts/kalos.sh start       # kalosd on :9221
scripts/kalos.sh verify      # live checks
```

By default, `KALOS_REPO` is `../kalos`.

Sign in with `admin` / `Admin123!`. The other users are `trader1`, `trader2`, `trader3`, `risk1`, `risk2` and `ops1`, all with password `Demo123!`.

## Reselling

This is an original ISDG product for trading desks, brokers and fund operations. It has no customer data and no third-party branding. It is a control layer, not an execution venue: in a real deployment, routing and fills come from the firm's own OMS or FIX connections.
