pub struct Position {
pub id: usize,
pub symbol: String,
pub side: Side,
pub open_time: NaiveDateTime,
pub open_price: f64,
pub volume: f64,
pub sl: Option<f64>,
pub tp: Option<f64>,
pub margin_required: f64,
}Expand description
Represents an active position in the market.
Fields§
§id: usize§symbol: String§side: Side§open_time: NaiveDateTime§open_price: f64§volume: f64§sl: Option<f64>§tp: Option<f64>§margin_required: f64Margin required for this position
Implementations§
Source§impl Position
impl Position
pub fn new( id: usize, symbol: String, side: Side, open_time: NaiveDateTime, open_price: f64, volume: f64, sl: Option<f64>, tp: Option<f64>, margin_required: f64, ) -> Self
Sourcepub fn unrealized_pnl(&self, current_price: f64) -> f64
pub fn unrealized_pnl(&self, current_price: f64) -> f64
Calculate unrealized PnL based on current market price. For BUY: (Current - Open) * Volume * ContractSize For SELL: (Open - Current) * Volume * ContractSize
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Position
impl<'de> Deserialize<'de> for Position
Source§fn 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
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more