Repository navigation
[PRODUCT] diag: book, lots and option_bars probes — sessions read the live Book and the closed-lot ledger (v1.0.1250) - #1581
Merged
Conversation
… 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 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Three token-gated, read-only, sanitized probes on the existing
/api/diag/:probesurface 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.tsis untouched; same posture as every other probe (closed by default withoutDIAG_TOKEN,x-diag-tokenheader,sanitizeDiag).book— the SAME body as the owner's/api/bot/positions. The route body is nowpositionsBody()inserver/bot.tsand both callers serve it, never a second computation (thebenchmark/sleevesprecedent;diag.test.tspins 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/sleevesand the edge ledger are computed from; refreshed only throughsleevesBody()'s own path). Each row: symbol, side, open/close times, qty, basis, P&L, return %, entry/exit per share (diag.ts lotRow, whitelist-shaped likeorderRow). Rows are sanitized one by one with an explicittruncatedflag (archive-probe convention);?limitkeeps the newest rows, ≤ 5000.option_bars— bounded passthrough of Alpaca's historical daily option bars for ≤ 10 OCC contracts over ≤ 400 days (optionBarsQueryvalidates; 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.mdKNOWN STATE gains the fact line:positions-detail/orders/sleeves/benchmark/accountalready 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-detailwhile 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 theresearch/experiments.mdentry).Downstream chain (REASONING STANDARD §1)
Read-only.
positionsBody()is the exact former handler body; the owner route's response is byte-identical.lotsadds no fetch (it reads the sleeve cache).option_barsmakes ≤ 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,bookservespositionsBody()on both sides,lotsreadssleeveCache?.taxInputs.eventsafterawait sleevesBody(),option_barstouches market data only);lotRowarithmetic (long lot, short-lot mirror, stock, garbage numerics → null);optionBarsQuery/optionBarsUrl(OCC-only, ≤ 10 symbols, ≤ 400 days, defaults, no key in the URL).Generated by Claude Code