Skip to main content

apple_quant_algorithmic/aggregation/
ohlc.rs

1use rust_decimal::Decimal;
2
3use crate::{
4	timestamp::{TradeTimestampRangeIncluded, TradeTimestampRangeInclusive},
5	instrument::InstrumentSpec, price::AbsolutePrice,
6};
7
8/// Genericless version of [`OHLC`].
9#[derive(Debug)]
10pub struct RuntimeOHLC {
11	pub open: Decimal,
12	pub high: Decimal,
13	pub low: Decimal,
14	pub close: Decimal,
15}
16
17/// Represents first, last, and extremes of a range of prices.
18#[derive(Debug)]
19pub struct OHLC<
20	const NS_LEN: u64,
21	IS: InstrumentSpec,
22> {
23	pub open: AbsolutePrice<IS>,
24	pub high: AbsolutePrice<IS>,
25	pub low: AbsolutePrice<IS>,
26	pub close: AbsolutePrice<IS>,
27}
28
29impl<
30	const NS_LEN: u64,
31	IS: InstrumentSpec,
32> OHLC<NS_LEN, IS> {
33	pub fn as_runtime(
34		&self,
35	) -> RuntimeOHLC {
36		RuntimeOHLC {
37			open: self.open.as_decimal(),
38			high: self.high.as_decimal(),
39			low: self.low.as_decimal(),
40			close: self.close.as_decimal(),
41		}
42	}
43}
44
45/// Collection of both price and timestamp information.
46#[derive(Debug)]
47pub struct OHLCTradeTimestampRange<
48	const NS_LEN: u64,
49	IS: InstrumentSpec,
50> {
51	pub ohlc: OHLC<NS_LEN, IS>,
52	pub trade_timestamp_range: TradeTimestampRangeInclusive,
53}
54
55impl<
56	const NS_LEN: u64,
57	IS: InstrumentSpec,
58> TradeTimestampRangeIncluded for OHLCTradeTimestampRange<NS_LEN, IS> {
59	fn trade_timestamp_range_inclusive(
60		&self,
61	) -> TradeTimestampRangeInclusive {
62		self.trade_timestamp_range
63	}
64}