StrategyCore

Struct StrategyCore 

Source
pub struct StrategyCore {
    pub actor: DataActorCore,
    pub config: StrategyConfig,
    pub order_manager: Option<OrderManager>,
    pub order_factory: Option<OrderFactory>,
    pub portfolio: Option<Rc<RefCell<Portfolio>>>,
    pub gtd_timers: AHashMap<ClientOrderId, Ustr>,
}
Expand description

The core component of a Strategy, managing data, orders, and state.

This struct is intended to be held as a member within a user’s custom strategy struct. The user’s struct should then Deref and DerefMut to this StrategyCore instance to satisfy the trait bounds of Strategy and DataActor.

Fields§

§actor: DataActorCore

The underlying data actor core.

§config: StrategyConfig

The strategy configuration.

§order_manager: Option<OrderManager>

The order manager.

§order_factory: Option<OrderFactory>

The order factory.

§portfolio: Option<Rc<RefCell<Portfolio>>>

The portfolio.

§gtd_timers: AHashMap<ClientOrderId, Ustr>

Maps client order IDs to GTD expiry timer names.

Implementations§

Source§

impl StrategyCore

Source

pub fn new(config: StrategyConfig) -> Self

Creates a new StrategyCore instance.

Source

pub fn register( &mut self, trader_id: TraderId, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, portfolio: Rc<RefCell<Portfolio>>, ) -> Result<()>

Registers the strategy with the trading engine components.

This is typically called by the framework when the strategy is added to an engine.

§Errors

Returns an error if registration with the actor core fails.

Methods from Deref<Target = DataActorCore>§

Source

pub fn mem_address(&self) -> String

Returns the memory address of this instance as a hexadecimal string.

Source

pub fn state(&self) -> ComponentState

Returns the actors state.

Source

pub fn trader_id(&self) -> Option<TraderId>

Returns the trader ID this actor is registered to.

Source

pub fn actor_id(&self) -> ActorId

Returns the actors ID.

Source

pub fn timestamp_ns(&self) -> UnixNanos

Returns a UNIX nanoseconds timestamp from the actor’s internal clock.

Source

pub fn clock(&mut self) -> RefMut<'_, dyn Clock + 'static>

Returns the clock for the actor (if registered).

§Panics

Panics if the actor has not been registered with a trader.

Source

pub fn clock_rc(&self) -> Rc<RefCell<dyn Clock>>

Returns a clone of the reference-counted clock.

§Panics

Panics if the actor has not yet been registered (clock is None).

Source

pub fn cache(&self) -> Ref<'_, Cache>

Returns a read-only reference to the cache.

§Panics

Panics if the actor has not yet been registered (cache is None).

Source

pub fn cache_rc(&self) -> Rc<RefCell<Cache>>

Returns a clone of the reference-counted cache.

§Panics

Panics if the actor has not yet been registered (cache is None).

Source

pub fn register( &mut self, trader_id: TraderId, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, ) -> Result<(), Error>

Register the data actor with a trader.

§Errors

Returns an error if the actor has already been registered with a trader or if the provided dependencies are invalid.

Source

pub fn register_warning_event(&mut self, event_type: &str)

Register an event type for warning log levels.

Source

pub fn deregister_warning_event(&mut self, event_type: &str)

Deregister an event type from warning log levels.

Source

pub fn is_registered(&self) -> bool

Source

pub fn shutdown_system(&self, reason: Option<String>)

Sends a shutdown command to the system with an optional reason.

§Panics

Panics if the actor is not registered or has no trader ID.

Source

