Skip to main content

PositionManager

Struct PositionManager 

Source
pub struct PositionManager { /* private fields */ }
Expand description

Owns all positions and provides indexed access.

Implementations§

Source§

impl PositionManager

Source

pub fn new() -> Self

Source

pub fn add(&mut self, position: Position)

Insert a position. Overwrites if the id already exists.

Source

pub fn add_checked( &mut self, position: Position, ) -> Result<(), PositionManagerError>

Atomically insert a position after rejecting a duplicate non-empty trade ID.

Validation happens before any primary or secondary index mutation. The legacy Self::add API remains available for callers that require its historical last-write-wins behavior.

Source

pub fn remove(&mut self, id: &str) -> Option<Position>

Remove a position by id.

Source

pub fn get(&self, id: &str) -> Option<&Position>

Immutable lookup.

Source

pub fn get_mut(&mut self, id: &str) -> Option<&mut Position>

Mutable lookup.

Source

pub fn len(&self) -> usize

Total number of tracked positions (all statuses).

Source

pub fn is_empty(&self) -> bool

Source

pub fn iter(&self) -> impl Iterator<Item = (&PositionId, &Position)>

Iterate over all positions.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&PositionId, &mut Position)>

Iterate mutably over all positions.

Source

pub fn position_ids_sorted(&self) -> Vec<PositionId> ⓘ

All position IDs in stable lexicographic order.

Source

pub fn ids_by_symbol_status( &self, symbol: &str, status: PositionStatus, ) -> Vec<PositionId> ⓘ

Collect ids of positions matching the given status and symbol.

Source

pub fn ids_by_symbol_status_sorted( &self, symbol: &str, status: PositionStatus, ) -> Vec<PositionId> ⓘ

Stable lexicographic variant of Self::ids_by_symbol_status.

Source

pub fn ids_by_status(&self, status: PositionStatus) -> Vec<PositionId> ⓘ

Collect ids of all positions with the given status.

Source

pub fn ids_by_status_sorted(&self, status: PositionStatus) -> Vec<PositionId> ⓘ

Stable lexicographic variant of Self::ids_by_status.

Source

pub fn ids_by_symbol_side(&self, symbol: &str, side: Side) -> Vec<PositionId> ⓘ

Collect ids of open positions on a given symbol with a given side.

Source

pub fn ids_by_symbol_side_sorted( &self, symbol: &str, side: Side, ) -> Vec<PositionId> ⓘ

Stable lexicographic variant of Self::ids_by_symbol_side.

Source

pub fn open_positions(&self) -> Vec<&Position>

All open (active) positions.

Source

pub fn pending_positions(&self) -> Vec<&Position>

All pending (unfilled) positions.

Source

pub fn closed_positions(&self) -> Vec<&Position>

All closed positions.

Source

pub fn open_ids_by_symbol(&self, symbol: &str) -> Vec<PositionId> ⓘ

Collect ids of all open positions on a given symbol.

Source

pub fn open_ids_by_symbol_sorted(&self, symbol: &str) -> Vec<PositionId> ⓘ

Stable lexicographic variant of Self::open_ids_by_symbol.

Source

pub fn pending_ids_by_symbol(&self, symbol: &str) -> Vec<PositionId> ⓘ

Collect ids of all pending positions on a given symbol.

Source

pub fn pending_ids_by_symbol_sorted(&self, symbol: &str) -> Vec<PositionId> ⓘ

Stable lexicographic variant of Self::pending_ids_by_symbol.

Source

pub fn ids_for_symbol(&self, symbol: &str) -> Vec<PositionId> ⓘ

All position IDs for a symbol (any status), via the symbol index.

Source

pub fn ids_for_symbol_sorted(&self, symbol: &str) -> Vec<PositionId> ⓘ

Stable lexicographic variant of Self::ids_for_symbol.

Source

pub fn add_group(&mut self, group: PositionGroup)

Create or update a position group.

Source

pub fn get_group(&self, id: &str) -> Option<&PositionGroup>

Get a group by id.

Source

pub fn add_to_group(&mut self, group_id: &str, position_id: PositionId)

Add a position to an existing group. Creates the group if it does not exist.

Source

pub fn group_position_ids(&self, group_id: &str) -> Vec<PositionId> ⓘ

Return all position ids belonging to a group.

Source

pub fn remove_group(&mut self, group_id: &str) -> Option<PositionGroup>

Remove a group (does not close or remove the positions).

Source

pub fn open_ids_by_group(&self, group_id: &str) -> Vec<PositionId> ⓘ

All open position IDs in a group.

Source

pub fn pending_ids_by_group(&self, group_id: &str) -> Vec<PositionId> ⓘ

All pending position IDs in a group.

Source

pub fn all_group_ids(&self) -> Vec<&GroupId> ⓘ

All group IDs that currently exist.

Source

pub fn all_group_ids_sorted(&self) -> Vec<&GroupId> ⓘ

All group IDs in stable lexicographic order.

Source

pub fn id_by_trade_id(&self, trade_id: &str) -> Option<PositionId>

Look up the position ID for a given application-defined trade id.

Source

pub fn would_duplicate_trade_id( &self, position: &Position, ) -> Option<PositionId>

Return the current owner when adding position would duplicate a trade ID already assigned to a different position.

This is opt-in validation; Self::add intentionally retains its legacy last-write-wins trade-index behavior.

Source

pub fn ensure_trade_id_available( &self, trade_id: &str, position_id: Option<&str>, ) -> Result<(), PositionManagerError>

Validate a non-empty trade ID without mutating manager state.

Source

pub fn duplicate_trade_ids(&self) -> Vec<TradeId> ⓘ

Find every trade ID currently present on more than one stored position. Results are stable and lexicographically sorted.

Source

pub fn set_trade_id(&mut self, position_id: &str, trade_id: TradeId)

Update the trade_id mapping for a position (used when trade_id is attached after position creation, e.g. during scale-in).

Source

pub fn set_trade_id_checked( &mut self, position_id: &str, trade_id: TradeId, ) -> Result<(), PositionManagerError>

Atomically attach a trade ID to a stored position and update the index.

Source

pub fn open_ids_by_side(&self, side: Side) -> Vec<PositionId> ⓘ

Collect ids of all open positions matching a side filter.

Source

pub fn open_ids_by_side_sorted(&self, side: Side) -> Vec<PositionId> ⓘ

Stable lexicographic variant of Self::open_ids_by_side.

Source

pub fn all_open_ids(&self) -> Vec<PositionId> ⓘ

Collect ids of all open positions regardless of symbol.

Source

pub fn all_open_ids_sorted(&self) -> Vec<PositionId> ⓘ

All open position IDs in stable lexicographic order.

Source

pub fn all_pending_ids(&self) -> Vec<PositionId> ⓘ

Collect ids of all pending positions regardless of symbol.

Source

pub fn all_pending_ids_sorted(&self) -> Vec<PositionId> ⓘ

All pending position IDs in stable lexicographic order.

Trait Implementations§

Source§

impl Clone for PositionManager

Source§

fn clone(&self) -> PositionManager

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 PositionManager

Source§

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

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

impl Default for PositionManager

Source§

fn default() -> PositionManager

Returns the “default value” for a type. 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> 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