Skip to content

Commit

Permalink
switched to yahoo v6 since v7 died
Browse files Browse the repository at this point in the history
  • Loading branch information
EtoileScintillante committed Apr 5, 2024
1 parent d4a6fc9 commit 6bc26e9
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/bot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void Bot::commandHandler(const dpp::slashcommand_t &event)
}

// Create candlestick chart
(showV == "n") ? createCandle(symbol, period) : createCandleAndVolume(symbol, period);
(showV == "n") ? createCandle(symbol, period) : createCandleWithVolume(symbol, period);

// Additional delay to make sure the file is fully written to disk
// Without this delay the bot sends an empty image file
Expand Down
14 changes: 2 additions & 12 deletions src/data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ Metrics fetchMetrics(const std::string &symbol)
Metrics equityMetrics;

// Construct the Yahoo Finance API URL with the symbol
std::string apiUrl = "https://query1.finance.yahoo.com/v7/finance/options/" + symbol;
std::string apiUrl = "https://query1.finance.yahoo.com/v6/finance/options/" + symbol;

// Fetch data from the Yahoo Finance API
std::string response = httpGet(apiUrl);
Expand All @@ -284,11 +284,7 @@ Metrics fetchMetrics(const std::string &symbol)
const rapidjson::Value &quote = optionChain["quote"];

// Extract metrics from quote object
if (quote.HasMember("displayName") && quote["displayName"].IsString()) // name from displayName
{
equityMetrics.name = quote["displayName"].GetString();
}
else if ((quote.HasMember("shortName") && quote["shortName"].IsString())) // name from shortName
if ((quote.HasMember("shortName") && quote["shortName"].IsString())) // name from shortName
{
equityMetrics.name = quote["shortName"].GetString();
}
Expand All @@ -308,10 +304,6 @@ Metrics fetchMetrics(const std::string &symbol)
{
equityMetrics.marketCap = quote["marketCap"].GetDouble();
}
if (quote.HasMember("dividendYield") && quote["dividendYield"].IsNumber()) // dividendYield
{
equityMetrics.dividendYield = quote["dividendYield"].GetDouble();
}
if (quote.HasMember("trailingPE") && quote["trailingPE"].IsNumber()) // peRatio
{
equityMetrics.peRatio = quote["trailingPE"].GetDouble();
Expand Down Expand Up @@ -389,7 +381,6 @@ std::string getFormattedMetrics(const std::string &symbol, bool markdown)
formattedMetrics << "Metrics for " << metrics.name << ":\n";
formattedMetrics << std::fixed << std::setprecision(2);
formattedMetrics << "- Market Cap: " << metrics.marketCap << " " << metrics.currency << "\n";
formattedMetrics << "- Dividend Yield: " << metrics.dividendYield << "%\n";
formattedMetrics << "- P/E Ratio: " << metrics.peRatio << "\n";
formattedMetrics << "- Latest Price: " << metrics.latestPrice << " " << metrics.currency << "\n";
formattedMetrics << "- Open price: " << metrics.openPrice << " " << metrics.currency << "\n";
Expand All @@ -408,7 +399,6 @@ std::string getFormattedMetrics(const std::string &symbol, bool markdown)
formattedMetrics << "### Metrics for " << metrics.name << "\n";
formattedMetrics << std::fixed << std::setprecision(2);
formattedMetrics << "- Market Cap: `" << metrics.marketCap << " " << metrics.currency << "`\n";
formattedMetrics << "- Dividend Yield: `" << metrics.dividendYield << "%`\n";
formattedMetrics << "- P/E Ratio: `" << metrics.peRatio << "`\n";
formattedMetrics << "- Latest Price: `" << metrics.latestPrice << " " << metrics.currency << "`\n";
formattedMetrics << "- Open price: `" << metrics.openPrice << " " << metrics.currency << "`\n";
Expand Down
3 changes: 1 addition & 2 deletions src/include/data.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ struct Metrics
std::string symbol = "-"; // Symbol
std::string marketState = "_"; // State of market (Open/Regular, Closed, Pre, Post)
double marketCap = 0; // Market capitalization, i.e. amount of shares (or coins in case of crypto) * price
double dividendYield = 0; // Dividend yield as a percentage
double peRatio = 0; // Price-to-earnings ratio (P/E ratio) indicating stock valuation
double latestPrice = 0; // Latest price
double latestChange = 0; // Latest price change in percentage (compared to open price of that day)
Expand Down Expand Up @@ -95,7 +94,7 @@ void fetchAndWriteEquityData(const std::string &symbol, const std::string &durat

/// Function to fetch stock/future/index/crypto metrics from Yahoo Finance API for a single symbol.
/// @param symbol The symbol of the stock/future/index/crypto.
/// @return Metrics struct containing price info, dividend yield, market capitalization and more.
/// @return Metrics struct containing price info, market capitalization and more.
Metrics fetchMetrics(const std::string &symbol);

/// Function to get stock/future/index/crypto metrics in a readable way.
Expand Down

0 comments on commit 6bc26e9

Please sign in to comment.