Skip to main content

FuturePosition

Struct FuturePosition 

Source
pub struct FuturePosition {
    pub symbol: String,
    pub quantity: Positive,
    pub entry_price: Positive,
    pub side: Side,
    pub expiration_date: ExpirationDate,
    pub contract_size: Positive,
    pub initial_margin_req: Positive,
    pub maintenance_margin_req: Positive,
    pub date: DateTime<Utc>,
    pub fees: Positive,
}
Expand description

Represents a futures contract position.

Futures are standardized contracts traded on exchanges that obligate the buyer to purchase (or seller to sell) an asset at a predetermined price on a specific future date.

§Fields

  • symbol - Contract symbol (e.g., “ES”, “CL”, “BTC-QUARTERLY”)
  • quantity - Number of contracts
  • entry_price - Average entry price
  • side - Long or Short position
  • expiration_date - Contract expiry date
  • contract_size - Multiplier (e.g., 50 for ES, 1000 for CL)
  • initial_margin - Initial margin requirement
  • maintenance_margin - Maintenance margin level
  • date - Position open timestamp
  • fees - Commission and exchange fees

Fields§

§symbol: String

Contract symbol (e.g., “ES”, “CL”, “GC”).

§quantity: Positive

Number of contracts held.

§entry_price: Positive

Average entry price per contract.

§side: Side

Position direction (Long or Short).

§expiration_date: ExpirationDate

Contract expiration date.

§contract_size: Positive

Contract size multiplier (notional per point).

§initial_margin_req: Positive

Initial margin requirement per contract.

§maintenance_margin_req: Positive

Maintenance margin requirement per contract.

§date: DateTime<Utc>

Timestamp when the position was opened.

§fees: Positive

Total trading fees paid.

Implementations§

Source§

impl FuturePosition

Source

pub fn new( symbol: String, quantity: Positive, entry_price: Positive, side: Side, expiration_date: ExpirationDate, contract_size: Positive, initial_margin_req: Positive, maintenance_margin_req: Positive, date: DateTime<Utc>, fees: Positive, ) -> Self

Creates a new futures position.

§Arguments
  • symbol - Contract symbol
  • quantity - Number of contracts
  • entry_price - Average entry price
  • side - Long or Short
  • expiration_date - Contract expiry
  • contract_size - Contract multiplier
  • initial_margin_req - Initial margin per contract
  • maintenance_margin_req - Maintenance margin per contract
  • date - Position open timestamp
  • fees - Trading fees
Source

pub fn long( symbol: String, quantity: Positive, entry_price: Positive, expiration_date: ExpirationDate, contract_size: Positive, margin: Positive, ) -> Self

Creates a long futures position with default settings.

§Arguments
  • symbol - Contract symbol
  • quantity - Number of contracts
  • entry_price - Entry price
  • expiration_date - Contract expiry
  • contract_size - Contract multiplier
  • margin - Margin requirement
Source

pub fn short( symbol: String, quantity: Positive, entry_price: Positive, expiration_date: ExpirationDate, contract_size: Positive, margin: Positive, ) -> Self

Creates a short futures position with default settings.

§Arguments
  • symbol - Contract symbol
  • quantity - Number of contracts
  • entry_price - Entry price
  • expiration_date - Contract expiry
  • contract_size - Contract multiplier
  • margin - Margin requirement
Source

pub fn notional_value_at_entry(&self) -> Result<Positive, PositionError>

Returns the notional value of the position at entry.

Notional = quantity × entry_price × contract_size

§Errors

