jalibu / MMM-Jast

A minimalistic stock ticker based on Yahoo's finance API for the MagicMirror² platform.
MIT License
67 stars 22 forks source link

Json Decode Error #32

Closed lxy1992 closed 2 years ago

lxy1992 commented 2 years ago

Platform

Raspberry Pi OS

Node.js Version

v16.13.1

MagicMirror Version

2.17.1

Module Version

v.2.6.0

Description

First, Thank you for write this module, its really make us much easier to enjoy magic mirror. However, I need you help now, I am not good at JS, so I cannot fix it by myself. The problem is when I setup the module as the readme write. And I got the error message like

API request for AMZN failed: invalid json response body at 
https://query2.finance.yahoo.com/v10/finance/quoteSummary/AMZN?formatted=false&modules=price 
reason: Unexpected token < in JSON at position 0

I guess, it's something wrong with the decoding of the response into json, so I check the resposne. Its seems ok

{
   "quoteSummary":{
      "result":[
         {
            "price":{
               "maxAge":1,
               "preMarketSource":"FREE_REALTIME",
               "postMarketChangePercent":-9.25174E-4,
               "postMarketChange":-0.109901,
               "postMarketTime":1640998794,
               "postMarketPrice":118.68,
               "postMarketSource":"FREE_REALTIME",
               "regularMarketChangePercent":-0.034149095,
               "regularMarketChange":-4.199997,
               "regularMarketTime":1640984442,
               "priceHint":2,
               "regularMarketPrice":118.79,
               "regularMarketDayHigh":122.91,
               "regularMarketDayLow":118.59,
               "regularMarketVolume":24024133,
               "regularMarketPreviousClose":122.99,
               "regularMarketSource":"DELAYED",
               "regularMarketOpen":121.23,
               "exchange":"NYQ",
               "exchangeName":"NYSE",
               "exchangeDataDelayedBy":0,
               "marketState":"CLOSED",
               "quoteType":"EQUITY",
               "symbol":"BABA",
               "underlyingSymbol":null,
               "shortName":"Alibaba Group Holding Limited",
               "longName":"Alibaba Group Holding Limited",
               "currency":"USD",
               "quoteSourceName":"Nasdaq Real Time Price",
               "currencySymbol":"$",
               "fromCurrency":null,
               "toCurrency":null,
               "lastMarket":null,
               "marketCap":331230478336
            }
         }
      ],
      "error":null
   }
}

So, I guess its only need to check the decode part. Hope you can fix this ASAP. Thanks a lot.

PS. Happy new year !

Expected behavior

Hope the module can show the info

Current behavior

just keep loading and show me some warning which I think it should be a error. Like I report above.

Possible solution

the decoding part of handling the response from the third part financial API.

Steps to reproduce

  1. Start it
  2. See the loading page
  3. See the warning info in the log

Log

[WARN]  API request for BABA failed: invalid json response body at https://query2.finance.yahoo.com/v10/finance/quoteSummary/BABA?formatted=false&modules=price reason: Unexpected token < in JSON at position 0

config.js

{
    module: "MMM-Jast",
    position: "top_left",
    config: {
        maxWidth: "100%",
        updateIntervalInSeconds: 300,
        fadeSpeedInSeconds: 3.5,
        scroll: "vertical", // One of ["none", "vertical", "horizontal"]
        useGrouping: false,
        currencyStyle: "code", // One of ["code", "symbol", "name"]
        lastUpdateFormat: "HH:mm",
        showColors: true,
        showCurrency: true,
        showChangePercent: true,
        showChangeValue: false,
        showChangeValueCurrency: false,
        showLastUpdate: false,
        showPortfolioValue: false,
        showPortfolioGrowthPercent: false,
        showPortfolioGrowth: false,
        numberDecimalsValues: 2,
        numberDecimalsPercentages: 1,
        virtualHorizontalMultiplier: 2,
        stocks: [
            { name: "apple", symbol: "AAPL", quantity: 10 },
            { name: "AMZN", symbol: "AMZN", quantity: 15 },
            { name: "TSLA", symbol: "TSLA" },
            { name: "Alibaba", symbol: "BABA"}
        ]
    }
}

Additional info

No response

jalibu commented 2 years ago

Hi @lxy1992 ,

I can't reproduce that with your provided config. As you can see, it works fine (just changed scroll to 'none' for the screenshot) image

Does this error still occur on your side?

jalibu commented 2 years ago

@lxy1992 any updates here? Otherwise I'd close

unliar commented 2 years ago

This error is because Yahoo no longer provides services to mainland China.

the API returns a service shutdown notification HTML.

below is the snapshoot

image

maybe the readme should add a notice for that