Struct FuturesPosition

Source
#[repr(align(64))]
pub struct FuturesPosition {
Show 14 fields pub id: PositionId, pub venue: Venue, pub symbol: String, pub side: PositionSide, pub amount: Decimal, pub entry_price: Decimal, pub breakeven_price: Decimal, pub unrealized_pnl: Decimal, pub realized_pnl: Decimal, pub margin_type: MarginType, pub isolated_wallet: Decimal, pub creation_time_ns: u64, pub update_time_ns: u64, pub metadata: Value,
}
Expand description

Represents a futures position in the system

Fields§

§id: PositionId

Unique position ID

§venue: Venue

Exchange identifier

§symbol: String

Trading symbol (e.g. “BTCUSDT”)

§side: PositionSide

Position side (long/short/both)

§amount: Decimal

Position amount (positive for long, negative for short in unified margin)

§entry_price: Decimal

Entry price

§breakeven_price: Decimal

Breakeven price

§unrealized_pnl: Decimal

Unrealized PnL

§realized_pnl: Decimal

Accumulated realized PnL

§margin_type: MarginType

Margin type

§isolated_wallet: Decimal

Isolated wallet amount (for isolated margin)

§creation_time_ns: u64

Position creation time in nanoseconds

§update_time_ns: u64

Position update time in nanoseconds

§metadata: Value

Additional position metadata

Implementations§

Source§

impl FuturesPosition

Source

pub fn new( venue: Venue, symbol: impl AsRef<str>, side: PositionSide, amount: Decimal, entry_price: Decimal, margin_type: MarginType, ) -> Self

Create a new futures position

Source

pub fn update( &mut self, amount: Decimal, entry_price: Decimal, breakeven_price: Decimal, unrealized_pnl: Decimal, realized_pnl: Decimal, isolated_wallet: Decimal, )

Update position with new data from exchange position reports

This method performs a complete update of all mutable position fields based on fresh data received from the exchange. It’s designed for high-frequency updates where position state changes rapidly.

§Parameters
  • amount - New position size (positive for long, negative for short in unified margin)
  • entry_price - Updated average entry price after fills or position adjustments
  • breakeven_price - Price at which the position breaks even (includes fees)
  • unrealized_pnl - Current unrealized profit/loss at market price
  • realized_pnl - Accumulated realized profit/loss from closed portions
  • isolated_wallet - Available margin for isolated positions (0 for cross margin)
§Field Mutations

This method updates the following fields:

  • amount: Position size with sign indicating direction
  • entry_price: Average entry price (weighted by fills)
  • breakeven_price: Break-even price including fees and funding
  • unrealized_pnl: Mark-to-market P&L at current price
  • realized_pnl: Cumulative realized P&L from position reductions
  • isolated_wallet: Margin available for isolated positions
  • update_time_ns: Automatically set to current nanosecond timestamp
§Performance Notes
  • Cache-line aligned struct (#[repr(align(64))]) for optimal memory access
  • Uses high-precision Decimal arithmetic for financial calculations
  • Nanosecond timestamp precision for HFT latency tracking
  • Designed for frequent updates in high-frequency trading scenarios
§Example
let mut position = FuturesPosition::new(/*...*/);

// Update with fresh exchange data
position.update(
    dec!(1.5),      // New position size
    dec!(50200.0),  // Updated entry price
    dec!(50250.0),  // Break-even price
    dec!(750.0),    // Unrealized P&L
    dec!(100.0),    // Realized P&L
    dec!(1000.0),   // Isolated wallet
);
Source

pub const fn is_closed(&self) -> bool

Check if position is closed (amount is zero)

Source

pub fn get_notional_value(&self, current_price: Decimal) -> Decimal

Get position value at current price

Source

pub fn get_pnl(&self, current_price: Decimal) -> Decimal

Get position PnL at current price

Trait Implementations§

Source§

impl Clone for FuturesPosition

Source§

fn clone(&self) -> FuturesPosition

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for FuturesPosition

Source§

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

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

impl<'de> Deserialize<'de> for FuturesPosition

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 FuturesPosition

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

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

§

impl<T> ErasedDestructor for T
where T: 'static,