penumbra_dex/
candlestick.rsuse anyhow::Result;
use serde::{Deserialize, Serialize};
use penumbra_proto::{core::component::dex::v1 as pb, DomainType};
#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
#[serde(try_from = "pb::CandlestickData", into = "pb::CandlestickData")]
pub struct CandlestickData {
pub height: u64,
pub open: f64,
pub close: f64,
pub high: f64,
pub low: f64,
pub direct_volume: f64,
pub swap_volume: f64,
}
impl DomainType for CandlestickData {
type Proto = pb::CandlestickData;
}
impl From<CandlestickData> for pb::CandlestickData {
fn from(cd: CandlestickData) -> Self {
Self {
height: cd.height,
open: cd.open,
close: cd.close,
high: cd.high,
low: cd.low,
direct_volume: cd.direct_volume,
swap_volume: cd.swap_volume,
}
}
}
impl TryFrom<pb::CandlestickData> for CandlestickData {
type Error = anyhow::Error;
fn try_from(cd: pb::CandlestickData) -> Result<Self, Self::Error> {
Ok(Self {
height: cd.height,
open: cd.open,
close: cd.close,
high: cd.high,
low: cd.low,
direct_volume: cd.direct_volume,
swap_volume: cd.swap_volume,
})
}
}