Skip to content

Commit

Permalink
fix: support quote where firstTradeDate equal null
Browse files Browse the repository at this point in the history
Make the "firstTradeDate" key optional as it is returned as a null value
for the symbol SIWA.F. This means that the first_trade_date field of the
YMetaData struct is now Option<i32> instead of i32.
  • Loading branch information
tirithen authored and xemwebe committed Sep 3, 2023
1 parent d88e11e commit adb48bc
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/async_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ mod tests {

assert_eq!(&resp.chart.result[0].meta.symbol, "IBM");
assert_eq!(&resp.chart.result[0].meta.data_granularity, "1d");
assert_eq!(&resp.chart.result[0].meta.first_trade_date, &-252322200);
assert_eq!(
&resp.chart.result[0].meta.first_trade_date,
&Some(-252322200)
);

let _ = resp.last_quote().unwrap();
}
Expand Down Expand Up @@ -234,6 +237,17 @@ mod tests {
let _ = response.last_quote().unwrap();
}

#[test]
fn test_mutual_fund_latest_with_null_first_trade_date() {
let provider = YahooConnector::new();
let response = tokio_test::block_on(provider.get_latest_quotes("SIWA.F", "1d")).unwrap();

assert_eq!(&response.chart.result[0].meta.symbol, "SIWA.F");
assert_eq!(&response.chart.result[0].meta.range, "1mo");
assert_eq!(&response.chart.result[0].meta.data_granularity, "1d");
let _ = response.last_quote().unwrap();
}

#[test]
fn test_mutual_fund_range() {
let provider = YahooConnector::new();
Expand Down
5 changes: 4 additions & 1 deletion src/blocking_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ mod tests {

assert_eq!(&resp.chart.result[0].meta.symbol, "IBM");
assert_eq!(&resp.chart.result[0].meta.data_granularity, "1d");
assert_eq!(&resp.chart.result[0].meta.first_trade_date, &-252322200);
assert_eq!(
&resp.chart.result[0].meta.first_trade_date,
&Some(-252322200)
);

let _ = resp.last_quote().unwrap();
}
Expand Down
3 changes: 2 additions & 1 deletion src/quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ pub struct YMetaData {
pub symbol: String,
pub exchange_name: String,
pub instrument_type: String,
pub first_trade_date: i32,
#[serde(default)]
pub first_trade_date: Option<i32>,
pub regular_market_time: u32,
pub gmtoffset: i32,
pub timezone: String,
Expand Down

0 comments on commit adb48bc

Please sign in to comment.