Coder Social home page Coder Social logo

finance-quote's Introduction

NAME

Finance::Quote - Get stock and mutual fund quotes from various exchanges

SYNOPSIS

use Finance::Quote;

$q = Finance::Quote->new;
%quotes  = $q->fetch("nasdaq", @stocks);

DESCRIPTION

This module gets stock quotes from various internet sources all over the world. Quotes are obtained by constructing a quoter object and using the fetch method to gather data, which is returned as a two-dimensional hash (or a reference to such a hash, if called in a scalar context). For example:

$q = Finance::Quote->new;
%info = $q->fetch("australia", "CML");
print "The price of CML is ".$info{"CML", "price"};

The first part of the hash (eg, "CML") is referred to as the stock. The second part (in this case, "price") is referred to as the label.

LABELS

When information about a stock is returned, the following standard labels may be used. Some custom-written modules may use labels not mentioned here. If you wish to be certain that you obtain a certain set of labels for a given stock, you can specify that using require_labels().

ask          Ask
avg_vol      Average Daily Vol
bid          Bid
cap          Market Capitalization
close        Previous Close
currency     Currency code for the returned data
date         Last Trade Date  (MM/DD/YY format)
day_range    Day's Range
div          Dividend per Share
div_date     Dividend Pay Date
div_yield    Dividend Yield
eps          Earnings per Share
errormsg     If success is false, this field may contain the reason why.
ex_div       Ex-Dividend Date.
exchange     The exchange the information was obtained from.
high         Highest trade today
isin         International Securities Identification Number
isodate      ISO 8601 formatted date 
last         Last Price
low          Lowest trade today
method       The module (as could be passed to fetch) which found this information.
name         Company or Mutual Fund Name
nav          Net Asset Value
net          Net Change
open         Today's Open
p_change     Percent Change from previous day's close
pe           P/E Ratio
success      Did the stock successfully return information? (true/false)
time         Last Trade Time
type         The type of equity returned
volume       Volume
year_range   52-Week Range
yield        Yield (usually 30 day avg)

If all stock lookups fail (possibly because of a failed connection) then the empty list may be returned, or undef in a scalar context.

INSTALLATION

Please note that the Github repository is not meant for general users of Finance::Quote for installation.

If you downloaded the Finance-Quote-N.NN.tar.gz tarball from CPAN (N.NN is the version number, ex: Finance-Quote-1.50.tar.gz), run the following commands:

tar xzf Finance-Quote-1.50.tar.gz
cd Finance-Quote-1.50.tar.gz
perl Makefile.PL
make
make test
make install

If you have the CPAN module installed: Using cpanm (Requires App::cpanminus)

cpanm Finance::Quote

or Using CPAN shell

perl -MCPAN -e shell
install Finance::Quote

SUPPORT AND DOCUMENTATION

After installing, you can find documentation for this module with the perldoc command.

perldoc Finance::Quote

You can also look for information at:

PUBLIC CLASS METHODS

Finance::Quote implements public class methods for constructing a quoter object, getting or setting default class values, and for listing available methods.

new

my $q = Finance::Quote->new()
my $q = Finance::Quote->new('-defaults')
my $q = Finance::Quote->new(timeout => 30)
my $q = Finance::Quote->new('YahooJSON', fetch_currency => 'EUR')
my $q = Finance::Quote->new('alphavantage' => {API_KEY => '...'})
my $q = Finance::Quote->new('IEXCloud', 'iexcloud' => {API_KEY => '...'});
my $q = Finance::Quote->new(currency_rates => {order => ['ECB', 'Fixer'], 'fixer' => {API_KEY => '...'}});

Finance::Quote modules access a wide range of sources to provide quotes. A module provides one or more methods to fetch quotes. One method is usually the name of the module in lower case. Other methods, if provided, are descriptive names, such as 'canada', 'nasdaq', or 'nyse'.

A Finance::Quote object uses one or more methods to fetch quotes for securities.

new constructs a Finance::Quote object and enables the caller to load only specific modules, set parameters that control the behavior of the fetch method, and pass method specific parameters.

  • timeout = T> sets the web request timeout to T seconds
  • failover = B> where B is a boolean value indicating if failover in fetch is permitted
  • fetch_currency = C> sets the desired currency code to C for fetch results
  • currency_rates = H> configures the order currency rate modules are consulted for exchange rates and currency rate module options
  • required_labels = A> sets the required labels for fetch results to array A
  • <ModuleName> as a string is the name of a specific Finance::Quote::Module to load
  • <methodname => H> passes hash H to methodname during fetch to configure the method

With no arguments, new creates a Finance::Quote object with the default methods. If the environment variable FQ_LOAD_QUOTELET is set, then the contents of FQ_LOAD_QUOTELET (split on whitespace) will be used as the argument list. This allows users to load their own custom modules without having to change existing code. If any method names are passed to new or the flag '-defaults' is included in the argument list, then FQ_LOAD_QUOTELET is ignored.

When new() is passed one or more class name arguments, an object is created with only the specified modules loaded. If the first argument is '-defaults', then the default modules will be loaded first, followed by any other specified modules. Note that the FQ_LOAD_QUOTELET environment variable must begin with '-defaults' if you wish the default modules to be loaded.

