Skip to main content

TradingEnvironment

Struct TradingEnvironment 

Source
pub struct TradingEnvironment<'runtime> { /* private fields */ }
Expand description

Device-resident trading dynamics over one Runtime and the canonical lifecycle. Observations append signed exposure, equity/capital, peak/capital, drawdown, remaining horizon, unrealized PnL/capital, position age/horizon and peak unrealized position PnL/capital.

Implementations§

Source§

impl TradingEnvironment<'_>

Source

pub fn snapshot(&self) -> Result<TradingState>

Explicitly synchronize and read a portable exact environment snapshot.

§Errors

Requires healthy initialized state and no open environment transaction.

Source

pub fn restore(&mut self, state: &TradingState) -> Result<()>

Restore into unchanged source/config and stable captured buffers.

§Errors

Rejects incompatible or unhealthy state before mutating any buffer.

Source§

impl<'runtime> TradingEnvironment<'runtime>

Source

pub fn set_taker_fee(&mut self, taker_fee: f32) -> Result<()>

Change the actual-notional fee between episodes without resetting lane state. Existing captured programs retain their recorded fee; discard and recapture the TradingRolloutProgram before collecting with the new configuration. Snapshots remain bound to the fee in effect when they were taken.

§Errors

Rejects invalid fees, active execution, unhealthy state, or any initialized lane which has advanced beyond reset or retains inventory/pending execution.

Source

