Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions polyte-clob/src/api/markets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,18 @@ impl Markets {
)
.query("token_id", token_id.into())
}

/// Get historical prices for a token
pub fn prices_history(&self, token_id: impl Into<String>) -> Request<PricesHistoryResponse> {
Request::get(
self.client.clone(),
self.base_url.clone(),
"/prices-history",
AuthMode::None,
self.chain_id,
)
.query("market", token_id.into())
}
}

/// Market information
Expand Down Expand Up @@ -143,3 +155,20 @@ pub struct PriceResponse {
pub struct MidpointResponse {
pub mid: String,
}

/// A single point in the price history timeseries
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PriceHistoryPoint {
/// Unix timestamp (seconds)
#[serde(rename = "t")]
pub timestamp: i64,
/// Price at this point in time
#[serde(rename = "p")]
pub price: f64,
}

/// Response from the prices-history endpoint
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PricesHistoryResponse {
pub history: Vec<PriceHistoryPoint>,
}