Stock Indexes

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Stock Indexes

Post by lohill » Tue Aug 14, 2012 11:26 pm

Can anyone explain why the following code retrieves the the indexes for NASDAQ and the S&P 500 but fails to produce a 3rd line for the DOW Jones Industrial average. On Yahoo, through the browser, ^DJI gets the DOW just fine.

Code: Select all

on mouseUp
   put "&f=l1c" into yahooConfig
   put "^IXIC,^GSPC,^DJI," into tStocks
   put "http://finance.yahoo.com/d/quotes.csv?s=" & tStocks & yahooConfig into myURL
   put url myURL into myRetrieve
   answer myRetrieve
end mouseUp
It seems to fail no matter which position '^DJI' lies in tStocks. (i.e. I always get just two lines of data.)

Thanks,
Larry

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10330
Joined: Wed May 06, 2009 2:28 pm

Re: Stock Indexes

Post by dunbarx » Wed Aug 15, 2012 1:14 am

Hi.

Per your comment that isolating the "DJI" portion,

In safari, if I write:

put "^DJI" into tStocks

I get "Missing Symbols List".

Is there something wrong with "^DJI"?

Craig Newman

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Stock Indexes

Post by lohill » Wed Aug 15, 2012 4:38 pm

Hi Craig,
In safari, if I write:

put "^DJI" into tStocks

I get "Missing Symbols List".
I'm not quite sure what you are doing when you say this but if I use Safari to go to http://finance.yahoo.com and type ^DJI into the blank for getting a quote it gives me the correct answer. This indicates to me that '^DJI' is OK with Yahoo. The other symbols work there and also in my code so the only thing I can think of is that there is some filter at the Yahoo end that does not let ^DJI get through.

Larry

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Stock Indexes

Post by mwieder » Wed Aug 15, 2012 5:04 pm

I'm not quite sure what you are doing when you say this
Here's what Craig is talking about:

Code: Select all

    put "&f=l1c" into yahooConfig
    put "^DJI" into tStocks
    put "http://finance.yahoo.com/d/quotes.csv?s=" & tStocks & yahooConfig into myURL
If you ask for *just* the Dow Jones average, you can see that yahoo ignores it. For whatever reason, yahoo has chosen not to provide the Dow through its RESTful interface. There's nothing wrong with your code.

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Stock Indexes

Post by lohill » Wed Aug 15, 2012 5:51 pm

mweider,

Thanks for the RESTful clue. A little Googling found this for me from 2010.
Hello Tom,
Thank you for writing to Yahoo! Finance.
I understand you're reporting that you cannot download CSV data for ^DJI. I can certainly give you more information about this.
The limitation you are encountering is due to restrictions by the Dow Jones Index. Yahoo! is no longer able to provide Dow Jones Index data in this manner. I apologize for any inconvenience caused.
Please let me know if I can be of further assistance.
Thank you again for contacting Yahoo! Finance.

Regards,
Brett
Yahoo! Finance Customer Care
I am going to have to try other methods.
Larry

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Stock Indexes

Post by mwieder » Wed Aug 15, 2012 6:27 pm

You can try grabbing the data from http://finance.yahoo.com/q?s=^DJI&ql=1 and then screenscraping for the tag containing "^dji". Yahoo won't like it, but if you don't hit it too often you're probably OK.

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Stock Indexes

Post by lohill » Wed Aug 15, 2012 7:22 pm

mweider (Mark?),
You can try grabbing the data from http://finance.yahoo.com/q?s=^DJI&ql=1 and then screenscraping for the tag containing "^dji". Yahoo won't like it, but if you don't hit it too often you're probably OK.
I'll take a look at your suggestion.

In the interim I tried something interesting with revBrowser. Using the following code I was able to produce the information for AAPL in the rectangle but when I tried '^DJI' nothing was returned. The same was true for '^GSPC' and '^IXIC'.

Code: Select all

on mouseUp
   local tBrowserId
   put "http://finance.yahoo.com/q?s=AAPL"  into tURL
   put revBrowserOpen(the windowId of this stack, tURL) into tBrowserId
   revBrowserSet tBrowserId, "rect", "10,50,500,500"
   if tBrowserId is not an integer then
      answer "Failed to open browser"
      exit mouseup
   end if
   wait 5 seconds
   revBrowserClose tBrowserID
   answer "Done"
end mouseUp
Very interesting,

Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Stock Indexes

Post by lohill » Wed Aug 15, 2012 7:58 pm

What does the '&ql=1' do? It does not seem to make any difference whether or not it is there either in Safari or in my revBrowser code.

Thanks,
Larry

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Stock Indexes

Post by mwieder » Wed Aug 15, 2012 8:01 pm

No idea... yahoo put it into the url when I requested the latest report. You're right, it doesn't seem to make a difference.

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Stock Indexes

Post by mwieder » Wed Aug 15, 2012 8:06 pm

Give this a try:

Code: Select all

on mouseUp
    local tStocks
    local myURL
    local myRetrieve
    local tCharPos
    local tCurrentValue
    
    put "^DJI" into tStocks
    put "http://finance.yahoo.com/q?s=" & tStocks into myURL
    put url myURL into myRetrieve
    put offset("yfs_l10_" & tStocks & quote &  ">" , myRetrieve) into tCharPos
    if tCharPos > 0 then
        if matchtext(myRetrieve, "(?i)yfs_l10_.*" & char 2 to -1 of tStocks & quote & ">([0-9,.]+)" , tCurrentValue) then
            answer "found:" & tCurrentValue
        end if
    end if
end mouseUp

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Stock Indexes

Post by lohill » Wed Aug 15, 2012 10:18 pm

mwieder,
Give this a try:
Great! It works just fine. I now have to study it a bit to see if I can incorporate change and percentage change as well.

Thanks for taking the time to help.

Larry

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Stock Indexes

Post by lohill » Wed Aug 15, 2012 11:17 pm

WOW,

I have never used 'matchtext' before!

Larry

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3581
Joined: Mon Jan 22, 2007 7:36 am
Contact:

Re: Stock Indexes

Post by mwieder » Wed Aug 15, 2012 11:22 pm

Yeah, it's a little tricky to use, but if you can tweak the regex properly it's a very powerful tool to have around.

lohill
Posts: 770
Joined: Tue Dec 08, 2009 6:37 pm

Re: Stock Indexes

Post by lohill » Fri Aug 17, 2012 8:33 pm

mwieder,

You gave me this to help find the DOW value:
if matchtext(myRetrieve, "(?i)yfs_l10_.*" & char 2 to -1 of tStocks & quote & ">([0-9,.]+)" , tCurrentValue) then
I have made modifications in an attempt to get the percentage change in the index. This is close but it is not getting the value I want. With the semicolon in the pattern it gives me the EDT time (less the AM/PM). Without the semicolon it just gives me the first digit(s) of the time. The time is actually after the string I am trying to march in myChunk which is a subset (up to EDT or date) of myRetrieve.

Don't spend any time on it but if if you have a quick suggestion I'd appreciate it. I can manually calculate the poercentage if necessary because I have captured the 'Up'/'Down' number.

By the way, in your matchtext, what is the significance of the leading "(?i)"? Also, is the ".*" the equivalent of a wild card?

Thanks,
Larry

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1685
Joined: Sat Feb 28, 2009 11:49 pm

Re: Stock Indexes

Post by sturgis » Fri Aug 17, 2012 8:59 pm

Can't help with nailing down the exact pattern, but the (?i) means case insensitive. And yes, period '.' matches almost any char, and the * means match any number of the preceeding char. So if it was 7* it would match 7 and any number of 7's that follow. 7777777

Post Reply