Skip to content

Show the recent trade window, not just the last print - #23

Merged
piekstra merged 1 commit into
mainfrom
fix/market-rail-recent-window
Aug 11, 2026
Merged

Show the recent trade window, not just the last print#23
piekstra merged 1 commit into
mainfrom
fix/market-rail-recent-window

Conversation

@piekstra

Copy link
Copy Markdown
Owner

The gap

The market rail builds a reference from the orderbook, the trades feed, and the
last print, then objects if the order is materially worse than it. On a thin book
the last print can be days old and far from where the property actually
changes hands — so one stale outlier silently dominates two healthy live quotes.

Observed live: a bid was refused as "6.3% above the market reference", where that
reference was a single print from three days earlier. The orderbook and the
feed both quoted materially higher, and the median of recent prints sat between
them. The rail was arguably right to ask — but it displayed only the number that
made it object, so there was no way to distinguish a stale outlier from a genuine
repricing without leaving the tool and querying the tape by hand.

The change

The diagnostic block now also shows:

  • median of the recent window, plus its low/high range
  • the age of the last print
  orderbook   bid $63.55  ask $65.00
  trades feed bid $63.66  ask $63.99
  last trade  $59.26, 3d ago   (1890 recent print(s))
  recent      median $61.02  range $59.26–$63.20  (last 20 print(s))

That's enough to tell at a glance that the objection rests on a stale tail rather
than on current pricing.

Trigger semantics are unchanged. This is about giving a human enough context to
judge an override, not about loosening the check — overriding a rail by habit is
how it stops protecting you.

Note on window selection

The window is chosen by timestamp, not array order. The payload is not
guaranteed sorted, so taking the first N would summarise arbitrary prints and
quietly mislead. There's a test pinning this: newest prints appended last must
still be what the median reflects.

Tests

  • median over odd / even / empty samples
  • describe surfaces the median and range, reproducing the live case above
  • the recent window is selected by time, not array order

The market rail vetoes an order by comparing it to a reference built from the
book, the feed, and the last print. On a thin book the last print can be days
old and far from where the property actually changes hands, so a single stale
outlier silently dominates two healthy live quotes — and nothing in the output
let the operator tell an outlier from a genuine repricing.

Observed live: a bid was refused as "6.3% above the market reference" where
that reference was one print from three days earlier. The orderbook and the
feed both quoted materially higher, and the median of recent prints sat
between them. The rail was arguably right to ask, but it showed only the number
that made it object.

Adds to the diagnostic block:
  * median of the recent window, and its low/high range
  * the AGE of the last print

The window is selected by timestamp rather than array order; the payload is not
guaranteed sorted, and taking the first N would summarise arbitrary prints.

Trigger semantics are unchanged — this is about giving a human enough to judge,
not about loosening the check.
@piekstra
piekstra merged commit 0b0cf62 into main Aug 11, 2026
2 checks passed
@piekstra
piekstra deleted the fix/market-rail-recent-window branch August 11, 2026 19:59
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.

1 participant