Skip to main content

hypercall_types/
observability.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4/// Bounded set of authentication failure reasons used for low-cardinality
5/// API authentication metrics.
6#[derive(Debug, Clone, Copy)]
7pub enum AuthFailureReason {
8    SignatureRecovery,
9    PlaceOrderSignature,
10    CancelOrderSignature,
11    CancelOrderCloidSignature,
12    MarginModeSignature,
13    SettlementPayoutSeenSignature,
14}
15
16impl AuthFailureReason {
17    pub fn as_str(&self) -> &'static str {
18        match self {
19            Self::SignatureRecovery => "signature_recovery",
20            Self::PlaceOrderSignature => "place_order_signature",
21            Self::CancelOrderSignature => "cancel_order_signature",
22            Self::CancelOrderCloidSignature => "cancel_order_cloid_signature",
23            Self::MarginModeSignature => "margin_mode_signature",
24            Self::SettlementPayoutSeenSignature => "settlement_payout_seen_signature",
25        }
26    }
27}
28
29/// Deterministic digest of engine state for comparison.
30///
31/// Uses Decimal strings to ensure deterministic formatting.
32#[derive(Debug, Clone, Serialize, Deserialize, Default)]
33pub struct EngineStateDigest {
34    /// Next order ID that will be assigned.
35    pub next_order_id: u64,
36    /// Next trade ID that will be assigned.
37    pub next_trade_id: u64,
38    /// L2 sequence counter.
39    pub l2_seq: i64,
40    /// Per-symbol summaries.
41    pub symbols: HashMap<String, SymbolSummary>,
42}
43
44impl EngineStateDigest {
45    /// Check if two digests are equal for determinism testing.
46    pub fn is_equal_to(&self, other: &EngineStateDigest) -> bool {
47        self.next_order_id == other.next_order_id
48            && self.next_trade_id == other.next_trade_id
49            && self.l2_seq == other.l2_seq
50            && self.symbols == other.symbols
51    }
52}
53
54/// Summary of a single symbol's orderbook state.
55#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq)]
56pub struct SymbolSummary {
57    /// Best bid price as string to avoid float formatting issues.
58    pub best_bid: Option<String>,
59    /// Best ask price as string.
60    pub best_ask: Option<String>,
61    /// Total number of orders in the book.
62    pub total_orders: usize,
63}