Skip to content

Commit 0c174d9

Browse files
luisleo526claude
andcommitted
Docs: the arm options, the adoption table and the grid re-lowering waiver (R5 gap lane N13, item 3)
native-engine.md: WaitForApplied's first_match and scope next to the L7b knobs; the adapter paragraph restated for the host-sized Book child with the per-shape {anchored, adopted, withdrawn} table and each retained shape's measured reason; and the formal waiver of the Pine adapter's grid re-lowering. The waiver is lane R7's STEP 2 trial re-run after L8b on this tree (the adapter submits raw levels, project() declares QuantizeFillsAndTriggers + HalfUp). B1 is closed: no run aborts (R7: nine zero-offset-trail tapes and six POOC panels; now 449/450 and 183/183). B2 still moves 30 pinned checks in four units with no adapter-side remedy (24 + 3 + 2 + 1) and 12 more with an adapter-side cause; the corpus differs on 5/312 probes in the engine-only entry-incarnation column only. No class of triggers is byte-identical on its own -- the grid is a run-wide switch -- so nothing is re-lowered and design row PG records it as measured-infeasible for the Pine adapter. Co-Authored-By: Claude Fable 5.1 <[email protected]> (cherry picked from commit d292458b2f1fefbd9f71a2679652c63dd2ed90c9)
1 parent 0c68375 commit 0c174d9

3 files changed

Lines changed: 97 additions & 23 deletions

File tree

