simulator-client 0.18.0

Async WebSocket client for the Solana simulator backtest API
Documentation
# simulator-client

Async WebSocket client for the Termina Solana simulator backtest API.

```toml
[dependencies]
simulator-client = "0.16"
```

## Quickstart

Use `ManagedBacktestSession`. It owns the control and subscription WebSockets,
keepalives, and reconnect-and-reattach, and surfaces a single event stream.

```rust
use simulator_client::{Continue, CreateSession, ManagedBacktestSession, managed::ManagedEvent};

async fn run() -> Result<(), Box<dyn std::error::Error>> {
    let create = CreateSession::builder()
        .start_slot(100)
        .slot_count(10)
        .build()
        .into_request()?;

    let mut session = ManagedBacktestSession::start(
        "wss://simulator.termina.technology/backtest".to_string(),
        "my-api-key".to_string(),
        create,
    )
    .await?;

    loop {
        match session.next_event().await? {
            ManagedEvent::ReadyForContinue => {
                let advance = Continue::builder().advance_count(1).build().into_params();
                session.send_continue(advance).await?;
            }
            ManagedEvent::Completed { .. } => break,
            _ => {}
        }
    }

    session.shutdown().await;
    Ok(())
}
```

For a run split across several sessions, `managed::ManagedParallelSession`
multiplexes the batch over one control connection.

## Reconnects are not optional

A backtest session runs on its own host and outlives the WebSocket you talk to
it through — but only if something comes back for it.

The management service in front of your session is redeployed routinely. When
it shuts down it pauses each live session, records it as handed off, and closes
the control WebSocket with code `1012` (`management handoff`). The session then
waits to be claimed:

- Reconnect and send `AttachBacktestSession` (with the last sequence number you
  received) followed by `ResumeAttachedSession`, and the session resumes with
  everything you missed replayed.
- Do nothing, and the server reclaims it once `disconnect_timeout_secs` elapses.
  The run is gone.

Not every disconnect is graceful — a load balancer draining a target can reset
the socket with no close frame at all. Treat **any** transport error as
"reconnect and reattach", never as a failed run.

`ManagedBacktestSession` implements all of this. Its control task reconnects
with backoff and re-handshakes with attach + resume, and it defaults
`disconnect_timeout_secs` to a window wider than its own reconnect budget so the
server does not reclaim a session while the client is still retrying. If you
drive the protocol yourself, budget for the same.

## Low-level API

`BacktestClient` / `BacktestSession` are a single raw WebSocket with **no
reconnect and no reattach**: the connection dropping ends the run. Use them only
when you need direct `BacktestRequest` / `BacktestResponse` access, and then
implement the reattach loop above yourself via `BacktestClient::attach_session`
and `BacktestSession::resume_attached_session`.

## Docs

Full API documentation: <https://docs.rs/simulator-client>.