Struct lfest::prelude::Exchange

source ·
pub struct Exchange<A, Q, UserOrderId>
where Q: Currency, Q::PairedCurrency: MarginCurrency, UserOrderId: Clone + Debug + Eq + PartialEq + Hash,
{ /* private fields */ }
Expand description

The main leveraged futures exchange for simulated trading

Implementations§

source§

impl<A, Q, UserOrderId> Exchange<A, Q, UserOrderId>
where Q: Currency, Q::PairedCurrency: MarginCurrency, UserOrderId: Clone + Debug + Eq + PartialEq + Hash,

source

pub fn config(&self) -> &Config<Q::PairedCurrency>

The exchange configuration.

source

pub fn market_state(&self) -> &MarketState

The current state of the simulated market.

source

pub fn account(&self) -> &Account<Q::PairedCurrency, UserOrderId>

The main user account.

source

pub fn account_tracker(&self) -> &A

A performance tracker for the user account.

source§

impl<A, Q, UserOrderId> Exchange<A, Q, UserOrderId>

source

pub fn new(account_tracker: A, config: Config<Q::PairedCurrency>) -> Self

Create a new Exchange with the desired config and whether to use candles as infomation source

source

pub fn update_state( &mut self, timestamp_ns: TimestampNs, market_update: MarketUpdate<Q> ) -> Result<Vec<LimitOrderUpdate<Q, UserOrderId>>>

Update the exchange state with new information

§Parameters:

timestamp_ns: Is used in the AccountTracker A and if setting order timestamps is enabled in the config. market_update: Newest market information

§Returns:

If Ok, returns updates regarding limit orders, wether partially filled or fully.

source

pub fn submit_limit_order( &mut self, order: LimitOrder<Q, UserOrderId, NewOrder> ) -> Result<LimitOrder<Q, UserOrderId, Pending<Q>>>

§Arguments:

order: The order that is being submitted.

§Returns:

If Ok, the order with timestamp and id filled in. Else its an error.

source

pub fn submit_market_order( &mut self, order: MarketOrder<Q, UserOrderId, NewOrder> ) -> Result<MarketOrder<Q, UserOrderId, Filled>>

Submit a new MarketOrder to the exchange.

§Arguments:

order: The order that is being submitted.

§Returns:

If Ok, the order with timestamp and id filled in. Else its an error.

source

pub fn cancel_limit_order_by_user_id( &mut self, user_order_id: UserOrderId ) -> Result<LimitOrder<Q, UserOrderId, Pending<Q>>>

Cancel an active limit order based on the user_order_id.

§Arguments:

user_order_id: The user order id of the order to cancel.

§Returns:

the cancelled order if successfull, error when the user_order_id is not found

source

pub fn cancel_order( &mut self, order_id: OrderId ) -> Result<LimitOrder<Q, UserOrderId, Pending<Q>>>

Cancel an active limit order.

§Arguments:

order_id: The id (assigned by the exchange) of the order to cancel.

§Returns:

An order if successful with the given order_id.

Trait Implementations§

source§

impl<A: Clone, Q, UserOrderId> Clone for Exchange<A, Q, UserOrderId>
where Q: Currency + Clone, Q::PairedCurrency: MarginCurrency + Clone, UserOrderId: Clone + Debug + Eq + PartialEq + Hash + Clone,

source§

fn clone(&self) -> Exchange<A, Q, UserOrderId>

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<A: Debug, Q, UserOrderId> Debug for Exchange<A, Q, UserOrderId>
where Q: Currency + Debug, Q::PairedCurrency: MarginCurrency + Debug, UserOrderId: Clone + Debug + Eq + PartialEq + Hash + Debug,

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A, Q, UserOrderId> Freeze for Exchange<A, Q, UserOrderId>
where <Q as Currency>::PairedCurrency: Sized + Freeze, A: Freeze, Q: Freeze,

§

impl<A, Q, UserOrderId> RefUnwindSafe for Exchange<A, Q, UserOrderId>

§

impl<A, Q, UserOrderId> Send for Exchange<A, Q, UserOrderId>
where <Q as Currency>::PairedCurrency: Sized, A: Send, UserOrderId: Send,

§

impl<A, Q, UserOrderId> Sync for Exchange<A, Q, UserOrderId>
where <Q as Currency>::PairedCurrency: Sized + Sync, A: Sync, Q: Sync, UserOrderId: Sync,

§

impl<A, Q, UserOrderId> Unpin for Exchange<A, Q, UserOrderId>
where <Q as Currency>::PairedCurrency: Sized + Unpin, A: Unpin, Q: Unpin, UserOrderId: Unpin,

§

impl<A, Q, UserOrderId> UnwindSafe for Exchange<A, Q, UserOrderId>
where <Q as Currency>::PairedCurrency: Sized + UnwindSafe, A: UnwindSafe, Q: UnwindSafe, UserOrderId: UnwindSafe,

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.

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