diff --git a/CHANGELOG.md b/CHANGELOG.md index 8a386895..b72d0809 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +Unreleased +---------- +- Fixed JSON decoding error when no bars are returned in response to + `data::v2::bars::Get` request + + 0.22.1 ------ - Added support for realtime market data streaming via diff --git a/src/data/v2/bars.rs b/src/data/v2/bars.rs index f08c96be..4a686ca5 100644 --- a/src/data/v2/bars.rs +++ b/src/data/v2/bars.rs @@ -11,6 +11,7 @@ use serde::Serialize; use serde_urlencoded::to_string as to_query; use crate::data::DATA_BASE_URL; +use crate::util::vec_from_str; use crate::Str; @@ -107,6 +108,7 @@ pub struct Bar { #[non_exhaustive] pub struct Bars { /// The list of returned bars. + #[serde(deserialize_with = "vec_from_str")] pub bars: Vec, /// The symbol the bars correspond to. pub symbol: String, @@ -198,6 +200,27 @@ mod tests { assert!(res.next_page_token.is_some()) } + /// Check that we can decode a response containing no bars correctly. + #[test(tokio::test)] + async fn no_bars() { + let api_info = ApiInfo::from_env().unwrap(); + let client = Client::new(api_info); + let start = Utc.ymd(2021, 11, 5).and_hms_milli(0, 0, 0, 0); + let end = Utc.ymd(2021, 11, 5).and_hms_milli(0, 0, 0, 0); + + let request = BarReq { + symbol: "SPY".to_string(), + limit: None, + start, + end, + timeframe: TimeFrame::OneDay, + page_token: None, + adjustment: None, + }; + let res = client.issue::(&request).await.unwrap(); + assert_eq!(res.bars, Vec::new()) + } + /// Check that we can request historic bar data for a stock. #[test(tokio::test)] async fn request_bars() {