Method names correspond to the Perl module in the Finance::Quote module space. For example, Finance::Quote-new('ASX')> will load the module Finance::Quote::ASX, which provides the method "asx".

Some methods require API keys or have unique options. Passing 'method => HASH' to new() enables the caller to provide a configuration HASH to the corresponding method.

The key 'currency_rates' configures the Finanace::Quote currency rate conversion. By default, to maintain backward compatibility, Finance::Quote::CurrencyRates::AlphaVantage is used for currency conversion. This end point requires an API key, which can either be set in the environment or included in the configuration hash. To specify a different primary currency conversion method or configure fallback methods, include the 'order' key, which points to an array of Finance::Quote::CurrencyRates module names. Setting the environment variable FQ_CURRENCY will change the default endpoint used for currency conversion. See the documentation for the individual Finance::Quote::CurrencyRates to learn more.

get_default_currency_fields

my @fields = Finance::Quote::get_default_currency_fields();

get_default_currency_fields returns the standard list of fields in a quote that are automatically converted during currency conversion. Individual modules may override this list.

get_default_timeout

my $value = Finance::Quote::get_default_timeout();

get_default_timeout returns the current Finance::Quote default timeout in seconds for web requests. Finance::Quote does not specify a default timeout, deferring to the underlying user agent for web requests. So this function will return undef unless set_default_timeout was previously called.

set_default_timeout

Finance::Quote::set_default_timeout(45);

set_default_timeout sets the Finance::Quote default timeout to a new value.

get_methods

my @methods = Finance::Quote::get_methods();

get_methods returns the list of methods that can be passed to new when creating a quoter object and as the first argument to fetch.

get_features

my %features = Finance::Quote::get_features();

get_features returns a hash with three keys: quote_methods, quote_modules, and currency_modules.

$features{quote_methods} is a hash with key/value pairs of method_name => [array of module names]
$features{quote_modules} is a hash with key/value pairs of module_name => [array of parameter names]
$features{currency_modules} is a hash with key/value pairs of currency_module_name => [array of paramater names]

Parameter names are values that the module needs to function, such as API_KEY. Most modules will have an empty list. Modules with a parameter are configured when creating the Finance::Quote by passing the argument

'module_name_in_lower_case' => {paramter => value}

to Finance::Quote->new().

The keys of the $features{currency_modules} hash are the names of currency modules that can be used for currency conversion and the order in which the modules are used is controlled by the argument

currency_rates => {order => [subset of $features{currency_modules}]} 

to Finance::Quote->new(). By default, only AlphaVantage in used for currency conversion, so "order" must be set to use other currency modules.

PUBLIC OBJECT METHODS

B_to_billions

my $value = $q->B_to_billions("20B");

B_to_billions is a utility function that expands a numeric string with a "B" suffix to the corresponding multiple of 1000000000.

decimal_shiftup

my $value = $q->decimal_shiftup("123.45", 1);  # returns 1234.5
my $value = $q->decimal_shiftup("0.25", 1);    # returns 2.5

decimal_shiftup moves a the decimal point in a numeric string the specified number of places to the right.

fetch

my %stocks  = $q->fetch("alphavantage", "IBM", "MSFT", "LNUX");
my $hashref = $q->fetch("nasdaq", "IBM", "MSFT", "LNUX");

fetch takes a method as its first argument and the remaining arguments are treated as securities. If the quoter $q was constructed with a specific method or methods, then only those methods are available.

When called in an array context, a hash is returned. In a scalar context, a reference to a hash will be returned. The keys for the returned hash are {SECURITY,LABEL}. For the above example call, $stocks{"IBM","high"} is the high value for IBM.

$q->get_methods() returns the list of valid methods for quoter object $q. Some methods specify a specific Finance::Quote module, such as 'alphavantage'. Other methods are available from multiple Finance::Quote modules, such as 'nasdaq'. The quoter failover over option determines if multiple modules are consulted for methods such as 'nasdaq' that more than one implementation.

get_failover

my $failover = $q->get_failover();

Failover is when the fetch method attempts to retrieve quote information for a security from alternate sources when the requested method fails. get_failover returns a boolean value indicating if the quoter object will use failover or not.

set_failover

$q->set_failover(False);

set_failover sets the failover flag on the quoter object.

get_fetch_currency

my $currency = $q->get_fetch_currency();

get_fetch_currency returns either the desired currency code for the quoter object or undef if no target currency was set during construction or with the set_fetch_currency function.

set_fetch_currency

$q->set_fetch_currency("FRF");  # Get results in French Francs.

set_fetch_currency method is used to request that all information be returned in the specified currency. Note that this increases the chance stock-lookup failure, as remote requests must be made to fetch both the stock information and the currency rates. In order to improve reliability and speed performance, currency conversion rates are cached and are assumed not to change for the duration of the Finance::Quote object.

See the introduction to this page for information on how to configure the source of currency conversion rates.

get_required_labels

my @labels = $q->get_required_labels();

get_required_labels returns the list of labels that must be populated for a security quote to be considered valid and returned by fetch.

set_required_labels

