Skip to content

Commit d71f031

Browse files
authored
10 create end to end trade management logic (#14)
feat: add QuestDB tick streaming with multi-symbol support and refactored trade flow * Integrate QuestDB tick data streaming with multi-symbol loop support * Extract strategy logic for querying QuestDB into dedicated module * Refactor tick flow, operations flow, and trade management operations * Fix run script shell scoping issue (build script running in child process) * Update and stabilise GitHub Actions workflow (macOS target, build & test optimisation) * Update CMakeLists.txt for updated source structure
1 parent 5c0f90d commit d71f031

34 files changed

Lines changed: 603 additions & 354 deletions

.github/workflows/build.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/build.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
pull_request:
6+
types: [opened, synchronize, reopened]
7+
8+
name: Build
9+
10+
env:
11+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
12+
13+
jobs:
14+
build:
15+
name: Build & Test
16+
runs-on: macos-26
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v5
21+
22+
- name: Set up Homebrew
23+
id: set-up-homebrew
24+
uses: Homebrew/actions/setup-homebrew@main
25+
26+
- name: Install dependencies
27+
run: bash ./.github/workflows/scripts/brew.sh
28+
29+
- name: Build C++ Libraries
30+
run: bash ./scripts/build_dep.sh
31+
32+
- name: Select Xcode version
33+
run: sudo xcode-select -switch /Applications/Xcode.app
34+
35+
- name: Run tests
36+
run: >
37+
OTHER_CFLAGS="-fprofile-instr-generate -fcoverage-mapping"
38+
OTHER_CPLUSPLUSFLAGS="-fprofile-instr-generate -fcoverage-mapping"
39+
OTHER_SWIFT_FLAGS="-profile-generate -profile-coverage-mapping"
40+
LLVM_PROFILE_FILE="/tmp/coverage.profraw"
41+
CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO
42+
xcodebuild
43+
-scheme tests
44+
-destination 'platform=macOS'
45+
-resultBundlePath TestResult/
46+
-enableCodeCoverage YES
47+
-derivedDataPath "${RUNNER_TEMP}/Build/DerivedData"
48+
-parallelizeTargets
49+
-jobs "$(sysctl -n hw.logicalcpu)"
50+
HEADER_SEARCH_PATHS="./external/libpqxx/include/pqxx/internal ./external/libpqxx/include/ ./external/libpqxx/build/include/ ./external/"
51+
LIBRARY_SEARCH_PATHS="./external/libpqxx/src/ ./external/libpqxx/build/src/"
52+
OTHER_LDFLAGS="-L./external/libpqxx/build/src -lpqxx -lpq -L$(brew --prefix pkgconf)/lib -L$(brew --prefix pkgconf)/lib/pkgconfig -L$(brew --prefix postgresql@18)/lib/postgresql -L$(brew --prefix postgresql@18)/lib/postgresql/pgxs -L$(brew --prefix postgresql@18)/lib/postgresql/pkgconfig"
53+
clean build test
54+
| xcpretty -r junit && exit ${PIPESTATUS[0]}
55+
56+
- name: Convert coverage report to sonarqube format
57+
run: >
58+
bash ./.github/workflows/scripts/xccov-to-sonarqube-generic.sh *.xcresult/ > sonarqube-generic-coverage.xml
59+
60+
- name: Upload coverage report
61+
uses: actions/upload-artifact@v7
62+
with:
63+
name: sonarqube-coverage
64+
path: sonarqube-generic-coverage.xml
65+
retention-days: 1
File renamed without changes.

.github/workflows/sonar.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
on:
2+
# Triggered on completion of the Build workflow so we can consume its
3+
# coverage artifact. workflow_run fires regardless of whether the upstream
4+
# was triggered by push or pull_request.
5+
workflow_run:
6+
workflows: ["Build"]
7+
types: [completed]
8+
9+
name: SonarCloud Scan
10+
11+
env:
12+
BUILD_TYPE: Release
13+
BUILD_WRAPPER_OUT_DIR: build_wrapper_output_directory # Directory where build-wrapper output will be placed
14+
# Opt into Node.js 24 for JavaScript actions ahead of the June 2026 default switch.
15+
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
16+
17+
jobs:
18+
19+
sonar-scan:
20+
name: SonarCloud Scan
21+
runs-on: ubuntu-latest
22+
# Only run if the upstream Build workflow succeeded.
23+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
24+
steps:
25+
# Check out the same commit the Build workflow ran against. workflow_run
26+
# otherwise defaults to the default branch.
27+
- name: Checkout repository on branch
28+
uses: actions/checkout@v5
29+
with:
30+
ref: ${{ github.event.workflow_run.head_sha }}
31+
fetch-depth: 0
32+
- name: Check compiler version, for debugging
33+
run: |
34+
g++ --version
35+
cmake --version
36+
- name: Build C++ Libraries
37+
run: >
38+
sh ./scripts/build.sh
39+
- name: Install Python 3.12 for gcovr
40+
uses: actions/setup-python@v6
41+
with:
42+
python-version: 3.12
43+
# Gcovr provides a utility for managing the use of the GNU gcov utility and generating
44+
# summarized code coverage results. This command is inspired by the Python coverage.py
45+
# package, which provides a similar utility for Python.
46+
# https://pypi.org/project/gcovr/
47+
- name: Install gcovr
48+
run: |
49+
pip install gcovr==8.3
50+
# SonarQube Server and Cloud (formerly SonarQube and SonarCloud) is a widely used static
51+
# analysis solution for continuous code quality and security inspection.
52+
# This action now supports and is the official entrypoint for scanning C++ projects via GitHub actions.
53+
# https://github.com/SonarSource/sonarqube-scan-action
54+
- name: Install Build Wrapper
55+
uses: SonarSource/sonarqube-scan-action/install-build-wrapper@v4.2.1
56+
# This step installs the SonarQube build wrapper, which is necessary for analyzing C/C++ projects.
57+
58+
# Cross-workflow artifact download. v4 requires run-id and github-token
59+
# when fetching from a different workflow run. The artifact lands at
60+
# ./artifact/sonarqube-generic-coverage.xml so the existing
61+
# sonar.coverageReportPaths argument keeps working unchanged.
62+
- name: Download coverage artifact from Build workflow
63+
uses: actions/download-artifact@v5
64+
with:
65+
name: sonarqube-coverage
66+
path: artifact
67+
run-id: ${{ github.event.workflow_run.id }}
68+
github-token: ${{ secrets.GITHUB_TOKEN }}
69+
70+
# Configures the CMake build system, specifying the source directory and build directory, and setting the build type
71+
- name: Configure CMake
72+
run: cmake -S ${{github.workspace}} -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
73+
74+
# Runs the build wrapper to capture build commands and outputs them to the specified directory. Then builds the project using CMake
75+
- name: Run build-wrapper
76+
run: |
77+
build-wrapper-linux-x86-64 --out-dir ${{ env.BUILD_WRAPPER_OUT_DIR }} cmake --build ${{github.workspace}}/build --config ${{env.BUILD_TYPE}} --clean-first
78+
79+
# Performs the SonarQube scan using the scan action. Uses captured build commands for analysis and requires GitHub and SonarQube tokens for authentication
80+
- name: SonarQube Scan
81+
uses: SonarSource/sonarqube-scan-action@v4.2.1
82+
env:
83+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
85+
with:
86+
args: >
87+
--define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
88+
--define sonar.coverageReportPaths=artifact/sonarqube-generic-coverage.xml

.github/workflows/sonarcloud.yml

Lines changed: 0 additions & 137 deletions
This file was deleted.

.vscode/c_cpp_properties.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"configurations": [
3+
{
4+
"name": "Mac",
5+
"compileCommands": "${workspaceFolder}/build/compile_commands.json",
6+
"includePath": [
7+
"${workspaceFolder}/external/libpqxx/include"
8+
]
9+
}
10+
],
11+
"version": 4
12+
}

