Skip to content

Commit 3bb18ac

Browse files
authored
feat(lazer/adk): Add asset id (#3148)
* add asset id * change asset id to string * Revert "change asset id to string" This reverts commit 8430929. * add asset class enum * make fn public * remove unnecessary rename * bump version * add validation for dynamic value presence
1 parent e95f035 commit 3bb18ac

File tree

4 files changed

+47
-4
lines changed

4 files changed

+47
-4
lines changed

Cargo.lock

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lazer/sdk/rust/protocol/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "pyth-lazer-protocol"
3-
version = "0.20.1"
3+
version = "0.20.2"
44
edition = "2021"
55
description = "Pyth Lazer SDK - protocol types."
66
license = "Apache-2.0"

lazer/sdk/rust/protocol/src/dynamic_value.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use std::collections::BTreeMap;
22

33
use crate::time::{DurationUs, TimestampUs};
4+
use anyhow::bail;
45
use derive_more::From;
56
use serde::{
67
ser::{SerializeMap, SerializeSeq},
@@ -54,3 +55,12 @@ impl Serialize for DynamicValue {
5455
}
5556
}
5657
}
58+
59+
impl DynamicValue {
60+
pub fn is_str(&self, field_name: &str) -> anyhow::Result<()> {
61+
match self {
62+
DynamicValue::String(_) => Ok(()),
63+
_ => bail!("invalid value type for {field_name}: expected String, got {self:?}"),
64+
}
65+
}
66+
}

lazer/sdk/rust/protocol/src/lib.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ pub use crate::{
3434
symbol_state::SymbolState,
3535
};
3636

37+
#[derive(
38+
Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, From, Into,
39+
)]
40+
pub struct AssetId(pub u32);
41+
3742
#[derive(
3843
Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize, From, Into,
3944
)]
@@ -84,6 +89,34 @@ pub enum PriceFeedProperty {
8489
// More fields may be added later.
8590
}
8691

92+
#[derive(Debug, Clone, Deserialize)]
93+
#[serde(rename_all = "kebab-case")]
94+
pub enum AssetClass {
95+
Crypto,
96+
Fx,
97+
Equity,
98+
Metal,
99+
Rates,
100+
Nav,
101+
Commodity,
102+
FundingRate,
103+
}
104+
105+
impl AssetClass {
106+
pub fn as_str(&self) -> &'static str {
107+
match self {
108+
AssetClass::Crypto => "crypto",
109+
AssetClass::Fx => "fx",
110+
AssetClass::Equity => "equity",
111+
AssetClass::Metal => "metal",
112+
AssetClass::Rates => "rates",
113+
AssetClass::Nav => "nav",
114+
AssetClass::Commodity => "commodity",
115+
AssetClass::FundingRate => "funding-rate",
116+
}
117+
}
118+
}
119+
87120
// Operation and coefficient for converting value to mantissa.
88121
enum ExponentFactor {
89122
// mantissa = value * factor

0 commit comments

Comments
 (0)