my $labels = ['close', 'isodate', 'last'];
$q->set_required_labels($labels);

set_required_labels updates the list of required labels for the quoter object.

get_timeout

my $timeout = $q->get_timeout();

get_timeout returns the timeout in seconds the quoter object is using for web requests.

set_timeout

$q->set_timeout(45);

set_timeout updated the timeout in seconds for the quoter object.

store_date

$quoter->store_date(\%info, $stocks, {eurodate => '06/11/2020'});

store_date is used by modules to consistent store date information about securities. Given the various pieces of a date, this function figures out how to construct a ISO date (yyyy-mm-dd) and US date (mm/dd/yyyy) and stores those values in %info for security $stock.

get_user_agent

my $ua = $q->get_user_agent();

get_user_agent returns the LWP::UserAgent the quoter object is using for web requests.

isoTime

$q->isoTime("11:39PM");    # returns "23:39"
$q->isoTime("9:10 AM");    # returns "09:10"

isoTime returns an ISO formatted time.

PUBLIC CLASS OR OBJECT METHODS

The following methods are available as class methods, but can also be called from Finance::Quote objects.

scale_field

my $value = Finance::Quote->scale_field('1023', '0.01')

scale_field is a utility function that scales the first argument by the second argument. In the above example, value is '10.23'.

currency

my $value = $q->currency('15.95 USD', 'AUD');
my $value = Finance::Quote->currency('23.45 EUR', 'RUB');

currency converts a value with a currency code suffix to another currency using the current exchange rate as determined by the Finance::Quote::CurrencyRates method or methods configured for the quoter $q. When called as a class method, only Finance::Quote::AlphaVantage is used, which requires an API key. See the introduction for information on configuring currency rate conversions and see Finance::Quote::CurrencyRates::AlphaVantage for information about the API key.

currency_lookup

my $currency = $quoter->currency_lookup();
my $currency = $quoter->currency_lookup( name => "Caribbean");
my $currency = $quoter->currency_loopup( country => qw/denmark/i );
my $currency = $q->currency_lookup(country => qr/united states/i, number => 840);

currency_lookup takes zero or more constraints and filters the list of currencies known to Finance::Quote. It returns a hash reference where the keys are ISO currency codes and the values are hash references containing metadata about the currency.

A constraint is a key name and either a scalar or regular expression. A currency satisfies the constraint if its metadata hash contains the constraint key and the value of that metadata field matches the regular expression or contains the constraint value as a substring. If the metadata field is an array, then it satisfies the constraint if any value in the array satisfies the constraint.

parse_csv

my @list = Finance::Quote::parse_csv($string);

parse_csv is a utility function for splitting a comma separated value string into a list of terms, treating double-quoted strings that contain commas as a single value.

parse_csv_semicolon

my @list = Finance::Quote::parse_csv_semicolon($string);

parse_csv is a utility function for splitting a semicolon separated value string into a list of terms, treating double-quoted strings that contain semicolons as a single value.

LEGACY METHODS

default_currency_fields

Replaced with get_default_currency_fields().

sources

Replaced with get_methods().

failover

Replaced with get_failover() and set_failover().

require_labels

Replaced with get_required_labels() and set_required_labels().

user_agent

Replaced with get_user_agent().

set_currency

Replaced with get_fetch_currency() and set_fetch_currency().

ENVIRONMENT

Finance::Quote respects all environment that your installed version of LWP::UserAgent respects. Most importantly, it respects the http_proxy environment variable.

BUGS

The caller cannot control the fetch failover order.

The two-dimensional hash is a somewhat unwieldly method of passing around information when compared to references

COPYRIGHT & LICENSE

Copyright 1998, Dj Padzensky
Copyright 1998, 1999 Linas Vepstas
Copyright 2000, Yannick LE NY (update for Yahoo Europe and YahooQuote)
Copyright 2000-2001, Paul Fenwick (updates for ASX, maintenance and release)
Copyright 2000-2001, Brent Neal (update for TIAA-CREF)
Copyright 2000 Volker Stuerzl (DWS)
Copyright 2001 Rob Sessink (AEX support)
Copyright 2001 Leigh Wedding (ASX updates)
Copyright 2001 James Treacy (TD Waterhouse support)
Copyright 2008 Erik Colson (isoTime)

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.

Currency information fetched through this module is bound by the terms and conditons of the data source.

Other copyrights and conditions may apply to data fetched through this module. Please refer to the sub-modules for further information.

AUTHORS

Dj Padzensky <[email protected]>, PadzNet, Inc.
Linas Vepstas <[email protected]>
Yannick LE NY <[email protected]>
Paul Fenwick <[email protected]>
Brent Neal <[email protected]>
Volker Stuerzl <[email protected]>
Keith Refson <Keith.Refson#earth.ox.ac.uk>
Rob Sessink <[email protected]>
Leigh Wedding <[email protected]>
Tobias Vancura <[email protected]>
James Treacy <[email protected]>
Bradley Dean <[email protected]>
Erik Colson <[email protected]>

The Finance::Quote home page can be found at http://finance-quote.sourceforge.net/

The Finance::YahooQuote home page can be found at http://www.padz.net/~djpadz/YahooQuote/

