apple_quant_algorithmic/timestamp/
bin.rs1use bevy::prelude::Deref;
2
3use crate::timestamp::{Timestamp, Timestamped, TradeTimestamp};
4
5#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
6pub struct RuntimeBinTimestamp {
7 pub timestamp: Timestamp,
8 pub ns_len: u64,
9}
10
11#[derive(Debug, Deref, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
12pub struct BinTimestamp<const NS_LEN: u64>(Timestamp);
13
14impl<const NS_LEN: u64> BinTimestamp<NS_LEN> {
15 pub fn new(trade_timestamp: &TradeTimestamp) -> Self {
16 Self(Timestamp::new(
17 trade_timestamp.as_utc_nanos() / (NS_LEN as i128),
18 ))
19 }
20
21 pub fn bin_index(&self) -> u64 {
22 (self.0.as_utc_nanos() / NS_LEN as i128) as u64
23 }
24}
25
26impl<const NS_LEN: u64> Timestamped for BinTimestamp<NS_LEN> {
27 fn timestamp(&self) -> &Timestamp {
28 &self.0
29 }
30}