Skip to content

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ add_subdirectory(external/libpqxx EXCLUDE_FROM_ALL)

# Include directories
include_directories(
${CMAKE_SOURCE_DIR}/source/include
${CMAKE_SOURCE_DIR}/source/include/utilities
${CMAKE_SOURCE_DIR}/source/include/models
${CMAKE_SOURCE_DIR}/source/include/trading
${CMAKE_SOURCE_DIR}/source/include/trading_definitions
${CMAKE_SOURCE_DIR}/include
${CMAKE_SOURCE_DIR}/include/utilities
${CMAKE_SOURCE_DIR}/include/models
${CMAKE_SOURCE_DIR}/include/trading
${CMAKE_SOURCE_DIR}/include/trading_definitions
${CMAKE_SOURCE_DIR}/external
)

Expand Down
12 changes: 10 additions & 2 deletions backtesting-engine-cpp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
940A61142C92CE210083FEB8 /* configManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 940A61112C92CE210083FEB8 /* configManager.cpp */; };
940A61172C92CE960083FEB8 /* serviceA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 940A61152C92CE960083FEB8 /* serviceA.cpp */; };
940A61182C92CE960083FEB8 /* serviceA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 940A61152C92CE960083FEB8 /* serviceA.cpp */; };
941408AE2D59F93F000ED1F9 /* sqlManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941408AD2D59F93F000ED1F9 /* sqlManager.cpp */; };
941408AF2D59F93F000ED1F9 /* sqlManager.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941408AD2D59F93F000ED1F9 /* sqlManager.cpp */; };
941B549A2D3BBADE00E3BF64 /* trading_definitions_json.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941B54992D3BBADD00E3BF64 /* trading_definitions_json.cpp */; };
941B549B2D3BBADE00E3BF64 /* trading_definitions_json.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 941B54992D3BBADD00E3BF64 /* trading_definitions_json.cpp */; };
94280BA32D2FC00200F1CF56 /* base64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 94280BA22D2FC00200F1CF56 /* base64.cpp */; };
Expand Down Expand Up @@ -51,6 +53,8 @@
940A61122C92CE210083FEB8 /* configManager.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = configManager.hpp; sourceTree = "<group>"; };
940A61152C92CE960083FEB8 /* serviceA.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = serviceA.cpp; sourceTree = "<group>"; };
940A61162C92CE960083FEB8 /* serviceA.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = serviceA.hpp; sourceTree = "<group>"; };
941408AD2D59F93F000ED1F9 /* sqlManager.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = sqlManager.cpp; sourceTree = "<group>"; };
941408B02D59F954000ED1F9 /* sqlManager.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = sqlManager.hpp; sourceTree = "<group>"; };
941B54902D3BBA4900E3BF64 /* ohlc_variables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ohlc_variables.hpp; sourceTree = "<group>"; };
941B54912D3BBA5600E3BF64 /* ohlc_rsi_variables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = ohlc_rsi_variables.hpp; sourceTree = "<group>"; };
941B54922D3BBA6500E3BF64 /* trading_variables.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; path = trading_variables.hpp; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1317,6 +1321,7 @@
94CD849E2D2D22C900041BBA /* external */,
944D0DD22C8C3704004DD0FC /* images */,
944D0DCE2C8C3704004DD0FC /* scripts */,
94DE4F772C8C3E7C00FE48FF /* include */,
9470B5A22C8C5AD0007D9CC6 /* source */,
9470B5AD2C8C5B99007D9CC6 /* tests */,
948A9CEC2C906ADB00E23669 /* resources */,
Expand Down Expand Up @@ -1395,16 +1400,16 @@
9470B5A22C8C5AD0007D9CC6 /* source */ = {
isa = PBXGroup;
children = (
943398232D57E53400287A2D /* jsonParser.cpp */,
94674B8C2D533E7800973137 /* models */,
94674B862D533B4000973137 /* trading */,
94DE4F772C8C3E7C00FE48FF /* include */,
941B54982D3BBAD800E3BF64 /* trading_definitions */,
94280BA72D2FC29F00F1CF56 /* utilities */,
9470B5A32C8C5AD0007D9CC6 /* main.cpp */,
940A61112C92CE210083FEB8 /* configManager.cpp */,
940A61152C92CE960083FEB8 /* serviceA.cpp */,
94CD8B9F2D2E8CE500041BBA /* databaseConnection.cpp */,
943398232D57E53400287A2D /* jsonParser.cpp */,
941408AD2D59F93F000ED1F9 /* sqlManager.cpp */,
);
path = source;
sourceTree = "<group>";
Expand Down Expand Up @@ -3510,6 +3515,7 @@
94DE4F772C8C3E7C00FE48FF /* include */ = {
isa = PBXGroup;
children = (
941408B02D59F954000ED1F9 /* sqlManager.hpp */,
943398222D57E52900287A2D /* jsonParser.hpp */,
94674B842D533B2F00973137 /* trading */,
942966D72D48E84100532862 /* models */,
Expand Down Expand Up @@ -3616,6 +3622,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
941408AE2D59F93F000ED1F9 /* sqlManager.cpp in Sources */,
9470B5A42C8C5AD0007D9CC6 /* main.cpp in Sources */,
943398252D57E53400287A2D /* jsonParser.cpp in Sources */,
94280BA32D2FC00200F1CF56 /* base64.cpp in Sources */,
Expand All @@ -3633,6 +3640,7 @@
buildActionMask = 2147483647;
files = (
94CD8BA12D2E8CE500041BBA /* databaseConnection.cpp in Sources */,
941408AF2D59F93F000ED1F9 /* sqlManager.cpp in Sources */,
943398242D57E53400287A2D /* jsonParser.cpp in Sources */,
94280BA42D2FC00200F1CF56 /* base64.cpp in Sources */,
94674B8D2D533E7800973137 /* trade.cpp in Sources */,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// This code is licensed under MIT license (see LICENSE.txt for details)
// ---------------------------------------
#pragma once
#include <chrono>

struct PriceData {
double value1;
Expand Down
File renamed without changes.
File renamed without changes.
18 changes: 18 additions & 0 deletions include/sqlManager.hpp
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;
};
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions scripts/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

# Build the source code
source $current_dir/environment.sh
# source $current_dir/environment.sh - no longer necessary
source $current_dir/clean.sh
source $current_dir/build.sh

Expand Down Expand Up @@ -49,5 +49,5 @@ output=$(echo "$json" | base64)

# Step 6: Run the tests for now (/executable) from the root directory
# Passing two arguements, the destination of the QuestDB and the Strategy JSON (in base64)
./"$BUILD_DIR/$EXECUTABLE_NAME" localhost "$output"
./"$BUILD_DIR/$EXECUTABLE_NAME" 100.85.44.114 "$output"

6 changes: 6 additions & 0 deletions source/jsonParser.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// Backtesting Engine in C++
//
// (c) 2025 Ryan McCaffery | https://mccaffers.com
// This code is licensed under MIT license (see LICENSE.txt for details)
// ---------------------------------------

#include "jsonParser.hpp"
#include "base64.hpp"
#include <iostream>
Expand Down
6 changes: 2 additions & 4 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "trading_definitions.hpp" // For everything
#include "tradeManager.hpp"
#include "jsonParser.hpp"
#include "sqlManager.hpp"

using json = nlohmann::json;

Expand All @@ -33,10 +34,7 @@ int main(int argc, const char * argv[]) {
// Load strategy from Base64 argv[2]
JsonParser::parseConfigurationFromBase64(argv[2]);

// Example query - replace with your actual query
std::string query = "SELECT * FROM EURUSD LIMIT 5;";

std::vector<PriceData> priceData = db.executeQuery(query);
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);
Expand Down
14 changes: 14 additions & 0 deletions source/sqlManager.cpp
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) + ";";
}

std::vector<PriceData> SqlManager::getInitialPriceData(const DatabaseConnection& db) {
return db.executeQuery(getBaseQuery());
}