Need Help with Yahoo Finance API Web Request

Former Member
Former Member
Hey ..

Well .. I have a need for some help. I am interested in making a stock app .. so that I can check my stocks.

Edit .. I can get the data in the simulator, which is a start.

It is as follows ..

{query=>{results=>{quote=>{OneyrTargetPrice=>null, LowLimit=>null, HoldingsGain=>null, AverageDailyVolume=>934476, Commission=>null, ExDividendDate=>null, MarketCapitalization=>316.96B, HoldingsValueRealtime=>null, LastTradeDate=>2/10/2017, ErrorIndicationreturnedforsymbolchangedinvalid=>null, HighLimit=>null, EPSEstimateNextYear=>null, LastTradePriceOnly=>1.05, Symbol=>LAC.TO, LastTradeTime=>3:59pm, PriceSales=>486880.53, Bid=>1.04, Volume=>1823026, DaysHigh=>1.05, Notes=>null, PriceBook=>6.25, TradeDate=>null, FiftydayMovingAverage=>0.93, PercentChangeFromYearLow=>+141.38%, DaysLow=>1.00, ChangeRealtime=>null, DaysRangeRealtime=>null, PricePaid=>null, PercentChange=>+5.00%, Name=>LITHIUM AMERICAS CORP, symbol=>LAC.TO, AskRealtime=>null, DaysValueChangeRealtime=>null, PriceEPSEstimateNextYear=>null, HoldingsGainPercent=>null, YearHigh=>1.14, EPSEstimateCurrentYear=>0.00, AfterHoursChangeRealtime=>null, BookValue=>0.16, PreviousClose=>1.00, Currency=>CAD, SharesOwned=>null, ChangePercentRealtime=>null, DividendYield=>null, ChangeFromFiftydayMovingAverage=>0.12, EarningsShare=>-0.08, PEGRatio=>0.00, Ask=>1.05, MoreInfo=>null, TickerTrend=>null, PercebtChangeFromYearHigh=>-7.89%, ShortRatio=>0.00, YearLow=>0.44, YearRange=>0.44 - 1.14, Open=>1.02, Change_PercentChange=>+0.05 - +5.00%, TwoHundreddayMovingAverage=>0.86, ChangeFromYearHigh=>-0.09, PERatioRealtime=>null, PercentChangeFromFiftydayMovingAverage=>+13.16%, DaysRange=>1.00 - 1.05, EPSEstimateNextQuarter=>0.00, PriceEPSEstimateCurrentYear=>null, LastTradeWithTime=>3:59pm - <b>1.05</b>, StockExchange=>TOR, MarketCapRealtime=>null, HoldingsValue=>null, PERatio=>null, Change=>+0.05, DaysValueChange=>null, DividendShare=>null, AnnualizedGain=>null, BidRealtime=>null, LastTradeRealtimeWithTime=>null, ChangeFromTwoHundreddayMovingAverage=>0.19, HoldingsGainRealtime=>null, PercentChangeFromTwoHundreddayMovingAverage=>+22.17%, ChangeFromYearLow=>0.61, HoldingsGainPercentRealtime=>null, OrderBookRealtime=>null, EBITDA=>-10.93M, ChangeinPercent=>+5.00%, DividendPayDate=>null}}, created=>2017-02-12T20:08:06Z, count=>1, lang=>en-US}}

My web request is as follows ..