The GnuCash home page can be found at http://www.gnucash.org/

SEE ALSO

Finance::Quote::CurrencyRates::AlphaVantage,
Finance::Quote::CurrencyRates::ECB,
Finance::Quote::CurrencyRates::Fixer,
Finance::Quote::CurrencyRates::OpenExchange,
Finance::Quote::CurrencyRates::YahooJSON,
Finance::Quote::AEX,
Finance::Quote::ASEGR,
Finance::Quote::ASX,
Finance::Quote::Bloomberg,
Finance::Quote::BSEIndia,
Finance::Quote::Bourso,
Finance::Quote::BVB,
Finance::Quote::CSE,
Finance::Quote::Comdirect,
Finance::Quote::Consorsbank,
Finance::Quote::Currencies,
Finance::Quote::DWS,
Finance::Quote::Deka,
Finance::Quote::FTfunds,
Finance::Quote::Finanzpartner,
Finance::Quote::Fondsweb,
Finance::Quote::GoldMoney,
Finance::Quote::GoogleWeb,
Finance::Quote::HU,
Finance::Quote::IEXCloud,
Finance::Quote::IndiaMutual,
Finance::Quote::MarketWatch,
Finance::Quote::MorningstarAU,
Finance::Quote::MorningstarCH,
Finance::Quote::MorningstarJP,
Finance::Quote::MorningstarUK,
Finance::Quote::NSEIndia,
Finance::Quote::NZX,
Finance::Quote::OnVista,
Finance::Quote::Oslobors,
Finance::Quote::SEB,
Finance::Quote::SIX,
Finance::Quote::TSP,
Finance::Quote::TMX,
Finance::Quote::Tiaacref,
Finance::Quote::TesouroDireto,
Finance::Quote::TreasuryDirect,
Finance::Quote::Troweprice,
Finance::Quote::TwelveData,
Finance::Quote::Union,
Finance::Quote::YahooJSON,
Finance::Quote::YahooWeb,
Finance::Quote::ZA

You should have received the Finance::Quote hacker's guide with this package. Please read it if you are interested in adding extra methods to this package. The latest hacker's guide can also be found on GitHub at https://github.com/finance-quote/finance-quote/blob/master/Documentation/Hackers-Guide

finance-quote's People

Contributors

alex314159 avatar andre-j avatar bgr22112 avatar bit81 avatar bjdean avatar bpschuck avatar e-dorigatti avatar ecocode avatar fabrica64 avatar fritteli avatar goodvibes2 avatar gregoa avatar hiranya avatar jhaiduce avatar jvolkening avatar linas avatar mtalexander avatar mumpitzstuff avatar pghmcfc avatar pjf avatar s7eph4n avatar shastry avatar sigvei avatar skaringa avatar ste-zz avatar thinuspollard avatar vincentl avatar x42x64 avatar yrro avatar zedthou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

finance-quote's Issues

Currency is missing for stocks from Moscow Stock Exchange from AlphaVantage

Trying to query some stocks from Moscow Stock Exchange, and I get

gnc-fq-dump alphavantage RUAL.ME 
Finance::Quote fields Gnucash uses:
    symbol: RUAL.ME              <=== required
      date: 11/10/2017           <=== required
  currency: ** missing **        <=== required
      last: 40.7500              <=\       
       nav:                      <=== one of these
     price:                      <=/        
  timezone:                      <=== optional

** This stock quote cannot be used by gnucash!!

The currency for all Moscow Stock Exchange stocks (that end with .ME suffix) should be RUB (Russian Ruble).

Yahoo stopped working for good

It appears that Yahoo has shut down its quote service entirely. When you access the URL you now get:

It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com.

And there is a forum thread confirming the decision to shut it down.

ALPHAVANTAGE_API_KEY warning on every use by default

Since the addition of the AlphaVantage source, anyone running F:Q without the requisite environment variable set (e.g. everyone that has just upgraded) gets the warning about the unset variable, even if not using that source:

$ gnc-fq-dump ukfunds GB00B6WFCS60
Expected ALPHAVANTAGE_API_KEY to be set; get an API key at https://www.alphavantage.co at /usr/share/perl5/vendor_perl/Finance/Quote/AlphaVantage.pm line 33.                                                                                                                                         
Compilation failed in require at (eval 9) line 1.
BEGIN failed--compilation aborted at (eval 9) line 1.
 at /usr/bin/gnc-fq-dump line 148.
Finance::Quote fields Gnucash uses:
    symbol: GB00B6WFCS60         <=== required
      date: 11/02/2017           <=== recommended
  currency: GBP                  <=== required
      last: 1.0873               <=\
       nav: 1.0873               <=== one of these
     price: 1.0873               <=/
  timezone:                      <=== optional

Surely there has to be a better way?

AlphaVantage: Wrong suffix for Stockholm

GnuCash cannot get data from the Stockholm stock exchange. The currency is missing since the suffix is incorrect in AlphaVantage.pm. The correct suffix is '.STO', e.g. ERIC-B.STO for Ericsson.

Add Morningstar AU source for managed funds

The Morningstar AU website has a comprehensive quotation service for Australian managed funds. While there there is a Finance::Quote::Morningstar module for the Morningstar SW website and Finance::Quote::MStarUK for the Morningstar UK website there is none for the Australian variant.

