GnuCash  5.6-150-g038405b370+
Public Member Functions
GncQuotes Class Reference

Public Member Functions

 GncQuotes ()
 Create a GncQuotes object. More...
 
void fetch (QofBook *book)
 Fetch quotes for all commodities in our db that have a quote source set. More...
 
void fetch (CommVec &commodities)
 Fetch quotes for a vector of commodities. More...
 
void fetch (gnc_commodity *comm)
 Fetch quote for a single commodity. More...
 
void report (const char *source, const StrVec &commodities, bool verbose=false)
 Report quote results from Finance::Quote to std::cout. More...
 
const std::string & version () noexcept
 Get the installed Finance::Quote version. More...
 
const QuoteSources & sources () noexcept
 Get the available Finance::Quote sources as a std::vector. More...
 
bool had_failures () noexcept
 Report if there were quotes requested but not retrieved. More...
 
const QFVec & failures () noexcept
 Report the commodities for which quotes were requested but not successfully retrieved. More...
 
const std::string report_failures () noexcept
 

Detailed Description

Definition at line 65 of file gnc-quotes.hpp.

Constructor & Destructor Documentation

◆ GncQuotes()

GncQuotes::GncQuotes ( )

Create a GncQuotes object.

Throws a GncQuoteException if Finance::Quote is not installed or fails to initialize.

Definition at line 1040 of file gnc-quotes.cpp.

1041 {
1042  try
1043  {
1044  m_impl = std::make_unique<GncQuotesImpl>();
1045  } catch (const GncQuoteSourceError &err) {
1046  throw(GncQuoteException(err.what()));
1047  }
1048 }

Member Function Documentation

◆ failures()

const QFVec & GncQuotes::failures ( )
noexcept

Report the commodities for which quotes were requested but not successfully retrieved.

This does not include requested commodities that didn't have a quote source.

Returns
a reference to a vector of QuoteFailure tuples.
Note
The vector and its contents belong to the GncQuotes object and will be destroyed with it.

Definition at line 1092 of file gnc-quotes.cpp.

1093 {
1094  return m_impl->failures();
1095 }

◆ fetch() [1/3]

void GncQuotes::fetch ( QofBook *  book)

Fetch quotes for all commodities in our db that have a quote source set.

Parameters
bookThe current book.

Definition at line 1052 of file gnc-quotes.cpp.

1053 {
1054  m_impl->fetch (book);
1055 }

◆ fetch() [2/3]

void GncQuotes::fetch ( CommVec &  commodities)

Fetch quotes for a vector of commodities.

Parameters
commoditiesstd::vector of the gnc_commodity* to get quotes for.
Note
Commodities without a quote source will be silently ignored.

Definition at line 1057 of file gnc-quotes.cpp.

1058 {
1059  m_impl->fetch (commodities);
1060 }

◆ fetch() [3/3]

void GncQuotes::fetch ( gnc_commodity *  comm)

Fetch quote for a single commodity.

Parameters
commCommodity for which to retrieve a quote
Note
Commodity must have a quote source set or the call will silently fail.

Definition at line 1062 of file gnc-quotes.cpp.

1063 {
1064  m_impl->fetch (comm);
1065 }

◆ had_failures()

bool GncQuotes::had_failures ( )
noexcept

Report if there were quotes requested but not retrieved.

Returns
True if there were quote failures.

Definition at line 1086 of file gnc-quotes.cpp.

1087 {
1088  return m_impl->had_failures();
1089 }

◆ report()

void GncQuotes::report ( const char *  source,
const StrVec &  commodities,
bool  verbose = false 
)

Report quote results from Finance::Quote to std::cout.

Parameters
sourceA valid quote source
commoditiesA std::vector of symbols to request quotes for.
Note
If requesting currency rates the first symbol is the to-currency and the rest are from-currencies. For example, {"USD", "EUR", "CAD"} will print the price of 1 Euro and 1 Canadian Dollar in US Dollars.
Parameters
verboseIgnored for currency queries. If false it will print the six fields GnuCash uses regardless of whether a value was returned; if true it will print all of the fields for which Finanace::Quote returned values.

Definition at line 1067 of file gnc-quotes.cpp.

1069 {
1070  m_impl->report(source, commodities, verbose);
1071 }

◆ sources()

const QuoteSources & GncQuotes::sources ( )
noexcept

Get the available Finance::Quote sources as a std::vector.

Returns
The quote sources configured in Finance::Quote

Definition at line 1078 of file gnc-quotes.cpp.

1079 {
1080  return m_impl->sources ();
1081 }

◆ version()

const std::string & GncQuotes::version ( )
noexcept

Get the installed Finance::Quote version.

Returns
the Finance::Quote version string

Definition at line 1073 of file gnc-quotes.cpp.

1074 {
1075  return m_impl->version ();
1076 }

The documentation for this class was generated from the following files: