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
impl Trader
Sourcepub fn new(
trader_id: TraderId,
instance_id: UUID4,
environment: Environment,
clock: Rc<RefCell<dyn Clock>>,
cache: Rc<RefCell<Cache>>,
) -> Self
pub fn new( trader_id: TraderId, instance_id: UUID4, environment: Environment, clock: Rc<RefCell<dyn Clock>>, cache: Rc<RefCell<Cache>>, ) -> Self
Creates a new Trader
instance.
Sourcepub const fn instance_id(&self) -> UUID4
pub const fn instance_id(&self) -> UUID4
Returns the instance ID.
Sourcepub const fn environment(&self) -> Environment
pub const fn environment(&self) -> Environment
Returns the trading environment.
Sourcepub const fn ts_created(&self) -> UnixNanos
pub const fn ts_created(&self) -> UnixNanos
Returns the timestamp when the trader was created (UNIX nanoseconds).
Sourcepub const fn ts_started(&self) -> Option<UnixNanos>
pub const fn ts_started(&self) -> Option<UnixNanos>
Returns the timestamp when the trader was last started (UNIX nanoseconds).
Sourcepub const fn ts_stopped(&self) -> Option<UnixNanos>
pub const fn ts_stopped(&self) -> Option<UnixNanos>
Returns the timestamp when the trader was last stopped (UNIX nanoseconds).
Sourcepub const fn actor_count(&self) -> usize
pub const fn actor_count(&self) -> usize
Returns the number of registered actors.
Sourcepub fn strategy_count(&self) -> usize
pub fn strategy_count(&self) -> usize
Returns the number of registered strategies.
Sourcepub fn exec_algorithm_count(&self) -> usize
pub fn exec_algorithm_count(&self) -> usize
Returns the number of registered execution algorithms.
Sourcepub fn component_count(&self) -> usize
pub fn component_count(&self) -> usize
Returns the total number of registered components.
Sourcepub fn strategy_ids(&self) -> Vec<StrategyId>
pub fn strategy_ids(&self) -> Vec<StrategyId>
Returns a list of all registered strategy IDs.
Sourcepub fn exec_algorithm_ids(&self) -> Vec<ExecAlgorithmId>
pub fn exec_algorithm_ids(&self) -> Vec<ExecAlgorithmId>
Returns a list of all registered execution algorithm IDs.
Sourcepub fn add_actor<T>(&mut self, actor: T) -> Result<()>where
T: DataActor + Component + Debug + 'static,
pub fn add_actor<T>(&mut self, actor: T) -> Result<()>where
T: DataActor + Component + Debug + 'static,
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.
Sourcepub fn add_strategy(&mut self, strategy: Box<dyn Component>) -> Result<()>
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
Sourcepub fn add_exec_algorithm(
&mut self,
exec_algorithm: Box<dyn Component>,
) -> Result<()>
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
Sourcepub fn start_components(&mut self) -> Result<()>
pub fn start_components(&mut self) -> Result<()>
Sourcepub fn stop_components(&mut self) -> Result<()>
pub fn stop_components(&mut self) -> Result<()>
Sourcepub fn reset_components(&mut self) -> Result<()>
pub fn reset_components(&mut self) -> Result<()>
Sourcepub fn dispose_components(&mut self) -> Result<()>
pub fn dispose_components(&mut self) -> Result<()>
Sourcepub fn initialize(&mut self) -> Result<()>
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
impl Component for Trader
Source§fn component_id(&self) -> ComponentId
fn component_id(&self) -> ComponentId
Source§fn transition_state(&mut self, trigger: ComponentTrigger) -> Result<()>
fn transition_state(&mut self, trigger: ComponentTrigger) -> Result<()>
Source§fn register(
&mut self,
_trader_id: TraderId,
_clock: Rc<RefCell<dyn Clock>>,
_cache: Rc<RefCell<Cache>>,
) -> Result<()>
fn register( &mut self, _trader_id: TraderId, _clock: Rc<RefCell<dyn Clock>>, _cache: Rc<RefCell<Cache>>, ) -> Result<()>
§fn not_running(&self) -> bool
fn not_running(&self) -> bool
§fn is_running(&self) -> bool
fn is_running(&self) -> bool
§fn is_stopped(&self) -> bool
fn is_stopped(&self) -> bool
§fn is_degraded(&self) -> bool
fn is_degraded(&self) -> bool
§fn is_faulted(&self) -> bool
fn is_faulted(&self) -> bool
§fn is_disposed(&self) -> bool
fn is_disposed(&self) -> bool
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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