apple-quant-algorithmic 0.1.0

Apple Quant's algorithmic trading api
Documentation
use bevy::prelude::Deref;

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

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

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

impl<const NS_LEN: u64> BinTimestamp<NS_LEN> {
	pub fn new(trade_timestamp: &TradeTimestamp) -> Self {
		Self(Timestamp::new(
			trade_timestamp.as_utc_nanos() / (NS_LEN as i128),
		))
	}

	pub fn bin_index(&self) -> u64 {
		(self.0.as_utc_nanos() / NS_LEN as i128) as u64
	}
}

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