pub struct Position {
Show 18 fields pub position_id: PositionId, pub meta: PositionMeta, pub exchange: String, pub symbol: SymbolId, pub direction: Direction, pub quantity: f64, pub enter_fees: Fees, pub enter_fees_total: FeeAmount, pub enter_avg_price_gross: f64, pub enter_value_gross: f64, pub exit_fees: Fees, pub exit_fees_total: FeeAmount, pub exit_avg_price_gross: f64, pub exit_value_gross: f64, pub current_symbol_price: f64, pub current_value_gross: f64, pub unrealised_profit_loss: f64, pub realised_profit_loss: f64,
}
Expand description

Data encapsulating the state of an ongoing or closed Position.

Fields

position_id: PositionId

Unique identifier for a Position generated from an engine_id, ExchangeId & SymbolId.

meta: PositionMeta

Metadata detailing trace UUIDs, timestamps & equity associated with entering, updating & exiting.

exchange: String

Exchange associated with this Position instance.

symbol: SymbolId

Ticker symbol associated with this Position instance.

direction: Direction

Long or Short.

quantity: f64

+ve or -ve quantity of symbol contracts opened.

enter_fees: Fees

All fees types incurred from entering a Position, and their associated FeeAmount.

enter_fees_total: FeeAmount

Total of enter_fees incurred. Sum of every FeeAmount in Fees when entering a Position.

enter_avg_price_gross: f64

Enter average price excluding the entry_fees_total.

enter_value_gross: f64

abs(Quantity) * enter_avg_price_gross.

exit_fees: Fees

All fees types incurred from exiting a Position, and their associated FeeAmount.

exit_fees_total: FeeAmount

Total of exit_fees incurred. Sum of every FeeAmount in Fees when entering a Position.

exit_avg_price_gross: f64

Exit average price excluding the exit_fees_total.

exit_value_gross: f64

abs(Quantity) * exit_avg_price_gross.

current_symbol_price: f64

Symbol current close price.

current_value_gross: f64

abs(Quantity) * current_symbol_price.

unrealised_profit_loss: f64

Unrealised P&L whilst the Position is open.

realised_profit_loss: f64

Realised P&L after the Position has closed.

Implementations

Returns a PositionBuilder instance.

source

pub fn parse_entry_direction(
    fill: &FillEvent
) -> Result<Direction, PortfolioError>

Determine the Position entry Direction by analysing the input FillEvent.

Calculate the approximate Position::unrealised_profit_loss of a Position.

Calculate the exact Position::realised_profit_loss of a Position.

Calculate the PnL return of a closed Position - assumed Position::realised_profit_loss is appropriately calculated.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Converts to this type from the input type.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Returns a new Position, given an input FillEvent & an associated engine_id.

Exits an open Position, given the input Portfolio equity & the FillEvent returned from an Execution handler. Read more

Updates an open Position using the latest input MarketEvent, returning a PositionUpdate that communicates the open Position’s change in state. Read more

Serialize this value into the given Serde serializer. Read more

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

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

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

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