api.rs 1.7 KB

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