PineForge v0.13.1-379-g9b50973
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
native_c_api.h
Go to the documentation of this file.
1/*
2 * SPDX-License-Identifier: Apache-2.0
3 *
4 * native_c_api.h — versioned C-level native host API (R5 lane L13).
5 *
6 * A host that is not written in C++ drives the kernel through this header:
7 * it hands the runtime a callback table, runs a batch of bars, and submits,
8 * replaces, cancels or executes order requests from inside those callbacks.
9 * It is the C spelling of <pineforge/native_host.hpp>'s NativeStrategyHost —
10 * the same kernel, the same events, no PineScript and no codegen.
11 *
12 * SCOPE
13 * ─────
14 * ✓ Create / free a native host backed by a C callback table
15 * ✓ Run a batch of OHLCV bars and fill a pf_report_t
16 * ✓ submit / replace / cancel / cancel_all / cancel_where / execute_current
17 * ✓ Read the physical position, the live working book, the open lots (the
18 * book lot by lot, marked at a price — strategy.opentrades.* for a C host)
19 * and the event history
20 * ✓ Read the run's lifecycle state and its typed failure
21 * ✓ Read a closed row's own identifiers — its entry and exit ticket, its exit
22 * comment and its close cause — with the pineforge.h accessors, which take
23 * any handle this header produces
24 * ✓ Extend the run specification with the fields pf_native_run_spec_v1 predates
25 * ✓ Declare an auxiliary finer feed, build a series from it, and append its
26 * later bars to a realtime stream
27 *
28 * ✗ Streaming has no new symbols: strategy_stream_begin / _push_bar /
29 * _push_tick / _advance_time / _end / _fill_report take any handle this
30 * header produces, unchanged.
31 * ✗ resolve_execution_terms is exposed only as its UNITS half, for a
32 * host-sized close (pf_native_callbacks_v1::on_close_units). Its price and
33 * opening-shape halves, validate_execution_precommit and
34 * resolve_anchored_level stay C++-only; see the exclusion list below.
35 * ✗ hash_host_extension is not exposed: the callback table carries no hash
36 * hook, so a C host's broker-state hash is the kernel's own fold. The
37 * per-bar rows need no new symbol: `report_policy` = KernelRecorded with
38 * strategy_set_broker_state_hash_recording on fills
39 * pf_report_t::broker_state_hash, one row per script bar.
40 * ✗ WaitForApplied::first_match and WaitForApplied::scope are not exposed:
41 * a WAIT_FOR_APPLIED child submitted here keeps the defaults (AtArmPrint,
42 * OwnerLot). NativeArmScope::Book exists for a HostSized close, whose
43 * units the unexposed terms hook answers.
44 *
45 * COVERAGE
46 * ────────
47 * Every public member of NativeStrategyHost, and either its C spelling or the
48 * reason it has none. scripts/check_native_c_api_surface.py proves this list is
49 * exactly that class's public surface: a member added there without a row here,
50 * or a row here naming a member that no longer exists, fails CI.
51 *
52 * [C] on_bar strategy_native_run_v1 / the strategy_stream_* ingress
53 * [--] prepare_native_begin borrows the codegen ingress (InputsMap, SymInfo, the opaque
54 * overrides) that no C host supplies; a C run is declared up front
55 * with strategy_configure_native_ext_v1
56 * [C] on_native_run_begin pf_native_callbacks_v1::on_run_begin
57 * [C] on_native_input pf_native_callbacks_v1::on_input
58 * [C] on_native_tick pf_native_callbacks_v1::on_tick
59 * [C] on_native_timeframe_bar pf_native_callbacks_v1::on_timeframe_bar
60 * [C] on_native_bar_open pf_native_callbacks_v1::on_bar_open
61 * [C] on_native_bar pf_native_callbacks_v1::on_bar
62 * [C] on_native_recalculate pf_native_callbacks_v1::on_recalculate
63 * [C] on_native_sub_bar pf_native_callbacks_v1::on_sub_bar
64 * [C] on_native_applied pf_native_callbacks_v1::on_applied
65 * [C] on_native_margin_call pf_native_callbacks_v1::on_margin_call
66 * [C] resolve_execution_terms pf_native_callbacks_v1::on_close_units -- the UNITS half only; the
67 * price and the opening shape stay the kernel's
68 * [--] validate_execution_precommit its view is an ExecutionPlan, an AccountEffectProjection and a
69 * variable-length closed-row P&L vector, none of which has a size-
70 * prefixed POD; a C host gates an opening with
71 * PF_NATIVE_INTENT_SIZED's placement-time admission or with
72 * on_margin_requirement
73 * [--] resolve_anchored_level the generic knob for where an anchored level sits is
74 * pf_native_request_v1::anchor_rounding; the hook exists for a source
75 * language's own level arithmetic, and a C host that wants another
76 * level replaces the leg on its PF_NATIVE_EVENT_ARMED
77 * [C] resolve_margin_requirement pf_native_callbacks_v1::on_margin_requirement
78 * [C] margin_check_allowed pf_native_callbacks_v1::on_margin_check
79 * [C] resolve_margin_call_units pf_native_callbacks_v1::on_margin_call_units
80 * [C] owns_lot_excursions pf_native_callbacks_v1::on_lot_excursion -- installing it IS
81 * declaring ownership
82 * [C] closed_lot_excursion pf_native_callbacks_v1::on_lot_excursion
83 * [C] current_partial_bar strategy_native_partial_bar_v1
84 * [C] native_recalculation_count strategy_native_recalculations_v1
85 * [C] native_recalculations_skipped strategy_native_recalculations_v1
86 * [C] current_execution_point pf_native_decision_v1::price / ::quote_kind, on every callback
87 * [C] trail_state strategy_native_trail_state_v1
88 * [--] inspect_current_execution its preview carries the account-effect projection and a variable-
89 * length closed-row P&L vector with no size-prefixed POD;
90 * strategy_native_execute_current_v1 answers the same verdicts as
91 * pf_native_execute_outcome_e and pf_native_refusal_e
92 * [C] execute_current strategy_native_execute_current_v1
93 * [C] native_series_bar strategy_native_series_bar_v1
94 * [C] declare_timeframe_subscriptions strategy_native_declare_subscriptions_v1
95 * [--] declare_auxiliary_feed a C host declares the run's auxiliary finer feed up front, in
96 * pf_native_run_spec_ext_v1's auxiliary tail under
97 * PF_NATIVE_SPEC_EXT_AUXILIARY_FEED; the begin-time REPLACEMENT
98 * takes a std::optional<NativeAuxiliaryFeed> with no size-
99 * prefixed POD, and withdrawing a feed the spec declared has no
100 * C caller
101 * [C] append_auxiliary_bars strategy_native_append_auxiliary_bars_v1
102 * [C] configure_native strategy_configure_native_v1 / strategy_configure_native_ext_v1
103 * [C] configure_native_fx_curve strategy_configure_native_fx_curve_v1 (pineforge.h)
104 * [C] native_state strategy_native_state_v1
105 * [C] submit strategy_native_submit_v1
106 * [C] replace strategy_native_replace_v1
107 * [--] submit_market a C++ convenience that REFUSES non-market extras instead of dropping
108 * them; the same request is strategy_native_submit_v1 with
109 * PF_NATIVE_TRIGGER_MARKET and a zero-filled struct
110 * [--] replace_market the same convenience for a replace; see submit_market
111 * [C] cancel strategy_native_cancel_v1
112 * [C] native_working_requests strategy_native_working_len_v1 / strategy_native_working_get_v1
113 * [C] native_open_lots strategy_native_open_lot_count_v1 / strategy_native_open_lot_get_v1
114 * [C] cancel_all strategy_native_cancel_all_v1
115 * [C] cancel_where strategy_native_cancel_where_v1
116 * [C] cohort_open strategy_native_cohort_open_v1
117 * [C] cohort_add strategy_native_cohort_add_v1
118 * [C] cohort_remove strategy_native_cohort_remove_v1
119 * [C] physical_position strategy_native_position_v1
120 * [C] native_marked_equity strategy_native_marked_equity_v1
121 * [C] native_liquidation_price strategy_native_liquidation_price_v1
122 * [C] native_risk_state strategy_native_risk_state_v1
123 * [C] native_events strategy_native_events_v1
124 * [C] native_decision_floor pf_native_state_v1::decision_floor_ms
125 * [C] native_consumed_high_water pf_native_state_v1::consumed_high_water
126 * [C] native_continuation_hash strategy_native_continuation_hash_v1
127 * [--] native_sized_units the basis it converts is the C++ native_order::Sized variant,
128 * which has no size-prefixed POD of its own (pf_native_request_v1
129 * carries a sizing BLOCK, not the variant); a C host submits
130 * PF_NATIVE_INTENT_SIZED and reads the units the kernel resolved
131 * from the applied execution
132 *
133 * One asymmetry this list does not reach, recorded here because a C host will
134 * look for it: pf_trade_t carries no exit ticket. That POD is the codegen
135 * ABI's, runtime-allocated and iterated with the caller's own sizeof, so a
136 * tail costs a PF_ABI_VERSION bump for every existing consumer — and it needs
137 * none. strategy_closed_trade_entry_id / _exit_id / _exit_comment /
138 * _close_cause (pineforge.h) index exactly the rows of pf_report_t::trades,
139 * are implemented in the kernel archive, and take any handle, so a C host
140 * reads back the ticket its own margin model declared
141 * (pf_native_run_spec_ext_v1::margin_liquidation_label) without a new symbol.
142 * Executed by the fx-roll scenario of tests/test_native_c_api.c.
143 *
144 * HARDENING RULES
145 * ───────────────
146 * - Every struct is tagged and size-prefixed: `struct_size` is the exact
147 * sizeof of the version the caller compiled against, `version` is that
148 * layout's version constant. A mismatch is refused with PF_NATIVE_E_STRUCT
149 * and mutates nothing. The one exception is the deliberately additive tail
150 * of pf_native_run_spec_ext_v1: that struct has three published layouts and
151 * the runtime accepts each (see PF_NATIVE_RUN_SPEC_EXT_V1_BASE_SIZE and
152 * PF_NATIVE_RUN_SPEC_EXT_V1_RISK_SIZE).
153 * - Every enum-valued field is translated by an exhaustive switch. A value
154 * outside its enumeration is refused with PF_NATIVE_E_TAG; a value this
155 * version deliberately cannot represent is refused with
156 * PF_NATIVE_E_UNSUPPORTED. No C value is ever cast onto a C++ variant.
157 * - C callbacks must not unwind. A callback that returns non-zero latches
158 * NativeFailureCode::CallbackException (PF_NATIVE_FAILURE_CALLBACK) and the
159 * run ends Failed; the code is readable with strategy_native_state_v1.
160 * - Commands follow the kernel's existing legality rule: inside a callback,
161 * or between realtime inputs. A command issued anywhere else returns
162 * PF_NATIVE_E_STATE and changes nothing.
163 *
164 * STABILITY
165 * ─────────
166 * Same guarantee as <pineforge/pineforge.h>: within a major version the
167 * layouts below are append-only and the signatures never change. A later
168 * revision appends fields and raises the version constant; the size prefix
169 * keeps an old caller refused rather than silently misread.
170 */
171
172#ifndef PINEFORGE_NATIVE_C_API_H
173#define PINEFORGE_NATIVE_C_API_H
174
175#include <stdint.h>
176#include <stddef.h>
177
178/* pf_strategy_t, pf_bar_t, pf_report_t, PF_API. pineforge.h includes this
179 * header back at its end; both guards make either include order work. */
180#include <pineforge/pineforge.h>
181
182/** Feature probe for the C-level native host API.
183 * When defined, #strategy_native_host_create_v1 is available. */
184#define PINEFORGE_HAS_NATIVE_C_API_V1 1
185
186/** Monotonic version of this header's native-C layouts. Every versioned
187 * struct below carries it in its `version` field. */
188#define PF_NATIVE_API_VERSION 1
189
190#ifdef __cplusplus
191extern "C" {
192#endif
193
194/** @defgroup pf_native_c_status Status codes
195 * @brief Every `int`-returning symbol here answers 0 or one of these.
196 *
197 * Negative values are errors and never mutate run state. Non-negative
198 * values are outcomes: 0 is success everywhere, and
199 * #strategy_native_execute_current_v1 additionally answers the positive
200 * #pf_native_execute_outcome_t codes.
201 * @{ */
202#define PF_NATIVE_OK 0 /**< Success. */
203#define PF_NATIVE_E_HANDLE -1 /**< NULL handle, or not a C-callback native host. */
204#define PF_NATIVE_E_STRUCT -2 /**< `struct_size` / `version` mismatch. */
205#define PF_NATIVE_E_TAG -3 /**< An enum field outside its enumeration. */
206#define PF_NATIVE_E_ARGUMENT -4 /**< NULL output, negative count, out-of-range index. */
207#define PF_NATIVE_E_STATE -5 /**< Illegal here: the command legality rule, or the
208 * kernel's own lifecycle, refused it. */
209#define PF_NATIVE_E_REJECTED -6 /**< The kernel rejected the request (reason written out). */
210#define PF_NATIVE_E_UNSUPPORTED -7 /**< A tag this API version cannot represent. */
211#define PF_NATIVE_E_EXCEPTION -8 /**< A C++ exception was contained at the boundary. */
212#define PF_NATIVE_E_NOT_WORKING -9 /**< The target handle is no longer a live request. */
213#define PF_NATIVE_E_INVALID_TARGET -10 /**< The target handle was never issued by this run. */
214#define PF_NATIVE_E_RUN_FAILED -11 /**< The run did not reach Completed; read the state. */
215#define PF_NATIVE_E_REFUSED -12 /**< execute_current refused; see pf_native_refusal_e. */
216/** Non-negative outcome: the kernel HAS no answer here and the output was
217 * left at its documented empty. It is not an error — the C++ spelling of
218 * each accessor that returns it is a `std::optional`, whose empty is a
219 * legitimate answer (no path walk, an unarmed trail, a series that has not
220 * delivered, a run with no margin model). Only the accessors whose own
221 * documentation names it can return it; #strategy_native_execute_current_v1
222 * never does, its positive codes being #pf_native_execute_outcome_t. */
223#define PF_NATIVE_ABSENT 1
224/** @} */
225
226/** `NativeFailureCode::CallbackException` — the code latched when a C callback
227 * returns non-zero. Mirrors the C++ enumerator; pinned by a static_assert. */
228#define PF_NATIVE_FAILURE_CALLBACK 5
229
230/** @defgroup pf_native_c_enums Translated enumerations
231 * @brief Every value below is the exact integer of the C++ alternative it
232 * names, pinned by static_asserts in src/native_c_host.cpp.
233 * @{ */
234
235/** Order intent — the alternative index of `native_order::OrderIntent`. */
236typedef enum pf_native_intent_e {
237 PF_NATIVE_INTENT_FLATTEN = 0, /**< Close the whole book. */
238 PF_NATIVE_INTENT_REDUCE = 1, /**< Reduce; see #pf_native_reduction_t. */
239 PF_NATIVE_INTENT_TRANSACT = 2, /**< `intent_value` signed units. */
240 PF_NATIVE_INTENT_REVERSE_TO = 3, /**< `intent_value` target signed exposure. */
241 PF_NATIVE_INTENT_HOST_SIZED = 4, /**< The cohort close, and nothing else;
242 * see #PF_NATIVE_OWNER_BIND_COHORT.
243 * Refused PF_NATIVE_E_UNSUPPORTED
244 * under any other owner. */
245 PF_NATIVE_INTENT_SIZED = 5 /**< Kernel-sized opening (L3). */
247
248/** Reduction size — the alternative index of `native_order::ReductionSize`. */
249typedef enum pf_native_reduction_e {
250 PF_NATIVE_REDUCE_EXPLICIT_UNITS = 0, /**< `intent_value` units. */
251 PF_NATIVE_REDUCE_OWNER_OPENED = 1, /**< Exactly what the owner opened. */
252 PF_NATIVE_REDUCE_SCOPE_FRACTION = 2 /**< `intent_value` fraction in (0, 1]. */
254
255/** Scope claim of a fractional reduce. */
260
261/** Side of a kernel-sized opening. */
262typedef enum pf_native_side_e {
266
267/** Sizing basis — the alternative index of `native_order::SizeBasis`. */
268typedef enum pf_native_size_basis_e {
269 PF_NATIVE_SIZE_BASIS_CASH = 0, /**< `intent_value` account-currency cash. */
270 PF_NATIVE_SIZE_BASIS_EQUITY_FRACTION = 1 /**< `intent_value` fraction of marked equity. */
272
273/** When a sizing basis resolves. */
278
279/** Whether resolved sizing snaps onto the run's quantity grid. */
280typedef enum pf_native_grid_policy_e {
284
285/** Trigger — the alternative index of `native_order::Trigger`. */
286typedef enum pf_native_trigger_e {
287 PF_NATIVE_TRIGGER_MARKET = 0, /**< p1, p2 ignored. */
288 PF_NATIVE_TRIGGER_LIMIT = 1, /**< p1 = price; `fill_through` makes it market-if-touched. */
289 PF_NATIVE_TRIGGER_STOP = 2, /**< p1 = price. */
290 PF_NATIVE_TRIGGER_STOP_LIMIT = 3, /**< p1 = stop, p2 = limit. */
291 PF_NATIVE_TRIGGER_TRAIL = 4 /**< p1 = offset, p2 = arm price when `trail_has_arm_price`. */
293
294/** Where a trigger level comes from — `native_order::TriggerAnchor` (L7). */
295typedef enum pf_native_anchor_e {
296 PF_NATIVE_ANCHOR_ABSOLUTE = 0, /**< The level written in the trigger. */
297 PF_NATIVE_ANCHOR_FROM_OWNER_FILL = 1 /**< owner fill + `anchor_offset` (signed). */
299
300/** How a materialized anchored level snaps onto the run's price tick ladder —
301 * `native_order::NativeAnchorRounding` (L7b). RAW is the established
302 * behaviour; the other two need `price_tick > 0` at acceptance. */
303typedef enum pf_native_anchor_rounding_e {
304 PF_NATIVE_ANCHOR_ROUNDING_RAW = 0, /**< fill + offset exactly. */
305 PF_NATIVE_ANCHOR_ROUNDING_HALF_UP = 1, /**< Nearest tick, ties away from zero. */
306 PF_NATIVE_ANCHOR_ROUNDING_DIRECTIONAL = 2 /**< Toward the region the leg needs. */
308
309/** Whether a WAIT_FOR_APPLIED child is a working order before its arm —
310 * `native_order::NativeArmVisibility` (L7b). PENDING_UNTIL_ARMED keeps it
311 * out of #strategy_native_working_len_v1 / #strategy_native_working_get_v1
312 * until its ArmedEvent; it stays a live request the whole time (replace,
313 * cancel, cancel_all still address it, and it never matches before the arm
314 * under either value). */
319
320/** Capacity — the alternative index of `native_order::Capacity`. */
321typedef enum pf_native_capacity_e {
322 PF_NATIVE_CAPACITY_IMMEDIATE = 0, /**< Whole remaining at one point. */
323 PF_NATIVE_CAPACITY_POINT_BUDGET = 1 /**< `capacity_units` per matching point. */
325
326/** Owner — the alternative index of `native_order::Owner`. */
327typedef enum pf_native_owner_e {
328 PF_NATIVE_OWNER_INDEPENDENT = 0, /**< No owner. */
329 PF_NATIVE_OWNER_WAIT_FOR_APPLIED = 1, /**< One parent in `owner_incarnations`. */
330 PF_NATIVE_OWNER_BIND_OPENING = 2, /**< One opening + `owner_cycle`. */
331 PF_NATIVE_OWNER_BIND_OPENINGS = 3, /**< `owner_n` openings + `owner_cycle`. */
332 /** `cohort` from #strategy_native_cohort_open_v1. The kernel pairs this
333 * owner with exactly one intent — a host-sized CLOSE — so a cohort close
334 * is spelled #PF_NATIVE_INTENT_HOST_SIZED with this owner and no
335 * quantity of its own: the roster's live openings are the target and the
336 * cohort authority decides the units. That pairing is the only shape in
337 * which HOST_SIZED is accepted here. */
340
341/** Group — the alternative index of `native_order::Group`. */
342typedef enum pf_native_group_e {
344 PF_NATIVE_GROUP_MEMBER = 1 /**< `group_id`, `group_cohort`, `group_effect`. */
346
347/** What a filled group member does to its siblings. */
348typedef enum pf_native_group_effect_e {
352
353/** Which identity text #strategy_native_cancel_where_v1 compares.
354 *
355 * Both are the free text the request carried: `comment` is the established
356 * selector, `label` is where a host that names its orders puts its own id,
357 * so LABEL is the one call that withdraws every live request issued under
358 * one such id. Neither is indexed; both walk the live book once. */
359typedef enum pf_native_request_field_e {
363
364/** Price rule of an immediate execution. */
369
370/** Outcome of #strategy_native_execute_current_v1 (non-negative returns). */
371typedef enum pf_native_execute_outcome_e {
372 PF_NATIVE_EXECUTED_APPLIED = 0, /**< An execution was applied. */
373 PF_NATIVE_EXECUTED_NO_EFFECT = 1, /**< Legal, nothing to execute. */
374 PF_NATIVE_EXECUTED_MATCH_REJECTED = 2, /**< Terms/admission rejected it. */
375 PF_NATIVE_EXECUTED_CANCELLED = 3 /**< The request was cancelled instead. */
377
378/** Why execute_current refused. Written to `*refusal`, if supplied, when
379 * #strategy_native_execute_current_v1 answers PF_NATIVE_E_REFUSED. Mirrors
380 * `NativeCurrentRefusal`. */
392
393/** Lifecycle of the native run — mirrors `NativeLifecycleKind`. */
401
402/** Event tag of #pf_native_event_v1.
403 *
404 * 1..18 are the first eighteen alternatives of `native_order::CommandEvent`,
405 * in variant order plus one; 19 and 20 are the driver-point and account
406 * observations `native_events()` also carries. 21 is L9's `NativeRiskEvent`,
407 * the nineteenth CommandEvent alternative: it was added after this header
408 * froze, so it keeps a tag of its own past the two observations rather than
409 * taking 19 and renumbering them. A reader compiled before it skips it by
410 * tag, exactly as it must skip any tag it does not know.
411 *
412 * One kind named in the design is NOT represented and never appears here: a
413 * completed higher-timeframe bucket, delivered only through
414 * `on_timeframe_bar` and never recorded in the event history. */
438
439/** Which generic risk limit a #PF_NATIVE_EVENT_RISK event reports — the
440 * `reason` field of #pf_native_event_v1, mirroring
441 * `native_order::RiskLimitKind` (L9). */
448
449/** Which day a risk limit's "day" is — `NativeRiskDay`. SESSION is the run's
450 * own session calendar (an overnight session is one day); CALENDAR_TIMEZONE
451 * is the civil date in the spec's scheduling timezone. */
456
457/** What a breach does — `NativeRiskAction`. BLOCK_OPENINGS refuses every
458 * opening while the block lasts and leaves the live book alone;
459 * FLATTEN_AND_BLOCK first closes the book with one kernel-originated
460 * Flatten. */
465
466/** Remaining projection of a live request — `native_order::RemainingProjection`. */
474
475/** Trigger state of a live request — `native_order::TriggerState`. */
487
488/** Which extension blocks of #pf_native_run_spec_ext_v1 are meaningful. */
489typedef enum pf_native_spec_ext_mask_e {
496 /** L9's generic risk limits. Only a caller whose
497 * pf_native_run_spec_ext_v1 carries the risk tail may set this bit; a
498 * caller sending the base layout is refused with PF_NATIVE_E_STRUCT. */
500 /** The retained intrabar execution path. Needs the N8 tail. */
502 /** The four feed-shape and presentation policies: slot labels, feed
503 * tolerance, the forced path order and abort reporting. Needs the N8
504 * tail. */
506 /** The auxiliary finer feed. Only a caller whose
507 * pf_native_run_spec_ext_v1 carries the auxiliary tail may set this bit;
508 * a caller sending any earlier layout is refused with
509 * PF_NATIVE_E_STRUCT. */
512
513/** The bars a declared series is built from — `NativeSeriesSource`. */
514typedef enum pf_native_series_source_e {
515 PF_NATIVE_SERIES_SOURCE_INPUT = 0, /**< The accepted input (the default). */
516 PF_NATIVE_SERIES_SOURCE_AUXILIARY_FEED = 1 /**< The run's auxiliary finer feed. */
518
519/** WHICH price a kernel-sized basis converts at — `native_order::SizePrice`
520 * (L3b). RESOLVED is the established behaviour: the price the kernel would
521 * otherwise settle at. SIGNAL is the decision-point price at placement,
522 * carried to the expected fill by the side's slippage and rounded onto the
523 * run's fill grid. SIGNAL_ON_TICK is that same rule measured on the
524 * INSTRUMENT's own tick ladder (`price_tick`) instead of the fill grid,
525 * rounded before the slippage as well as after. */
531
532/** WHICH measurement of the bound scope a fractional reduce takes its
533 * fraction of — `native_order::ScopeBasis`. AT_MATCH reads the scope as it
534 * stands at the matching candidate. AT_ACCEPTANCE freezes the scope SIZE
535 * when the request is accepted, so two 50 % siblings on one 10-unit lot both
536 * claim 5 under GROSS even after the first has executed. */
541
542/** When the kernel tests the maintenance requirement —
543 * `NativeLiquidationCheck`, the `margin_check` field of
544 * #pf_native_run_spec_ext_v1. */
545typedef enum pf_native_liquidation_check_e {
546 PF_NATIVE_LIQUIDATION_PATH_ADVERSE_EXTREME = 0, /**< Solve and rest at the level. */
547 PF_NATIVE_LIQUIDATION_CALCULATION_ONLY = 1, /**< Test the mark; rest nothing. */
548 PF_NATIVE_LIQUIDATION_PATH_ADVERSE_EXTREME_MARK = 2 /**< Rest AT the adverse mark. */
550
551/** Which equity the maintenance requirement is tested against —
552 * `NativeMarginEquityBasis`. */
557
558/** Which base the liquidation level is solved from —
559 * `NativeLiquidationLevelBase`. */
564
565/** Which intrabar execution path the run retains — the alternative of
566 * `IntrabarPath`. NONE is the whole default surface. LOWER_TF retains the
567 * caller's own finer bars (and is the one mode that delivers
568 * #pf_native_callbacks_v1::on_sub_bar). SYNTHESIZED samples each script
569 * bar's own OHLC path through the generic sampler and retains no feed. */
575
576/** Whether matching stays continuous between generated samples —
577 * `IntrabarPath::SampleEligibility`. LOWER_TF only; a synthesized path's
578 * point-only eligibility is inherent to that mode. */
583
584/** Whether a confirmed bar must name a canonical input slot —
585 * `NativeSlotLabelPolicy`. A feed-shape policy, not a source-language one;
586 * the two modes never share a continuation. */
591
592/** Opt-in admission exceptions for a tolerated input-feed shape —
593 * `NativeFeedTolerance`. A BIT MASK, not an enumerator: the values combine,
594 * and any bit outside this set is PF_NATIVE_E_TAG. */
595typedef enum pf_native_feed_tolerance_e {
597 /** Finite OHLC need not be positive; NaN volume means unavailable. */
599 /** Stream warmups admit finite, non-negative interim OHLC. */
602
603/** Generic ordering for a modeled OHLC path — `NativePathOrder`. AUTO keeps
604 * the open-proximity rule; the forced modes make the first excursion
605 * explicit for replay and live hosts. */
611
612/** How a cooperative abort is presented — `NativeAbortReporting`. */
613typedef enum pf_native_abort_reporting_e {
617
618/** Why the kernel is asking the host to calculate — `NativeCalculationReason`
619 * (L5), the `reason` argument of #pf_native_callbacks_v1::on_recalculate.
620 * SUB_BAR is reserved and never delivered there: a lower-timeframe sub-bar
621 * has its own hook, #pf_native_callbacks_v1::on_sub_bar. */
622typedef enum pf_native_calc_reason_e {
623 PF_NATIVE_CALC_BAR_CLOSE = 0, /**< The script bar's own calculation; `cause` NULL. */
624 PF_NATIVE_CALC_ORDER_FILL = 1, /**< At an applied execution's cursor; `cause` is it. */
625 PF_NATIVE_CALC_TICK = 2, /**< At a modeled point or print; `cause` NULL. */
626 PF_NATIVE_CALC_SUB_BAR = 3 /**< Reserved; see on_sub_bar. */
628
629/** Which kernel check point is about to test the maintenance requirement —
630 * `NativeMarginCheckKind` (L4b). These are the kernel's own points; a broker
631 * model that checks somewhere else is host policy, expressed by suppressing
632 * the points it does not share. */
633typedef enum pf_native_margin_check_kind_e {
634 PF_NATIVE_MARGIN_CHECK_BAR_OPEN = 0, /**< The script bar's open. */
635 PF_NATIVE_MARGIN_CHECK_AFTER_APPLIED = 1, /**< The re-arm after a point's fills. */
636 PF_NATIVE_MARGIN_CHECK_CALCULATION = 2, /**< A CalculationOnly model's calculation. */
637 PF_NATIVE_MARGIN_CHECK_FX_ROLL = 3 /**< A step of the run's declared
638 * #pf_native_fx_curve_v1: the first point
639 * the account converts at a new rate,
640 * offered immediately before that point is
641 * matched. A run that declares no curve has
642 * none, and a CalculationOnly model, which
643 * measures at its calculation alone, is not
644 * offered it. */
646
647/** What an ANSWERING callback's return value means.
648 *
649 * The four answering hooks of #pf_native_callbacks_v1 do not report success:
650 * their return value selects WHOSE answer the kernel uses, so every value is
651 * in contract and an answering hook can never fail the run. A host that
652 * needs to abort does it from an observation callback, which keeps the
653 * "non-zero ends the run Failed" rule exactly where it already was. */
654typedef enum pf_native_answer_e {
655 PF_NATIVE_ANSWER_DEFAULT = 0, /**< Keep the kernel's own; the output is ignored. */
656 PF_NATIVE_ANSWER_PROVIDED = 1 /**< Use the output. Any non-zero value means this. */
658
659/** @} */ /* end of pf_native_c_enums */
660
661/** @defgroup pf_native_c_types Transport types
662 * @{ */
663
664/** Where the kernel is, presented to every callback.
665 *
666 * A read-only snapshot of `NativeDecisionContext` plus the current quote:
667 * `price` is the execution point's price where one exists and NaN where the
668 * callback has no execution point (the bar's own close calculation). */
669typedef struct pf_native_decision_v1 {
670 uint32_t struct_size; /**< sizeof(pf_native_decision_v1). */
671 uint32_t version; /**< PF_NATIVE_API_VERSION. */
672 uint64_t ordinal; /**< Matching-point ordinal. */
673 int32_t interval_index; /**< Script interval index. */
674 int32_t sub_index; /**< Sub-bar index inside the script bar. */
675 int32_t sub_count; /**< Sub-bars in this script bar (1 when unmagnified). */
676 int32_t is_terminal_sub_bar; /**< 1 on the script bar's last sub-bar. */
677 int64_t effective_time_ms; /**< The point's effective decision time. */
678 int64_t script_bar_open_ms; /**< Open of the script bar under delivery. */
679 int64_t sub_bar_open_ms; /**< Open of the sub-bar under delivery. */
680 int64_t decision_floor_ms; /**< Lower bound a new request may be matched at. */
681 double price; /**< Current quote, NaN outside an execution point. */
682 uint8_t provenance; /**< NativePriceProvenance. */
683 uint8_t path_phase; /**< NativePathPhase. */
684 uint8_t completion; /**< NativeCompletionKind. */
685 uint8_t quote_kind; /**< NativeCurrentQuoteKind; 0 when price is NaN. */
687
688/** One applied execution, presented to `on_applied`. */
689typedef struct pf_native_applied_v1 {
690 uint32_t struct_size; /**< sizeof(pf_native_applied_v1). */
691 uint32_t version; /**< PF_NATIVE_API_VERSION. */
692 uint64_t ordinal; /**< Event ordinal. */
693 uint64_t incarnation; /**< The request that executed. */
694 uint64_t opened_lot_incarnation; /**< The lot this fill opened, 0 when none. */
695 double raw_price; /**< The path price the match was found at. */
696 double resolved_price; /**< The booked price after terms and slippage. */
697 double closed_units; /**< Units closed by this fill. */
698 double opened_units; /**< Units opened by this fill. */
699 double filled_working; /**< Working units this fill consumed. */
700 double ticket; /**< `current_ticket` at the fill. */
701 int64_t cycle_before; /**< Position cycle before the fill. */
702 int64_t cycle_after; /**< Position cycle after the fill. */
703 uint8_t terminal; /**< 1 when the request is finished. */
704 uint8_t terminal_reason; /**< AppliedTerminalReason, valid when `has_terminal_reason`. */
705 uint8_t has_terminal_reason; /**< 1 when `terminal_reason` is meaningful. */
706 uint8_t reserved0;
708
709/** One recorded event, read back by #strategy_native_events_v1.
710 *
711 * `kind` tags the union: every field below is documented per kind and is
712 * zero where that kind has no such fact.
713 * - ACCEPTED / ARMED / CLOSE_BOUND / QUANTITY_BOUND: `incarnation`.
714 * - REJECTED / REPLACE_REJECTED: `reason` is a RequestRejectReason.
715 * - REPLACED: `incarnation` is the predecessor, `successor` the new handle.
716 * - CANCELLED: `reason` is a CancelReason.
717 * - MATCH_REJECTED: `reason` is a MatchRejectReason, cursor fields set.
718 * - APPLIED: every price/unit/cycle field, `terminal`, cursor fields.
719 * - MARGIN_CALL: `price` = mark, `closed_units` = liquidated units,
720 * `raw_price` = the re-solved liquidation price.
721 * - ACTIVATED: `reason` is an ActivationKind, `price` the reached price.
722 * - DRIVER_POINT: cursor fields and `raw_price`.
723 * - ACCOUNT: `price` = marked equity, `raw_price` = realized balance,
724 * `opened_units` = signed position units.
725 * - RISK: `reason` is a #pf_native_risk_limit_t, `price` = the observed
726 * value that reached the limit, `raw_price` = the limit it was measured
727 * against (account currency for the two loss limits — a percent limit is
728 * already resolved against its basis equity — days or fills for the two
729 * counts), `cycle_before` = the risk day the breach happened on, on the
730 * spec's own day basis, `successor` = the cursor's matching-point
731 * ordinal, cursor fields set. The event names no request: it is an
732 * account fact, so `incarnation` stays 0. */
733typedef struct pf_native_event_v1 {
734 uint32_t struct_size; /**< sizeof(pf_native_event_v1). */
735 uint32_t version; /**< PF_NATIVE_API_VERSION. */
736 uint32_t kind; /**< #pf_native_event_kind_t. */
737 uint32_t reason; /**< Per-kind reason enumerator, 0 when none. */
738 uint64_t ordinal; /**< Event ordinal; strictly increasing. */
739 uint64_t incarnation; /**< Subject request, 0 when the kind has none. */
740 uint64_t successor; /**< REPLACED: the new handle. RISK: the cursor's
741 * matching-point ordinal. 0 otherwise. */
742 double raw_price;
744 double price;
748 int64_t cycle_after;
749 int64_t effective_time_ms; /**< Cursor effective time, 0 when the kind has no cursor. */
750 int32_t interval_index; /**< Cursor interval index. */
751 uint8_t provenance; /**< Cursor NativePriceProvenance. */
752 uint8_t path_phase; /**< Cursor NativePathPhase. */
753 uint8_t terminal; /**< APPLIED only. */
754 uint8_t reserved0[3];
756
757/** One live request, copied out by #strategy_native_working_get_v1.
758 *
759 * `label` and `comment` borrow the snapshot taken by the most recent
760 * #strategy_native_working_len_v1 call on this handle. They stay valid until
761 * the next call to that function, or until the host is freed; copy them if
762 * the host keeps them longer. */
763typedef struct pf_native_working_v1 {
764 uint32_t struct_size; /**< sizeof(pf_native_working_v1). */
765 uint32_t version; /**< PF_NATIVE_API_VERSION. */
766 uint64_t incarnation; /**< The request's handle. */
767 uint32_t intent; /**< #pf_native_intent_t as accepted. */
768 uint32_t trigger; /**< #pf_native_trigger_t as accepted. */
769 uint32_t owner; /**< #pf_native_owner_t as accepted. */
770 uint32_t capacity; /**< #pf_native_capacity_t as accepted. */
771 uint32_t group_kind; /**< #pf_native_group_t as accepted. */
772 uint32_t group_effect; /**< #pf_native_group_effect_t, 0 when no group. */
773 uint32_t remaining_kind; /**< #pf_native_remaining_t. */
774 uint32_t trigger_state; /**< #pf_native_trigger_state_t. */
775 uint32_t origin; /**< RequestOrigin: 0 host, 1 kernel liquidation, 2 kernel risk. */
776 uint32_t reserved0;
777 double intent_value; /**< The intent's own scalar, 0 when it has none. */
778 double p1; /**< Trigger level 1 (limit / stop / trail offset). */
779 double p2; /**< Trigger level 2 (stop-limit limit / trail arm). */
780 double capacity_units; /**< Point budget, 0 for immediate capacity. */
781 double remaining_units; /**< Valid when `remaining_kind` is UNITS. */
782 uint64_t group_id;
784 uint64_t acceptance_ordinal; /**< Birth: the accepting event. */
785 int64_t decision_time_lower_bound; /**< Birth: earliest matchable time. */
786 const char* label; /**< Borrowed; see the struct note. */
787 const char* comment; /**< Borrowed; see the struct note. */
789
790/** One open physical lot, copied out by #strategy_native_open_lot_get_v1 —
791 * the C spelling of `NativeOpenLot` (R5 gap lane N18): the book that
792 * #strategy_native_position_v1 aggregates, lot by lot, marked at the price
793 * #strategy_native_open_lot_count_v1 was given. Every field is what the
794 * kernel already holds for the lot; reading it moves nothing.
795 *
796 * `unrealized_pnl` is the lot's own term of the marked equity: the move from
797 * `entry_price` to `mark`, in account currency, less `entry_commission`.
798 * The two excursions are the largest moves for and against the lot the
799 * kernel has sampled along the delivered path, in account currency, gross
800 * of fees, with `mark` folded in. A NaN `mark` keeps every booking fact,
801 * leaves `unrealized_pnl` NaN and folds nothing into the excursions.
802 *
803 * `entry_label` and `entry_comment` borrow the snapshot taken by the most
804 * recent #strategy_native_open_lot_count_v1 call on this handle. They stay
805 * valid until the next call to that function, or until the host is freed;
806 * copy them if the host keeps them longer. */
807typedef struct pf_native_open_lot_v1 {
808 uint32_t struct_size; /**< sizeof(pf_native_open_lot_v1). */
809 uint32_t version; /**< PF_NATIVE_API_VERSION. */
810 uint64_t ordinal; /**< Position in the book, oldest first. */
811 uint64_t entry_incarnation; /**< The request whose fill opened the lot; never
812 * reused; 0 only for a legacy synthetic lot. */
813 int64_t cycle; /**< The position cycle the lot belongs to — the
814 * `owner_cycle` a BIND_OPENING(S) request names. */
815 uint32_t side; /**< #pf_native_side_t. */
816 int32_t entry_bar_index; /**< Script-bar index of the opening fill. */
817 int64_t entry_time_ms; /**< Effective time of the opening fill. */
818 double entry_price; /**< Booked entry price. */
819 double signed_units; /**< Remaining units: > 0 long, < 0 short. */
820 double entry_commission; /**< Entry fee still on the lot, account currency;
821 * a partial realization takes its share with it. */
822 double mark; /**< The price the three fields below were marked at. */
823 double unrealized_pnl; /**< Fee-net move to `mark`, account currency; NaN for a NaN mark. */
824 double favorable_excursion; /**< Largest move for the lot so far, account currency, >= 0. */
825 double adverse_excursion; /**< Largest move against the lot so far, account currency, >= 0. */
826 const char* entry_label; /**< Borrowed; see the struct note. */
827 const char* entry_comment; /**< Borrowed; see the struct note. */
829
830/** The run's lifecycle and its typed failure. */
831typedef struct pf_native_state_v1 {
832 uint32_t struct_size; /**< sizeof(pf_native_state_v1). */
833 uint32_t version; /**< PF_NATIVE_API_VERSION. */
834 uint32_t lifecycle; /**< #pf_native_lifecycle_t. */
835 uint32_t failure_code; /**< NativeFailureCode; PF_NATIVE_FAILURE_CALLBACK for a
836 * callback that returned non-zero. */
837 uint32_t failure_operation; /**< NativeFailureOperation. */
839 uint64_t failure_ordinal; /**< The point the failure was latched at, 0 when absent. */
842 uint32_t phase; /**< NativeRunPhase while Running. */
843 uint32_t completion; /**< NativeCompletion once Completed. */
845
846/** The trail projection of #strategy_native_trail_state_v1 — the C spelling
847 * of `NativeTrailState`. Before the arm is reached `activated` is 0 and
848 * every other field is 0; once armed, `best_price` and `current_level` are
849 * the exact raw matcher values and `activation_ordinal` identifies the
850 * TrailArm event that began tracking. */
852 uint32_t struct_size; /**< sizeof(pf_native_trail_state_v1). */
853 uint32_t version; /**< PF_NATIVE_API_VERSION. */
854 uint32_t activated; /**< 0/1: the arm price has been reached. */
855 uint32_t reserved0;
856 double best_price; /**< Running best; 0 before the arm. */
857 double current_level; /**< The stop the best is riding; 0 before the arm. */
858 uint64_t activation_ordinal; /**< The TrailArm event; 0 before the arm. */
860
861/** The facts one margin hook is handed — the C spelling of
862 * `NativeMarginRequirementView`, `NativeMarginCheckPoint` and
863 * `NativeMarginCallView`, which differ only in which of these facts they
864 * carry. Every field is documented per hook and is zero where that hook has
865 * no such fact, exactly as #pf_native_event_v1's union is:
866 *
867 * - on_margin_check: `kind`, `liquidation_resting`, the position, `mark`
868 * and the cursor. `equity` and `required` are 0 — nothing has been
869 * evaluated yet at that point.
870 * - on_margin_requirement: `kind`, the position, `mark`, and the two
871 * numbers the kernel is ABOUT to compare (`equity`, `required`) — exactly
872 * what it would compare if the host answered PF_NATIVE_ANSWER_DEFAULT.
873 * - on_margin_call_units: the position being liquidated, the sizing `mark`,
874 * the `equity` and `required` measured there, and the cursor. `kind` and
875 * `liquidation_resting` are 0: a call is not a check point. */
877 uint32_t struct_size; /**< sizeof(pf_native_margin_view_v1). */
878 uint32_t version; /**< PF_NATIVE_API_VERSION. */
879 uint32_t kind; /**< #pf_native_margin_check_kind_t. */
880 uint32_t liquidation_resting; /**< 0/1: a liquidation rests from an earlier point. */
881 double signed_units; /**< The book being measured. */
883 uint64_t lot_count;
884 double mark; /**< The price the breach is measured at. */
885 double equity; /**< Marked equity on the model's basis. */
886 double required; /**< Maintenance requirement of the whole position at `mark`. */
889 double cursor_t;
891 uint8_t cursor_provenance; /**< NativePriceProvenance. */
892 uint8_t cursor_path_phase; /**< NativePathPhase. */
893 uint8_t reserved0[2];
895
896/** The host's answer to one requirement view — `NativeMarginDecision`.
897 * `required` and `equity` replace the kernel's two numbers for that check
898 * point only: they are a broker's money rule, never a second account.
899 * `force_breach` makes the kernel proceed past `required > equity` even when
900 * the answered numbers do not meet it. Read only when the hook answers
901 * #PF_NATIVE_ANSWER_PROVIDED; a nonfinite `required` or `equity` is refused
902 * by the kernel and the check point is abandoned, exactly as in C++. */
904 uint32_t struct_size; /**< sizeof(pf_native_margin_decision_v1). */
905 uint32_t version; /**< PF_NATIVE_API_VERSION. */
906 uint32_t force_breach; /**< 0/1. */
907 uint32_t reserved0;
908 double required;
909 double equity;
911
912/** The facts a host-sized CLOSE is resolved from, handed to
913 * #pf_native_callbacks_v1::on_close_units.
914 *
915 * It is the UNITS half of `NativeExecutionTermsFacts`, and only that half:
916 * `scope_exposure_units` is what the bound scope holds at this candidate —
917 * for a cohort close, the live units of the roster's own openings and
918 * nothing else. The price half and the opening shape stay the kernel's. */
920 uint32_t struct_size; /**< sizeof(pf_native_close_view_v1). */
921 uint32_t version; /**< PF_NATIVE_API_VERSION. */
922 uint64_t incarnation; /**< The request being resolved. */
923 double scope_exposure_units; /**< What the bound scope holds here. */
924 double default_resolved_price; /**< The price the kernel would settle at. */
925 double position_units; /**< The whole physical book, signed. */
928 uint32_t is_buy; /**< 0/1: the side this candidate would trade on. */
929 uint32_t reserved0;
931
932/** One closing lot's booking facts — `ClosedLotExcursionFacts` (RULING A48).
933 * Handed to #pf_native_callbacks_v1::on_lot_excursion, whose two outputs are
934 * the favorable and adverse magnitudes the closing row then carries. Facts
935 * in, magnitudes out: nothing about the host's price model crosses the
936 * boundary in either direction. */
938 uint32_t struct_size; /**< sizeof(pf_native_lot_excursion_v1). */
939 uint32_t version; /**< PF_NATIVE_API_VERSION. */
940 uint64_t entry_incarnation; /**< The lot's opening request. */
943 double lot_qty; /**< The whole lot. */
944 double closed_qty; /**< What this fill closes of it. */
946 double carried_favorable; /**< What the lot carried in, for a partial close. */
950 uint8_t is_long;
951 uint8_t entry_bar_high_masked; /**< The entry bar's high is not this trade's. */
952 uint8_t entry_bar_low_masked; /**< The entry bar's low is not this trade's. */
953 uint8_t reserved0;
955
956/** The run's generic risk ledger — the C spelling of `NativeRiskState` (L9).
957 *
958 * Every field is its zero for a run that declares no risk block, exactly as
959 * the C++ value is. `blocked` is whether openings are refused right now and
960 * `reason` names the limit that did it (valid only when `has_reason`);
961 * `day_ordinal` is the risk day the ledger is on, on the spec's own day
962 * basis, and is meaningful only when `has_day`. Observation only: reading it
963 * moves nothing. */
965 uint32_t struct_size; /**< sizeof(pf_native_risk_state_v1). */
966 uint32_t version; /**< PF_NATIVE_API_VERSION. */
967 uint32_t blocked; /**< 0/1: openings are refused right now. */
968 uint32_t has_reason; /**< 0/1: `reason` is meaningful. */
969 uint32_t reason; /**< #pf_native_risk_limit_t that blocked. */
970 uint32_t has_day; /**< 0/1: the ledger has reached a day. */
971 uint32_t consecutive_loss_days; /**< Days that closed with a realized loss. */
972 uint32_t reserved0;
973 int64_t day_ordinal; /**< The risk day, on the spec's day basis. */
974 uint64_t fills_today; /**< Applied fills counted in that day. */
975 double peak_equity; /**< Running peak of the marked equity. */
976 double day_open_equity; /**< Equity the current day opened at. */
978
979/** One order request. Translated field by field into `native_order::Request`;
980 * it is never cast. Zero-initialise it, set `struct_size` and `version`, then
981 * set only the fields the chosen `intent` and `trigger` document.
982 *
983 * This struct has THREE published layouts and the runtime accepts any of
984 * them: the base layout the L13 lane first shipped
985 * (#PF_NATIVE_REQUEST_V1_BASE_SIZE), that layout plus L7b's anchored-leg
986 * tail (#PF_NATIVE_REQUEST_V1_ANCHOR_SIZE), and the current one, which
987 * appends L3b's sizing detail (`size_price`, `reduce_basis`). A caller
988 * compiled against an earlier layout keeps working unchanged and simply gets
989 * the later tails' defaults (RAW, WORKING, RESOLVED, AT_MATCH). Any other
990 * `struct_size` is PF_NATIVE_E_STRUCT. Both tails are append-only: nothing
991 * above them moved. */
992typedef struct pf_native_request_v1 {
993 uint32_t struct_size; /**< sizeof(pf_native_request_v1). */
994 uint32_t version; /**< PF_NATIVE_API_VERSION. */
995
996 /* Intent */
997 uint32_t intent; /**< #pf_native_intent_t. */
998 uint32_t reduce_size; /**< #pf_native_reduction_t, REDUCE only. */
999 uint32_t reduce_claim; /**< #pf_native_scope_claim_t, SCOPE_FRACTION only. */
1000 uint32_t side; /**< #pf_native_side_t, SIZED only. */
1001 uint32_t size_basis; /**< #pf_native_size_basis_t, SIZED only. */
1002 uint32_t size_time; /**< #pf_native_size_time_t, SIZED only. */
1003 uint32_t grid_policy; /**< #pf_native_grid_policy_t, SIZED only. */
1004 uint32_t reserve_percent_fee; /**< 0/1, SIZED only. */
1005 double intent_value; /**< The intent's own scalar; see #pf_native_intent_t. */
1006
1007 /* Trigger */
1008 uint32_t trigger; /**< #pf_native_trigger_t. */
1009 uint32_t anchor; /**< #pf_native_anchor_t (L7). */
1010 double p1; /**< Limit/stop price, or trail offset. */
1011 double p2; /**< Stop-limit limit, or trail arm price. */
1012 double anchor_offset; /**< FROM_OWNER_FILL: signed offset. */
1013 uint8_t fill_through; /**< LIMIT only: market-if-touched. */
1014 uint8_t trail_offset_in_ticks; /**< TRAIL: p1 is a tick count, not a distance. */
1015 uint8_t trail_has_arm_price; /**< TRAIL: p2 is the arm price. */
1016 uint8_t anchor_offset_in_ticks; /**< FROM_OWNER_FILL: the offset is a tick count. */
1017
1018 /* Capacity */
1019 uint32_t capacity; /**< #pf_native_capacity_t. */
1020 double capacity_units; /**< POINT_BUDGET only. */
1021
1022 /* Owner */
1023 uint32_t owner; /**< #pf_native_owner_t. */
1024 uint32_t owner_n; /**< Length of `owner_incarnations`. */
1025 const uint64_t* owner_incarnations; /**< Borrowed for the call only. */
1026 int64_t owner_cycle; /**< BIND_OPENING / BIND_OPENINGS. */
1027 uint64_t cohort; /**< BIND_COHORT. */
1028
1029 /* Group */
1030 uint32_t group_kind; /**< #pf_native_group_t. */
1031 uint32_t group_effect; /**< #pf_native_group_effect_t. */
1032 uint64_t group_id; /**< MEMBER only. */
1033 int64_t group_cohort; /**< MEMBER only. */
1034
1035 /* Identity. Both borrowed for the call only; the kernel copies them.
1036 * NULL is the empty string. */
1037 const char* label;
1038 const char* comment;
1039
1040 /* ── The additive anchored-leg tail (L7b). Read only when `struct_size`
1041 * is the current sizeof; a caller sending the base layout stops at
1042 * `comment` above and gets every default (RAW, WORKING). ── */
1043 uint32_t anchor_rounding; /**< #pf_native_anchor_rounding_t, FROM_OWNER_FILL only. */
1044 uint32_t visibility; /**< #pf_native_arm_visibility_t, WAIT_FOR_APPLIED only. */
1045
1046 /* ── The additive sizing-detail tail (L3b). Read only when `struct_size`
1047 * is the current sizeof; a caller sending either earlier layout stops
1048 * above and gets both defaults (RESOLVED, AT_MATCH), which is what every
1049 * request accepted before this tail already resolved as. ── */
1050 uint32_t size_price; /**< #pf_native_size_price_t, SIZED only. */
1051 uint32_t reduce_basis; /**< #pf_native_scope_basis_t, SCOPE_FRACTION only. */
1053
1054/** Byte length of #pf_native_request_v1 as the L13 lane first published it,
1055 * before the anchored-leg tail was appended. It is the offset of the first
1056 * appended field, so it stays correct on every target this header builds
1057 * for — it is not a literal. The runtime accepts this length as well as the
1058 * current `sizeof`, which is what makes the tail additive rather than a
1059 * layout break. */
1060#define PF_NATIVE_REQUEST_V1_BASE_SIZE \
1061 ((uint32_t)offsetof(pf_native_request_v1, anchor_rounding))
1062
1063/** Byte length of #pf_native_request_v1 with L7b's anchored-leg tail but
1064 * without L3b's sizing-detail tail — the second of its three published
1065 * layouts. Defined as the offset of the first field appended after it, for
1066 * the same reason #PF_NATIVE_REQUEST_V1_BASE_SIZE is. */
1067#define PF_NATIVE_REQUEST_V1_ANCHOR_SIZE \
1068 ((uint32_t)offsetof(pf_native_request_v1, size_price))
1069
1070/** One declared higher-timeframe series of #pf_native_run_spec_ext_v1.
1071 *
1072 * A row is a series INSTANCE, not a period: several rows may carry the same
1073 * `tf`, each delivered under its own index (the `subscription` argument of
1074 * #pf_native_callbacks_v1::on_timeframe_bar). Same-period rows may not carry
1075 * DIFFERENT `authoritative_bars`.
1076 *
1077 * `gaps` occupies the word this struct published as `reserved0`, which every
1078 * layout required to be zero — so a caller that zero-fills the struct keeps
1079 * barmerge.gaps_off, and the struct's size and field offsets are unchanged.
1080 * Any value but 0 or 1 is PF_NATIVE_E_TAG. */
1082 uint32_t struct_size; /**< sizeof(pf_native_subscription_v1). */
1083 uint32_t lookahead; /**< 0 = barmerge.lookahead_off, 1 = lookahead_on. */
1084 const char* tf; /**< Non-NULL timeframe literal. */
1085 const pf_bar_t* authoritative_bars; /**< Optional exchange bars; copied. */
1086 int32_t authoritative_n; /**< Length of `authoritative_bars`. */
1087 uint32_t gaps; /**< 0 = barmerge.gaps_off, 1 = gaps_on. */
1089
1090/** The run-specification fields #pf_native_run_spec_v1 predates.
1091 *
1092 * It is a companion to #pf_native_run_spec_v1, not a second configure step:
1093 * the kernel configures a host exactly once, so both halves are handed to
1094 * #strategy_configure_native_ext_v1 together and that call replaces
1095 * #strategy_configure_native_v1 for a host that needs these fields.
1096 * `present_mask` selects the blocks that are meaningful; an absent block
1097 * keeps the kernel's own default, so an all-zero mask configures exactly
1098 * what #strategy_configure_native_v1 would have.
1099 *
1100 * Every field of NativeRunSpec that is not fixed by
1101 * #pf_native_run_spec_v1 now travels here. The one deliberate omission is
1102 * `identity`, which the base spec owns.
1103 *
1104 * This struct has FOUR published layouts and the runtime accepts any of
1105 * them: the base layout the L13 lane first shipped
1106 * (#PF_NATIVE_RUN_SPEC_EXT_V1_BASE_SIZE); that layout plus L9's `risk_*`
1107 * tail (#PF_NATIVE_RUN_SPEC_EXT_V1_RISK_SIZE); that one plus N8's intrabar
1108 * path, the four feed-shape and presentation policies, and the margin
1109 * model's equity basis, level base and liquidation strings
1110 * (#PF_NATIVE_RUN_SPEC_EXT_V1_POLICY_SIZE); and the current one, which
1111 * appends the `auxiliary_*` tail after them. A caller compiled against an
1112 * earlier layout keeps working unchanged and simply cannot set the mask
1113 * bits its struct has no fields for (#PF_NATIVE_SPEC_EXT_RISK,
1114 * #PF_NATIVE_SPEC_EXT_INTRABAR, #PF_NATIVE_SPEC_EXT_FEED_POLICY,
1115 * #PF_NATIVE_SPEC_EXT_AUXILIARY_FEED): doing so is PF_NATIVE_E_STRUCT. Any
1116 * other `struct_size` is PF_NATIVE_E_STRUCT too. Every tail is append-only:
1117 * nothing above them moved. */
1119 uint32_t struct_size; /**< sizeof(pf_native_run_spec_ext_v1). */
1120 uint32_t version; /**< PF_NATIVE_API_VERSION. */
1121 uint32_t present_mask; /**< #pf_native_spec_ext_mask_t bits. */
1122
1123 uint32_t report_policy; /**< NativeReportPolicy. */
1124 uint32_t report_open_position_at_end; /**< 0/1; KernelRecorded only. */
1125
1126 uint32_t price_grid; /**< NativePriceGrid. */
1127 uint32_t grid_rounding; /**< NativeGridRounding. */
1128
1129 uint32_t calculation; /**< NativeCalculationTrigger. */
1130 uint32_t max_recalculations_per_point; /**< Fill-cascade bound; 0 is legal. */
1131
1132 uint32_t open_bar_view; /**< NativeOpenBarView. */
1133
1134 uint32_t margin_sizing; /**< NativeLiquidationSizing. */
1135 uint32_t margin_check; /**< #pf_native_liquidation_check_t. */
1139 double margin_initial_long; /**< 0 = maintenance-only side: no kernel
1140 opening requirement, host owns
1141 admission; legal only with that
1142 side's maintenance set. */
1143 double margin_initial_short; /**< 0 = maintenance-only; see above. */
1146 double margin_shortfall_multiple; /**< The C++ default is 1.0, not 0: a
1147 * PRESENT block has every field read,
1148 * so a zero-filled struct must still
1149 * write it — including under a sizing
1150 * policy that never scales. */
1152
1153 const pf_native_subscription_v1* subscriptions; /**< Borrowed for the call. */
1155 uint32_t reserved0;
1156
1157 /* ── The additive risk tail (L9). Read only when `present_mask` carries
1158 * PF_NATIVE_SPEC_EXT_RISK; a caller sending the base layout stops at
1159 * `reserved0` above. Each limit is opt-in through its own `has_` flag,
1160 * and a block whose four flags are all 0 is a declared-but-empty block —
1161 * which is exactly what the C++ `NativeRiskLimits{}` is. ── */
1162 uint32_t risk_has_max_drawdown; /**< 0/1. */
1163 uint32_t risk_max_drawdown_percent; /**< 0/1: the value is a percent of the
1164 * running equity peak, out of 100. */
1165 double risk_max_drawdown; /**< Threshold; account currency unless percent. */
1166 uint32_t risk_has_max_intraday_loss; /**< 0/1. */
1167 uint32_t risk_max_intraday_loss_percent; /**< 0/1: percent of the day's opening equity. */
1168 double risk_max_intraday_loss; /**< Threshold; account currency unless percent. */
1170 uint32_t risk_max_consecutive_loss_days; /**< Days, when the flag is 1. */
1171 uint32_t risk_has_max_fills_per_day; /**< 0/1. */
1172 uint32_t risk_max_fills_per_day; /**< Applied fills, when the flag is 1. */
1173 uint32_t risk_day_basis; /**< #pf_native_risk_day_t. */
1174 uint32_t risk_action; /**< #pf_native_risk_action_t. */
1175
1176 /* ── The additive intrabar / policy tail (N8). Read only when
1177 * `struct_size` is the current sizeof; a caller sending either earlier
1178 * layout stops at `risk_action` above and keeps every kernel default.
1179 * The two blocks below have mask bits of their own; the four margin
1180 * fields at the end extend the EXISTING PF_NATIVE_SPEC_EXT_MARGIN block
1181 * and are read only when that bit is set AND this tail is present. ── */
1182 uint32_t intrabar_kind; /**< #pf_native_intrabar_kind_t. */
1183 int32_t intrabar_samples; /**< Samples per script bar; LOWER_TF and SYNTHESIZED. */
1184 uint32_t intrabar_distribution; /**< #pf_magnifier_distribution_t. */
1185 uint32_t intrabar_volume_weighted; /**< 0/1. */
1188 uint32_t intrabar_sample_eligibility; /**< #pf_native_sample_eligibility_t, LOWER_TF only. */
1189 int32_t intrabar_n; /**< Length of `intrabar_bars`; LOWER_TF only. */
1190 const char* intrabar_tf; /**< The finer timeframe; LOWER_TF only, non-NULL. */
1191 const pf_bar_t* intrabar_bars; /**< The finer feed; borrowed for the call, copied. */
1192
1193 uint32_t slot_label_policy; /**< #pf_native_slot_label_t. FEED_TOLERANT keeps
1194 * the caller's own labels, and a
1195 * #PF_NATIVE_INTRABAR_LOWER_TF path then
1196 * delivers no sub-bar: its bars are not
1197 * keyed to canonical input slots. */
1198 uint32_t feed_tolerance; /**< #pf_native_feed_tolerance_t bits. */
1199 uint32_t path_order; /**< #pf_native_path_order_t. */
1200 uint32_t abort_reporting; /**< #pf_native_abort_reporting_t. */
1201
1202 uint32_t margin_equity_basis; /**< #pf_native_margin_equity_basis_t. */
1203 uint32_t margin_level_base; /**< #pf_native_margin_level_base_t. */
1204 const char* margin_liquidation_label; /**< Ticket of a kernel liquidation; NULL is "". */
1205 const char* margin_liquidation_comment; /**< Comment of the same; NULL is "". */
1206
1207 /* ── The additive auxiliary-feed tail. Read only when `present_mask`
1208 * carries PF_NATIVE_SPEC_EXT_AUXILIARY_FEED; a caller sending an earlier
1209 * layout stops at `margin_liquidation_comment`, `risk_action` or
1210 * `reserved0` above. The feed is the
1211 * run's own symbol at a timeframe strictly finer than the input, routed
1212 * by time into the series that name it (`NativeAuxiliaryFeed`). ── */
1213 const char* auxiliary_tf; /**< Non-NULL feed timeframe literal. */
1214 const pf_bar_t* auxiliary_bars; /**< Strictly increasing bars; copied. May be
1215 * NULL when `auxiliary_n` is 0. */
1216 int32_t auxiliary_n; /**< Length of `auxiliary_bars`. */
1217 uint32_t reserved1; /**< Must be 0. */
1218 /** Optional, borrowed for the call: `subscriptions_n` entries of
1219 * #pf_native_series_source_t, one per row of `subscriptions`. NULL means
1220 * every series is built from the input. Meaningful only together with
1221 * PF_NATIVE_SPEC_EXT_SUBSCRIPTIONS. */
1222 const uint32_t* subscription_sources;
1224
1225/** Byte length of #pf_native_run_spec_ext_v1 as the L13 lane first published
1226 * it, before the `risk_*` tail was appended. It is the offset of the first
1227 * appended field, so it stays correct on every target this header builds for
1228 * — it is not a literal. The runtime accepts this length as well as the
1229 * current `sizeof`, which is what makes the tail additive rather than a
1230 * layout break. */
1231#define PF_NATIVE_RUN_SPEC_EXT_V1_BASE_SIZE \
1232 ((uint32_t)offsetof(pf_native_run_spec_ext_v1, risk_has_max_drawdown))
1233
1234/** Byte length of #pf_native_run_spec_ext_v1 with L9's risk tail but without
1235 * N8's intrabar / policy tail — the second of its four published layouts. */
1236#define PF_NATIVE_RUN_SPEC_EXT_V1_RISK_SIZE \
1237 ((uint32_t)offsetof(pf_native_run_spec_ext_v1, intrabar_kind))
1238
1239/** Byte length of #pf_native_run_spec_ext_v1 with N8's intrabar / policy tail
1240 * but before the `auxiliary_*` tail was appended — the third of its four
1241 * published layouts. It is the offset of the first auxiliary field, for the
1242 * same reason #PF_NATIVE_RUN_SPEC_EXT_V1_BASE_SIZE is an offset. */
1243#define PF_NATIVE_RUN_SPEC_EXT_V1_POLICY_SIZE \
1244 ((uint32_t)offsetof(pf_native_run_spec_ext_v1, auxiliary_tf))
1245
1246/** The C host's strategy logic.
1247 *
1248 * Every entry may be NULL, which is exactly the C++ default: the kernel does
1249 * nothing for that hook. `user` is handed back unchanged to every callback.
1250 * A callback must never let an exception, a longjmp or any other non-local
1251 * exit escape.
1252 *
1253 * There are two classes of entry, and they read their return value
1254 * differently. An OBSERVATION callback — everything down to and including
1255 * `on_sub_bar` — returns 0 to continue; any other value ends the run Failed
1256 * with PF_NATIVE_FAILURE_CALLBACK. An ANSWERING callback — the four margin
1257 * and excursion hooks at the end — returns a #pf_native_answer_t selecting
1258 * WHOSE answer the kernel uses; every value is in contract, so an answering
1259 * hook can never fail the run. That split is deliberate: the answering hooks
1260 * are consulted from kernel paths that are not inside the callback guard, so
1261 * a failure raised there could not be latched without unwinding through
1262 * them. A host that must abort does it from an observation callback.
1263 *
1264 * Commands are legal inside `on_bar_open`, `on_bar`, `on_tick` and
1265 * `on_applied`. `on_run_begin`, `on_input`, `on_timeframe_bar` and
1266 * `on_margin_call` are observation-only: a command there answers
1267 * PF_NATIVE_E_STATE and changes nothing.
1268 *
1269 * `on_bar` is also the recalculation hook: with a calculation trigger above
1270 * BarClose the kernel calls it again at each fill cursor or modeled point,
1271 * which is exactly what the C++ `on_native_recalculate` default does. */
1273 uint32_t struct_size; /**< sizeof(pf_native_callbacks_v1). */
1274 uint32_t version; /**< PF_NATIVE_API_VERSION. */
1275 void* user; /**< Opaque; handed back unchanged. */
1276 int (*on_run_begin)(void* user);
1277 int (*on_input)(void* user, const pf_bar_t* bar, int32_t input_index,
1278 int32_t completes_script_interval);
1279 int (*on_bar_open)(void* user, const pf_bar_t* bar, const pf_native_decision_v1* at);
1280 int (*on_bar)(void* user, const pf_bar_t* bar, const pf_native_decision_v1* at);
1281 int (*on_tick)(void* user, const pf_bar_t* bar, const pf_native_decision_v1* at);
1282 int (*on_applied)(void* user, const pf_native_applied_v1* applied,
1283 const pf_native_decision_v1* at);
1284 int (*on_timeframe_bar)(void* user, const pf_bar_t* bar, uint32_t subscription,
1285 uint32_t completion, int64_t delivered_at_ms);
1286 int (*on_margin_call)(void* user, const pf_native_event_v1* margin_call);
1287
1288 /* ── The additive hook tail. Read only when `struct_size` is the current
1289 * sizeof; a caller sending the base layout stops at `on_margin_call`
1290 * above and gets exactly the kernel's own defaults for all six, which is
1291 * what every host compiled before this tail already had. ── */
1292
1293 /** EVERY calculation of the run, including the script bar's own close —
1294 * `on_native_recalculate`. `reason` is a #pf_native_calc_reason_t and
1295 * `cause` is the applied execution of an ORDER_FILL recalculation, valid
1296 * only for that call and NULL otherwise. `bar` is the COMPLETE script
1297 * bar even mid-path; #strategy_native_partial_bar_v1 is the
1298 * lookahead-free bar so far. Commands are legal here.
1299 *
1300 * Installing it REPLACES `on_bar` for every calculation, exactly as
1301 * overriding `on_native_recalculate` replaces the C++ default forwarding:
1302 * a host that wants both calls `on_bar` itself from here. Leaving it
1303 * NULL keeps the established contract, where the kernel forwards every
1304 * calculation to `on_bar`. Observation callback: non-zero ends the run. */
1305 int (*on_recalculate)(void* user, const pf_bar_t* bar, const pf_native_decision_v1* at,
1306 uint32_t reason, const pf_native_applied_v1* cause);
1307
1308 /** One completed lower-timeframe sub-bar of a run that retains a lower
1309 * feed — `on_native_sub_bar`. Delivered
1310 * after that sub-bar's whole matching path and before the next one's;
1311 * never called for a run with no retained lower feed. The decision point
1312 * is the sub-bar's last modeled point, so commands and
1313 * #strategy_native_execute_current_v1 are legal.
1314 * Observation callback: non-zero ends the run. */
1315 int (*on_sub_bar)(void* user, const pf_bar_t* sub, const pf_native_decision_v1* at);
1316
1317 /** The two numbers one check point is about to compare —
1318 * `resolve_margin_requirement`. ANSWERING callback: return
1319 * #PF_NATIVE_ANSWER_DEFAULT to keep the kernel's own, any other value to
1320 * use @p out. The kernel keeps the whole mechanism — the level solve,
1321 * the check points, its own request, the receipt, `on_margin_call`; this
1322 * supplies only the money rule brokers legitimately differ on. */
1325
1326 /** Whether this kernel check point is one the host's broker model shares
1327 * — `margin_check_allowed`. ANSWERING callback: return
1328 * #PF_NATIVE_ANSWER_DEFAULT to admit the point (the kernel's own
1329 * answer), any other value to use @p allowed (0 suppresses it). A
1330 * suppressed point is not evaluated, re-armed or withdrawn: the margin
1331 * state is left exactly as the last admitted point left it. */
1332 int (*on_margin_check)(void* user, const pf_native_margin_view_v1* at, int32_t* allowed);
1333
1334 /** The size of a kernel-issued liquidation, before it rests —
1335 * `resolve_margin_call_units`. ANSWERING callback: return
1336 * #PF_NATIVE_ANSWER_DEFAULT to keep the run spec's sizing policy, any
1337 * other value to use @p units, which the kernel clamps into (0, held].
1338 * It has the last word on units, including over a forced breach. */
1340 double* units);
1341
1342 /** The favorable and adverse magnitudes of one closing lot —
1343 * `closed_lot_excursion`. Installing it at all is
1344 * `owns_lot_excursions() == true`: the consumer then stops sampling
1345 * excursion at matched trigger prices for the WHOLE run and every
1346 * closing row takes both magnitudes from here. ANSWERING callback:
1347 * return #PF_NATIVE_ANSWER_DEFAULT to answer the kernel's own zero
1348 * magnitudes — which, ownership having been declared, is what a declined
1349 * lot gets — or any other value to use @p favorable and @p adverse. */
1351 double* favorable, double* adverse);
1352
1353 /** How many units a host-sized CLOSE takes — the units half of
1354 * `resolve_execution_terms`, and the only half this header exposes.
1355 * Consulted for #PF_NATIVE_INTENT_HOST_SIZED candidates and nothing
1356 * else; without it a cohort close resolves no quantity and stands
1357 * deferred, which is exactly what the C++ default does. ANSWERING
1358 * callback: return #PF_NATIVE_ANSWER_DEFAULT to keep that default, any
1359 * other value to close @p units of
1360 * #pf_native_close_view_v1::scope_exposure_units. */
1361 int (*on_close_units)(void* user, const pf_native_close_view_v1* view, double* units);
1363
1364/** Byte length of #pf_native_callbacks_v1 as the L13 lane first published it,
1365 * before the six-hook tail was appended. It is the offset of the first
1366 * appended field, so it stays correct on every target this header builds for
1367 * — it is not a literal. #strategy_native_host_create_v1 accepts this length
1368 * as well as the current `sizeof`, which is what makes the tail additive
1369 * rather than a layout break. */
1370#define PF_NATIVE_CALLBACKS_V1_BASE_SIZE \
1371 ((uint32_t)offsetof(pf_native_callbacks_v1, on_recalculate))
1372
1373/** @} */ /* end of pf_native_c_types */
1374
1375/** @defgroup pf_native_c_api Entry points
1376 * @{ */
1377
1378/** This header's layout version. Mirrors #strategy_stream_api_version. */
1380
1381/** Allocate a native host that forwards every kernel callback to @p callbacks.
1382 *
1383 * The table is copied; the caller's struct need not outlive the call. The
1384 * returned handle is a `pf_strategy_t` the existing runtime symbols accept:
1385 * #strategy_configure_native_v1, the whole `strategy_stream_*` family, the
1386 * read-only accessors and #report_free all take it unchanged.
1387 *
1388 * @return The handle, or NULL for a NULL/mis-sized table or on allocation
1389 * failure. Release it with #strategy_native_host_free — never
1390 * #strategy_free, which does not own this allocation. */
1392
1393/** Release a handle from #strategy_native_host_create_v1. NULL is a no-op;
1394 * a handle this API did not create is refused without freeing anything. */
1396
1397/** Run @p n bars as one batch and fill @p out.
1398 *
1399 * The specification must already be Ready (#strategy_configure_native_v1).
1400 * @p out may be NULL to skip reporting; otherwise its arrays are
1401 * heap-allocated and released by #report_free.
1402 * @return PF_NATIVE_OK when the run reached Completed, PF_NATIVE_E_RUN_FAILED
1403 * when it did not (read #strategy_native_state_v1 for the code). */
1405 pf_report_t* out);
1406
1407/** Free the heap arrays inside a report filled by #strategy_native_run_v1.
1408 *
1409 * The unprefixed #report_free is a per-strategy export the transpiler emits,
1410 * so it is absent from a runtime a C host links on its own: this is that
1411 * host's release path. Idempotent; NULL is a no-op. The `pf_report_t` struct
1412 * itself stays caller-owned. */
1414
1415/** Submit @p request.
1416 *
1417 * Legal from inside a native callback; the request joins the working book
1418 * and is matched by the consumer from the next execution point on. The
1419 * handle it answers with is the request's identity for the rest of the run:
1420 * replace, cancel and every event carry it.
1421 *
1422 * @param s The host this run is driving, from #strategy_create.
1423 * @param request Borrowed for the call only; the kernel copies what it
1424 * keeps.
1425 * @param incarnation Optional; receives the accepted request's handle.
1426 * @param reject Optional; receives a RequestRejectReason on rejection.
1427 * @return PF_NATIVE_OK when accepted, PF_NATIVE_E_REJECTED when the kernel
1428 * rejected it, PF_NATIVE_E_STATE when commands are not legal here.
1429 *
1430 * Exercised by `tests/test_native_c_api.c`. */
1432 uint64_t* incarnation, uint32_t* reject);
1433
1434/** Replace the live request @p incarnation with @p request.
1435 *
1436 * Amendment, not cancel-and-resubmit: the predecessor leaves the book and
1437 * the successor takes its place in one step, and the REPLACED event names
1438 * both. A target that is no longer working is PF_NATIVE_E_NOT_WORKING.
1439 *
1440 * @param s The host this run is driving, from #strategy_create.
1441 * @param incarnation The live request to amend, as #strategy_native_submit_v1
1442 * handed it back.
1443 * @param request Borrowed for the call only.
1444 * @param successor Optional; receives the successor's handle.
1445 * @return PF_NATIVE_OK, PF_NATIVE_E_REJECTED, PF_NATIVE_E_NOT_WORKING,
1446 * PF_NATIVE_E_INVALID_TARGET, or PF_NATIVE_E_STATE.
1447 *
1448 * Exercised by `tests/test_native_c_api.c`. */
1450 const pf_native_request_v1* request,
1451 uint64_t* successor);
1452
1453/** Cancel one live request.
1454 * @return PF_NATIVE_OK, PF_NATIVE_E_NOT_WORKING, PF_NATIVE_E_INVALID_TARGET
1455 * or PF_NATIVE_E_STATE. */
1457
1458/** Cancel every live request, dependants included.
1459 * @return The number cancelled (>= 0), or PF_NATIVE_E_STATE. */
1461
1462/** Cancel exactly the live requests whose @p field equals @p text.
1463 *
1464 * The C spelling of `NativeStrategyHost::cancel_where`. With
1465 * #PF_NATIVE_FIELD_LABEL it is the one call that withdraws every live
1466 * request a host issued under one of its own order ids; with
1467 * #PF_NATIVE_FIELD_COMMENT it is the established comment predicate. A
1468 * dependant of a cancelled owner still leaves the book, but it is counted
1469 * only when its own field matched. Text that matches nothing is not a
1470 * command.
1471 *
1472 * @param s The host this run is driving, from #strategy_create.
1473 * @param text Borrowed for the call only; "" matches the requests that
1474 * carry no such text. NULL is PF_NATIVE_E_ARGUMENT, not "".
1475 * @param field #pf_native_request_field_t.
1476 * @return The number cancelled (>= 0), PF_NATIVE_E_TAG for a field outside
1477 * the enumeration, PF_NATIVE_E_ARGUMENT for a NULL @p text, or another
1478 * negative status.
1479 *
1480 * Exercised by `tests/test_native_c_api.c`. */
1482 uint32_t field);
1483
1484/** Execute one live request at the current execution point.
1485 *
1486 * Legal only inside a callback the kernel has opened an execution point for
1487 * (`on_bar`, `on_bar_open`, `on_tick`, `on_applied`, `on_recalculate`);
1488 * anywhere else the answer is PF_NATIVE_E_STATE. The request is filled at
1489 * this cursor rather than waiting for the consumer's own matching pass.
1490 *
1491 * @param s The host this run is driving, from #strategy_create.
1492 * @param incarnation The live request to execute, as
1493 * #strategy_native_submit_v1 handed it back. A handle
1494 * that is not in the working book is
1495 * PF_NATIVE_E_INVALID_TARGET.
1496 * @param price_rule #pf_native_price_rule_t.
1497 * @param refusal Optional; receives a #pf_native_refusal_t when the
1498 * return is PF_NATIVE_E_REFUSED.
1499 * @return A non-negative #pf_native_execute_outcome_t, or a negative status.
1500 *
1501 * Exercised by `tests/test_native_c_api.c`. */
1503 uint32_t price_rule, uint32_t* refusal);
1504
1505/** Read the physical position. Every output is optional.
1506 * @return PF_NATIVE_OK, or a negative status. */
1508 double* average_price, uint64_t* lots);
1509
1510/** Snapshot the live working book and return its length.
1511 *
1512 * The snapshot is retained on the handle: #strategy_native_working_get_v1
1513 * reads from it, so a row already copied out is not invalidated by a later
1514 * command. The next call to this function replaces the snapshot.
1515 * @return The row count (>= 0), or a negative status. */
1517
1518/** Copy row @p index of the most recent working snapshot into @p out.
1519 *
1520 * @p out is an in/out size prefix: set `out->struct_size` to
1521 * `sizeof(pf_native_working_v1)` before the call. Everything else is filled.
1522 * @return PF_NATIVE_OK, PF_NATIVE_E_ARGUMENT for an out-of-range index,
1523 * PF_NATIVE_E_STRUCT for a mis-sized row, or another negative status. */
1526
1527/** Snapshot the open lots marked at @p mark and return their count.
1528 *
1529 * The C spelling of `NativeStrategyHost::native_open_lots(mark)` (R5 gap
1530 * lane N18). The snapshot is retained on the handle:
1531 * #strategy_native_open_lot_get_v1 reads from it, so a row already copied
1532 * out is not invalidated by a later command; the next call to this function
1533 * replaces it. Observation only — it moves no fill, no hash and no row — and
1534 * legal wherever #strategy_native_position_v1 is. A NaN @p mark keeps every
1535 * booking fact and leaves `unrealized_pnl` NaN.
1536 * @return The row count (>= 0), or a negative status. */
1538
1539/** Copy row @p index of the most recent open-lot snapshot into @p out.
1540 *
1541 * @p out is an in/out size prefix: set `out->struct_size` to
1542 * `sizeof(pf_native_open_lot_v1)` before the call. Everything else is filled.
1543 * @return PF_NATIVE_OK, PF_NATIVE_E_ARGUMENT for an out-of-range index,
1544 * PF_NATIVE_E_STRUCT for a mis-sized row, or another negative status. */
1547
1548/** Copy up to @p cap events with an ordinal strictly greater than
1549 * @p after_ordinal into @p out, in the kernel's own recording order.
1550 *
1551 * Ordinals are non-decreasing rather than strictly increasing: an applied
1552 * execution and the account observation it produced carry the same one. A
1553 * page therefore never ends in the middle of such a group (for @p cap >= 2),
1554 * so a poller advances by the last returned `ordinal` without losing or
1555 * repeating a row. The history is append-only, so the same @p after_ordinal
1556 * always yields the same rows.
1557 * @return The number written (>= 0), or a negative status. */
1558PF_API int strategy_native_events_v1(pf_strategy_t s, uint64_t after_ordinal,
1559 pf_native_event_v1* out, int cap);
1560
1561/** Read the run's lifecycle and typed failure into @p out.
1562 *
1563 * @p out is an in/out size prefix: set `out->struct_size` to
1564 * `sizeof(pf_native_state_v1)` before the call. */
1566
1567/** Declare this run's higher-timeframe series from inside `on_run_begin` —
1568 * `declare_timeframe_subscriptions()`.
1569 *
1570 * The list REPLACES the `subscriptions` staged by
1571 * #strategy_configure_native_ext_v1; the kernel registers from the staged
1572 * spec after the callback returns, so the run's continuation identity folds
1573 * what actually ran. @p n may be 0 (with @p rows NULL), which declares no
1574 * series at all.
1575 * @return PF_NATIVE_OK when the list was staged; PF_NATIVE_E_STATE anywhere
1576 * but inside `on_run_begin` and for a list this run's input timeframe would
1577 * refuse — the same validation #strategy_configure_native_ext_v1 applies —
1578 * in which case nothing is staged and nothing changes. */
1580 const pf_native_subscription_v1* rows,
1581 int n);
1582
1583/** The bar so far at the current cursor — `current_partial_bar()`.
1584 *
1585 * Open of the script bar's first modeled point, running high/low, close at
1586 * the cursor; volume is the activity actually consumed so far. Valid in the
1587 * bar-open, applied, tick, sub-bar and recalculation callbacks.
1588 * @return PF_NATIVE_OK when @p out was written, #PF_NATIVE_ABSENT outside a
1589 * path walk — including in the bar's own close calculation, where the
1590 * callback already holds the complete bar — leaving @p out untouched. */
1592
1593/** How many recalculations the kernel drove, and how many it suppressed
1594 * because a point had spent its `max_recalculations_per_point` budget —
1595 * `native_recalculation_count()` / `native_recalculations_skipped()`.
1596 * Either pointer may be NULL. Observation only. */
1598 uint64_t* skipped);
1599
1600/** The trail projection of one live request — `trail_state()`.
1601 *
1602 * @p incarnation names a request this run issued.
1603 * @return PF_NATIVE_OK when @p out was written, #PF_NATIVE_ABSENT when the
1604 * handle is not a live Trail request (unknown, finished, or another
1605 * trigger), leaving @p out untouched. */
1608
1609/** The latest completed bucket of a declared subscription —
1610 * `native_series_bar()`. @p subscription is the row's index in the
1611 * `subscriptions` array #strategy_configure_native_ext_v1 was given (or the
1612 * list #strategy_native_declare_subscriptions_v1 installed). Legal inside
1613 * every callback, `on_timeframe_bar` included.
1614 * @return PF_NATIVE_OK when @p out was written, #PF_NATIVE_ABSENT before the
1615 * series' first delivery, for an unknown index, and on every input bar a
1616 * `gaps = 1` series publishes nothing on — the empty that stands for na. */
1618 pf_bar_t* out);
1619
1620/** The account's marked equity at @p mark — `native_marked_equity()`. */
1622
1623/** The price at which the marked equity falls below the run's maintenance
1624 * requirement for the live position's side — `native_liquidation_price()`.
1625 * @return PF_NATIVE_OK when @p out was written, #PF_NATIVE_ABSENT when the
1626 * run declares no margin model, the side has no maintenance fraction, the
1627 * book is flat, or no finite price solves the breach (a long at full
1628 * maintenance); @p out is then written NaN. */
1630
1631/** The run's generic risk ledger — `native_risk_state()`. Every field is its
1632 * zero for a run that declares no risk block. */
1634
1635/** The run's continuation identity — `native_continuation_hash()`. Two runs
1636 * driven the same way that folded the same declarations and the same inputs
1637 * answer the same value; a batch and a stream over identical bars booking
1638 * identical trades do NOT, because the driving mode is part of a
1639 * continuation. It is the C spelling of the hash a stream resumes against,
1640 * and the same reason the per-bar broker-state hash is per driving mode
1641 * (`pineforge.h`, `strategy_set_broker_state_hash_recording`). */
1643
1644/** Open a cohort roster for PF_NATIVE_OWNER_BIND_COHORT. */
1646
1647/** Enrol a live request into a cohort roster. */
1649 uint64_t incarnation);
1650
1651/** Remove a request from a cohort roster. */
1653 uint64_t incarnation);
1654
1655/** Configure a native run from the v1 specification plus the extension.
1656 *
1657 * Use this INSTEAD of #strategy_configure_native_v1, not after it: the
1658 * kernel configures a host exactly once and refuses (and fails) a second
1659 * attempt, so this call takes both halves and applies them together.
1660 * @p base is the same #pf_native_run_spec_v1 the other entry point takes.
1661 *
1662 * Refuses without mutation — the handle stays usable — for an
1663 * already-configured handle, a mis-sized struct, an unknown enumerator, or a
1664 * specification the kernel's own validation rejects.
1665 * @return PF_NATIVE_OK, or a negative status. */
1667 const pf_native_run_spec_v1* base,
1668 const pf_native_run_spec_ext_v1* ext);
1669
1670/** Append later bars to the run's declared auxiliary feed on a realtime
1671 * stream (`NativeStrategyHost::append_auxiliary_bars`).
1672 *
1673 * Legal between stream inputs, after #strategy_stream_begin, on a host whose
1674 * specification declared PF_NATIVE_SPEC_EXT_AUXILIARY_FEED. The bars are
1675 * copied, join the feed behind every bar it holds, and ride on the next
1676 * pushed bar whose period they opened before — the routing a batch of the
1677 * same bars applies. @p n of 0 is accepted and appends nothing.
1678 *
1679 * Refused without mutation, the handle staying usable, for bars that are out
1680 * of order or not after the feed's last bar, a bar with invalid OHLCV, a bar
1681 * that opened inside an input period already accepted, a host that declared
1682 * no feed, and a run that is not realtime: PF_NATIVE_E_STATE, the reason
1683 * readable with #strategy_get_last_error. A call from inside a callback fails the
1684 * run, as every reentrant stream input does.
1685 * @return PF_NATIVE_OK, or a negative status. */
1687 int32_t n);
1688
1689/** @} */ /* end of pf_native_c_api */
1690
1691#ifdef __cplusplus
1692} /* extern "C" */
1693#endif
1694
1695#endif /* PINEFORGE_NATIVE_C_API_H */
int strategy_native_run_v1(pf_strategy_t s, const pf_bar_t *bars, int n, pf_report_t *out)
Run n bars as one batch and fill out.
int strategy_native_cancel_where_v1(pf_strategy_t s, const char *text, uint32_t field)
Cancel exactly the live requests whose field equals text.
void strategy_native_host_free(pf_strategy_t s)
Release a handle from strategy_native_host_create_v1.
int strategy_native_position_v1(pf_strategy_t s, double *signed_units, double *average_price, uint64_t *lots)
Read the physical position.
int strategy_native_continuation_hash_v1(pf_strategy_t s, uint64_t *out)
The run's continuation identity — native_continuation_hash().
int strategy_native_recalculations_v1(pf_strategy_t s, uint64_t *driven, uint64_t *skipped)
How many recalculations the kernel drove, and how many it suppressed because a point had spent its ma...
int strategy_native_trail_state_v1(pf_strategy_t s, uint64_t incarnation, pf_native_trail_state_v1 *out)
The trail projection of one live request — trail_state().
int strategy_native_cohort_open_v1(pf_strategy_t s, uint64_t *cohort)
Open a cohort roster for PF_NATIVE_OWNER_BIND_COHORT.
int strategy_configure_native_ext_v1(pf_strategy_t s, const pf_native_run_spec_v1 *base, const pf_native_run_spec_ext_v1 *ext)
Configure a native run from the v1 specification plus the extension.
int strategy_native_marked_equity_v1(pf_strategy_t s, double mark, double *out)
The account's marked equity at mark — native_marked_equity().
int strategy_native_api_version(void)
This header's layout version.
int strategy_native_declare_subscriptions_v1(pf_strategy_t s, const pf_native_subscription_v1 *rows, int n)
Declare this run's higher-timeframe series from inside on_run_begin — declare_timeframe_subscriptions...
int strategy_native_partial_bar_v1(pf_strategy_t s, pf_bar_t *out)
The bar so far at the current cursor — current_partial_bar().
int strategy_native_append_auxiliary_bars_v1(pf_strategy_t s, const pf_bar_t *bars, int32_t n)
Append later bars to the run's declared auxiliary feed on a realtime stream (NativeStrategyHost::appe...
int strategy_native_open_lot_count_v1(pf_strategy_t s, double mark)
Snapshot the open lots marked at mark and return their count.
int strategy_native_execute_current_v1(pf_strategy_t s, uint64_t incarnation, uint32_t price_rule, uint32_t *refusal)
Execute one live request at the current execution point.
int strategy_native_cohort_add_v1(pf_strategy_t s, uint64_t cohort, uint64_t incarnation)
Enrol a live request into a cohort roster.
int strategy_native_risk_state_v1(pf_strategy_t s, pf_native_risk_state_v1 *out)
The run's generic risk ledger — native_risk_state().
int strategy_native_liquidation_price_v1(pf_strategy_t s, double *out)
The price at which the marked equity falls below the run's maintenance requirement for the live posit...
int strategy_native_events_v1(pf_strategy_t s, uint64_t after_ordinal, pf_native_event_v1 *out, int cap)
Copy up to cap events with an ordinal strictly greater than after_ordinal into out,...
pf_strategy_t strategy_native_host_create_v1(const pf_native_callbacks_v1 *callbacks)
Allocate a native host that forwards every kernel callback to callbacks.
int strategy_native_series_bar_v1(pf_strategy_t s, uint32_t subscription, pf_bar_t *out)
The latest completed bucket of a declared subscription — native_series_bar().
int strategy_native_working_len_v1(pf_strategy_t s)
Snapshot the live working book and return its length.
int strategy_native_cancel_v1(pf_strategy_t s, uint64_t incarnation)
Cancel one live request.
int strategy_native_working_get_v1(pf_strategy_t s, int index, pf_native_working_v1 *out)
Copy row index of the most recent working snapshot into out.
int strategy_native_state_v1(pf_strategy_t s, pf_native_state_v1 *out)
Read the run's lifecycle and typed failure into out.
int strategy_native_cohort_remove_v1(pf_strategy_t s, uint64_t cohort, uint64_t incarnation)
Remove a request from a cohort roster.
int strategy_native_open_lot_get_v1(pf_strategy_t s, int index, pf_native_open_lot_v1 *out)
Copy row index of the most recent open-lot snapshot into out.
int strategy_native_submit_v1(pf_strategy_t s, const pf_native_request_v1 *request, uint64_t *incarnation, uint32_t *reject)
Submit request.
void strategy_native_report_free_v1(pf_report_t *report)
Free the heap arrays inside a report filled by strategy_native_run_v1.
int strategy_native_replace_v1(pf_strategy_t s, uint64_t incarnation, const pf_native_request_v1 *request, uint64_t *successor)
Replace the live request incarnation with request.
int strategy_native_cancel_all_v1(pf_strategy_t s)
Cancel every live request, dependants included.
pf_native_intent_t
Order intent — the alternative index of native_order::OrderIntent.
pf_native_refusal_t
Why execute_current refused.
pf_native_grid_policy_t
Whether resolved sizing snaps onto the run's quantity grid.
pf_native_size_basis_t
Sizing basis — the alternative index of native_order::SizeBasis.
pf_native_liquidation_check_t
When the kernel tests the maintenance requirement — NativeLiquidationCheck, the margin_check field of...
pf_native_risk_day_t
Which day a risk limit's "day" is — NativeRiskDay.
pf_native_spec_ext_mask_t
Which extension blocks of pf_native_run_spec_ext_v1 are meaningful.
pf_native_execute_outcome_t
Outcome of strategy_native_execute_current_v1 (non-negative returns).
pf_native_scope_basis_t
WHICH measurement of the bound scope a fractional reduce takes its fraction of — native_order::ScopeB...
pf_native_abort_reporting_t
How a cooperative abort is presented — NativeAbortReporting.
pf_native_size_time_t
When a sizing basis resolves.
pf_native_arm_visibility_t
Whether a WAIT_FOR_APPLIED child is a working order before its arm — native_order::NativeArmVisibilit...
pf_native_intrabar_kind_t
Which intrabar execution path the run retains — the alternative of IntrabarPath.
pf_native_size_price_t
WHICH price a kernel-sized basis converts at — native_order::SizePrice (L3b).
pf_native_side_t
Side of a kernel-sized opening.
pf_native_sample_eligibility_t
Whether matching stays continuous between generated samples — IntrabarPath::SampleEligibility.
pf_native_series_source_t
The bars a declared series is built from — NativeSeriesSource.
pf_native_calc_reason_t
Why the kernel is asking the host to calculate — NativeCalculationReason (L5), the reason argument of...
pf_native_group_t
Group — the alternative index of native_order::Group.
pf_native_price_rule_t
Price rule of an immediate execution.
pf_native_margin_equity_basis_t
Which equity the maintenance requirement is tested against — NativeMarginEquityBasis.
pf_native_group_effect_t
What a filled group member does to its siblings.
pf_native_request_field_t
Which identity text strategy_native_cancel_where_v1 compares.
pf_native_slot_label_t
Whether a confirmed bar must name a canonical input slot — NativeSlotLabelPolicy.
pf_native_owner_t
Owner — the alternative index of native_order::Owner.
pf_native_capacity_t
Capacity — the alternative index of native_order::Capacity.
pf_native_feed_tolerance_t
Opt-in admission exceptions for a tolerated input-feed shape — NativeFeedTolerance.
pf_native_path_order_t
Generic ordering for a modeled OHLC path — NativePathOrder.
pf_native_anchor_rounding_t
How a materialized anchored level snaps onto the run's price tick ladder — native_order::NativeAnchor...
pf_native_margin_level_base_t
Which base the liquidation level is solved from — NativeLiquidationLevelBase.
pf_native_risk_limit_t
Which generic risk limit a PF_NATIVE_EVENT_RISK event reports — the reason field of pf_native_event_v...
pf_native_margin_check_kind_t
Which kernel check point is about to test the maintenance requirement — NativeMarginCheckKind (L4b).
pf_native_lifecycle_t
Lifecycle of the native run — mirrors NativeLifecycleKind.
pf_native_trigger_t
Trigger — the alternative index of native_order::Trigger.
pf_native_scope_claim_t
Scope claim of a fractional reduce.
pf_native_reduction_t
Reduction size — the alternative index of native_order::ReductionSize.
pf_native_answer_t
What an ANSWERING callback's return value means.
pf_native_anchor_t
Where a trigger level comes from — native_order::TriggerAnchor (L7).
pf_native_event_kind_t
Event tag of pf_native_event_v1.
pf_native_remaining_t
Remaining projection of a live request — native_order::RemainingProjection.
pf_native_risk_action_t
What a breach does — NativeRiskAction.
pf_native_trigger_state_t
Trigger state of a live request — native_order::TriggerState.
@ PF_NATIVE_INTENT_SIZED
Kernel-sized opening (L3).
@ PF_NATIVE_INTENT_REDUCE
Reduce; see pf_native_reduction_t.
@ PF_NATIVE_INTENT_TRANSACT
intent_value signed units.
@ PF_NATIVE_INTENT_HOST_SIZED
The cohort close, and nothing else; see PF_NATIVE_OWNER_BIND_COHORT.
@ PF_NATIVE_INTENT_FLATTEN
Close the whole book.
@ PF_NATIVE_INTENT_REVERSE_TO
intent_value target signed exposure.
@ PF_NATIVE_REFUSAL_NOT_ACCEPTED_IN_CALLBACK
@ PF_NATIVE_REFUSAL_NOT_WORKING
@ PF_NATIVE_REFUSAL_INVALID_HANDLE
@ PF_NATIVE_REFUSAL_INVALID_SELECTION
@ PF_NATIVE_REFUSAL_UNSUPPORTED_REQUEST
@ PF_NATIVE_REFUSAL_NO_EXECUTION_CONTEXT
@ PF_NATIVE_REFUSAL_UNREADY_OWNER
@ PF_NATIVE_REFUSAL_CONFIGURATION_MISMATCH
@ PF_NATIVE_REFUSAL_REENTRANT
@ PF_NATIVE_GRID_SNAP
@ PF_NATIVE_GRID_EXPLICIT_UNITS
@ PF_NATIVE_SIZE_BASIS_EQUITY_FRACTION
intent_value fraction of marked equity.
@ PF_NATIVE_SIZE_BASIS_CASH
intent_value account-currency cash.
@ PF_NATIVE_LIQUIDATION_PATH_ADVERSE_EXTREME
Solve and rest at the level.
@ PF_NATIVE_LIQUIDATION_CALCULATION_ONLY
Test the mark; rest nothing.
@ PF_NATIVE_LIQUIDATION_PATH_ADVERSE_EXTREME_MARK
Rest AT the adverse mark.
@ PF_NATIVE_RISK_DAY_SESSION
@ PF_NATIVE_RISK_DAY_CALENDAR_TIMEZONE
@ PF_NATIVE_SPEC_EXT_FEED_POLICY
The four feed-shape and presentation policies: slot labels, feed tolerance, the forced path order and...
@ PF_NATIVE_SPEC_EXT_MARGIN
@ PF_NATIVE_SPEC_EXT_OPEN_BAR_VIEW
@ PF_NATIVE_SPEC_EXT_SUBSCRIPTIONS
@ PF_NATIVE_SPEC_EXT_CALCULATION
@ PF_NATIVE_SPEC_EXT_AUXILIARY_FEED
The auxiliary finer feed.
@ PF_NATIVE_SPEC_EXT_PRICE_GRID
@ PF_NATIVE_SPEC_EXT_REPORT
@ PF_NATIVE_SPEC_EXT_RISK
L9's generic risk limits.
@ PF_NATIVE_SPEC_EXT_INTRABAR
The retained intrabar execution path.
@ PF_NATIVE_EXECUTED_CANCELLED
The request was cancelled instead.
@ PF_NATIVE_EXECUTED_MATCH_REJECTED
Terms/admission rejected it.
@ PF_NATIVE_EXECUTED_NO_EFFECT
Legal, nothing to execute.
@ PF_NATIVE_EXECUTED_APPLIED
An execution was applied.
@ PF_NATIVE_SCOPE_BASIS_AT_MATCH
@ PF_NATIVE_SCOPE_BASIS_AT_ACCEPTANCE
@ PF_NATIVE_ABORT_QUIET
@ PF_NATIVE_ABORT_ERROR
@ PF_NATIVE_SIZE_AT_ACCEPTANCE
@ PF_NATIVE_SIZE_AT_MATCH
@ PF_NATIVE_ARM_VISIBILITY_WORKING
@ PF_NATIVE_ARM_VISIBILITY_PENDING_UNTIL_ARMED
@ PF_NATIVE_INTRABAR_SYNTHESIZED
@ PF_NATIVE_INTRABAR_NONE
@ PF_NATIVE_INTRABAR_LOWER_TF
@ PF_NATIVE_SIZE_PRICE_RESOLVED
@ PF_NATIVE_SIZE_PRICE_SIGNAL
@ PF_NATIVE_SIZE_PRICE_SIGNAL_ON_TICK
@ PF_NATIVE_SIDE_LONG
@ PF_NATIVE_SIDE_SHORT
@ PF_NATIVE_SAMPLE_DISTRIBUTION_SAMPLES
@ PF_NATIVE_SAMPLE_CONTINUOUS_SEGMENTS
@ PF_NATIVE_SERIES_SOURCE_AUXILIARY_FEED
The run's auxiliary finer feed.
@ PF_NATIVE_SERIES_SOURCE_INPUT
The accepted input (the default).
@ PF_NATIVE_CALC_SUB_BAR
Reserved; see on_sub_bar.
@ PF_NATIVE_CALC_BAR_CLOSE
The script bar's own calculation; cause NULL.
@ PF_NATIVE_CALC_TICK
At a modeled point or print; cause NULL.
@ PF_NATIVE_CALC_ORDER_FILL
At an applied execution's cursor; cause is it.
@ PF_NATIVE_GROUP_MEMBER
group_id, group_cohort, group_effect.
@ PF_NATIVE_GROUP_NONE
@ PF_NATIVE_PRICE_AS_PRESENTED
@ PF_NATIVE_PRICE_NEAREST_TICK
@ PF_NATIVE_MARGIN_EQUITY_BEFORE_OPEN_COMMISSION
@ PF_NATIVE_MARGIN_EQUITY_MARKED
@ PF_NATIVE_GROUP_REDUCE
@ PF_NATIVE_GROUP_CANCEL
@ PF_NATIVE_FIELD_LABEL
@ PF_NATIVE_FIELD_COMMENT
@ PF_NATIVE_SLOT_LABEL_FEED_TOLERANT
@ PF_NATIVE_SLOT_LABEL_CANONICAL
@ PF_NATIVE_OWNER_WAIT_FOR_APPLIED
One parent in owner_incarnations.
@ PF_NATIVE_OWNER_BIND_COHORT
cohort from strategy_native_cohort_open_v1.
@ PF_NATIVE_OWNER_BIND_OPENINGS
owner_n openings + owner_cycle.
@ PF_NATIVE_OWNER_INDEPENDENT
No owner.
@ PF_NATIVE_OWNER_BIND_OPENING
One opening + owner_cycle.
@ PF_NATIVE_CAPACITY_IMMEDIATE
Whole remaining at one point.
@ PF_NATIVE_CAPACITY_POINT_BUDGET
capacity_units per matching point.
@ PF_NATIVE_FEED_TOLERANCE_WARMUP_NONNEGATIVE
Stream warmups admit finite, non-negative interim OHLC.
@ PF_NATIVE_FEED_TOLERANCE_BATCH_STRUCTURAL
Finite OHLC need not be positive; NaN volume means unavailable.
@ PF_NATIVE_FEED_TOLERANCE_NONE
@ PF_NATIVE_PATH_ORDER_HIGH_FIRST
@ PF_NATIVE_PATH_ORDER_LOW_FIRST
@ PF_NATIVE_PATH_ORDER_AUTO
@ PF_NATIVE_ANCHOR_ROUNDING_RAW
fill + offset exactly.
@ PF_NATIVE_ANCHOR_ROUNDING_DIRECTIONAL
Toward the region the leg needs.
@ PF_NATIVE_ANCHOR_ROUNDING_HALF_UP
Nearest tick, ties away from zero.
@ PF_NATIVE_MARGIN_LEVEL_MARKED_EQUITY
@ PF_NATIVE_MARGIN_LEVEL_REALIZED_ONLY
@ PF_NATIVE_RISK_MAX_INTRADAY_LOSS
@ PF_NATIVE_RISK_MAX_CONSECUTIVE_LOSS_DAYS
@ PF_NATIVE_RISK_MAX_FILLS_PER_DAY
@ PF_NATIVE_RISK_MAX_DRAWDOWN
@ PF_NATIVE_MARGIN_CHECK_AFTER_APPLIED
The re-arm after a point's fills.
@ PF_NATIVE_MARGIN_CHECK_FX_ROLL
A step of the run's declared pf_native_fx_curve_v1: the first point the account converts at a new rat...
@ PF_NATIVE_MARGIN_CHECK_CALCULATION
A CalculationOnly model's calculation.
@ PF_NATIVE_MARGIN_CHECK_BAR_OPEN
The script bar's open.
@ PF_NATIVE_LIFECYCLE_FAILED
@ PF_NATIVE_LIFECYCLE_RUNNING
@ PF_NATIVE_LIFECYCLE_READY
@ PF_NATIVE_LIFECYCLE_COMPLETED
@ PF_NATIVE_LIFECYCLE_UNCONFIGURED
@ PF_NATIVE_TRIGGER_LIMIT
p1 = price; fill_through makes it market-if-touched.
@ PF_NATIVE_TRIGGER_TRAIL
p1 = offset, p2 = arm price when trail_has_arm_price.
@ PF_NATIVE_TRIGGER_STOP
p1 = price.
@ PF_NATIVE_TRIGGER_STOP_LIMIT
p1 = stop, p2 = limit.
@ PF_NATIVE_TRIGGER_MARKET
p1, p2 ignored.
@ PF_NATIVE_SCOPE_NET_OF_SIBLINGS
@ PF_NATIVE_SCOPE_GROSS
@ PF_NATIVE_REDUCE_OWNER_OPENED
Exactly what the owner opened.
@ PF_NATIVE_REDUCE_SCOPE_FRACTION
intent_value fraction in (0, 1].
@ PF_NATIVE_REDUCE_EXPLICIT_UNITS
intent_value units.
@ PF_NATIVE_ANSWER_DEFAULT
Keep the kernel's own; the output is ignored.
@ PF_NATIVE_ANSWER_PROVIDED
Use the output.
@ PF_NATIVE_ANCHOR_FROM_OWNER_FILL
owner fill + anchor_offset (signed).
@ PF_NATIVE_ANCHOR_ABSOLUTE
The level written in the trigger.
@ PF_NATIVE_EVENT_INVALID_HANDLE
@ PF_NATIVE_EVENT_NO_EFFECT
@ PF_NATIVE_EVENT_RISK
@ PF_NATIVE_EVENT_MARGIN_CALL
@ PF_NATIVE_EVENT_ARMED
@ PF_NATIVE_EVENT_CANCELLED
@ PF_NATIVE_EVENT_RESERVATION_REDUCED
@ PF_NATIVE_EVENT_REPLACED
@ PF_NATIVE_EVENT_QUANTITY_BOUND
@ PF_NATIVE_EVENT_REJECTED
@ PF_NATIVE_EVENT_REPLACE_REJECTED
@ PF_NATIVE_EVENT_CLOSE_BOUND
@ PF_NATIVE_EVENT_ACTIVATED
@ PF_NATIVE_EVENT_DRIVER_POINT
@ PF_NATIVE_EVENT_ACCOUNT
@ PF_NATIVE_EVENT_DEFERRED_GROUP
@ PF_NATIVE_EVENT_NOT_WORKING
@ PF_NATIVE_EVENT_MATCH_REJECTED
@ PF_NATIVE_EVENT_TERMS_RESOLVED
@ PF_NATIVE_EVENT_ACCEPTED
@ PF_NATIVE_EVENT_APPLIED
@ PF_NATIVE_REMAINING_NO_TARGET
@ PF_NATIVE_REMAINING_UNITS
remaining_units is meaningful.
@ PF_NATIVE_REMAINING_FLATTEN_ALL
@ PF_NATIVE_REMAINING_UNBOUND
@ PF_NATIVE_REMAINING_DEFERRED
@ PF_NATIVE_RISK_FLATTEN_AND_BLOCK
@ PF_NATIVE_RISK_BLOCK_OPENINGS
@ PF_NATIVE_TRIGGER_STATE_LIMIT_READY
@ PF_NATIVE_TRIGGER_STATE_STOP_ACTIVE
@ PF_NATIVE_TRIGGER_STATE_STOP_LIMIT_PENDING
@ PF_NATIVE_TRIGGER_STATE_MARKET_READY
@ PF_NATIVE_TRIGGER_STATE_TRAIL_ACTIVE
@ PF_NATIVE_TRIGGER_STATE_TRAIL_WAIT_ARM
@ PF_NATIVE_TRIGGER_STATE_STOP_LIMIT_LIVE
@ PF_NATIVE_TRIGGER_STATE_STOP_IDLE
@ PF_NATIVE_TRIGGER_STATE_TRAIL_TRACK
void * pf_strategy_t
Opaque handle to a compiled strategy instance.
Definition pineforge.h:433
#define PF_API
Definition pineforge.h:70
Single OHLCV bar pushed into the engine.
Definition pineforge.h:127
One applied execution, presented to on_applied.
uint64_t incarnation
The request that executed.
int64_t cycle_after
Position cycle after the fill.
double ticket
current_ticket at the fill.
int64_t cycle_before
Position cycle before the fill.
double resolved_price
The booked price after terms and slippage.
uint8_t terminal
1 when the request is finished.
uint8_t has_terminal_reason
1 when terminal_reason is meaningful.
uint32_t version
PF_NATIVE_API_VERSION.
uint32_t struct_size
sizeof(pf_native_applied_v1).
double closed_units
Units closed by this fill.
uint8_t terminal_reason
AppliedTerminalReason, valid when has_terminal_reason.
uint64_t ordinal
Event ordinal.
double opened_units
Units opened by this fill.
uint64_t opened_lot_incarnation
The lot this fill opened, 0 when none.
double raw_price
The path price the match was found at.
double filled_working
Working units this fill consumed.
The C host's strategy logic.
int(* on_timeframe_bar)(void *user, const pf_bar_t *bar, uint32_t subscription, uint32_t completion, int64_t delivered_at_ms)
uint32_t version
PF_NATIVE_API_VERSION.
int(* on_bar_open)(void *user, const pf_bar_t *bar, const pf_native_decision_v1 *at)
int(* on_applied)(void *user, const pf_native_applied_v1 *applied, const pf_native_decision_v1 *at)
int(* on_sub_bar)(void *user, const pf_bar_t *sub, const pf_native_decision_v1 *at)
One completed lower-timeframe sub-bar of a run that retains a lower feed — on_native_sub_bar.
int(* on_margin_call)(void *user, const pf_native_event_v1 *margin_call)
int(* on_bar)(void *user, const pf_bar_t *bar, const pf_native_decision_v1 *at)
int(* on_tick)(void *user, const pf_bar_t *bar, const pf_native_decision_v1 *at)
int(* on_run_begin)(void *user)
void * user
Opaque; handed back unchanged.
int(* on_lot_excursion)(void *user, const pf_native_lot_excursion_v1 *facts, double *favorable, double *adverse)
The favorable and adverse magnitudes of one closing lot — closed_lot_excursion.
int(* on_margin_requirement)(void *user, const pf_native_margin_view_v1 *view, pf_native_margin_decision_v1 *out)
The two numbers one check point is about to compare — resolve_margin_requirement.
int(* on_close_units)(void *user, const pf_native_close_view_v1 *view, double *units)
How many units a host-sized CLOSE takes — the units half of resolve_execution_terms,...
int(* on_input)(void *user, const pf_bar_t *bar, int32_t input_index, int32_t completes_script_interval)
int(* on_recalculate)(void *user, const pf_bar_t *bar, const pf_native_decision_v1 *at, uint32_t reason, const pf_native_applied_v1 *cause)
EVERY calculation of the run, including the script bar's own close — on_native_recalculate.
int(* on_margin_call_units)(void *user, const pf_native_margin_view_v1 *view, double *units)
The size of a kernel-issued liquidation, before it rests — resolve_margin_call_units.
uint32_t struct_size
sizeof(pf_native_callbacks_v1).
int(* on_margin_check)(void *user, const pf_native_margin_view_v1 *at, int32_t *allowed)
Whether this kernel check point is one the host's broker model shares — margin_check_allowed.
The facts a host-sized CLOSE is resolved from, handed to pf_native_callbacks_v1::on_close_units.
uint32_t is_buy
0/1: the side this candidate would trade on.
uint32_t struct_size
sizeof(pf_native_close_view_v1).
double position_units
The whole physical book, signed.
double scope_exposure_units
What the bound scope holds here.
double default_resolved_price
The price the kernel would settle at.
uint64_t incarnation
The request being resolved.
uint32_t version
PF_NATIVE_API_VERSION.
Where the kernel is, presented to every callback.
int32_t sub_index
Sub-bar index inside the script bar.
int64_t decision_floor_ms
Lower bound a new request may be matched at.
int64_t effective_time_ms
The point's effective decision time.
int32_t is_terminal_sub_bar
1 on the script bar's last sub-bar.
int32_t sub_count
Sub-bars in this script bar (1 when unmagnified).
uint32_t struct_size
sizeof(pf_native_decision_v1).
uint64_t ordinal
Matching-point ordinal.
int32_t interval_index
Script interval index.
int64_t script_bar_open_ms
Open of the script bar under delivery.
uint8_t completion
NativeCompletionKind.
uint8_t path_phase
NativePathPhase.
uint32_t version
PF_NATIVE_API_VERSION.
uint8_t quote_kind
NativeCurrentQuoteKind; 0 when price is NaN.
uint8_t provenance
NativePriceProvenance.
double price
Current quote, NaN outside an execution point.
int64_t sub_bar_open_ms
Open of the sub-bar under delivery.
One recorded event, read back by strategy_native_events_v1.
uint8_t terminal
APPLIED only.
uint64_t successor
REPLACED: the new handle.
uint64_t incarnation
Subject request, 0 when the kind has none.
uint32_t version
PF_NATIVE_API_VERSION.
uint32_t reason
Per-kind reason enumerator, 0 when none.
uint8_t provenance
Cursor NativePriceProvenance.
int32_t interval_index
Cursor interval index.
int64_t effective_time_ms
Cursor effective time, 0 when the kind has no cursor.
uint32_t kind
pf_native_event_kind_t.
uint32_t struct_size
sizeof(pf_native_event_v1).
uint8_t path_phase
Cursor NativePathPhase.
uint64_t ordinal
Event ordinal; strictly increasing.
One closing lot's booking facts — ClosedLotExcursionFacts (RULING A48).
uint64_t entry_incarnation
The lot's opening request.
double carried_favorable
What the lot carried in, for a partial close.
double closed_qty
What this fill closes of it.
uint32_t struct_size
sizeof(pf_native_lot_excursion_v1).
double lot_qty
The whole lot.
uint8_t entry_bar_high_masked
The entry bar's high is not this trade's.
uint32_t version
PF_NATIVE_API_VERSION.
uint8_t entry_bar_low_masked
The entry bar's low is not this trade's.
The host's answer to one requirement view — NativeMarginDecision.
uint32_t struct_size
sizeof(pf_native_margin_decision_v1).
uint32_t version
PF_NATIVE_API_VERSION.
The facts one margin hook is handed — the C spelling of NativeMarginRequirementView,...
uint8_t cursor_provenance
NativePriceProvenance.
double required
Maintenance requirement of the whole position at mark.
uint8_t cursor_path_phase
NativePathPhase.
uint32_t version
PF_NATIVE_API_VERSION.
uint32_t kind
pf_native_margin_check_kind_t.
double signed_units
The book being measured.
double equity
Marked equity on the model's basis.
double mark
The price the breach is measured at.
uint32_t liquidation_resting
0/1: a liquidation rests from an earlier point.
uint32_t struct_size
sizeof(pf_native_margin_view_v1).
One open physical lot, copied out by strategy_native_open_lot_get_v1 — the C spelling of NativeOpenLo...
uint64_t ordinal
Position in the book, oldest first.
const char * entry_label
Borrowed; see the struct note.
double unrealized_pnl
Fee-net move to mark, account currency; NaN for a NaN mark.
double adverse_excursion
Largest move against the lot so far, account currency, >= 0.
uint32_t struct_size
sizeof(pf_native_open_lot_v1).
double entry_commission
Entry fee still on the lot, account currency; a partial realization takes its share with it.
int64_t entry_time_ms
Effective time of the opening fill.
uint32_t side
pf_native_side_t.
double signed_units
Remaining units: > 0 long, < 0 short.
double entry_price
Booked entry price.
uint32_t version
PF_NATIVE_API_VERSION.
double mark
The price the three fields below were marked at.
const char * entry_comment
Borrowed; see the struct note.
int64_t cycle
The position cycle the lot belongs to — the owner_cycle a BIND_OPENING(S) request names.
int32_t entry_bar_index
Script-bar index of the opening fill.
double favorable_excursion
Largest move for the lot so far, account currency, >= 0.
uint64_t entry_incarnation
The request whose fill opened the lot; never reused; 0 only for a legacy synthetic lot.
One order request.
uint32_t reserve_percent_fee
0/1, SIZED only.
uint32_t owner
pf_native_owner_t.
double p1
Limit/stop price, or trail offset.
uint32_t visibility
pf_native_arm_visibility_t, WAIT_FOR_APPLIED only.
uint64_t group_id
MEMBER only.
uint32_t struct_size
sizeof(pf_native_request_v1).
uint32_t owner_n
Length of owner_incarnations.
uint32_t reduce_basis
pf_native_scope_basis_t, SCOPE_FRACTION only.
uint32_t capacity
pf_native_capacity_t.
uint32_t side
pf_native_side_t, SIZED only.
uint32_t intent
pf_native_intent_t.
uint32_t size_time
pf_native_size_time_t, SIZED only.
int64_t owner_cycle
BIND_OPENING / BIND_OPENINGS.
double anchor_offset
FROM_OWNER_FILL: signed offset.
uint32_t group_effect
pf_native_group_effect_t.
int64_t group_cohort
MEMBER only.
uint32_t reduce_claim
pf_native_scope_claim_t, SCOPE_FRACTION only.
uint8_t fill_through
LIMIT only: market-if-touched.
uint8_t anchor_offset_in_ticks
FROM_OWNER_FILL: the offset is a tick count.
double capacity_units
POINT_BUDGET only.
const uint64_t * owner_incarnations
Borrowed for the call only.
uint8_t trail_offset_in_ticks
TRAIL: p1 is a tick count, not a distance.
uint32_t version
PF_NATIVE_API_VERSION.
double p2
Stop-limit limit, or trail arm price.
uint32_t size_price
pf_native_size_price_t, SIZED only.
double intent_value
The intent's own scalar; see pf_native_intent_t.
uint32_t trigger
pf_native_trigger_t.
uint32_t grid_policy
pf_native_grid_policy_t, SIZED only.
uint32_t reduce_size
pf_native_reduction_t, REDUCE only.
uint8_t trail_has_arm_price
TRAIL: p2 is the arm price.
uint32_t anchor
pf_native_anchor_t (L7).
uint64_t cohort
BIND_COHORT.
uint32_t size_basis
pf_native_size_basis_t, SIZED only.
uint32_t anchor_rounding
pf_native_anchor_rounding_t, FROM_OWNER_FILL only.
uint32_t group_kind
pf_native_group_t.
The run's generic risk ledger — the C spelling of NativeRiskState (L9).
uint32_t has_reason
0/1: reason is meaningful.
uint32_t blocked
0/1: openings are refused right now.
uint32_t version
PF_NATIVE_API_VERSION.
uint32_t reason
pf_native_risk_limit_t that blocked.
double peak_equity
Running peak of the marked equity.
uint64_t fills_today
Applied fills counted in that day.
uint32_t consecutive_loss_days
Days that closed with a realized loss.
double day_open_equity
Equity the current day opened at.
uint32_t has_day
0/1: the ledger has reached a day.
uint32_t struct_size
sizeof(pf_native_risk_state_v1).
int64_t day_ordinal
The risk day, on the spec's day basis.
The run-specification fields pf_native_run_spec_v1 predates.
uint32_t price_grid
NativePriceGrid.
uint32_t reserved1
Must be 0.
uint32_t report_open_position_at_end
0/1; KernelRecorded only.
uint32_t risk_has_max_intraday_loss
0/1.
const char * intrabar_tf
The finer timeframe; LOWER_TF only, non-NULL.
uint32_t abort_reporting
pf_native_abort_reporting_t.
uint32_t present_mask
pf_native_spec_ext_mask_t bits.
const char * margin_liquidation_comment
Comment of the same; NULL is "".
uint32_t intrabar_sample_eligibility
pf_native_sample_eligibility_t, LOWER_TF only.
uint32_t struct_size
sizeof(pf_native_run_spec_ext_v1).
uint32_t open_bar_view
NativeOpenBarView.
uint32_t risk_has_max_fills_per_day
0/1.
int32_t intrabar_samples
Samples per script bar; LOWER_TF and SYNTHESIZED.
const pf_bar_t * auxiliary_bars
Strictly increasing bars; copied.
int32_t intrabar_volume_weighted_min_samples
double risk_max_intraday_loss
Threshold; account currency unless percent.
double margin_initial_long
0 = maintenance-only side: no kernel opening requirement, host owns admission; legal only with that s...
double margin_initial_short
0 = maintenance-only; see above.
uint32_t feed_tolerance
pf_native_feed_tolerance_t bits.
uint32_t intrabar_kind
pf_native_intrabar_kind_t.
uint32_t version
PF_NATIVE_API_VERSION.
const pf_native_subscription_v1 * subscriptions
Borrowed for the call.
uint32_t slot_label_policy
pf_native_slot_label_t.
const uint32_t * subscription_sources
Optional, borrowed for the call: subscriptions_n entries of pf_native_series_source_t,...
const pf_bar_t * intrabar_bars
The finer feed; borrowed for the call, copied.
uint32_t report_policy
NativeReportPolicy.
double risk_max_drawdown
Threshold; account currency unless percent.
int32_t intrabar_n
Length of intrabar_bars; LOWER_TF only.
uint32_t risk_max_drawdown_percent
0/1: the value is a percent of the running equity peak, out of 100.
uint32_t margin_sizing
NativeLiquidationSizing.
uint32_t path_order
pf_native_path_order_t.
uint32_t risk_max_intraday_loss_percent
0/1: percent of the day's opening equity.
uint32_t risk_max_fills_per_day
Applied fills, when the flag is 1.
uint32_t calculation
NativeCalculationTrigger.
uint32_t risk_max_consecutive_loss_days
Days, when the flag is 1.
double margin_shortfall_multiple
The C++ default is 1.0, not 0: a PRESENT block has every field read, so a zero-filled struct must sti...
uint32_t risk_has_max_consecutive_loss_days
0/1.
uint32_t margin_level_base
pf_native_margin_level_base_t.
int32_t intrabar_volume_weighted_max_samples
const char * margin_liquidation_label
Ticket of a kernel liquidation; NULL is "".
uint32_t intrabar_volume_weighted
0/1.
const char * auxiliary_tf
Non-NULL feed timeframe literal.
uint32_t margin_check
pf_native_liquidation_check_t.
uint32_t risk_has_max_drawdown
0/1.
uint32_t risk_day_basis
pf_native_risk_day_t.
uint32_t risk_action
pf_native_risk_action_t.
uint32_t margin_equity_basis
pf_native_margin_equity_basis_t.
uint32_t grid_rounding
NativeGridRounding.
uint32_t intrabar_distribution
pf_magnifier_distribution_t.
int32_t auxiliary_n
Length of auxiliary_bars.
uint32_t max_recalculations_per_point
Fill-cascade bound; 0 is legal.
Versioned native run specification.
Definition pineforge.h:469
The run's lifecycle and its typed failure.
uint64_t consumed_high_water
uint64_t failure_ordinal
The point the failure was latched at, 0 when absent.
uint32_t failure_operation
NativeFailureOperation.
uint32_t phase
NativeRunPhase while Running.
uint32_t lifecycle
pf_native_lifecycle_t.
uint32_t failure_discriminator
uint32_t completion
NativeCompletion once Completed.
uint32_t struct_size
sizeof(pf_native_state_v1).
uint32_t failure_code
NativeFailureCode; PF_NATIVE_FAILURE_CALLBACK for a callback that returned non-zero.
uint32_t version
PF_NATIVE_API_VERSION.
One declared higher-timeframe series of pf_native_run_spec_ext_v1.
const pf_bar_t * authoritative_bars
Optional exchange bars; copied.
uint32_t struct_size
sizeof(pf_native_subscription_v1).
uint32_t gaps
0 = barmerge.gaps_off, 1 = gaps_on.
uint32_t lookahead
0 = barmerge.lookahead_off, 1 = lookahead_on.
int32_t authoritative_n
Length of authoritative_bars.
const char * tf
Non-NULL timeframe literal.
The trail projection of strategy_native_trail_state_v1 — the C spelling of NativeTrailState.
double best_price
Running best; 0 before the arm.
uint64_t activation_ordinal
The TrailArm event; 0 before the arm.
double current_level
The stop the best is riding; 0 before the arm.
uint32_t struct_size
sizeof(pf_native_trail_state_v1).
uint32_t version
PF_NATIVE_API_VERSION.
uint32_t activated
0/1: the arm price has been reached.
One live request, copied out by strategy_native_working_get_v1.
double p2
Trigger level 2 (stop-limit limit / trail arm).
double capacity_units
Point budget, 0 for immediate capacity.
double p1
Trigger level 1 (limit / stop / trail offset).
double remaining_units
Valid when remaining_kind is UNITS.
uint32_t remaining_kind
pf_native_remaining_t.
uint32_t struct_size
sizeof(pf_native_working_v1).
uint32_t origin
RequestOrigin: 0 host, 1 kernel liquidation, 2 kernel risk.
int64_t decision_time_lower_bound
Birth: earliest matchable time.
const char * comment
Borrowed; see the struct note.
uint64_t acceptance_ordinal
Birth: the accepting event.
uint32_t version
PF_NATIVE_API_VERSION.
uint32_t intent
pf_native_intent_t as accepted.
uint32_t group_kind
pf_native_group_t as accepted.
double intent_value
The intent's own scalar, 0 when it has none.
uint32_t owner
pf_native_owner_t as accepted.
uint32_t capacity
pf_native_capacity_t as accepted.
const char * label
Borrowed; see the struct note.
uint64_t incarnation
The request's handle.
uint32_t group_effect
pf_native_group_effect_t, 0 when no group.
uint32_t trigger
pf_native_trigger_t as accepted.
uint32_t trigger_state
pf_native_trigger_state_t.
Backtest report filled by run_backtest / run_backtest_full.
Definition pineforge.h:365