-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathnative_c_api.h
More file actions
3289 lines (3079 loc) · 193 KB
/
Copy pathnative_c_api.h
File metadata and controls
3289 lines (3079 loc) · 193 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* SPDX-License-Identifier: Apache-2.0
*
* native_c_api.h — versioned C-level native host API (R5 lane L13).
*
* A host that is not written in C++ drives the kernel through this header:
* it hands the runtime a callback table, runs a batch of bars, and submits,
* replaces, cancels or executes order requests from inside those callbacks.
* It drives the same kernel as <pineforge/native_host.hpp>'s NativeStrategyHost;
* the C++ it does not spell in 1.0 is docs/pages/native-engine.md's boundary table.
*
* SCOPE
* ─────
* ✓ Create / free a native host backed by a C callback table
* ✓ Run a batch of OHLCV bars and fill a pf_report_t
* ✓ submit / replace / cancel / cancel_all / cancel_where / execute_current
* ✓ Read the physical position, the live working book, the open lots (the
* book lot by lot, marked at a price — strategy.opentrades.* for a C host)
* and the event history
* ✓ Read, at every decision point, the script interval and the session day
* of its open and of the next input — the facts session-day flags are
* derived from
* ✓ Read the run's lifecycle state and its typed failure
* ✓ Read a margin call's whole economics — equity, requirement and the
* position on either side of it — by its event ordinal
* ✓ Read a closed row's own identifiers — its entry and exit ticket, its exit
* comment and its close cause — with the pineforge.h accessors, which take
* any handle this header produces
* ✓ Arm a WAIT_FOR_APPLIED child after its owner's print, or bound to the
* whole book, and size its close with on_close_units
* ✓ Ask the kernel what a SIZED request would resolve to, before submitting
* ✓ Extend the run specification with the fields pf_native_run_spec_v1 predates
* ✓ Declare an auxiliary finer feed — up front, or from `on_run_begin` —
* build a series from it, and append its later bars to a realtime stream,
* each refusal named by the kernel's own typed answer
* ✓ Declare, from `on_applied`, where a lot's opening fill sat on its entry
* bar, for a host that owns its lots' excursions
*
* ✗ Streaming has no new symbols: strategy_stream_begin / _push_bar /
* _push_tick / _advance_time / _end / _fill_report take any handle this
* header produces, unchanged.
* ✓ Answer the kernel's policy hooks: a host-sized close's units
* (on_close_units), a candidate's settlement price and opening shape
* (on_execution_terms), the last gate before a fill (on_precommit), where
* an anchored leg is armed (on_anchored_level), and the host's own state
* folded into the broker-state hash (on_hash_extension). The per-bar hash
* rows need no new symbol: `report_policy` =
* PF_NATIVE_REPORT_KERNEL_RECORDED with
* strategy_set_broker_state_hash_recording fills
* pf_report_t::broker_state_hash, one row per script bar.
*
* COVERAGE
* ────────
* Every public member of NativeStrategyHost, and either its C spelling or the
* reason it has none. scripts/check_native_c_api_surface.py proves this list is
* exactly that class's public surface: a member added there without a row here,
* or a row here naming a member that no longer exists, fails CI.
*
* [C] on_bar strategy_native_run_v1 / the strategy_stream_* ingress
* [--] prepare_native_begin borrows the codegen ingress (InputsMap, SymInfo, the opaque
* overrides) that no C host supplies; a C run is declared up front
* with strategy_configure_native_ext_v1
* [C] on_native_run_begin pf_native_callbacks_v1::on_run_begin
* [C] on_native_input pf_native_callbacks_v1::on_input
* [C] on_native_tick pf_native_callbacks_v1::on_tick
* [C] on_native_timeframe_bar pf_native_callbacks_v1::on_timeframe_bar; its
* NativeTimeframeBarContext::interval is read inside
* that callback with strategy_native_timeframe_bar_interval_v1
* [C] on_native_bar_open pf_native_callbacks_v1::on_bar_open
* [C] on_native_bar pf_native_callbacks_v1::on_bar
* [C] on_native_recalculate pf_native_callbacks_v1::on_recalculate
* [C] on_native_sub_bar pf_native_callbacks_v1::on_sub_bar
* [C] on_native_applied pf_native_callbacks_v1::on_applied
* [C] on_native_margin_call pf_native_callbacks_v1::on_margin_call -- the call's whole
* MarginCallEvent is strategy_native_margin_call_v1, by the
* ordinal the hook is handed
* [C] resolve_execution_terms pf_native_callbacks_v1::on_close_units (the units of a host-sized
* close) and pf_native_callbacks_v1::on_execution_terms (the price,
* the opening shape and the grid policy)
* [C] validate_execution_precommit pf_native_callbacks_v1::on_precommit -- the plan, the inspection
* and the projected account flattened into
* pf_native_precommit_view_v1, the closed rows' P&L borrowed
* [C] resolve_anchored_level pf_native_callbacks_v1::on_anchored_level
* [C] resolve_margin_requirement pf_native_callbacks_v1::on_margin_requirement
* [C] margin_check_allowed pf_native_callbacks_v1::on_margin_check
* [C] resolve_margin_call_units pf_native_callbacks_v1::on_margin_call_units
* [C] owns_lot_excursions pf_native_callbacks_v1::on_lot_excursion -- installing it IS
* declaring ownership
* [C] closed_lot_excursion pf_native_callbacks_v1::on_lot_excursion
* [C] declare_native_bar_open_hook pf_native_callbacks_v1::on_bar_open -- a table without it
* declares none, once, when the host is created
* [C] declare_native_precommit_hook pf_native_callbacks_v1::on_precommit -- a table without it
* declares none, once, when the host is created
* [C] current_partial_bar strategy_native_partial_bar_v1
* [C] native_recalculation_count strategy_native_recalculations_v1
* [C] native_recalculations_skipped strategy_native_recalculations_v1
* [C] current_execution_point pf_native_decision_v1::price / ::quote_kind, on every callback;
* its script interval and session days are the decision's
* session tail
* [C] trail_state strategy_native_trail_state_v1
* [--] inspect_current_execution scheduled for 1.1.0 (C-SURFACE-2): C has no non-mutating call,
* and strategy_native_execute_current_v1 applies the command, so
* it is no preview; the preview's refusal, readiness, account
* projection and closed-row P&L have no size-prefixed POD in 1.0
* [C] execute_current strategy_native_execute_current_v1
* [--] mark_native_report_point the C spec does not name KernelRecordedAtHostMarks,
* so a C host cannot select its mark cadence
* [C] native_series_bar strategy_native_series_bar_v1
* [C] declare_timeframe_subscriptions strategy_native_declare_subscriptions_v1 -- a row is
* pf_native_subscription_v1, whose `lookahead` / `gaps` bools are
* pf_native_lookahead_e / pf_native_gaps_e words
* [C] declare_timeframe_subscriptions_result strategy_native_declare_subscriptions_ext_v1 -- the
* same call, its NativeRunSpecValidation written to `error` /
* `field` (pf_native_spec_error_e / pf_native_spec_field_e), plus
* a series source per row
* [C] declare_auxiliary_feed strategy_native_declare_auxiliary_feed_v1 -- a NULL `tf`
* withdraws the staged feed
* [C] declare_auxiliary_feed_result strategy_native_declare_auxiliary_feed_v1, whose `error` /
* `field` out-parameters are the typed answer
* [C] append_auxiliary_bars strategy_native_append_auxiliary_bars_v1
* [C] append_auxiliary_bars_result strategy_native_append_auxiliary_bars_ext_v1 --
* NativeAuxiliaryAppendError (pf_native_append_error_e) and the
* bar of the call it stopped on
* [C] configure_native strategy_configure_native_v1 / strategy_configure_native_ext_v1 /
* strategy_configure_native_ext_result_v1 -- the last writes
* NativeRunSpecError / NativeRunSpecField out-parameters;
* the two specs' enum-valued words are pf_native_fee_kind_e,
* pf_native_close_execution_e, pf_native_open_directions_e,
* pf_native_report_policy_e, pf_native_price_grid_e,
* pf_native_grid_rounding_e, pf_native_calc_trigger_e,
* pf_native_open_bar_view_e, pf_native_liquidation_sizing_e
* and pf_native_event_retention_e words
* [C] configure_native_fx_curve strategy_configure_native_fx_curve_v1 (pineforge.h)
* [C] native_state strategy_native_state_v1
* [C] submit strategy_native_submit_v1 -- a WAIT_FOR_APPLIED child's
* first_match / scope are pf_native_request_v1::arm_first_match /
* arm_scope
* [C] replace strategy_native_replace_v1, or strategy_native_replace_ext_v1
* for the ReplaceResult::reason the first one drops
* [--] submit_market a C++ convenience that REFUSES non-market extras instead of dropping
* them; the same request is strategy_native_submit_v1 with
* PF_NATIVE_TRIGGER_MARKET and a zero-filled struct
* [--] replace_market the same convenience for a replace; see submit_market
* [C] cancel strategy_native_cancel_v1
* [C] native_working_requests strategy_native_working_len_v1 / strategy_native_working_get_v1;
* a Trail's arm_price presence is
* pf_native_working_v1::trail_has_arm_price, the anchor and
* owner relation are pf_native_working_v1::anchor .. arm_scope
* [C] native_open_lots strategy_native_open_lot_count_v1 / strategy_native_open_lot_get_v1
* [C] cancel_all strategy_native_cancel_all_v1
* [C] cancel_where strategy_native_cancel_where_v1
* [C] cohort_open strategy_native_cohort_open_v1
* [C] cohort_add strategy_native_cohort_add_v1
* [C] cohort_remove strategy_native_cohort_remove_v1
* [C] physical_position strategy_native_position_v1
* [C] native_marked_equity strategy_native_marked_equity_v1
* [C] native_liquidation_price strategy_native_liquidation_price_v1
* [--] native_aggregates_input_bars its one reader is the Pine host, which re-dates a closed row
* onto the aggregated script bar TradingView reports; a C host
* reads the rows the kernel books as they are, and names both
* timeframes in its own spec
* [C] native_risk_state strategy_native_risk_state_v1
* [C] native_events strategy_native_events_v1
* [C] native_acknowledge_events strategy_native_acknowledge_events_v1
* [C] native_event_window_start strategy_native_event_window_v1
* [C] native_decision_floor pf_native_state_v1::decision_floor_ms
* [C] native_consumed_high_water pf_native_state_v1::consumed_high_water
* [C] native_continuation_hash strategy_native_continuation_hash_v1
* [--] native_closed_rows_amended a C host reads the closed rows and never writes one -- the kernel
* books them -- so it has no amendment to name
* [C] native_sized_units strategy_native_sized_units_v1 -- a PF_NATIVE_INTENT_SIZED
* pf_native_request_v1 is the Sized basis; its sizing block is
* read, nothing is submitted
*
* Three asymmetries this list does not reach, recorded here because a C host
* will look for them; the 1.0 C boundary table lists every other one.
*
* pf_native_working_v1 has two trigger numbers, p1 and p2 -- plus, in its own
* additive tail, trail_has_arm_price, which tells an absent arm from an arm at
* 0.0 -- while a trail now has three numbers: offset, arm price and
* pf_native_request_v1::trail_best_seed. The readback keeps the first two and
* the presence flag; it does NOT carry the seed. The seed is a SUBMISSION
* input -- a floor on where the ride starts, consumed once at the arm -- and
* what a host wants back afterwards is the ride itself, which
* strategy_native_trail_state_v1 already answers as best_price and
* current_level. Another readout tail would cost every caller that sends the
* current sizeof a recompile, for a number the caller wrote.
* Executed by the trail-seed and arm-presence scenarios of
* tests/test_native_c_api.c.
*
* pf_trade_t carries no exit ticket. That POD is the codegen
* ABI's, runtime-allocated and iterated with the caller's own sizeof, so a
* tail costs a PF_ABI_VERSION bump for every existing consumer — and it needs
* none. strategy_closed_trade_entry_id / _exit_id / _exit_comment /
* _close_cause (pineforge.h) index exactly the rows of pf_report_t::trades,
* are implemented in the kernel archive, and take any handle, so a C host
* reads back the ticket its own margin model declared
* (pf_native_run_spec_ext_v1::margin_liquidation_label) without a new symbol.
* Executed by the fx-roll scenario of tests/test_native_c_api.c.
*
* pf_native_decision_v1 carries three of NativeDecisionContext's four
* session-day facts (in_session, opens_session_day, closes_session_day, in
* the base layout's former tail padding, so a table of every published length
* is handed them) and not the fourth, closes_session_day_open_ended. That one
* differs from closes_session_day on a batch's final bar alone, for a host
* that recomputes a batch whose last input is still forming; a C host's live
* edge is the strategy_stream_* ingress, whose bars already read the calendar
* there, and that padding holds exactly the three facts and their presence
* byte. Executed by the session-day scenario of tests/test_native_c_api.c.
*
* BASE-CLASS SEAMS
* ────────────────
* The rows at the top of this block census NativeStrategyHost's own surface,
* so they cannot see a member of its base. The BacktestEngine members a host
* is documented to call or override from its callbacks are opted in one by
* one: engine.hpp marks each with a `@host-seam` line, and
* scripts/check_native_c_api_surface.py proves this list is exactly the
* marked set, with a C spelling or a reason for each, exactly as it does for
* those rows. A new protected member a host is meant to reach takes the
* marker and a row here.
*
* [C] declare_opened_lot_entry_bar_mask strategy_native_declare_opened_lot_entry_bar_mask_v1 -- legal
* inside on_applied alone; executed by the entry-bar mask
* scenario of tests/test_native_c_api.c
* [C] hash_host_extension pf_native_callbacks_v1::on_hash_extension -- the host folds a
* 64-bit digest of its own state after the kernel's bytes
* [--] hash_source_extension the deprecated spelling of hash_host_extension, kept for C++
* subclasses written against it; a C host has only the current
* spelling, on_hash_extension
*
* HARDENING RULES
* ───────────────
* - Every struct is tagged and size-prefixed: `struct_size` is the exact
* sizeof of the version the caller compiled against, `version` is that
* layout's version constant. A mismatch is refused with PF_NATIVE_E_STRUCT
* and mutates nothing. The exception is a deliberately additive tail: a
* struct that grew one publishes every earlier layout's length as a
* `*_SIZE` constant and the runtime accepts each — pf_native_request_v1,
* pf_native_run_spec_ext_v1 and pf_native_callbacks_v1 as inputs,
* pf_native_working_v1 as a readout. A readout is written only as far as
* the length its caller sent. A struct the runtime PRESENTS to a callback
* (pf_native_decision_v1) is presented at the layout the caller's
* callback table was published with, and its `struct_size` says so.
* - Every enum-valued field is translated by an exhaustive switch. A value
* outside its enumeration is refused with PF_NATIVE_E_TAG; a value this
* version deliberately cannot represent is refused with
* PF_NATIVE_E_UNSUPPORTED. No C value is ever cast onto a C++ variant.
* - C callbacks must not unwind. A callback that returns non-zero latches
* NativeFailureCode::CallbackException (PF_NATIVE_FAILURE_CALLBACK) and the
* run ends Failed; the code is readable with strategy_native_state_v1.
* - Commands follow the kernel's existing legality rule: inside a callback,
* or between realtime inputs. A command issued anywhere else returns
* PF_NATIVE_E_STATE and changes nothing.
*
* STABILITY
* ─────────
* Same guarantee as <pineforge/pineforge.h>: within a major version the
* layouts below are append-only and the signatures never change. A field is
* appended one of two ways. A deliberately additive tail (HARDENING RULES
* above) keeps the version constant: the struct publishes every earlier
* layout's length as a `*_SIZE` constant and the runtime accepts each, so a
* caller compiled against an earlier layout keeps working unchanged, and a
* readout is written only as far as the length that caller sent. Any other
* layout change is a new revision that raises the version constant; there
* the size prefix keeps an old caller refused rather than silently misread.
*/
#ifndef PINEFORGE_NATIVE_C_API_H
#define PINEFORGE_NATIVE_C_API_H
#include <stdint.h>
#include <stddef.h>
/* pf_strategy_t, pf_bar_t, pf_report_t, PF_API. pineforge.h includes this
* header back at its end; both guards make either include order work. */
#include <pineforge/pineforge.h>
/** Feature probe for the C-level native host API.
* When defined, #strategy_native_host_create_v1 is available. */
#define PINEFORGE_HAS_NATIVE_C_API_V1 1
/** Monotonic version of this header's native-C layouts. Every versioned
* struct below carries it in its `version` field. */
#define PF_NATIVE_API_VERSION 1
#ifdef __cplusplus
extern "C" {
#endif
/** @defgroup pf_native_c_status Status codes
* @brief Every `int`-returning symbol here answers 0 or one of these.
*
* Negative values are errors. A C-layer validation refusal does not mutate
* native run state; a kernel-origin refusal can latch Failed, as the
* configure-reuse and reentrant-append contracts below specify.
* Non-negative values are outcomes: 0 is success everywhere, and
* #strategy_native_execute_current_v1 additionally answers the positive
* #pf_native_execute_outcome_t codes.
* @{ */
#define PF_NATIVE_OK 0 /**< Success. */
#define PF_NATIVE_E_HANDLE -1 /**< NULL handle, or not a C-callback native host. */
#define PF_NATIVE_E_STRUCT -2 /**< `struct_size` / `version` mismatch. */
#define PF_NATIVE_E_TAG -3 /**< An enum field outside its enumeration. */
#define PF_NATIVE_E_ARGUMENT -4 /**< NULL output, negative count, out-of-range index. */
#define PF_NATIVE_E_STATE -5 /**< Illegal here: the command legality rule, or the
* kernel's own lifecycle, refused it. */
#define PF_NATIVE_E_REJECTED -6 /**< The kernel rejected the request (reason written out). */
#define PF_NATIVE_E_UNSUPPORTED -7 /**< A tag this API version cannot represent. */
#define PF_NATIVE_E_EXCEPTION -8 /**< A C++ exception was contained at the boundary. */
#define PF_NATIVE_E_NOT_WORKING -9 /**< A nonzero target incarnation is not live, whether it was retired or never issued. */
#define PF_NATIVE_E_INVALID_TARGET -10 /**< Malformed target: incarnation 0. C commands pair an incarnation with this handle's current run identity, so they cannot pass a foreign run identity. */
#define PF_NATIVE_E_RUN_FAILED -11 /**< The run did not reach Completed; read the state. */
#define PF_NATIVE_E_REFUSED -12 /**< execute_current refused; see pf_native_refusal_e. */
/** Non-negative outcome: the kernel HAS no answer here and the output was
* left at its documented empty. It is not an error — the C++ spelling of
* each accessor that returns it is a `std::optional`, whose empty is a
* legitimate answer (no path walk, an unarmed trail, a series that has not
* delivered, a run with no margin model). Only the accessors whose own
* documentation names it can return it; #strategy_native_execute_current_v1
* never does, its positive codes being #pf_native_execute_outcome_t. */
#define PF_NATIVE_ABSENT 1
/** @} */
/** `NativeFailureCode::CallbackException` — the code latched when a C callback
* returns non-zero. The historical spelling of
* #PF_NATIVE_FAILURE_CALLBACK_EXCEPTION, kept for the callers written
* against it; pinned by a static_assert. */
#define PF_NATIVE_FAILURE_CALLBACK 5
/** @defgroup pf_native_c_enums Translated enumerations
* @brief Every value below is the exact integer of the C++ alternative it
* names, pinned by static_asserts in src/native_c_host.cpp.
* @{ */
/** Order intent — the alternative index of `native_order::OrderIntent`. */
typedef enum pf_native_intent_e {
PF_NATIVE_INTENT_FLATTEN = 0, /**< Close the whole book. */
PF_NATIVE_INTENT_REDUCE = 1, /**< Reduce; see #pf_native_reduction_t. */
PF_NATIVE_INTENT_TRANSACT = 2, /**< `intent_value` signed units. */
PF_NATIVE_INTENT_REVERSE_TO = 3, /**< `intent_value` target signed exposure. */
PF_NATIVE_INTENT_HOST_SIZED = 4, /**< A close sized by on_close_units: the
* cohort close (#PF_NATIVE_OWNER_BIND_COHORT)
* or a WAIT_FOR_APPLIED child that carries
* the arm tail (#pf_native_arm_scope_t;
* the kernel admits it under BOOK only).
* Refused PF_NATIVE_E_UNSUPPORTED under
* any other owner. */
PF_NATIVE_INTENT_SIZED = 5 /**< Kernel-sized opening (L3). */
} pf_native_intent_t;
/** Reduction size — the alternative index of `native_order::ReductionSize`. */
typedef enum pf_native_reduction_e {
PF_NATIVE_REDUCE_EXPLICIT_UNITS = 0, /**< `intent_value` units. */
PF_NATIVE_REDUCE_OWNER_OPENED = 1, /**< Exactly what the owner opened. */
PF_NATIVE_REDUCE_SCOPE_FRACTION = 2 /**< `intent_value` fraction in (0, 1]. */
} pf_native_reduction_t;
/** Scope claim of a fractional reduce. */
typedef enum pf_native_scope_claim_e {
PF_NATIVE_SCOPE_GROSS = 0,
PF_NATIVE_SCOPE_NET_OF_SIBLINGS = 1
} pf_native_scope_claim_t;
/** Side of a kernel-sized opening. */
typedef enum pf_native_side_e {
PF_NATIVE_SIDE_LONG = 0,
PF_NATIVE_SIDE_SHORT = 1
} pf_native_side_t;
/** Sizing basis — the alternative index of `native_order::SizeBasis`. */
typedef enum pf_native_size_basis_e {
PF_NATIVE_SIZE_BASIS_CASH = 0, /**< `intent_value` account-currency cash. */
PF_NATIVE_SIZE_BASIS_EQUITY_FRACTION = 1 /**< `intent_value` fraction of marked equity. */
} pf_native_size_basis_t;
/** When a sizing basis resolves. */
typedef enum pf_native_size_time_e {
PF_NATIVE_SIZE_AT_MATCH = 0,
PF_NATIVE_SIZE_AT_ACCEPTANCE = 1
} pf_native_size_time_t;
/** Whether resolved sizing snaps onto the run's quantity grid. */
typedef enum pf_native_grid_policy_e {
PF_NATIVE_GRID_SNAP = 0,
PF_NATIVE_GRID_EXPLICIT_UNITS = 1
} pf_native_grid_policy_t;
/** Trigger — the alternative index of `native_order::Trigger`. */
typedef enum pf_native_trigger_e {
PF_NATIVE_TRIGGER_MARKET = 0, /**< p1, p2 ignored. */
PF_NATIVE_TRIGGER_LIMIT = 1, /**< p1 = price; `fill_through` makes it market-if-touched. */
PF_NATIVE_TRIGGER_STOP = 2, /**< p1 = price. */
PF_NATIVE_TRIGGER_STOP_LIMIT = 3, /**< p1 = stop, p2 = limit. */
PF_NATIVE_TRIGGER_TRAIL = 4 /**< p1 = offset, p2 = arm price when `trail_has_arm_price`;
* `trail_best_seed` when `trail_has_best_seed`. */
} pf_native_trigger_t;
/** Where a trigger level comes from — `native_order::TriggerAnchor` (L7). */
typedef enum pf_native_anchor_e {
PF_NATIVE_ANCHOR_ABSOLUTE = 0, /**< The level written in the trigger. */
PF_NATIVE_ANCHOR_FROM_OWNER_FILL = 1 /**< owner fill + `anchor_offset` (signed). */
} pf_native_anchor_t;
/** How a materialized anchored level snaps onto the run's price tick ladder —
* `native_order::NativeAnchorRounding` (L7b). RAW is the established
* behaviour; the other two need `price_tick > 0` at acceptance. */
typedef enum pf_native_anchor_rounding_e {
PF_NATIVE_ANCHOR_ROUNDING_RAW = 0, /**< fill + offset exactly. */
PF_NATIVE_ANCHOR_ROUNDING_HALF_UP = 1, /**< Nearest tick, ties away from zero. */
PF_NATIVE_ANCHOR_ROUNDING_DIRECTIONAL = 2 /**< Toward the region the leg needs. */
} pf_native_anchor_rounding_t;
/** Whether a WAIT_FOR_APPLIED child is a working order before its arm —
* `native_order::NativeArmVisibility` (L7b). PENDING_UNTIL_ARMED keeps it
* out of #strategy_native_working_len_v1 / #strategy_native_working_get_v1
* until its ArmedEvent; it stays a live request the whole time (replace,
* cancel, cancel_all still address it, and it never matches before the arm
* under either value). */
typedef enum pf_native_arm_visibility_e {
PF_NATIVE_ARM_VISIBILITY_WORKING = 0,
PF_NATIVE_ARM_VISIBILITY_PENDING_UNTIL_ARMED = 1
} pf_native_arm_visibility_t;
/** Whether an armed WAIT_FOR_APPLIED child may trade on its owner's own fill
* print — `native_order::NativeArmFirstMatch`. AT_ARM_PRINT (the default) is
* the established book: the armed child is a candidate at that very cursor,
* so a level the print already satisfies matches there. AFTER_ARM_PRINT
* gives it the birth rule of a request submitted from the owner's own
* `on_applied`: on the point that armed it, it sees only the path after the
* print. It governs a priced trigger's level test; a market trigger has no
* level. Both are broker models. */
typedef enum pf_native_arm_first_match_e {
PF_NATIVE_ARM_FIRST_MATCH_AT_ARM_PRINT = 0,
PF_NATIVE_ARM_FIRST_MATCH_AFTER_ARM_PRINT = 1
} pf_native_arm_first_match_t;
/** What an armed CLOSING child (REDUCE, FLATTEN, a host-sized close) closes —
* `native_order::NativeArmScope`. OWNER_LOT (the default) is the lot its
* owner's fill opened, and nothing a later add brings. BOOK binds it, at the
* arm, to the whole position that fill left, so a protective leg placed with
* its entry covers later adds. A host-sized close may wait for its owner only
* under BOOK (its units are #pf_native_callbacks_v1::on_close_units'); a
* waiting transaction closes nothing and must keep OWNER_LOT. */
typedef enum pf_native_arm_scope_e {
PF_NATIVE_ARM_SCOPE_OWNER_LOT = 0,
PF_NATIVE_ARM_SCOPE_BOOK = 1
} pf_native_arm_scope_t;
/** Capacity — the alternative index of `native_order::Capacity`. */
typedef enum pf_native_capacity_e {
PF_NATIVE_CAPACITY_IMMEDIATE = 0, /**< Whole remaining at one point. */
PF_NATIVE_CAPACITY_POINT_BUDGET = 1 /**< `capacity_units` per matching point. */
} pf_native_capacity_t;
/** Owner — the alternative index of `native_order::Owner`. */
typedef enum pf_native_owner_e {
PF_NATIVE_OWNER_INDEPENDENT = 0, /**< No owner. */
PF_NATIVE_OWNER_WAIT_FOR_APPLIED = 1, /**< One parent in `owner_incarnations`. */
PF_NATIVE_OWNER_BIND_OPENING = 2, /**< One opening + `owner_cycle`. */
PF_NATIVE_OWNER_BIND_OPENINGS = 3, /**< `owner_n` openings + `owner_cycle`. */
/** `cohort` from #strategy_native_cohort_open_v1. The kernel pairs this
* owner with exactly one intent — a host-sized CLOSE — so a cohort close
* is spelled #PF_NATIVE_INTENT_HOST_SIZED with this owner and no
* quantity of its own: the roster's live openings are the target and the
* cohort authority decides the units. That pairing is the only shape in
* which HOST_SIZED is accepted here. */
PF_NATIVE_OWNER_BIND_COHORT = 4
} pf_native_owner_t;
/** Group — the alternative index of `native_order::Group`. */
typedef enum pf_native_group_e {
PF_NATIVE_GROUP_NONE = 0,
PF_NATIVE_GROUP_MEMBER = 1 /**< `group_id`, `group_cohort`, `group_effect`. */
} pf_native_group_t;
/** What a filled group member does to its siblings. */
typedef enum pf_native_group_effect_e {
PF_NATIVE_GROUP_CANCEL = 0,
PF_NATIVE_GROUP_REDUCE = 1
} pf_native_group_effect_t;
/** Which identity text #strategy_native_cancel_where_v1 compares.
*
* Both are the free text the request carried: `comment` is the established
* selector, `label` is where a host that names its orders puts its own id,
* so LABEL is the one call that withdraws every live request issued under
* one such id. Neither is indexed; both walk the live book once. */
typedef enum pf_native_request_field_e {
PF_NATIVE_FIELD_COMMENT = 0,
PF_NATIVE_FIELD_LABEL = 1
} pf_native_request_field_t;
/** Price rule of an immediate execution. */
typedef enum pf_native_price_rule_e {
PF_NATIVE_PRICE_AS_PRESENTED = 0,
PF_NATIVE_PRICE_NEAREST_TICK = 1
} pf_native_price_rule_t;
/** Outcome of #strategy_native_execute_current_v1 (non-negative returns). */
typedef enum pf_native_execute_outcome_e {
PF_NATIVE_EXECUTED_APPLIED = 0, /**< An execution was applied. */
PF_NATIVE_EXECUTED_NO_EFFECT = 1, /**< Legal, nothing to execute. */
PF_NATIVE_EXECUTED_MATCH_REJECTED = 2, /**< Terms/admission rejected it. */
PF_NATIVE_EXECUTED_CANCELLED = 3 /**< The request was cancelled instead. */
} pf_native_execute_outcome_t;
/** Why execute_current refused. Written to `*refusal`, if supplied, when
* #strategy_native_execute_current_v1 answers PF_NATIVE_E_REFUSED. Mirrors
* `NativeCurrentRefusal`. */
typedef enum pf_native_refusal_e {
PF_NATIVE_REFUSAL_NO_EXECUTION_CONTEXT = 0,
PF_NATIVE_REFUSAL_REENTRANT = 1,
PF_NATIVE_REFUSAL_INVALID_HANDLE = 2,
PF_NATIVE_REFUSAL_NOT_WORKING = 3,
PF_NATIVE_REFUSAL_NOT_ACCEPTED_IN_CALLBACK = 4,
PF_NATIVE_REFUSAL_UNSUPPORTED_REQUEST = 5,
PF_NATIVE_REFUSAL_UNREADY_OWNER = 6,
PF_NATIVE_REFUSAL_INVALID_SELECTION = 7,
PF_NATIVE_REFUSAL_CONFIGURATION_MISMATCH = 8
} pf_native_refusal_t;
/** Lifecycle of the native run — mirrors `NativeLifecycleKind`. */
typedef enum pf_native_lifecycle_e {
PF_NATIVE_LIFECYCLE_UNCONFIGURED = 0,
PF_NATIVE_LIFECYCLE_READY = 1,
PF_NATIVE_LIFECYCLE_RUNNING = 2,
PF_NATIVE_LIFECYCLE_COMPLETED = 3,
PF_NATIVE_LIFECYCLE_FAILED = 4
} pf_native_lifecycle_t;
/** Event tag of #pf_native_event_v1.
*
* 1..18 are the first eighteen alternatives of `native_order::CommandEvent`,
* in variant order plus one; 19 and 20 are the driver-point and account
* observations `native_events()` also carries. 21 is L9's `NativeRiskEvent`,
* the nineteenth CommandEvent alternative: it was added after this header
* froze, so it keeps a tag of its own past the two observations rather than
* taking 19 and renumbering them. A reader compiled before it skips it by
* tag, exactly as it must skip any tag it does not know.
*
* One kind named in the design is NOT represented and never appears here: a
* completed higher-timeframe bucket, delivered only through
* `on_timeframe_bar` and never recorded in the event history. */
typedef enum pf_native_event_kind_e {
PF_NATIVE_EVENT_ACCEPTED = 1,
PF_NATIVE_EVENT_REJECTED = 2,
PF_NATIVE_EVENT_REPLACED = 3,
PF_NATIVE_EVENT_REPLACE_REJECTED = 4,
PF_NATIVE_EVENT_CANCELLED = 5,
PF_NATIVE_EVENT_NOT_WORKING = 6,
PF_NATIVE_EVENT_INVALID_HANDLE = 7,
PF_NATIVE_EVENT_NO_EFFECT = 8,
PF_NATIVE_EVENT_MATCH_REJECTED = 9,
PF_NATIVE_EVENT_APPLIED = 10,
PF_NATIVE_EVENT_CLOSE_BOUND = 11,
PF_NATIVE_EVENT_ACTIVATED = 12,
PF_NATIVE_EVENT_RESERVATION_REDUCED = 13,
PF_NATIVE_EVENT_DEFERRED_GROUP = 14,
PF_NATIVE_EVENT_QUANTITY_BOUND = 15,
PF_NATIVE_EVENT_ARMED = 16,
PF_NATIVE_EVENT_TERMS_RESOLVED = 17,
PF_NATIVE_EVENT_MARGIN_CALL = 18,
PF_NATIVE_EVENT_DRIVER_POINT = 19,
PF_NATIVE_EVENT_ACCOUNT = 20,
PF_NATIVE_EVENT_RISK = 21
} pf_native_event_kind_t;
/** Which generic risk limit a #PF_NATIVE_EVENT_RISK event reports — the
* `reason` field of #pf_native_event_v1, mirroring
* `native_order::RiskLimitKind` (L9). */
typedef enum pf_native_risk_limit_e {
PF_NATIVE_RISK_MAX_DRAWDOWN = 0,
PF_NATIVE_RISK_MAX_INTRADAY_LOSS = 1,
PF_NATIVE_RISK_MAX_CONSECUTIVE_LOSS_DAYS = 2,
PF_NATIVE_RISK_MAX_FILLS_PER_DAY = 3
} pf_native_risk_limit_t;
/** Which day a risk limit's "day" is — `NativeRiskDay`. SESSION is the run's
* own session calendar (an overnight session is one day); CALENDAR_TIMEZONE
* is the civil date in the spec's scheduling timezone. */
typedef enum pf_native_risk_day_e {
PF_NATIVE_RISK_DAY_SESSION = 0,
PF_NATIVE_RISK_DAY_CALENDAR_TIMEZONE = 1
} pf_native_risk_day_t;
/** What a breach does — `NativeRiskAction`. BLOCK_OPENINGS refuses every
* opening while the block lasts and leaves the live book alone;
* FLATTEN_AND_BLOCK first closes the book with one kernel-originated
* Flatten. */
typedef enum pf_native_risk_action_e {
PF_NATIVE_RISK_BLOCK_OPENINGS = 0,
PF_NATIVE_RISK_FLATTEN_AND_BLOCK = 1
} pf_native_risk_action_t;
/** Remaining projection of a live request — `native_order::RemainingProjection`. */
typedef enum pf_native_remaining_e {
PF_NATIVE_REMAINING_UNBOUND = 0,
PF_NATIVE_REMAINING_FLATTEN_ALL = 1,
PF_NATIVE_REMAINING_UNITS = 2, /**< `remaining_units` is meaningful. */
PF_NATIVE_REMAINING_DEFERRED = 3,
PF_NATIVE_REMAINING_NO_TARGET = 4
} pf_native_remaining_t;
/** Trigger state of a live request — `native_order::TriggerState`. */
typedef enum pf_native_trigger_state_e {
PF_NATIVE_TRIGGER_STATE_MARKET_READY = 0,
PF_NATIVE_TRIGGER_STATE_LIMIT_READY = 1,
PF_NATIVE_TRIGGER_STATE_STOP_IDLE = 2,
PF_NATIVE_TRIGGER_STATE_STOP_ACTIVE = 3,
PF_NATIVE_TRIGGER_STATE_STOP_LIMIT_PENDING = 4,
PF_NATIVE_TRIGGER_STATE_STOP_LIMIT_LIVE = 5,
PF_NATIVE_TRIGGER_STATE_TRAIL_WAIT_ARM = 6,
PF_NATIVE_TRIGGER_STATE_TRAIL_TRACK = 7,
PF_NATIVE_TRIGGER_STATE_TRAIL_ACTIVE = 8
} pf_native_trigger_state_t;
/** What one execution costs — `NativeFeeKind`, the `fee_kind` word of
* #pf_native_run_spec_v1, charged at its `fee_value`. */
typedef enum pf_native_fee_kind_e {
PF_NATIVE_FEE_PERCENT = 0, /**< `fee_value` percent of |units| × price ×
* point value × account FX (the default). */
PF_NATIVE_FEE_CASH_PER_UNIT = 1, /**< `fee_value` account currency per unit. */
PF_NATIVE_FEE_CASH_PER_EXECUTION = 2 /**< `fee_value` account currency per execution. */
} pf_native_fee_kind_t;
/** When a request born at a script calculation may first match —
* `NativeCloseExecution`, the `close_execution` word of
* #pf_native_run_spec_v1. */
typedef enum pf_native_close_execution_e {
PF_NATIVE_CLOSE_EXECUTION_NEXT_ELIGIBLE_POINT = 0, /**< A later eligible point — the
* next modeled opening, an
* observed print or a carried
* open — never the bar's
* presented prices (the
* default). */
PF_NATIVE_CLOSE_EXECUTION_AFTER_CALCULATION = 1 /**< Also a modeled close point
* right after that
* calculation. */
} pf_native_close_execution_t;
/** Which opening directions the run admits — `NativeOpenDirections`, the
* `allowed_open_directions` word of #pf_native_run_spec_v1; BOTH is
* LONG | SHORT. A refused opening is a match rejection of the whole
* transaction, and a pure reduction stays legal under NONE. Zero is NOT the
* kernel's default here, unlike every other word these enumerations type: a
* zero-filled spec admits no opening at all. */
typedef enum pf_native_open_directions_e {
PF_NATIVE_OPEN_DIRECTIONS_NONE = 0,
PF_NATIVE_OPEN_DIRECTIONS_LONG = 1,
PF_NATIVE_OPEN_DIRECTIONS_SHORT = 2,
PF_NATIVE_OPEN_DIRECTIONS_BOTH = 3 /**< The kernel's default. */
} pf_native_open_directions_t;
/** Who records the per-script-bar report series — `NativeReportPolicy`, the
* `report_policy` word of #pf_native_run_spec_ext_v1. The kernel's third
* policy, `KernelRecordedAtHostMarks`, has no C value: under it the host
* names each report point itself, from inside its own callbacks, and the
* callback table carries no call that marks one — a C host could only
* declare a series nobody records. Its integer, 2, is PF_NATIVE_E_TAG like
* any other word outside this enumeration. */
typedef enum pf_native_report_policy_e {
PF_NATIVE_REPORT_HOST_RECORDED = 0, /**< The host's; the kernel appends no point
* (the default). */
PF_NATIVE_REPORT_KERNEL_RECORDED = 1 /**< One equity point per script calculation;
* `report_open_position_at_end` applies. */
} pf_native_report_policy_t;
/** A generic instrument price grid — `NativePriceGrid`, the `price_grid`
* word of #pf_native_run_spec_ext_v1. Both quantizing values need
* `price_tick > 0`. */
typedef enum pf_native_price_grid_e {
PF_NATIVE_PRICE_GRID_NONE = 0, /**< Every price booked as the
* path presents it (the
* default). */
PF_NATIVE_PRICE_GRID_QUANTIZE_FILLS = 1, /**< Each fill booked on the
* tick ladder. */
PF_NATIVE_PRICE_GRID_QUANTIZE_FILLS_AND_TRIGGERS = 2 /**< And each resting trigger
* tested against the
* quantized path. */
} pf_native_price_grid_t;
/** How a quantizing grid rounds — `NativeGridRounding`, the `grid_rounding`
* word of #pf_native_run_spec_ext_v1, read beside `price_grid`. */
typedef enum pf_native_grid_rounding_e {
PF_NATIVE_GRID_ROUNDING_HALF_UP = 0, /**< The nearest tick, ties away from zero
* (the default). */
PF_NATIVE_GRID_ROUNDING_DIRECTIONAL = 1 /**< Toward the region the order needs: a
* buy limit down and a sell limit up, a
* stop the other way, a market fill to
* its adverse side. */
} pf_native_grid_rounding_t;
/** When the kernel asks the host to calculate — `NativeCalculationTrigger`,
* the `calculation` word of #pf_native_run_spec_ext_v1. Each value is a
* strict superset of the one before it. */
typedef enum pf_native_calc_trigger_e {
PF_NATIVE_CALC_TRIGGER_BAR_CLOSE = 0, /**< Once per script bar, at its close
* (the default). */
PF_NATIVE_CALC_TRIGGER_BAR_CLOSE_AND_FILLS = 1, /**< And at each applied execution's
* cursor, bounded by
* `max_recalculations_per_point`. */
PF_NATIVE_CALC_TRIGGER_EVERY_MODELED_POINT = 2 /**< And at every modeled point and
* every observed print. */
} pf_native_calc_trigger_t;
/** What #pf_native_callbacks_v1::on_bar_open is handed — `NativeOpenBarView`,
* the `open_bar_view` word of #pf_native_run_spec_ext_v1. Neither value
* changes a match, a fill or any other callback. */
typedef enum pf_native_open_bar_view_e {
PF_NATIVE_OPEN_BAR_VIEW_COMPLETE = 0, /**< The whole script bar (the default). */
PF_NATIVE_OPEN_BAR_VIEW_OPEN_ONLY = 1 /**< Its lookahead masked: H = L = C = open,
* volume 0. */
} pf_native_open_bar_view_t;
/** Which units a kernel-issued liquidation reduces —
* `NativeLiquidationSizing`, the `margin_sizing` word of
* #pf_native_run_spec_ext_v1. Clamped to the position held;
* #pf_native_callbacks_v1::on_margin_call_units has the last word. */
typedef enum pf_native_liquidation_sizing_e {
PF_NATIVE_LIQUIDATION_SIZING_RESTORE_MINIMUM = 0, /**< The fewest units that restore
* the requirement at the sizing
* mark (the default). */
PF_NATIVE_LIQUIDATION_SIZING_SHORTFALL_MULTIPLE = 1, /**< That restore times
* `margin_shortfall_multiple`. */
PF_NATIVE_LIQUIDATION_SIZING_FLATTEN = 2 /**< The whole position. */
} pf_native_liquidation_sizing_t;
/** Which extension blocks of #pf_native_run_spec_ext_v1 are meaningful. */
typedef enum pf_native_spec_ext_mask_e {
PF_NATIVE_SPEC_EXT_REPORT = 1u << 0,
PF_NATIVE_SPEC_EXT_PRICE_GRID = 1u << 1,
PF_NATIVE_SPEC_EXT_CALCULATION = 1u << 2,
PF_NATIVE_SPEC_EXT_OPEN_BAR_VIEW = 1u << 3,
PF_NATIVE_SPEC_EXT_MARGIN = 1u << 4,
PF_NATIVE_SPEC_EXT_SUBSCRIPTIONS = 1u << 5,
/** L9's generic risk limits. Only a caller whose
* pf_native_run_spec_ext_v1 carries the risk tail may set this bit; a
* caller sending the base layout is refused with PF_NATIVE_E_STRUCT. */
PF_NATIVE_SPEC_EXT_RISK = 1u << 6,
/** The retained intrabar execution path. Needs the N8 tail. */
PF_NATIVE_SPEC_EXT_INTRABAR = 1u << 7,
/** The four feed-shape and presentation policies: slot labels, feed
* tolerance, the forced path order and abort reporting. Needs the N8
* tail. */
PF_NATIVE_SPEC_EXT_FEED_POLICY = 1u << 8,
/** The auxiliary finer feed. Only a caller whose
* pf_native_run_spec_ext_v1 carries the auxiliary tail may set this bit;
* a caller sending any earlier layout is refused with
* PF_NATIVE_E_STRUCT. */
PF_NATIVE_SPEC_EXT_AUXILIARY_FEED = 1u << 9,
/** What the run keeps of its event record (`event_retention`). Only a
* caller whose pf_native_run_spec_ext_v1 carries the retention tail may
* set this bit; a caller sending any earlier layout is refused with
* PF_NATIVE_E_STRUCT. Without it the run keeps
* #PF_NATIVE_EVENT_RETENTION_FULL. */
PF_NATIVE_SPEC_EXT_EVENT_RETENTION = 1u << 10,
/** The settlement's quantity tolerance (`quantity_tolerance`). Only a
* caller whose pf_native_run_spec_ext_v1 carries the tolerance tail may
* set this bit; a caller sending any earlier layout is refused with
* PF_NATIVE_E_STRUCT. Without it the settlement stays exact. */
PF_NATIVE_SPEC_EXT_QUANTITY_TOLERANCE = 1u << 11
} pf_native_spec_ext_mask_t;
/** What a run keeps of its event record — `NativeRunSpec::event_retention`,
* the `event_retention` word of #pf_native_run_spec_ext_v1, read under
* #PF_NATIVE_SPEC_EXT_EVENT_RETENTION.
*
* WINDOW keeps the command journal only until the host has read it: a host
* that polls #strategy_native_events_v1 acknowledges what it has read
* (#strategy_native_acknowledge_events_v1) and the kernel drops the
* acknowledged events at the next script-bar boundary, while a host that
* never acknowledges is served by its callbacks alone and its window closes
* at every script-bar end. No driver point and no account row is kept.
* COMMANDS keeps the whole command journal and every account row, and no
* driver point. FULL keeps everything, O(run) in memory.
*
* A C host that does not set the bit -- every caller of
* #strategy_configure_native_v1, and every caller of an earlier
* pf_native_run_spec_ext_v1 layout -- runs under FULL, the record its
* layout was published with, so reading a whole run's events after it has
* ended keeps working unchanged. The C++ default is WINDOW. */
typedef enum pf_native_event_retention_e {
PF_NATIVE_EVENT_RETENTION_WINDOW = 0, /**< The unread journal only. */
PF_NATIVE_EVENT_RETENTION_FULL = 1, /**< Journal, driver points, account rows. */
PF_NATIVE_EVENT_RETENTION_COMMANDS = 2 /**< Journal and account rows. */
} pf_native_event_retention_t;
/** The bars a declared series is built from — `NativeSeriesSource`. */
typedef enum pf_native_series_source_e {
PF_NATIVE_SERIES_SOURCE_INPUT = 0, /**< The accepted input (the default). */
PF_NATIVE_SERIES_SOURCE_AUXILIARY_FEED = 1 /**< The run's auxiliary finer feed. */
} pf_native_series_source_t;
/** When a declared series delivers a completed bucket —
* `NativeTimeframeSubscription::lookahead`, the `lookahead` word of
* #pf_native_subscription_v1. AT_FIRST_INPUT resolves the historical input
* ahead; a stream's live inputs have nothing ahead to resolve, so under
* either value they deliver each bucket at its completion. */
typedef enum pf_native_lookahead_e {
PF_NATIVE_LOOKAHEAD_AT_COMPLETION = 0, /**< On the input that completes the
* bucket (the default). */
PF_NATIVE_LOOKAHEAD_AT_FIRST_INPUT = 1 /**< The bucket's final values, on its
* first contributing input. */
} pf_native_lookahead_t;
/** What a declared series holds on an accepted input that delivers no bucket
* of it — `NativeTimeframeSubscription::gaps`, the `gaps` word of
* #pf_native_subscription_v1. Neither value changes which buckets complete,
* when they are delivered or what they contain. */
typedef enum pf_native_gaps_e {
PF_NATIVE_GAPS_HOLD = 0, /**< The last delivered bucket, until the next
* delivery replaces it (the default). */
PF_NATIVE_GAPS_CLEAR = 1 /**< Nothing: #strategy_native_series_bar_v1
* answers #PF_NATIVE_ABSENT on that input. */
} pf_native_gaps_t;
/** WHICH price a kernel-sized basis converts at — `native_order::SizePrice`
* (L3b). RESOLVED is the established behaviour: the price the kernel would
* otherwise settle at. SIGNAL is the decision-point price at placement,
* carried to the expected fill by the side's slippage and rounded onto the
* run's fill grid. SIGNAL_ON_TICK is that same rule measured on the
* INSTRUMENT's own tick ladder (`price_tick`) instead of the fill grid,
* rounded before the slippage as well as after. */
typedef enum pf_native_size_price_e {
PF_NATIVE_SIZE_PRICE_RESOLVED = 0,
PF_NATIVE_SIZE_PRICE_SIGNAL = 1,
PF_NATIVE_SIZE_PRICE_SIGNAL_ON_TICK = 2
} pf_native_size_price_t;
/** WHICH measurement of the bound scope a fractional reduce takes its
* fraction of — `native_order::ScopeBasis`. AT_MATCH reads the scope as it
* stands at the matching candidate. AT_ACCEPTANCE freezes the scope SIZE
* when the request is accepted, so two 50 % siblings on one 10-unit lot both
* claim 5 under GROSS even after the first has executed. */
typedef enum pf_native_scope_basis_e {
PF_NATIVE_SCOPE_BASIS_AT_MATCH = 0,
PF_NATIVE_SCOPE_BASIS_AT_ACCEPTANCE = 1
} pf_native_scope_basis_t;
/** When the kernel tests the maintenance requirement —
* `NativeLiquidationCheck`, the `margin_check` field of
* #pf_native_run_spec_ext_v1. */
typedef enum pf_native_liquidation_check_e {
PF_NATIVE_LIQUIDATION_PATH_ADVERSE_EXTREME = 0, /**< Solve and rest at the level. */
PF_NATIVE_LIQUIDATION_CALCULATION_ONLY = 1, /**< Test the mark; rest nothing. */
PF_NATIVE_LIQUIDATION_PATH_ADVERSE_EXTREME_MARK = 2 /**< Rest AT the adverse mark. */
} pf_native_liquidation_check_t;
/** Which equity the maintenance requirement is tested against —
* `NativeMarginEquityBasis`. */
typedef enum pf_native_margin_equity_basis_e {
PF_NATIVE_MARGIN_EQUITY_MARKED = 0,
PF_NATIVE_MARGIN_EQUITY_BEFORE_OPEN_COMMISSION = 1
} pf_native_margin_equity_basis_t;
/** Which base the liquidation level is solved from —
* `NativeLiquidationLevelBase`. */
typedef enum pf_native_margin_level_base_e {
PF_NATIVE_MARGIN_LEVEL_MARKED_EQUITY = 0,
PF_NATIVE_MARGIN_LEVEL_REALIZED_ONLY = 1
} pf_native_margin_level_base_t;
/** Which intrabar execution path the run retains — the alternative of
* `IntrabarPath`. NONE is the whole default surface. LOWER_TF retains the
* caller's own finer bars (and is the one mode that delivers
* #pf_native_callbacks_v1::on_sub_bar). SYNTHESIZED samples each script
* bar's own OHLC path through the generic sampler and retains no feed. */
typedef enum pf_native_intrabar_kind_e {
PF_NATIVE_INTRABAR_NONE = 0,
PF_NATIVE_INTRABAR_LOWER_TF = 1,
PF_NATIVE_INTRABAR_SYNTHESIZED = 2
} pf_native_intrabar_kind_t;
/** Whether matching stays continuous between generated samples —
* `IntrabarPath::SampleEligibility`. LOWER_TF only; a synthesized path's
* point-only eligibility is inherent to that mode. */
typedef enum pf_native_sample_eligibility_e {
PF_NATIVE_SAMPLE_CONTINUOUS_SEGMENTS = 0,
PF_NATIVE_SAMPLE_DISTRIBUTION_SAMPLES = 1
} pf_native_sample_eligibility_t;
/** Whether a confirmed bar must name a canonical input slot —
* `NativeSlotLabelPolicy`. A feed-shape policy, not a source-language one;
* the two modes never share a continuation. */
typedef enum pf_native_slot_label_e {
PF_NATIVE_SLOT_LABEL_CANONICAL = 0,
PF_NATIVE_SLOT_LABEL_FEED_TOLERANT = 1
} pf_native_slot_label_t;
/** Opt-in admission exceptions for a tolerated input-feed shape —
* `NativeFeedTolerance`. A BIT MASK, not an enumerator: the values combine,
* and any bit outside this set is PF_NATIVE_E_TAG. */
typedef enum pf_native_feed_tolerance_e {
PF_NATIVE_FEED_TOLERANCE_NONE = 0,
/** Finite OHLC need not be positive; NaN volume means unavailable. */
PF_NATIVE_FEED_TOLERANCE_BATCH_STRUCTURAL = 1u << 0,
/** Stream warmups admit finite, non-negative interim OHLC. */
PF_NATIVE_FEED_TOLERANCE_WARMUP_NONNEGATIVE = 1u << 1
} pf_native_feed_tolerance_t;
/** Generic ordering for a modeled OHLC path — `NativePathOrder`. AUTO keeps
* the open-proximity rule; the forced modes make the first excursion
* explicit for replay and live hosts. */
typedef enum pf_native_path_order_e {
PF_NATIVE_PATH_ORDER_AUTO = 0,
PF_NATIVE_PATH_ORDER_HIGH_FIRST = 1,
PF_NATIVE_PATH_ORDER_LOW_FIRST = 2
} pf_native_path_order_t;
/** How a cooperative abort is presented — `NativeAbortReporting`. */
typedef enum pf_native_abort_reporting_e {
PF_NATIVE_ABORT_ERROR = 0,
PF_NATIVE_ABORT_QUIET = 1
} pf_native_abort_reporting_t;
/** Why the kernel is asking the host to calculate — `NativeCalculationReason`
* (L5), the `reason` argument of #pf_native_callbacks_v1::on_recalculate.
* SUB_BAR is reserved and never delivered there: a lower-timeframe sub-bar
* has its own hook, #pf_native_callbacks_v1::on_sub_bar. */
typedef enum pf_native_calc_reason_e {
PF_NATIVE_CALC_BAR_CLOSE = 0, /**< The script bar's own calculation; `cause` NULL. */
PF_NATIVE_CALC_ORDER_FILL = 1, /**< At an applied execution's cursor; `cause` is it. */
PF_NATIVE_CALC_TICK = 2, /**< At a modeled point or print; `cause` NULL. */
PF_NATIVE_CALC_SUB_BAR = 3 /**< Reserved; see on_sub_bar. */
} pf_native_calc_reason_t;
/** Which kernel check point is about to test the maintenance requirement —
* `NativeMarginCheckKind` (L4b). These are the kernel's own points; a broker
* model that checks somewhere else is host policy, expressed by suppressing
* the points it does not share. */
typedef enum pf_native_margin_check_kind_e {
PF_NATIVE_MARGIN_CHECK_BAR_OPEN = 0, /**< The script bar's open. */
PF_NATIVE_MARGIN_CHECK_AFTER_APPLIED = 1, /**< The re-arm after a point's fills. */
PF_NATIVE_MARGIN_CHECK_CALCULATION = 2, /**< A CalculationOnly model's calculation. */
PF_NATIVE_MARGIN_CHECK_FX_ROLL = 3, /**< A step of the run's declared
* #pf_native_fx_curve_v1: the first point
* the account converts at a new rate,
* offered immediately before that point is
* matched. A run that declares no curve has
* none, and a CalculationOnly model, which
* measures at its calculation alone, is not
* offered it. */
PF_NATIVE_MARGIN_CHECK_INTRABAR_SAMPLE = 4 /**< A delivered sample, after the
* script bar's first, of a
* #PF_NATIVE_INTRABAR_LOWER_TF path matched as
* continuous segments, measured at its own
* price immediately before it is matched. A
* one-price distribution path and a
* CalculationOnly model are not offered it. */
} pf_native_margin_check_kind_t;
/** What an ANSWERING callback's return value means.
*
* The four answering hooks of #pf_native_callbacks_v1 do not report success:
* their return value selects WHOSE answer the kernel uses, so every value is
* in contract and an answering hook can never fail the run. A host that
* needs to abort does it from an observation callback, which keeps the
* "non-zero ends the run Failed" rule exactly where it already was. */
typedef enum pf_native_answer_e {
PF_NATIVE_ANSWER_DEFAULT = 0, /**< Keep the kernel's own; the output is ignored. */
PF_NATIVE_ANSWER_PROVIDED = 1 /**< Use the output. Any non-zero value means this. */
} pf_native_answer_t;
/** Where an opened lot's own fill sits on its entry bar's modeled path —
* `OpenedLotFillPoint`, the one fact
* #strategy_native_declare_opened_lot_entry_bar_mask_v1 carries. ON_PATH is
* a fill at a price the path reaches: the kernel derives which end of the
* bar, if either, the path had already reached before it. AFTER_PATH is a
* fill at the bar's closing point, after the whole path: both ends precede
* it. */
typedef enum pf_native_opened_lot_fill_point_e {
PF_NATIVE_OPENED_LOT_FILL_POINT_ON_PATH = 0,
PF_NATIVE_OPENED_LOT_FILL_POINT_AFTER_PATH = 1
} pf_native_opened_lot_fill_point_t;
/* ── The readout words ─────────────────────────────────────────────
* Every enumeration below names a word the runtime WRITES for a C host: a
* field of a struct it fills or presents, an event's reason, a callback
* argument or an out-parameter. The fields stay the integer words they were
* published as, so no layout moves; each value is written by an exhaustive
* translation of its kernel enumeration, and a kernel value no enumeration
* here names cannot build (src/native_c_host.cpp). */
/** Where a point's price came from — `NativePriceProvenance`: the
* `provenance` word of #pf_native_decision_v1 and #pf_native_event_v1 and
* #pf_native_margin_view_v1::cursor_provenance. */
typedef enum pf_native_price_provenance_e {
PF_NATIVE_PROVENANCE_CONFIRMED = 0, /**< A confirmed input bar's own label,
* or a point on its modeled path. */
PF_NATIVE_PROVENANCE_OBSERVED_PRINT = 1, /**< A realtime print. */
PF_NATIVE_PROVENANCE_MODELED_OHLC_OPEN = 2, /**< A modeled path's opening point. */
PF_NATIVE_PROVENANCE_MODELED_OHLC_CLOSE = 3, /**< A modeled path's closing point. */
PF_NATIVE_PROVENANCE_CARRIED_OPEN = 4, /**< A quiet tradable interval's carried
* last price. */
PF_NATIVE_PROVENANCE_AFTER_CALCULATION_CLOSE = 5, /**< The close point right after a
* calculation. */
PF_NATIVE_PROVENANCE_PARTIAL_FINALIZED = 6, /**< A partially finalized observed slot. */
PF_NATIVE_PROVENANCE_CALCULATION = 7, /**< The script calculation point itself. */
PF_NATIVE_PROVENANCE_CURRENT_EXECUTION = 8 /**< A synchronous
* #strategy_native_execute_current_v1. */
} pf_native_price_provenance_t;