Repository: tarkah/tickrs (language: rust)

Issue:
Unable to track U.S. Dollar Index
I'm unable to add USDX (Yahoo! Finance quote DX-Y.NYB) under symbols. I've added it under symbols like so:
```yml
symbols:
    - BTC-USD
    - ETH-USD
    - ADA-USD
    - LINK-USD
    - BTC-ETH
    - DX-Y.NYB
```
and the graph seems to be stuck loading the graph. If indexes are supposed to be added differently it isn't made clear by the documentation.

![image](https://user-images.githubusercontent.com/80115848/110140301-3de6b280-7dd4-11eb-84ad-fce14842735f.png)

Thanks! - Gustav


Discussion / hints:
Thanks for opening the issue! Hmm, that symbol definitely works when I query the API directly with it. There must be a missing value from the response that I'm expecting that doesn't exist on indexes. I'll get this fixed.

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 069e0db..8ee0ce1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,10 @@ and `Removed`.
 
 ## [Unreleased]
 
+### Fixed
+
+- Fix bug preventing Index tickers from working ([#115])
+
 ## [0.14.1] - 2021-03-02
 
 ### Fixed
@@ -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
\ No newline at end of file
diff --git a/api/src/client.rs b/api/src/client.rs
index 4c9edd4..069aeb1 100644
--- a/api/src/client.rs
+++ b/api/src/client.rs
@@ -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;
diff --git a/api/src/model.rs b/api/src/model.rs
index 49bad04..285b944 100644
--- a/api/src/model.rs
+++ b/api/src/model.rs
@@ -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>,
 }
 
@@ -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)]
diff --git a/src/service/stock.rs b/src/service/stock.rs
index 2be8e0c..e78a530 100644
--- a/src/service/stock.rs
+++ b/src/service/stock.rs
@@ -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 {
@@ -64,6 +64,7 @@ impl Service for StockService {
             .company_handle
             .response()
             .try_iter()
+            .map(Box::new)
             .map(Update::CompanyData);
         updates.extend(company_updates);
 
diff --git a/src/task/current_price.rs b/src/task/current_price.rs
index 084b397..ac8578f 100644
--- a/src/task/current_price.rs
+++ b/src/task/current_price.rs
@@ -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 {
diff --git a/src/widget/stock.rs b/src/widget/stock.rs
index b160928..ea430ef 100644
--- a/src/widget/stock.rs
+++ b/src/widget/stock.rs
@@ -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 {
@@ -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;


Test patch: