---
name: agent-wallstreet-desk
description: Machine-readable agent handbook for W4-F06 Agent-WallStreet-Desk (https://quantdesk.fastmesh.dev) — deterministic four-stage public-disclosure signal extraction (SEC EDGAR Form D/8-K/13F, Polymarket/Kalshi spread, ECB FX XML, ClinicalTrials.gov v2 Phase 3, openFDA/USPTO), SQLite HMAC-SHA256 material-change watch-diff webhooks, and sub-second 10,000-trial Decimal Monte Carlo VaR/CVaR/Half-Kelly/Tornado risk modeling over REST API, Remote /mcp, treg hub, and Causal Bazaar. Strictly $0 billed on empty, unchanged, fake-200, SSRF-blocked, or HTTP 422 signals.
---

# Agent-WallStreet-Desk (`quantdesk.fastmesh.dev`) — Agent Skill Handbook

> **Hard Engineering & Billing Guarantees**:
> 1. **100% Legal Public Data Only**: Official SEC EDGAR disclosures, Polymarket Gamma/CLOB & Kalshi Trade API v2 public quotes, ECB official daily & 90-day FX XML, NIH ClinicalTrials.gov API v2, and FDA Drugs@FDA / Orange Book / USPTO Official Gazette. Zero MNPI, zero paywall bypass, zero login scraping.
> 2. **Strict `$0` Empty-Signal & Guardrail Guarantee (`billed_micros: 0`)**: Strictly `$0` billed on empty payloads, unchanged Stage 3 snapshots or initial baseline registration, fake-200 upstream error/CloudFront/CAPTCHA shells, pre-fetch SSRF blocks (`127.0.0.0/8`, `10/8`, `172.16/12`, `192.168/16`, `169.254/16`, `::1`, non-`http(s)` schemes), or HTTP `422` validation errors.
> 3. **Bit-Exact Reproducibility & SHA-256 Audit Provenance**: Pure Python 3 stdlib `decimal.Decimal` quantization + isolated `random.Random(seed)` 10,000-trial Monte Carlo risk modeling with canonical `content_sha256` and `receipt_sha256` digests on every response.
> 4. **Zero Client Strategy or Holdings Resale (`zero_resale_policy: true`)**: Caller portfolios, watchlists, risk inputs, and trading logic are never resold, pooled across tenants, or used for third-party model training.
>
> **Regulatory Compliance Boundary**: Agent-WallStreet-Desk is a deterministic quantitative data extraction and risk modeling engineering tool only. It is **NOT investment advice** under the U.S. Investment Advisers Act of 1940, **NOT a broker-dealer**, and provides **ZERO asset management, order routing, or custody**. Contact: `support@fastmesh.dev`.

---

## Integration Surfaces & Transparent Pricing

| Surface | Endpoint / Identifier | Protocol & Pricing |
| :--- | :--- | :--- |
| **Remote MCP Server** | `https://quantdesk.fastmesh.dev/mcp` | JSON-RPC 2.0 (`initialize`, `notifications/initialized`, `tools/list`, `tools/call`) |
| **REST + OpenAPI 3.1.0** | `https://quantdesk.fastmesh.dev/openapi.json` | `POST /v1/desk/harvest-signal` (`$0.05`), `POST /v1/desk/watch-diff` (`$0.025` change only), `POST /v1/desk/risk-simulate` (`$0.05`), `POST /v1/desk/full-brief` (`$0.10`), `GET /health` |
| **treg hub (`0%` Commission)** | `singularity.agent-wallstreet-desk` | `$0.05` harvest / `$0.025` diff / `$0.05` risk / `$0.10` full brief (`$0` on empty/unchanged/fake-200/SSRF) |
| **Causal Bazaar Public Card** | `w4_f06_agent_wallstreet_desk_v1` | `is_public=1`, `price_micros=50000`, `max_price_micros=2000000` (hard spend cap `<= $2.00`) |
| **5s Try-Now Storefront & Creem Packs** | `https://quantdesk.fastmesh.dev/` | One-time never-expiring prepaid packs: `$99` Starter (`2,000` runs) / `$299` Pro Desk (`8,000` runs) / `$999` Institutional Feed (`35,000` runs) |

---

## 1. Calling via Remote `/mcp` (JSON-RPC 2.0)

Exposed flat MCP tools (4):
- `quantdesk_harvest_signal` — Stage 1+2 SSRF-safe public-disclosure harvest, entity alignment, anti-fake-200 verification, and `VerifiedFactorSignal` (`50,000` micros; `$0` on empty/fake-200/SSRF/422)
- `quantdesk_watch_diff` — Stage 3 SQLite snapshot canonical SHA-256 diff and HMAC-SHA256 `X-QuantDesk-Signature` webhook emission (`25,000` micros ONLY on material change; `$0` on unchanged/baseline)
- `quantdesk_risk_simulate` — Stage 4 deterministic 10,000-trial Decimal Monte Carlo risk desk with VaR/CVaR 95 & 99, max drawdown, ruin probability, half-Kelly cap, and Tornado sensitivity (`50,000` micros; `$0` on 422)
- `quantdesk_full_brief` — Combined Stage 1–4 pipeline returning `VerifiedFactorSignal`, optional `watch_diff`, and 10,000-trial `risk_simulation` (`100,000` micros; `$0` on any Stage 1–2 rejection or 422)

```bash
# 1. Initialize and list all 4 quantdesk_* MCP tools
curl -fsSL -X POST "https://quantdesk.fastmesh.dev/mcp" \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'

# 2. Run combined Stage 1-4 quantitative brief via MCP (seed=42, 10,000 trials)
curl -fsSL -X POST "https://quantdesk.fastmesh.dev/mcp" \
  -H "Content-Type: application/json" \
  -d '{
    "jsonrpc": "2.0",
    "id": 2,
    "method": "tools/call",
    "params": {
      "name": "quantdesk_full_brief",
      "arguments": {
        "source_type": "prediction_spread",
        "raw_payload": {
          "market_id": "fed_rate_cut_pair_01",
          "polymarket": {"yes_ask": "0.5200", "no_ask": "0.4900", "end_date": "2026-12-18T20:00:00Z", "taker_fee_bps": 0},
          "kalshi": {"ticker": "KXFED-26DEC", "yes_ask_dollars": "0.5600", "no_ask_dollars": "0.4400", "close_time": "2026-12-18T20:00:00Z"}
        },
        "seed": 42,
        "trials": 10000,
        "horizon_days": 21,
        "initial_capital": 100000
      }
    }
  }'
```

---

## 2. REST API Endpoints & Canonical Request/Response Contracts

All five legal public `source_type` values support BOTH live SSRF-safe `source_url` fetching AND deterministic offline `raw_payload` (JSON/XML/HTML) parsing:
- `sec_edgar`: SEC Form D (`primary_doc.xml` / EFTS), Form 8-K (Atom / submissions JSON), Form 13F-HR (exact-USD infotable XML), and US-GAAP `companyfacts`
- `prediction_spread`: Polymarket Gamma + CLOB order book (`max(bids)` / `min(asks)`) paired with Kalshi Trade API v2 (`yes_bid_dollars` / `orderbook_fp` implied asks)
- `ecb_fx`: ECB official daily `eurofxref-daily.xml` (`29` currencies) and `eurofxref-hist-90d.xml` with explicit `http://www.ecb.int/vocabulary/2002-08-01/eurofxref` namespace handling
- `clinical_trials`: ClinicalTrials.gov API v2 Industry Phase 3 studies (`COMPLETED`, `TERMINATED`, `ACTIVE_NOT_RECRUITING`, `hasResults`, `whyStopped`)
- `openfda_uspto`: openFDA `drugsfda.json` (`ORIG`/`SUPPL` `AP`/`TA`), `enforcement.json` recalls, FDA Orange Book `patent.txt`/`exclusivity.txt`, and USPTO Official Gazette

### A. Stage 1+2 — `POST /v1/desk/harvest-signal` (`50,000` micros / `$0.05`; `$0` on reject)

```bash
curl -fsSL -X POST "https://quantdesk.fastmesh.dev/v1/desk/harvest-signal" \
  -H "Content-Type: application/json" \
  -d '{
    "source_type": "ecb_fx",
    "source_url": "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml"
  }'
```

Canonical `VerifiedFactorSignal` fields:
`source_type`, `source_url`, `observed_at`, `entity_id`, `cik`, `ticker`, `nct_id`, `application_id`, `event_kind`, `factor_score` (Decimal-quantized float in `[-1.0, 1.0]`), `confidence` (`[0.0, 1.0]`), `metrics`, `content_sha256`, `receipt_sha256`, `billed_micros`, `charged_micros`, `billable`, `cache_status`, `disclaimer`.

### B. Stage 3 — `POST /v1/desk/watch-diff` (`25,000` micros ONLY on material change; `$0` on unchanged/baseline)

```bash
curl -fsSL -X POST "https://quantdesk.fastmesh.dev/v1/desk/watch-diff" \
  -H "Content-Type: application/json" \
  -d '{
    "watch_id": "ctgov_NCT03937154",
    "source_type": "clinical_trials",
    "raw_payload": {
      "protocolSection": {
        "identificationModule": {"nctId": "NCT03937154", "briefTitle": "Phase 3 Romiplostim Study"},
        "statusModule": {"overallStatus": "COMPLETED"},
        "sponsorCollaboratorsModule": {"leadSponsor": {"name": "Amgen", "class": "INDUSTRY"}},
        "designModule": {"phases": ["PHASE3"], "enrollmentInfo": {"count": 145}}
      },
      "hasResults": true
    }
  }'
```

Canonical `watch-diff` fields:
`watch_id`, `source_type`, `changed`, `change_reason`, `previous_sha256`, `current_sha256`, `diff_summary`, `signal`, `webhook_emitted`, `webhook` (`null` if unchanged; otherwise `{headers: {X-QuantDesk-Signature, X-QuantDesk-Event-Id, X-QuantDesk-Timestamp}, signature, event_id, timestamp_s, delivery_status, raw_body, payload}`), `receipt_sha256`, `billed_micros`, `charged_micros`, `billable`.

Materiality gates that trigger a billable webhook:
- `sec_edgar`: new `accessionNumber`, Form D `totalAmountSold` change `> $100,000`, or 13F position weight change `> 50 bps`
- `prediction_spread`: `|delta_net_edge_bps| >= 25 bps`, implied probability shift `>= 300 bps`, or settlement date change
- `ecb_fx`: new ECB `@time` date AND target pair move `>= 25 bps` (or tracked currency `>= 50 bps`)
- `clinical_trials`: `overallStatus` transition, `hasResults` flip (`false -> true`), primary completion slippage `> 30` days, or new `whyStopped` text
- `openfda_uspto`: new `AP`/`TA` drug approval, Class I/II recall, Orange Book patent listing/delisting, or USPTO weekly grant change

### C. Stage 4 — `POST /v1/desk/risk-simulate` (`50,000` micros / `$0.05`; `$0` on HTTP `422`)

```bash
curl -fsSL -X POST "https://quantdesk.fastmesh.dev/v1/desk/risk-simulate" \
  -H "Content-Type: application/json" \
  -d '{
    "factor_score": 0.62,
    "expected_return": 0.085,
    "volatility": 0.24,
    "jump_prob": 0.04,
    "jump_mean": -0.12,
    "horizon_days": 21,
    "initial_capital": 100000,
    "seed": 42,
    "trials": 10000
  }'
```

Canonical `risk-simulate` fields:
`seed`, `trials`, `horizon_days`, `initial_capital`, `p5`, `p50`, `p95`, `mean_return`, `std_return`, `var_95`, `cvar_95`, `var_99`, `cvar_99`, `max_drawdown`, `ruin_probability`, `half_kelly_cap`, `tornado_sensitivity` (ranked list of `{rank, factor, low_outcome, high_outcome, swing, variance_share_pct, direction}`), `decimal_exact`, `histogram_bins`, `receipt_sha256`, `billed_micros`, `charged_micros`, `billable`.

### D. Combined Stage 1–4 — `POST /v1/desk/full-brief` (`100,000` micros / `$0.10`; `$0` on Stage 1–2 reject or `422`)

Runs Stage 1+2 harvest/verify, optional Stage 3 snapshot diff (when `watch_id` is provided), and Stage 4 10,000-trial Decimal Monte Carlo simulation in one atomic call, returning `ok`, `status_code`, `source_type`, `signal`, `watch_diff`, `risk_simulation`, `receipt_sha256`, `billed_micros`, `charged_micros`, `billable`, `latency_ms`, `zero_resale_policy: true`, and `disclaimer`.

---

## 3. Verifying Outbound Webhooks (`X-QuantDesk-Signature`) & Offline SHA-256 Receipts

Verify outbound Stage 3 watch-diff webhooks in pure Python 3 stdlib:

```python
import hashlib
import hmac

def verify_quantdesk_webhook(raw_body: bytes, header_sig: str, secret: str) -> bool:
    expected = "sha256=" + hmac.new(
        secret.encode("utf-8"), raw_body, hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(expected, header_sig.strip())
```

---

## 4. Calling via `treg hub` (`0%` Commission) & Causal Bazaar

```bash
# Zero-commission treg hub call ($0 on empty, unchanged, fake-200, or SSRF)
treg call singularity.agent-wallstreet-desk \
  --data '{"operation":"full_brief","source_type":"ecb_fx","source_url":"https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml","seed":42,"trials":10000}'
```

- **Causal Bazaar Hand**: `w4_f06_agent_wallstreet_desk_v1` (`is_public=1`, `price_micros=50000`, `max_price_micros=2000000`, CLI `run_hand.py`).
- **Prepaid Creem Credit Packs** (`POST /webhooks/creem` HMAC-SHA256 `creem-signature` with SQLite `event_id` idempotency):
  - **Quant Starter (`$99`)**: `sku_f06_starter_99` (`prod_quantdesk_starter_99`) — `2,000` base runs (`100,000,000` micros, `$0.0495`/run)
  - **Pro Desk (`$299`, Most Popular)**: `sku_f06_pro_299` (`prod_quantdesk_pro_299`) — `8,000` base runs (`400,000,000` micros, `$0.0374`/run)
  - **Institutional Feed (`$999`)**: `sku_f06_institutional_999` (`prod_quantdesk_institutional_999`) — `35,000` base runs (`1,750,000,000` micros, `$0.0285`/run)

---

## 5. Production Gotchas Handled Automatically by Agent-WallStreet-Desk

1. **SEC EDGAR**: Complies with SEC Fair Access (`User-Agent: AgentWallStreetDesk support@fastmesh.dev`), uses `efts.sec.gov/LATEST/search-index?forms=D` to prevent `browse-edgar` `type=D` prefix collisions with `DEFM14A`, enforces `count=10` multiples on Atom feeds, and treats post-2023 Form 13F-HR `<value>` strictly as **exact USD dollars** (not thousands).
2. **Polymarket & Kalshi**: Computes `max(bids)` / `min(asks)` on Polymarket CLOB `/book` (which sorts bids ascending and asks descending), decodes JSON-stringified Gamma fields, supports Kalshi 2026 fixed-point `*_dollars` and `orderbook_fp` bid ladders (`implied YES ask = 1.0000 - max(no_dollars)`), and flags settlement gaps `> 3` days.
3. **ECB FX XML**: Binds explicit namespace `http://www.ecb.int/vocabulary/2002-08-01/eurofxref` and skips billing on weekend/TARGET holiday unchanged snapshots.
4. **ClinicalTrials.gov v2**: Applies `fields=` projection (`~1.9 KB / 0.8s` vs `739 KB / 20s`), comma-separated `filter.overallStatus`, and partial `YYYY-MM` date normalization.
5. **openFDA / USPTO Fake-200 Protection**: Intercepts retired USPTO CloudFront `HTTP 200` error HTML (`X-Cache: Error from cloudfront`, `12,258` bytes) and Cloudflare/SPA shells with strictly **`billed_micros = 0`**.