Comm.makeWebRequest("query.yahooapis.com/.../yql, null, {},method(:onWebResponse) );



But I am only interested in really .. the LastTradePrice and the OpeningPrice. I can do the needed math.

If someone would be able to let me know how to parse out the needed data from the above .. that would be nice.

Thanks
Kevin
  • Former Member
    Former Member over 8 years ago
    With a bit of testing .. I have determined that both of you are absolutely correct.

    This is a good learning experience for me. I do need to test things out for myself. :)

    So .. I get a code of -300 if there is no internet and yes I do check for GCM as well .. if that is not there, then nothing works.

    My app is making good progress. I did learn today that one of my stocks, I was using the wrong symbol. I know .. it is a TSXV thing .. but it is all working now.
  • Former Member
    Former Member over 8 years ago
    Ok ... so well, I am abandoning Yahoo Finance API, the reason .. the data is just flaky. I can run it 3x in a row and get 3 different results. One may be an hour old, one may be 2 hours old and the 3rd from a previous day. It corresponds with what I have seen others indicate. The only time the data is right .. is after the markets close which is unacceptable for the project.

    I am wanting to use Google Finance API. I know it is not supported by Google but I can send the following in my browser and get data back.

    finance.google.com/.../info

    I get the following back. I have confirmed that this data is accurate.

    // [{"id": "718117","t" : "ACB","e" : "CVE","l" : "2.62","l_fix" : "2.62","l_cur" : "CA$2.62","s": "0","ltt":"4:00PM EST","lt" : "Feb 27, 4:00PM EST","lt_dts" : "2017-02-27T16:00:00Z","c" : "0.00","c_fix" : "0.00","cp" : "0.00","cp_fix" : "0.00","ccol" : "chb","pcls_fix" : "2.62"},{"id": "121280306767104","t" : "WEED","e" : "TSE","l" : "12.39","l_fix" : "12.39","l_cur" : "CA$12.39","s": "0","ltt":"4:35PM EST","lt" : "Feb 27, 4:35PM EST","lt_dts" : "2017-02-27T16:35:31Z","c" : "+0.68","c_fix" : "0.68","cp" : "5.81","cp_fix" : "5.81","ccol" : "chg","pcls_fix" : "11.71"},{"id": "729318","t" : "LAC","e" : "TSE","l" : "1.06","l_fix" : "1.06","l_cur" : "CA$1.06","s": "0","ltt":"4:00PM EST","lt" : "Feb 27, 4:00PM EST","lt_dts" : "2017-02-27T16:00:00Z","c" : "-0.05","c_fix" : "-0.05","cp" : "-4.50","cp_fix" : "-4.50","ccol" : "chr","pcls_fix" : "1.11"}]

    I really only need 6 of these items .. 2 for each stock. I need the l (last price I assume), and pcls_fix (previous close), the ones in red.

    I cannot get the data back from Google from my application .. I get a - 400 code with null data.

    Wondering if someone could give me some insight on how to get the data back into my Connect IQ project.
  • AFAICT, the problem is that the first two characters of the result ate //, which trips up the JSON parser (it isn't valid JSON). It seems that you'll have to do something to avoid the leading slashes from getting into the response, or remove them before getting to Garmin Connect Mobile.

    That said, the Google finance API is deprecated and isn't supposed to be used by public applications. Something you might need to keep in mind.
  • Former Member
    Former Member over 8 years ago
    Travis is exactly right. The data returned from that API is not valid JSON, so ConnectIQ will never accept it. If this is a private project and does not violate Google's terms of use, you could use an intermediate server to reformat the JSON into a valid format. (This would even allow you to strip out the data you don't need, and speed things up on the CIQ phone link side.)

    I do not know the specifics of Google's terms of use, so it is possible this would still violate them for a personal project, you should verify this based on your project's needs.
  • Former Member
    Former Member over 8 years ago
    Thank you guys .. and yes this is a private project, to track my personal stocks.

    I guess that I will be forced to leave it with Yahoo. It would be fine if I could get the data back .. cause I could just parse out the data I need, but seeing as that is not possible I guess I will leave it as it is.

    I may update it .. to check for the time in regards to the data, and decide if I will show it on the screen at that time cause old data (much more than the 15 min delay) is not of any value to me.
  • Cool. I see a lot of potential for my wine education app development. I will look into talking with someone and develop this. I know it will take money and time to create this up, but I'm planning to make a question and answer up that will help people who look into the wine education exams and see obstacles. I also had to take some difficult exams throughout my career and I always needed a reliable application that could make the whole learning process easier. What is this would be an investment and I'm looking at people that invested money successfully like Steve Carell Net Worth and how he achieved it. Some great lessons to be learned, if you're not jealous of people but eager to learn from them.