Struct PortfolioState
pub struct PortfolioState {Show 31 fields
pub positions: BTreeMap<PositionKey, Position>,
pub open_orders: BTreeMap<OrderId, Order>,
pub balances: BTreeMap<BalanceKey, Decimal>,
pub risk_state: RiskStopState,
pub risk_state_trigger: Option<String>,
pub daily_pnl: Decimal,
pub monthly_pnl: Decimal,
pub total_pnl: Decimal,
pub hwm: Decimal,
pub seen_fill_ids: BTreeSet<FillDedupKey>,
pub pending_intents: BTreeMap<ClientIntentId, PendingIntent>,
pub command_to_intent: BTreeMap<CommandId, ClientIntentId>,
pub command_seqs: BTreeMap<CommandId, u64>,
pub retiring_order_targets_by_command: BTreeMap<CommandId, BTreeSet<OrderId>>,
pub direct_retiring_order_ids: BTreeSet<OrderId>,
pub terminal_order_attribution: BTreeMap<OrderId, TerminalOrderAttribution>,
pub seen_intent_ids: BTreeSet<ClientIntentId>,
pub seen_command_ids: BTreeSet<CommandId>,
pub seen_ack_command_ids: BTreeSet<CommandId>,
pub last_prices: BTreeMap<PositionKey, Price>,
pub pre_ack_fills: BTreeMap<OrderId, Decimal>,
pub tombstoned_orders: BTreeSet<OrderId>,
pub tombstoned_order_seqs: BTreeMap<OrderId, u64>,
pub closed_order_ids: BTreeSet<OrderId>,
pub reconcile: ReconcileTracking,
pub strategy_pnl: BTreeMap<String, StrategyPnl>,
pub pair_daily_pnl: BTreeMap<PositionKey, Decimal>,
pub velocity_pnl_window: Vec<PnlSnapshot>,
pub velocity_gate: VelocityGateLevel,
pub last_pnl_reset_date: Option<(i32, u32)>,
pub last_pnl_reset_month: Option<(i32, u32)>,
}Expand description
Fields§
§positions: BTreeMap<PositionKey, Position>Open positions keyed by (venue_id, instrument_id).
open_orders: BTreeMap<OrderId, Order>Orders currently open on venues.
balances: BTreeMap<BalanceKey, Decimal>Per-venue asset balances.
risk_state: RiskStopStateCurrent risk stop state.
risk_state_trigger: Option<String>Trigger string from the most recent RiskState transition.
daily_pnl: DecimalCumulative daily realized P&L.
monthly_pnl: DecimalCumulative monthly realized P&L.
total_pnl: DecimalCumulative total realized P&L.
hwm: DecimalHigh-water mark for drawdown calculation.
seen_fill_ids: BTreeSet<FillDedupKey>Seen fills for deduplication (JOURNAL_SPEC §9.4). Keyed by (venue_order_id, fill_id) because fill_id is only unique per venue/order, not globally.
pending_intents: BTreeMap<ClientIntentId, PendingIntent>Intents awaiting execution acknowledgment.
command_to_intent: BTreeMap<CommandId, ClientIntentId>Maps command → intent for ExecutionAck lookup.
command_seqs: BTreeMap<CommandId, u64>Journal seq where each command was issued (ExecutionCommand.seq). Used to disambiguate stale tombstones from reused venue_order_id acks.
retiring_order_targets_by_command: BTreeMap<CommandId, BTreeSet<OrderId>>Snapshot of live order IDs targeted by issued Cancel / CancelAll commands and not yet reconciled by a reject or terminal order update. Risk uses this to treat retiring orders as already on their way out across the command -> ack -> terminal lifecycle.
Omitted from bare PortfolioState serialization and state hashing so
full replay can rebuild it from journaled command lifecycle events
without breaking determinism. Checkpoint payloads persist it
separately so checkpoint-accelerated resumes preserve in-flight cancel
state until reconciliation refreshes venue truth.
direct_retiring_order_ids: BTreeSet<OrderId>Live order IDs targeted by successful out-of-band direct cancels
(for example pair-loss-cap neutralization) that have not yet received
a terminal OrderState.
Omitted from bare PortfolioState serialization and state hashing
because it is reconstructed from journaled DirectRetirement events
plus later terminal / reconcile events. The checkpoint payload persists
it separately so checkpoint-accelerated resumes preserve the same
retirement view until venue truth clears it.
terminal_order_attribution: BTreeMap<OrderId, TerminalOrderAttribution>Attribution retained for direct-cancelled orders that were locally terminalized before late venue lifecycle events arrived.
Omitted from bare PortfolioState serialization and state hashing
because cleanup is performed by runtime code (clear_terminal_order_attribution),
not the pure reducer. Including it in state_hash would cause replay
divergence since replay only calls reduce() and never clears entries.
The checkpoint payload persists it separately so checkpoint-accelerated
resumes preserve the attribution data for late fills.
seen_intent_ids: BTreeSet<ClientIntentId>Run-wide seen client_intent_id values for §9.4 uniqueness.
seen_command_ids: BTreeSet<CommandId>Run-wide seen command_id values for §9.4 uniqueness.
seen_ack_command_ids: BTreeSet<CommandId>ExecutionAck command IDs already processed; duplicate acks are no-op.
last_prices: BTreeMap<PositionKey, Price>Last trade price per venue:instrument for mark-to-market.
pre_ack_fills: BTreeMap<OrderId, Decimal>Cumulative fill qty received before ExecutionAck, keyed by venue_order_id.
reduce_execution_ack reconciles this so the order starts with the
correct filled_qty.
tombstoned_orders: BTreeSet<OrderId>Orders that received a terminal OrderState before their ExecutionAck.
Prevents late acks from resurrecting dead orders.
tombstoned_order_seqs: BTreeMap<OrderId, u64>First terminal seq observed for tombstoned orders.
closed_order_ids: BTreeSet<OrderId>Venue order IDs that have had at least one terminal OrderState processed.
Guards against duplicate terminal events inserting stale tombstones.
reconcile: ReconcileTrackingPer-scope reconciliation divergence tracking.
strategy_pnl: BTreeMap<String, StrategyPnl>Per-strategy realized P&L tracking.
pair_daily_pnl: BTreeMap<PositionKey, Decimal>Per-pair daily realized P&L for pair-level loss caps.
Key: PositionKey (venue_id/instrument_id). Resets on day boundary.
Always serialized and required in checkpoints so stale snapshots fail
closed instead of silently zeroing pair loss tracking.
velocity_pnl_window: Vec<PnlSnapshot>Per-fill P&L snapshots for velocity gate evaluation. Pruned to 2 hours.
velocity_gate: VelocityGateLevelCurrent velocity gate level (orthogonal to risk_state).
last_pnl_reset_date: Option<(i32, u32)>Date (year, ordinal) of last daily P&L reset. Used by reducer to detect day boundary.
last_pnl_reset_month: Option<(i32, u32)>Date (year, month) of last monthly P&L reset.
Trait Implementations§
§impl Clone for PortfolioState
impl Clone for PortfolioState
§fn clone(&self) -> PortfolioState
fn clone(&self) -> PortfolioState
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for PortfolioState
impl Debug for PortfolioState
§impl Default for PortfolioState
impl Default for PortfolioState
§impl<'de> Deserialize<'de> for PortfolioState
impl<'de> Deserialize<'de> for PortfolioState
§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
§impl PartialEq for PortfolioState
impl PartialEq for PortfolioState
§impl Serialize for PortfolioState
impl Serialize for PortfolioState
impl Eq for PortfolioState
impl StructuralPartialEq for PortfolioState
Auto Trait Implementations§
impl Freeze for PortfolioState
impl RefUnwindSafe for PortfolioState
impl Send for PortfolioState
impl Sync for PortfolioState
impl Unpin for PortfolioState
impl UnsafeUnpin for PortfolioState
impl UnwindSafe for PortfolioState
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)