[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [RT] Downloading Yahoo Quotes



PureBytes Links

Trading Reference Links

Got Linux?


The `get_daily' script below takes one or more Yahoo! stock/index
symbols on the command line, and builds a data file, $sym.dat, for each
symbol, containing the data downloaded from Yahoo! It doesn't first
check to see if the data file already, exists, and to begin where it
left off - it downloads the entire file again.

---- get_daily ----
#!/bin/csh -f
# get_daily symbols ...
set dt = `date +"&d=%m&e=%d&f=%Y"`
foreach x ($*)
    set sym = `echo $x | sed -e 's/^^//' | tr "[A-Z]" "[a-z]"`
    lynx -dump
'http://chart.yahoo.com/table.csv?s='"$x"'&a=1&b=10&c=28'"$dt"'&g=d&q=q&
y=0&z='"$x"'&x=.csv'  | awk -f yahoo_data.awk > $sym.dat
end

---- yahoo_data.awk ---
BEGIN { FS = ","; mnames = "JanFebMarAprMayJunJulAugSepOctNovDec" }
NR > 1 {
#Date,Open,High,Low,Close,Volume
ddate = $1; dopen = $2; dhigh = $3; dlow = $4; dclose = $5; dvolume = $6
   nf = split(ddate, fld, "-")
   if (nf == 1) {
       nf = split(ddate, fld, " ")
       if (nf == 2) {
           fld[3] = fld[2]
           fld[2] = fld[1]
           fld[1] = "01"
           nf = 3
       }
   }
   if (nf != 3) {
      printf "date in error on line %d\n", NR
      printf "|%s|\n", $0
      next
   }
   dd = fld[1] + 0
   mm = int((index(mnames, fld[2]) + 2) / 3)
   if (mm < 1 || mm > 12) {
      printf "date in error on line %d\n", NR
      printf "|%s|\n", $0
      next
   }
   yy = fld[3] + 1900
   if (yy < 1920) yy += 100
   yymmdd = yy * 10000 + mm * 100  + dd
   printf "%8d%12.4f%12.4f%12.4f%12.4f%12d\n", \
       yymmdd, dopen, dhigh, dlow, dclose, dvolume | "sort +0n"
}

-----Original Message-----
From: Brooks Rimes
Sent: Thursday, July 19, 2001 6:53 PM
Subject: [RT] Downloading Yahoo Quotes


Are there any other programmers out there who have written code to
download historical quotes from Yahoo?


To unsubscribe from this group, send an email to:
realtraders-unsubscribe@xxxxxxxxxxxxxxx

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/