Skip to content

Commit

Permalink
FIX: Use POST for metadata endpoints with symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
threecgreen committed Jan 16, 2025
1 parent 8d6151c commit ab7ba6d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 28 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 0.18.1 - TBD

### Bug fixes
- Changed historical metadata methods with `symbols` parameter to use a `POST` request
to allow for requesting supported maximum of 2000 symbols

## 0.18.0 - 2025-01-08

### Enhancements
Expand Down
49 changes: 22 additions & 27 deletions src/historical/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ impl MetadataClient<'_> {
/// This function returns an error when it fails to communicate with the Databento API
/// or the API indicates there's an issue with the request.
pub async fn get_record_count(&mut self, params: &GetRecordCountParams) -> crate::Result<u64> {
let resp = self
.get("get_record_count")?
.add_to_query(params)
.send()
.await?;
let mut form = Vec::new();
params.add_to_form(&mut form);
let resp = self.post("get_record_count")?.form(&form).send().await?;
handle_response(resp).await
}

Expand All @@ -154,11 +152,9 @@ impl MetadataClient<'_> {
&mut self,
params: &GetBillableSizeParams,
) -> crate::Result<u64> {
let resp = self
.get("get_billable_size")?
.add_to_query(params)
.send()
.await?;
let mut form = Vec::new();
params.add_to_form(&mut form);
let resp = self.post("get_billable_size")?.form(&form).send().await?;
handle_response(resp).await
}

Expand All @@ -169,13 +165,19 @@ impl MetadataClient<'_> {
/// This function returns an error when it fails to communicate with the Databento API
/// or the API indicates there's an issue with the request.
pub async fn get_cost(&mut self, params: &GetCostParams) -> crate::Result<f64> {
let resp = self.get("get_cost")?.add_to_query(params).send().await?;
let mut form = Vec::new();
params.add_to_form(&mut form);
let resp = self.post("get_cost")?.form(&form).send().await?;
handle_response(resp).await
}

fn get(&mut self, slug: &str) -> crate::Result<RequestBuilder> {
self.inner.get(&format!("metadata.{slug}"))
}

fn post(&mut self, slug: &str) -> crate::Result<RequestBuilder> {
self.inner.post(&format!("metadata.{slug}"))
}
}

/// A type of data feed.
Expand Down Expand Up @@ -284,7 +286,6 @@ pub struct DatasetRange {
pub end: time::OffsetDateTime,
}

#[allow(deprecated)]
impl<'de> Deserialize<'de> for DatasetRange {
fn deserialize<D>(deserializer: D) -> std::result::Result<Self, D::Error>
where
Expand Down Expand Up @@ -430,20 +431,16 @@ fn deserialize_date<'de, D: serde::Deserializer<'de>>(
let dt_str = String::deserialize(deserializer)?;
time::Date::parse(&dt_str, super::DATE_FORMAT).map_err(serde::de::Error::custom)
}
impl AddToQuery<GetQueryParams> for reqwest::RequestBuilder {
fn add_to_query(mut self, params: &GetQueryParams) -> Self {
self = self
.query(&[
("dataset", params.dataset.as_str()),
("schema", params.schema.as_str()),
("stype_in", params.stype_in.as_str()),
])
.add_to_query(&params.symbols)
.add_to_query(&params.date_time_range);
if let Some(limit) = params.limit {
self = self.query(&[("limit", &limit.to_string())]);
impl GetQueryParams {
fn add_to_form(&self, form: &mut Vec<(&'static str, String)>) {
form.push(("dataset", self.dataset.to_string()));
form.push(("schema", self.schema.to_string()));
form.push(("stype_in", self.stype_in.to_string()));
form.push(("symbols", self.symbols.to_api_string()));
self.date_time_range.add_to_form(form);
if let Some(limit) = self.limit {
form.push(("limit", limit.get().to_string()))
}
self
}
}

Expand Down Expand Up @@ -650,7 +647,6 @@ mod tests {
}

#[tokio::test]
#[allow(deprecated)]
async fn test_get_dataset_range() {
const DATASET: &str = "XNAS.ITCH";
let mock_server = MockServer::start().await;
Expand Down Expand Up @@ -679,7 +675,6 @@ mod tests {
}

#[tokio::test]
#[allow(deprecated)]
async fn test_get_dataset_range_no_dates() {
const DATASET: &str = "XNAS.ITCH";
let mock_server = MockServer::start().await;
Expand Down
1 change: 0 additions & 1 deletion src/live/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,6 @@ impl fmt::Debug for Client {
}

#[cfg(test)]
#[allow(deprecated)]
mod tests {
use std::{ffi::c_char, fmt};

Expand Down

0 comments on commit ab7ba6d

Please sign in to comment.