1669 void set_begin_mode(
bool is_stream,
bool bar_magnifier =
false) noexcept;
1674 cohorts_by_id_.fixture_implicit_spill_interval(calls);
1678 cohorts_by_id_.fixture_spill_predicate(predicate);
1681 fixture_verify_source_entry_slots_ = enabled;
1684 fixture_bracket_remove_precheck_ = enabled;
1689 const ::pineforge::detail::IdPairStore<std::int64_t, true>&
1747 double limit_price =
std::numeric_limits<
double>::quiet_NaN(),
1748 double stop_price =
std::numeric_limits<
double>::quiet_NaN(),
1749 double qty =
std::numeric_limits<
double>::quiet_NaN(),
1750 const
std::
string& comment = {},
const std::string& oca_name = {},
1751 int oca_type = 0,
int qty_type = -1);
1752 void close(
const SourceId&
id,
const std::string& comment = {},
1753 double qty = std::numeric_limits<double>::quiet_NaN(),
1754 double qty_percent = std::numeric_limits<double>::quiet_NaN(),
1755 bool immediately =
false, std::uint64_t callsite_token = 0);
1758 double limit_price,
double stop_price,
1759 double trail_points = std::numeric_limits<double>::quiet_NaN(),
1760 double trail_offset = std::numeric_limits<double>::quiet_NaN(),
1761 double trail_price = std::numeric_limits<double>::quiet_NaN(),
1762 double qty_percent = 100.0,
const std::string& comment = {},
1763 double qty = std::numeric_limits<double>::quiet_NaN(),
1764 const std::string& oca_name = {},
1765 double profit_ticks = std::numeric_limits<double>::quiet_NaN(),
1766 double loss_ticks = std::numeric_limits<double>::quiet_NaN());
1768 const std::string& comment = {});
1772 double limit_price = std::numeric_limits<double>::quiet_NaN(),
1773 double stop_price = std::numeric_limits<double>::quiet_NaN(),
1774 const std::string& oca_name = {},
int oca_type = 0);
1776 native_order::ExecutionTerms
resolve_terms(
const NativeExecutionTermsFacts&)
const;
1796 return anchored_relative_stats_;
1834 std::int64_t sub_bar_open_ms)
const;
1839 double print = std::numeric_limits<double>::quiet_NaN())
const;
1842 double fill, std::int64_t sub_bar_open_ms)
const;
1866 std::int64_t
chart_day_key(std::int64_t timestamp_ms)
const noexcept;
1873#ifdef PINEFORGE_VALUE_INVALID_FIXTURES
1876 void fixture_value_invalid_drawdown_limit(
double value,
bool percent)
noexcept {
1885 return cohort_exposure_for(
id);
1890 return close_logical_units_.size();
1893 return close_batch_pending_debt_;
1896 return close_batch_admitted_total_;
1913 return risk_.direction == 0 || (is_long ? risk_.direction > 0 : risk_.direction < 0);
1917 return risk_.max_intraday_loss_percent;
1932 return market_pyramid_adds_.count(incarnation) != 0;
1942 return coof_recalc_active_ && coof_context_.coordinate.path_phase == NativePathPhase::Close;
1947 named_entry_cancel_tokens_.clear();
1948 pending_same_bar_close_qty_ = 0.0;
1949 source_batch_mutated_ =
false;
1952 return named_entry_cancel_tokens_.find(
id) != named_entry_cancel_tokens_.end();
1964 bool post_calculation =
true,
1965 bool pre_script_drain =
false);
1972 bool explicit_brackets_only =
false,
1973 double current_open = std::numeric_limits<double>::quiet_NaN());
1976 std::uint64_t source_fill_sequence);
1986 struct ExitGroupWork;
1988 const
SourceId& from_entry = {})
const;
1992 return {exit_phase_final_, exit_phase_digest_};
1995 return std::min(trade_exit_phase_.size(), trade_exit_phase_.resident_capacity());
2001 const std::function<std::size_t(std::size_t)>& source_at); ExitGroupWork
exit_group_work() const noexcept;
2039 void preserve_position_tail_before_seal(
2040 std::
size_t global_end, const
std::
string& scratch_directory);
2046 std::shared_ptr<
detail::PositionTailSpill> position_tail_spill_;
2051 std::shared_ptr<
detail::PositionTailSummary> position_tail_summary_;
2052 void observe_position_tail_rows();
2053 void begin_position_tail_summary();
2055 struct CohortFacts {
2058 std::vector<native_order::RequestHandle> opened;
2068 std::unordered_map<std::uint64_t, double> live_units_by_origin;
2069 std::int64_t cycle = 0;
2070 Record retired_record() const noexcept;
2071 static CohortFacts restore_record(const
Record&,
bool arena_backed = false);
2072 bool spillable() const noexcept;
2073 bool held() const noexcept;
2077 std::uint8_t erased_opening_sides = 0;
2079 using CohortTable = ::
pineforge::
detail::DiskResidentIdTable<CohortFacts>;
2080 struct PendingBracketLeg {
2084 std::uint64_t family_key = 0;
2087 struct PendingEntry {
2093 struct DelayedMarketOrder {
2097 std::uint64_t release_open_epoch = 0;
2098 bool execute_at_open =
false;
2106 struct DeferredOpenMarketableSell {
2109 double fill_price = std::numeric_limits<double>::quiet_NaN();
2110 double path_position = 0.0;
2111 bool open_marketable =
false;
2119 struct EntrySubmissionContext {
2120 double current = 0.0;
2121 double limit_price = std::numeric_limits<double>::quiet_NaN();
2122 double stop_price = std::numeric_limits<double>::quiet_NaN();
2123 bool default_sized =
false;
2124 bool priced =
false;
2125 bool reverses =
false;
2126 bool opposite_opening_pending =
false;
2127 bool pure_stop_entry =
false;
2128 bool coof_market_next_open =
false;
2129 bool coof_priced_next_open =
false;
2130 bool coof_market_at_second_extreme =
false;
2131 bool paired_all_in_reentry =
false;
2134 struct PendingSameBarCommand {
2135 native_order::Request request;
2136 PlacementSnapshot snapshot;
2138 bool opening =
false;
2142 bool staged_reversal =
false;
2143 double staged_reversal_held_units = 0.0;
2144 std::optional<native_order::Request> unbatched_request;
2145 std::optional<PlacementSnapshot> unbatched_snapshot;
2146 EntrySubmissionContext unbatched_context;
2153 struct SourceShadowPending {
2154 PlacementSnapshot snapshot;
2158 struct PendingRelativeExit {
2161 double trail_points = std::numeric_limits<double>::quiet_NaN();
2162 double trail_offset = std::numeric_limits<double>::quiet_NaN();
2163 double trail_price = std::numeric_limits<double>::quiet_NaN();
2164 double qty_percent = 100.0;
2165 std::string comment;
2166 double qty = std::numeric_limits<double>::quiet_NaN();
2167 std::string oca_name;
2168 double profit_ticks = std::numeric_limits<double>::quiet_NaN();
2169 double loss_ticks = std::numeric_limits<double>::quiet_NaN();
2183 struct AnchoredRelativeLeg {
2187 native_order::RequestHandle handle{};
2188 native_order::RequestHandle parent{};
2189 bool parent_long =
true;
2192 double operand_ticks = 0.0;
2193 double trail_offset = std::numeric_limits<double>::quiet_NaN();
2194 native_order::Request request;
2196 double installed_level = std::numeric_limits<double>::quiet_NaN();
2206 struct PerEntryExitChild {
2207 std::uint64_t origin = 0;
2208 double fill_price = std::numeric_limits<double>::quiet_NaN();
2210 bool consumed =
false;
2212 struct PerEntryExit {
2214 std::int64_t cycle = 0;
2215 bool long_side =
true;
2216 double profit_ticks = std::numeric_limits<double>::quiet_NaN();
2217 double loss_ticks = std::numeric_limits<double>::quiet_NaN();
2218 std::string comment;
2219 std::vector<PerEntryExitChild> children;
2222 struct PendingCoofRequest {
2223 native_order::Request request;
2224 PlacementSnapshot snapshot;
2226 bool opening =
false;
2227 std::uint64_t family_key = 0;
2228 bool next_open =
false;
2231 struct PendingMarginRevival {
2232 PlacementSnapshot snapshot;
2233 std::int32_t decline_bar = -1;
2236 struct NamedEntryCancelToken {
2237 std::uint64_t entry_incarnation = 0;
2238 std::uint64_t surviving_exit_incarnation = 0;
2244 struct CloseCallsiteState {
2245 bool active =
false;
2246 std::uint64_t token = 0;
2250 std::string comment{};
2251 double target = 0.0;
2252 std::uint64_t queue_sequence = 0;
2258 struct CloseLedgerRecord {
2263 NativeStrategyHost& require_host()
const;
2264 bool modeled_input()
const;
2265 void require_cohort_ticket(
const SourceId* prospective =
nullptr)
const;
2266 native_order::CohortHandle cohort_for(
const SourceId&
id);
2267 std::optional<native_order::RequestHandle> submit_or_replace(
2268 native_order::Request request, PlacementSnapshot snapshot,
bool opening,
2269 const SourceId& replacement_key = {});
2270 void remember(
const native_order::RequestHandle&, PlacementSnapshot&&);
2271 void retire(native_order::RequestHandle)
noexcept;
2274 void erase_retired_rows(
const NativeDecisionContext&);
2277 void retire_origin_prefixes();
2278 void release_closed_cohort_origins();
2279 bool lifecycle_readable(
const PlacementSnapshot&)
const noexcept;
2282 void set_exit_phase(std::size_t trade_index, std::uint8_t phase);
2283 std::vector<native_order::RequestHandle> openings_for(
const SourceId&)
const;
2284 double cohort_exposure_for(
const SourceId&)
const noexcept;
2285 double cohort_exposure_for(
const CohortFacts&)
const noexcept;
2287 std::optional<double> from_entry_units(
const SourceId&)
const noexcept;
2288 bool from_entry_filled_this_cycle(
const SourceId&)
const;
2289 double percent_commission_live_equity(
double)
const noexcept;
2293 double percent_commission_live_equity(
double, std::optional<double> fx)
const noexcept;
2296 double strategy_equity_at(
double mark, std::optional<double> fx)
const noexcept;
2300 void mark_sizing_equity(PineSizingSnapshot&,
double mark,
2301 std::optional<double> fx = std::nullopt)
const noexcept;
2302 double quantize_close_units(
double basis,
double percent)
const noexcept;
2303 double quantize_percent_exit_units(
double requested,
2304 double available)
const noexcept;
2305 bool compute_exit_reservation(
const SourceId& exit_id,
2307 double requested_qty,
2308 double& qty_percent,
2310 double percentage_basis,
2311 double& reserved_qty)
const;
2312 void reconcile_deferred_exit_reservations(
const SourceId& from_entry,
2314 void reconcile_exit_reservations_after_margin();
2315 double active_staged_fx(std::int64_t)
const noexcept;
2316 void apply_fx_open_margin_slice(
const Bar&,
const NativeDecisionContext&);
2317 void apply_fx_opening_margin_slice(
const native_order::ExecutionAppliedEvent&,
2318 const NativeDecisionContext&);
2319 void schedule_preopen_margin_slice(
const Bar&,
const NativeDecisionContext&);
2320 bool leveraged_entry_bar_checked() const noexcept;
2321 bool preopen_slice_class(const PlacementSnapshot&,
2322 const NativeDecisionContext&) const noexcept;
2326 bool submit_margin_call_slice(
double mark_price, const NativeDecisionContext&,
2327 bool opening_checkpoint = false,
2328 std::optional<
double> resolved_execution_price = std::nullopt);
2329 bool submit_margin_call_units(
double mark_price, const NativeDecisionContext&,
2331 bool force_execution_price = true,
2332 std::optional<
double> resolved_execution_price = std::nullopt);
2333 bool submit_tv_money_long_margin_call(const Bar&, const NativeDecisionContext&,
2334 int* fired_waypoint =
nullptr);
2335 void fold_source_money();
2336 void fold_source_money_through(const
PineStrategyHost& pine, std::uint64_t count);
2337 bool gain_loss_regime() const;
2338 bool gain_loss_run_regime() const;
2339 double gain_loss_signal_equity(
double mark) const;
2340 double gain_loss_mirror_equity(
double mark) const;
2341 std::optional<
double> pooc_fee_units(const PineSizingSnapshot&) const;
2342 double tv_pooc_fee_grossed_unit(
double price) const;
2343 bool unified_admission_scope(const PlacementSnapshot&,
bool market_or_stop,
2344 double signed_units,
double units,
2345 bool beside_exits = false) const;
2346 bool unified_admission_terms(const PlacementSnapshot&, const NativeExecutionTermsFacts&,
2347 bool market_or_stop,
bool opposite,
2348 native_order::ExecutionTerms& result,
bool& admitted) const;
2349 bool unified_fill_admits(const PlacementSnapshot&,
double units,
double quote) const;
2350 void record_close_first(
bool whole_position);
2351 void credit_pyramiding_record(const
SourceId&
id, std::uint64_t incarnation,
double units);
2352 void book_pyramiding_records(const
SourceId&
id, std::uint64_t armed_for,
double units);
2353 std::optional<std::
size_t> open_ledger_records() const;
2354 std::optional<std::
size_t> held_ledger_records() const;
2355 std::uint64_t entry_incarnation_of(const
SourceId& from_entry) const;
2356 bool exit_tombstoned(const
SourceId& exit_id, const
SourceId& from_entry) const;
2357 bool unified_placement_book_clear() const;
2358 bool pinned_lot_grid() const;
2359 bool slipped_long_margin_scope() const;
2360 bool slipped_long_book_scope() const;
2361 double slipped_long_margin_units(
double quote) const;
2362 bool slipped_long_unit_shortfall(
double quote) const;
2363 bool close_all_at_next_point(
2364 const Bar&,
int fired,
2365 const std::vector<std::pair<native_order::RequestHandle, PlacementSnapshot>>& closes,
2366 const NativeDecisionContext&);
2367 bool slipped_pooc_opening_money_scope(
2368 const Bar&, const NativeDecisionContext&) const;
2369 bool submit_slipped_pooc_opening_money_call(
2370 const Bar&, const NativeDecisionContext&);
2371 bool schedule_tv_money_long_margin_before_trail(
2372 const Bar&, const NativeDecisionContext&);
2373 std::optional<std::int64_t> flat_sibling_placement(std::
size_t min_lots) const;
2374 bool flat_sibling_book(const PlacementSnapshot&, std::int32_t interval_index,
2376 bool flat_sibling_fill_follows(const PlacementSnapshot&,
2377 const native_order::RequestHandle&) const;
2378 bool add_sibling_fill_follows(const PlacementSnapshot&,
2379 const native_order::RequestHandle&) const;
2380 std::
size_t add_sibling_lots(std::int64_t placed) const;
2381 bool whole_unit_follow_up_due(
double called_units,
double mark) const;
2382 bool margin_follow_up_scope() const noexcept;
2383 double margin_follow_up_units(
double called_units,
double fill,
2384 std::int64_t sub_bar_open_ms) const;
2385 void follow_margin_call(
double called_units,
double fill,
double current,
2386 const NativeDecisionContext&);
2387 bool short_call_vetoed(const
SourceMarginMoney&,
double units,
bool opening_checkpoint,
2388 double print = std::numeric_limits<
double>::quiet_NaN()) const;
2392 bool close_sized_open_call_scope(
bool short_book,
bool several_lots = false) const;
2393 double close_sized_open_units(
double close_mark,
double print,
2394 std::int64_t sub_bar_open_ms) const;
2395 bool run_close_sized_open_calls(
double units,
double opening_mark,
2396 const NativeDecisionContext&);
2399 bool opening_released_leg(const PlacementSnapshot& row, std::uint64_t leg,
2400 std::uint64_t opening, const
SourceId&
id,
bool short_book,
2401 const NativeDecisionContext&) const;
2402 bool priced_exit_precedes_opening(
bool short_book, std::uint64_t opening,
2403 const
SourceId& opening_id, const NativeDecisionContext&,
2404 const PlacementSnapshot* filled,
bool* at_open) const;
2405 void run_opening_checkpoint(
double fill,
bool market,
bool sibling_book,
2406 bool adds_book_last, const NativeDecisionContext&);
2407 double open_print_follow_up_units(
double held_before,
double equity_before,
double entry,
2408 double called,
double fill,
bool short_book,
2409 std::int64_t sub_bar_open_ms) const;
2410 double open_print_lot_follow_up_units(const std::vector<std::pair<
double,
double>>& taken,
2411 double equity_before,
double held_before,
double fill,
2412 bool short_book, std::int64_t sub_bar_open_ms) const;
2413 bool lagged_short_scope() const noexcept;
2414 double lagged_short_follow_up_units(const std::vector<std::pair<
double,
double>>& taken,
2415 double equity_before,
double held_before,
double fill,
2416 std::int64_t sub_bar_open_ms) const;
2417 double call_short_with_lagged_follow_up(
double mark,
double units,
2418 const NativeDecisionContext&,
bool owed = false);
2419 bool whole_share_lag_scope() const noexcept;
2420 double whole_share_lag_units(const std::vector<std::pair<
double,
double>>& taken,
2421 double equity_before,
double held_before,
double fill,
2422 std::int64_t sub_bar_open_ms) const;
2423 bool open_call_owing_follow_up(
double opening_mark, const NativeDecisionContext&);
2424 bool short_path_points_scope(const NativeDecisionContext&) const;
2425 void execute_owed_short_follow_up(
int point,
double price, const NativeDecisionContext&);
2426 void hold_owed_close_follow_up(
double close, const NativeDecisionContext&);
2427 void book_owed_close_follow_up(const Bar&, const NativeDecisionContext&);
2428 void walk_short_path_points(const Bar&, const NativeDecisionContext&);
2429 void schedule_lagged_short_follow_up(const native_order::ExecutionAppliedEvent&,
2430 const NativeDecisionContext&);
2431 bool pending_veto_point_first(const Bar&, const NativeDecisionContext&,
double opening_mark);
2432 void record_close_call_after_script(
double book_before,
double called,
2433 const NativeDecisionContext&);
2434 void apply_frozen_reversal_close(const PlacementSnapshot&, const NativeExecutionTermsFacts&,
2435 native_order::ExecutionTerms&) const;
2436 native_order::ExecutionTerms resolve_source_terms(const NativeExecutionTermsFacts&) const;
2437 double gain_loss_closed_equity() const;
2438 bool declined_reversal_at_open(const Bar&) const;
2439 bool schedule_margin_call_path(const Bar&, const NativeDecisionContext&);
2440 bool schedule_priced_opening_margin(const Bar&, const NativeDecisionContext&,
double fill);
2441 bool close_point_margin_scope() const noexcept;
2442 void withdraw_waypoint_margin_calls();
2443 bool rest_waypoint_margin_call(const Bar&,
int from,
int to, const NativeDecisionContext&);
2444 bool close_point_margin_call(const Bar&, const NativeDecisionContext&,
bool cancelled);
2445 bool book_close_point_call(
double mark,
double units, const NativeDecisionContext&,
2446 bool queued,
double reference_mark = 0.0);
2447 void close_point_follow_up(
double mark,
double called_units, const NativeDecisionContext&);
2448 std::vector<std::pair<native_order::RequestHandle, PlacementSnapshot>>
2449 same_bar_close_alls(const NativeDecisionContext&) const;
2450 void size_close_alls_at_placement(
2451 std::vector<std::pair<native_order::RequestHandle, PlacementSnapshot>>&,
double placed);
2452 bool close_point_margin_call_at_open(const Bar&, const Bar& prior,
2453 const NativeDecisionContext&);
2456 void defer_declined_reversal_exits_at_adverse(const Bar&,
2457 const NativeDecisionContext&,
2458 bool margin_scheduled);
2459 bool intraday_loss_breached(
double mark_price) const;
2460 bool submit_intraday_loss_close(
double mark_price, const NativeDecisionContext&,
2461 bool execute_current);
2462 void schedule_intraday_loss_path(const Bar&, const NativeDecisionContext&);
2463 void update_risk_state(
double mark_price);
2464 bool intraday_loss_orders_blocked() const noexcept;
2465 compat::pine::CapClock cap_clock(const NativeDecisionContext&) const;
2466 compat::pine::Calculation cap_calculation(const NativeDecisionContext&) const;
2467 compat::pine::MatchedAttempt cap_attempt(
2468 const PlacementSnapshot&, std::uint64_t incarnation,
2469 const native_order::ExecutionAppliedEvent* applied =
nullptr) const;
2470 bool cap_placement_denied(const NativeDecisionContext&);
2471 void observe_intraday_cap(const native_order::ExecutionAppliedEvent&,
2472 const PlacementSnapshot&, const NativeDecisionContext&);
2473 void observe_intraday_cap_noop(
bool is_long, const NativeDecisionContext&);
2474 void execute_cap_close_now(const compat::pine::CloseNow&);
2475 void execute_due_cap_close(const NativeDecisionContext&);
2476 void maybe_activate_short_seed_plan();
2477 void activate_short_seed_plan_at_open(const NativeDecisionContext&);
2478 bool qualify_short_seed_plan(const ShortSeedPlan&) const;
2479 bool short_seed_context_is_live() const noexcept;
2480 void record_dropped_close(const
SourceId&, const std::
string&,
double,
double,
2481 bool, std::uint64_t);
2482 void record_opening_fee(const PlacementSnapshot&,
2483 const native_order::ExecutionAppliedEvent&);
2484 void consume_opening_fees(const native_order::ExecutionAppliedEvent&,
2486 void consume_cohort_units(const
SourceId&, const native_order::ExecutionAppliedEvent&);
2487 void consume_closed_trade_rows(const native_order::ExecutionAppliedEvent&,
2488 const PlacementSnapshot*);
2489 bool origin_is_pending(const native_order::RequestHandle&) const noexcept;
2494 std::vector<std::
size_t> live_origin_positions(const CohortFacts&) const;
2503 IExecutionConsumer* bound_consumer() const noexcept;
2505 bool cohort_opened_on_side(const CohortFacts&,
bool is_long) const noexcept;
2510 const native_order::RequestHandle& origin) const noexcept;
2512 bool immediate_close_placed_on(std::int32_t bar) const noexcept;
2513 void cancel_bracket_origin(native_order::RequestHandle);
2517 void cancel_bracket_siblings(native_order::RequestHandle, std::uint64_t executed_at = 0);
2518 void cancel_exit_orders_for_full_close(const
SourceId& from_entry);
2519 void cancel_exit_orders_for_full_close(const detail::ScratchByteSource& from_entry);
2520 void retire_in_position_exits_at_flat(
bool preserve_pending_parents,
2521 bool dormant_rows_only,
2522 const PlacementSnapshot* paired_close);
2523 void materialize_relative_exits(PlacementSnapshot,
2524 const native_order::ExecutionAppliedEvent&);
2525 void withdraw_anchored_relative_legs(const
SourceId* exit_id,
2527 void withdraw_anchored_relative_readers(const detail::ScratchByteSource* exit_id,
2528 const detail::ScratchByteSource* from_entry);
2529 bool anchorable_relative_exit(const PendingRelativeExit&,
2530 native_order::RequestHandle& parent,
2531 bool& parent_long) const;
2532 struct RelativeLegShape {
2535 double signed_ticks = 0.0;
2536 double operand_ticks = 0.0;
2538 std::vector<RelativeLegShape> relative_leg_shapes(
const PendingRelativeExit&,
2539 bool parent_long)
const;
2540 bool armed_relative_legs_adoptable(
const PlacementSnapshot& opening,
2541 const native_order::ExecutionAppliedEvent&,
2542 const std::vector<PendingRelativeExit>&)
const;
2547 double exit_limit_trigger(
double limit_price,
double tick,
bool exit_is_buy)
const noexcept;
2548 double one_shot_trail_trigger(
double activation,
double source_trail_offset,
double tick,
2549 bool exit_is_buy,
bool quantized_activation)
const noexcept;
2550 void materialize_pending_bracket_legs(
2551 const native_order::ExecutionAppliedEvent&);
2552 void stage_flat_children_before_parent(
const SourceId&, std::int32_t,
2554 bool defer_coof_tail() const noexcept;
2555 bool coof_fill_at_second_extreme() const noexcept;
2556 bool source_path_uses_high_first(const Bar&) const noexcept;
2557 bool coof_fill_on_path_point() const noexcept;
2558 bool coof_fill_at_path_point(
double waypoint) const noexcept;
2559 bool coof_waits_for_next_sub_bar() const noexcept;
2560 bool coof_current_fill_was_forced_waypoint() const noexcept;
2561 double coof_next_waypoint(
int* path_index =
nullptr) const noexcept;
2562 bool coof_remaining_recrosses(
double level,
bool long_position) const noexcept;
2563 bool coof_leg_reaches_exit(const PlacementSnapshot&) const noexcept;
2564 void flush_coof_tail(
bool openings_only = false,
2565 bool include_next_open = false);
2566 native_order::Owner owner_for_close(const
SourceId&,
bool dynamic) const;
2567 bool same_bar_market_tx_scope() const;
2568 bool fixed_unmargined_market_batch_scope() const;
2569 void reroute_fixed_entries_before_request(
bool invalidate_batch = true);
2570 std::
size_t accepted_entries_in_cycle(
bool is_long, const
SourceId&
id) const;
2571 bool opposite_entry_opening_pending(
bool is_long) const;
2572 void submit_entry_with_policy(native_order::Request request, PlacementSnapshot snapshot,
2573 const
SourceId&
id, const EntrySubmissionContext& context);
2574 void reroute_incomplete_fixed_batch(
bool invalidate_batch);
2575 void flush_pending_same_bar_commands(
bool flat_pair_follows = false,
2576 bool invalidate_batch = true);
2582 double default_sizing_units(const PineSizingSnapshot&) const;
2587 double default_sizing_cash(const PineSizingSnapshot&) const;
2588 bool default_sizing_reserves_percent_fee() const noexcept;
2592 bool default_sizing_reserves_cash_fee() const noexcept;
2593 double default_sizing_lot_floor(
double units) const noexcept;
2601 double typed_quantity_units(
double money,
bool percent,
double price,
double fx) const;
2602 std::optional<
double> typed_entry_units(const PlacementSnapshot&,
double price,
double fx,
2603 native_order::RequestHandle target) const;
2608 std::optional<native_order::Sized> default_sizing_shape(
2609 const PineSizingSnapshot&) const;
2610 std::optional<native_order::Sized> default_sizing_intent(
2611 const PineSizingSnapshot&,
bool is_long) const;
2617 bool core_sizing_price_matches(const PineSizingSnapshot&,
bool is_long) const;
2618 double default_market_sizing_price(
double mark,
bool is_long) const noexcept;
2619 native_order::Trigger trigger_for(
double limit_price,
double stop_price) const;
2620 native_order::Group group_for(const std::
string&,
int, std::int64_t = 0) const;
2621 PineSizingSnapshot sizing_snapshot() const;
2622 std::uint64_t key_for(const
SourceId&, const
SourceId& = {})
const noexcept;
2623 void refresh_pending_view() noexcept;
2624 OrderBirth capture_order_birth() const;
2626 void initialize_l4c_policy(PlacementSnapshot&, native_order::RequestHandle);
2627 void update_l4c_priority();
2628 void update_l4c_lifecycle(const native_order::ExecutionAppliedEvent&,
2629 const NativeDecisionContext&);
2630 using ReceiptHighWaterReader = std::uint64_t (*)(const NativeStrategyHost&) noexcept;
2637 std::uint64_t terminal_receipt_cursor_ = 0;
2646 ReceiptHighWaterReader event_high_water_reader_ =
nullptr;
2647 ReceiptHighWaterReader terminal_receipt_high_water_reader_ =
nullptr;
2648 bool is_declined_market_reversal(
2649 const native_order::MatchRejectedEvent&) const noexcept;
2650 bool follows_same_bar_declined_reversal(
2651 const PlacementSnapshot&, const NativePrecommitView&) const;
2652 bool bracket_belongs_to_reversal(
2653 const PlacementSnapshot&, const PlacementSnapshot&) const;
2654 void suspend_brackets_for_reversal(
2655 const PlacementSnapshot&, const exit_legs::Frame&,
double open_price);
2656 void suspend_declined_reversal_brackets(
2657 const native_order::MatchRejectedEvent&);
2658 bool reissue_revives_declined_exit(const PlacementSnapshot&) const noexcept;
2659 void suspend_coof_declined_reversal_at_open(
2660 const Bar&, const NativeDecisionContext&);
2661 void hold_reversal_pair_brackets(const
SourceId&);
2668 void retire_cancelled_exits(
2670 const std::vector<std::pair<std::uint64_t, std::uint64_t>>& cancelled);
2671 void purge_brackets_after_applied_reversal(const PlacementSnapshot&);
2672 void revive_brackets_after_margin(
2673 const native_order::ExecutionAppliedEvent&, const NativeDecisionContext&);
2674 int projected_pending_size() const noexcept;
2675 bool projected_pending_at(
int index, const PlacementSnapshot*& snapshot,
2676 native_order::RequestHandle& handle) const noexcept;
2677 int projected_raw_pending_size() const noexcept;
2678 bool projected_raw_pending_at(
int index, const PlacementSnapshot*& snapshot,
2679 native_order::RequestHandle& handle) const noexcept;
2680 static
bool same_projected_order(const PlacementSnapshot& left,
2681 const PlacementSnapshot& right) noexcept;
2682 void apply_open_market_admission(const NativeDecisionContext&);
2683 void defer_open_marketable_sells(const Bar& bar);
2684 void admit_deferred_open_marketable_sells();
2685 void rearm_throttled_reopens();
2688 void retune_carried_trails_for_tick_reach(const Bar&, const NativeDecisionContext&);
2689 void restore_carried_trail_retunes();
2690 void flush_pooc_marketable_limit_entry_fills(const Bar&, const NativeDecisionContext&);
2693 void fill_pooc_close_entries(
double raw_close, const NativeDecisionContext&,
2695 void flush_pooc_marketable_exit_fills(const Bar&, const NativeDecisionContext&);
2698 void fill_pooc_close_exits(
double raw_close, const NativeDecisionContext&);
2699 bool pooc_close_market_pending(const NativeDecisionContext&) const;
2700 bool pooc_close_entry_immediate_pending(const NativeDecisionContext&,
2701 const native_order::RequestHandle* except) const;
2704 bool fill_time_global_exit(const PlacementSnapshot&) const;
2707 bool per_entry_exit_scope() const;
2708 detail::ExitScratchRows<PerEntryExitChild> per_entry_open_entries(
bool long_side) const;
2709 detail::ExitScratchRows<native_order::RequestHandle> per_entry_child_legs(
2710 const
SourceId& exit_id, std::uint64_t origin) const;
2711 bool per_entry_exit_call(const
SourceId& exit_id, const
SourceId& from_entry,
double limit,
2712 double stop,
double trail_points,
double trail_offset,
2713 double trail_price,
double qty_percent, const std::
string& comment,
2714 double qty, const std::
string& oca_name,
double profit_ticks,
2715 double loss_ticks, std::uint64_t command_sequence);
2716 void submit_per_entry_child(const PerEntryExit&
exit, const PerEntryExitChild& child,
2717 std::uint64_t command_sequence);
2718 void per_entry_exits_at_entry_fill(const PlacementSnapshot& opening,
2719 const native_order::ExecutionAppliedEvent& event);
2720 void per_entry_exits_after_fill(const std::optional<PlacementSnapshot>& placement,
2721 const native_order::ExecutionAppliedEvent& event);
2722 void end_per_entry_exit(std::
size_t index);
2723 void cancel_working_legs(
2724 const detail::ExitScratchRows<native_order::RequestHandle>& legs);
2725 void order_per_entry_point_ties();
2726 void record_market_review(admission::Checkpoint,
int,
2727 const std::vector<native_order::RequestHandle>&);
2728 void refresh_pending_sizing_after_margin(
2729 const native_order::ExecutionAppliedEvent&, const NativeDecisionContext&);
2730 void apply_reversal_gap_bracket_policy(
2731 const Bar&, const NativeDecisionContext&,
bool defer_trails = false);
2732 void reaccept_gapped_bracket_behind_same_id_add(
2733 const Bar&, const NativeDecisionContext&);
2734 void order_open_marketable_limit_entries(const Bar&, const NativeDecisionContext&);
2735 void apply_terminal_explicit_market_policy(const NativeDecisionContext&);
2736 void apply_terminal_explicit_market_policy(const NativeDecisionContext&,
bool execute_now);
2737 bool enqueue_pooc_fifo_close(const
SourceId&, const std::
string&,
2738 std::uint64_t, std::uint64_t);
2739 void observe_close_ledger(const native_order::ExecutionAppliedEvent&,
2740 const PlacementSnapshot*);
2741 bool entry_order_pending(const
SourceId&) const;
2742 bool entry_order_working(const
SourceId*
id) const;
2743 bool priced_entry_order_working(const
SourceId*
id) const;
2744 bool margins_disabled() const noexcept;
2745 bool whole_level_exit(
double limit_price,
double stop_price,
double trail_points,
2746 double trail_price,
double profit_ticks,
double loss_ticks,
double qty,
2747 double qty_percent) const noexcept;
2748 bool open_lot_of(const
SourceId&
id) const;
2749 bool standing_exit(const
SourceId& exit_id, const
SourceId& from_entry) const;
2750 void unvoid_exit(PlacementSnapshot& row);
2751 void execute_or_withdraw_close(native_order::RequestHandle
close,
bool void_issue);
2752 void withdraw_void_exits(const
SourceId& entry_id);
2753 void settle_void_global_exits(
bool market_entry);
2754 void bind_pending_exits_to_fill(const
SourceId& entry_id);
2755 void withdraw_unplaced_cap_adds(const NativeDecisionContext& context);
2756 void stash_id_bound_exits(const
SourceId& entry_id);
2757 void rearm_id_bound_exits(const
SourceId& entry_id);
2758 void place_entry(const
SourceId&
id,
bool is_long,
double limit_price,
double stop_price,
2759 double qty, const std::
string& comment, const std::
string& oca_name,
2760 int oca_type,
int qty_type);
2761 void credit_close_ledger(const
SourceId&,
double units);
2762 void book_close_ledger(const
SourceId&,
double units);
2765 NativeStrategyHost* host_ =
nullptr;
2766 mutable std::shared_ptr<detail::ExitScratchContext> exit_scratch_;
2769 mutable std::shared_ptr<detail::CommandScratchRun> trade_scratch_run_;
2770 mutable std::shared_ptr<detail::CommandScratchRun> dependency_scratch_run_;
2772 PineStrategyConfig config_{};
2773 StagedConfiguration staged_{};
2774 mutable std::uint64_t run_counter_ = 0;
2775 std::uint64_t source_sequence_ = 0;
2776 std::uint64_t command_ordinal_ = 0;
2777 std::uint64_t broker_open_epoch_ = 0;
2778 std::int64_t last_broker_open_ms_ = std::numeric_limits<std::int64_t>::min();
2779 std::uint64_t source_command_sequence_ = 0;
2780 std::int32_t entry_attempt_bar_ = -1;
2781 std::uint32_t entry_attempts_on_bar_ = 0;
2788 std::unordered_map<std::uint64_t, detail::LiveSourceHandle> live_by_source_key_;
2789 std::unordered_map<std::uint64_t, BracketRoster> bracket_families_;
2794 std::unordered_map<std::uint64_t, BracketRoster::Settled> settled_bracket_families_;
2795 std::uint64_t settled_bracket_digest_ = 0;
2796 BracketRoster& bracket_family(std::uint64_t key);
2797 void archive_settled_bracket_families();
2798 void clear_bracket_families() noexcept;
2799 std::vector<PendingBracketLeg> pending_bracket_legs_;
2800 std::vector<PendingEntry> pending_entries_;
2801 std::vector<DelayedMarketOrder> delayed_market_orders_;
2802 std::vector<DeferredOpenMarketableSell> deferred_open_marketable_sells_;
2805 mutable std::vector<PlacementSnapshot> throttled_reopen_rearm_;
2806 int entry_openings_interval_index_ = -1;
2807 int entry_openings_this_interval_ = 0;
2808 std::vector<PendingSameBarCommand> pending_same_bar_commands_;
2809 std::vector<SourceShadowPending> source_shadow_pending_;
2810 double pending_same_bar_close_qty_ = 0.0;
2811 std::vector<PendingRelativeExit> pending_relative_exits_;
2814 mutable std::vector<AnchoredRelativeLeg> anchored_relative_legs_;
2816 std::int64_t anchored_cohort_sequence_ = 0;
2817 std::vector<PerEntryExit> per_entry_exits_;
2818 std::vector<PendingCoofRequest> pending_coof_requests_;
2819 std::vector<PendingMarginRevival> pending_margin_revivals_;
2820 std::vector<native_order::RequestHandle> live_handles_;
2821 std::vector<native_order::RequestHandle> first_open_newborns_;
2825 std::uint64_t dropped_close_count_ = 0;
2826 std::uint64_t dropped_close_digest_ = 1469598103934665603ULL;
2827 std::vector<OpenEntryFeeFact> open_entry_fees_;
2832 std::unordered_set<std::uint64_t> current_debited_applied_ordinals_;
2833 std::unordered_set<std::uint64_t> intraday_loss_relabel_ordinals_;
2834 pineforge::detail::IdPairStore<std::int64_t, true> consumed_partial_exit_cycles_{
2836 std::unordered_set<std::uint64_t> bracket_shadowed_openings_;
2837 std::unordered_map<SourceId, NamedEntryCancelToken> named_entry_cancel_tokens_;
2843 struct IdBoundExit {
2846 PineExitLevels levels;
2847 double qty_percent = std::numeric_limits<double>::quiet_NaN();
2848 double qty = std::numeric_limits<double>::quiet_NaN();
2849 std::string comment;
2850 std::string oca_name;
2852 std::vector<IdBoundExit> id_bound_exits_;
2857 std::map<SourceId, double> close_logical_units_;
2858 std::vector<CloseLedgerRecord> close_ledger_records_;
2862 struct PyramidingRecord {
2864 std::uint64_t incarnation = 0;
2867 std::vector<PyramidingRecord> pyramiding_records_;
2870 std::unordered_map<SourceId, std::uint64_t> exit_tombstones_;
2871 std::map<std::uint64_t, CloseCallsiteState> close_batch_callsites_;
2872 std::int32_t close_batch_bar_ = -1;
2873 std::uint64_t close_batch_queue_sequence_ = 0;
2874 double close_batch_pending_debt_ = 0.0;
2875 double close_batch_admitted_total_ = 0.0;
2876 std::uint64_t receipt_cursor_ = 0;
2877 std::uint64_t last_applied_ordinal_ = 0;
2878 bool materializing_relative_ =
false;
2881 native_order::RequestHandle materializing_parent_{};
2882 std::int64_t current_position_cycle_ = 0;
2883 int current_position_sign_ = 0;
2884 std::uint64_t next_sequential_group_ = 0;
2885 bool source_batch_mutated_ =
false;
2886 bool coof_recalc_active_ =
false;
2887 bool coof_first_open_ =
false;
2888 bool coof_open_stop_next_waypoint_ =
false;
2893 bool coof_fill_forced_ =
false;
2894 std::uint64_t coof_market_entry_recalc_incarnation_ = 0;
2895 std::uint64_t coof_market_entry_recalc_fill_seq_ = 0;
2896 std::uint64_t coof_current_fill_seq_ = 0;
2897 double coof_fill_cursor_t_ = std::numeric_limits<double>::quiet_NaN();
2898 double coof_fill_target_print_ = std::numeric_limits<double>::quiet_NaN();
2899 NativeDecisionContext coof_context_{};
2900 Bar coof_script_bar_{};
2901 bool coof_script_bar_valid_ =
false;
2905 std::int64_t pooc_close_basis_last_bar_ = std::numeric_limits<std::int64_t>::min();
2906 std::uint64_t pooc_close_basis_count_ = 0;
2907 std::uint64_t pooc_close_basis_digest_ = 1469598103934665603ULL;
2908 double pooc_open_basis_ = 0.0;
2909 std::int64_t pooc_open_script_bar_ = std::numeric_limits<std::int64_t>::min();
2910 std::int64_t close_all_pending_script_bar_ = std::numeric_limits<std::int64_t>::min();
2914 std::int64_t close_first_script_bar_ = std::numeric_limits<std::int64_t>::min();
2915 std::int32_t close_first_side_ = 0;
2916 double last_fx_rate_ = std::numeric_limits<double>::quiet_NaN();
2917 std::int64_t position_open_script_bar_ = std::numeric_limits<std::int64_t>::min();
2918 std::uint64_t position_open_epoch_ = 0;
2919 std::int32_t position_open_bar_index_ = -1;
2921 bool position_open_priced_ =
false;
2922 std::int64_t last_margin_call_script_bar_ = std::numeric_limits<std::int64_t>::min();
2936 std::uint64_t kernel_margin_path_point_ = std::numeric_limits<std::uint64_t>::max();
2944 std::uint64_t kernel_margin_resize_point_ = std::numeric_limits<std::uint64_t>::max();
2951 std::uint64_t close_margin_point_ = std::numeric_limits<std::uint64_t>::max();
2952 std::int64_t close_margin_cancelled_bar_ = std::numeric_limits<std::int64_t>::min();
2956 std::int64_t close_margin_follow_up_bar_ = std::numeric_limits<std::int64_t>::min();
2957 double close_margin_follow_up_units_ = 0.0;
2962 std::int64_t waypoint_chain_bar_ = std::numeric_limits<std::int64_t>::min();
2967 std::int64_t close_margin_open_bar_ = std::numeric_limits<std::int64_t>::min();
2973 std::int64_t pooc_close_checkpoint_deferred_ms_ = std::numeric_limits<std::int64_t>::min();
2974 std::int32_t signal_close_mc_event_bar_ = -1;
2975 std::int64_t signal_close_mc_position_cycle_ = 0;
2976 std::uint64_t signal_close_mc_entry_incarnation_ = 0;
2977 std::uint64_t signal_close_mc_fill_seq_ = 0;
2978 double signal_close_mc_before_qty_ = std::numeric_limits<double>::quiet_NaN();
2979 double signal_close_mc_remaining_qty_ = std::numeric_limits<double>::quiet_NaN();
2980 std::uint64_t last_margin_call_event_ordinal_ = 0;
2981 std::uint64_t last_margin_call_entry_incarnation_ = 0;
2982 std::int64_t last_margin_call_position_cycle_ = 0;
2983 bool last_margin_call_at_script_close_ =
false;
2984 double last_margin_call_closed_units_ = 0.0;
2985 double last_margin_call_remaining_units_ = 0.0;
2988 double source_gains_ = 0.0;
2989 double source_losses_ = 0.0;
2990 std::uint64_t source_money_folded_ = 0;
2991 std::int64_t risk_coof_direct_script_bar_ = std::numeric_limits<std::int64_t>::min();
2992 std::uint64_t cap_latest_fill_ = 0;
2993 bool source_margin_call_enabled_ =
true;
2994 Bar policy_script_bar_{};
2995 bool policy_script_bar_valid_ =
false;
2996 std::unordered_set<std::uint64_t> market_pyramid_adds_;
2997 std::unordered_map<std::uint64_t, NativeTrailState> trail_state_at_open_;
3000 std::vector<std::pair<native_order::RequestHandle, double>> carried_trail_retunes_;
3001 bool stream_mode_ =
false;
3002 SourceDayLedger day_ledger_{};
3003 PineRiskState risk_{};
3004 ShortSeedPlan short_seed_{};
3005 PendingShortSeedPlan pending_short_seed_{};
3006 native_order::RequestHandle short_seed_long_candidate_{};
3007 int last_bar_dual_entry_path_ = 0;
3008 std::int64_t last_bar_dual_entry_script_open_ms_ =
3009 std::numeric_limits<std::int64_t>::min();
3011 ::pineforge::detail::ScratchSequence<std::uint8_t> trade_exit_phase_;
3022 struct ExitGroupCertificate {
3024 std::size_t base = 0, start = 0, end = 0;
3025 bool rows_valid =
false;
3026 } exit_group_certificate_;
3027 ExitGroupWork exit_group_work_{};
3028 bool exit_group_certified(
const TradeLedger&)
const noexcept;
3029 void invalidate_exit_group(std::size_t first, std::size_t count = 1) noexcept;
3030 void certify_exit_group(const
TradeLedger&,
std::
size_t start,
bool ordered = true);
3031 void finish_exit_group_sort(::
pineforge::
detail::CommandScratchStore&,
3040 std::uint64_t exit_rank_keys_digest_ = 1469598103934665603ULL;
3041 std::uint32_t exit_rank_peak_ = 0;
3042 std::uint32_t exit_rank_alt_peak_ = 0;
3043 void require_tree_precommit(
const NativePrecommitView&)
const;
3044 void require_exit_rank_key(
const SourceId&)
const;
3045 void note_exit_rank_key(
const SourceId&);
3046 void note_exit_rank_transients();
3050 std::size_t exit_phase_final_ = 0;
3051 std::uint64_t exit_phase_digest_ = 1469598103934665603ULL;
3057 mutable std::size_t admission_events_folded_ = 0;
3058 mutable std::uint64_t admission_events_last_ = 0;
3059 mutable std::uint64_t admission_events_digest_ = 1469598103934665603ULL;
3065 std::int64_t owed_follow_up_bar_ = std::numeric_limits<std::int64_t>::min();
3066 std::int32_t owed_follow_up_point_ = -1;
3067 double owed_follow_up_units_ = 0.0;
3072 std::int64_t close_call_after_script_bar_ = std::numeric_limits<std::int64_t>::min();
3073 double close_call_after_script_book_ = 0.0;
3074 double close_call_after_script_units_ = 0.0;
3080 std::int64_t open_exit_first_bar_ = std::numeric_limits<std::int64_t>::min();
3081 std::uint64_t open_exit_first_origin_ = 0;
3083 double open_exit_first_fill_ = 0.0;
3091 std::size_t cohort_opened_slot_count_ = 0;
3092 bool fixture_verify_source_entry_slots_ =
false;
3093 bool fixture_bracket_remove_precheck_ =
true;
3102 bool open_call_sequence_ =
false;
3103 std::vector<std::uint64_t> unrepeated_margin_calls_;
3107 bool bar_magnifier_ =
false;
3112 mutable const NativeStrategyHost* pine_view_host_ =
nullptr;
3120 struct RetiredRowScratch {
3121 std::vector<std::uint64_t> roots;
3122 std::vector<std::uint64_t> askable_origins;
3123 std::vector<std::uint64_t> live_groups;
3124 std::vector<std::int32_t> source_bars;
3125 std::vector<std::pair<std::uint64_t, const PlacementSnapshot*>> candidates;
3126 std::vector<std::uint64_t> candidate_names;
3127 std::vector<std::uint64_t> first_reissues;
3128 std::vector<const PlacementSnapshot*> origin_pins;
3129 std::vector<std::uint64_t> doomed;
3138 std::vector<HeldLeg> held;
3139 std::vector<std::uint64_t> released;
3145 std::vector<std::pair<std::uint64_t, std::uint64_t>> unsuperseded;
3150 std::uint64_t reissue_high_water = 0;
3151 std::int64_t reissue_cycle = -1;
3152 std::vector<std::pair<std::uint64_t, std::uint64_t>> reissues;
3153 std::vector<std::pair<std::uint64_t, std::uint64_t>> next_reissues;
3154 std::vector<std::size_t> new_candidates;
3155 std::vector<std::size_t> known_candidates;
3156 std::vector<std::size_t> unresolved_candidates;
3160 std::vector<std::uint64_t> adopted_reissues;
3168 std::vector<std::uint64_t> working_roots;
3169 std::vector<std::uint64_t> lot_openings;
3170 std::vector<std::uint64_t> successor_lots;
3171 std::vector<std::pair<native_order::CohortHandle, std::uint64_t>> released_origins;
3173 bool roster_pass_due =
true;
3178 static constexpr std::size_t family_count =
3180 static constexpr std::size_t market_order_slot = family_count;
3181 static constexpr std::size_t exit_policy_slot = family_count + 1;
3182 std::size_t live_families[family_count + 2]{};
3186 bool origin_fronts_pinned =
true;
3187 void clear() noexcept {
3189 askable_origins.clear();
3190 live_groups.clear();
3191 source_bars.clear();
3193 candidate_names.clear();
3194 first_reissues.clear();
3195 origin_pins.clear();
3199 next_reissues.clear();
3200 new_candidates.clear();
3201 known_candidates.clear();
3202 unresolved_candidates.clear();
3205 RetiredRowScratch retired_row_scratch_;
3206 void remember_live(
const native_order::RequestHandle&, PlacementSnapshot&&);
3207 void forget_live(
const native_order::RequestHandle&)
noexcept;
3208 void requeue_live(
const native_order::RequestHandle&);
3209 void clear_live() noexcept;
3210 void erase_placement(
std::uint64_t);
3211 void count_live(const PlacementSnapshot&,
bool adding) noexcept;
3212 void assert_live_counts() const noexcept;
3214 bool has_live_exit_policy() const noexcept;
3215 bool has_live_trail_policy() const noexcept;
3223 struct StagedScopeFacts {
3224 bool positive_grid =
false;
3225 bool unit_grid =
false;
3226 bool unit_point_money =
false;
3227 bool unit_money =
false;
3228 bool mintick =
false;
3230 StagedScopeFacts staged_scopes_{};
3231 bool lot_grid_pinned_ =
false;
3232 bool gain_loss_configured_ =
false;
3233 bool slipped_long_configured_ =
false;
3234 bool unified_configured_ =
false;
3235 bool ledger_records_configured_ =
false;
3236 bool pooc_fee_configured_ =
false;
3237 void refresh_configuration_scopes(
const PineStrategyConfig& config)
noexcept;
3240 void order_same_point_entries();
3241 double pending_opposite_market_units(
bool is_long, std::int64_t script_open_ms,
const SourceId&
id)
const;
3244 bool same_point_pair_scope()
const;
3245 bool same_point_two_leg_book(
const SourceId&
id, std::int64_t script_open_ms)
const;
3246 bool same_point_pair_fill_follows(
const PlacementSnapshot& filled,
3247 const native_order::RequestHandle& filled_handle,
3248 double price)
const;
3250 bool fill_pooc_close_pair(
double raw_close,
const NativeDecisionContext& context);
3251 void finish_admission_bar();
3252 void on_bar_close_policy(
const Bar&,
const NativeDecisionContext&);
3253 void fold_admission_events()
const;
3254 std::uint64_t checked_live_key(
const SourceId&)
const;
3255 detail::LiveSourceHandle live_source_value(native_order::RequestHandle,
const SourceId&)
const;
3256 void cancel_reversal_exit_owners(
const std::vector<SourceId>& preserved,
3257 detail::ExitScratchRows<SourceId>& selection);
3259 mutable std::uint64_t projected_raw_pending_calls_ = 0;
3262 std::uint64_t pending_projection_version_ = 0;
3263 mutable std::uint64_t projected_pending_version_ = 0;
3264 mutable std::uint64_t projected_placement_version_ = 0;
3265 mutable bool projected_pending_valid_ =
false;
3266 mutable std::vector<int> projected_pending_indexes_;
3267 mutable std::vector<int> projected_pending_next_;
3268 bool ensure_projected_pending_index()
const;
3269 int projected_pending_next(
int index)
const noexcept;
3270 int projected_raw_pending_next(
int raw)
const noexcept;
3271 int projected_level_resolved(
const PlacementSnapshot&)
const noexcept;
3274 template<
class Row> Row& pending_write(Row& row)
noexcept {
3275 refresh_pending_view();
3279 static bool scan_projected_pending_at(
3281 native_order::RequestHandle&,
int* raw_index =
nullptr) noexcept;
3303 std::uint64_t
m = 0,
R = 0,
C = 0;
3311 RetirementWork retirement_work_{};
3312 struct RetirementObservation {
3314 RetirementWork& work;
3315 std::uint64_t slots, restored, spilled, spill_visits;
3317 : RetirementObservation(owner, owner.retirement_work_) {}
3319 : adapter(owner), work(destination), slots(owner.placement_.visited_slots()),
3320 restored(owner.cohorts_by_id_.work_counters().rows_restored),
3321 spilled(owner.cohorts_by_id_.work_counters().rows_spilled),
3322 spill_visits(owner.cohorts_by_id_.work_counters().rows_visited_by_spill) {}
3323 ~RetirementObservation() {
3324 const auto& backing = adapter.cohorts_by_id_.work_counters();
3325 work.placement_slots += adapter.placement_.visited_slots() - slots;
3326 work.backing_rows_restored += backing.rows_restored - restored;
3327 work.backing_rows_spilled += backing.rows_spilled - spilled;
3328 work.spill_rows_visited += backing.rows_visited_by_spill - spill_visits;
3333 struct RetirementInputs {
3334 std::vector<std::uint64_t> roots, askable, groups, marks;
3335 std::vector<std::int32_t> bar_numbers;
3336 bool operator==(
const RetirementInputs& other)
const noexcept {
3337 return roots == other.roots && askable == other.askable
3338 && groups == other.groups && marks == other.marks && bar_numbers == other.bar_numbers;
3341 struct RetirementGate {
3342 RetirementInputs saved, current;
3343 bool certified =
false;
3344 std::int64_t cycle = -1, interval = -1;
3345 std::int64_t broker_open = std::numeric_limits<std::int64_t>::min();
3346 std::int64_t interval_expiry = std::numeric_limits<std::int64_t>::max();
3347 std::int64_t broker_expiry = std::numeric_limits<std::int64_t>::max();
3349 RetirementGate retirement_gate_;
3350 void invalidate_retirement() noexcept { retirement_gate_.certified =
false; }
3351 bool capture_retirement_inputs(RetirementInputs&)
const;
3352 void observe_retirement_expiry(
const PlacementSnapshot&, std::int64_t interval)
noexcept;
3353 void sweep_retired_rows(
const NativeDecisionContext&,
RetirementWork&);
3354 void finish_retirement_phases();
3356 std::array<std::uint64_t, 3> retirement_validation_state()
const;