1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* Copyright 2023 Architect Financial Technologies LLC. This is free
 * software released under the GNU Affero Public License version 3. */

//! This is the protocol for sending symbology over the wire between
//! the symbology server and clients, and from the loaders to the
//! symbology server.

use crate::Str;
use anyhow::Result;
use bytes::Bytes;
use derive::FromValue;
use netidx_derive::Pack;
use serde_derive::{Deserialize, Serialize};
use std::{fmt::Display, str::FromStr};

pub mod cficode;
pub mod cpty;
pub mod market;
pub mod product;
pub mod query;
pub mod route;
pub mod venue;

pub use cpty::CptyId;
pub use market::{
    ExchangeMarketKind, Market, MarketId, MarketInfo, MarketKind, PoolMarketKind,
};
pub use product::{Product, ProductId, ProductKind};
pub use route::{Route, RouteId};
pub use venue::{Venue, VenueId};

/// All named symbology identifiers implement the trait Symbolic, which specifies
/// some common minimum functionality.
pub trait Symbolic: Clone + 'static {
    type Id: Copy + Ord + Eq + FromStr + From<Str> + Display;

    fn type_name() -> &'static str;
    fn id(&self) -> Self::Id;
    fn name(&self) -> Str;
    fn validate(&self) -> Result<()> {
        Ok(())
    }
}

/// Symbology server/client wire type
#[derive(Debug, Clone, Serialize, Deserialize, Pack, FromValue)]
pub struct SymbologyUpdate {
    pub sequence_number: u64,
    pub kind: SymbologyUpdateKind,
}

#[derive(Debug, Clone, Serialize, Deserialize, Pack, FromValue)]
pub enum SymbologyUpdateKind {
    AddRoute(Route),
    RemoveRoute(RouteId),
    AddVenue(Venue),
    RemoveVenue(VenueId),
    AddProduct(Product),
    RemoveProduct(ProductId),
    AddMarket(Market),
    RemoveMarket(MarketId),
    /// compressed is a zstd compressed packed Pooled<Vec<SymbologyUpdateKind>>
    Snapshot {
        original_length: usize,
        compressed: Bytes,
    },
    /// elided version of [Snapshot] for no-op squashes--never stored in history,
    /// only used for synced clients
    SnapshotUnchanged(Bytes),
    #[pack(other)]
    Unknown,
}