betex 0.9.1

Betfair / Prediction Market Exchange
Documentation
//! Wire format types for streaming events.

use crate::{book::BookEvent, types::MarketId};
use serde::{Deserialize, Serialize};

/// A streamable event with metadata for WebSocket/SSE delivery.
///
/// This is the wire format sent to clients. It includes:
/// - Sequence number for ordering and gap detection
/// - Market ID for client-side filtering
/// - Timestamp for latency measurement
/// - The event payload
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StreamEvent {
    /// Global sequence number from the disruptor.
    pub seq: u64,
    /// Per-market sequence number from the disruptor.
    pub market_seq: u64,
    /// Market ID if the event is market-specific (for filtering).
    pub market_id: Option<MarketId>,
    /// Unix timestamp in milliseconds when the event was created.
    pub timestamp_ms: i64,
    /// The actual event payload.
    pub event: BookEvent,
}

impl StreamEvent {
    /// Create a new stream event from a disruptor envelope.
    pub fn new(
        seq: u64,
        market_seq: u64,
        market_id: Option<MarketId>,
        event: BookEvent,
        timestamp_ms: i64,
    ) -> Self {
        Self {
            seq,
            market_seq,
            market_id,
            timestamp_ms,
            event,
        }
    }
}