‎docs/design/native-feature-parity.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ Columns: **Feature** (adapter mechanism, cited) · **Native today** (`yes` / `pa
146146
| FP3 | Commission: percent / cash per unit / cash per execution (`fee_kind_for` pine_adapter.cpp:415-422) | **yes** — `NativeFeeKind` native_run_spec.hpp:19-23; `quote_execution_commissions` engine_execution.cpp:960-996 | K | — | F:G2 O:H8 S:F1 | — |
147147
| FP4 | Booked fill quantized to the instrument tick, nearest or directional (`nearest_tick` pine_adapter.cpp:252-255, `source_bar_fill` pine_adapter.cpp:9553-9562, `directional_tick` pine_adapter.cpp:297-301) | **no** — `price_tick` is only a slippage multiplier native_execution_consumer.cpp:3671; `bar_fill_price` engine.hpp:1198 is reachable only through `NativeCurrentPriceRule::NearestTick` native_execution_consumer.cpp:3851-3852; reference helpers are dead engine.hpp:1338, engine.hpp:1348, engine.hpp:1388 | K | L8 | O:H4 O:H6 F:G4 S:F3 | **Disagree:** O kernel / F, S "stays adapter, no promotion". R5-3: own kernel lane. |
148148
| FP5 | Trigger tested against the tick-quantized bar | **no** — the kernel tests raw prices against raw levels | K+A | L8 | O:H5 F:G4 S:F3 | R5-3: the optional quantized trigger test is K; TV's exact half-tick rule (`source_trigger_threshold` pine_adapter.cpp:328-376) is A on top. |
149+
| PG | The Pine adapter on the kernel price grid: raw levels submitted, `project()` declaring `QuantizeFillsAndTriggers` + `HalfUp`, `source_trigger_threshold` deleted (lane R7; re-tested after L8b by gap lane N13) | **measured-infeasible for the Pine adapter** — B1 (the sub-tick cursor-print abort) is closed by L8b's `ActivationGrid`: 0 aborted runs under the trial (R7: 9 zero-offset-trail tapes + 6 POOC panels; now `test_zero_offset_trail_rides_l4c` 449/450, `test_pooc_short_close_tick_l4d` 183/183). B2 (TradingView quantizes per order kind, the grid is one run-wide rule) still moves 30 pinned checks in 4 units with no adapter-side remedy: `test_coof_market_limit_recross_l4c` 24, `test_stop_tick_rounding_l4d` 3, `test_adapter_grid_relower` 2, `test_zero_offset_trail_rides_l4c` 1; 12 more checks in 3 units have an adapter-side cause (`test_trail_fill_snap_l4c` 2, `test_native_margin_hooks` 2, `test_adapter_brackets_relower` 8 book digests). Corpus: 5/312 probes differ, in the engine-only entry-incarnation column only (every probe runs a 0.01 tick on an on-grid feed, so it cannot arbitrate) | A | waived (R7, N13) | — | **Waiver.** No class of triggers is byte-identical on its own: the grid is a run-wide switch and a per-kind mask would spell TradingView's inconsistency into the kernel (not generic, R5-3). The adapter stays on `NativePriceGrid::None` and keeps `source_trigger_threshold` and its call sites; native-engine.md "The Pine adapter's grid re-lowering is waived". |
149150
| FP6 | Account-currency FX | **partial** — scalar `account_fx` + immutable `NativeFxCurve` native_host.hpp:484 in batch; the stream refuses a non-empty curve native_execution_consumer.cpp:1251-1261, native-engine.md:415. **Closed by audit lane N6:** the declared curve is the run's immutable FX epoch and a confirmed-bar stream runs under it exactly as a batch does (stream twin in `tests/test_native_margin_fx_roll.cpp`); no realtime rate ingestion and no tick-driven input under a curve are stated as permanent limits with their reasons (native-engine.md, "Stream FX") | K | unassigned → N6 | F:D9 S:F4 | **Disagree:** F out of scope ("O7 clock" native-engine.md:739-744) / S its P10, a stream-safe FX epoch. No R5 lane → §4 U4 (answered by N6: S's "same curve in batch and stream", without a new clock or callback). |
150151
| FP7 | *(quirk)* TV tick conventions: half-tick threshold pine_adapter.cpp:328-376 (used pine_adapter.cpp:7053-7058, pine_adapter.cpp:7627-7651), `source_bar_fill_tick` pine_adapter.cpp:273-286, raw-vs-booked spelling pine_adapter.cpp:9519-9625, margin-call fill pricing pine_adapter.cpp:11588-11597 | n/a — already isolated behind the terms seam (adapter `resolve_terms` pine_adapter.cpp:9310) | A | — | F:G4 O:H5 S:F3 | R5-1, R5-3 |
151152

@@ -677,6 +678,7 @@ template <class Key> class OrderBook; // id
677678
```
678679
679680
- A leg with owner `WaitForApplied` / `BindOpening` and a non-absolute anchor gets its level when the owner's fill arms it (`ArmedEvent` native_order.hpp:716-723 already exists) (O). Fallback with no kernel change: the toolkit materializes relative levels from the host's `on_native_applied` (F).
681+
- Gap lane N13 (after R4d): two facts of the arm were missing and are now opt-in fields appended to `WaitForApplied`, each default byte-identical and folded only when set. `NativeArmFirstMatch { AtArmPrint, AfterArmPrint }`: whether the armed leg is a candidate at its owner's fill print or, like a request born in the owner's fill callback, only after it. `NativeArmScope { OwnerLot, Book }`: whether an armed closing leg closes the lot its owner opened or is bound at the arm to the whole position (a `BookClose`), under which it may be `HostSized`. Ruling: generic — both are broker models of a contingent child, neither names a source language — and they are what makes an anchored child the very request a host would submit from `on_native_applied`. The Pine adapter's relative `strategy.exit` legs use both; R4d's owner-lot spelling left a later same-id add open where the source leg closes the book (`rel-pyramid-set-once`, tests/test_adapter_brackets_relower.cpp).
680682
- Not adopted (R5-2): S's kernel bracket object, its C symbols `strategy_native_bracket_*` and its TU list (`engine_orders.cpp`, `engine_execution.cpp`).
681683
- TUs: `native_order.{hpp,cpp}` (arming), `native_matching.hpp` (`checked_trail_stop`), `native_execution_consumer.cpp` (`prepare_owner_applied` path, command surface).
682684

‎docs/pages/native-engine.md‎

Lines changed: 94 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,32 @@ never sets it, so Pine-compatible runs are unchanged.
247247
excluded), so a `close_execution = AfterCalculation` leg reissued at the
248248
close and reached by that close's print fills at the next open
249249
(tests/test_native_price_grid.cpp, sections L8b-1 to L8b-4).
250+
- The Pine adapter's grid re-lowering is waived: measured-infeasible (R5 gap
251+
lane N13, the re-run of lane R7's trial after L8b). The trial has the
252+
adapter submit raw levels (`source_trigger_threshold` answering the level
253+
itself) and `project()` declare `QuantizeFillsAndTriggers` with `HalfUp`.
254+
L8b closed the first blocker: no run aborts any more (R7 measured nine
255+
NYSE:F / AAPL zero-offset-trail tapes and six `process_orders_on_close`
256+
panels failing with "native working-request preparation failed"; now
257+
`test_zero_offset_trail_rides_l4c` is 449 of 450 and
258+
`test_pooc_short_close_tick_l4d` 183 of 183). The second blocker is what is
259+
left and it has no adapter-side remedy: TradingView quantizes per order
260+
kind, the grid is one rule for the run. It still moves 30 pinned checks in
261+
four units — 24 in `test_coof_market_limit_recross_l4c` (an on-grid exit
262+
limit stays raw under `calc_on_order_fills`), 3 in
263+
`test_stop_tick_rounding_l4d` (a stop booked 14.01 on another bar where
264+
TradingView books 13.98), 2 in `test_adapter_grid_relower` (the trail stop
265+
one ULP under its ladder point exits a bar early) and 1 in
266+
`test_zero_offset_trail_rides_l4c` (the quantized running best) — plus 12
267+
checks with an adapter-side cause (the grid pre-rounds
268+
`default_resolved_price`, 196.135 booking 196.14 for TradingView's 196.13;
269+
a rounded-money liquidation twin; eight pending-book digests where a
270+
bit-equal re-issue keeps a request the adapter replaces today). The corpus
271+
cannot arbitrate: all 312 probes run a 0.01 tick on an on-grid feed, and
272+
under the trial 5 of them differ only in the engine-only entry-incarnation
273+
column. No class of triggers is byte-identical on its own, because the
274+
grid is a run-wide switch and a per-kind mask is not generic; the adapter
275+
stays on `None` and keeps `source_trigger_threshold`.
250276