pub fn subscribe_data( &mut self, handler: ShareableMessageHandler, data_type: DataType, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering data subscriptions from the trait.

§Panics

Panics if the actor is not properly registered.

Source

pub fn subscribe_quotes( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering quotes subscriptions from the trait.

Source

pub fn subscribe_instruments( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, venue: Venue, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering instruments subscriptions from the trait.

Source

pub fn subscribe_instrument( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering instrument subscriptions from the trait.

Source

pub fn subscribe_book_deltas( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, book_type: BookType, depth: Option<NonZero<usize>>, client_id: Option<ClientId>, managed: bool, params: Option<IndexMap<String, String>>, )

Helper method for registering book deltas subscriptions from the trait.

Source

pub fn subscribe_book_at_interval( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, book_type: BookType, depth: Option<NonZero<usize>>, interval_ms: NonZero<usize>, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering book snapshots subscriptions from the trait.

Source

pub fn subscribe_trades( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering trades subscriptions from the trait.

Source

pub fn subscribe_bars( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, bar_type: BarType, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering bars subscriptions from the trait.

Source

pub fn subscribe_mark_prices( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering mark prices subscriptions from the trait.

Source

pub fn subscribe_index_prices( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering index prices subscriptions from the trait.

Source

pub fn subscribe_funding_rates( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering funding rates subscriptions from the trait.

Source

pub fn subscribe_instrument_status( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering instrument status subscriptions from the trait.

Source

pub fn subscribe_instrument_close( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering instrument close subscriptions from the trait.

Source

pub fn subscribe_order_fills( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, )

Helper method for registering order fills subscriptions from the trait.

Source

pub fn subscribe_order_cancels( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, )

Helper method for registering order cancels subscriptions from the trait.

Source

pub fn unsubscribe_data( &mut self, data_type: DataType, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from data.

Source

pub fn unsubscribe_instruments( &mut self, venue: Venue, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from instruments.

Source

pub fn unsubscribe_instrument( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from instrument.

Source

pub fn unsubscribe_book_deltas( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from book deltas.

Source

pub fn unsubscribe_book_at_interval( &mut self, instrument_id: InstrumentId, interval_ms: NonZero<usize>, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from book snapshots at interval.

Source

pub fn unsubscribe_quotes( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from quotes.

Source

pub fn unsubscribe_trades( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from trades.

Source

pub fn unsubscribe_bars( &mut self, bar_type: BarType, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from bars.

Source

pub fn unsubscribe_mark_prices( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from mark prices.

Source

pub fn unsubscribe_index_prices( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from index prices.

Source

pub fn unsubscribe_funding_rates( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from funding rates.

Source

pub fn unsubscribe_instrument_status( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from instrument status.

Source

pub fn unsubscribe_instrument_close( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from instrument close.

Source

pub fn unsubscribe_order_fills(&mut self, instrument_id: InstrumentId)

Helper method for unsubscribing from order fills.

Source

pub fn unsubscribe_order_cancels(&mut self, instrument_id: InstrumentId)

Helper method for unsubscribing from order cancels.

Source

pub fn request_data( &self, data_type: DataType, client_id: ClientId, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<NonZero<usize>>, params: Option<IndexMap<String, String>>, handler: ShareableMessageHandler, ) -> Result<UUID4, Error>

Helper method for requesting data.

§Errors

Returns an error if input parameters are invalid.

Source

pub fn request_instrument( &self, instrument_id: InstrumentId, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, handler: ShareableMessageHandler, ) -> Result<UUID4, Error>

Helper method for requesting instrument.

§Errors

Returns an error if input parameters are invalid.

Source

pub fn request_instruments( &self, venue: Option<Venue>, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, handler: ShareableMessageHandler, ) -> Result<UUID4, Error>

Helper method for requesting instruments.

§Errors

Returns an error if input parameters are invalid.

Source

pub fn request_book_snapshot( &self, instrument_id: InstrumentId, depth: Option<NonZero<usize>>, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, handler: ShareableMessageHandler, ) -> Result<UUID4, Error>

Helper method for requesting book snapshot.

§Errors

Returns an error if input parameters are invalid.

Source

pub fn request_quotes( &self, instrument_id: InstrumentId, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<NonZero<usize>>, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, handler: ShareableMessageHandler, ) -> Result<UUID4, Error>

Helper method for requesting quotes.

§Errors

Returns an error if input parameters are invalid.

Source

pub fn request_trades( &self, instrument_id: InstrumentId, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<NonZero<usize>>, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, handler: ShareableMessageHandler, ) -> Result<UUID4, Error>

Helper method for requesting trades.

§Errors

Returns an error if input parameters are invalid.

Source

pub fn request_bars( &self, bar_type: BarType, start: Option<DateTime<Utc>>, end: Option<DateTime<Utc>>, limit: Option<NonZero<usize>>, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, handler: ShareableMessageHandler, ) -> Result<UUID4, Error>

Helper method for requesting bars.

§Errors

Returns an error if input parameters are invalid.

Source

pub fn subscribe_blocks( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, chain: Blockchain, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering block subscriptions from the trait.

Source

pub fn subscribe_pool( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering pool subscriptions from the trait.

Source

pub fn subscribe_pool_swaps( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering pool swap subscriptions from the trait.

Source

pub fn subscribe_pool_liquidity_updates( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering pool liquidity update subscriptions from the trait.

Source

pub fn subscribe_pool_fee_collects( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering pool fee collect subscriptions from the trait.

Source

pub fn subscribe_pool_flash_events( &mut self, topic: MStr<Topic>, handler: ShareableMessageHandler, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for registering pool flash event subscriptions from the trait.

Source

pub fn unsubscribe_blocks( &mut self, chain: Blockchain, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from blocks.

Source

pub fn unsubscribe_pool( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from pool definition updates.

Source

pub fn unsubscribe_pool_swaps( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from pool swaps.

Source

pub fn unsubscribe_pool_liquidity_updates( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from pool liquidity updates.

Source

pub fn unsubscribe_pool_fee_collects( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from pool fee collects.

Source

pub fn unsubscribe_pool_flash_events( &mut self, instrument_id: InstrumentId, client_id: Option<ClientId>, params: Option<IndexMap<String, String>>, )

Helper method for unsubscribing from pool flash events.

Trait Implementations§

Source§

impl Debug for StrategyCore

Source§

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

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

impl Deref for StrategyCore

Source§

type Target = DataActorCore

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl DerefMut for StrategyCore

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

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
§

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

§

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

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

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

§

fn vzip(self) -> V

§

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