penumbra_sdk_dex/
candlestick.rs1use anyhow::Result;
2use serde::{Deserialize, Serialize};
3
4use penumbra_sdk_proto::{core::component::dex::v1 as pb, DomainType};
5
6#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
7#[serde(try_from = "pb::CandlestickData", into = "pb::CandlestickData")]
8pub struct CandlestickData {
9 pub height: u64,
11 pub open: f64,
13 pub close: f64,
15 pub high: f64,
17 pub low: f64,
19 pub direct_volume: f64,
21 pub swap_volume: f64,
23}
24
25impl DomainType for CandlestickData {
26 type Proto = pb::CandlestickData;
27}
28
29impl From<CandlestickData> for pb::CandlestickData {
30 fn from(cd: CandlestickData) -> Self {
31 Self {
32 height: cd.height,
33 open: cd.open,
34 close: cd.close,
35 high: cd.high,
36 low: cd.low,
37 direct_volume: cd.direct_volume,
38 swap_volume: cd.swap_volume,
39 }
40 }
41}
42
43impl TryFrom<pb::CandlestickData> for CandlestickData {
44 type Error = anyhow::Error;
45 fn try_from(cd: pb::CandlestickData) -> Result<Self, Self::Error> {
46 Ok(Self {
47 height: cd.height,
48 open: cd.open,
49 close: cd.close,
50 high: cd.high,
51 low: cd.low,
52 direct_volume: cd.direct_volume,
53 swap_volume: cd.swap_volume,
54 })
55 }
56}