pub struct Position {
pub data: PositionData,
pub rules: Vec<Rule>,
}Expand description
A position: data + composable management rules.
Fields§
§data: PositionData§rules: Vec<Rule>Implementations§
Source§impl Position
impl Position
Sourcepub fn new_market(
id: PositionId,
symbol: String,
side: Side,
fill: Fill,
rules: Vec<Rule>,
) -> Self
pub fn new_market( id: PositionId, symbol: String, side: Side, fill: Fill, rules: Vec<Rule>, ) -> Self
Create a new position that is immediately filled (Market order).
Sourcepub fn new_pending(
id: PositionId,
symbol: String,
side: Side,
order_type: OrderType,
pending_price: f64,
size: f64,
ts: NaiveDateTime,
rules: Vec<Rule>,
) -> Self
pub fn new_pending( id: PositionId, symbol: String, side: Side, order_type: OrderType, pending_price: f64, size: f64, ts: NaiveDateTime, rules: Vec<Rule>, ) -> Self
Create a pending position (Limit or Stop order).
Sourcepub fn set_trade_id(&mut self, trade_id: Option<TradeId>)
pub fn set_trade_id(&mut self, trade_id: Option<TradeId>)
Attach or replace a trade_id on this position.
Sourcepub fn pending_fill_purpose(
&self,
quote: &PriceQuote,
model: FillModel,
) -> Option<FillPurpose>
pub fn pending_fill_purpose( &self, quote: &PriceQuote, model: FillModel, ) -> Option<FillPurpose>
Return the execution purpose when this pending order is triggered by
quote. This check is pure and is shared by Legacy and FutureQuote paths.
Sourcepub fn try_fill(&mut self, quote: &PriceQuote, model: FillModel) -> bool
pub fn try_fill(&mut self, quote: &PriceQuote, model: FillModel) -> bool
Check if a pending order should fill at the given quote.
Returns true (and transitions the position to Open) if the fill
condition is met. Legacy semantics retain the requested-price fill.
Sourcepub fn evaluate_rules(
&mut self,
quote: &PriceQuote,
model: FillModel,
) -> Vec<Effect>
pub fn evaluate_rules( &mut self, quote: &PriceQuote, model: FillModel, ) -> Vec<Effect>
Evaluate all management rules against the current quote.
Rules may mutate their own internal state (e.g. mark themselves as triggered), but the position data is only read, not written. The engine applies the returned effects to the position afterwards.
Sourcepub fn current_effective_stop(&self) -> Option<EffectiveStop>
pub fn current_effective_stop(&self) -> Option<EffectiveStop>
Find the current fixed-stoploss price, if any.
pub fn current_stoploss(&self) -> Option<f64>
Sourcepub fn set_stoploss(&mut self, new_price: f64) -> Option<f64>
pub fn set_stoploss(&mut self, new_price: f64) -> Option<f64>
Update the fixed-stoploss price. Returns the old price (if any).
pub fn set_stoploss_with_origin( &mut self, new_price: f64, origin: StopOrigin, ) -> Option<f64>
Sourcepub fn remove_rule(&mut self, name: &str) -> bool
pub fn remove_rule(&mut self, name: &str) -> bool
Remove a rule by name. Returns true if a rule was removed.
Sourcepub fn evaluate_stateful_rules(
&mut self,
quote: &PriceQuote,
model: FillModel,
) -> Vec<Effect>
pub fn evaluate_stateful_rules( &mut self, quote: &PriceQuote, model: FillModel, ) -> Vec<Effect>
Evaluate only stateful rules (trailing stop, time exit, breakeven-after-targets). Used when static rules are handled by the alert register.
Sourcepub fn has_stateful_rules(&self) -> bool
pub fn has_stateful_rules(&self) -> bool
Whether this position has any stateful rules requiring tick-by-tick evaluation.