Skip to main content

Position

Struct Position 

Source
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

Source

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).

Source

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).

Source

pub fn set_trade_id(&mut self, trade_id: Option<TradeId>)

Attach or replace a trade_id on this position.

Source

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.

Source

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.

Source

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.

Source

pub fn current_effective_stop(&self) -> Option<EffectiveStop>

Find the current fixed-stoploss price, if any.

Source

pub fn current_stoploss(&self) -> Option<f64>

Source

pub fn set_stoploss(&mut self, new_price: f64) -> Option<f64>

Update the fixed-stoploss price. Returns the old price (if any).

Source

pub fn set_stoploss_with_origin( &mut self, new_price: f64, origin: StopOrigin, ) -> Option<f64>

Source

pub fn remove_rule(&mut self, name: &str) -> bool

Remove a rule by name. Returns true if a rule was removed.

Source

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.

Source

pub fn has_stateful_rules(&self) -> bool

Whether this position has any stateful rules requiring tick-by-tick evaluation.

Trait Implementations§

Source§

impl Clone for Position

Source§

fn clone(&self) -> Position

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Position

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Position

Source§

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

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

impl Serialize for Position

Source§

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

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

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

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V