use std::time::Duration;
use crate::rest_cache::RestCache;
use digdigdig3::core::types::{AccountType, ExchangeId, Ticker};
pub type TickerKey = (ExchangeId, AccountType, String);
pub fn ticker_cache(ttl: Duration) -> RestCache<TickerKey, Ticker> {
RestCache::new(ttl)
}
#[derive(Debug, Clone)]
pub struct CacheConfig {
pub enabled: bool,
pub ticker_ttl: Duration,
}
impl Default for CacheConfig {
fn default() -> Self {
Self { enabled: false, ticker_ttl: Duration::from_secs(1) }
}
}
impl CacheConfig {
pub fn on() -> Self {
Self { enabled: true, ticker_ttl: Duration::from_secs(1) }
}
pub fn ticker_ttl(mut self, ttl: Duration) -> Self {
self.ticker_ttl = ttl;
self
}
}