apple-quant-algorithmic 0.3.0

Apple Quant's algorithmic library.
mod index;

use std::ops::Deref;

use crate::timestamp::{Timestamp, Timestamped, TradeTimestamp};

pub use index::*;

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct RuntimeBinTimestamp {
	pub timestamp: Timestamp,
	pub ns_len: u64,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub struct BinTimestamp<const NS_LEN: u64>(BinIndex<NS_LEN>);

impl<const NS_LEN: u64> From<TradeTimestamp> for BinTimestamp<NS_LEN> {
	fn from(
		value: TradeTimestamp,
	) -> Self {
		let bin_index = BinIndex::from_timestamped(value);
		Self(bin_index)
	}
}

impl<const NS_LEN: u64> Deref for BinTimestamp<NS_LEN> {
	type Target = BinIndex<NS_LEN>;

	fn deref(
		&self,
	) -> &Self::Target {
		&self.0
	}
}

impl<const NS_LEN: u64> Timestamped for BinTimestamp<NS_LEN> {
	fn timestamp(
		&self,
	) -> Timestamp {
		self.0.timestamp()
	}
}