How to read multiple stock from yahoo finance into appinventor

456 views
Skip to first unread message
Assigned to ewpa...@gmail.com by steve....@gmail.com

Ask1900

unread,
Aug 28, 2017, 3:56:05 PM8/28/17
to mitappinv...@googlegroups.com
I have started to learn to build app with appinventor so completely new to this and would appreciate some help.  I want to show the Google and IBM stock price information on the phone screen simultaneously.

When I download the stock information for these two stocks from yahoo finance, they come as 2 csv strings, each on a different line so appinventor falls over when it tries to  read 'list from csv row text' because of the new line.  I also tried 'list from csv table text' and both produced error and just read the data as blank.

Anyone know how I can get appinventor to read both stock information in one URL call?  Otherwise I would have to call the URL twice.

Thanks.

SteveJG

unread,
Aug 28, 2017, 10:09:21 PM8/28/17
to MIT App Inventor Forum
You did not show with a copy of your blocks how you are downloading stock information so we don't really know what you are attempting.

Depending on your code, you could place the two stock symbols into a list, then use a for each item in list block to populate a Label, perhaps like this

and retrieve it all with a single URL call.

Regards,
Steve

Ask1900

unread,
Aug 29, 2017, 6:49:27 AM8/29/17
to mitappinv...@googlegroups.com
Thank you for replying.  I read the stocks in as shown by the tutorial for stock app in appinventor and so i end up with a data string as


price,change
price,change

the first line is that for google and the second line is for ibm.  if i just request google stock then i am fine with reading in the one line but the issue appear when i attempt to read two stocks at the same time and end up with an extra line.  app inventor reads this as blank in the command 'get response content'.  effectively i need appinventor to be able to read a csv string that are separated by a new line, at the moment it can only read the csv string if the string is on one line.

Ryan Cheung

unread,
Aug 29, 2017, 8:26:52 AM8/29/17
to MIT App Inventor Forum
I made a stock quote app too. You may try the request link like http://download.finance.yahoo.com/d/quotes.csv?f=nl1c1&e=.csv&s=2628.hk,1398.hk

It will return 2 stock with stock name , price , and price change in csv. Use csv to list block to convert the csv to list. Then you can do whatever you want.

Ryan 

SteveJG

unread,
Aug 29, 2017, 10:08:31 AM8/29/17
to mitappinv...@googlegroups.com
@Ryan ...thanks for your URL...I was not aware of that way to provide multiple stock reports.

@Ask1900

You are dealing with multiple issues.

1) You still did not post the blocks and links you used to obtain GOOG and IBM stock prices using the Yahoo Finance API  ( https://developer.yahoo.com/finance/company.html )  The method of using the Yahoo Finance API determines what you have to do to post multiple stock quotes in a single URL post.

2) the Stock Quotes for App Inventor 2 in the MIT tutorials (  http://appinventor.mit.edu/explore/ai2/stockquotes.html  )  contains erroneous information.  The http://finance.yahoo.com/d/quotes.csv?f=l1&s=   is no longer valid (since about mid 2016) .  You should use the link provided by Ryan  (  http://download.finance.yahoo.com/d/quotes.csv?f=nl1c1&e=.csv&s=  )   or use a structure like  http://download.finance.yahoo.com/d/quotes.csv?s=GOOG&f=sl1d1t1c1ohgv&e=.csv&columns='symbol,price,date,time,change,col1,high,low,col2      and modify the code in the Web.Get event handler.  I use this methodology with a different url call.  MIT really needs to update this tutorial because at present, as shown, the tutorial code does not work and that is sad.

3)  Ryan's URL is a very simple way to achieve your goals .

either one of these constructions will provide your goal 

The first line of the join is      http://download.finance.yahoo.com/d/quotes.csv?f=nl1c1&e=.csv&s=    

