pub struct PositionData {Show 18 fields
pub id: PositionId,
pub symbol: String,
pub side: Side,
pub order_type: OrderType,
pub status: PositionStatus,
pub pending_price: Option<f64>,
pub size: f64,
pub entries: Vec<Fill>,
pub remaining_ratio: f64,
pub closed_size: f64,
pub open_entry_value: f64,
pub target_hits: u32,
pub open_ts: Option<NaiveDateTime>,
pub close_ts: Option<NaiveDateTime>,
pub group: Option<GroupId>,
pub trade_id: Option<TradeId>,
pub stop_origin: Option<StopOrigin>,
pub records: Vec<(PositionRecord, NaiveDateTime)>,
}Expand description
Core position data — the pure state without rules.
Fields§
§id: PositionIdUnique identifier.
symbol: StringInstrument symbol (e.g. “EURUSD”, “XAUUSD”).
side: SideTrade direction.
order_type: OrderTypeHow the order was placed.
status: PositionStatusCurrent lifecycle status.
pending_price: Option<f64>For Limit/Stop orders: the price at which the order should fill.
size: f64Intended order size (lots / units).
entries: Vec<Fill>Actual execution fills (one for market, potentially many for scale-in).
remaining_ratio: f64Fraction of all entered size still open (1.0 = full, 0.0 = closed).
Retained for wire compatibility and rule views. Absolute sizes are the source of truth and every core mutation keeps this value synchronized.
closed_size: f64Absolute size closed across all partial and full exits.
Entry size is the sum of entries; open size is derived as entered size
minus this value. Older serialized positions infer this from
remaining_ratio during deserialization.
open_entry_value: f64Cost basis assigned to the inventory that is still open.
Positions use average-cost accounting: every close releases
average_entry * close_size from this value, while a scale-in adds only
the new fill’s value. Historical entries remain unchanged for audit.
Older serialized positions infer this from their historical weighted
average and remaining size.
target_hits: u32Number of take-profit levels that have been hit. Used by
BreakevenAfterTargets rule.
open_ts: Option<NaiveDateTime>When the position first filled.
close_ts: Option<NaiveDateTime>When the position was fully closed.
group: Option<GroupId>Optional group for per-signal-source tracking and group-level actions.
trade_id: Option<TradeId>Optional application-defined trade identity.
Parsers mint a stable TradeId (for example, chat_id:msg_id) and
reference it from later management signals via PositionRef::ByTradeId.
When None, management signals must use bulk references or the
engine’s PositionId.
stop_origin: Option<StopOrigin>Provenance of the current fixed protective stop.
records: Vec<(PositionRecord, NaiveDateTime)>Immutable audit trail.
Implementations§
Source§impl PositionData
impl PositionData
Sourcepub fn average_entry(&self) -> f64
pub fn average_entry(&self) -> f64
Average-cost entry price of the inventory that is still open.
Historical fills are intentionally not re-averaged here: after a partial close, only the remaining inventory basis participates in a later scale-in and subsequent close.
Sourcepub fn historical_average_entry(&self) -> f64
pub fn historical_average_entry(&self) -> f64
Volume-weighted average across all historical entry fills.
Sourcepub fn total_filled_size(&self) -> f64
pub fn total_filled_size(&self) -> f64
Total filled size (sum of all fills).
Sourcepub fn remaining_size(&self) -> f64
pub fn remaining_size(&self) -> f64
Size still active in the market, derived from absolute quantities.
Sourcepub fn open_ratio(&self) -> f64
pub fn open_ratio(&self) -> f64
Fraction of all entered size that is still open.
Sourcepub fn capped_close_ratio(&self, ratio: f64) -> f64
pub fn capped_close_ratio(&self, ratio: f64) -> f64
Cap an original-entered-size close ratio to the exposure still open.
Sourcepub fn close_size_for_ratio(&self, ratio: f64) -> f64
pub fn close_size_for_ratio(&self, ratio: f64) -> f64
Absolute size represented by a close ratio, capped to open exposure.
Sourcepub fn unrealized_pnl(&self, current_price: f64) -> f64
pub fn unrealized_pnl(&self, current_price: f64) -> f64
Unrealised P&L at the given price.
Sourcepub fn add_fill(&mut self, fill: Fill)
pub fn add_fill(&mut self, fill: Fill)
Add a fill (scale-in), preserving previously closed absolute size and adding the fill only to active inventory cost basis.
Sourcepub fn replace_latest_fill_execution(
&mut self,
price: f64,
ts: NaiveDateTime,
) -> bool
pub fn replace_latest_fill_execution( &mut self, price: f64, ts: NaiveDateTime, ) -> bool
Replace the most recent entry fill price and timestamp.
Future-quote backtests use this after a pending order triggers so the
engine’s average entry matches the authoritative gap-aware execution
fill produced by the execution pricer. Returns false when no fill
exists or the replacement is invalid.
Sourcepub fn synchronize_latest_fill(&mut self, fill: Fill) -> bool
pub fn synchronize_latest_fill(&mut self, fill: Fill) -> bool
Replace the latest entry fill and its audit record.
Future-quote executors use this after the engine transitions a pending
order to Open, keeping core position state synchronized with the
externally calculated gap/improvement execution price.
Sourcepub fn apply_partial_close(
&mut self,
ratio: f64,
price: f64,
reason: CloseReason,
ts: NaiveDateTime,
)
pub fn apply_partial_close( &mut self, ratio: f64, price: f64, reason: CloseReason, ts: NaiveDateTime, )
Record a partial close using an original-entered-size ratio.
The close is capped to the absolute size still open. If no exposure
remains, the status is flipped to Closed and both absolute and ratio
accounting reach exact zero.
Sourcepub fn apply_full_close(&mut self, reason: CloseReason, ts: NaiveDateTime)
pub fn apply_full_close(&mut self, reason: CloseReason, ts: NaiveDateTime)
Mark the position as fully closed.
Sourcepub fn view(&self) -> PositionView<'_>
pub fn view(&self) -> PositionView<'_>
Create a read-only view for rule evaluation.
Trait Implementations§
Source§impl Clone for PositionData
impl Clone for PositionData
Source§fn clone(&self) -> PositionData
fn clone(&self) -> PositionData
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more