BaseStrategy

Struct BaseStrategy 

Source
pub struct BaseStrategy<E: Exchange + 'static> {
    pub exchange: Arc<E>,
    pub market_id: String,
    pub market: Option<Market>,
    pub state: StrategyState,
    pub config: StrategyConfig,
    pub positions: Vec<Position>,
    pub open_orders: Vec<Order>,
    pub event_tx: Sender<StrategyEvent>,
    /* private fields */
}

Fields§

§exchange: Arc<E>§market_id: String§market: Option<Market>§state: StrategyState§config: StrategyConfig§positions: Vec<Position>§open_orders: Vec<Order>§event_tx: Sender<StrategyEvent>

Implementations§

Source§

impl<E: Exchange + 'static> BaseStrategy<E>

Source

pub fn new(exchange: Arc<E>, market_id: String, config: StrategyConfig) -> Self

Source

pub fn subscribe(&self) -> Receiver<StrategyEvent>

Source

pub async fn refresh_state(&mut self) -> Result<(), DrmError>

Source

pub async fn cancel_all_orders(&mut self) -> Result<(), DrmError>

Source

pub fn get_position(&self, outcome: &str) -> Option<&Position>

Source

pub fn get_net_position(&self) -> f64

Source

pub async fn place_order( &mut self, outcome: &str, side: OrderSide, price: f64, size: f64, token_id: Option<&str>, ) -> Result<Order, DrmError>

Source

pub fn log(&self, message: &str)

Source

pub fn is_running(&self) -> bool

Source

pub async fn signal_stop(&self)

Source

pub async fn should_stop(&self) -> bool

Source

pub async fn reset_stop_signal(&self)

Source

pub async fn run_loop<F, Fut>(&mut self, on_tick: F) -> Result<(), DrmError>
where F: FnMut(&mut Self) -> Fut + Send, Fut: Future<Output = Result<(), DrmError>> + Send,

Source

pub fn pause(&mut self)

Source

pub fn resume(&mut self)

Source

pub async fn get_account_state(&self) -> Result<AccountState, DrmError>

Source

pub fn calculate_order_size(&self, price: f64, max_exposure: f64) -> f64

Source

pub fn calculate_spread_prices( &self, mid_price: f64, spread_bps: u32, ) -> (f64, f64)

Trait Implementations§

Source§

impl<E: Exchange + 'static> Drop for BaseStrategy<E>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<E> Freeze for BaseStrategy<E>

§

impl<E> !RefUnwindSafe for BaseStrategy<E>

§

impl<E> Send for BaseStrategy<E>

§

impl<E> Sync for BaseStrategy<E>

§

impl<E> Unpin for BaseStrategy<E>

§

impl<E> !UnwindSafe for BaseStrategy<E>

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