pub fn new( runtime: &'runtime Runtime, config: TradingConfig, series: &[TradingSeries], ) -> Result<Self>

Validate/upload immutable data and allocate analytical lane state. Call reset, then submit/wait explicitly before observing it.

§Errors

Rejects discontinuous or invalid data, insufficient episode coverage, overflowing extents, unsupported policy, allocation or recording failure.

Source

pub fn new_with_row_capacity( runtime: &'runtime Runtime, config: TradingConfig, series: &[TradingSeries], capacity: usize, ) -> Result<Self>

Allocate stable table capacity for replay across changing contiguous segments. Padding is unreachable: bounds always describe only supplied source rows.

§Errors

Returns the validation errors of new or an excessive capacity error.

Source

pub fn replace_series(&mut self, series: &[TradingSeries]) -> Result<()>

Replace resident source tables without replacing captured storage. Call at a completed rollout boundary; lane state must be reset afterwards.

§Errors

Rejects invalid/discontinuous source data, changed feature width/capacity, active environment execution, or upload/completion failure.

Source

pub fn step_terminal( &mut self, action: &Matrix, ) -> Result<EnvironmentTransition>

Step and close all lanes at this collection boundary, charging exit costs in this transition. This is a task terminal, never a free reset.

§Errors

Returns the normal Environment step validation/recording failures.

Source

pub const fn ledger(&self) -> &Matrix

Analytical rows: equity, quantity, mark, peak, fees, funding, slippage, fill count, maximum drawdown, entry price, age in source steps and peak unrealized position PnL. Peak is zero while flat or never profitable. These are never exact money values.

Source

pub const fn metadata(&self) -> &Matrix

Cursor, episode steps, episode ordinal, failure status (zero means healthy).

Source

pub fn check_status(&self) -> Result<()>

Explicitly observe status after exact completion and reject any failed lane. No action/price readback occurs during device rollout steps.

§Errors

Returns readback/completion failure or a poisoned numerical/action lane.

Trait Implementations§

Source§

impl Environment for TradingEnvironment<'_>

Source§

fn runtime(&self) -> &Runtime

Return the sole Runtime borrowed by this session.
Source§

fn spec(&self) -> &EnvironmentSpec

Return the structural environment contract.
Source§

fn environments(&self) -> u32

Return the positive vector-environment lane count.
Source§

fn observation(&self) -> &Matrix

Return the current device-resident observation.
Source§

fn execution(&self) -> &EnvironmentExecution

Return the embedded execution lifecycle.
Source§

fn execution_mut(&mut self) -> &mut EnvironmentExecution

Mutably return the embedded execution lifecycle.
Source§

fn record_reset(&mut self, seed: u64) -> Result<()>

Record implementation-specific reset commands.
Source§

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

Record reset of lanes that ended on the previous step.
Source§

fn commit_recorded_state(&mut self)

Commit host metadata after queue submission accepts the transaction.
Source§

fn rollback_recorded_state(&mut self)

Roll back host metadata after an unsubmitted transaction is discarded.
Source§

fn record_step(&mut self, action: &Matrix) -> Result<EnvironmentTransition>

Record one implementation-specific step.
Source§

fn holds_committed_state(&self) -> bool

Whether the environment currently holds committed episode state. Read more
Source§

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

Begin or retain an idempotent command transaction. Read more
Source§

fn reset(&mut self, seed: u64) -> Result<()>

Record a full environment reset into the active transaction. Read more
Source§

fn step(&mut self, action: &Matrix) -> Result<EnvironmentTransition>

Record one environment step into the active transaction. Read more
Source§

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

Record reset of completed lanes into the active transaction. Read more
Source§

fn submit(&mut self) -> Result<Event>

Submit the exact active command transaction without waiting. Read more
Source§

fn submit_timed(&mut self) -> Result<Event>

Submit the active transaction with device timestamps around its complete command batch. The returned Event exposes the exact device duration; explicit wait still releases this environment’s pending lifecycle state. Read more
Source§

fn wait(&mut self, event: &Event) -> Result<()>

Wait for this environment’s exact pending event. Read more
Source§

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

Discard only the unsubmitted command transaction. Read more
Source§

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

Explicitly complete submitted work, discard unsubmitted work, and close. Read more

Auto Trait Implementations§

§

impl<'runtime> !RefUnwindSafe for TradingEnvironment<'runtime>

§

impl<'runtime> !Send for TradingEnvironment<'runtime>

§

impl<'runtime> !Sync for TradingEnvironment<'runtime>

§

impl<'runtime> !UnwindSafe for TradingEnvironment<'runtime>

§

impl<'runtime> Forget for TradingEnvironment<'runtime>

§

impl<'runtime> Freeze for TradingEnvironment<'runtime>
where &'runtime Runtime: Freeze, *const RcInner<RefCell<RuntimeState>> is !null: Freeze, PhantomData<RcInner<RefCell<RuntimeState>>>: Freeze, *const ArcInner<Device> is !null: Freeze, PhantomData<ArcInner<Device>>: Freeze, *const ArcInner<RetirementCompletion> is !null: Freeze, PhantomData<ArcInner<RetirementCompletion>>: Freeze, *const ArcInner<WorkerControl> is !null: Freeze, PhantomData<ArcInner<WorkerControl>>: Freeze, *const ArcInner<TimestampPairInner> is !null: Freeze, PhantomData<ArcInner<TimestampPairInner>>: Freeze, *const ArcInner<Mutex<Vec<Arc<DecodeStatus>>>> is !null: Freeze, PhantomData<ArcInner<Mutex<Vec<Arc<DecodeStatus>>>>>: Freeze, *const ArcInner<Mutex<Vec<Arc<EncodeReceipt>>>> is !null: Freeze, PhantomData<ArcInner<Mutex<Vec<Arc<EncodeReceipt>>>>>: Freeze, *const u8 is !null: Freeze, PhantomData<u8>: Freeze, PhantomData<usize>: Freeze, *const RcInner<StorageInner> is !null: Freeze, PhantomData<RcInner<StorageInner>>: Freeze, *const RcInner<MatrixSemantic> is !null: Freeze, PhantomData<RcInner<MatrixSemantic>>: Freeze, PhantomData<Rc<()>>: Freeze,

§

impl<'runtime> Move for TradingEnvironment<'runtime>

§

impl<'runtime> Unpin for TradingEnvironment<'runtime>
where &'runtime Runtime: Unpin, Rc<RefCell<RuntimeState>>: Unpin, Arc<Device>: Unpin, Arc<RetirementCompletion>: Unpin, Arc<WorkerControl>: Unpin, Arc<TimestampPairInner>: Unpin, Arc<Mutex<Vec<Arc<DecodeStatus>>>>: Unpin, Arc<Mutex<Vec<Arc<EncodeReceipt>>>>: Unpin, *const u8 is !null: Unpin, Rc<StorageInner>: Unpin, Rc<MatrixSemantic>: Unpin, Rc<()>: Unpin,

§

impl<'runtime> UnsafeUnpin for TradingEnvironment<'runtime>
where &'runtime Runtime: UnsafeUnpin, *const RcInner<RefCell<RuntimeState>> is !null: UnsafeUnpin, PhantomData<RcInner<RefCell<RuntimeState>>>: UnsafeUnpin, *const ArcInner<Device> is !null: UnsafeUnpin, PhantomData<ArcInner<Device>>: UnsafeUnpin, *const ArcInner<RetirementCompletion> is !null: UnsafeUnpin, PhantomData<ArcInner<RetirementCompletion>>: UnsafeUnpin, *const ArcInner<WorkerControl> is !null: UnsafeUnpin, PhantomData<ArcInner<WorkerControl>>: UnsafeUnpin, *const ArcInner<TimestampPairInner> is !null: UnsafeUnpin, PhantomData<ArcInner<TimestampPairInner>>: UnsafeUnpin, *const ArcInner<Mutex<Vec<Arc<DecodeStatus>>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Vec<Arc<DecodeStatus>>>>>: UnsafeUnpin, *const ArcInner<Mutex<Vec<Arc<EncodeReceipt>>>> is !null: UnsafeUnpin, PhantomData<ArcInner<Mutex<Vec<Arc<EncodeReceipt>>>>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, PhantomData<usize>: UnsafeUnpin, *const RcInner<StorageInner> is !null: UnsafeUnpin, PhantomData<RcInner<StorageInner>>: UnsafeUnpin, *const RcInner<MatrixSemantic> is !null: UnsafeUnpin, PhantomData<RcInner<MatrixSemantic>>: UnsafeUnpin, PhantomData<Rc<()>>: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

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<F, T> IntoSample<T> for F
where T: FromSample<F>,

Source§

fn into_sample(self) -> T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.