pub struct BacktestSession { /* private fields */ }Expand description
Active backtest session over a WebSocket connection.
Dropping the session sends a best-effort close frame if a Tokio runtime is
available. Call BacktestSession::close to request server-side cleanup.
Implementations§
Source§impl BacktestSession
impl BacktestSession
Sourcepub fn session_id(&self) -> Option<&str>
pub fn session_id(&self) -> Option<&str>
Return the server-assigned session id, if known.
Sourcepub fn rpc_endpoint(&self) -> Option<&str>
pub fn rpc_endpoint(&self) -> Option<&str>
Return the session-scoped RPC endpoint if provided.
Sourcepub fn rpc(&self) -> &RpcClient
pub fn rpc(&self) -> &RpcClient
Return the RPC client for this session’s endpoint.
Always available after BacktestClient::create_session completes.
Sourcepub fn is_ready_for_continue(&self) -> bool
pub fn is_ready_for_continue(&self) -> bool
Return whether the session is currently ready to accept Continue.
Sourcepub fn apply_response(&mut self, response: &BacktestResponse)
pub fn apply_response(&mut self, response: &BacktestResponse)
Update internal readiness state based on a response.
Sourcepub async fn send(
&mut self,
request: &BacktestRequest,
timeout: Option<Duration>,
) -> BacktestClientResult<()>
pub async fn send( &mut self, request: &BacktestRequest, timeout: Option<Duration>, ) -> BacktestClientResult<()>
Send a raw backtest request over the WebSocket.
Sourcepub async fn next_response(
&mut self,
timeout: Option<Duration>,
) -> BacktestClientResult<Option<BacktestResponse>>
pub async fn next_response( &mut self, timeout: Option<Duration>, ) -> BacktestClientResult<Option<BacktestResponse>>
Receive the next response, using the backlog first.
Sourcepub async fn next_event(
&mut self,
timeout: Option<Duration>,
) -> BacktestClientResult<Option<BacktestResponse>>
pub async fn next_event( &mut self, timeout: Option<Duration>, ) -> BacktestClientResult<Option<BacktestResponse>>
Receive the next response and update readiness state.
Sourcepub fn responses(
self,
timeout: Option<Duration>,
) -> impl Stream<Item = BacktestClientResult<BacktestResponse>>
pub fn responses( self, timeout: Option<Duration>, ) -> impl Stream<Item = BacktestClientResult<BacktestResponse>>
Stream responses, updating readiness state as items arrive.
This consumes the session and yields responses until the connection ends.
Sourcepub async fn ensure_ready(
&mut self,
timeout: Option<Duration>,
) -> BacktestClientResult<ReadyOutcome>
pub async fn ensure_ready( &mut self, timeout: Option<Duration>, ) -> BacktestClientResult<ReadyOutcome>
Wait for the session to become ready or completed.
Sourcepub async fn wait_for_status(
&mut self,
desired: BacktestStatus,
timeout: Option<Duration>,
) -> BacktestClientResult<()>
pub async fn wait_for_status( &mut self, desired: BacktestStatus, timeout: Option<Duration>, ) -> BacktestClientResult<()>
Wait for a specific status to be emitted.
Sourcepub async fn send_continue(
&mut self,
params: ContinueParams,
timeout: Option<Duration>,
) -> BacktestClientResult<()>
pub async fn send_continue( &mut self, params: ContinueParams, timeout: Option<Duration>, ) -> BacktestClientResult<()>
Send a Continue request and reset readiness.
Sourcepub async fn advance_step<F>(
&mut self,
state: &mut AdvanceState,
wait_for_slots: bool,
timeout: Option<Duration>,
on_event: &mut F,
) -> BacktestClientResult<()>where
F: FnMut(&BacktestResponse),
pub async fn advance_step<F>(
&mut self,
state: &mut AdvanceState,
wait_for_slots: bool,
timeout: Option<Duration>,
on_event: &mut F,
) -> BacktestClientResult<()>where
F: FnMut(&BacktestResponse),
Read and apply a single response while advancing.
Sourcepub async fn continue_until_ready<F>(
&mut self,
cont: Continue,
timeout: Option<Duration>,
on_event: F,
) -> BacktestClientResult<ContinueResult>where
F: FnMut(&BacktestResponse),
pub async fn continue_until_ready<F>(
&mut self,
cont: Continue,
timeout: Option<Duration>,
on_event: F,
) -> BacktestClientResult<ContinueResult>where
F: FnMut(&BacktestResponse),
Advance until the session becomes ready for another Continue.
Sourcepub async fn advance<F>(
&mut self,
cont: Continue,
timeout: Option<Duration>,
on_event: F,
) -> BacktestClientResult<ContinueResult>where
F: FnMut(&BacktestResponse),
pub async fn advance<F>(
&mut self,
cont: Continue,
timeout: Option<Duration>,
on_event: F,
) -> BacktestClientResult<ContinueResult>where
F: FnMut(&BacktestResponse),
Advance and wait for both readiness and slot notifications.
Sourcepub async fn modify_program(
&self,
program_id: &str,
elf: &[u8],
) -> Result<BTreeMap<Address, AccountData>, ProgramModError>
pub async fn modify_program( &self, program_id: &str, elf: &[u8], ) -> Result<BTreeMap<Address, AccountData>, ProgramModError>
Build a program-data account modification from raw ELF bytes.
Derives the ProgramData address from program_id, queries the session’s RPC endpoint
for the current slot and rent-exempt minimum, then returns a modification map ready to
pass to Continue::builder().modify_accounts(...).
The deploy slot is set to current_slot - 1 so the program appears deployed before the
next executed slot.
Sourcepub async fn modify_accounts(
&self,
modifications: &AccountModifications,
) -> BacktestClientResult<usize>
pub async fn modify_accounts( &self, modifications: &AccountModifications, ) -> BacktestClientResult<usize>
Modify accounts on the session’s RPC endpoint via the custom modifyAccounts method.
Returns the number of accounts modified on success.
Sourcepub async fn subscribe_program_logs<F, Fut>(
&self,
program_id: &str,
commitment: CommitmentConfig,
on_notification: F,
) -> Result<LogSubscriptionHandle, SubscriptionError>
pub async fn subscribe_program_logs<F, Fut>( &self, program_id: &str, commitment: CommitmentConfig, on_notification: F, ) -> Result<LogSubscriptionHandle, SubscriptionError>
Subscribe to program log notifications using the session’s RPC endpoint.
Equivalent to calling subscribe_program_logs with
the endpoint from rpc_endpoint, which is set after
BacktestClient::create_session completes.
Sourcepub async fn subscribe_account_diffs<F, Fut>(
&self,
account: &str,
on_notification: F,
) -> Result<AccountDiffSubscriptionHandle, SubscriptionError>
pub async fn subscribe_account_diffs<F, Fut>( &self, account: &str, on_notification: F, ) -> Result<AccountDiffSubscriptionHandle, SubscriptionError>
Subscribe to account diff notifications using the session’s RPC endpoint.
Equivalent to calling subscribe_account_diffs with
the endpoint from rpc_endpoint, which is set after
BacktestClient::create_session completes.
Sourcepub async fn close(
&mut self,
timeout: Option<Duration>,
) -> BacktestClientResult<()>
pub async fn close( &mut self, timeout: Option<Duration>, ) -> BacktestClientResult<()>
Request server cleanup and close the underlying WebSocket.
This is idempotent and will return Ok(()) if the connection is already closed.
Sourcepub async fn close_with_frame(
&mut self,
timeout: Option<Duration>,
frame: Option<CloseFrame<'static>>,
) -> BacktestClientResult<()>
pub async fn close_with_frame( &mut self, timeout: Option<Duration>, frame: Option<CloseFrame<'static>>, ) -> BacktestClientResult<()>
Close the session with a specific WebSocket close frame.
Sourcepub async fn close_with_reason(
&mut self,
timeout: Option<Duration>,
code: CloseCode,
reason: impl Into<String>,
) -> BacktestClientResult<()>
pub async fn close_with_reason( &mut self, timeout: Option<Duration>, code: CloseCode, reason: impl Into<String>, ) -> BacktestClientResult<()>
Close the session with a close code and reason.
Trait Implementations§
Source§impl Debug for BacktestSession
impl Debug for BacktestSession
Auto Trait Implementations§
impl !Freeze for BacktestSession
impl !RefUnwindSafe for BacktestSession
impl Send for BacktestSession
impl Sync for BacktestSession
impl Unpin for BacktestSession
impl UnsafeUnpin for BacktestSession
impl !UnwindSafe for BacktestSession
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§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