Skip to main content

subscribe_replacements

Function subscribe_replacements 

Source
pub async fn subscribe_replacements<F, Fut>(
    rpc_endpoint: &str,
    on_notification: F,
) -> Result<SubscriptionHandle, SubscriptionError>
where F: Fn(ReplacementNotification) -> Fut + Send + Sync + 'static, Fut: Future<Output = ()> + Send + 'static,
Expand description

Subscribe to the session’s reroute results.

Each result (a requote simulation, a reroute directly to a venue, or the original swap) arrives as a ReplacementNotification; branch on its variant, or hand the stream to crate::reroute_report::from_stream / crate::reroute_report::probes_from_stream. Every result shares this one stream: tell them apart by slot, batch_index and original_signature. Callbacks run one at a time, in order. Never reconnects: a dropped WebSocket ends the stream with SubscriptionRuntimeError::Closed.

§Errors

SubscriptionError if the subscription cannot be started.

§Example

use simulator_client::{ManagedBacktestSession, ReplacementNotification, subscribe_replacements};

let handle = subscribe_replacements(
    &session.session_info().rpc_endpoint,
    |result| async move {
        match result {
            ReplacementNotification::Requote(requote) => {
                println!("slot={} sig={}", requote.core.slot, requote.core.original_signature);
            }
            ReplacementNotification::Venue(probe) => {
                println!("template={} sig={}", probe.template, probe.core.original_signature);
            }
            ReplacementNotification::Original(original) => {
                println!("baseline sig={}", original.core.original_signature);
            }
        }
    },
)
.await?;

handle.shutdown().await?;