-
Notifications
You must be signed in to change notification settings - Fork 5
Refactoring include out of the source folder, added in an SQL manager #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
f203bdd
c6a399b
cc87cf0
cf014a8
82aca01
9bf8d0a
0f69def
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Backtesting Engine in C++ | ||
| // | ||
| // (c) 2025 Ryan McCaffery | https://mccaffers.com | ||
| // This code is licensed under MIT license (see LICENSE.txt for details) | ||
| // --------------------------------------- | ||
| #pragma once | ||
| #include <string> | ||
| #include <vector> | ||
| #include "models/priceData.hpp" | ||
| #include "databaseConnection.hpp" | ||
|
|
||
| class SqlManager { | ||
| public: | ||
| static std::vector<PriceData> getInitialPriceData(const DatabaseConnection& db); | ||
| static std::string getBaseQuery(); | ||
| private: | ||
| static constexpr int DEFAULT_LIMIT = 1000; | ||
| }; |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,14 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Backtesting Engine in C++ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // (c) 2025 Ryan McCaffery | https://mccaffers.com | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // This code is licensed under MIT license (see LICENSE.txt for details) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // --------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "sqlManager.hpp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string SqlManager::getBaseQuery() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "SELECT * FROM EURUSD LIMIT " + std::to_string(DEFAULT_LIMIT) + ";"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+7
to
+9
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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
AI
Apr 5, 2026
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.