Category: | Web Stuff |
Author/Contact Info | cacharbe Chuck Charbeneau ccharbeneau@lear.com |
Description: | A while back I had to re-write our intranet stock listing application that retreived stock information from the Yahoo! finance site (I didn't write the original). It was a huge cluge, and took forever to render, as each stock symbol, 401k symbol etc, was a seperate LWP request, and each request had to be parsed for the necessary data. The application began breaking down when Yahoo went through some major HTML/Display rewrites. While working on the re-write I discovered something that turned 75 LWP requests into two requests; one for the indices information, and one for the list of symbols for which I needed data. The discovery was that Yahoo has a publically facing application server that offers up all financial data in CSV rather than html. I could request ALL the symbols I needed at once, and it was returned in orderly, well formatted, easy to parse CSV. Needless to say, I saw a significant performance increase. Yesterday I was asked if I could create a small web application that allowed users to get current currency exchange rates, and rather than re-inventing the wheel, I went back to the stock work I had done and found that the same server would do the exchange for you if given the correct URL. I have included an example of a correct URL, but I am leaving getting the correct Country Currency codes as an exercise to the user. They are readily available from a few different sources.
Usage might be somethig like:
C-. |
sub GetFactor { my ($symbol) = @_; #Expects either ^Xyy where yy = 2 letter code o +r AAABBB=X #WHERE A and B are Official three letter Countr +y Codes, AAA # being the 'From' money, and BBB #being the 'To' money ex. Us dollar to British +Pound would be #USDGBP=X my $src_url = "http://finance.yahoo.com/d/quotes.csv?f=snl1d1t1c1o +hgv&e=.csv&s=".$symbol; $ua = new LWP::UserAgent; $ua->proxy(http => 'http://<PROXY INFO>'); $ua->agent('Mozilla/2.0 (compatible; MSIE 3.02; Win32)'); $ua->timeout(30); $req = new HTTP::Request GET => $src_url; $req->proxy_authorization_basic('<USERNAME>', '<PWD>'); $resp = $ua->request($req); if (!$resp->is_success || !$resp) { $errmsg = "<FONT COLOR=#FF0000>Failed to retrieve stock indice +s --". $resp->Status_line ." $!</FONT>"; print "$errmsg<br>\n"; die; } #$resp->Format = <SYMBOL>,"<SOURCE>",<FACTOR>,"<LAST TRADE DATE>", +"<LAST TRADE TIME>",N/A,N/A,N/A,N/A,N/A return split /,/,$resp->content; } |
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Yahoo Currency Exchange Interface
by merlyn (Sage) on Dec 14, 2001 at 01:40 UTC | |
by cacharbe (Curate) on Dec 14, 2001 at 01:49 UTC | |
by merlyn (Sage) on Dec 14, 2001 at 01:51 UTC | |
by cacharbe (Curate) on Dec 14, 2001 at 02:05 UTC | |
by rob_au (Abbot) on Dec 14, 2001 at 08:48 UTC | |
| |
by pjf (Curate) on Dec 14, 2001 at 15:31 UTC | |
by sparkyichi (Deacon) on Dec 14, 2001 at 02:13 UTC |