-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hermes] add /v2/price_feeds endpoint (#1277)
* initial stab * fix comments * add filter feature * fix deprecated warnings * use cache * Update price_feeds API query * Update PriceFeedsQueryParams struct in price_feeds.rs * fix merge conflict * fix default value * add tracing info * fix comment * address comments * change var name * refactor * refactor * refactor * refactor * undo changes in cache.rs * undo changes in aggregate.rs * address comments * address comments * address comments and improve fetching data speed * address comments * address comments * bump * change chunk size * change function name * address comment * address comments * address comments * address comments * Remove debug print statement * address comments and add to openapi
- Loading branch information
Showing
14 changed files
with
1,364 additions
and
369 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod latest_price_updates; | ||
pub mod price_feeds_metadata; | ||
pub mod timestamp_price_updates; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
use { | ||
crate::{ | ||
api::{ | ||
rest::RestError, | ||
types::{ | ||
AssetType, | ||
PriceFeedMetadata, | ||
}, | ||
}, | ||
price_feeds_metadata::get_price_feeds_metadata, | ||
}, | ||
anyhow::Result, | ||
axum::{ | ||
extract::State, | ||
Json, | ||
}, | ||
serde::Deserialize, | ||
serde_qs::axum::QsQuery, | ||
utoipa::IntoParams, | ||
}; | ||
|
||
|
||
#[derive(Debug, Deserialize, IntoParams)] | ||
#[into_params(parameter_in=Query)] | ||
pub struct PriceFeedsMetadataQueryParams { | ||
/// Optional query parameter. If provided, the results will be filtered to all price feeds whose symbol contains the query string. Query string is case insensitive. | ||
#[param(example = "bitcoin")] | ||
query: Option<String>, | ||
|
||
/// Optional query parameter. If provided, the results will be filtered by asset type. Possible values are crypto, equity, fx, metal, rates. Filter string is case insensitive. | ||
#[param(example = "crypto")] | ||
asset_type: Option<AssetType>, | ||
} | ||
|
||
/// Get the set of price feeds. | ||
/// | ||
/// This endpoint fetches all price feeds from the Pyth network. It can be filtered by asset type | ||
/// and query string. | ||
#[utoipa::path( | ||
get, | ||
path = "/v2/price_feeds", | ||
responses( | ||
(status = 200, description = "Price feeds metadata retrieved successfully", body = Vec<RpcPriceIdentifier>) | ||
), | ||
params( | ||
PriceFeedsMetadataQueryParams | ||
) | ||
)] | ||
pub async fn price_feeds_metadata( | ||
State(state): State<crate::api::ApiState>, | ||
QsQuery(params): QsQuery<PriceFeedsMetadataQueryParams>, | ||
) -> Result<Json<Vec<PriceFeedMetadata>>, RestError> { | ||
let price_feeds_metadata = | ||
get_price_feeds_metadata(&*state.state, params.query, params.asset_type) | ||
.await | ||
.map_err(|e| { | ||
tracing::warn!("RPC connection error: {}", e); | ||
RestError::RpcConnectionError { | ||
message: format!("RPC connection error: {}", e), | ||
} | ||
})?; | ||
|
||
Ok(Json(price_feeds_metadata)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.