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();
373 std::optional<native_order::CommandEvent>
command;
375 std::optional<NativeAccountObservation>
account;
423 native_order::NativeCandidatePriceKind::PointPrice;
587 std::optional<native_order::RiskLimitKind>
reason;
770#define PINEFORGE_HAS_NATIVE_STRATEGY_HOST_V18 1
881 native_order::OpeningShape::Transact};
1026 std::vector<NativeTimeframeSubscription> subscriptions);
1170 double equity,
double fx)
const;
BacktestEngine(NativeConsumerBindTag)
NativeFxCurveSetupResult configure_native_fx_curve(const NativeFxCurve &curve)
Stage the run's immutable FX epoch, legal only while Ready.
std::optional< Bar > current_partial_bar() const
The bar so far at the current cursor, folded from the modeled points this script bar has already pres...
virtual void prepare_native_begin(const NativeBeginArgs &)
Offered once per begin, before the run starts, with the begin's own arguments — the bars,...
virtual void on_native_input(const Bar &, const NativeInputContext &)
Called once for every accepted confirmed input bar, before that bar is aggregated or matched.
~NativeStrategyHost() override
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_where(std::string_view comment)
Withdraw exactly the live requests carrying this comment, and answer how many of those left the book.
std::vector< NativeWorkingRequest > native_working_requests() const
Working-book snapshot and bulk cancellation.
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 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.
NativeStrategyHost & operator=(const NativeStrategyHost &)=delete
NativeCurrentExecutionResult execute_current(const NativeCurrentExecution &)
Consume, synchronously, a request accepted or replaced in this very callback.
void on_bar(const Bar &bar) final
The engine's own bar entry, taken over by the native consumer and sealed.
native_order::CancelResult cancel(const native_order::RequestHandle &target)
Cancel one live request by handle.
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 bool margin_check_allowed(const NativeMarginCheckPoint &) const
Consulted at each kernel check point before anything is evaluated.
virtual void on_native_bar(const Bar &bar, const NativeDecisionContext &context)=0
The current decision point remains valid for the complete callback.
friend class NativeExecutionConsumer
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...
native_order::ReplaceResult replace(const native_order::RequestHandle &target, const native_order::Request &request, native_order::ReplaceOptions options)
Replace with options.
NativePhysicalPosition physical_position() const
The book as one aggregate, copied out.
std::size_t cancel_where(std::string_view text, NativeRequestField field)
The same predicate over either identity text.
native_order::SubmitResult submit_market(const native_order::Request &request)
The deliberately narrow market-default convenience: the same acceptance path as submit,...
virtual void on_native_bar_open(const Bar &, const NativeDecisionContext &)
Precedes the matching pass at the script bar's open decision point.
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 ...
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 ...
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...
NativeSetupResult configure_native(const NativeRunSpec &spec)
The only setup call.
NativeCurrentExecutionPreview inspect_current_execution(const NativeCurrentExecution &) const
A read-only preview of a current execution: the settlement readiness, any typed refusal or terms outc...
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...
NativeRiskState native_risk_state() const
The run's generic risk ledger.
std::vector< NativeMarketEvent > native_events(uint64_t after_ordinal) const
Owning snapshots copied at query time.
virtual bool owns_lot_excursions() const noexcept
RULING A48 — the ONE generic per-lot excursion capability.
NativeStrategyHost(const NativeStrategyHost &)=delete
native_order::SubmitResult submit(const native_order::Request &request)
Accept one complete request.
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 ClosedLotExcursion closed_lot_excursion(const ClosedLotExcursionFacts &) const
The per-lot excursion a host owns, consulted for every closing row once owns_lot_excursions() answers...
std::optional< NativeCurrentPointView > current_execution_point() const
The active callback's quote and calendar-derived decision context, as an owning value.
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...
uint64_t native_consumed_high_water() const
The highest run_number this host has consumed.
std::size_t cancel_all()
Withdraw every live request, dependants of a cancelled owner included, and answer how many left the b...
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.
uint64_t native_continuation_hash() const
The consumer's continuation identity: what a stream resumes against.
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...
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...
virtual void on_native_margin_call(const native_order::MarginCallEvent &)
A kernel-issued liquidation that filled.
NativeStrategyHost(NativeStrategyHost &&)=delete
void cohort_remove(native_order::CohortHandle cohort, native_order::RequestHandle origin)
Take one opening back off a roster.
virtual native_order::ExecutionTerms resolve_execution_terms(const NativeExecutionTermsFacts &facts) const
The fill-terms hook, consulted at every matching candidate.
virtual void on_native_run_begin()
Offered once per successful begin, after the reset and before any bar.
bool append_auxiliary_bars(const Bar *bars, std::size_t n)
A realtime stream's later bars of its declared auxiliary feed.
std::uint64_t native_recalculations_skipped() const
How many recalculations max_recalculations_per_point dropped at their matching point.
virtual void on_native_tick(const Bar &, const NativeTickContext &)
Called once for every accepted realtime print, before matching at that point.
NativeStrategyHost & operator=(NativeStrategyHost &&)=delete
NativeStateView native_state() const
The whole run state as one owning read.
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...
native_order::CohortHandle cohort_open()
Open a roster a later close can bind to.
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 (...
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...
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...
void cohort_add(native_order::CohortHandle cohort, native_order::RequestHandle origin)
Enroll one accepted opening's handle in a roster.
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...
std::variant< NativeUnconfigured, NativeReady, NativeRunning, NativeCompleted, NativeFailed > NativeLifecycle
The lifecycle as one value. Exhaustive over the five alternatives above.
NativeLifecycleKind
Where a host stands.
NativeCurrentRefusal
Why a current-execution command cannot be consumed here.
constexpr bool native_failure_has_cause(NativeFailureContextKind kind) noexcept
Whether a context of this kind populates its NativeInRunCause.
NativeRequestField
Which of a request's two free-text identity fields a bulk predicate reads.
constexpr NativeFailureContextKind native_failure_context_kind(bool cause, bool recipient, bool cursor) noexcept
The kind that says exactly these three alternatives are 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,...
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.
NativeCompletion
How a Completed run ended: a batch reached the last bar, or a stream was ended.
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.
NativeCalculationReason
Why the kernel is asking the host to calculate.
NativeRunPhase
Which driving is Running: a batch run(), a stream's internal warmup, or its realtime leg.
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.
NativeFailureContext native_failure_cause(std::uint64_t ordinal) noexcept
A context carrying one causing event ordinal.
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_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.
NativePrecommitVerdict
The host is consulted before generic opening-margin admission.
NativeEventKind
Which of NativeMarketEvent's three alternatives is populated.
NativeFailureContextKind
In-run failure references.
NativeAnchoredTrigger
Which trigger of an anchored leg the owner's fill is about to supply.
NativeCurrentQuoteKind
Where a price came from: the callback's own market decision point, or the execution it is anchored to...
NativeSetupStatus
Whether a setup call applied its value or refused it.
NativeFailureContext native_failure_recipient(std::uint64_t incarnation) noexcept
A context carrying one addressed request incarnation.
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.
NativeCompletionKind
How a script interval or a higher-timeframe bucket was closed.
std::variant< AllowanceUnset, AllowanceUnits, AllowanceAllScope, AllowanceDeferred > Allowance
NativeCandidatePriceKind
Which price a candidate is being offered at: the point's own price, or the request's trigger level (a...
std::variant< MarketReady, LimitReady, StopIdle, StopActive, StopLimitPending, StopLimitLive, TrailWaitArm, TrailTrack, TrailActive > TriggerState
std::variant< RemainingUnbound, RemainingFlattenAll, RemainingUnits, RemainingDeferred, NoTarget > Remaining
std::variant< execution::Flatten, order_action::Reduce, order_action::Transact, execution::ReverseTo > ExecutionPlan
The settlement shape one execution takes.
std::shared_ptr< const RequestDefinition > DefinitionRef
std::variant< RemainingProjectionUnbound, RemainingProjectionFlattenAll, RemainingProjectionUnits, RemainingProjectionDeferred, RemainingProjectionNoTarget > RemainingProjection
std::variant< execution::Book, execution::OpeningExposure, SelectedExposure > ExecutionScope
What one execution acted on: the whole book, one opening's exposure, or a bound selection.
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...
native_order::MatchCursor owner_cursor
native_order::RequestHandle leg
std::uint64_t owner_applied_ordinal
native_order::Side leg_side
NativeAnchoredTrigger trigger
std::uint64_t owner_lot_incarnation
native_order::RequestHandle owner
Borrowed begin-call facts.
const SymInfo * syminfo
The rich run overload's symbol metadata is borrowed only for this callback.
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
int magnifier_volume_weighted_min_samples
bool magnifier_volume_weighted
int magnifier_volume_weighted_max_samples
NativeCompletion completion
Recomputed observations, never an apply token.
execution::AccountEffectProjection account
std::optional< native_order::CancelReason > terms_cancellation
std::optional< NativeCurrentRefusal > refusal
std::optional< execution::Status > settlement_readiness
std::optional< native_order::MatchRejectReason > terms_rejection
std::vector< double > closed_row_pnl
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,...
NativeDecisionContext decision
std::uint64_t quote_origin_ordinal
NativeCurrentQuoteKind quote_kind
Read-only owning-value facts for one candidate.
bool shared_cursor_collision
A retained crossing can share a rounded cursor quote with another request's level.
native_order::ExecutionScope scope
native_order::DefinitionRef definition
NativeCurrentPriceRule price_rule
double pending_group_deduction
native_order::MatchCursor cursor
native_order::DriverEligibilityClass driver_class
native_order::Remaining remaining
native_order::NativeCandidatePriceKind price_kind
native_order::TriggerState trigger_state
NativeCurrentQuoteKind quote_kind
std::int64_t fx_effective_time_ms
double opposite_book_units
native_order::Allowance allowance
native_order::RequestHandle target
double default_resolved_price
std::optional< double > trigger_level
NativePhysicalPosition position
double scope_exposure_units
std::optional< NativeRunSpec > spec
The three in-run facts a failure may carry, tagged by kind.
NativeFailureContextKind kind
NativeInRunRecipient recipient
The durable record native_state().failure answers: the code, the operation it happened in,...
std::uint32_t discriminator
NativeFailureOperation operation
NativeFailureContext context
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 input_interval
native_calendar::NativeInterval script_interval
Ephemeral factual view of one kernel-issued liquidation before its units are fixed.
native_order::MatchCursor cursor
NativePhysicalPosition position
Ephemeral factual view of one kernel check point, offered to the host before the check runs.
NativePhysicalPosition position
NativeMarginCheckKind kind
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,...
native_order::MatchCursor cursor
NativePhysicalPosition position
NativeMarginCheckKind kind
One owning row of native_events(after_ordinal): a command event, a driver point or an account observa...
std::optional< NativeAccountObservation > account
std::optional< NativeDriverPoint > driver
std::optional< native_order::CommandEvent > command
Owning value row for one open physical lot, copied at query time by native_open_lots(mark) — the lot-...
std::string entry_comment
double favorable_excursion
std::uint64_t entry_incarnation
std::int64_t entry_time_ms
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
native_order::MatchCursor cursor
execution::Status settlement_readiness
execution::AccountEffectProjection account
native_order::ExecutionPlan plan
native_order::DefinitionRef definition
double inspected_opened_units
double inspected_current_ticket
double inspected_closed_units
native_order::RequestHandle target
std::vector< double > closed_row_pnl
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
uint64_t consumed_high_water
int64_t decision_floor_ms
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),...
native_calendar::NativeInterval interval
NativeCompletionKind completion
std::int64_t delivered_at_ms
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.