apple-quant-algorithmic 0.2.0

Apple Quant's algorithmic trading api
Documentation
use rust_decimal::Decimal;

use crate::{
	instrument::InstrumentSpec,
	price::AbsolutePrice,
	timestamp::{TradeTimestampRange, TradeTimestampedRange},
};

/// 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: TradeTimestampRange,
}

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