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();
2173 bool void_global =
false;
2187 struct AnchoredRelativeLeg {
2191 native_order::RequestHandle handle{};
2192 native_order::RequestHandle parent{};
2193 bool parent_long =
true;
2196 double operand_ticks = 0.0;
2197 double trail_offset = std::numeric_limits<double>::quiet_NaN();
2198 native_order::Request request;
2200 double installed_level = std::numeric_limits<double>::quiet_NaN();
2210 struct PerEntryExitChild {
2211 std::uint64_t origin = 0;
2212 double fill_price = std::numeric_limits<double>::quiet_NaN();
2214 bool consumed =
false;
2216 struct PerEntryExit {
2218 std::int64_t cycle = 0;
2219 bool long_side =
true;
2220 double profit_ticks = std::numeric_limits<double>::quiet_NaN();
2221 double loss_ticks = std::numeric_limits<double>::quiet_NaN();
2222 std::string comment;
2223 std::vector<PerEntryExitChild> children;
2226 struct PendingCoofRequest {
2227 native_order::Request request;
2228 PlacementSnapshot snapshot;
2230 bool opening =
false;
2231 std::uint64_t family_key = 0;
2232 bool next_open =
false;
2235 struct PendingMarginRevival {
2236 PlacementSnapshot snapshot;
2237 std::int32_t decline_bar = -1;
2240 struct NamedEntryCancelToken {
2241 std::uint64_t entry_incarnation = 0;
2242 std::uint64_t surviving_exit_incarnation = 0;
2248 struct CloseCallsiteState {
2249 bool active =
false;
2250 std::uint64_t token = 0;
2254 std::string comment{};
2255 double target = 0.0;
2256 std::uint64_t queue_sequence = 0;
2262 struct CloseLedgerRecord {
2267 NativeStrategyHost& require_host()
const;
2268 bool modeled_input()
const;
2269 void require_cohort_ticket(
const SourceId* prospective =
nullptr)
const;
2270 native_order::CohortHandle cohort_for(
const SourceId&
id);
2271 std::optional<native_order::RequestHandle> submit_or_replace(
2272 native_order::Request request, PlacementSnapshot snapshot,
bool opening,
2273 const SourceId& replacement_key = {});
2274 void remember(
const native_order::RequestHandle&, PlacementSnapshot&&);
2275 void retire(native_order::RequestHandle)
noexcept;
2278 void erase_retired_rows(
const NativeDecisionContext&);
2281 void retire_origin_prefixes();
2282 void release_closed_cohort_origins();
2283 bool lifecycle_readable(
const PlacementSnapshot&)
const noexcept;
2286 void set_exit_phase(std::size_t trade_index, std::uint8_t phase);
2287 std::vector<native_order::RequestHandle> openings_for(
const SourceId&)
const;
2288 double cohort_exposure_for(
const SourceId&)
const noexcept;
2289 double cohort_exposure_for(
const CohortFacts&)
const noexcept;
2291 std::optional<double> from_entry_units(
const SourceId&)
const noexcept;
2292 bool from_entry_filled_this_cycle(
const SourceId&)
const;
2293 double percent_commission_live_equity(
double)
const noexcept;
2297 double percent_commission_live_equity(
double, std::optional<double> fx)
const noexcept;
2300 double strategy_equity_at(
double mark, std::optional<double> fx)
const noexcept;
2304 void mark_sizing_equity(PineSizingSnapshot&,
double mark,
2305 std::optional<double> fx = std::nullopt)
const noexcept;
2306 double quantize_close_units(
double basis,
double percent)
const noexcept;
2307 double quantize_percent_exit_units(
double requested,
2308 double available)
const noexcept;
2309 bool compute_exit_reservation(
const SourceId& exit_id,
2311 double requested_qty,
2312 double& qty_percent,
2314 double percentage_basis,
2315 double& reserved_qty)
const;
2316 void reconcile_deferred_exit_reservations(
const SourceId& from_entry,
2318 void reconcile_exit_reservations_after_margin();
2319 double active_staged_fx(std::int64_t)
const noexcept;
2320 void apply_fx_open_margin_slice(
const Bar&,
const NativeDecisionContext&);
2321 void apply_fx_opening_margin_slice(
const native_order::ExecutionAppliedEvent&,
2322 const NativeDecisionContext&);
2323 void schedule_preopen_margin_slice(
const Bar&,
const NativeDecisionContext&);
2324 bool leveraged_entry_bar_checked() const noexcept;
2325 bool preopen_slice_class(const PlacementSnapshot&,
2326 const NativeDecisionContext&) const noexcept;
2330 bool submit_margin_call_slice(
double mark_price, const NativeDecisionContext&,
2331 bool opening_checkpoint = false,
2332 std::optional<
double> resolved_execution_price = std::nullopt);
2333 bool submit_margin_call_units(
double mark_price, const NativeDecisionContext&,
2335 bool force_execution_price = true,
2336 std::optional<
double> resolved_execution_price = std::nullopt);
2337 bool submit_tv_money_long_margin_call(const Bar&, const NativeDecisionContext&,
2338 int* fired_waypoint =
nullptr);
2339 void fold_source_money();
2340 void fold_source_money_through(const
PineStrategyHost& pine, std::uint64_t count);
2341 bool gain_loss_regime() const;
2342 bool gain_loss_run_regime() const;
2343 double gain_loss_signal_equity(
double mark) const;
2344 double gain_loss_mirror_equity(
double mark) const;
2345 std::optional<
double> pooc_fee_units(const PineSizingSnapshot&) const;
2346 double tv_pooc_fee_grossed_unit(
double price) const;
2347 bool unified_admission_scope(const PlacementSnapshot&,
bool market_or_stop,
2348 double signed_units,
double units,
2349 bool beside_exits = false) const;
2350 bool unified_admission_terms(const PlacementSnapshot&, const NativeExecutionTermsFacts&,
2351 bool market_or_stop,
bool opposite,
2352 native_order::ExecutionTerms& result,
bool& admitted) const;
2353 bool unified_fill_admits(const PlacementSnapshot&,
double units,
double quote) const;
2354 void record_close_first(
bool whole_position);
2355 void credit_pyramiding_record(const
SourceId&
id, std::uint64_t incarnation,
double units);
2356 void book_pyramiding_records(const
SourceId&
id, std::uint64_t armed_for,
double units);
2357 std::optional<std::
size_t> open_ledger_records() const;
2358 std::optional<std::
size_t> held_ledger_records() const;
2359 std::uint64_t entry_incarnation_of(const
SourceId& from_entry) const;
2360 bool exit_tombstoned(const
SourceId& exit_id, const
SourceId& from_entry) const;
2361 bool unified_placement_book_clear() const;
2362 bool pinned_lot_grid() const;
2363 bool slipped_long_margin_scope() const;
2364 bool slipped_long_book_scope() const;
2365 double slipped_long_margin_units(
double quote) const;
2366 bool slipped_long_unit_shortfall(
double quote) const;
2367 bool close_all_at_next_point(
2368 const Bar&,
int fired,
2369 const std::vector<std::pair<native_order::RequestHandle, PlacementSnapshot>>& closes,
2370 const NativeDecisionContext&);
2371 bool slipped_pooc_opening_money_scope(
2372 const Bar&, const NativeDecisionContext&) const;
2373 bool submit_slipped_pooc_opening_money_call(
2374 const Bar&, const NativeDecisionContext&);
2375 bool schedule_tv_money_long_margin_before_trail(
2376 const Bar&, const NativeDecisionContext&);
2377 std::optional<std::int64_t> flat_sibling_placement(std::
size_t min_lots) const;
2378 bool flat_sibling_book(const PlacementSnapshot&, std::int32_t interval_index,
2380 bool flat_sibling_fill_follows(const PlacementSnapshot&,
2381 const native_order::RequestHandle&) const;
2382 bool add_sibling_fill_follows(const PlacementSnapshot&,
2383 const native_order::RequestHandle&) const;
2384 std::
size_t add_sibling_lots(std::int64_t placed) const;
2385 bool whole_unit_follow_up_due(
double called_units,
double mark) const;
2386 bool margin_follow_up_scope() const noexcept;
2387 double margin_follow_up_units(
double called_units,
double fill,
2388 std::int64_t sub_bar_open_ms) const;
2389 void follow_margin_call(
double called_units,
double fill,
double current,
2390 const NativeDecisionContext&);
2391 bool short_call_vetoed(const
SourceMarginMoney&,
double units,
bool opening_checkpoint,
2392 double print = std::numeric_limits<
double>::quiet_NaN()) const;
2396 bool close_sized_open_call_scope(
bool short_book,
bool several_lots = false) const;
2397 double close_sized_open_units(
double close_mark,
double print,
2398 std::int64_t sub_bar_open_ms) const;
2399 bool run_close_sized_open_calls(
double units,
double opening_mark,
2400 const NativeDecisionContext&);
2403 bool opening_released_leg(const PlacementSnapshot& row, std::uint64_t leg,
2404 std::uint64_t opening, const
SourceId&
id,
bool short_book,
2405 const NativeDecisionContext&) const;
2406 bool priced_exit_precedes_opening(
bool short_book, std::uint64_t opening,
2407 const
SourceId& opening_id, const NativeDecisionContext&,
2408 const PlacementSnapshot* filled,
bool* at_open) const;
2409 void run_opening_checkpoint(
double fill,
bool market,
bool sibling_book,
2410 bool adds_book_last, const NativeDecisionContext&);
2411 double open_print_follow_up_units(
double held_before,
double equity_before,
double entry,
2412 double called,
double fill,
bool short_book,
2413 std::int64_t sub_bar_open_ms) const;
2414 double open_print_lot_follow_up_units(const std::vector<std::pair<
double,
double>>& taken,
2415 double equity_before,
double held_before,
double fill,
2416 bool short_book, std::int64_t sub_bar_open_ms) const;
2417 bool lagged_short_scope() const noexcept;
2418 double lagged_short_follow_up_units(const std::vector<std::pair<
double,
double>>& taken,
2419 double equity_before,
double held_before,
double fill,
2420 std::int64_t sub_bar_open_ms) const;
2421 double call_short_with_lagged_follow_up(
double mark,
double units,
2422 const NativeDecisionContext&,
bool owed = false);
2423 bool whole_share_lag_scope() const noexcept;
2424 double whole_share_lag_units(const std::vector<std::pair<
double,
double>>& taken,
2425 double equity_before,
double held_before,
double fill,
2426 std::int64_t sub_bar_open_ms) const;
2427 bool open_call_owing_follow_up(
double opening_mark, const NativeDecisionContext&);
2428 bool short_path_points_scope(const NativeDecisionContext&) const;
2429 void execute_owed_short_follow_up(
int point,
double price, const NativeDecisionContext&);
2430 void hold_owed_close_follow_up(
double close, const NativeDecisionContext&);
2431 void book_owed_close_follow_up(const Bar&, const NativeDecisionContext&);
2432 void walk_short_path_points(const Bar&, const NativeDecisionContext&);
2433 void schedule_lagged_short_follow_up(const native_order::ExecutionAppliedEvent&,
2434 const NativeDecisionContext&);
2435 bool pending_veto_point_first(const Bar&, const NativeDecisionContext&,
double opening_mark);
2436 void record_close_call_after_script(
double book_before,
double called,
2437 const NativeDecisionContext&);
2438 void apply_frozen_reversal_close(const PlacementSnapshot&, const NativeExecutionTermsFacts&,
2439 native_order::ExecutionTerms&) const;
2440 native_order::ExecutionTerms resolve_source_terms(const NativeExecutionTermsFacts&) const;
2441 double gain_loss_closed_equity() const;
2442 bool declined_reversal_at_open(const Bar&) const;
2443 bool schedule_margin_call_path(const Bar&, const NativeDecisionContext&);
2444 bool schedule_priced_opening_margin(const Bar&, const NativeDecisionContext&,
double fill);
2445 bool close_point_margin_scope() const noexcept;
2446 void withdraw_waypoint_margin_calls();
2447 bool rest_waypoint_margin_call(const Bar&,
int from,
int to, const NativeDecisionContext&);
2448 bool close_point_margin_call(const Bar&, const NativeDecisionContext&,
bool cancelled);
2449 bool book_close_point_call(
double mark,
double units, const NativeDecisionContext&,
2450 bool queued,
double reference_mark = 0.0);
2451 void close_point_follow_up(
double mark,
double called_units, const NativeDecisionContext&);
2452 std::vector<std::pair<native_order::RequestHandle, PlacementSnapshot>>
2453 same_bar_close_alls(const NativeDecisionContext&) const;
2454 void size_close_alls_at_placement(
2455 std::vector<std::pair<native_order::RequestHandle, PlacementSnapshot>>&,
double placed);
2456 bool close_point_margin_call_at_open(const Bar&, const Bar& prior,
2457 const NativeDecisionContext&);
2460 void defer_declined_reversal_exits_at_adverse(const Bar&,
2461 const NativeDecisionContext&,
2462 bool margin_scheduled);
2463 bool intraday_loss_breached(
double mark_price) const;
2464 bool submit_intraday_loss_close(
double mark_price, const NativeDecisionContext&,
2465 bool execute_current);
2466 void schedule_intraday_loss_path(const Bar&, const NativeDecisionContext&);
2467 void update_risk_state(
double mark_price);
2468 bool intraday_loss_orders_blocked() const noexcept;
2469 compat::pine::CapClock cap_clock(const NativeDecisionContext&) const;
2470 compat::pine::Calculation cap_calculation(const NativeDecisionContext&) const;
2471 compat::pine::MatchedAttempt cap_attempt(
2472 const PlacementSnapshot&, std::uint64_t incarnation,
2473 const native_order::ExecutionAppliedEvent* applied =
nullptr) const;
2474 bool cap_placement_denied(const NativeDecisionContext&);
2475 void observe_intraday_cap(const native_order::ExecutionAppliedEvent&,
2476 const PlacementSnapshot&, const NativeDecisionContext&);
2477 void observe_intraday_cap_noop(
bool is_long, const NativeDecisionContext&);
2478 void execute_cap_close_now(const compat::pine::CloseNow&);
2479 void execute_due_cap_close(const NativeDecisionContext&);
2480 void maybe_activate_short_seed_plan();
2481 void activate_short_seed_plan_at_open(const NativeDecisionContext&);
2482 bool qualify_short_seed_plan(const ShortSeedPlan&) const;
2483 bool short_seed_context_is_live() const noexcept;
2484 void record_dropped_close(const
SourceId&, const std::
string&,
double,
double,
2485 bool, std::uint64_t);
2486 void record_opening_fee(const PlacementSnapshot&,
2487 const native_order::ExecutionAppliedEvent&);
2488 void consume_opening_fees(const native_order::ExecutionAppliedEvent&,
2490 void consume_cohort_units(const
SourceId&, const native_order::ExecutionAppliedEvent&);
2491 void consume_closed_trade_rows(const native_order::ExecutionAppliedEvent&,
2492 const PlacementSnapshot*);
2493 bool origin_is_pending(const native_order::RequestHandle&) const noexcept;
2498 std::vector<std::
size_t> live_origin_positions(const CohortFacts&) const;
2507 IExecutionConsumer* bound_consumer() const noexcept;
2509 bool cohort_opened_on_side(const CohortFacts&,
bool is_long) const noexcept;
2514 const native_order::RequestHandle& origin) const noexcept;
2516 bool immediate_close_placed_on(std::int32_t bar) const noexcept;
2517 void cancel_bracket_origin(native_order::RequestHandle);
2521 void cancel_bracket_siblings(native_order::RequestHandle, std::uint64_t executed_at = 0);
2522 void cancel_exit_orders_for_full_close(const
SourceId& from_entry);
2523 void cancel_exit_orders_for_full_close(const detail::ScratchByteSource& from_entry);
2524 void retire_in_position_exits_at_flat(
bool preserve_pending_parents,
2525 bool dormant_rows_only,
2526 const PlacementSnapshot* paired_close);
2527 void materialize_relative_exits(PlacementSnapshot,
2528 const native_order::ExecutionAppliedEvent&);
2529 void withdraw_anchored_relative_legs(const
SourceId* exit_id,
2531 void withdraw_anchored_relative_readers(const detail::ScratchByteSource* exit_id,
2532 const detail::ScratchByteSource* from_entry);
2533 bool anchorable_relative_exit(const PendingRelativeExit&,
2534 native_order::RequestHandle& parent,
2535 bool& parent_long) const;
2536 struct RelativeLegShape {
2539 double signed_ticks = 0.0;
2540 double operand_ticks = 0.0;
2542 std::vector<RelativeLegShape> relative_leg_shapes(
const PendingRelativeExit&,
2543 bool parent_long)
const;
2544 bool armed_relative_legs_adoptable(
const PlacementSnapshot& opening,
2545 const native_order::ExecutionAppliedEvent&,
2546 const std::vector<PendingRelativeExit>&)
const;
2551 double exit_limit_trigger(
double limit_price,
double tick,
bool exit_is_buy)
const noexcept;
2552 double one_shot_trail_trigger(
double activation,
double source_trail_offset,
double tick,
2553 bool exit_is_buy,
bool quantized_activation)
const noexcept;
2554 void materialize_pending_bracket_legs(
2555 const native_order::ExecutionAppliedEvent&);
2556 void stage_flat_children_before_parent(
const SourceId&, std::int32_t,
2558 bool defer_coof_tail() const noexcept;
2559 bool coof_fill_at_second_extreme() const noexcept;
2560 bool source_path_uses_high_first(const Bar&) const noexcept;
2561 bool coof_fill_on_path_point() const noexcept;
2562 bool coof_fill_at_path_point(
double waypoint) const noexcept;
2563 bool coof_waits_for_next_sub_bar() const noexcept;
2564 bool coof_current_fill_was_forced_waypoint() const noexcept;
2565 double coof_next_waypoint(
int* path_index =
nullptr) const noexcept;
2566 bool coof_remaining_recrosses(
double level,
bool long_position) const noexcept;
2567 bool coof_leg_reaches_exit(const PlacementSnapshot&) const noexcept;
2568 void flush_coof_tail(
bool openings_only = false,
2569 bool include_next_open = false);
2570 native_order::Owner owner_for_close(const
SourceId&,
bool dynamic) const;
2571 bool same_bar_market_tx_scope() const;
2572 bool fixed_unmargined_market_batch_scope() const;
2573 void reroute_fixed_entries_before_request(
bool invalidate_batch = true);
2574 std::
size_t accepted_entries_in_cycle(
bool is_long, const
SourceId&
id) const;
2575 bool opposite_entry_opening_pending(
bool is_long) const;
2576 void submit_entry_with_policy(native_order::Request request, PlacementSnapshot snapshot,
2577 const
SourceId&
id, const EntrySubmissionContext& context);
2578 void reroute_incomplete_fixed_batch(
bool invalidate_batch);
2579 void flush_pending_same_bar_commands(
bool flat_pair_follows = false,
2580 bool invalidate_batch = true);
2586 double default_sizing_units(const PineSizingSnapshot&) const;
2591 double default_sizing_cash(const PineSizingSnapshot&) const;
2592 bool default_sizing_reserves_percent_fee() const noexcept;
2596 bool default_sizing_reserves_cash_fee() const noexcept;
2597 double default_sizing_lot_floor(
double units) const noexcept;
2605 double typed_quantity_units(
double money,
bool percent,
double price,
double fx) const;
2606 std::optional<
double> typed_entry_units(const PlacementSnapshot&,
double price,
double fx,
2607 native_order::RequestHandle target) const;
2612 std::optional<native_order::Sized> default_sizing_shape(
2613 const PineSizingSnapshot&) const;
2614 std::optional<native_order::Sized> default_sizing_intent(
2615 const PineSizingSnapshot&,
bool is_long) const;
2621 bool core_sizing_price_matches(const PineSizingSnapshot&,
bool is_long) const;
2622 double default_market_sizing_price(
double mark,
bool is_long) const noexcept;
2623 native_order::Trigger trigger_for(
double limit_price,
double stop_price) const;
2624 native_order::Group group_for(const std::
string&,
int, std::int64_t = 0) const;
2625 PineSizingSnapshot sizing_snapshot() const;
2626 std::uint64_t key_for(const
SourceId&, const
SourceId& = {})
const noexcept;
2627 void refresh_pending_view() noexcept;
2628 OrderBirth capture_order_birth() const;
2630 void initialize_l4c_policy(PlacementSnapshot&, native_order::RequestHandle);
2631 void update_l4c_priority();
2632 void update_l4c_lifecycle(const native_order::ExecutionAppliedEvent&,
2633 const NativeDecisionContext&);
2634 using ReceiptHighWaterReader = std::uint64_t (*)(const NativeStrategyHost&) noexcept;
2641 std::uint64_t terminal_receipt_cursor_ = 0;
2650 ReceiptHighWaterReader event_high_water_reader_ =
nullptr;
2651 ReceiptHighWaterReader terminal_receipt_high_water_reader_ =
nullptr;
2652 bool is_declined_market_reversal(
2653 const native_order::MatchRejectedEvent&) const noexcept;
2654 bool follows_same_bar_declined_reversal(
2655 const PlacementSnapshot&, const NativePrecommitView&) const;
2656 bool bracket_belongs_to_reversal(
2657 const PlacementSnapshot&, const PlacementSnapshot&) const;
2658 void suspend_brackets_for_reversal(
2659 const PlacementSnapshot&, const exit_legs::Frame&,
double open_price);
2660 void suspend_declined_reversal_brackets(
2661 const native_order::MatchRejectedEvent&);
2662 bool reissue_revives_declined_exit(const PlacementSnapshot&) const noexcept;
2663 void suspend_coof_declined_reversal_at_open(
2664 const Bar&, const NativeDecisionContext&);
2665 void hold_reversal_pair_brackets(const
SourceId&);
2672 void retire_cancelled_exits(
2674 const std::vector<std::pair<std::uint64_t, std::uint64_t>>& cancelled);
2675 void purge_brackets_after_applied_reversal(const PlacementSnapshot&);
2676 void revive_brackets_after_margin(
2677 const native_order::ExecutionAppliedEvent&, const NativeDecisionContext&);
2678 int projected_pending_size() const noexcept;
2679 bool projected_pending_at(
int index, const PlacementSnapshot*& snapshot,
2680 native_order::RequestHandle& handle) const noexcept;
2681 int projected_raw_pending_size() const noexcept;
2682 bool projected_raw_pending_at(
int index, const PlacementSnapshot*& snapshot,
2683 native_order::RequestHandle& handle) const noexcept;
2684 static
bool same_projected_order(const PlacementSnapshot& left,
2685 const PlacementSnapshot& right) noexcept;
2686 void apply_open_market_admission(const NativeDecisionContext&);
2687 void defer_open_marketable_sells(const Bar& bar);
2688 void admit_deferred_open_marketable_sells();
2689 void rearm_throttled_reopens();
2692 void retune_carried_trails_for_tick_reach(const Bar&, const NativeDecisionContext&);
2693 void restore_carried_trail_retunes();
2694 void flush_pooc_marketable_limit_entry_fills(const Bar&, const NativeDecisionContext&);
2697 void fill_pooc_close_entries(
double raw_close, const NativeDecisionContext&,
2699 void flush_pooc_marketable_exit_fills(const Bar&, const NativeDecisionContext&);
2702 void fill_pooc_close_exits(
double raw_close, const NativeDecisionContext&);
2703 bool pooc_close_market_pending(const NativeDecisionContext&) const;
2704 bool pooc_close_entry_immediate_pending(const NativeDecisionContext&,
2705 const native_order::RequestHandle* except) const;
2708 bool fill_time_global_exit(const PlacementSnapshot&) const;
2711 bool per_entry_exit_scope() const;
2712 detail::ExitScratchRows<PerEntryExitChild> per_entry_open_entries(
bool long_side) const;
2713 detail::ExitScratchRows<native_order::RequestHandle> per_entry_child_legs(
2714 const
SourceId& exit_id, std::uint64_t origin) const;
2715 bool per_entry_exit_call(const
SourceId& exit_id, const
SourceId& from_entry,
double limit,
2716 double stop,
double trail_points,
double trail_offset,
2717 double trail_price,
double qty_percent, const std::
string& comment,
2718 double qty, const std::
string& oca_name,
double profit_ticks,
2719 double loss_ticks, std::uint64_t command_sequence);
2720 void submit_per_entry_child(const PerEntryExit&
exit, const PerEntryExitChild& child,
2721 std::uint64_t command_sequence);
2722 void per_entry_exits_at_entry_fill(const PlacementSnapshot& opening,
2723 const native_order::ExecutionAppliedEvent& event);
2724 void per_entry_exits_after_fill(const std::optional<PlacementSnapshot>& placement,
2725 const native_order::ExecutionAppliedEvent& event);
2726 void end_per_entry_exit(std::
size_t index);
2727 void cancel_working_legs(
2728 const detail::ExitScratchRows<native_order::RequestHandle>& legs);
2729 void order_per_entry_point_ties();
2730 void record_market_review(admission::Checkpoint,
int,
2731 const std::vector<native_order::RequestHandle>&);
2732 void refresh_pending_sizing_after_margin(
2733 const native_order::ExecutionAppliedEvent&, const NativeDecisionContext&);
2734 void apply_reversal_gap_bracket_policy(
2735 const Bar&, const NativeDecisionContext&,
bool defer_trails = false);
2736 void reaccept_gapped_bracket_behind_same_id_add(
2737 const Bar&, const NativeDecisionContext&);
2738 void order_open_marketable_limit_entries(const Bar&, const NativeDecisionContext&);
2739 void apply_terminal_explicit_market_policy(const NativeDecisionContext&);
2740 void apply_terminal_explicit_market_policy(const NativeDecisionContext&,
bool execute_now);
2741 bool enqueue_pooc_fifo_close(const
SourceId&, const std::
string&,
2742 std::uint64_t, std::uint64_t);
2743 void observe_close_ledger(const native_order::ExecutionAppliedEvent&,
2744 const PlacementSnapshot*);
2745 bool entry_order_pending(const
SourceId&) const;
2746 bool entry_order_working(const
SourceId*
id) const;
2747 bool priced_entry_order_working(const
SourceId*
id) const;
2748 bool margins_disabled() const noexcept;
2749 bool whole_level_exit(
double limit_price,
double stop_price,
double trail_points,
2750 double trail_price,
double profit_ticks,
double loss_ticks,
double qty,
2751 double qty_percent) const noexcept;
2752 bool open_lot_of(const
SourceId&
id) const;
2753 bool standing_exit(const
SourceId& exit_id, const
SourceId& from_entry) const;
2754 void unvoid_exit(PlacementSnapshot& row);
2755 void execute_or_withdraw_close(native_order::RequestHandle
close,
bool void_issue);
2756 void withdraw_void_exits(const
SourceId& entry_id);
2757 void settle_void_global_exits(
bool market_entry);
2758 void bind_pending_exits_to_fill(const
SourceId& entry_id);
2759 void withdraw_unplaced_cap_adds(const NativeDecisionContext& context);
2760 void stash_id_bound_exits(const
SourceId& entry_id);
2761 void rearm_id_bound_exits(const
SourceId& entry_id);
2762 void place_entry(const
SourceId&
id,
bool is_long,
double limit_price,
double stop_price,
2763 double qty, const std::
string& comment, const std::
string& oca_name,
2764 int oca_type,
int qty_type);
2765 void credit_close_ledger(const
SourceId&,
double units);
2766 void book_close_ledger(const
SourceId&,
double units);
2769 NativeStrategyHost* host_ =
nullptr;
2770 mutable std::shared_ptr<detail::ExitScratchContext> exit_scratch_;
2773 mutable std::shared_ptr<detail::CommandScratchRun> trade_scratch_run_;
2774 mutable std::shared_ptr<detail::CommandScratchRun> dependency_scratch_run_;
2776 PineStrategyConfig config_{};
2777 StagedConfiguration staged_{};
2778 mutable std::uint64_t run_counter_ = 0;
2779 std::uint64_t source_sequence_ = 0;
2780 std::uint64_t command_ordinal_ = 0;
2781 std::uint64_t broker_open_epoch_ = 0;
2782 std::int64_t last_broker_open_ms_ = std::numeric_limits<std::int64_t>::min();
2783 std::uint64_t source_command_sequence_ = 0;
2784 std::int32_t entry_attempt_bar_ = -1;
2785 std::uint32_t entry_attempts_on_bar_ = 0;
2792 std::unordered_map<std::uint64_t, detail::LiveSourceHandle> live_by_source_key_;
2793 std::unordered_map<std::uint64_t, BracketRoster> bracket_families_;
2798 std::unordered_map<std::uint64_t, BracketRoster::Settled> settled_bracket_families_;
2799 std::uint64_t settled_bracket_digest_ = 0;
2800 BracketRoster& bracket_family(std::uint64_t key);
2801 void archive_settled_bracket_families();
2802 void clear_bracket_families() noexcept;
2803 std::vector<PendingBracketLeg> pending_bracket_legs_;
2804 std::vector<PendingEntry> pending_entries_;
2805 std::vector<DelayedMarketOrder> delayed_market_orders_;
2806 std::vector<DeferredOpenMarketableSell> deferred_open_marketable_sells_;
2809 mutable std::vector<PlacementSnapshot> throttled_reopen_rearm_;
2810 int entry_openings_interval_index_ = -1;
2811 int entry_openings_this_interval_ = 0;
2812 std::vector<PendingSameBarCommand> pending_same_bar_commands_;
2813 std::vector<SourceShadowPending> source_shadow_pending_;
2814 double pending_same_bar_close_qty_ = 0.0;
2815 std::vector<PendingRelativeExit> pending_relative_exits_;
2818 mutable std::vector<AnchoredRelativeLeg> anchored_relative_legs_;
2820 std::int64_t anchored_cohort_sequence_ = 0;
2821 std::vector<PerEntryExit> per_entry_exits_;
2822 std::vector<PendingCoofRequest> pending_coof_requests_;
2823 std::vector<PendingMarginRevival> pending_margin_revivals_;
2824 std::vector<native_order::RequestHandle> live_handles_;
2825 std::vector<native_order::RequestHandle> first_open_newborns_;
2829 std::uint64_t dropped_close_count_ = 0;
2830 std::uint64_t dropped_close_digest_ = 1469598103934665603ULL;
2831 std::vector<OpenEntryFeeFact> open_entry_fees_;
2836 std::unordered_set<std::uint64_t> current_debited_applied_ordinals_;
2837 std::unordered_set<std::uint64_t> intraday_loss_relabel_ordinals_;
2838 pineforge::detail::IdPairStore<std::int64_t, true> consumed_partial_exit_cycles_{
2840 std::unordered_set<std::uint64_t> bracket_shadowed_openings_;
2841 std::unordered_map<SourceId, NamedEntryCancelToken> named_entry_cancel_tokens_;
2847 struct IdBoundExit {
2850 PineExitLevels levels;
2851 double qty_percent = std::numeric_limits<double>::quiet_NaN();
2852 double qty = std::numeric_limits<double>::quiet_NaN();
2853 std::string comment;
2854 std::string oca_name;
2856 std::vector<IdBoundExit> id_bound_exits_;
2861 std::map<SourceId, double> close_logical_units_;
2862 std::vector<CloseLedgerRecord> close_ledger_records_;
2866 struct PyramidingRecord {
2868 std::uint64_t incarnation = 0;
2871 std::vector<PyramidingRecord> pyramiding_records_;
2874 std::unordered_map<SourceId, std::uint64_t> exit_tombstones_;
2875 std::map<std::uint64_t, CloseCallsiteState> close_batch_callsites_;
2876 std::int32_t close_batch_bar_ = -1;
2877 std::uint64_t close_batch_queue_sequence_ = 0;
2878 double close_batch_pending_debt_ = 0.0;
2879 double close_batch_admitted_total_ = 0.0;
2880 std::uint64_t receipt_cursor_ = 0;
2881 std::uint64_t last_applied_ordinal_ = 0;
2882 bool materializing_relative_ =
false;
2885 native_order::RequestHandle materializing_parent_{};
2886 std::int64_t current_position_cycle_ = 0;
2887 int current_position_sign_ = 0;
2888 std::uint64_t next_sequential_group_ = 0;
2889 bool source_batch_mutated_ =
false;
2890 bool coof_recalc_active_ =
false;
2891 bool coof_first_open_ =
false;
2892 bool coof_open_stop_next_waypoint_ =
false;
2897 bool coof_fill_forced_ =
false;
2898 std::uint64_t coof_market_entry_recalc_incarnation_ = 0;
2899 std::uint64_t coof_market_entry_recalc_fill_seq_ = 0;
2900 std::uint64_t coof_current_fill_seq_ = 0;
2901 double coof_fill_cursor_t_ = std::numeric_limits<double>::quiet_NaN();
2902 double coof_fill_target_print_ = std::numeric_limits<double>::quiet_NaN();
2903 NativeDecisionContext coof_context_{};
2904 Bar coof_script_bar_{};
2905 bool coof_script_bar_valid_ =
false;
2909 std::int64_t pooc_close_basis_last_bar_ = std::numeric_limits<std::int64_t>::min();
2910 std::uint64_t pooc_close_basis_count_ = 0;
2911 std::uint64_t pooc_close_basis_digest_ = 1469598103934665603ULL;
2912 double pooc_open_basis_ = 0.0;
2913 std::int64_t pooc_open_script_bar_ = std::numeric_limits<std::int64_t>::min();
2914 std::int64_t close_all_pending_script_bar_ = std::numeric_limits<std::int64_t>::min();
2918 std::int64_t close_first_script_bar_ = std::numeric_limits<std::int64_t>::min();
2919 std::int32_t close_first_side_ = 0;
2920 double last_fx_rate_ = std::numeric_limits<double>::quiet_NaN();
2921 std::int64_t position_open_script_bar_ = std::numeric_limits<std::int64_t>::min();
2922 std::uint64_t position_open_epoch_ = 0;
2923 std::int32_t position_open_bar_index_ = -1;
2925 bool position_open_priced_ =
false;
2926 std::int64_t last_margin_call_script_bar_ = std::numeric_limits<std::int64_t>::min();
2940 std::uint64_t kernel_margin_path_point_ = std::numeric_limits<std::uint64_t>::max();
2948 std::uint64_t kernel_margin_resize_point_ = std::numeric_limits<std::uint64_t>::max();
2955 std::uint64_t close_margin_point_ = std::numeric_limits<std::uint64_t>::max();
2956 std::int64_t close_margin_cancelled_bar_ = std::numeric_limits<std::int64_t>::min();
2960 std::int64_t close_margin_follow_up_bar_ = std::numeric_limits<std::int64_t>::min();
2961 double close_margin_follow_up_units_ = 0.0;
2966 std::int64_t waypoint_chain_bar_ = std::numeric_limits<std::int64_t>::min();
2971 std::int64_t close_margin_open_bar_ = std::numeric_limits<std::int64_t>::min();
2977 std::int64_t pooc_close_checkpoint_deferred_ms_ = std::numeric_limits<std::int64_t>::min();
2978 std::int32_t signal_close_mc_event_bar_ = -1;
2979 std::int64_t signal_close_mc_position_cycle_ = 0;
2980 std::uint64_t signal_close_mc_entry_incarnation_ = 0;
2981 std::uint64_t signal_close_mc_fill_seq_ = 0;
2982 double signal_close_mc_before_qty_ = std::numeric_limits<double>::quiet_NaN();
2983 double signal_close_mc_remaining_qty_ = std::numeric_limits<double>::quiet_NaN();
2984 std::uint64_t last_margin_call_event_ordinal_ = 0;
2985 std::uint64_t last_margin_call_entry_incarnation_ = 0;
2986 std::int64_t last_margin_call_position_cycle_ = 0;
2987 bool last_margin_call_at_script_close_ =
false;
2988 double last_margin_call_closed_units_ = 0.0;
2989 double last_margin_call_remaining_units_ = 0.0;
2992 double source_gains_ = 0.0;
2993 double source_losses_ = 0.0;
2994 std::uint64_t source_money_folded_ = 0;
2995 std::int64_t risk_coof_direct_script_bar_ = std::numeric_limits<std::int64_t>::min();
2996 std::uint64_t cap_latest_fill_ = 0;
2997 bool source_margin_call_enabled_ =
true;
2998 Bar policy_script_bar_{};
2999 bool policy_script_bar_valid_ =
false;
3000 std::unordered_set<std::uint64_t> market_pyramid_adds_;
3001 std::unordered_map<std::uint64_t, NativeTrailState> trail_state_at_open_;
3004 std::vector<std::pair<native_order::RequestHandle, double>> carried_trail_retunes_;
3005 bool stream_mode_ =
false;
3006 SourceDayLedger day_ledger_{};
3007 PineRiskState risk_{};
3008 ShortSeedPlan short_seed_{};
3009 PendingShortSeedPlan pending_short_seed_{};
3010 native_order::RequestHandle short_seed_long_candidate_{};
3011 int last_bar_dual_entry_path_ = 0;
3012 std::int64_t last_bar_dual_entry_script_open_ms_ =
3013 std::numeric_limits<std::int64_t>::min();
3015 ::pineforge::detail::ScratchSequence<std::uint8_t> trade_exit_phase_;
3026 struct ExitGroupCertificate {
3028 std::size_t base = 0, start = 0, end = 0;
3029 bool rows_valid =
false;
3030 } exit_group_certificate_;
3031 ExitGroupWork exit_group_work_{};
3032 bool exit_group_certified(
const TradeLedger&)
const noexcept;
3033 void invalidate_exit_group(std::size_t first, std::size_t count = 1) noexcept;
3034 void certify_exit_group(const
TradeLedger&,
std::
size_t start,
bool ordered = true);
3035 void finish_exit_group_sort(::
pineforge::
detail::CommandScratchStore&,
3044 std::uint64_t exit_rank_keys_digest_ = 1469598103934665603ULL;
3045 std::uint32_t exit_rank_peak_ = 0;
3046 std::uint32_t exit_rank_alt_peak_ = 0;
3047 void require_tree_precommit(
const NativePrecommitView&)
const;
3048 void require_exit_rank_key(
const SourceId&)
const;
3049 void note_exit_rank_key(
const SourceId&);
3050 void note_exit_rank_transients();
3054 std::size_t exit_phase_final_ = 0;
3055 std::uint64_t exit_phase_digest_ = 1469598103934665603ULL;
3061 mutable std::size_t admission_events_folded_ = 0;
3062 mutable std::uint64_t admission_events_last_ = 0;
3063 mutable std::uint64_t admission_events_digest_ = 1469598103934665603ULL;
3069 std::int64_t owed_follow_up_bar_ = std::numeric_limits<std::int64_t>::min();
3070 std::int32_t owed_follow_up_point_ = -1;
3071 double owed_follow_up_units_ = 0.0;
3076 std::int64_t close_call_after_script_bar_ = std::numeric_limits<std::int64_t>::min();
3077 double close_call_after_script_book_ = 0.0;
3078 double close_call_after_script_units_ = 0.0;
3084 std::int64_t open_exit_first_bar_ = std::numeric_limits<std::int64_t>::min();
3085 std::uint64_t open_exit_first_origin_ = 0;
3087 double open_exit_first_fill_ = 0.0;
3095 std::size_t cohort_opened_slot_count_ = 0;
3096 bool fixture_verify_source_entry_slots_ =
false;
3097 bool fixture_bracket_remove_precheck_ =
true;
3106 bool open_call_sequence_ =
false;
3107 std::vector<std::uint64_t> unrepeated_margin_calls_;
3111 bool bar_magnifier_ =
false;
3116 mutable const NativeStrategyHost* pine_view_host_ =
nullptr;
3124 struct RetiredRowScratch {
3125 std::vector<std::uint64_t> roots;
3126 std::vector<std::uint64_t> askable_origins;
3127 std::vector<std::uint64_t> live_groups;
3128 std::vector<std::int32_t> source_bars;
3129 std::vector<std::pair<std::uint64_t, const PlacementSnapshot*>> candidates;
3130 std::vector<std::uint64_t> candidate_names;
3131 std::vector<std::uint64_t> first_reissues;
3132 std::vector<const PlacementSnapshot*> origin_pins;
3133 std::vector<std::uint64_t> doomed;
3142 std::vector<HeldLeg> held;
3143 std::vector<std::uint64_t> released;
3149 std::vector<std::pair<std::uint64_t, std::uint64_t>> unsuperseded;
3154 std::uint64_t reissue_high_water = 0;
3155 std::int64_t reissue_cycle = -1;
3156 std::vector<std::pair<std::uint64_t, std::uint64_t>> reissues;
3157 std::vector<std::pair<std::uint64_t, std::uint64_t>> next_reissues;
3158 std::vector<std::size_t> new_candidates;
3159 std::vector<std::size_t> known_candidates;
3160 std::vector<std::size_t> unresolved_candidates;
3164 std::vector<std::uint64_t> adopted_reissues;
3172 std::vector<std::uint64_t> working_roots;
3173 std::vector<std::uint64_t> lot_openings;
3174 std::vector<std::uint64_t> successor_lots;
3175 std::vector<std::pair<native_order::CohortHandle, std::uint64_t>> released_origins;
3177 bool roster_pass_due =
true;
3182 static constexpr std::size_t family_count =
3184 static constexpr std::size_t market_order_slot = family_count;
3185 static constexpr std::size_t exit_policy_slot = family_count + 1;
3186 std::size_t live_families[family_count + 2]{};
3190 bool origin_fronts_pinned =
true;
3191 void clear() noexcept {
3193 askable_origins.clear();
3194 live_groups.clear();
3195 source_bars.clear();
3197 candidate_names.clear();
3198 first_reissues.clear();
3199 origin_pins.clear();
3203 next_reissues.clear();
3204 new_candidates.clear();
3205 known_candidates.clear();
3206 unresolved_candidates.clear();
3209 RetiredRowScratch retired_row_scratch_;
3210 void remember_live(
const native_order::RequestHandle&, PlacementSnapshot&&);
3211 void forget_live(
const native_order::RequestHandle&)
noexcept;
3212 void requeue_live(
const native_order::RequestHandle&);
3213 void clear_live() noexcept;
3214 void erase_placement(
std::uint64_t);
3215 void count_live(const PlacementSnapshot&,
bool adding) noexcept;
3216 void assert_live_counts() const noexcept;
3218 bool has_live_exit_policy() const noexcept;
3219 bool has_live_trail_policy() const noexcept;
3227 struct StagedScopeFacts {
3228 bool positive_grid =
false;
3229 bool unit_grid =
false;
3230 bool unit_point_money =
false;
3231 bool unit_money =
false;
3232 bool mintick =
false;
3234 StagedScopeFacts staged_scopes_{};
3235 bool lot_grid_pinned_ =
false;
3236 bool gain_loss_configured_ =
false;
3237 bool slipped_long_configured_ =
false;
3238 bool unified_configured_ =
false;
3239 bool ledger_records_configured_ =
false;
3240 bool pooc_fee_configured_ =
false;
3241 void refresh_configuration_scopes(
const PineStrategyConfig& config)
noexcept;
3244 void order_same_point_entries();
3245 double pending_opposite_market_units(
bool is_long, std::int64_t script_open_ms,
const SourceId&
id)
const;
3248 bool same_point_pair_scope()
const;
3249 bool same_point_two_leg_book(
const SourceId&
id, std::int64_t script_open_ms)
const;
3250 bool same_point_pair_fill_follows(
const PlacementSnapshot& filled,
3251 const native_order::RequestHandle& filled_handle,
3252 double price)
const;
3254 bool fill_pooc_close_pair(
double raw_close,
const NativeDecisionContext& context);
3255 void finish_admission_bar();
3256 void on_bar_close_policy(
const Bar&,
const NativeDecisionContext&);
3257 void fold_admission_events()
const;
3258 std::uint64_t checked_live_key(
const SourceId&)
const;
3259 detail::LiveSourceHandle live_source_value(native_order::RequestHandle,
const SourceId&)
const;
3260 void cancel_reversal_exit_owners(
const std::vector<SourceId>& preserved,
3261 detail::ExitScratchRows<SourceId>& selection);
3263 mutable std::uint64_t projected_raw_pending_calls_ = 0;
3266 std::uint64_t pending_projection_version_ = 0;
3267 mutable std::uint64_t projected_pending_version_ = 0;
3268 mutable std::uint64_t projected_placement_version_ = 0;
3269 mutable bool projected_pending_valid_ =
false;
3270 mutable std::vector<int> projected_pending_indexes_;
3271 mutable std::vector<int> projected_pending_next_;
3272 bool ensure_projected_pending_index()
const;
3273 int projected_pending_next(
int index)
const noexcept;
3274 int projected_raw_pending_next(
int raw)
const noexcept;
3275 int projected_level_resolved(
const PlacementSnapshot&)
const noexcept;
3278 template<
class Row> Row& pending_write(Row& row)
noexcept {
3279 refresh_pending_view();
3283 static bool scan_projected_pending_at(
3285 native_order::RequestHandle&,
int* raw_index =
nullptr) noexcept;
3307 std::uint64_t
m = 0,
R = 0,
C = 0;
3315 RetirementWork retirement_work_{};
3316 struct RetirementObservation {
3318 RetirementWork& work;
3319 std::uint64_t slots, restored, spilled, spill_visits;
3321 : RetirementObservation(owner, owner.retirement_work_) {}
3323 : adapter(owner), work(destination), slots(owner.placement_.visited_slots()),
3324 restored(owner.cohorts_by_id_.work_counters().rows_restored),
3325 spilled(owner.cohorts_by_id_.work_counters().rows_spilled),
3326 spill_visits(owner.cohorts_by_id_.work_counters().rows_visited_by_spill) {}
3327 ~RetirementObservation() {
3328 const auto& backing = adapter.cohorts_by_id_.work_counters();
3329 work.placement_slots += adapter.placement_.visited_slots() - slots;
3330 work.backing_rows_restored += backing.rows_restored - restored;
3331 work.backing_rows_spilled += backing.rows_spilled - spilled;
3332 work.spill_rows_visited += backing.rows_visited_by_spill - spill_visits;
3337 struct RetirementInputs {
3338 std::vector<std::uint64_t> roots, askable, groups, marks;
3339 std::vector<std::int32_t> bar_numbers;
3340 bool operator==(
const RetirementInputs& other)
const noexcept {
3341 return roots == other.roots && askable == other.askable
3342 && groups == other.groups && marks == other.marks && bar_numbers == other.bar_numbers;
3345 struct RetirementGate {
3346 RetirementInputs saved, current;
3347 bool certified =
false;
3348 std::int64_t cycle = -1, interval = -1;
3349 std::int64_t broker_open = std::numeric_limits<std::int64_t>::min();
3350 std::int64_t interval_expiry = std::numeric_limits<std::int64_t>::max();
3351 std::int64_t broker_expiry = std::numeric_limits<std::int64_t>::max();
3353 RetirementGate retirement_gate_;
3354 void invalidate_retirement() noexcept { retirement_gate_.certified =
false; }
3355 bool capture_retirement_inputs(RetirementInputs&)
const;
3356 void observe_retirement_expiry(
const PlacementSnapshot&, std::int64_t interval)
noexcept;
3357 void sweep_retired_rows(
const NativeDecisionContext&,
RetirementWork&);
3358 void finish_retirement_phases();
3360 std::array<std::uint64_t, 3> retirement_validation_state()
const;