Skip to main content

apple_quant_algorithmic/aggregation/
ohlc.rs

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