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_V20 1
969 return {facts.default_resolved_price, std::nullopt,
970 native_order::OpeningShape::Transact};
1017 return std::nullopt;
1034 return std::nullopt;
1163 std::vector<NativeTimeframeSubscription> subscriptions);
1172 std::vector<NativeTimeframeSubscription> subscriptions);
1351 double equity,
double fx)
const;
BacktestEngine(NativeConsumerBindTag)
std::optional< NativeWorkingRequest > native_working_request(const native_order::RequestHandle &) const
uint64_t native_continuation_hash() const
The consumer's continuation identity: what a stream resumes against.
NativeSetupResult declare_timeframe_subscriptions_result(std::vector< NativeTimeframeSubscription > subscriptions)
The same call, answered the way configure_native answers the identical validation: Applied,...
bool report_presenter_supports_non_full() const noexcept override
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.
NativeRiskState native_risk_state() const
The run's generic risk ledger.
bool mark_native_report_point(int64_t report_ts)
Append one kernel-owned equity point at this host's report mark.
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::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,...
std::size_t cancel_where(std::string_view text, NativeRequestField field)
The same predicate over either identity text.
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.
std::vector< NativeWorkingRequest > native_working_requests() const
Working-book snapshot and bulk cancellation.
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 (...
virtual void on_native_margin_call(const native_order::MarginCallEvent &)
A kernel-issued liquidation that filled.
int64_t native_decision_floor() const
The run's monotonic decision floor in epoch milliseconds — the same value NativeStateView::decision_f...
~NativeStrategyHost() override
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.
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.
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...
void native_acknowledge_events(uint64_t through_ordinal)
The host has read every event through through_ordinal (the bounded event journal).
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...
std::optional< NativeCurrentPointView > current_execution_point() const
The active callback's quote and calendar-derived decision context, as an owning value.
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...
friend class NativeExecutionConsumer
NativeStrategyHost & operator=(const NativeStrategyHost &)=delete
native_order::SubmitResult submit(const native_order::Request &request)
Accept one complete request.
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...
NativeStateView native_state() const
The whole run state as one owning read.
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 ...
void declare_native_bar_open_hook(bool implemented)
Which of two optional hooks this host implements (the optional-hook and quiet-point changes).
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...
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 native_aggregates_input_bars() const
Whether the configured run's script bars are buckets the kernel gathers from its input bars – native_...
NativeFxCurveSetupResult configure_native_fx_curve(const NativeFxCurve &curve)
Stage the run's immutable FX epoch, legal only while Ready.
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...
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...
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.
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...
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.
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.
std::uint64_t broker_state_hash_projection() const override
native_order::ReplaceResult replace(const native_order::RequestHandle &target, const native_order::Request &request, native_order::ReplaceOptions options)
Replace with options.
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 ...
NativeSetupResult configure_native(const NativeRunSpec &spec)
The only setup call.
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...
NativeStrategyHost(NativeStrategyHost &&)=delete
NativeStrategyHost & operator=(NativeStrategyHost &&)=delete
std::vector< NativeMarketEvent > native_events(uint64_t after_ordinal) const
Owning snapshots copied at query time.
NativePhysicalPosition physical_position() const
The book as one aggregate, copied out.
NativeStrategyHost(const NativeStrategyHost &)=delete
detail::ScratchStatus visit_native_open_lot_values(void *, bool(*)(void *, std::uint64_t, double, double)) const
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...
std::size_t cancel_all()
Withdraw every live request, dependants of a cancelled owner included, and answer how many left the b...
std::optional< NativeCurrentRefusal > activate_current_stop_limit(const native_order::RequestHandle &target)
Activate only the named pending stop-limit when its stop is reached by the current quote.
virtual void prepare_native_begin(const NativeBeginArgs &)
Offered once per begin, before the run starts, with the begin's own arguments — the bars,...
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...
void on_bar(const Bar &bar) final
The engine's own bar entry, taken over by the native consumer and sealed.
virtual bool margin_check_allowed(const NativeMarginCheckPoint &) const
Consulted at each kernel check point before anything is evaluated.
uint64_t native_consumed_high_water() const
The highest run_number this host has consumed.
void native_visit_open_lots(double mark, void *, void(*)(void *, const NativeOpenLotView &)) const
void declare_native_precommit_hook(bool implemented)
declare_native_precommit_hook(false): validate_execution_precommit is the default admission,...
uint64_t native_event_window_start() const
The oldest ordinal a read can still return: every command event at or above it is retained,...
virtual void on_native_bar_open(const Bar &, const NativeDecisionContext &)
Precedes the matching pass at the script bar's open decision point.
virtual void on_native_run_begin()
Offered once per successful begin, after the reset and before any bar.
native_order::CohortHandle cohort_open()
Open a roster a later close can bind to.
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_bar(const Bar &bar, const NativeDecisionContext &context)=0
The current decision point remains valid for the complete callback.
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.
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
detail::ScratchStatus visit_native_open_lots(double mark, void *, bool(*)(void *, const NativeOpenLotView &)) const
void cohort_remove(native_order::CohortHandle cohort, native_order::RequestHandle origin)
Take one opening back off a roster.
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...
std::uint64_t native_recalculations_skipped() const
How many recalculations max_recalculations_per_point dropped at their matching point.
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...
bool append_auxiliary_bars(const Bar *bars, std::size_t n)
A realtime stream's later bars of its declared auxiliary feed.
virtual native_order::ExecutionTerms resolve_execution_terms(const NativeExecutionTermsFacts &facts) const
The fill-terms hook, consulted at every matching candidate.
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...
constexpr std::uint8_t native_failure_context_bits(NativeFailureContextKind kind) noexcept
The bit-union under NativeFailureContextKind: Cause=1, Recipient=2, Cursor=4.
NativeAnchoredTrigger
Which trigger of an anchored leg the owner's fill is about to supply.
NativeRequestField
Which of a request's two free-text identity fields a bulk predicate reads.
NativeCalculationReason
Why the kernel is asking the host to calculate.
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.
NativeLifecycleKind
Where a host stands.
constexpr bool native_failure_has_cursor(NativeFailureContextKind kind) noexcept
Whether a context of this kind populates its NativeInRunCursor.
NativeCompletion
How a Completed run ended: a batch reached the last bar, or a stream was ended.
NativeFailureContext native_failure_recipient(std::uint64_t incarnation) noexcept
A context carrying one addressed request incarnation.
NativeRunPhase
Which driving is Running: a batch run(), a stream's internal warmup, or its realtime leg.
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.
constexpr bool native_failure_has_cause(NativeFailureContextKind kind) noexcept
Whether a context of this kind populates its NativeInRunCause.
NativeFailureCode
The durable first failure of a run, in NativeFailure::code.
NativePrecommitVerdict
The host is consulted before generic opening-margin admission.
NativeFailureOperation
Which operation was in flight when the failure latched — the second half of "what went wrong",...
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.
NativeCurrentRefusal
Why a current-execution command cannot be consumed here.
NativeSetupStatus
Whether a setup call applied its value or refused it.
NativeFailureContext native_failure_cursor(NativeCoordinate point, double t=0.0) noexcept
A context carrying one path cursor.
NativeMarginCheckKind
Which kernel check point is about to test the maintenance requirement.
NativeFailureContext native_failure_cause(std::uint64_t ordinal) noexcept
A context carrying one causing event ordinal.
NativeFailureContextKind
In-run failure references.
NativeEventKind
Which of NativeMarketEvent's three alternatives is populated.
constexpr bool native_failure_has_recipient(NativeFailureContextKind kind) noexcept
Whether a context of this kind populates its NativeInRunRecipient.
NativeCurrentPriceRule
Which price a current execution settles at: the active callback's quote as presented,...
std::variant< NativeUnconfigured, NativeReady, NativeRunning, NativeCompleted, NativeFailed > NativeLifecycle
The lifecycle as one value. Exhaustive over the five alternatives above.
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.
NativeCurrentQuoteKind
Where a price came from: the callback's own market decision point, or the execution it is anchored to...
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...
std::uint64_t owner_applied_ordinal
native_order::RequestHandle leg
NativeAnchoredTrigger trigger
native_order::RequestHandle owner
std::uint64_t owner_lot_incarnation
native_order::Side leg_side
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.
bool magnifier_volume_weighted
int magnifier_volume_weighted_max_samples
MagnifierDistribution magnifier_distribution
bool simple_run
Which public overload began the run: the bare run(bars, n) lifecycle (true) or a timeframe-aware / ma...
const void * overrides_opaque
const SymInfo * syminfo
The rich run overload's symbol metadata is borrowed only for this callback.
int magnifier_volume_weighted_min_samples
NativeCompletion completion
Recomputed observations, never an apply token.
std::vector< double > closed_row_pnl
execution::AccountEffectProjection account
std::optional< execution::Status > settlement_readiness
std::optional< native_order::CancelReason > terms_cancellation
std::optional< native_order::MatchRejectReason > terms_rejection
std::optional< NativeCurrentRefusal > refusal
A synchronous execution of one request accepted or replaced in this very callback: a target handle an...
native_order::RequestHandle target
NativeCurrentPriceRule price_rule
What current_execution_point() answers inside a callback: the point's decision context,...
NativeDecisionContext decision
NativeCurrentQuoteKind quote_kind
std::uint64_t quote_origin_ordinal
Read-only owning-value facts for one candidate.
double default_resolved_price
native_order::DriverEligibilityClass driver_class
bool shared_cursor_collision
A retained crossing can share a rounded cursor quote with another request's level.
NativeCurrentPriceRule price_rule
std::optional< double > trigger_level
std::int64_t fx_effective_time_ms
double scope_exposure_units
native_order::ExecutionScope scope
native_order::TriggerState trigger_state
native_order::NativeCandidatePriceKind price_kind
native_order::MatchCursor cursor
NativeCurrentQuoteKind quote_kind
native_order::Remaining remaining
native_order::RequestHandle target
double opposite_book_units
double pending_group_deduction
native_order::Allowance allowance
NativePhysicalPosition position
native_order::DefinitionRef definition
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,...
NativeFailureContext context
NativeFailureOperation operation
std::uint32_t discriminator
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...
native_calendar::NativeInterval input_interval
bool completes_script_interval
native_calendar::NativeInterval script_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
bool liquidation_resting
Whether the model already holds a liquidation resting from an earlier admitted point.
native_order::MatchCursor cursor
NativePhysicalPosition position
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< native_order::CommandEvent > command
std::optional< NativeAccountObservation > account
std::optional< NativeDriverPoint > driver
Callback-local view of the same FIFO row.
std::string_view entry_label
std::int64_t entry_time_ms
double favorable_excursion
std::uint64_t entry_incarnation
std::string_view entry_comment
Owning value row for one open physical lot, copied at query time by native_open_lots(mark) — the lot-...
double favorable_excursion
std::string entry_comment
std::int64_t entry_time_ms
std::uint64_t entry_incarnation
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.
execution::Status settlement_readiness
native_order::ExecutionScope scope
native_order::RequestHandle target
native_order::ExecutionPlan plan
double inspected_current_ticket
native_order::MatchCursor cursor
native_order::DefinitionRef definition
std::vector< double > closed_row_pnl
double inspected_closed_units
double inspected_opened_units
execution::AccountEffectProjection account
The run's generic risk ledger (L9), as the kernel holds it.
std::optional< native_order::RiskLimitKind > reason
std::uint32_t consecutive_loss_days
std::uint64_t fills_today
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
int64_t decision_floor_ms
NativeCompletion completion
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
native_calendar::NativeInterval interval
NativeCompletionKind completion
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::RemainingProjection remaining
native_order::TriggerState trigger_state
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.