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.
The connection is not managed: it never reconnects, and a close — including
the 1012 the management service sends when it hands a live session off
during a redeploy — leaves the session running server-side until its
disconnect_timeout_secs elapses. Reclaim it by reconnecting with
crate::BacktestClient::attach_session and then
BacktestSession::resume_attached_session, or use
crate::ManagedBacktestSession and get that loop for free.
Implementations§
Source§impl BacktestSession
impl BacktestSession
Sourcepub fn session_id(&self) -> Option<SessionId>
pub fn session_id(&self) -> Option<SessionId>
Return the server-assigned session id, if known.
pub fn session_name(&self) -> Option<&str>
Sourcepub fn rpc_endpoint(&self) -> Option<&str>
pub fn rpc_endpoint(&self) -> Option<&str>
Return the session-scoped RPC endpoint if provided.
Sourcepub fn task_id(&self) -> Option<&str>
pub fn task_id(&self) -> Option<&str>
Return the opaque task_id reported by the server for this session,
if any.
Sourcepub fn last_sequence(&self) -> Option<u64>
pub fn last_sequence(&self) -> Option<u64>
Return the highest sequenced control-websocket response observed so far.
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 resume_attached_session(&mut self) -> BacktestClientResult<()>
pub async fn resume_attached_session(&mut self) -> BacktestClientResult<()>
Sent after reattaching and rebuilding any dependent subscriptions so the manager can resume a session that was paused for handoff.
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.
Sourcepub fn abort(self)
pub fn abort(self)
Drop the connection without sending CloseBacktestSession, so the server
reaps the session via its disconnect timeout (the dropped-connection path)
rather than the prompt teardown close requests.
Consumes the session so Drop can’t run its best-effort close: the taken
stream is dropped here, closing the socket with a bare FIN.
Source§impl BacktestSession
impl BacktestSession
Sourcepub async fn advance_to_discovery(
&mut self,
offset: Option<u32>,
timeout: Option<Duration>,
) -> BacktestClientResult<DiscoveryStepResult>
pub async fn advance_to_discovery( &mut self, offset: Option<u32>, timeout: Option<Duration>, ) -> BacktestClientResult<DiscoveryStepResult>
Wait for the next batch matching a registered discovery filter and pause immediately before it executes.
DiscoveryBatch events are emitted by the server as a background scan
independent of execution — no Continue is needed to trigger them.
This method consumes the next queued DiscoveryBatch, sends ContinueTo
to execute up to (but not including) that batch, then waits for Paused.
While paused, the session’s RPC endpoint reflects state through
batch_index - 1 of the discovered slot — no transaction in the
discovered batch has executed yet.
Trait Implementations§
Source§impl Debug for BacktestSession
impl Debug for BacktestSession
Source§impl Drop for BacktestSession
impl Drop for BacktestSession
Auto Trait Implementations§
impl !Freeze for BacktestSession
impl !RefUnwindSafe for BacktestSession
impl !UnwindSafe for BacktestSession
impl Send for BacktestSession
impl Sync for BacktestSession
impl Unpin for BacktestSession
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.