#[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: PositionIdUnique position ID
venue: VenueExchange identifier
symbol: StringTrading symbol (e.g. “BTCUSDT”)
side: PositionSidePosition side (long/short/both)
amount: DecimalPosition amount (positive for long, negative for short in unified margin)
entry_price: DecimalEntry price
breakeven_price: DecimalBreakeven price
unrealized_pnl: DecimalUnrealized PnL
realized_pnl: DecimalAccumulated realized PnL
margin_type: MarginTypeMargin type
isolated_wallet: DecimalIsolated wallet amount (for isolated margin)
creation_time_ns: u64Position creation time in nanoseconds
update_time_ns: u64Position update time in nanoseconds
metadata: ValueAdditional position metadata
Implementations§
Source§impl FuturesPosition
impl FuturesPosition
Sourcepub fn new(
venue: Venue,
symbol: impl AsRef<str>,
side: PositionSide,
amount: Decimal,
entry_price: Decimal,
margin_type: MarginType,
) -> Self
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
Sourcepub fn update(
&mut self,
amount: Decimal,
entry_price: Decimal,
breakeven_price: Decimal,
unrealized_pnl: Decimal,
realized_pnl: Decimal,
isolated_wallet: Decimal,
)
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 adjustmentsbreakeven_price- Price at which the position breaks even (includes fees)unrealized_pnl- Current unrealized profit/loss at market pricerealized_pnl- Accumulated realized profit/loss from closed portionsisolated_wallet- Available margin for isolated positions (0 for cross margin)
§Field Mutations
This method updates the following fields:
amount: Position size with sign indicating directionentry_price: Average entry price (weighted by fills)breakeven_price: Break-even price including fees and fundingunrealized_pnl: Mark-to-market P&L at current pricerealized_pnl: Cumulative realized P&L from position reductionsisolated_wallet: Margin available for isolated positionsupdate_time_ns: Automatically set to current nanosecond timestamp
§Performance Notes
- Cache-line aligned struct (
#[repr(align(64))]) for optimal memory access - Uses high-precision
Decimalarithmetic 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
);Sourcepub fn get_notional_value(&self, current_price: Decimal) -> Decimal
pub fn get_notional_value(&self, current_price: Decimal) -> Decimal
Get position value at current price
Trait Implementations§
Source§impl Clone for FuturesPosition
impl Clone for FuturesPosition
Source§fn clone(&self) -> FuturesPosition
fn clone(&self) -> FuturesPosition
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source. Read more