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
enter_fees_total: FeeAmount
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
exit_fees_total: FeeAmount
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
sourceimpl Position
impl Position
sourcepub fn builder() -> PositionBuilder
pub fn builder() -> PositionBuilder
Returns a PositionBuilder
instance.
sourcepub fn calculate_avg_price_gross(fill: &FillEvent) -> f64
pub fn calculate_avg_price_gross(fill: &FillEvent) -> f64
Calculates the Position::enter_avg_price_gross
or Position::exit_avg_price_gross
of
a FillEvent
.
sourcepub fn parse_entry_direction(
fill: &FillEvent
) -> Result<Direction, PortfolioError>
pub fn parse_entry_direction(
fill: &FillEvent
) -> Result<Direction, PortfolioError>
sourcepub fn calculate_unrealised_profit_loss(&self) -> f64
pub fn calculate_unrealised_profit_loss(&self) -> f64
Calculate the approximate Position::unrealised_profit_loss
of a Position
.
sourcepub fn calculate_realised_profit_loss(&self) -> f64
pub fn calculate_realised_profit_loss(&self) -> f64
Calculate the exact Position::realised_profit_loss
of a Position
.
sourcepub fn calculate_profit_loss_return(&self) -> f64
pub fn calculate_profit_loss_return(&self) -> f64
Calculate the PnL return of a closed Position
- assumed Position::realised_profit_loss
is
appropriately calculated.
Trait Implementations
sourceimpl<'de> Deserialize<'de> for Position
impl<'de> Deserialize<'de> for Position
sourcefn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl From<&'_ mut Position> for PositionUpdate
impl From<&'_ mut Position> for PositionUpdate
sourceimpl PartialOrd<Position> for Position
impl PartialOrd<Position> for Position
sourcefn partial_cmp(&self, other: &Position) -> Option<Ordering>
fn partial_cmp(&self, other: &Position) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
sourceimpl PositionEnterer for Position
impl PositionEnterer for Position
sourceimpl PositionExiter for Position
impl PositionExiter for Position
sourcefn exit(
&mut self,
balance: Balance,
fill: &FillEvent
) -> Result<PositionExit, PortfolioError>
fn exit(
&mut self,
balance: Balance,
fill: &FillEvent
) -> Result<PositionExit, PortfolioError>
sourceimpl PositionUpdater for Position
impl PositionUpdater for Position
sourcefn update(&mut self, market: &MarketEvent) -> PositionUpdate
fn update(&mut self, market: &MarketEvent) -> PositionUpdate
Updates an open Position
using the latest input MarketEvent
, returning a
PositionUpdate
that communicates the open Position
’s change in state. Read more
sourceimpl TryFrom<&'_ mut Position> for PositionExit
impl TryFrom<&'_ mut Position> for PositionExit
impl StructuralPartialEq for Position
Auto Trait Implementations
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnwindSafe for Position
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
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
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more