142 return static_cast<std::uint8_t
>(kind);
172 bool cause,
bool recipient,
bool cursor)
noexcept {
174 (cause ? 1u : 0u) | (recipient ? 2u : 0u) | (cursor ? 4u : 0u));
181 if (ordinal == 0)
return context;
190 if (incarnation == 0)
return context;
213 bool has_cause =
false;
214 bool has_recipient =
false;
215 bool has_cursor =
false;
216 if (cause !=
nullptr && cause->ordinal != 0 && cause->run == run) {
220 if (recipient !=
nullptr && recipient->incarnation != 0 && recipient->run == run) {
221 has_recipient =
true;
224 if (cursor !=
nullptr) {
264 return failed.spec ? &failed.spec->identity :
nullptr;
267static_assert(std::is_trivially_copyable_v<NativeInRunCause>);
268static_assert(std::is_trivially_copyable_v<NativeInRunRecipient>);
269static_assert(std::is_trivially_copyable_v<NativeInRunCursor>);
270static_assert(std::is_trivially_copyable_v<NativeFailureContext>);
271static_assert(std::is_trivially_copyable_v<NativeFailure>);
272static_assert(std::is_nothrow_copy_constructible_v<NativeFailure>);
273static_assert(std::is_nothrow_copy_assignable_v<NativeFailure>);
274static_assert(std::is_nothrow_move_constructible_v<NativeFailed>);
275static_assert(std::is_nothrow_move_assignable_v<NativeFailed>);
340 double mark = std::numeric_limits<double>::quiet_NaN();
360 double mark = std::numeric_limits<double>::quiet_NaN();
393 std::optional<native_order::CommandEvent>
command;
395 std::optional<NativeAccountObservation>
account;
489 native_order::NativeCandidatePriceKind::PointPrice;
665 std::optional<native_order::RiskLimitKind>
reason;
857#define PINEFORGE_HAS_NATIVE_STRATEGY_HOST_V19 1
969 return {facts.default_resolved_price, std::nullopt,
970 native_order::OpeningShape::Transact};
1017 return std::nullopt;
1034 return std::nullopt;
1157 std::vector<NativeTimeframeSubscription> subscriptions);
1166 std::vector<NativeTimeframeSubscription> subscriptions);
1345 double equity,
double fx)
const;
BacktestEngine(NativeConsumerBindTag)
virtual bool margin_check_allowed(const NativeMarginCheckPoint &) const
Consulted at each kernel check point before anything is evaluated.
native_order::ReplaceResult replace_market(const native_order::RequestHandle &target, const native_order::Request &request)
The same market-default convenience for a replace; see submit_market.
detail::ScratchStatus visit_native_open_lots(double mark, void *, bool(*)(void *, const NativeOpenLotView &)) const
native_order::CohortHandle cohort_open()
Open a roster a later close can bind to.
detail::ScratchStatus visit_native_open_lot_values(void *, bool(*)(void *, std::uint64_t, double, double)) const
virtual void on_native_tick(const Bar &, const NativeTickContext &)
Called once for every accepted realtime print, before matching at that point.
virtual bool owns_lot_excursions() const noexcept
RULING A48 — the ONE generic per-lot excursion capability.
~NativeStrategyHost() override
NativeStateView native_state() const
The whole run state as one owning read.
std::optional< Bar > native_series_bar(std::size_t subscription) const
The latest completed bucket delivered for a declared subscription, or nullopt before its first delive...
virtual void on_native_bar_open(const Bar &, const NativeDecisionContext &)
Precedes the matching pass at the script bar's open decision point.
std::optional< Bar > current_partial_bar() const
The bar so far, folded from the path points this script bar has already consumed: open of its first p...
std::uint64_t native_recalculation_count() const
How many recalculations the kernel has driven this run, and how many it suppressed because a point ha...
virtual void on_native_margin_call(const native_order::MarginCallEvent &)
A kernel-issued liquidation that filled.
virtual ClosedLotExcursion closed_lot_excursion(const ClosedLotExcursionFacts &) const
The per-lot excursion a host owns, consulted for every closing row once owns_lot_excursions() answers...
uint64_t native_event_window_start() const
The oldest ordinal a read can still return: every command event at or above it is retained,...
void declare_native_bar_open_hook(bool implemented)
Which of two optional hooks this host implements (R5 lane D2-A).
virtual std::optional< double > resolve_anchored_level(const NativeAnchoredLevelView &) const
The level an anchored leg (FromOwnerFill) is about to be armed at, offered to the host exactly once p...
NativeCurrentExecutionResult execute_current(const NativeCurrentExecution &)
Consume, synchronously, a request accepted or replaced in this very callback.
NativeStrategyHost(const NativeStrategyHost &)=delete
std::vector< NativeWorkingRequest > native_working_requests() const
Working-book snapshot and bulk cancellation.
std::optional< NativeCurrentPointView > current_execution_point() const
The active callback's quote and calendar-derived decision context, as an owning value.
NativeRiskState native_risk_state() const
The run's generic risk ledger.
std::optional< double > native_liquidation_price() const
The price at which the marked equity falls below the run's maintenance requirement for the live posit...
native_order::ReplaceResult replace(const native_order::RequestHandle &target, const native_order::Request &request, native_order::ReplaceOptions options)
Replace with options.
virtual void on_native_bar(const Bar &bar, const NativeDecisionContext &context)=0
The current decision point remains valid for the complete callback.
virtual void on_native_timeframe_bar(const Bar &, const NativeTimeframeBarContext &)
One completed bucket of a declared higher-timeframe subscription, delivered on an accepted input bar ...
int64_t native_decision_floor() const
The run's monotonic decision floor in epoch milliseconds — the same value NativeStateView::decision_f...
std::size_t cancel_all()
Withdraw every live request, dependants of a cancelled owner included, and answer how many left the b...
NativeFxCurveSetupResult configure_native_fx_curve(const NativeFxCurve &curve)
Stage the run's immutable FX epoch, legal only while Ready.
friend class NativeExecutionConsumer
NativeCurrentExecutionPreview inspect_current_execution(const NativeCurrentExecution &) const
A read-only preview of a current execution: the settlement readiness, any typed refusal or terms outc...
virtual void on_native_applied(const native_order::ExecutionAppliedEvent &, const NativeDecisionContext &)
The calculate-on-fill hook: offered once per applied execution, FIFO, after the account record and th...
virtual void on_native_run_begin()
Offered once per successful begin, after the reset and before any bar.
virtual void prepare_native_begin(const NativeBeginArgs &)
Offered once per begin, before the run starts, with the begin's own arguments — the bars,...
double native_marked_equity(double mark) const
The account's equity marked at this price: the realized balance plus every open lot's own fee-net ter...
bool append_auxiliary_bars(const Bar *bars, std::size_t n)
A realtime stream's later bars of its declared auxiliary feed.
NativePhysicalPosition physical_position() const
The book as one aggregate, copied out.
bool native_aggregates_input_bars() const
Whether the configured run's script bars are buckets the kernel gathers from its input bars – native_...
NativeSetupResult declare_timeframe_subscriptions_result(std::vector< NativeTimeframeSubscription > subscriptions)
The same call, answered the way configure_native answers the identical validation: Applied,...
std::size_t cancel_where(std::string_view text, NativeRequestField field)
The same predicate over either identity text.
NativeSetupResult configure_native(const NativeRunSpec &spec)
The only setup call.
std::size_t cancel_where(std::string_view comment)
Withdraw exactly the live requests carrying this comment, and answer how many of those left the book.
native_order::ReplaceResult replace(const native_order::RequestHandle &target, const native_order::Request &request)
Replace one live request: validate first, then retire that incarnation and birth a successor with a n...
NativeStrategyHost & operator=(NativeStrategyHost &&)=delete
native_order::SubmitResult submit(const native_order::Request &request)
Accept one complete request.
uint64_t native_consumed_high_water() const
The highest run_number this host has consumed.
void on_bar(const Bar &bar) final
The engine's own bar entry, taken over by the native consumer and sealed.
bool declare_timeframe_subscriptions(std::vector< NativeTimeframeSubscription > subscriptions)
Declare this run's higher-timeframe series from inside on_native_run_begin, for a host whose series a...
void native_closed_rows_amended(std::size_t first_row)
The closed rows (the engine's trades_) are part of broker_state_hash(), folded once each through a ru...
std::vector< NativeOpenLot > native_open_lots(double mark) const
The book lot by lot, oldest first, marked at mark: one NativeOpenLot per physical lot (physical_posit...
virtual std::optional< NativeMarginDecision > resolve_margin_requirement(const NativeMarginRequirementView &) const
Consulted at EVERY kernel check point, BEFORE the breach test, exactly as resolve_execution_terms is ...
NativeStrategyHost & operator=(const NativeStrategyHost &)=delete
uint64_t native_continuation_hash() const
The consumer's continuation identity: what a stream resumes against.
virtual void on_native_sub_bar(const Bar &sub, const NativeDecisionContext &ctx)
One completed lower-timeframe sub-bar of an IntrabarPath::lower_tf path, delivered after that sub-bar...
detail::ScratchStatus visit_native_working_requests(void *, bool(*)(void *, const NativeWorkingRequest &)) const
Live-order reads, owning accessor's visibility; spilled rows may allocate and do scratch I/O.
void native_acknowledge_events(uint64_t through_ordinal)
The host has read every event through through_ordinal (R5 lane V19-B).
std::vector< NativeMarketEvent > native_events(uint64_t after_ordinal) const
Owning snapshots copied at query time.
bool declare_auxiliary_feed(std::optional< NativeAuxiliaryFeed > feed)
The same begin-time hook for NativeRunSpec::auxiliary_feed: the feed REPLACES the staged spec's own (...
void declare_native_precommit_hook(bool implemented)
declare_native_precommit_hook(false): validate_execution_precommit is the default admission,...
void cohort_remove(native_order::CohortHandle cohort, native_order::RequestHandle origin)
Take one opening back off a roster.
std::uint64_t native_recalculations_skipped() const
How many recalculations max_recalculations_per_point dropped at their matching point.
std::optional< double > native_sized_units(const native_order::Sized &sized, double price, double equity, double fx) const
The units a kernel-sized intent resolves to under this run's spec at a sizing price,...
virtual std::optional< double > resolve_margin_call_units(const NativeMarginCallView &) const
The kernel's own liquidation sizing, offered to the host before the reduction rests.
std::uint64_t broker_state_hash_projection() const override
virtual void on_native_input(const Bar &, const NativeInputContext &)
Called once for every accepted confirmed input bar, before that bar is aggregated or matched.
bool report_presenter_supports_non_full() const noexcept override
virtual native_order::ExecutionTerms resolve_execution_terms(const NativeExecutionTermsFacts &facts) const
The fill-terms hook, consulted at every matching candidate.
virtual NativePrecommitVerdict validate_execution_precommit(const NativePrecommitView &) const
The last gate before a physical effect, offered once per Applied-ready attempt and never during inspe...
virtual void on_native_recalculate(const Bar &bar, const NativeDecisionContext &ctx, NativeCalculationReason reason, const native_order::ExecutionAppliedEvent *cause)
EVERY calculation of the run arrives here first, including the script bar's own close calculation (re...
NativeAuxiliaryAppendResult append_auxiliary_bars_result(const Bar *bars, std::size_t n)
The same call, answering NativeAuxiliaryAppendError and the bar of this call it stopped on.
void native_visit_open_lots(double mark, void *, void(*)(void *, const NativeOpenLotView &)) const
std::optional< NativeWorkingRequest > native_working_request(const native_order::RequestHandle &) const
NativeStrategyHost(NativeStrategyHost &&)=delete
bool mark_native_report_point(int64_t report_ts)
Append one kernel-owned equity point at this host's report mark.
native_order::SubmitResult submit_market(const native_order::Request &request)
The deliberately narrow market-default convenience: the same acceptance path as submit,...
std::optional< NativeTrailState > trail_state(const native_order::RequestHandle &target) const
Where one live trail's own trigger has reached: activated, the running best, the current level and th...
void cohort_add(native_order::CohortHandle cohort, native_order::RequestHandle origin)
Enroll one accepted opening's handle in a roster.
void native_visit_working_requests(void *, void(*)(void *, const NativeWorkingRequest &)) const
NativeSetupResult declare_auxiliary_feed_result(std::optional< NativeAuxiliaryFeed > feed)
The same call, answered the way configure_native answers the identical validation: Applied,...
native_order::CancelResult cancel(const native_order::RequestHandle &target)
Cancel one live request by handle.
constexpr bool native_failure_has_recipient(NativeFailureContextKind kind) noexcept
Whether a context of this kind populates its NativeInRunRecipient.
NativeFailureContext native_failure_recipient(std::uint64_t incarnation) noexcept
A context carrying one addressed request incarnation.
NativeFailureOperation
Which operation was in flight when the failure latched — the second half of "what went wrong",...
NativeCompletion
How a Completed run ended: a batch reached the last bar, or a stream was ended.
constexpr std::uint8_t native_failure_context_bits(NativeFailureContextKind kind) noexcept
The bit-union under NativeFailureContextKind: Cause=1, Recipient=2, Cursor=4.
NativeFailureContext native_failure_cause(std::uint64_t ordinal) noexcept
A context carrying one causing event ordinal.
NativeRunPhase
Which driving is Running: a batch run(), a stream's internal warmup, or its realtime leg.
NativeFailureContextKind
In-run failure references.
NativeEventKind
Which of NativeMarketEvent's three alternatives is populated.
std::variant< NativeUnconfigured, NativeReady, NativeRunning, NativeCompleted, NativeFailed > NativeLifecycle
The lifecycle as one value. Exhaustive over the five alternatives above.
constexpr bool native_failure_has_cursor(NativeFailureContextKind kind) noexcept
Whether a context of this kind populates its NativeInRunCursor.
NativeFailureCode
The durable first failure of a run, in NativeFailure::code.
NativeCurrentQuoteKind
Where a price came from: the callback's own market decision point, or the execution it is anchored to...
NativeFailureContext native_failure_cursor(NativeCoordinate point, double t=0.0) noexcept
A context carrying one path cursor.
constexpr NativeFailureContextKind native_failure_context_kind(bool cause, bool recipient, bool cursor) noexcept
The kind that says exactly these three alternatives are populated.
NativeFailureContext native_failure_context_in_run(const native_order::RunIdentity &run, const native_order::EventId *cause, const native_order::RequestHandle *recipient, const native_order::MatchCursor *cursor) noexcept
Copies only ordinals/incarnation/cursor scalars.
NativeAnchoredTrigger
Which trigger of an anchored leg the owner's fill is about to supply.
const native_order::RunIdentity * native_failed_run_identity(const NativeFailed &failed) noexcept
The RunIdentity the failed spec carried, or nullptr when configure failed before staging one.
NativeSetupStatus
Whether a setup call applied its value or refused it.
NativeCalculationReason
Why the kernel is asking the host to calculate.
NativeCurrentPriceRule
Which price a current execution settles at: the active callback's quote as presented,...
NativeAuxiliaryAppendError
Why append_auxiliary_bars refused.
@ NoAuxiliaryFeed
The run declared no auxiliary feed, in its spec or at begin.
@ InvalidBarArray
A null array with a non-zero count.
@ NotRealtime
The run is not on its realtime leg (a batch, or a stream still in warmup).
@ Reentrant
Called from inside a callback or an in-flight input.
@ UnorderedBars
index is a bar that is not strictly after its predecessor — the one before it in this call,...
@ HostFailed
The host had already failed; nothing was read.
@ InvalidBar
index is a bar native_bar_structurally_valid refuses.
@ InputPeriodAlreadyAccepted
The first bar opened inside an input period the run has already accepted.
@ AllocationFailure
Growing the appended-bar store threw. This one DOES fail the host.
NativeCurrentRefusal
Why a current-execution command cannot be consumed here.
std::variant< NativeCurrentRefusal, native_order::ExecutionAppliedEvent, native_order::NoEffectEvent, native_order::MatchRejectedEvent, native_order::CancelledEvent > NativeCurrentExecutionResult
What execute_current answers: a refusal, or the applied outcome.
NativePrecommitVerdict
The host is consulted before generic opening-margin admission.
NativeMarginCheckKind
Which kernel check point is about to test the maintenance requirement.
NativeRequestField
Which of a request's two free-text identity fields a bulk predicate reads.
NativeLifecycleKind
Where a host stands.
constexpr bool native_failure_has_cause(NativeFailureContextKind kind) noexcept
Whether a context of this kind populates its NativeInRunCause.
NativeCompletionKind
How a script interval or a higher-timeframe bucket was closed.
std::shared_ptr< const RequestDefinition > DefinitionRef
std::variant< AllowanceUnset, AllowanceUnits, AllowanceAllScope, AllowanceDeferred > Allowance
std::variant< execution::Book, execution::OpeningExposure, SelectedExposure > ExecutionScope
What one execution acted on: the whole book, one opening's exposure, or a bound selection.
NativeCandidatePriceKind
Which price a candidate is being offered at: the point's own price, or the request's trigger level (a...
std::variant< RemainingUnbound, RemainingFlattenAll, RemainingUnits, RemainingDeferred, NoTarget > Remaining
std::variant< RemainingProjectionUnbound, RemainingProjectionFlattenAll, RemainingProjectionUnits, RemainingProjectionDeferred, RemainingProjectionNoTarget > RemainingProjection
std::variant< execution::Flatten, order_action::Reduce, order_action::Transact, execution::ReverseTo > ExecutionPlan
The settlement shape one execution takes.
std::variant< MarketReady, LimitReady, StopIdle, StopActive, StopLimitPending, StopLimitLive, TrailWaitArm, TrailTrack, TrailActive > TriggerState
std::unordered_map< std::string, std::string > InputsMap
The account row that follows an applied execution in the event history: the shared ordinal,...
int64_t effective_time_ms
Ephemeral read-only facts of one anchored-leg materialization (L7b), offered to the host exactly once...
NativeAnchoredTrigger trigger
native_order::RequestHandle owner
native_order::Side leg_side
std::uint64_t owner_applied_ordinal
native_order::RequestHandle leg
std::uint64_t owner_lot_incarnation
native_order::MatchCursor owner_cursor
What append_auxiliary_bars_result answers: the status, the refusal by name, and which bar OF THIS CAL...
NativeAuxiliaryAppendError error
Borrowed begin-call facts.
MagnifierDistribution magnifier_distribution
const void * overrides_opaque
int magnifier_volume_weighted_min_samples
int magnifier_volume_weighted_max_samples
bool simple_run
Which public overload began the run: the bare run(bars, n) lifecycle (true) or a timeframe-aware / ma...
const SymInfo * syminfo
The rich run overload's symbol metadata is borrowed only for this callback.
bool magnifier_volume_weighted
NativeCompletion completion
Recomputed observations, never an apply token.
execution::AccountEffectProjection account
std::optional< execution::Status > settlement_readiness
std::optional< NativeCurrentRefusal > refusal
std::optional< native_order::MatchRejectReason > terms_rejection
std::vector< double > closed_row_pnl
std::optional< native_order::CancelReason > terms_cancellation
A synchronous execution of one request accepted or replaced in this very callback: a target handle an...
NativeCurrentPriceRule price_rule
native_order::RequestHandle target
What current_execution_point() answers inside a callback: the point's decision context,...
std::uint64_t quote_origin_ordinal
NativeDecisionContext decision
NativeCurrentQuoteKind quote_kind
Read-only owning-value facts for one candidate.
native_order::MatchCursor cursor
bool shared_cursor_collision
A retained crossing can share a rounded cursor quote with another request's level.
native_order::Remaining remaining
native_order::RequestHandle target
double pending_group_deduction
native_order::DefinitionRef definition
double default_resolved_price
std::int64_t fx_effective_time_ms
NativeCurrentPriceRule price_rule
double scope_exposure_units
native_order::ExecutionScope scope
double opposite_book_units
NativeCurrentQuoteKind quote_kind
native_order::Allowance allowance
native_order::DriverEligibilityClass driver_class
native_order::NativeCandidatePriceKind price_kind
native_order::TriggerState trigger_state
NativePhysicalPosition position
std::optional< double > trigger_level
std::optional< NativeRunSpec > spec
The three in-run facts a failure may carry, tagged by kind.
NativeInRunRecipient recipient
NativeFailureContextKind kind
The durable record native_state().failure answers: the code, the operation it happened in,...
std::uint32_t discriminator
NativeFailureContext context
NativeFailureOperation operation
What configure_native_fx_curve answers: the status and, on refusal, the curve validation with the ind...
NativeFxCurveValidation validation
The event ordinal a failure was caused by, 0 when absent.
Where on the modeled path a failure happened: the driver point's coordinate and its interpolation pos...
The request incarnation a failure was addressed to, 0 when absent.
std::uint64_t incarnation
Accepted input facts presented before the generic consumer aggregates the bar into its script interva...
bool completes_script_interval
native_calendar::NativeInterval script_interval
native_calendar::NativeInterval input_interval
Ephemeral factual view of one kernel-issued liquidation before its units are fixed.
NativePhysicalPosition position
native_order::MatchCursor cursor
Ephemeral factual view of one kernel check point, offered to the host before the check runs.
NativeMarginCheckKind kind
NativePhysicalPosition position
bool liquidation_resting
Whether the model already holds a liquidation resting from an earlier admitted point.
native_order::MatchCursor cursor
The host's answer to one requirement view.
Ephemeral factual view of the numbers the kernel is about to compare, at one check point,...
NativePhysicalPosition position
NativeMarginCheckKind kind
native_order::MatchCursor cursor
One owning row of native_events(after_ordinal): a command event, a driver point or an account observa...
std::optional< NativeAccountObservation > account
std::optional< native_order::CommandEvent > command
std::optional< NativeDriverPoint > driver
Callback-local view of the same FIFO row.
std::int64_t entry_time_ms
std::string_view entry_comment
std::string_view entry_label
std::uint64_t entry_incarnation
double favorable_excursion
Owning value row for one open physical lot, copied at query time by native_open_lots(mark) — the lot-...
std::int64_t entry_time_ms
double favorable_excursion
std::uint64_t entry_incarnation
std::string entry_comment
The book as one aggregate: signed units, the volume-weighted average entry price and the number of op...
Ephemeral factual view of one prepared execution before any physical effect.
native_order::ExecutionScope scope
execution::Status settlement_readiness
execution::AccountEffectProjection account
native_order::DefinitionRef definition
double inspected_current_ticket
native_order::MatchCursor cursor
native_order::RequestHandle target
native_order::ExecutionPlan plan
double inspected_opened_units
std::vector< double > closed_row_pnl
double inspected_closed_units
The run's generic risk ledger (L9), as the kernel holds it.
std::uint32_t consecutive_loss_days
std::uint64_t fills_today
std::optional< native_order::RiskLimitKind > reason
What configure_native answers: the status and, on refusal, the first error field validate_native_run_...
NativeRunSpecValidation validation
The flattened run state native_state() answers: the lifecycle kind, a borrowed pointer to the staged ...
const NativeRunSpec * spec
NativeCompletion completion
int64_t decision_floor_ms
uint64_t consumed_high_water
One accepted realtime print before native matching at its current decision point.
NativeDecisionContext decision
One completed higher-timeframe bucket of a declared subscription (NativeRunSpec::subscriptions),...
std::int64_t delivered_at_ms
NativeCompletionKind completion
native_calendar::NativeInterval interval
Read-only projection of a live generic Trail request.
std::uint64_t activation_ordinal
Owning value row for one live request, copied at query time.
native_order::TriggerState trigger_state
native_order::RemainingProjection remaining
native_order::DefinitionRef definition
Everything the kernel knows about WHERE a point is, as one owning value: its event ordinal,...
What validate_native_fx_curve and configure_native_fx_curve report: the error and the index of the el...
An immutable account-currency FX curve: parallel arrays of effective-from timestamps in epoch millise...
A host-maintained, run-scoped roster identity.
One committed execution: the definition, the cursor, the resolved price and units,...
A kernel-issued liquidation that actually filled.
A candidate the run refused, with its MatchRejectReason and the cursor it was refused at.
A reduction or a flatten that had nothing to close: terminal, with no execution identity,...
Replacement behaviour that is not expressible in the successor request.
Aggregate field order keeps market construction: Request{Transact{1.0}, "buy", "comment"}...
Allocation-free facts suitable for the host's durable failure variant.
One complete setup value, staged/copied by NativeStrategyHost before it is applied at begin.