atelier_data 0.0.15

Data Artifacts and I/O for the atelier-rs engine
use std::fmt;
use std::str::FromStr;

use serde::{Deserialize, Serialize};

/// Supported exchange identifiers.
///
/// Used for dispatch in workers, config validation, and output path
/// partitioning.  The string representation is always lowercase
/// (e.g. `"bybit"`, `"coinbase"`).
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum Exchange {
    Bybit,
    Coinbase,
    Kraken,
    Binance,
}

impl fmt::Display for Exchange {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Exchange::Bybit => write!(f, "bybit"),
            Exchange::Coinbase => write!(f, "coinbase"),
            Exchange::Kraken => write!(f, "kraken"),
            Exchange::Binance => write!(f, "binance"),
        }
    }
}

impl FromStr for Exchange {
    type Err = String;

    fn from_str(s: &str) -> Result<Self, Self::Err> {
        match s.to_lowercase().as_str() {
            "bybit" => Ok(Exchange::Bybit),
            "coinbase" => Ok(Exchange::Coinbase),
            "kraken" => Ok(Exchange::Kraken),
            "binance" => Ok(Exchange::Binance),
            other => Err(format!("unsupported exchange: {}", other)),
        }
    }
}