pub struct TradePosition { /* private fields */ }

Implementations§

source§

impl TradePosition

source

pub fn new( id: u32, order_id: &str, ordered_price: f64, order_effective_duration: i64, token_name: &str, fund_name: &str, position_type: PositionType, predicted_price: f64, atr: Option<f64> ) -> Self

source

pub fn on_opened( &mut self, average_open_price: f64, amount: f64, amount_in_anchor_token: f64, fee: f64, take_profit_price: f64, cut_loss_price: f64 ) -> Result<(), ()>

source

pub fn request_close(&mut self, order_id: &str, reason: &str) -> Result<(), ()>

source

pub fn on_closed( &mut self, close_price: Option<f64>, fee: f64, do_liquidate: bool, liquidated_reason: Option<String> )

source

pub fn cancel(&mut self) -> bool

source

pub fn on_updated( &mut self, current_price: f64, average_open_price: f64, position_type: PositionType, take_profit_price: f64, cut_loss_price: f64, amount: f64, amount_in_anchor_token: f64, fee: f64 )

source

pub fn should_cancel_order(&self) -> bool

source

pub fn should_close(&self, close_price: f64) -> Option<ReasonForClose>

source

pub fn is_expired(&self, max_holding_duration: i64) -> Option<ReasonForClose>

source

pub fn total_pnl(&self, current_price: Option<f64>) -> Option<f64>

source

pub fn id(&self) -> Option<u32>

source

pub fn average_open_price(&self) -> f64

source

pub fn order_id(&self) -> &str

source

pub fn ordered_price(&self) -> f64

source

pub fn predicted_price(&self) -> f64

source

pub fn state(&self) -> State

source

pub fn token_name(&self) -> &str

source

pub fn fund_name(&self) -> &str

source

pub fn amount(&self) -> f64

source

pub fn position_type(&self) -> PositionType

source

pub fn cut_loss_price(&self) -> f64

source

pub fn amount_in_anchor_token(&self) -> f64

source

pub fn print_info(&self, current_price: f64)

Trait Implementations§

source§

impl Clone for TradePosition

source§

fn clone(&self) -> TradePosition

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for TradePosition

source§

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

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

impl Default for TradePosition

source§

fn default() -> TradePosition

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

impl<'de> Deserialize<'de> for TradePosition

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 HasId for TradePosition

source§

fn id(&self) -> Option<u32>

source§

impl Serialize for TradePosition

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

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

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

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, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,