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>>, cache: Rc<RefCell<Cache>>, ) -> 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 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<ActorId>

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<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.
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 component_id(&self) -> ComponentId

Returns the unique identifier for this component.
Source§

fn state(&self) -> ComponentState

Returns the current state of the component.
Source§

fn transition_state(&mut self, trigger: ComponentTrigger) -> Result<()>

Transition the component with the state trigger. Read more
Source§

fn register( &mut self, _trader_id: TraderId, _clock: Rc<RefCell<dyn Clock>>, _cache: Rc<RefCell<Cache>>, ) -> Result<()>

Registers the component with a system. Read more
Source§

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

Actions to be performed on start. Read more
Source§

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

Actions to be performed on stop. Read more
Source§

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

Actions to be performed on reset. Read more
Source§

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

Actions to be performed on dispose. Read more
§

fn is_ready(&self) -> bool

Returns whether the component is ready.
§

fn not_running(&self) -> bool

Returns whether the component is not running.
§

fn is_running(&self) -> bool

Returns whether the component is running.
§

fn is_stopped(&self) -> bool

Returns whether the component is stopped.
§

fn is_degraded(&self) -> bool

Returns whether the component has been degraded.
§

fn is_faulted(&self) -> bool

Returns whether the component has been faulted.
§

fn is_disposed(&self) -> bool

Returns whether the component has been disposed.
§

fn initialize(&mut self) -> Result<(), Error>

Initializes the component. Read more
§

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

Starts the component. Read more
§

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

Stops the component. Read more
§

fn resume(&mut self) -> Result<(), Error>

Resumes the component. Read more
§

fn degrade(&mut self) -> Result<(), Error>

Degrades the component. Read more
§

fn fault(&mut self) -> Result<(), Error>

Faults the component. Read more
§

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

Resets the component to its initial state. Read more
§

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

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

fn on_resume(&mut self) -> Result<(), Error>

Actions to be performed on resume. Read more
§

fn on_degrade(&mut self) -> Result<(), Error>

Actions to be performed on degrade. Read more
§

fn on_fault(&mut self) -> Result<(), Error>

Actions to be performed on fault. Read more
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> 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<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
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.
§

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
§

impl<T> ErasedDestructor for T
where T: 'static,