CMakeLists.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ project(BacktestingEngine)
1414
set(CMAKE_CXX_STANDARD 20)
1515
set(CMAKE_CXX_STANDARD_REQUIRED ON)
1616

17-
1817
# Configure libpqxx build
1918
set(PQXX_LIBRARIES_INSTALL ON)
2019
set(SKIP_BUILD_TEST ON)
@@ -51,8 +50,18 @@ file(GLOB_RECURSE SOURCES "source/*.cpp")
5150
# Create a library of your project's code
5251
add_library(BacktestingEngineLib STATIC ${SOURCES})
5352

54-
# Link against pqxx
55-
target_link_libraries(BacktestingEngineLib pqxx)
53+
# Configure OpenMP. On Apple, provide Homebrew libomp hints before discovery.
54+
if(APPLE)
55+
set(OpenMP_C_FLAGS "-Xclang -fopenmp")
56+
set(OpenMP_CXX_FLAGS "-Xclang -fopenmp")
57+
set(OpenMP_C_LIB_NAMES "omp")
58+
set(OpenMP_CXX_LIB_NAMES "omp")
59+
set(OpenMP_omp_LIBRARY /opt/homebrew/opt/libomp/lib/libomp.dylib)
60+
target_include_directories(BacktestingEngineLib PRIVATE /opt/homebrew/opt/libomp/include)
61+
endif()
62+
63+
find_package(OpenMP REQUIRED)
64+
target_link_libraries(BacktestingEngineLib PUBLIC pqxx OpenMP::OpenMP_CXX)
5665

5766
# Main executable
5867
add_executable(BacktestingEngine source/main.cpp)

0 commit comments

Comments
 (0)