simulator-client 0.24.0

Async WebSocket client for the Solana simulator backtest API
Documentation
use simulator_api::DirectFillTemplate;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Recipe {
    pub name: &'static str,
    json: &'static str,
}

impl Recipe {
    pub fn templates(&self) -> Vec<DirectFillTemplate> {
        serde_json::from_str(self.json)
            .unwrap_or_else(|error| panic!("recipe {} ships invalid JSON: {error}", self.name))
    }
}

pub const PROP_AMMS: Recipe = Recipe {
    name: "prop-amms",
    json: include_str!("../recipes/prop_amms.json"),
};

pub const ALL: [Recipe; 1] = [PROP_AMMS];

#[cfg(test)]
mod tests {
    use std::collections::HashSet;

    use super::*;

    #[test]
    fn every_recipe_parses() {
        for recipe in ALL {
            assert!(
                !recipe.templates().is_empty(),
                "{} carries no templates",
                recipe.name
            );
        }
    }

    #[test]
    fn labels_are_unique_across_every_recipe() {
        let mut seen = HashSet::new();
        for recipe in ALL {
            for template in recipe.templates() {
                assert!(
                    seen.insert(template.label.clone()),
                    "{} repeats the label {}",
                    recipe.name,
                    template.label
                );
            }
        }
    }
}