Struct Trader

Source
pub struct Trader {
    pub trader_id: TraderId,
    pub instance_id: UUID4,
    pub environment: Environment,
    /* private fields */
}
Expand description

Central orchestrator for managing trading components.

The Trader manages the lifecycle and coordination of actors, strategies, and execution algorithms within the trading system. It provides component registration, state management, and integration with system engines.

Fields§

§trader_id: TraderId

The unique trader identifier.

§instance_id: UUID4

The unique instance identifier.

§environment: Environment

The trading environment context.

Implementations§

Source§

impl Trader

Source

pub fn new( trader_id: TraderId, instance_id: UUID4, environment: Environment, clock: Rc<RefCell<dyn Clock>>, ) -> Self

Creates a new Trader instance.

Source

pub const fn trader_id(&self) -> TraderId

Returns the trader ID.

Source

pub const fn instance_id(&self) -> UUID4

Returns the instance ID.

Source

pub const fn environment(&self) -> Environment

Returns the trading environment.

Source

pub const fn state(&self) -> ComponentState

Returns the current component state.

Source

pub const fn ts_created(&self) -> UnixNanos

Returns the timestamp when the trader was created (UNIX nanoseconds).

Source

pub const fn ts_started(&self) -> Option<UnixNanos>

Returns the timestamp when the trader was last started (UNIX nanoseconds).

Source

pub const fn ts_stopped(&self) -> Option<UnixNanos>

Returns the timestamp when the trader was last stopped (UNIX nanoseconds).

Source

pub const fn is_running(&self) -> bool

Returns whether the trader is running.

Source

pub const fn is_stopped(&self) -> bool

Returns whether the trader is stopped.

Source

pub const fn is_disposed(&self) -> bool

Returns whether the trader is disposed.

Source

pub fn actor_count(&self) -> usize

Returns the number of registered actors.

Source

pub fn strategy_count(&self) -> usize

Returns the number of registered strategies.

Source

pub fn exec_algorithm_count(&self) -> usize

Returns the number of registered execution algorithms.

Source

pub fn component_count(&self) -> usize

Returns the total number of registered components.

Source

pub fn actor_ids(&self) -> Vec<ComponentId>

Returns a list of all registered actor IDs.

Source

pub fn strategy_ids(&self) -> Vec<StrategyId>

Returns a list of all registered strategy IDs.

Source

pub fn exec_algorithm_ids(&self) -> Vec<ExecAlgorithmId>

Returns a list of all registered execution algorithm IDs.

Source

pub fn add_actor(&mut self, actor: Box<dyn Component>) -> Result<()>

Adds an actor to the trader.

§Errors

Returns an error if:

  • The trader is not in a valid state for adding components
  • An actor with the same ID is already registered
Source

pub fn add_strategy(&mut self, strategy: Box<dyn Component>) -> Result<()>

Adds a strategy to the trader.

§Errors

Returns an error if:

  • The trader is not in a valid state for adding components
  • A strategy with the same ID is already registered
Source

pub fn add_exec_algorithm( &mut self, exec_algorithm: Box<dyn Component>, ) -> Result<()>

Adds an execution algorithm to the trader.

§Errors

Returns an error if:

  • The trader is not in a valid state for adding components
  • An execution algorithm with the same ID is already registered
Source

pub fn start_components(&mut self) -> Result<()>

Starts all registered components.

§Errors

Returns an error if any component fails to start.

Source

pub fn stop_components(&mut self) -> Result<()>

Stops all registered components.

§Errors

Returns an error if any component fails to stop.

Source

pub fn reset_components(&mut self) -> Result<()>

Resets all registered components.

§Errors

Returns an error if any component fails to reset.

Source

pub fn dispose_components(&mut self) -> Result<()>

Disposes of all registered components.

§Errors

Returns an error if any component fails to dispose.

Source

pub fn initialize(&mut self) -> Result<()>

Initializes the trader, transitioning from PreInitialized to Ready state.

This method must be called before starting the trader.

§Errors

Returns an error if the trader cannot be initialized from its current state.

Trait Implementations§

Source§

impl Component for Trader

Source§

fn id(&self) -> ComponentId

Returns the unique identifier for this component.
Source§

fn state(&self) -> ComponentState

Returns the current state of the component.
Source§

fn trigger(&self) -> ComponentTrigger

Returns the component trigger.
Source§

fn is_running(&self) -> bool

Returns whether the component is currently running.
Source§

fn is_stopped(&self) -> bool

Returns whether the component is stopped.
Source§

fn is_disposed(&self) -> bool

Returns whether the component has been disposed.
Source§

fn start(&mut self) -> Result<()>

Starts the component. Read more
Source§

fn stop(&mut self) -> Result<()>

Stops the component. Read more
Source§

fn reset(&mut self) -> Result<()>

Resets the component to its initial state. Read more
Source§

fn dispose(&mut self) -> Result<()>

Disposes of the component, releasing any resources. Read more
Source§

fn handle_event(&mut self, _event: TimeEvent)

Handles a timer event (TBD).
Source§

impl Debug for Trader

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Trader

§

impl !RefUnwindSafe for Trader

§

impl !Send for Trader

§

impl !Sync for Trader

§

impl Unpin for Trader

§

impl !UnwindSafe for Trader

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

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