Skip to content

[PRODUCT] diag: book, lots and option_bars probes — sessions read the live Book and the closed-lot ledger (v1.0.1250) - #1581

Merged
github-actions[bot] merged 1 commit into
mainfrom
claude/diag-book
Nov 2, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
claude/diag-book

Conversation

@mctils12-arch

Copy link
Copy Markdown
Owner

What

Three token-gated, read-only, sanitized probes on the existing /api/diag/:probe surface so agent sessions can read the live Book and the account's closed-lot history (human instruction 2026-11-02: "I cannot read your live Book from this session, since that endpoint is owner-only. Fix this so you can."). server/auth.ts is untouched; same posture as every other probe (closed by default without DIAG_TOKEN, x-diag-token header, sanitizeDiag).

  • book — the SAME body as the owner's /api/bot/positions. The route body is now positionsBody() in server/bot.ts and both callers serve it, never a second computation (the benchmark / sleeves precedent; diag.test.ts pins it). A session reads the Book's rows, the engine's exit levels per share lot and each option's recorded strategy.
  • lots — the sleeve ledger's closed-lot walk (sleeveLedger.realizedEvents, the cached list /api/bot/sleeves and the edge ledger are computed from; refreshed only through sleevesBody()'s own path). Each row: symbol, side, open/close times, qty, basis, P&L, return %, entry/exit per share (diag.ts lotRow, whitelist-shaped like orderRow). Rows are sanitized one by one with an explicit truncated flag (archive-probe convention); ?limit keeps the newest rows, ≤ 5000.
  • option_bars — bounded passthrough of Alpaca's historical daily option bars for ≤ 10 OCC contracts over ≤ 400 days (optionBarsQuery validates; keys travel in headers only; no account, order or position field is reachable from the case). This is the price path an exit-rule counterfactual needs.

CLAUDE.md KNOWN STATE gains the fact line: positions-detail / orders / sleeves / benchmark / account already existed (2026-07-07, 09-10, 10-20 widenings) and a session must read the Book with the token before describing the account.

Why now

The RULE-REVIEW candidate filed earlier today (bought options have no profit-taking exit) needs the account's own closed lots and each contract's daily price path to be judged with counterfactual evidence rather than opinion. Reading the live account through positions-detail while writing this PR also showed that the "option up 300 %" is the surviving long wing of a GOOGL iron condor the per-leg Tier-1 kill dismantled on Oct 28–29 (details in the research/experiments.md entry).

Downstream chain (REASONING STANDARD §1)

Read-only. positionsBody() is the exact former handler body; the owner route's response is byte-identical. lots adds no fetch (it reads the sleeve cache). option_bars makes ≤ 5 Alpaca data calls per request, only when a session asks. No trading, sizing, measurement or threshold code touched.

Tests

  • server/diag.test.ts +3: wiring + same-body pins for the three probes (whitelisted, sanitizeDiag, book serves positionsBody() on both sides, lots reads sleeveCache?.taxInputs.events after await sleevesBody(), option_bars touches market data only); lotRow arithmetic (long lot, short-lot mirror, stock, garbage numerics → null); optionBarsQuery / optionBarsUrl (OCC-only, ≤ 10 symbols, ≤ 400 days, defaults, no key in the URL).
  • Local: server suite 2938/2938; tsc ratchet 6 ≤ 6; counter ratchet OK (assertions pin locked at 25776).

Generated by Claude Code

… live Book and the closed-lot ledger (v1.0.1250)

Human (2026-11-02): "I cannot read your live Book from this session, since
that endpoint is owner-only. Fix this so you can." Three token-gated,
read-only, sanitized probes on the existing /api/diag surface (auth.ts
untouched):

- book: the SAME body as the owner's /api/bot/positions — the route body
  is now positionsBody() and both callers serve it (the benchmark/sleeves
  precedent; pinned), so a session reads the Book's rows, the engine's
  exit levels and each option's recorded strategy.
- lots: the sleeve ledger's closed-lot walk (sleeveLedger.realizedEvents,
  the cached list /api/bot/sleeves and the edge ledger are computed from,
  refreshed only through sleevesBody's path): symbol, side, open/close,
  qty, basis, P&L, return, entry/exit per share via diag.ts lotRow.
  Per-row sanitized with an explicit truncated flag; ?limit <= 5000.
- option_bars: bounded passthrough of Alpaca's historical daily option
  bars for <= 10 OCC contracts over <= 400 days (market data only, keys in
  headers, no account/order/position field reachable) — the price path an
  exit-rule counterfactual needs.

CLAUDE.md KNOWN STATE gains the fact line (positions-detail / orders /
sleeves / benchmark / account already existed; a session must read the
Book with the token before describing the account). Tests: diag.test.ts
+3 (wiring and same-body pins, lotRow arithmetic incl. the short-lot
mirror and garbage numerics, the query validator and key-free URL).
Counter pin: assertions locked 25776. No trading or measurement code
touched.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BrrwY7BFkP8VNdwKPfaVn5
@github-actions
github-actions Bot merged commit 9a8b85d into main Nov 2, 2026
6 checks passed
github-actions Bot pushed a commit that referenced this pull request Nov 2, 2026
… under candidate profit-taking rules (#1584)

Human (2026-11-02): "for the other options, figure out what's best for
taking profit". Data: /api/diag/lots (400 option lots since 05-07) and
/api/diag/option_bars (96 contracts' daily bars), the probes #1581 added.

Result: no bought-option profit rule has a population — of 91 bought lots,
7 lived past a day, all legs of structures, none ever closed a day above
+50% of its premium; the RULE-REVIEW candidate is withdrawn. Sold lots: the
live 50% target holds (a 25% target cuts the best lot $1,300 → $520 and
the total by ~$1,200; 75% ~ 50%). Where the money goes: 288 of 400 lots
never saw a second session (<1h −$4,812, <1d −$5,011, 1–7d −$3,784,
8–30d +$845) — the exit churn the condor repair (#1582) and the POS-KILL
structure hold (#1583) address in part; the same-day churn on single sold
legs needs intraday marks the archive does not keep yet.

Compiled: scripts/options_exit_study.py (re-runnable with DIAG_TOKEN);
research/options_exit_study_2026-11-02.md (method, limits, the GOOGL
condor case study, tables); research/experiments.md entry. No code path
of the bot touched; no threshold changed.


Claude-Session: https://claude.ai/code/session_01BrrwY7BFkP8VNdwKPfaVn5

Co-authored-by: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants