Skip to main content

Crate simulator_client

Crate simulator_client 

Source
Expand description

Ergonomic async client for the simulator backtest WebSocket API.

This wraps the simulator-api request/response protocol with helpers for common workflows (create session, wait ready, continue/advance, close), while still allowing full access to raw BacktestRequest / BacktestResponse when needed.

§Quickstart

use std::time::Duration;

use simulator_client::{BacktestClient, Continue, CreateSession};

let client = BacktestClient::builder()
    .url("ws://localhost:8900/backtest")
    .api_key("local-dev-key")
    .build();

let mut session = client
    .create_session(
        CreateSession::builder()
            .start_slot(100)
            .slot_count(10)
            .build(),
    )
    .await?;

session.ensure_ready(Some(Duration::from_secs(30))).await?;
session
    .continue_until_ready(
        Continue::builder().advance_count(1).build(),
        None,
        |_| {},
    )
    .await?;
session.close(Some(Duration::from_secs(10))).await?;

§Lifecycle notes

  • BacktestClient::create_session sends CreateBacktestSession and waits for SessionCreated, buffering other responses until the session is ready.
  • BacktestSession::close sends CloseBacktestSession and then closes the WebSocket.
  • Dropping BacktestSession sends a best-effort WebSocket close frame if a Tokio runtime is available. Call close explicitly to ensure server-side session cleanup.
  • connect_timeout governs the initial handshake; request_timeout applies to send/receive operations and can be overridden per call.
  • For streaming workflows, use BacktestSession::responses (consumes the session) or next_event to keep readiness state in sync while consuming responses.

Re-exports§

pub use injection::ProgramModError;
pub use injection::build_program_injection;
pub use subscriptions::LogSubscriptionHandle;
pub use subscriptions::SubscriptionError;
pub use subscriptions::subscribe_program_logs;
pub use urls::UrlError;
pub use urls::http_to_ws_url;

Modules§

injection
subscriptions
urls

Structs§

AdvanceState
Mutable state for driving a session with advance_step.
AvailableRange
One contiguous block range available on the history clerk.
BacktestClient
Backtest WebSocket client configured with a base URL and API key.
BacktestSession
Active backtest session over a WebSocket connection.
Continue
Builder for Continue requests.
ContinueResult
Summary of responses collected while advancing a backtest.
CreateSession
Builder for CreateBacktestSession.
SessionCoverage
Coverage of a session’s observed slot notifications and completion state.

Enums§

BacktestClientError
CoverageError
Coverage validation failures for a backtest session.
ReadyOutcome
Outcome of waiting for readiness on a backtest session.
SerializeEncodeError
Error serializing a transaction for injection.

Functions§

split_range
Split a user-requested [start_slot, end_slot] range across the available bundle ranges, returning a list of non-overlapping (start, end) pairs — one per bundle that intersects the requested range.

Type Aliases§

BacktestClientResult