Skip to main content

Module subscriptions

Module subscriptions 

Source
Expand description

Standalone subscriptions to a session’s RPC endpoint.

Each subscribe_* function opens its own WebSocket to the session’s RPC endpoint (SessionInfo::rpc_endpoint), runs your callback once per notification on a background task, and returns a handle.

  • These functions never reconnect. If the server closes the socket, the handle’s shutdown returns SubscriptionRuntimeError::Closed and the notifications after the close are lost. On a ManagedBacktestSession, prefer its subscribe_* methods, which reconnect and deliver results as ManagedEvents.
  • Subscribe before you continue the session, or you miss the notifications sent before the subscription was confirmed.
  • Always finish with handle.shutdown().await?, before you close the session. Dropping a handle does not stop its task.

Per-account diffs (subscribe_account_diffs, subscribe_account_diffs_many) and program logs (subscribe_program_logs) are only available here.

Structs§

AccountDiffContext
Slot context included in every account diff notification.
AccountDiffNotification
A single account diff notification delivered by accountDiffSubscribe.
AccountDiffSubscriptionHandle
Handle for a running account diff or program diff subscription.
ActionResultContext
Slot context included in every action result.
ActionResultNotification
One scheduled-action result delivered by actionSubscribe.
ActionSubscriptionHandle
Handle for a running subscribe_actions subscription.
ActionTransactionOutcome
One transaction’s result within a scheduled action’s sequence.
DiagnosticContext
Slot context included in every diagnostic sample.
DiagnosticNotification
One market’s /diagnostic sample at one size, delivered by diagnosticSubscribe: the router’s own pricing, not a fill the venue produced.
DiagnosticSubscriptionHandle
Handle for a running subscribe_diagnostics subscription.
L1Score
What the original swap filled, and how the stand-in scored against it. Flattened into the notification’s top level. l1 in a name means the original (onchain) swap.
LogSubscriptionHandle
Handle for a running subscribe_program_logs subscription.
OriginalNotification
The original swap replayed as the baseline (kind: "original"): the historical transaction re-run against the state it was quoted at, so the other kinds can be scored against a number produced the same way rather than against the chain’s.
ProbedHop
The hop a venue probe re-priced, as the original swap ran it onchain and as the replay ran it.
ReplacementContext
The slot the payload was produced at, in the shape every other subscription’s context takes.
ReplacementCore
The identity and outcome every notification carries, whatever its kind. Flattened into the notification’s top level.
RequoteNotification
A transaction rerouted through the router (kind: "requote"): the original swap’s transaction re-quoted and simulated. The original still executed onchain; this result is never committed.
RerouteLegNotification
One swap of a transaction rerouted through the router.
RoutedAccountDiffNotification
An account diff from subscribe_account_diffs_many, tagged with the subscribed account that produced it.
SubscriptionHandle
Handle for a running subscription; every typed handle converts into it with From.
VenueNotification
A venue probe (kind: "directFill"): one hop rerouted directly to a venue through your template, simulated against the state it would have traded on.

Enums§

ReplacementNotification
One reroute result for an original swap, streamed over replacementSubscribe: through the router, directly to a venue, or the original swap replayed as the baseline. Nothing stands in for the original. Tagged by kind, with the variant’s fields at the top level beside it.
SubscriptionError
Error starting a subscription. Returned by the subscribe_* functions before any notification is delivered; no background task is left running.
SubscriptionRuntimeError
Error from a running subscription, returned by the handle’s shutdown.
UiAccountConversionError
Error decoding a serialized UiAccount into the wire AccountData shape.

Functions§

account_data_from_ui
Decode a serde-serialized UiAccount (the pre/post payload shape) into the wire AccountData shape. Only base64 data is supported; space falls back to the decoded data length when absent.
subscribe_account_diffs
Subscribe to the changes of one account.
subscribe_account_diffs_many
Subscribe to the changes of many accounts over one WebSocket.
subscribe_actions
Subscribe to the results of the session’s scheduled actions.
subscribe_diagnostics
Subscribe to the session’s /diagnostic samples.
subscribe_program_diffs
Subscribe to the changes of every account a program owns.
subscribe_program_logs
Subscribe to the logs of every transaction that mentions program_id.
subscribe_replacements
Subscribe to the session’s reroute results.