As such I've written a Finance::Quote::MorningstarAU module to extract quotes based on the fund's APIR code via 2 new morningstarau and aufunds methods. Have even written the .t test suites for both these methods :-).

How can I add these to the project?

This should also help out with a source of Australian managed fund quotes issue as raised in #91.

alphavantage quotes cannot be used by gnucash as currency is missing

aclark@discus 0 ~ $ gnc-fq-dump -v alphavantage nab.ax
Finance::Quote fields Gnucash uses:
    symbol: nab.ax               <=== required
      date: 07/16/2018           <=== recommended
  currency: ** missing **        <=== required
      last: 27.8400              <=\       
       nav:                      <=== one of these
     price:                      <=/        
  timezone:                      <=== optional

** This stock quote cannot be used by GnuCash!


All fields returned by Finance::Quote for stock nab.ax

stock           field  value
-----           -----  -----
nab.ax          close: 27.8400
nab.ax     currency_set_by_fq: 1
nab.ax           date: 07/16/2018
nab.ax           high: 28.0800
nab.ax        isodate: 2018-07-16
nab.ax           last: 27.8400
nab.ax            low: 27.7500
nab.ax         method: alphavantage
nab.ax           open: 28.0600
nab.ax        success: 1
nab.ax         symbol: nab.ax
nab.ax         volume: 4224779

aclark@discus 0 ~ $ 

Modul VWD broken

Hi

The VWD Modul is broken because the url has changed.

Regards,

Add ECB reference rates as source

Could you please add a parser for the daily Euro reference rates provided by the European Central Bank:

https://www.ecb.europa.eu/stats/policy_and_exchange_rates/euro_reference_exchange_rates/html/index.en.html

For reasoning why do so, I’ll quote the ECB because I’ve got nothing to add:

““Given that the ECB reference rates are provided as a public good for individual citizens and institutions, it is essential to safeguard a high level of integrity and to underline that they are intended to be used solely as a reference for information rather than when making transactions,” said ECB Executive Board member Benoît Cœuré.

The ECB has been setting and publishing its reference rates for the euro on a daily basis since the currency was launched in January 1999. These rates are often used for the annual financial statements of corporations, tax returns, statistical reports and economic analyses. They are the most accessed item on the ECB’s website, with more than a million visits per month.“

So they might not be used for the real transactions but are used as a important reporting measure.

IEX API Change

I've been using IEX quotes in gnucash for a little under a year without issue. They just changed their API so it is no longer working.
https://iextrading.com/developer/docs/#getting-started

This is the information that I used to setup IEX initially:
#97

Alphavantage is still a problem for me in gnucash presumably because it makes too many consecutive calls. I have the API key for IEX now. Is there any way to use it with finance::quote?

AlphaVantage now supports batch quotes

On Dec 28, AlphaVantage announced support for fetching quotes in batch. The returned data isn't as rich as the daily time series data, but it is significantly faster.

Example batch quote return value:

{
    "Meta Data": {
        "1. Information": "Batch Stock Market Quotes",
        "2. Notes": "IEX Real-Time Price provided for free by IEX (https://iextrading.com/developer/).",
        "3. Time Zone": "US/Eastern"
    },
    "Stock Quotes": [
        {
            "1. symbol": "PPG",
            "2. price": "118.4100",
            "3. volume": "3734030",
            "4. timestamp": "2018-01-18 16:00:00"
        }
    ]
}

I think the main difference is that you only get a single price instead of open/close/high/low.

The speed increase is pretty significant though. Some benchmarking I did tonight shows it may be 29.6x faster for 25 symbols, 96.3x faster for 250 symbols. This is just from one run, but anecdotally the results were pretty consistent across multiple runs.

./benchmark.rb
Using 25 symbols: [list omitted for brevity]

Rehearsal ------------------------------------------------------------
Multiple single requests   0.090000   0.040000   0.130000 ( 29.845046)
Batch requests             0.000000   0.000000   0.000000 (  0.382820)
--------------------------------------------------- total: 0.130000sec

                               user     system      total        real
Multiple single requests   0.080000   0.040000   0.120000 ( 22.843711)
Batch requests             0.000000   0.010000   0.010000 (  0.772521)

Total number of requests executed (including rehearsal):
Single - 50
Batch  - 2

./benchmark.rb 250
Using 250 symbols: [list omitted for brevity]

Rehearsal ------------------------------------------------------------
Multiple single requests   0.890000   0.350000   1.240000 (237.607558)
Batch requests             0.010000   0.000000   0.010000 (  0.575303)
--------------------------------------------------- total: 1.250000sec

                               user     system      total        real
Multiple single requests   0.830000   0.320000   1.150000 (265.849517)
Batch requests             0.010000   0.000000   0.010000 (  2.759761)

Total number of requests executed (including rehearsal):
Single - 500
Batch  - 6

