mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
Bug 799419 - Intermittent quote price issue
Track quote source in Finance::Quote return json so that duplicate symbols in different namespaces can be kept separate.
This commit is contained in:
parent
e0f26f60c4
commit
6aeca0040e
@ -659,24 +659,33 @@ GNCPrice*
|
|||||||
GncQuotesImpl::parse_one_quote(const bpt::ptree& pt, gnc_commodity* comm)
|
GncQuotesImpl::parse_one_quote(const bpt::ptree& pt, gnc_commodity* comm)
|
||||||
{
|
{
|
||||||
PriceParams p;
|
PriceParams p;
|
||||||
|
bpt::ptree comm_pt;
|
||||||
|
|
||||||
p.ns = gnc_commodity_get_namespace (comm);
|
p.ns = gnc_commodity_get_namespace (comm);
|
||||||
p.mnemonic = gnc_commodity_get_mnemonic (comm);
|
p.mnemonic = gnc_commodity_get_mnemonic (comm);
|
||||||
if (gnc_commodity_equiv(comm, m_dflt_curr) ||
|
if (gnc_commodity_equiv(comm, m_dflt_curr) ||
|
||||||
(!p.mnemonic || (strcmp (p.mnemonic, "XXX") == 0)))
|
(!p.mnemonic || (strcmp (p.mnemonic, "XXX") == 0)))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
auto comm_pt_ai{pt.find(p.mnemonic)};
|
auto source{gnc_quote_source_get_internal_name(gnc_commodity_get_quote_source(comm))};
|
||||||
if (comm_pt_ai == pt.not_found())
|
auto source_pt_ai{pt.find(source)};
|
||||||
|
auto ok{source_pt_ai != pt.not_found()};
|
||||||
|
if (ok)
|
||||||
|
{
|
||||||
|
auto comm_pt_ai{source_pt_ai->second.find(p.mnemonic)};
|
||||||
|
ok = (comm_pt_ai != pt.not_found());
|
||||||
|
if (ok)
|
||||||
|
comm_pt = comm_pt_ai->second;
|
||||||
|
}
|
||||||
|
if (!ok)
|
||||||
{
|
{
|
||||||
m_failures.emplace_back(p.ns, p.mnemonic, GncQuoteError::NO_RESULT,
|
m_failures.emplace_back(p.ns, p.mnemonic, GncQuoteError::NO_RESULT,
|
||||||
empty_string);
|
empty_string);
|
||||||
PINFO("Skipped %s:%s - Finance::Quote didn't return any data.",
|
PINFO("Skipped %s:%s - Finance::Quote didn't return any data from %s.",
|
||||||
p.ns, p.mnemonic);
|
p.ns, p.mnemonic, source);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto comm_pt{comm_pt_ai->second};
|
|
||||||
parse_quote_json(p, comm_pt);
|
parse_quote_json(p, comm_pt);
|
||||||
|
|
||||||
if (!p.success)
|
if (!p.success)
|
||||||
{
|
{
|
||||||
m_failures.emplace_back(p.ns, p.mnemonic, GncQuoteError::QUOTE_FAILED,
|
m_failures.emplace_back(p.ns, p.mnemonic, GncQuoteError::QUOTE_FAILED,
|
||||||
|
@ -181,17 +181,19 @@ TEST_F(GncQuotesTest, offline_wiggle)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
"\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004},"
|
"\"currency\":{"
|
||||||
|
"\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004}},"
|
||||||
|
"\"alphavantage\":{"
|
||||||
"\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Alphavantage\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"alphavantage\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},"
|
"\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Alphavantage\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"alphavantage\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},"
|
||||||
"\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"alphavantage\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Alphavantage\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1},"
|
"\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"alphavantage\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Alphavantage\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1},"
|
||||||
"\"FKCM\":{\"success\":0,\"symbol\":\"FKCM\",\"errormsg\":\"Error retrieving quote for FKCM - no listing for this name found. Please check symbol and the two letter extension (if any)\"}"
|
"\"FKCM\":{\"success\":0,\"symbol\":\"FKCM\",\"errormsg\":\"Error retrieving quote for FKCM - no listing for this name found. Please check symbol and the two letter extension (if any)\"}"
|
||||||
"}"
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
GncQuotesImpl quotes(m_book, std::make_unique<GncMockQuoteSource>(std::move(quote_vec), std::move(err_vec)));
|
GncQuotesImpl quotes(m_book, std::make_unique<GncMockQuoteSource>(std::move(quote_vec), std::move(err_vec)));
|
||||||
quotes.fetch(m_book);
|
quotes.fetch(m_book);
|
||||||
auto failures{quotes.failures()};
|
auto failures{quotes.failures()};
|
||||||
ASSERT_EQ(1u, failures.size());
|
EXPECT_EQ(1u, failures.size());
|
||||||
EXPECT_EQ(GncQuoteError::QUOTE_FAILED, std::get<2>(failures[0]));
|
EXPECT_EQ(GncQuoteError::QUOTE_FAILED, std::get<2>(failures[0]));
|
||||||
auto pricedb{gnc_pricedb_get_db(m_book)};
|
auto pricedb{gnc_pricedb_get_db(m_book)};
|
||||||
EXPECT_EQ(3u, gnc_pricedb_get_num_prices(pricedb));
|
EXPECT_EQ(3u, gnc_pricedb_get_num_prices(pricedb));
|
||||||
@ -201,10 +203,11 @@ TEST_F(GncQuotesTest, offline_report)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
|
"\"alphavantage\":{"
|
||||||
"\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Alphavantage\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"alphavantage\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},"
|
"\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Alphavantage\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"alphavantage\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},"
|
||||||
"\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"alphavantage\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Alphavantage\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1},"
|
"\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"alphavantage\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Alphavantage\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1},"
|
||||||
"\"FKCM\":{\"success\":0,\"symbol\":\"FKCM\",\"errormsg\":\"Error retrieving quote for FKCM - no listing for this name found. Please check symbol and the two letter extension (if any)\"}"
|
"\"FKCM\":{\"success\":0,\"symbol\":\"FKCM\",\"errormsg\":\"Error retrieving quote for FKCM - no listing for this name found. Please check symbol and the two letter extension (if any)\"}"
|
||||||
"}"
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec commodities{"AAPL", "HPE", "FKCM"};
|
StrVec commodities{"AAPL", "HPE", "FKCM"};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
@ -217,8 +220,9 @@ TEST_F(GncQuotesTest, offline_currency_report)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
|
"\"currency\":{"
|
||||||
"\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004}"
|
"\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004}"
|
||||||
"}"
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec commodities{"USD", "EUR"};
|
StrVec commodities{"USD", "EUR"};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
@ -231,9 +235,10 @@ TEST_F(GncQuotesTest, comvec_fetch)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
|
"\"alphavantage\":{"
|
||||||
"\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Alphavantage\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"alphavantage\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},"
|
"\"AAPL\":{\"eps\":6.05,\"success\":1,\"year_range\":\" 129.04 - 182.94\",\"currency\":\"USD\",\"exchange\":\"Sourced from Alphavantage\",\"volume\":73539475,\"close\":157.22,\"high\":158.39,\"open\":156.64,\"div_yield\":0.5660857,\"last\":157.96,\"isodate\":\"2022-09-01\",\"method\":\"alphavantage\",\"name\":\"AAPL (Apple Inc.)\",\"pe\":26.10909,\"low\":154.67,\"type\":\"EQUITY\",\"symbol\":\"AAPL\",\"date\":\"09/01/2022\"},"
|
||||||
"\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"alphavantage\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Alphavantage\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1}"
|
"\"HPE\":{\"symbol\":\"HPE\",\"date\":\"09/01/2022\",\"low\":13.13,\"type\":\"EQUITY\",\"method\":\"alphavantage\",\"name\":\"HPE (Hewlett Packard Enterprise Comp)\",\"isodate\":\"2022-09-01\",\"pe\":4.7921147,\"last\":13.37,\"high\":13.535,\"close\":13.6,\"open\":13.5,\"div_yield\":3.5294116,\"volume\":16370483,\"exchange\":\"Sourced from Alphavantage\",\"currency\":\"USD\",\"year_range\":\" 12.4 - 17.76\",\"eps\":2.79,\"success\":1}"
|
||||||
"}"
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
auto commtable{gnc_commodity_table_get_table(m_book)};
|
auto commtable{gnc_commodity_table_get_table(m_book)};
|
||||||
@ -252,8 +257,9 @@ TEST_F(GncQuotesTest, fetch_one_commodity)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
|
"\"alphavantage\":{"
|
||||||
"\"HPE\":{\"date\":\"09/01/2022\",\"last\":13.37,\"currency\":\"USD\",\"success\":1}"
|
"\"HPE\":{\"date\":\"09/01/2022\",\"last\":13.37,\"currency\":\"USD\",\"success\":1}"
|
||||||
"}"
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
auto commtable{gnc_commodity_table_get_table(m_book)};
|
auto commtable{gnc_commodity_table_get_table(m_book)};
|
||||||
@ -281,8 +287,9 @@ TEST_F(GncQuotesTest, fetch_one_currency)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
|
"\"currency\":{"
|
||||||
"\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004}"
|
"\"EUR\":{\"symbol\":\"EUR\",\"currency\":\"USD\",\"success\":\"1\",\"inverted\":0,\"last\":1.0004}"
|
||||||
"}"
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
auto commtable{gnc_commodity_table_get_table(m_book)};
|
auto commtable{gnc_commodity_table_get_table(m_book)};
|
||||||
@ -312,8 +319,9 @@ TEST_F(GncQuotesTest, no_currency)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
|
"\"alphavantage\":{"
|
||||||
"\"HPE\":{\"date\":\"09/01/2022\",\"last\":13.37,\"success\":1}"
|
"\"HPE\":{\"date\":\"09/01/2022\",\"last\":13.37,\"success\":1}"
|
||||||
"}"
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
auto commtable{gnc_commodity_table_get_table(m_book)};
|
auto commtable{gnc_commodity_table_get_table(m_book)};
|
||||||
@ -331,8 +339,9 @@ TEST_F(GncQuotesTest, bad_currency)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
"\"HPE\":{\"date\":\"09/01/2022\",\"last\":13.37,\"currency\":\"BTC\",\"success\":1}"
|
"\"alphavantage\":{"
|
||||||
"}"
|
"\"HPE\":{\"date\":\"09/01/2022\",\"last\":13.37,\"currency\":\"BTC\",\"success\":1}"
|
||||||
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
auto commtable{gnc_commodity_table_get_table(m_book)};
|
auto commtable{gnc_commodity_table_get_table(m_book)};
|
||||||
@ -350,8 +359,9 @@ TEST_F(GncQuotesTest, no_date)
|
|||||||
{
|
{
|
||||||
StrVec quote_vec{
|
StrVec quote_vec{
|
||||||
"{"
|
"{"
|
||||||
|
"\"alphavantage\":{"
|
||||||
"\"HPE\":{\"last\":13.37,\"currency\":\"USD\",\"success\":1}"
|
"\"HPE\":{\"last\":13.37,\"currency\":\"USD\",\"success\":1}"
|
||||||
"}"
|
"}}"
|
||||||
};
|
};
|
||||||
StrVec err_vec;
|
StrVec err_vec;
|
||||||
auto commtable{gnc_commodity_table_get_table(m_book)};
|
auto commtable{gnc_commodity_table_get_table(m_book)};
|
||||||
|
@ -176,7 +176,7 @@ sub parse_currencies {
|
|||||||
$results{$from_currency}{"currency"} = $to_currency;
|
$results{$from_currency}{"currency"} = $to_currency;
|
||||||
$results{$from_currency}{"last"} = $price;
|
$results{$from_currency}{"last"} = $price;
|
||||||
}
|
}
|
||||||
return %results;
|
return ("currency" => \%results);
|
||||||
}
|
}
|
||||||
|
|
||||||
sub parse_commodities {
|
sub parse_commodities {
|
||||||
@ -184,7 +184,7 @@ sub parse_commodities {
|
|||||||
|
|
||||||
my %quote_data = $quoter->fetch($quote_method_name, keys %$commodities);
|
my %quote_data = $quoter->fetch($quote_method_name, keys %$commodities);
|
||||||
my %normalized_quote_data = sanitize_hash(%quote_data);
|
my %normalized_quote_data = sanitize_hash(%quote_data);
|
||||||
return %normalized_quote_data;
|
return ($quote_method_name => \%normalized_quote_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
#---------------------------------------------------------------------------
|
#---------------------------------------------------------------------------
|
||||||
|
Loading…
Reference in New Issue
Block a user