Skip to content

Commit

Permalink
Fix/index failure (#115)
Browse files Browse the repository at this point in the history
* fix optional fields

* fix clippy lint

* disable options for INDEX

* update CHANGELOG
  • Loading branch information
tarkah authored Mar 5, 2021
1 parent 94edbd3 commit 4ffce4c
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ and `Removed`.

## [Unreleased]

### Fixed

- Fix bug preventing Index tickers from working ([#115])

## [0.14.1] - 2021-03-02

### Fixed
Expand Down Expand Up @@ -168,3 +172,4 @@ and `Removed`.
[#93]: https://github.com/tarkah/tickrs/pull/93
[#110]: https://github.com/tarkah/tickrs/pull/110
[#112]: https://github.com/tarkah/tickrs/pull/112
[#115]: https://github.com/tarkah/tickrs/pull/115
2 changes: 1 addition & 1 deletion api/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ mod tests {
async fn test_company_data() {
let client = Client::new();

let symbols = vec!["SPY", "AAPL", "AMD", "TSLA", "ES=F", "BTC-USD"];
let symbols = vec!["SPY", "AAPL", "AMD", "TSLA", "ES=F", "BTC-USD", "DX-Y.NYB"];

for symbol in symbols {
let data = client.get_company_data(symbol).await;
Expand Down
7 changes: 4 additions & 3 deletions api/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ pub struct CompanyPrice {
pub long_name: Option<String>,
pub regular_market_price: CompanyMarketPrice,
pub regular_market_previous_close: CompanyMarketPrice,
pub post_market_price: CompanyPostMarketPrice,
pub regular_market_volume: CompanyMarketPrice,
pub post_market_price: OptionalCompanyMarketPrice,
pub regular_market_volume: OptionalCompanyMarketPrice,
pub currency: Option<String>,
}

Expand All @@ -152,9 +152,10 @@ pub struct CompanyMarketPrice {

#[derive(Debug, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
pub struct CompanyPostMarketPrice {
pub struct OptionalCompanyMarketPrice {
#[serde(rename = "raw")]
pub price: Option<f64>,
pub fmt: Option<String>,
}

#[derive(Debug, Deserialize, Clone)]
Expand Down
3 changes: 2 additions & 1 deletion src/service/stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl StockService {
pub enum Update {
NewPrice((f64, Option<f64>, String)),
Prices((TimeFrame, ChartMeta, Vec<Price>)),
CompanyData(CompanyData),
CompanyData(Box<CompanyData>),
}

impl Service for StockService {
Expand All @@ -64,6 +64,7 @@ impl Service for StockService {
.company_handle
.response()
.try_iter()
.map(Box::new)
.map(Update::CompanyData);
updates.extend(company_updates);

Expand Down
2 changes: 1 addition & 1 deletion src/task/current_price.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl AsyncTask for CurrentPrice {

let post_price = response.price.post_market_price.price;

let volume = response.price.regular_market_volume.fmt;
let volume = response.price.regular_market_volume.fmt.unwrap_or_default();

Some((regular_price, post_price, volume))
} else {
Expand Down
11 changes: 9 additions & 2 deletions src/widget/stock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,14 +254,14 @@ impl StockState {
self.chart_meta = Some(chart_meta);
}
service::stock::Update::CompanyData(data) => {
self.profile = Some(data);
self.profile = Some(*data);
}
}
}
}

fn options_enabled(&self) -> bool {
!self.is_crypto()
!self.is_crypto() && !self.is_index()
}

fn configure_enabled(&self) -> bool {
Expand All @@ -275,6 +275,13 @@ impl StockState {
== Some("CRYPTOCURRENCY")
}

fn is_index(&self) -> bool {
self.chart_meta
.as_ref()
.and_then(|m| m.instrument_type.as_deref())
== Some("INDEX")
}

pub fn toggle_options(&mut self) -> bool {
if !self.options_enabled() {
return false;
Expand Down

0 comments on commit 4ffce4c

Please sign in to comment.