Returns PositionError::PositiveError when the product leaves the Positive range. The three factors are pub fields, so nothing bounds it; Positive * Positive aborted on it (#788).

Source

pub fn notional_value_at_price( &self, current_price: Positive, ) -> Result<Positive, PositionError>

Returns the notional value at a given price.

§Arguments
  • current_price - Current market price
§Errors

Returns PositionError::PositiveError when the product leaves the Positive range (#788).

Source

pub fn unrealized_pnl( &self, current_price: Positive, ) -> Result<Decimal, PositionError>

Calculates the unrealized P&L at a given price.

§Arguments
  • current_price - Current market price
§Decision (issue #471): fallible because pnl_at_price is

This is the whole body of LegAble::pnl_at_price for a future, so leaving it infallible would have moved that method’s abort one frame down rather than removing it. entry_price, quantity and contract_size are pub, so no constructor guard bounds the product.

§Errors

Returns PositionError::DecimalError when the price difference, the quantity scaling or the contract-size scaling leaves the representable Decimal range.

Source

pub fn tick_value(&self, tick_size: Positive) -> Result<Positive, PositionError>

Calculates the tick value (value of one minimum price movement).

§Arguments
  • tick_size - Minimum price increment
§Errors

Returns PositionError::PositiveError when the product leaves the Positive range (#788).

Source

pub fn total_margin_required(&self) -> Result<Positive, PositionError>

Returns the total margin required for this position.

§Errors

Returns PositionError::PositiveError when the product leaves the Positive range (#788).

Source

pub fn basis(&self, spot_price: Positive) -> Decimal

Calculates the basis (futures price - spot price).

§Arguments
  • spot_price - Current spot price of the underlying
Source

pub fn implied_leverage(&self) -> Result<Decimal, PositionError>

Calculates the implied leverage of the position.

Leverage = Notional Value / Margin Required, and zero when no margin is required.

§Errors

Returns PositionError when the notional, the margin or their ratio leaves the representable range (#788).

Trait Implementations§

Source§

impl Clone for FuturePosition

Source§

fn clone(&self) -> Self

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 ComposeSchema for FuturePosition

Source§

impl Debug for FuturePosition

Source§

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

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

impl Default for FuturePosition

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for FuturePosition

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 Display for FuturePosition

Source§

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

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

impl Expirable for FuturePosition

Source§

fn expiration_timestamp(&self) -> Result<i64, PositionError>

Returns the expiration date as a Unix timestamp in seconds. Read more
Source§

fn days_to_expiration(&self) -> Result<Positive, PositionError>

Returns the number of days until expiration. Read more
Source§

fn is_expired(&self) -> Result<bool, PositionError>

Checks if the position has expired. Read more
Source§

fn time_to_expiration_years(&self) -> Result<Decimal, PositionError>

Returns the time to expiration in years (for pricing calculations). Read more
Source§

impl From<FuturePosition> for Leg

Source§

fn from(position: FuturePosition) -> Self

Converts to this type from the input type.
Source§

impl LegAble for FuturePosition

Source§

fn get_symbol(&self) -> &str

Returns the symbol/ticker of the underlying instrument.
Source§

fn get_quantity(&self) -> Positive

Returns the position quantity in the leg’s native unit (#830). Read more
Source§

fn get_side(&self) -> Side

Returns the position side (Long or Short).
Source§

fn pnl_at_price(&self, price: Positive) -> Result<Decimal, PositionError>

Calculates the profit/loss at a given price. Read more
Source§

fn total_cost(&self) -> Result<Positive, PositionError>

Returns the total cost to establish this position. Read more
Source§

fn fees(&self) -> Result<Positive, PositionError>

Returns the total fees associated with this position. Read more
Source§

fn is_long(&self) -> bool

Checks if this is a long position.
Source§

fn is_short(&self) -> bool

Checks if this is a short position.
Source§

fn notional_value(&self, price: Positive) -> Result<Positive, PositionError>

Returns the notional value of the position at a given price. Read more
Source§

impl Marginable for FuturePosition

Source§

fn liquidation_price( &self, _current_price: Positive, ) -> Result<Option<Positive>, PositionError>

None for a long whose margin buffer per unit exceeds the entry price: no non-negative price liquidates it. A short threshold below zero is floored at zero, the documented domain floor of Marginable::liquidation_price.

§Errors

Returns PositionError::DecimalError for a zero quantity or contract size, where the buffer per unit is undefined (the division aborted with Division by zero, #788), and when a margin, the buffer or the shifted price leaves the representable range.

Source§

fn initial_margin(&self) -> Result<Positive, PositionError>

Returns the initial margin requirement. Read more
Source§

fn maintenance_margin(&self) -> Result<Positive, PositionError>

Returns the maintenance margin requirement. Read more
Source§

fn leverage(&self) -> Result<Positive, PositionError>

Returns the current leverage applied to the position. Read more
Source§

fn is_liquidation_risk( &self, current_price: Positive, _margin_ratio: Decimal, ) -> Result<bool, PositionError>

Checks if the position is at risk of liquidation. Read more
Source§

impl PartialEq for FuturePosition

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for FuturePosition

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

impl StructuralPartialEq for FuturePosition

Source§

impl ToSchema for FuturePosition

Source§

fn name() -> Cow<'static, str>

Return name of the schema. Read more
Source§

fn schemas(schemas: &mut Vec<(String, RefOr<Schema>)>)

Implement reference utoipa::openapi::schema::Schemas for this 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> 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> Instrument for T

Source§

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

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

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.

Source§

impl<T> PartialSchema for T
where T: ComposeSchema + ?Sized,

Source§

fn schema() -> RefOr<Schema>

Return ref or schema of implementing type that can then be used to construct combined schemas.
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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