followed by  goog,ibm     .This is a slight modification of Ryan's code.   His code provides information from the hk (Hong Kong stock exchange). Substitute his 2628.hk,1398.hk   with goog,ibm and you should be fine.  You can also use more than two stock codes, separated by commas.   goog,ibm,msft,gm      etc.   I am not sure how many you can daisy chain.  Be sure NOT to separate with spaces.  The symbol must immediately follow the comma.

4)  The erroneous MIT tutorial blocks are 






change them as shown in #3   and they will work with the original MIT Get blocks when followed by the Web.Get call


5)  When asking for help, it is very important to post the links you use, the relevant block code image and to also perform a DoIt if not dealing with local variables.   Otherwise it is difficult for Forum members to provide meaningful advice.  

6)  There are MULTIPLE ways of handling the Yahoo Finance data.  (See the link in #1).

Did this solve your issue?    If you still want to separate your csv file info, you need to provide a screenshot of your blocks and show us how you obtained the csv.


Be aware, the information you obtain, per Yahoo's terms of use, can only be used in a non-commercial app.   If you sell your app, you cannot use their API.

Here is another link that might help you design your stock app   http://wern-ancheta.com/blog/2015/04/05/getting-started-with-the-yahoo-finance-api/  and just because you are new you (and others) might benefit from this advice:

We want you to have fun with App Inventor so here are some resources to help you learn to use the AI2 tools  A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook   http://www.appinventor.org/book2 ... the links are at the bottom of the Web page.  The book 'teaches' users how to program with AI2 blocks.

There is a free programming course here http://www.appinventor.org/content/CourseInABox/Intro  and the aia files for the projects in the book are here:  http://www.appinventor.org/bookFiles  

How to do a lot of basic things with App Inventor are described here:  http://www.appinventor.org/content/howDoYou/eventHandling  .


We urge new AI developers to do some tutorials before embarking on ambitious projects.  Doing, not just reading the tutorials will help you to actually learn to code with AI rather that just follow examples.

Regards,
Steve



Ask1900

unread,
Aug 29, 2017, 1:10:09 PM8/29/17
to MIT App Inventor Forum
@Ryan - i downloaded your link, which gives exactly what i had, except your stock names are different than mine.  However, when i use 'list from csv row text' block, it returns error and states that the data downloaded is empty.  I don't know how you managed to read this string into appinventor without error and yet I am getting an error?

error mesage 'Cannot parse text argument to "list from csv row" as CSV-formatted row<br/><i>Note:</i>&nbsp;'

i am fine if i only download one stock and not both

Evan Patton

unread,
Aug 29, 2017, 11:30:24 PM8/29/17
to MIT App Inventor Forum
@Ask1900: You should use the list from csv table instead of list from csv row. The former will parse multiple lines whereas the latter only parses a single line. For example, using the link Ryan provided I stored the result in a global called webResult. The following comes back after using "Do It" with the list from csv table block:


You would then parse this as a list of lists. Each element in the outer list is a row and then each element in the inner list is a cell in that row.

@SteveJG: I've passed along the issue of the incorrect tutorial to our educational team to have it corrected.

Evan

Ask1900

unread,
Aug 31, 2017, 10:44:45 AM8/31/17
to MIT App Inventor Forum
@Evan - thank you so much.  I did attempt to use list from csv table but i did not understand that it is a list of list, now that you have explained that it is a list of list and shown the picture, it all makes sense.  I have it working now, many thanks.

I did not use the download url from the tutorial as i did not really want google and ibm stock and the information i wanted from the individual stock is not the same as in the tutorial so i got my url for the download by googling as that explained how the url is built up so i could customise it to what i wanted.

Do you happen to know if this download is also available from google finance as that quotes stock price in real time whereas yahoo finance has a delay of 15 minutes.

@SteveJG - i am learning to develop app as a hobby and i plan only to develop apps for my own personal use so no worries about selling this :-)
Reply all
Reply to author
Forward
0 new messages