pyth_lazer_protocol/
api.rs

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