Skip to content

Commit 61309bd

Browse files
mccaffersCopilot
andauthored
Apply suggestions from code review
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 46e720d commit 61309bd

7 files changed

Lines changed: 20 additions & 12 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,17 @@ file(GLOB_RECURSE SOURCES "source/*.cpp")
5050
# Create a library of your project's code
5151
add_library(BacktestingEngineLib STATIC ${SOURCES})
5252

53-
# Replace find_package(OpenMP REQUIRED) with this:
53+
# Configure OpenMP. On Apple, provide Homebrew libomp hints before discovery.
5454
if(APPLE)
5555
set(OpenMP_C_FLAGS "-Xclang -fopenmp")
5656
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
5757
set(OpenMP_C_LIB_NAMES "omp")
5858
set(OpenMP_CXX_LIB_NAMES "omp")
5959
set(OpenMP_omp_LIBRARY /opt/homebrew/opt/libomp/lib/libomp.dylib)
60-
find_package(OpenMP REQUIRED)
6160
target_include_directories(BacktestingEngineLib PRIVATE /opt/homebrew/opt/libomp/include)
6261
endif()
6362

63+
find_package(OpenMP REQUIRED)
6464
target_link_libraries(BacktestingEngineLib PUBLIC pqxx OpenMP::OpenMP_CXX)
6565

6666
# Main executable

include/databaseConnection.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ class DatabaseConnection {
2020
const std::string& password = "");
2121

2222
void printResults(const std::vector<PriceData>& results) const;
23-
std::vector<PriceData> executeQuery(const std::string& query) const;
2423
std::vector<PriceData> streamQuery(const std::string& query) const;
2524

2625
const std::string& getConnectionString() const {

scripts/run.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,8 @@ current_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
55

66
# Build the source code
77
# source $current_dir/environment.sh - no longer necessary
8-
source $current_dir/clean.sh
9-
source $current_dir/build.sh
10-
if [ $? -ne 0 ]; then
8+
source "$current_dir/clean.sh"
9+
if ! bash "$current_dir/build.sh"; then
1110
echo "Error: Build failed. Aborting."
1211
exit 1
1312
fi

source/databaseConnection.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
#include <pqxx/pqxx>
1010
#include <cstdio>
1111
#include <charconv>
12-
#include <execution>
13-
#include <algorithm>
12+
#include <stdexcept>
1413

1514
static std::chrono::system_clock::time_point fastParseTimestamp(const char* ts) {
16-
int year, month, day, hour, min, sec, usec = 0;
17-
std::sscanf(ts, "%4d-%2d-%2d %2d:%2d:%2d.%d", &year, &month, &day, &hour, &min, &sec, &usec);
15+
int year = 0, month = 0, day = 0, hour = 0, min = 0, sec = 0, usec = 0;
16+
const int parsedFields =
17+
std::sscanf(ts, "%4d-%2d-%2d %2d:%2d:%2d.%d", &year, &month, &day, &hour, &min, &sec, &usec);
18+
if (parsedFields != 6 && parsedFields != 7) {
19+
throw std::runtime_error("Invalid timestamp format");
20+
}
1821

1922
// Cache timegm per date — tick data is time-ordered so date changes rarely
2023
static char cachedDate[11] = {};
@@ -53,7 +56,7 @@ std::vector<PriceData> DatabaseConnection::streamQuery(const std::string& query)
5356

5457
std::vector<PriceData> results(result.size());
5558

56-
for (int i = 0; i < (int)result.size(); ++i) {
59+
for (std::size_t i = 0; i < result.size(); ++i) {
5760
const auto& row = result[i];
5861
double ask, bid;
5962
auto symbol = row[0].view();

source/main.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ using json = nlohmann::json;
3232
// argv[2] — Base64-encoded JSON strategy configuration
3333
int main(int argc, const char * argv[]) {
3434

35+
if (argc < 3) {
36+
std::cerr << "Usage: " << argv[0] << " <questdb-host> <base64-config>" << std::endl;
37+
return 1;
38+
}
3539
DatabaseConnection db(argv[1], 8812, "qdb", "admin", "quest");
3640

3741
JsonParser::parseConfigurationFromBase64(argv[2]);

source/operations.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
#include <memory>
1212
#include <string>
1313
#include <iomanip>
14+
#include <cstdio>
15+
#include <ctime>
1416
#include "tradeManager.hpp"
1517

1618
void Operations::run(const std::vector<PriceData>& ticks) {
1719

18-
// Loop aroudn every tick
20+
// Loop around every tick
1921
// Example output:
2022
// symbol=AUSIDXAUD, ask=8602.4000, bid=8599.4000 timestamp=2026-03-12 18:39:01.076
2123
// symbol=AUSIDXAUD, ask=8602.9000, bid=8599.9000 timestamp=2026-03-12 18:39:01.584

source/sqlManager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
// This code is licensed under MIT license (see LICENSE.txt for details)
55
// ---------------------------------------
66
#include "sqlManager.hpp"
7+
#include <iostream>
78
#include <string>
89
#include <vector>
910

0 commit comments

Comments
 (0)