pyth_lazer_protocol/
api.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    router::{Channel, Format, JsonBinaryEncoding, JsonUpdate, PriceFeedId, PriceFeedProperty},
5    time::TimestampUs,
6};
7
8#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
9#[serde(rename_all = "camelCase")]
10pub struct LatestPriceRequest {
11    pub price_feed_ids: Vec<PriceFeedId>,
12    pub properties: Vec<PriceFeedProperty>,
13    // "chains" was renamed to "formats". "chains" is still supported for compatibility.
14    #[serde(alias = "chains")]
15    pub formats: Vec<Format>,
16    #[serde(default)]
17    pub json_binary_encoding: JsonBinaryEncoding,
18    /// If `true`, the stream update will contain a JSON object containing
19    /// all data of the update.
20    #[serde(default = "default_parsed")]
21    pub parsed: bool,
22    pub channel: Channel,
23}
24
25#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
26#[serde(rename_all = "camelCase")]
27pub struct PriceRequest {
28    pub timestamp: TimestampUs,
29    pub price_feed_ids: Vec<PriceFeedId>,
30    pub properties: Vec<PriceFeedProperty>,
31    pub formats: Vec<Format>,
32    #[serde(default)]
33    pub json_binary_encoding: JsonBinaryEncoding,
34    /// If `true`, the stream update will contain a JSON object containing
35    /// all data of the update.
36    #[serde(default = "default_parsed")]
37    pub parsed: bool,
38    pub channel: Channel,
39}
40
41#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
42#[serde(rename_all = "camelCase")]
43pub struct ReducePriceRequest {
44    pub payload: JsonUpdate,
45    pub price_feed_ids: Vec<PriceFeedId>,
46}
47
48pub type LatestPriceResponse = JsonUpdate;
49pub type ReducePriceResponse = JsonUpdate;
50pub type PriceResponse = JsonUpdate;
51
52pub fn default_parsed() -> bool {
53    true
54}