mirror of
https://github.com/Gnucash/gnucash.git
synced 2024-11-25 10:20:18 -06:00
[price-quotes] Remove superseded gnc-fq-dump and Quotes-example.pl
This commit is contained in:
parent
e817091de1
commit
673a925554
@ -1,6 +1,6 @@
|
||||
|
||||
set(_BIN_FILES "")
|
||||
foreach(file gnc-fq-update.in gnc-fq-dump.in finance-quote-wrapper.in)
|
||||
foreach(file gnc-fq-update.in finance-quote-wrapper.in)
|
||||
string(REPLACE ".in" "" _OUTPUT_FILE_NAME ${file})
|
||||
set(_ABS_OUTPUT_FILE ${BINDIR_BUILD}/${_OUTPUT_FILE_NAME})
|
||||
configure_file( ${file} ${_ABS_OUTPUT_FILE} @ONLY)
|
||||
@ -9,7 +9,7 @@ endforeach(file)
|
||||
|
||||
|
||||
set(_MAN_FILES "")
|
||||
foreach(file gnc-fq-dump finance-quote-wrapper)
|
||||
foreach(file finance-quote-wrapper)
|
||||
set(_POD_INPUT ${BINDIR_BUILD}/${file})
|
||||
set(_MAN_OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${file}.1)
|
||||
list(APPEND _MAN_FILES ${_MAN_OUTPUT})
|
||||
@ -26,4 +26,4 @@ add_custom_target(quotes-bin ALL DEPENDS ${_BIN_FILES})
|
||||
install(FILES ${_MAN_FILES} DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
|
||||
install(PROGRAMS ${_BIN_FILES} DESTINATION ${CMAKE_INSTALL_BINDIR})
|
||||
|
||||
set_dist_list(quotes_DIST CMakeLists.txt gnc-fq-dump.in gnc-fq-update.in finance-quote-wrapper.in Quote_example.pl README)
|
||||
set_dist_list(quotes_DIST CMakeLists.txt gnc-fq-update.in finance-quote-wrapper.in README)
|
||||
|
@ -1,90 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
##@file
|
||||
# @brief
|
||||
# example script showing how to use the Quote perl module.
|
||||
# gets prices for some stocks, for some mutual funds
|
||||
#
|
||||
# Note that this example uses the meta-level "fetch" command. We do
|
||||
# NOT used that in Gnucash because it's behavior is unpredictable If
|
||||
# the given method/exchange doesn't work, it'll fall back to other
|
||||
# methods, and I've seen no guarantee that all exchanges treat all
|
||||
# symbols the same. So in Gnucash, we use the backend methods
|
||||
# directly, i.e. $quoter->fidelity_direct("IBM", "LNUX");, etc. The
|
||||
# documentation page for each Finance::Quote sub-module describes how
|
||||
# to call it directly without fallbacks.
|
||||
#
|
||||
# @cond PERL
|
||||
|
||||
use Finance::Quote;
|
||||
|
||||
# Create a quote object.
|
||||
my $quoter = Finance::Quote->new();
|
||||
|
||||
# -----------------------------------
|
||||
# get quotes for two stocks ...
|
||||
%quotes = $quoter->fetch("alphavantage","IBM", "SGI");
|
||||
|
||||
# print some selected values
|
||||
print "NYSE by Alphavantage: ", $quotes {"IBM", "name"},
|
||||
" last price: ", $quotes {"IBM", "last"}, "\n";
|
||||
print "NYSE by Alphavantage: ", $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 = $quoter->fetch("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 = $quoter->fetch("fidelity",@funds);
|
||||
|
||||
print "Not all funds have a NAV; some have Yields:\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 = $quoter->fetch("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";
|
||||
|
||||
|
||||
# -----------------------------------
|
||||
|
||||
# demo for ASX. Grab the price of Coles-Myer and Telstra
|
||||
@funds = ("CML","TLS");
|
||||
%quotes = $quoter->fetch("australia",@funds);
|
||||
foreach $f (@funds) {
|
||||
print "ASX Price of $f is ".$quotes{$f,"last"}." at ".
|
||||
$quotes{$f,"date"}."\n";
|
||||
}
|
||||
print "\n\n";
|
||||
##@endcond Perl
|
@ -8,12 +8,6 @@ finance-quote-wrapper.in:
|
||||
allows gnucash to communicate with Finance::Quote.
|
||||
The requests and responses are in json format.
|
||||
|
||||
gnc-fq-dump.in:
|
||||
|
||||
Source file for gnc-fq-dump which is a perl script that retrieves
|
||||
a quote from Finance::Quote and dumps the response to the terminal.
|
||||
Its useful for determining problems with F::Q.
|
||||
|
||||
gnc-fq-update.in:
|
||||
|
||||
Source file for gnc-fq-update which is a perl script that updates
|
||||
|
@ -1,242 +0,0 @@
|
||||
#!@PERL@ -w
|
||||
#
|
||||
# Copyright (C) 2003, David Hampton <hampton@employees.org>
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
||||
# 02110-1301, USA.
|
||||
#
|
||||
|
||||
use strict;
|
||||
|
||||
sub check_modules {
|
||||
my @modules = qw(Finance::Quote);
|
||||
my @missing;
|
||||
|
||||
foreach my $mod (@modules) {
|
||||
if (eval "require $mod") {
|
||||
$mod->import();
|
||||
}
|
||||
else {
|
||||
push (@missing, $mod);
|
||||
}
|
||||
}
|
||||
|
||||
return unless @missing;
|
||||
|
||||
print STDERR "$0 cannot find all the Perl modules needed to run.\n";
|
||||
print STDERR "You need to install the following Perl modules:\n";
|
||||
foreach my $mod (@missing) {
|
||||
print STDERR " ".$mod."\n";
|
||||
}
|
||||
print STDERR "Use your system's package manager to install them,\n";
|
||||
print STDERR "or run 'gnc-fq-update' as root.\n";
|
||||
|
||||
exit 1;
|
||||
}
|
||||
|
||||
sub report {
|
||||
my($itemname, $qh, $verbose) = @_;
|
||||
my ($symbol, $date, $currency, $last, $nav, $price, $timezone, $keyname);
|
||||
my($gccanuse, $gcshoulduse) = (1, 1);
|
||||
|
||||
# Sanity check returned results
|
||||
if ((keys %$qh) < 1) {
|
||||
printf("No results found for stock $itemname.\n");
|
||||
return;
|
||||
} else {
|
||||
my ($stock, $attribute, %seen, $first);
|
||||
|
||||
foreach $keyname (sort keys %$qh) {
|
||||
($stock, $attribute) = split('\034', $keyname);
|
||||
last if $stock eq $itemname;
|
||||
$first = $stock if !defined $first;
|
||||
$seen{$stock} = 1;
|
||||
}
|
||||
|
||||
if ($stock ne $itemname) {
|
||||
printf "\nNo results found for stock $itemname, but results were returned for\n";
|
||||
printf "the stock(s) %s. ", join(", ", keys(%seen));
|
||||
printf "Printing data for the first stock returned.\n\n";
|
||||
|
||||
# Print stats for the first stock returned.
|
||||
$itemname = $first;
|
||||
}
|
||||
}
|
||||
|
||||
# Parse the quote fields and put warnings where necessary.
|
||||
if (defined($$qh{$itemname, "symbol"})) {
|
||||
$symbol = $$qh{$itemname, "symbol"};
|
||||
} else {
|
||||
$symbol = "$itemname (deduced)";
|
||||
$gccanuse = 0;
|
||||
}
|
||||
if (defined($$qh{$itemname, "date"})) {
|
||||
$date = $$qh{$itemname, "date"};
|
||||
} else {
|
||||
$date = "** missing **";
|
||||
$gcshoulduse = 0;
|
||||
}
|
||||
if (defined($$qh{$itemname, "currency"})) {
|
||||
$currency = $$qh{$itemname, "currency"};
|
||||
} else {
|
||||
$currency = "** missing **";
|
||||
$gccanuse = 0;
|
||||
}
|
||||
if ((!defined($$qh{$itemname, "last"})) &&
|
||||
(!defined($$qh{$itemname, "nav" })) &&
|
||||
(!defined($$qh{$itemname, "price"}))) {
|
||||
$$qh{$itemname, "last"} = "**missing**";
|
||||
$$qh{$itemname, "nav"} = "**missing**";
|
||||
$$qh{$itemname, "price"} = "**missing**";
|
||||
$gccanuse = 0;
|
||||
}
|
||||
$last = defined($$qh{$itemname, "last"})
|
||||
? $$qh{$itemname, "last"} : "";
|
||||
$nav = defined($$qh{$itemname, "nav"})
|
||||
? $$qh{$itemname, "nav"} : "";
|
||||
$price = defined($$qh{$itemname, "price"})
|
||||
? $$qh{$itemname, "price"} : "";
|
||||
$timezone = defined($$qh{$itemname, "timezone"})
|
||||
? $$qh{$itemname, "timezone"} : "";
|
||||
|
||||
# Dump gnucash recognized fields
|
||||
printf "Finance::Quote fields Gnucash uses:\n";
|
||||
printf " symbol: %-20s <=== required\n", $symbol;
|
||||
printf " date: %-20s <=== recommended\n", $date;
|
||||
printf " currency: %-20s <=== required\n", $currency;
|
||||
printf " last: %-20s <=\\\n", $last;
|
||||
printf " nav: %-20s <=== one of these\n", $nav;
|
||||
printf " price: %-20s <=/\n", $price;
|
||||
printf " timezone: %-20s <=== optional\n", $timezone;
|
||||
|
||||
# Report failure
|
||||
if ($gccanuse == 0) {
|
||||
printf "\n** This stock quote cannot be used by GnuCash!\n\n";
|
||||
} elsif ($gcshoulduse == 0) {
|
||||
printf "\n** This quote will have today's date, which might be incorrect.\n";
|
||||
printf " GnuCash will use it, but you might prefer that it doesn't.\n\n";
|
||||
}
|
||||
# Dump all fields if requested
|
||||
if ($verbose) {
|
||||
printf "\nAll fields returned by Finance::Quote for stock $itemname\n\n";
|
||||
printf "%-10s %10s %s\n", "stock", "field", "value";
|
||||
printf "%-10s %10s %s\n", "-----", "-----", "-----";
|
||||
foreach $keyname (sort keys %$qh) {
|
||||
my ($stock, $key) = split('\034', $keyname);
|
||||
printf "%-10s %10s: %s\n", $stock, $key, $$qh{$stock, $key};
|
||||
}
|
||||
print "\n";
|
||||
}
|
||||
}
|
||||
|
||||
sub chk_api_key {
|
||||
my $exch = $_[0];
|
||||
my $url = " https://wiki.gnucash.org/wiki/Online_Quotes#Source_Alphavantage.2C_US\n";
|
||||
if (($exch eq "currency") || ($exch eq "alphavantage")
|
||||
|| ($exch eq "vanguard")) {
|
||||
die "ERROR: ALPHAVANTAGE_API_KEY *must* be set for currency quotes and\n" .
|
||||
"stock quotes with source 'alphavantage' or 'vanguard'; see\n" . $url
|
||||
unless (defined ($ENV{'ALPHAVANTAGE_API_KEY'}));
|
||||
}
|
||||
if (($exch eq "canada") || ($exch eq "nasdaq")
|
||||
|| ($exch eq "nyse") || ($exch eq "usa")) {
|
||||
printf("WARNING: Multiple Source '%s' will not be able to use alphavantage " .
|
||||
"unless ALPHAVANTAGE_API_KEY is set; see\n%s", $exch, $url)
|
||||
unless (defined ($ENV{'ALPHAVANTAGE_API_KEY'}));
|
||||
}
|
||||
}
|
||||
|
||||
############## end of functions - start mainline #########################
|
||||
|
||||
# Check for and load non-standard modules
|
||||
check_modules ();
|
||||
|
||||
my $q = Finance::Quote->new;
|
||||
$q->timeout(60);
|
||||
|
||||
if ($#ARGV < 1) {
|
||||
my @sources = sort $q->sources();
|
||||
printf "\nUsage: $0 [-v] <quote-source> <stock> [<stock> ...]\n\n";
|
||||
printf "-v: verbose\n";
|
||||
printf "Available sources are:\n %s\n\n", join(' ', @sources);
|
||||
exit 0;
|
||||
}
|
||||
|
||||
my $verbose = 0;
|
||||
if ($ARGV[0] eq "-v") {
|
||||
$verbose = 1;
|
||||
shift;
|
||||
}
|
||||
|
||||
my $exchange = shift;
|
||||
chk_api_key ($exchange);
|
||||
if ($exchange eq "currency") {
|
||||
my $from = shift;
|
||||
while ($#ARGV >= 0) {
|
||||
my $to = shift;
|
||||
my $result = $q->currency($from, $to);
|
||||
# Sometimes quotes are available in only one direction.
|
||||
# If we didn't get the one we wanted try the reverse quote
|
||||
unless (defined($result)) {
|
||||
my $inv_res = $q->currency($to, $from);
|
||||
if (defined($inv_res)) {
|
||||
my $tmp = $to;
|
||||
$to = $from;
|
||||
$from = $tmp;
|
||||
$result = $inv_res;
|
||||
}
|
||||
}
|
||||
if (defined($result)) {
|
||||
printf "1 $from = $result $to\n";
|
||||
} else {
|
||||
printf "1 $from = <unknown> $to\n";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while ($#ARGV >= 0) {
|
||||
my $stock = shift;
|
||||
my %quotes = $q->fetch($exchange, $stock);
|
||||
report($stock, \%quotes, $verbose);
|
||||
if ($#ARGV >= 0) {
|
||||
printf "=====\n\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
=head1 NAME
|
||||
|
||||
gnc-fq-dump - Print out data from the F::Q module
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
Currency Exchange Rates
|
||||
gnc-fq-dump currency USD AUD
|
||||
gnc-fq-dump [-v] yahoo_json USDEUR=X
|
||||
Stock Quotes
|
||||
gnc-fq-dump [-v] alphavantage CSCO JNPR
|
||||
gnc-fq-dump [-v] alphavantage BAESY.PK
|
||||
gnc-fq-dump [-v] yahoo_json CBA.AX
|
||||
gnc-fq-dump [-v] europe 48406.PA 13000.PA
|
||||
gnc-fq-dump [-v] vwd 632034
|
||||
gnc-fq-dump [-v] ftportfolios FKYGTX
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
This program obtains information from Finance::Quote about any
|
||||
specified stock, and then dumps it to the screen in annotated form.
|
||||
This will allow someone to see what is returned, and whether it
|
||||
provides all the information needed by Gnucash.
|
||||
|
||||
=cut
|
Loading…
Reference in New Issue
Block a user