(Source is available at https://github.com/atmattpatt/alphavantage-benchmark)

Does it seem worthwhile to switch to batch quotes, or provide batch quotes as an additional source? It seems like the speed up would be pretty helpful for GnuCash users who might have lots of symbols to fetch, but only need the last price.

Boursorama page changed

Hi,

Boursorama page changed, and we cannot fetch the quotes anymore.
I'm not enough good in Perl to do it, but it would be nice if someone have time to have a look on it.

Thanks a lot
Ket

missing installation files

Trying to test latest Alphavantage fixes. The installation instructions refer to Makefile.PL and INSTALL, neither of which exist on master.

Or maybe the instructions are obsolete?

Add Fixer currency rates provider

Fixer uses ECB's official exchange rates and provides a convenient API.
Could be handy now that Yahoo is off the table.

I've used clients for Python. Perhaps there is already something written in Perl, as well.

The drawback is that there are only rates for about 32 currencies available.

1.48 and 1.49 dists contain BerkeleyDB files

Don't think these should be there:

-rw-r--r-- ec/ec         16384 2019-06-30 11:21 Finance-Quote-1.49/lib/GPATH
-rw-r--r-- ec/ec         16384 2019-06-30 11:21 Finance-Quote-1.49/lib/GTAGS
-rw-r--r-- ec/ec         16384 2019-06-30 11:21 Finance-Quote-1.49/lib/GRTAGS

They get installed on to the user's system too.

yahooJSON.pm returns date 00/00/2000 in Windows

This is because Microsoft strftime function does not support %T.
Also, because of multiple 'Use of uninitialized value' perl warnings, this causes GnuCash in Windows to hang when getting multiple quotes (in my case >15).

echo (yahoo_json "CBA") | perl gnc-fq-helper
Use of uninitialized value $year in numeric lt (<) at C:/strawberry/perl/site/lib/Finance/Quote.pm line 757.
Use of uninitialized value $month in pattern match (m//) at C:/strawberry/perl/site/lib/Finance/Quote.pm line 768.
Use of uninitialized value $month in sprintf at C:/strawberry/perl/site/lib/Finance/Quote.pm line 773.
Use of uninitialized value $day in sprintf at C:/strawberry/perl/site/lib/Finance/Quote.pm line 773.
Use of uninitialized value $month in sprintf at C:/strawberry/perl/site/lib/Finance/Quote.pm line 774.
Use of uninitialized value $day in sprintf at C:/strawberry/perl/site/lib/Finance/Quote.pm line 774.
[parse] Invalid date 00/00/2000 12:00:00
(("CBA" (symbol . "CBA") (gnc:time-no-zone . "2017-11-21 19:05:10") (last . 7.65) (currency . "USD")))

I shall soon create a pull request for fix these problems.

Newbie Install Issue

Documentation refers to an INSTALL file for more information on installation protocol. Does not appear to be present in distribution. Installation instructions on cpan page do not download dependencies, in particular Mozilla::CA, and it is unclear how to do this.

ASX doesn't return a date

For gnucash to be able to use ASX.pm quotes it needs a date to be returned.

~/DEVELOPMENT/finance-quote >>> perl Examples/stockdump.pl ASX NAB
$VAR1 = {
'NABlow' => '30.380',
'NABp_change' => '0.000
',
'NABbid' => '30.410',
'NABopen' => '30.500',
'NABprice' => '30.440',
'NABsuccess' => 1,
'NABlast' => '30.440',
'NABhigh' => '30.550',
'NABvolume' => '5508357',
'NABnet' => '$0.000
',
'NABsymbol' => 'NAB',
'NABmethod' => 'asx',
'NABcurrency' => 'AUD',
'NABoffer' => '30.450',
'NABexchange' => 'Australian Stock Exchange'
};

Source ASX no longer works since 21 Apr 2017

From: Chris Good [mailto:[email protected]]
Sent: Monday, 8 May 2017 7:09 PM
To: [email protected]
Subject: Source ASX no longer works since 21 Apr 2017

Hi,

Perl 5.22.1 Finance::Quote 1.38, Linux Ubuntu 16.04 & Windows 10

It was reported by several people on the [email protected]
mailing list that Finance::Quote stopped working for getting quotes
from the ASX (using ASX.pm) on around 21 Apr 2017.

The error it returned was: Failed to parse HTML table

I modified my version of ASX.pm to save the $response->content
to a file and it now includes:
Please enable JavaScript to view the page content.
and none of the required price info. The old url still works
when used in a browser such as IE 11 or Firefox.

I'm no web expert but it seems to me the web page used no
longer works unless the browser supports javascript.

I've tried setting UserAgent to pretend to be various versions of IE,
in conjunction with using cookies, but none worked.

I've found an alternate web page
http://m.asx.com.au/m/prices/shares.xhtml?issuerCode=xxx
(designed for mobile devices) that doesn't seem to have this
restriction and works from the LWP perl library so long
as cookies are also turned on.

I will be submitting a github pull request soon with my fixed ASX.pm.

The old web page used to handle up to 10 stocks at once.
Unfortunately, I cannot find a way to request quotes for multiple
stocks at once using the new url, so my fixed ASX.pm will be
slightly slower than it was.
The new ASX.pm returns all the same data as the old one.

There is another page
http://m.asx.com.au/m/company-info.xhtml?issuerCode=xxx
that contains all the previous data plus P/E, EPS & Yield but it
also needs javascript.

Regards,
Chris Good

AlphaVantage always returns an error when calling require_labels()

I discovered that if one calls require_labels(), then any subsequent fetch always returns an error. The argument of require_labels() doesn't really seem to matter. If you require anything whatsoever, a fetch will always return an error.

The fix turned out to be pretty simple, as the labels() method in AlphaVantage.pm is erroneously shadowed. Here is my fix for the labels method below inline, or apply the attached unified diff using patch. It worked just fine for me.

sub methods {
    return ( alphavantage => \&alphavantage,
             canada       => \&alphavantage,
             usa          => \&alphavantage,
             nyse         => \&alphavantage,
             nasdaq       => \&alphavantage,
             vanguard     => \&alphavantage,
    );
}

sub labels {
    return ( alphavantage => [qw/date isodate open high low close volume last/]
    );
}

PATCH-labels.txt

SIX (Swiss Exchange)

Hi,
I wrote modules for getting share and fund data from the Swiss Exchange:

http://stephan.walter.name/files/SIXshares.pm
http://stephan.walter.name/files/SIXfunds.pm

Examples:

Shares: Nestle (http://www.six-swiss-exchange.com/shares/security_info_en.html?id=NESN)
echo '(sixshares "NESN")' | gnc-fq-helper

Fund: UBS-ETF SLI (http://www.six-swiss-exchange.com/funds/security_info_en.html?id=SLICHA)
echo '(sixfunds "SMICHA")' | gnc-fq-helper
(I haven't yet figured out the scripts in /t/, but I might have a try...)

The code works for my needs (I use it with Gnucash), but I'm a complete beginner at Perl so beware..

The two files are mostly identical. I wonder if they could be put into a single module.

I just opened this issue in case anyone is interested in this code. Suggestions for improvements are welcome!

Can't fetch NZX quotes via NZX (or any alternative)

It currently isn't possible to get quotes from the NZ stock exchange. It used to be possible to get it via the Yahoo NZ option, until Yahoo shut it down. Now all methods, including NZX.pm fail.

It would be great if we had a usable option again.

Validate HU

Test HU.pm module. Make changes as necessary to test file.

Alphavantage throttling

Since yahoo disabled the API, using finance::quote has become more burdensome for users. I have been using alphavantage for finance::quote amongst other things. It seems a few weeks ago they further throttled API queries so that it is causing issues when using finance::quote for more than 8 queries in sequence. I am currently using it with gnucash and I have switched from alphavantage with some items I developed in php due to this issue. I noticed that alphavantage was using IEX trading as their source, so I started using them directly. They do not require a key and claim as many as 100 queries per minute. Is there a possibility of adding this as a source to finance::quote?

ASX Quotes - Unrounded values being returned

since about 1 Jul ASX quotes haas been returing a random selection of quote values of the dollar figure, a + sign and a string of numbers. see image
aagnu2
AAGNU

Workaround so far is to manually edit

No Australian Sources Work

I can't find any sources that work to get quotes for Australia.

aclark@discus 0 ~ $ gnc-fq-check 
("1.47" "adig" "aex" "aiahk" "alphavantage" "amfiindia" "asegr" "asia" "asx" "australia" "bamosz" "bet" "bmonesbittburns" "bourso" "brasil" "bse" "bsero" "canada" "canadamutual" "citywire" "cominvest" "cse" "deka" "dutch" "dwsfunds" "europe" "fetch_live_currencies" "fidelity" "fidelity_direct" "fidelityfixed" "financecanada" "finanzpartner" "finland" "fool" "france" "ftfunds" "ftportfolios" "ftportfolios_direct" "fundlibrary" "goldmoney" "greece" "hex" "hu" "hufund" "hungary" "hustock" "indiamutual" "known_currencies" "lerevenu" "maninv" "morningstar" "morningstarjp" "mstaruk" "nasdaq" "nyse" "nz" "nzx" "platinum" "romania" "seb_funds" "sixfunds" "sixshares" "stockhousecanada_fund" "tdefunds" "tdwaterhouse" "tiaacref" "tnetuk" "troweprice" "troweprice_direct" "trustnet" "tsp" "tsx" "uk_unit_trusts" "ukfunds" "unionfunds" "usa" "usfedbonds" "vanguard" "vwd" "yahoo" "yahoo_asia" "yahoo_australia" "yahoo_brasil" "yahoo_europe" "yahoo_json" "yahoo_nz" "yahoo_yql" "za" "za_unittrusts")

The multiple sources australia setting doesn't work:

aclark@discus 0 ~ $ gnc-fq-dump australia NAB
Finance::Quote fields Gnucash uses:
    symbol: NAB (deduced)        <=== required
      date: ** missing **        <=== recommended
  currency: ** missing **        <=== required
      last:                      <=\       
       nav:                      <=== one of these
     price:                      <=/        
  timezone:                      <=== optional

** This stock quote cannot be used by GnuCash!

ASX doesn't work:

aclark@discus 0 ~ $ gnc-fq-dump asx NAB
Finance::Quote fields Gnucash uses:
    symbol: NAB (deduced)        <=== required
      date: ** missing **        <=== recommended
  currency: ** missing **        <=== required
      last:                      <=\       
       nav:                      <=== one of these
     price:                      <=/        
  timezone:                      <=== optional

** This stock quote cannot be used by GnuCash!

Thought the ASX website does return results for that code: https://www.asx.com.au/asx/markets/priceLookup.do?by=asxCodes&asxCodes=NAB

Yahoo doesn't work, even with the .AX suffix that makes the website work:

aclark@discus 0 ~ $ gnc-fq-dump yahoo_australia NAB
No results found for stock NAB.
aclark@discus 0 ~ $ gnc-fq-dump yahoo_australia NAB.AX
No results found for stock NAB.AX.

Here's the relevant URL for au.finanace.yahoo.com: https://au.finance.yahoo.com/quote/NAB.AX?p=NAB.AX&.tsrc=fin-srch-v1

IEXCloud Changed

From IEX Cloud:

Update 1: Nasdaq-Listed Delayed Stock Prices and Real-Time Consolidated Volume Data
Due to data provider policy, effective Tuesday, July 16, two sets of data – (a) 15-minute delayed, intraday stock prices and (b) real-time consolidated volume data – for companies listed on Nasdaq (i.e., UTP or “Tape C” securities) will no longer be available through the IEX Cloud API, unless you are a Launch, Grow, or Scale user that is authorized by the UTP Plan Administrator to receive this data from IEX Cloud.

Need to update module to use lastestPrice if quote is null.

Python version

Hi,

A couple of us are interested in providing and using a Python version of F::Q for price retrieval for different other projects, including Piecash, Gnucash Portfolio, Asset Allocation. Would you be interested in hosting this project and including myself and @sdementen as maintainers?

This would be a CLI interface on top of a library (API) allowing direct use as well as being called from other apps/scripts.

Cheers

New test in asx.t getting Use of uninitialized value $got in string eq at (eval in cmp_ok)

Hi,

I've modified ASX.pm to add currency AUD for some specific asx codes which are not indexes and it works fine but when I put a new test in asx.t it fails with:
cgood@goodi7vmutest:/home/cgood/github/finance-quote/t
$ ONLINE_TEST=1 ./asx.t
1..35
ok 1 - Data returned for call to asx
ok 2 - WES query was successful
ok 3 - Last price for WES was > 0
ok 4 - BHP query was successful
ok 5 - Last price for BHP was > 0
ok 6 - Data returned for call to fetch
ok 7 - BOQ query was successful
ok 8 - Last price for BOQ was > 0
ok 9 - Currency of BOQ is AUD
Use of uninitialized value $got in string eq at (eval in cmp_ok) ./asx.t line 46.
not ok 10 - Currency of XRO is AUD

Failed test 'Currency of XRO is AUD'

at ./asx.t line 46.

got: undef

expected: 'AUD'

ok 11 - No percentage sign in p_change value
... etc (other tests all pass)

I cannot understand what is wrong.

Here is the new test in asx.t:

Check that we're getting currency information.

cmp_ok( $quotes{"BOQ", "currency"}, "eq", "AUD"
, "Currency of BOQ is AUD" );

Check that we're getting currency information for share starting with X.

cmp_ok( $quotes{"XRO", "currency"}, "eq", "AUD"
, "Currency of XRO is AUD" );

The first test for BOQ is the original test which works fine. I just copied those lines and changed BOQ to XRO. XRO works fine when I use GnuCash: gnc-fq-dump asx XRO (apart from usual no date being returned by ASX which is taken care of by GnuCash - No quotes from asx return a date).

I'd really appreciate any help!

Finance::Quote 1.38
Test::More CPAN_VERSION 1.302052 INST_VERSION 1.001014
Test::Builder CPAN_VERSION 1.302052 INST_VERSION 1.001014
Ubuntu 16.04

asx.t
ASX.pm

Regards, Chris Good

Fund Library, CA scraper not working

Hello,
Some time after May 16, 2019, the date of my last price update, the "Fund Library, CA" scraper in F::Q stopped working. I suspect fundlibrary.com has changed their website. Other quotes are still working as expected through Alpha Vantage. None of the other Canadian mutual fund scrapers (BMO Nesbitt Burns, Canada
Mutual, Finance Canada, TD Waterhouse Funds) seem to be working either, even after searching the gnucash mail list archives for methods people have used in the past.

When trying to get my quotes, I see:
"Unable to retrieve quotes for these items:
FUND: xxxxx
FUND: yyyyy
FUND: zzzzz
Continue using only the good quotes?"

As expected, selecting "No" will cancel and selecting "Yes" will update the other stock prices.

If any logs will help, let me know and I will post them.

Thanks,
Doug

Yahoo CSV endpoint is dead

It appears Yahoo has recently disabled the endpoint at https://download.finance.yahoo.com/d/quotes.csv which now returns a 403 error with the following text:

It has come to our attention that this service is being used in violation of the Yahoo Terms of Service. As such, the service is being discontinued. For all future markets and equities data research, please refer to finance.yahoo.com.

This change means that Finance::Quote returns no results for the yahoo source (or any of its aliases). Not sure if there is a fix, but just wanted to bring it to your attention.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.