apple-quant-algorithmic 0.3.0

Apple Quant's algorithmic library.
use rust_decimal::Decimal;

use crate::{
	timestamp::{TradeTimestampRangeIncluded, TradeTimestampRangeInclusive},
	instrument::InstrumentSpec, price::AbsolutePrice,
};

/// Genericless version of [`OHLC`].
#[derive(Debug)]
pub struct RuntimeOHLC {
	pub open: Decimal,
	pub high: Decimal,
	pub low: Decimal,
	pub close: Decimal,
}

/// Represents first, last, and extremes of a range of prices.
#[derive(Debug)]
pub struct OHLC<
	const NS_LEN: u64,
	IS: InstrumentSpec,
> {
	pub open: AbsolutePrice<IS>,
	pub high: AbsolutePrice<IS>,
	pub low: AbsolutePrice<IS>,
	pub close: AbsolutePrice<IS>,
}

impl<
	const NS_LEN: u64,
	IS: InstrumentSpec,
> OHLC<NS_LEN, IS> {
	pub fn as_runtime(
		&self,
	) -> RuntimeOHLC {
		RuntimeOHLC {
			open: self.open.as_decimal(),
			high: self.high.as_decimal(),
			low: self.low.as_decimal(),
			close: self.close.as_decimal(),
		}
	}
}

/// Collection of both price and timestamp information.
#[derive(Debug)]
pub struct OHLCTradeTimestampRange<
	const NS_LEN: u64,
	IS: InstrumentSpec,
> {
	pub ohlc: OHLC<NS_LEN, IS>,
	pub trade_timestamp_range: TradeTimestampRangeInclusive,
}

impl<
	const NS_LEN: u64,
	IS: InstrumentSpec,
> TradeTimestampRangeIncluded for OHLCTradeTimestampRange<NS_LEN, IS> {
	fn trade_timestamp_range_inclusive(
		&self,
	) -> TradeTimestampRangeInclusive {
		self.trade_timestamp_range
	}
}