use chrono::{DateTime, SecondsFormat};
use rust_decimal::Decimal;
use std::time::{SystemTime, UNIX_EPOCH};
pub fn current_timestamp_ms() -> u64 {
SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_millis() as u64)
.unwrap_or(0)
}
pub fn format_ts(ts: u64) -> String {
let timestamp_nanos: i64 = ts as i64;
let dt = DateTime::from_timestamp_nanos(timestamp_nanos);
dt.to_rfc3339_opts(SecondsFormat::Nanos, true)
}
pub fn decimal_to_f64(d: Decimal) -> f64 {
use std::str::FromStr;
f64::from_str(&d.to_string()).unwrap_or(0.0)
}
#[inline]
pub fn normalize_side(raw: &str) -> String {
match raw {
"Buy" | "BUY" | "buy" | "bid" => "buy".to_string(),
"Sell" | "SELL" | "sell" | "offer" => "sell".to_string(),
other => other.to_lowercase(),
}
}
#[inline]
pub fn normalize_symbol(raw: &str) -> String {
raw.replace(['-', '/', '_'], "").to_lowercase()
}