Struct Backtest

Source
pub struct Backtest<MD> { /* private fields */ }
Available on crate feature backtest only.
Expand description

This backtester provides multi-asset and multi-exchange model backtesting, allowing you to configure different setups such as queue models or asset types for each asset. However, this may result in slightly slower performance compared to Backtest.

Implementations§

Source§

impl<MD> Backtest<MD>
where MD: MarketDepth,

Source

pub fn builder() -> BacktestBuilder<MD>

Source

pub fn new( local: Vec<Box<dyn LocalProcessor<MD>>>, exch: Vec<Box<dyn Processor>>, reader: Vec<Reader<Event>>, ) -> Self

Source

pub fn goto_end(&mut self) -> Result<ElapseResult, BacktestError>

Trait Implementations§

Source§

impl<MD> Bot<MD> for Backtest<MD>
where MD: MarketDepth,

Source§

type Error = BacktestError

Source§

fn current_timestamp(&self) -> i64

In backtesting, this timestamp reflects the time at which the backtesting is conducted within the provided data. In a live bot, it’s literally the current local timestamp.
Source§

fn num_assets(&self) -> usize

Returns the number of assets.
Source§

fn position(&self, asset_no: usize) -> f64

Returns the position you currently hold. Read more
Source§

fn state_values(&self, asset_no: usize) -> &StateValues

Returns the state’s values such as balance, fee, and so on.
Source§

fn depth(&self, asset_no: usize) -> &MD

Returns the MarketDepth. Read more
Source§

fn last_trades(&self, asset_no: usize) -> &[Event]

Returns the last market trades. Read more
Source§

fn clear_last_trades(&mut self, asset_no: Option<usize>)

Clears the last market trades from the buffer. Read more
Source§

fn orders(&self, asset_no: usize) -> &HashMap<u64, Order>

Returns a hash map of order IDs and their corresponding Orders. Read more
Source§

fn submit_buy_order( &mut self, asset_no: usize, order_id: OrderId, price: f64, qty: f64, time_in_force: TimeInForce, order_type: OrdType, wait: bool, ) -> Result<ElapseResult, Self::Error>

Places a buy order. Read more
Source§

fn submit_sell_order( &mut self, asset_no: usize, order_id: OrderId, price: f64, qty: f64, time_in_force: TimeInForce, order_type: OrdType, wait: bool, ) -> Result<ElapseResult, Self::Error>

Places a sell order. Read more
Source§

fn submit_order( &mut self, asset_no: usize, order: OrderRequest, wait: bool, ) -> Result<ElapseResult, Self::Error>

Places an order.
Source§

fn modify( &mut self, asset_no: usize, order_id: OrderId, price: f64, qty: f64, wait: bool, ) -> Result<ElapseResult, Self::Error>

Modifies an open order. Read more
Source§

fn cancel( &mut self, asset_no: usize, order_id: OrderId, wait: bool, ) -> Result<ElapseResult, Self::Error>

Cancels an open order. Read more
Source§

fn clear_inactive_orders(&mut self, asset_no: Option<usize>)

Clears inactive orders from the local orders whose status is neither Status::New nor Status::PartiallyFilled.
Source§

fn wait_order_response( &mut self, asset_no: usize, order_id: OrderId, timeout: i64, ) -> Result<ElapseResult, BacktestError>

Waits for the response of the order with the given order ID until timeout.
Source§

fn wait_next_feed( &mut self, include_order_resp: bool, timeout: i64, ) -> Result<ElapseResult, Self::Error>

Wait until the next feed is received, or until timeout.
Source§

fn elapse(&mut self, duration: i64) -> Result<ElapseResult, Self::Error>

Elapses the specified duration. Read more
Source§

fn elapse_bt(&mut self, duration: i64) -> Result<ElapseResult, Self::Error>

Elapses time only in backtesting. In live mode, it is ignored. Read more
Source§

fn close(&mut self) -> Result<(), Self::Error>

Closes this backtester or bot.
Source§

fn feed_latency(&self, asset_no: usize) -> Option<(i64, i64)>

Returns the last feed’s exchange timestamp and local receipt timestamp.
Source§

fn order_latency(&self, asset_no: usize) -> Option<(i64, i64, i64)>

Returns the last order’s request timestamp, exchange timestamp, and response receipt timestamp.

Auto Trait Implementations§

§

impl<MD> Freeze for Backtest<MD>

§

impl<MD> !RefUnwindSafe for Backtest<MD>

§

impl<MD> !Send for Backtest<MD>

§

impl<MD> !Sync for Backtest<MD>

§

impl<MD> Unpin for Backtest<MD>

§

impl<MD> !UnwindSafe for Backtest<MD>

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

Source§

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

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

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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

Source§

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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