Skip to content

Refactoring include out of the source folder, added in an SQL manager#7

Merged
mccaffers merged 7 commits intomainfrom
dev/improve_code_coverage
Apr 6, 2026
Merged

Refactoring include out of the source folder, added in an SQL manager#7
mccaffers merged 7 commits intomainfrom
dev/improve_code_coverage

Conversation

@mccaffers
Copy link
Copy Markdown
Owner

No description provided.

@mccaffers mccaffers self-assigned this Feb 10, 2025
@mccaffers mccaffers added enhancement New feature or request cpp labels Feb 10, 2025
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@mccaffers mccaffers marked this pull request as ready for review April 5, 2026 11:56
Copilot AI review requested due to automatic review settings April 5, 2026 11:56
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR reorganizes project headers into a top-level include/ directory and introduces a small SqlManager abstraction to centralize the initial market-data query.

Changes:

  • Move/introduce headers under include/ and update build include paths accordingly.
  • Add SqlManager and wire it into main to fetch initial PriceData.
  • Adjust local run script behavior (environment sourcing removed; DB endpoint changed).

Reviewed changes

Copilot reviewed 8 out of 22 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
source/sqlManager.cpp Implements a centralized initial SQL query + execution wrapper.
include/sqlManager.hpp Declares the new SqlManager API and default limit.
source/main.cpp Switches initial query callsite to SqlManager.
source/jsonParser.cpp Adds file header comment block.
include/jsonParser.hpp Declares JsonParser public API in new include path.
include/databaseConnection.hpp Introduces/relocates DB connection interface into include/.
include/utilities/base64.hpp Introduces/relocates Base64 + Utilities declarations into include/.
include/configManager.hpp Introduces/relocates ConfigManager into include/.
include/serviceA.hpp Introduces/relocates ServiceA into include/.
include/models/priceData.hpp Adds required <chrono> include for timestamp.
include/models/trade.hpp Introduces/relocates Trade model into include/.
include/trading/tradeManager.hpp Introduces/relocates TradeManager interface into include/.
include/trading_definitions/*.hpp Introduces/relocates JSON-mapped config structs into include/.
include/trading_definitions.hpp Adds umbrella header for trading definitions.
scripts/run.sh Changes environment sourcing and hardcodes DB endpoint IP.
CMakeLists.txt Updates include directories to use top-level include/.
backtesting-engine-cpp.xcodeproj/project.pbxproj Adds include/ group and sqlManager sources to Xcode project.
Comments suppressed due to low confidence (1)

source/main.cpp:41

  • executeQuery() returns an empty vector on errors, but the code immediately indexes priceData[0] without checking. If the DB connection/query fails (or returns no rows), this will be an out-of-bounds access and crash. Add an explicit empty-check (and handle the failure case) before using priceData[0].
  std::vector<PriceData> priceData = SqlManager::getInitialPriceData(db);
  
  // Convert timestamp to readable format for debugging
  auto timeT = std::chrono::system_clock::to_time_t(priceData[0].timestamp);
  std::cout << "Timestamp: " << std::put_time(std::localtime(&timeT), "%Y-%m-%d %H:%M:%S") << std::endl;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +7 to +9

std::string SqlManager::getBaseQuery() {
return "SELECT * FROM EURUSD LIMIT " + std::to_string(DEFAULT_LIMIT) + ";";
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getBaseQuery() hardcodes the table/symbol (EURUSD) and the row limit, even though configuration includes a SYMBOLS field. To make SqlManager reusable (and avoid having to change code for different symbols/limits), consider taking symbol and limit as parameters (or reading them from the parsed configuration).

Suggested change
std::string SqlManager::getBaseQuery() {
return "SELECT * FROM EURUSD LIMIT " + std::to_string(DEFAULT_LIMIT) + ";";
#include <cstdlib>
#include <string>
namespace {
std::string getConfiguredSymbol() {
const char* symbols = std::getenv("SYMBOLS");
if (symbols == nullptr || *symbols == '\0') {
return "EURUSD";
}
std::string configuredSymbols(symbols);
std::size_t separator = configuredSymbols.find(',');
std::string symbol = configuredSymbols.substr(0, separator);
std::size_t first = symbol.find_first_not_of(" \t");
if (first == std::string::npos) {
return "EURUSD";
}
std::size_t last = symbol.find_last_not_of(" \t");
return symbol.substr(first, last - first + 1);
}
int getConfiguredLimit() {
const char* configuredLimit = std::getenv("SQL_LIMIT");
if (configuredLimit == nullptr || *configuredLimit == '\0') {
return DEFAULT_LIMIT;
}
char* end = nullptr;
long parsedLimit = std::strtol(configuredLimit, &end, 10);
if (end == configuredLimit || *end != '\0' || parsedLimit <= 0) {
return DEFAULT_LIMIT;
}
return static_cast<int>(parsedLimit);
}
} // namespace
std::string SqlManager::getBaseQuery() {
return "SELECT * FROM " + getConfiguredSymbol() + " LIMIT " + std::to_string(getConfiguredLimit()) + ";";

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +12
std::string SqlManager::getBaseQuery() {
return "SELECT * FROM EURUSD LIMIT " + std::to_string(DEFAULT_LIMIT) + ";";
}

std::vector<PriceData> SqlManager::getInitialPriceData(const DatabaseConnection& db) {
Copy link

Copilot AI Apr 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are XCTest-based tests for other components, but nothing covers the new SqlManager behavior (e.g., the generated base query / default limit). Adding a small unit test would help catch regressions as the query logic evolves.

Copilot uses AI. Check for mistakes.
@mccaffers mccaffers moved this from In progress to In review in @mccaffers Backtesting Project Tracking Apr 6, 2026
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 6, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@mccaffers mccaffers merged commit 54f7c04 into main Apr 6, 2026
3 of 5 checks passed
@mccaffers mccaffers deleted the dev/improve_code_coverage branch April 6, 2026 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cpp enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

2 participants