251277
Timeframe arguments on `run` / `stream_begin` must be **omitted/empty or
252278
byte-identical** to the spec. Conflicting values are a preflight refusal:
@@ -537,6 +563,35 @@ and the host supplies policy through a hook, exactly as
537563
`PendingUntilArmed`, under which an unarmed leg is not a working order. It
538564
is a live, accepted request the whole time; visibility governs
539565
enumeration, not addressing.
566+
- **First match.** `WaitForApplied{parent, visibility, first_match}` takes a
567+
`NativeArmFirstMatch`. The arm happens inside the owner's fill settlement,
568+
at the owner's fill print. `AtArmPrint` (default) is the established book:
569+
the armed leg is a candidate at that very cursor, so a level the fill print
570+
already satisfies matches at the print. `AfterArmPrint` gives it the birth
571+
rule of a request submitted from the owner's fill callback: on the driver
572+
point that armed it the print is consumed — a level already reached does
573+
not match there, a later crossing on that point still does — and from the
574+
next driver point on it is an ordinary working request. It governs the
575+
level test of a priced trigger; a market trigger has no level. Both are
576+
broker models (a contingent child that enters the book after its parent's
577+
trade cannot trade on that print; a simulated bracket commonly may), and a
578+
leg under `AfterArmPrint` is, trade for trade, the leg a host would submit
579+
from `on_native_applied`.
580+
- **Scope.** `WaitForApplied{parent, visibility, first_match, scope}` takes a
581+
`NativeArmScope`, which names what an armed *closing* leg closes.
582+
`OwnerLot` (default) is the established relation: the lot the owner's fill
583+
opened, and nothing a later add brings. `Book` binds the leg, at the arm,
584+
to the whole position that fill left — its `ArmedEvent` carries a
585+
`BookClose` for that cycle and side, bound at the fill's cursor, the very
586+
authority an `Independent` close acquires — so a protective leg placed with
587+
its entry also covers later adds and settles through the book like any
588+
other close. A `HostSized` close may wait for its owner only under `Book`
589+
(the owner-lot relation sizes from the units the owner opened; a book close
590+
is sized by `resolve_execution_terms` at the match); under `OwnerLot` it is
591+
still `InvalidOwner`. A waiting transaction closes nothing and must keep
592+
`OwnerLot`. Both fields fold into the continuation identity only when set,
593+
each under its own tag, and an unknown value is refused, never read as the
594+
default. The C request does not expose them (`native_c_api.h`).
540595
- **Facts at the arm (measured).** `Reduce{OwnerOpenedUnits{}}` is bound at
541596
the arm to what the owner opened (`QuantityBoundEvent`); a
542597
`ScopeFraction` with the default `AtMatch` basis resolves at the candidate
@@ -608,29 +663,46 @@ multiplying the count by the tick itself. A relative bracket leg — a
608663
`strategy.exit(from_entry=…, profit=…, loss=…, trail_points=…)` operand
609664
queued while its parent entry has not filled — is the anchored child above:
610665
at the end of the source evaluation in which the queued exit and its live
611-
parent both exist, `anchor_relative_exits` submits each such leg as
612-
`Reduce{OwnerOpenedUnits}` under `WaitForApplied{parent, PendingUntilArmed}`
613-
with a tick-spelled `FromOwnerFill{±ticks, true, Directional}` anchor in the
614-
exit's own OCA group, and `resolve_anchored_level` restates TradingView's
615-
projection at the arm (`directional_tick`, the price-grid spelling, the
616-
half-tick trigger threshold of the quantized bar; `trail_points` against the
617-
position's average price). The parent's fill point still runs the source
666+
parent both exist, `anchor_relative_exits` submits each such leg as the very
667+
request `exit()` submits at the parent's fill, placed ahead of it: a
668+
`HostSized` close under `WaitForApplied{parent, PendingUntilArmed,
669+
AfterArmPrint, Book}` with a tick-spelled `FromOwnerFill{±ticks, true,
670+
Directional}` anchor in the exit's own OCA group. The kernel computes the
671+
level (`fill ± ticks` on the tick ladder); `resolve_anchored_level` restates
672+
only TradingView's spelling of that ladder point and its trigger projection —
673+
the half-tick threshold of the quantized bar, a raw on-grid limit under
674+
`calc_on_order_fills`, the one-shot trail touch — through the same two
675+
functions `exit()` uses. The parent's fill point still runs the source
618676
`exit()` pipeline, because the leg's reservation, birth reach, L4C policy and
619-
same-bar ordering are facts of that point and have no kernel analogue; what
620-
changed is that it *adopts* the armed child instead of submitting whenever
621-
that child is bit for bit the trigger and OCA group it was about to submit,
622-
for the whole of a one-lot position. Otherwise the children are withdrawn
623-
before the path resumes and the fill point submits as it always did: a
624-
partial or explicit quantity, a sibling exit's reservation, a parent that
625-
adds to or reverses a live book, `calc_on_order_fills`,
626-
`process_orders_on_close` and stream runs (their fill point re-decides the
627-
trigger kind or stages the leg), and a level already inside its region at
628-
the parent's raw fill print, where a callback-born request starts after that
629-
print and an armed child may match at it. The queued definition and its
630-
shadow row therefore stay: the definition outlives parents (it may be
631-
declared before any entry exists and is re-anchored when a parent is
632-
replaced), and the shadow row is the source projection of a child the kernel
633-
deliberately does not list. The remaining TradingView rules stay adapter
677+
same-bar ordering are facts of that point and have no kernel analogue; it
678+
*adopts* the armed child instead of submitting whenever that child is the
679+
request it was about to submit: the same trigger bits, the same OCA group, a
680+
host-sized close of the book. Because the child is host-sized and
681+
book-scoped, that holds for every quantity the source resolves at the match
682+
(a percentage, a sibling's remainder) and for every book the parent's fill
683+
leaves (flat, a reversal, a later same-id add), under `calc_on_order_fills`
684+
and `process_orders_on_close` as well; and because it is `AfterArmPrint`, a
685+
level the fill print already satisfies behaves as the callback-born leg
686+
does. Otherwise the children are withdrawn before the path resumes and the
687+
fill point submits as it always did. What stays off the kernel path, each
688+
with its measurement (`tests/test_adapter_brackets_relower.cpp`):
689+
690+
| Shape | `{anchored, adopted, withdrawn}` | Why |
691+
| --- | --- | --- |
692+
| explicit `qty=` (`rel-qty-explicit`) | `{0,0,0}` | `exit()` stages an explicit quantity per origin (`pending_bracket_legs_`) and submits it at a later flush: the fill point has no request for a child to be |
693+
| `strategy.cancel(exit id)` in the same evaluation (`rel-cancel-exit-id`) | `{0,0,0}` | the definition is gone before the evaluation ends: no leg exists |
694+
| `close_entries_rule = "ANY"`, stream runs | not anchored | the fill-point leg is cohort-bound (`BindCohort`), a scope the arm does not spell; a stream's fill point stages the leg |
695+
| a parent re-issued, cancelled or declined (`rel-limit-parent` `{12,4,8}`, `rel-reissue-changed` `{18,2,16}`, `rel-breakout-pair` `{40,14,24}`, `rel-declined` `{2,0,2}`) | withdrawn | the kernel ends a waiting child with its parent (`OwnerGone`), a replaced parent included; keeping the children across a replace needs a re-parent transition in the event log, which is an epoch decision |
696+
| a sibling with no capacity left (`rel-two-exits` `{4,2,2}`), a level below zero (`rel-negative-short` `{2,1,1}`) | withdrawn | the fill point submits nothing for that leg |
697+
698+
Over the 47 pending-parent scenarios R4d pinned, the split moved from
699+
`{203, 98, 105}` to `{216, 119, 93}` (`{220, 123, 93}` with the two
700+
same-id-add scenarios this lane added), and every formerly `{0,0,0}` shape
701+
but the two recorded above runs on the kernel. The queued definition and its
702+
shadow row stay: the definition outlives parents (it may be declared before
703+
any entry exists and is re-anchored when a parent is replaced) and is what
704+
the fallback re-runs, and the shadow row is the source projection of a child
705+
the kernel deliberately does not list. The remaining TradingView rules stay adapter
634706
policy because no kernel primitive expresses them: the legacy broker rides
635707
the *tick-quantized* running best, which the adapter still spells as a
636708
half-a-tick trailing distance (`TrailTicks{0.5}`) rather than the kernel's

0 commit comments

Comments
 (0)