pub struct Position {
pub qty: f64,
pub entry_price: Option<f64>,
pub unrealised_pnl: f64,
}Expand description
Current exchange-reported position for a single symbol.
qty is signed: positive = long, negative = short, zero = flat.
§Example
use rustrade_core::{Position, Side};
// A 2-contract long opened at 100.
let long = Position {
qty: 2.0,
entry_price: Some(100.0),
unrealised_pnl: 0.0,
};
assert!(!long.is_flat());
assert_eq!(long.close_side(), Some(Side::Sell)); // close a long with a sell
// The constant for "no position".
assert!(Position::FLAT.is_flat());
assert!(Position::FLAT.close_side().is_none());Fields§
§qty: f64Signed position size — positive = long, negative = short.
entry_price: Option<f64>Average entry price (weighted by qty if multiple opens), or
None for a flat position.
unrealised_pnl: f64Unrealised PnL at the most recent mark price, in quote currency.
Implementations§
Trait Implementations§
impl Copy for Position
Source§impl<'de> Deserialize<'de> for Position
impl<'de> Deserialize<'de> for Position
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Position, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Position, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for Position
impl Serialize for Position
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl StructuralPartialEq for Position
Auto Trait Implementations§
impl Freeze for Position
impl RefUnwindSafe for Position
impl Send for Position
impl Sync for Position
impl Unpin for Position
impl UnsafeUnpin for Position
impl UnwindSafe for Position
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more