Skip to main content

PortfolioState

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<(OrderId, String)>, 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, Decimal>, 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

Top-level derived state maintained by the reducer.

Uses BTreeMap / BTreeSet throughout for deterministic serialization order, which is required for state hashing.

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: RiskStopState

Current risk stop state.

§risk_state_trigger: Option<String>

Trigger string from the most recent RiskState transition.

§daily_pnl: Decimal

Cumulative daily realized P&L.

§monthly_pnl: Decimal

Cumulative monthly realized P&L.

§total_pnl: Decimal

Cumulative total realized P&L.

§hwm: Decimal

High-water mark for drawdown calculation.

§seen_fill_ids: BTreeSet<(OrderId, String)>

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, Decimal>

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: ReconcileTracking

Per-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: VelocityGateLevel

Current 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

§

fn clone(&self) -> PortfolioState

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Debug for PortfolioState

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Default for PortfolioState

§

fn default() -> PortfolioState

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for PortfolioState

§

fn deserialize<__D>( __deserializer: __D, ) -> Result<PortfolioState, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl PartialEq for PortfolioState

§

fn eq(&self, other: &PortfolioState) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl Serialize for PortfolioState

§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl Eq for PortfolioState

§

impl StructuralPartialEq for PortfolioState

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,