mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add an example, strip out some blanks
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1524 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
64
src/quotes/Quote_example.pl
Executable file
64
src/quotes/Quote_example.pl
Executable file
@@ -0,0 +1,64 @@
|
||||
#! /usr/bin/perl -w
|
||||
#
|
||||
# example script showing how to use the Quote perl module.
|
||||
|
||||
use Quote;
|
||||
|
||||
# -----------------------------------
|
||||
# get quotes for two stocks ...
|
||||
%quotes = Quote::yahoo ("IBM", "SGI");
|
||||
|
||||
# print some selected values
|
||||
print "NYSE by Yahoo: ", $quotes {"IBM", "name"},
|
||||
" last price: ", $quotes {"IBM", "last"}, "\n";
|
||||
print "NYSE by Yahoo: ", $quotes {"SGI", "name"},
|
||||
" last price: ", $quotes {"SGI", "last"}, "\n";
|
||||
|
||||
# loop over and print all values.
|
||||
# Notes that values are stored ion a multi-dimensional associative array
|
||||
foreach $k (sort (keys %quotes)) {
|
||||
($sym, $attr) = split ($;, $k, 2);
|
||||
$val = $quotes {$sym, $attr};
|
||||
# $val = $quotes {$k}; # this also works, if desired ...
|
||||
print "\t$sym $attr =\t $val\n";
|
||||
}
|
||||
print "\n\n";
|
||||
|
||||
# -----------------------------------
|
||||
# get quotes from Fidelity Investments
|
||||
@funds = ("FGRIX", "FNMIX", "FASGX", "FCONX");
|
||||
%quotes = Quote::fidelity (@funds);
|
||||
|
||||
foreach $f (@funds) {
|
||||
$name = $quotes {$f, "name"};
|
||||
$nav = $quotes {$f, "nav"};
|
||||
print "Fidelity Fund $f $name \tNAV = $nav\n";
|
||||
}
|
||||
print "\n\n";
|
||||
|
||||
# -----------------------------------
|
||||
@funds = ("FGRXX");
|
||||
%quotes = Quote::fidelity (@funds);
|
||||
|
||||
print "Not all funds have a NAV; some have Yeilds:\n";
|
||||
foreach $f (@funds) {
|
||||
$name = $quotes {$f, "name"};
|
||||
$yield = $quotes {$f, "yield"};
|
||||
print "\tFidelity $f $name 30-day Yield = $yield percent\n";
|
||||
}
|
||||
print "\n\n";
|
||||
|
||||
# -----------------------------------
|
||||
# demo T. Rowe Price -- same as above
|
||||
@funds = ("PRFDX", "PRIDX");
|
||||
%quotes = Quote::troweprice (@funds);
|
||||
|
||||
foreach $f (@funds) {
|
||||
$nav = $quotes {$f, "nav"};
|
||||
$dayte = $quotes {$f, "date"};
|
||||
print "T. Rowe Price $f NAV = $nav as of $dayte\n";
|
||||
}
|
||||
print "\n\n";
|
||||
|
||||
|
||||
# -----------------------------------
|
||||
Reference in New Issue
Block a user