pub struct PositionManager { /* private fields */ }Expand description
Manages tracked positions and evaluates triggers.
Not thread-safe — intended to be owned by a single trading loop.
For concurrent access, wrap in Mutex or RwLock.
Implementations§
Source§impl PositionManager
impl PositionManager
Sourcepub fn track(&mut self, pos: ManagedPosition)
pub fn track(&mut self, pos: ManagedPosition)
Start tracking a position.
Sourcepub fn untrack(&mut self, position_id: u64) -> bool
pub fn untrack(&mut self, position_id: u64) -> bool
Stop tracking a position. Returns true if it was tracked.
Sourcepub fn get(&self, position_id: u64) -> Option<&ManagedPosition>
pub fn get(&self, position_id: u64) -> Option<&ManagedPosition>
Get a reference to a tracked position.
Sourcepub fn get_mut(&mut self, position_id: u64) -> Option<&mut ManagedPosition>
pub fn get_mut(&mut self, position_id: u64) -> Option<&mut ManagedPosition>
Get a mutable reference to a tracked position (e.g. to update triggers).
Sourcepub fn check_triggers(
&mut self,
prices: &HashMap<[u8; 32], f64>,
) -> Vec<TriggerAction>
pub fn check_triggers( &mut self, prices: &HashMap<[u8; 32], f64>, ) -> Vec<TriggerAction>
Evaluate all positions against per-perp mark prices.
Each position is only evaluated against the price for its own perp_id.
Positions whose perp_id is not in the prices map are skipped.
Returns at most one TriggerAction per position.
Sourcepub fn check_triggers_into(
&mut self,
prices: &HashMap<[u8; 32], f64>,
out: &mut Vec<TriggerAction>,
)
pub fn check_triggers_into( &mut self, prices: &HashMap<[u8; 32], f64>, out: &mut Vec<TriggerAction>, )
Zero-allocation trigger check: appends fired triggers to out.
Each position is only evaluated against the price for its own perp_id.
Call with a reusable Vec to avoid heap allocation on the hot path:
let mut mgr = PositionManager::new();
let mut buf: Vec<TriggerAction> = Vec::with_capacity(16);
let mut prices = HashMap::new();
prices.insert([0xAA; 32], 105.0);
// On each price tick:
buf.clear();
mgr.check_triggers_into(&prices, &mut buf);
// Process buf — no allocation after the first call.Trait Implementations§
Source§impl Debug for PositionManager
impl Debug for PositionManager
Auto Trait Implementations§
impl Freeze for PositionManager
impl RefUnwindSafe for PositionManager
impl Send for PositionManager
impl Sync for PositionManager
impl Unpin for PositionManager
impl UnsafeUnpin for PositionManager
impl UnwindSafe for PositionManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more