├── .clang-format
├── .conan
└── profiles
│ ├── arch
│ ├── x64
│ └── x86
│ ├── clang
│ └── 15
│ │ ├── compiler
│ │ ├── x64-libc++-debug
│ │ └── x64-libc++-release
│ ├── compiler
│ ├── clang
│ ├── gcc
│ └── msvc
│ ├── config
│ ├── debug
│ └── release
│ ├── cpp
│ └── 20
│ ├── gcc
│ └── 12
│ │ ├── compiler
│ │ ├── x64-libstdc++11-debug
│ │ └── x64-libstdc++11-release
│ ├── msvc
│ └── 193
│ │ ├── compiler
│ │ ├── x64-debug
│ │ └── x64-release
│ ├── os
│ └── current
│ └── stl
│ ├── libc++
│ └── libstdc++11
├── .conanrc
├── .github
└── workflows
│ └── cmake.yml
├── .gitignore
├── .vscode
├── c_cpp_properties.json
├── launch.json
├── settings.json
└── tasks.json
├── CMakeLists.txt
├── LICENSE
├── README.md
├── assets
└── images
│ └── heisenberg_photo.jpg
├── cmake
├── clang_format.cmake
└── cpp_crypto_algos_config.hpp.in
├── conanfile.txt
├── requirements.txt
├── resources
├── ComputationalFinanceInCPPWithDomainArchitectures.pdf
├── MLInvestmentMethodology.pptx
├── UniqueOptionPricingMeasureWithNeitherDynamicHedging_nor_CompleteMarkets.pdf
├── optimising_c_code_for_low_latency__1659984565.pdf
└── qanda.pdf
├── src
├── .clang-format
├── CMakeLists.txt
├── algo.hpp
├── apps
│ ├── CMakeLists.txt
│ ├── algo
│ │ ├── CMakeLists.txt
│ │ └── algo.cpp
│ ├── execute_order
│ │ ├── CMakeLists.txt
│ │ └── execute_order.cpp
│ ├── experiment
│ │ ├── CMakeLists.txt
│ │ └── experiment.cpp
│ └── streamer
│ │ ├── CMakeLists.txt
│ │ └── streamer.cpp
├── cc_damped_mr.hpp
├── cc_kaufman.hpp
├── cc_simple_mr.hpp
├── cc_trade_handler.hpp
├── cc_trade_stream.hpp
├── ccex_order_executor.hpp
├── enum.hpp
├── exchange.hpp
├── order_executor.hpp
├── order_type.hpp
├── program_options.hpp
├── side.hpp
├── trade_data.hpp
├── trade_stream.hpp
├── trade_stream_exception.hpp
├── trade_stream_maker.hpp
├── utils.hpp
└── wscc_trade_stream.hpp
├── talks
├── antony
│ ├── C++20 Techniques For Algorithmic Trading.pdf
│ └── README.md
├── jahan
│ └── README.md
├── rainer
│ ├── Concepts
│ │ ├── Concepts.pdf
│ │ ├── account1.cpp
│ │ ├── account2.cpp
│ │ ├── account3.cpp
│ │ ├── account4.cpp
│ │ ├── account5.cpp
│ │ └── account6.cpp
│ ├── ExtendPythonWithCpp
│ │ ├── Embed
│ │ │ ├── myMath.py
│ │ │ └── runPythonFunction.c
│ │ ├── Extend
│ │ │ ├── Native
│ │ │ │ └── setup.py
│ │ │ ├── SWIG
│ │ │ │ ├── helloWorld.c
│ │ │ │ ├── helloWorld.h
│ │ │ │ ├── helloWorld.i
│ │ │ │ └── setup.py
│ │ │ ├── SharedLibrary
│ │ │ │ ├── helloWorld.c
│ │ │ │ ├── helloWorld.h
│ │ │ │ └── main.c
│ │ │ └── pybind11
│ │ │ │ ├── function.cpp
│ │ │ │ └── human.cpp
│ │ └── ExtendEmbedC++Python.pdf
│ ├── README.md
│ └── Ranges
│ │ ├── Ranges.pdf
│ │ ├── begin.cpp
│ │ ├── rangesAccess.cpp
│ │ ├── rangesComposition.cpp
│ │ ├── rangesEntireContainer.cpp
│ │ ├── rangesFilterTransform.cpp
│ │ ├── rangesLazy.cpp
│ │ └── sortRanges.cpp
└── richard
│ └── README.md
└── windows.md
/.clang-format:
--------------------------------------------------------------------------------
1 | Language: Cpp
2 | Standard: Latest
3 |
4 | ColumnLimit: 120
5 | IndentWidth: 4
6 | UseTab: Never
7 |
8 | BreakBeforeBraces: Custom
9 | BraceWrapping:
10 | AfterCaseLabel: true
11 | AfterClass: true
12 | AfterControlStatement: Always
13 | AfterEnum: true
14 | AfterFunction: true
15 | AfterNamespace: true
16 | AfterStruct: true
17 | AfterUnion: true
18 | AfterExternBlock: true
19 | BeforeCatch: true
20 | BeforeElse: true
21 | BeforeLambdaBody: true
22 | BeforeWhile: true
23 | IndentBraces: false
24 | SplitEmptyFunction: false
25 | SplitEmptyRecord: false
26 | SplitEmptyNamespace: false
27 | BreakBeforeBinaryOperators: None
28 | BreakBeforeTernaryOperators: true
29 | BreakBeforeConceptDeclarations: true
30 | BreakConstructorInitializers: BeforeComma
31 | BreakInheritanceList: BeforeComma
32 | ConstructorInitializerAllOnOneLineOrOnePerLine: false
33 | ConstructorInitializerIndentWidth: 4
34 | ContinuationIndentWidth: 4
35 | Cpp11BracedListStyle: true
36 |
37 | EmptyLineBeforeAccessModifier: LogicalBlock
38 | IncludeBlocks: Preserve
39 |
40 | IndentCaseBlocks: false
41 | IndentCaseLabels: false
42 | IndentWrappedFunctionNames: true
43 | IndentExternBlock: Indent
44 | IndentPPDirectives: AfterHash
45 | IndentRequires: true
46 | LambdaBodyIndentation: Signature
47 | MaxEmptyLinesToKeep: 1
48 | NamespaceIndentation: Inner
49 |
50 | SpaceAfterTemplateKeyword: false
51 | SpaceAroundPointerQualifiers: Default
52 | SpaceBeforeCaseColon: false
53 | SpaceBeforeCpp11BracedList: false
54 | SpaceBeforeCtorInitializerColon: true
55 | SpaceBeforeInheritanceColon: true
56 | SpaceBeforeParens: ControlStatements
57 | SpaceBeforeRangeBasedForLoopColon: true
58 | SpaceBeforeSquareBrackets: false
59 | SpaceInEmptyBlock: false
60 | SpaceInEmptyParentheses: false
61 | SpacesBeforeTrailingComments: 4
62 | SpacesInCStyleCastParentheses: false
63 | SpacesInConditionalStatement: false
64 | SpacesInContainerLiterals: false
65 | SpacesInParentheses: false
66 | SpacesInSquareBrackets: false
67 |
68 | SortIncludes: CaseSensitive
69 | SortUsingDeclarations: true
70 |
71 | AccessModifierOffset: -4
72 | PointerAlignment: Left
73 | AlignAfterOpenBracket: AlwaysBreak
74 | AlignArrayOfStructures: Left
75 | AlignConsecutiveAssignments: None
76 | AlignConsecutiveBitFields: AcrossComments
77 | AlignConsecutiveDeclarations: None
78 | AlignConsecutiveMacros: None
79 | AlignEscapedNewlines: Left
80 | AlignOperands: AlignAfterOperator
81 | AlignTrailingComments: true
82 | AllowShortBlocksOnASingleLine: Always
83 | AllowAllParametersOfDeclarationOnNextLine: true
84 | AllowShortCaseLabelsOnASingleLine: true
85 | AllowShortEnumsOnASingleLine: true
86 | AllowShortFunctionsOnASingleLine: All
87 | AllowShortIfStatementsOnASingleLine: Never
88 | AllowShortLambdasOnASingleLine: All
89 | AllowShortLoopsOnASingleLine: false
90 | AlwaysBreakTemplateDeclarations: Yes
91 | BinPackArguments: false
92 | BinPackParameters: false
93 | BitFieldColonSpacing: After
94 |
95 | CompactNamespaces: true
96 | FixNamespaceComments: true
--------------------------------------------------------------------------------
/.conan/profiles/arch/x64:
--------------------------------------------------------------------------------
1 | [settings]
2 | arch=x86_64
3 |
--------------------------------------------------------------------------------
/.conan/profiles/arch/x86:
--------------------------------------------------------------------------------
1 | [settings]
2 | arch=x86
3 |
--------------------------------------------------------------------------------
/.conan/profiles/clang/15/compiler:
--------------------------------------------------------------------------------
1 | include(../../compiler/clang)
2 |
3 | [settings]
4 | compiler.version=15
5 |
--------------------------------------------------------------------------------
/.conan/profiles/clang/15/x64-libc++-debug:
--------------------------------------------------------------------------------
1 | include(../../default)
2 | include(../../arch/x64)
3 | include(../../cpp/20)
4 | include(../../config/debug)
5 | include(../../os/current)
6 | include(compiler)
7 |
--------------------------------------------------------------------------------
/.conan/profiles/clang/15/x64-libc++-release:
--------------------------------------------------------------------------------
1 | include(../../default)
2 | include(../../arch/x64)
3 | include(../../cpp/20)
4 | include(../../config/release)
5 | include(../../os/current)
6 | include(compiler)
7 |
--------------------------------------------------------------------------------
/.conan/profiles/compiler/clang:
--------------------------------------------------------------------------------
1 | include(../stl/libc++)
2 |
3 | [settings]
4 | compiler=clang
5 |
--------------------------------------------------------------------------------
/.conan/profiles/compiler/gcc:
--------------------------------------------------------------------------------
1 | include(../stl/libstdc++11)
2 |
3 | [settings]
4 | compiler=gcc
5 |
--------------------------------------------------------------------------------
/.conan/profiles/compiler/msvc:
--------------------------------------------------------------------------------
1 | [settings]
2 | compiler=msvc
3 |
--------------------------------------------------------------------------------
/.conan/profiles/config/debug:
--------------------------------------------------------------------------------
1 | [settings]
2 | build_type=Debug
3 |
--------------------------------------------------------------------------------
/.conan/profiles/config/release:
--------------------------------------------------------------------------------
1 | [settings]
2 | build_type=Release
3 |
--------------------------------------------------------------------------------
/.conan/profiles/cpp/20:
--------------------------------------------------------------------------------
1 | [settings]
2 | compiler.cppstd=20
3 |
--------------------------------------------------------------------------------
/.conan/profiles/gcc/12/compiler:
--------------------------------------------------------------------------------
1 | include(../../compiler/gcc)
2 |
3 | [settings]
4 | compiler.version=12
5 |
--------------------------------------------------------------------------------
/.conan/profiles/gcc/12/x64-libstdc++11-debug:
--------------------------------------------------------------------------------
1 | include(../../default)
2 | include(../../arch/x64)
3 | include(../../cpp/20)
4 | include(../../config/debug)
5 | include(../../os/current)
6 | include(compiler)
7 |
--------------------------------------------------------------------------------
/.conan/profiles/gcc/12/x64-libstdc++11-release:
--------------------------------------------------------------------------------
1 | include(../../default)
2 | include(../../arch/x64)
3 | include(../../cpp/20)
4 | include(../../config/release)
5 | include(../../os/current)
6 | include(compiler)
7 |
--------------------------------------------------------------------------------
/.conan/profiles/msvc/193/compiler:
--------------------------------------------------------------------------------
1 | include(../../compiler/msvc)
2 |
3 | [settings]
4 | compiler.version=193
5 | compiler.runtime=dynamic
6 |
--------------------------------------------------------------------------------
/.conan/profiles/msvc/193/x64-debug:
--------------------------------------------------------------------------------
1 | include(../../default)
2 | include(../../arch/x64)
3 | include(../../cpp/20)
4 | include(../../config/debug)
5 | include(../../os/current)
6 | include(compiler)
7 |
--------------------------------------------------------------------------------
/.conan/profiles/msvc/193/x64-release:
--------------------------------------------------------------------------------
1 | include(../../default)
2 | include(../../arch/x64)
3 | include(../../cpp/20)
4 | include(../../config/release)
5 | include(../../os/current)
6 | include(compiler)
7 |
--------------------------------------------------------------------------------
/.conan/profiles/os/current:
--------------------------------------------------------------------------------
1 | [settings]
2 | os = {{ {"Darwin": "Macos"}.get(platform.system(), platform.system()) }}
3 |
--------------------------------------------------------------------------------
/.conan/profiles/stl/libc++:
--------------------------------------------------------------------------------
1 | [settings]
2 | compiler.libcxx=libc++
3 |
--------------------------------------------------------------------------------
/.conan/profiles/stl/libstdc++11:
--------------------------------------------------------------------------------
1 | [settings]
2 | compiler.libcxx=libstdc++11
3 |
--------------------------------------------------------------------------------
/.conanrc:
--------------------------------------------------------------------------------
1 | conan_home=./.conan2
2 |
--------------------------------------------------------------------------------
/.github/workflows/cmake.yml:
--------------------------------------------------------------------------------
1 | name: CMake
2 |
3 | on:
4 | push:
5 | branches: [main]
6 | pull_request:
7 | branches: [main]
8 |
9 | jobs:
10 | build:
11 | name: ${{ matrix.settings.name }} ${{ matrix.configuration }}
12 | runs-on: ${{ matrix.settings.os }}
13 | strategy:
14 | matrix:
15 | configuration: [ "Release", "Debug" ]
16 | settings:
17 | - {
18 | name: "Ubuntu GCC-12",
19 | os: ubuntu-latest,
20 | compiler: { type: GCC, version: 12, conan: "gcc", cc: "gcc-12", cxx: "g++-12", std: 20 },
21 | lib: "libstdc++11"
22 | }
23 | - {
24 | name: "Ubuntu Clang-15 + libc++",
25 | os: ubuntu-latest,
26 | compiler: { type: CLANG, version: 15, conan: "clang", cc: "clang-15", cxx: "clang++-15", std: 20 },
27 | lib: "libc++",
28 | }
29 | - {
30 | name: "Visual Studio 2019",
31 | os: windows-latest,
32 | compiler: { type: VISUAL, version: 16, conan: "mscv", cc: "cl", cxx: "cl", std: 20 },
33 | }
34 |
35 | steps:
36 | - uses: actions/checkout@v2
37 |
38 | - name: Cache Conan data
39 | uses: actions/cache@v3
40 | env:
41 | cache-name: cache-conan-data
42 | with:
43 | path: ${{github.workspace}}/.conan2/p
44 | key: ${{ hashFiles('**/conanfile.py') }}-build-${{ matrix.settings.os }}-${{ matrix.configuration }}-${{ matrix.settings.compiler.conan }}-${{ matrix.settings.compiler.version }}-${{ matrix.settings.lib }}
45 | restore-keys: |
46 | ${{ hashFiles('**/conanfile.py') }}-build-${{ matrix.settings.os }}-${{ matrix.configuration }}-${{ matrix.settings.compiler.conan }}-${{ matrix.settings.compiler.version }}-
47 | ${{ hashFiles('**/conanfile.py') }}-build-${{ matrix.settings.os }}-${{ matrix.configuration }}-${{ matrix.settings.compiler.conan }}-
48 | ${{ hashFiles('**/conanfile.py') }}-build-${{ matrix.settings.os }}-${{ matrix.configuration }}-
49 | ${{ hashFiles('**/conanfile.py') }}-build-${{ matrix.settings.os }}-
50 |
51 | - name: Add msbuild to PATH
52 | if: matrix.settings.os == 'windows-latest'
53 | uses: microsoft/setup-msbuild@v1.3
54 | with:
55 | vs-version: "16.5"
56 |
57 | - name: Install Latest GCC
58 | if: matrix.settings.compiler.type == 'GCC'
59 | uses: egor-tensin/setup-gcc@v1
60 | with:
61 | version: ${{ matrix.settings.compiler.version }}
62 | platform: x64
63 |
64 | - name: Install Latest libstdC++11
65 | if: matrix.settings.compiler.type == 'CLANG' && matrix.settings.lib == 'libstdc++11'
66 | uses: egor-tensin/setup-gcc@v1
67 | with:
68 | version: 12
69 | platform: x64
70 |
71 | - name: Install Clang
72 | if: matrix.settings.compiler.type == 'CLANG'
73 | uses: egor-tensin/setup-clang@v1
74 | with:
75 | version: ${{ matrix.settings.compiler.version }}
76 | platform: x64
77 |
78 | - name: Install Libc++
79 | if: matrix.settings.compiler.type == 'CLANG' && matrix.settings.lib == 'libc++'
80 | shell: bash
81 | run: |
82 | sudo apt install -y libc++-${{ matrix.settings.compiler.version }}-dev libc++abi-${{ matrix.settings.compiler.version }}-dev libunwind-${{ matrix.settings.compiler.version }}-dev
83 |
84 | - name: Set up Python
85 | uses: actions/setup-python@v2
86 | with:
87 | python-version: '3.11'
88 |
89 | - name: Install Python requirements
90 | run: |
91 | pip install -r ./requirements.txt
92 |
93 | - name: Configure Conan
94 | shell: bash
95 | run: |
96 | conan profile detect --force
97 | sed -i.backup '/^\[settings\]$/,/^\[/ s/^build_type=.*/build_type=${{ matrix.configuration }}/' .conan2/profiles/default
98 | sed -i.backup '/^\[settings\]$/,/^\[/ s/^compiler.cppstd=.*/compiler.cppstd=${{ matrix.settings.compiler.std }}/' .conan2/profiles/default
99 | if [[ "${{ matrix.settings.compiler.type }}" == "GCC" || "${{ matrix.settings.compiler.type }}" == "CLANG" ]]; then
100 | sed -i.backup '/^\[settings\]$/,/^\[/ s/^compiler=.*/compiler=${{ matrix.settings.compiler.conan }}/' .conan2/profiles/default
101 | sed -i.backup '/^\[settings\]$/,/^\[/ s/^compiler.version=.*/compiler.version=${{ matrix.settings.compiler.version }}/' .conan2/profiles/default
102 | sed -i.backup '/^\[settings\]$/,/^\[/ s/^compiler.libcxx=.*/compiler.libcxx=${{ matrix.settings.lib }}/' .conan2/profiles/default
103 | fi
104 | conan profile show -pr default
105 |
106 | - name: Configure Install
107 | if: matrix.settings.os == 'windows-latest'
108 | shell: bash
109 | run: |
110 | conan install "${{github.workspace}}" --build missing -pr:b default -g VCVars -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" -of ./build
111 |
112 | - name: Configure Install
113 | if: matrix.settings.os != 'windows-latest'
114 | shell: bash
115 | run: |
116 | conan install "${{github.workspace}}" --build missing -pr:b default -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config" -of ./build
117 |
118 | - name: Configure CMake
119 | if: matrix.settings.os == 'windows-latest'
120 | shell: cmd
121 | run: |
122 | call build\conanvcvars.bat
123 | call build\conanbuild.bat
124 | cmake --preset conan-default
125 |
126 | - name: Configure CMake
127 | if: matrix.settings.os != 'windows-latest'
128 | shell: bash
129 | run: |
130 | source build/conanbuild.sh
131 | cmake --preset conan-default
132 |
133 | - name: Conan Preset
134 | shell: bash
135 | run: echo "CONAN_PRESET=conan-$(echo ${{matrix.configuration}} | tr '[:upper:]' '[:lower:]')" >> $GITHUB_ENV
136 |
137 | - name: Build
138 | if: matrix.settings.os == 'windows-latest'
139 | shell: cmd
140 | run: |
141 | call build\conanbuild.bat
142 | cmake --build --preset ${{ env.CONAN_PRESET }}
143 |
144 | - name: Build
145 | if: matrix.settings.os != 'windows-latest'
146 | shell: bash
147 | run: |
148 | source build/conanbuild.sh
149 | cmake --build --preset ${{ env.CONAN_PRESET }}
150 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Compiled Object files
5 | *.slo
6 | *.lo
7 | *.o
8 | *.obj
9 |
10 | # Precompiled Headers
11 | *.gch
12 | *.pch
13 |
14 | # Compiled Dynamic libraries
15 | *.so
16 | *.dylib
17 | *.dll
18 |
19 | # Fortran module files
20 | *.mod
21 | *.smod
22 |
23 | # Compiled Static libraries
24 | *.lai
25 | *.la
26 | *.a
27 | *.lib
28 |
29 | # Executables
30 | *.exe
31 | *.out
32 | *.app
33 |
34 | build/*
35 | .venv/*
36 |
37 | # Visual Studio artifacts
38 | .vs
39 | [Oo]ut
40 |
41 | # Conan2 directory
42 | .conan2
43 |
44 | # CMake build artifacts
45 | CMakeUserPresets.json
46 |
--------------------------------------------------------------------------------
/.vscode/c_cpp_properties.json:
--------------------------------------------------------------------------------
1 | {
2 | "configurations": [
3 | {
4 | "name": "Linux",
5 | "includePath": [
6 | "${workspaceFolder}/**",
7 | "${workspaceFolder}/build/_deps/ccapi-src/include/**",
8 | "${workspaceFolder}/build/_deps/websocketpp-src/websocketpp/**",
9 | "~/.conan/data/**",
10 | "${workspaceFolder}/src/**"
11 | ],
12 | "defines": [],
13 | "compilerPath": "/usr/bin/g++-11",
14 | "cStandard": "c17",
15 | "cppStandard": "c++20",
16 | "intelliSenseMode": "linux-gcc-x64",
17 | "configurationProvider": "ms-vscode.cmake-tools"
18 | }
19 | ],
20 | "version": 4
21 | }
--------------------------------------------------------------------------------
/.vscode/launch.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "0.2.0",
3 | "configurations": [
4 | {
5 | "name": "(gdb) execute_order - FTX",
6 | "type": "cppdbg",
7 | "request": "launch",
8 | "program": "${workspaceFolder}/build/bin/execute_order",
9 | "args":
10 | [ "--exchange=ftx"
11 | , "--symbol=BTC-PERP"
12 | , "--api_key=${env:FTX_API_KEY}"
13 | , "--api_secret=${env:FTX_API_SECRET}"
14 | , "--side=buy"
15 | , "--size=0.0025"
16 | , "--type=market"
17 | ],
18 | "stopAtEntry": false,
19 | "cwd": "${fileDirname}",
20 | "environment": [],
21 | "externalConsole": false,
22 | "MIMode": "gdb",
23 | "setupCommands": [
24 | {
25 | "description": "Enable pretty-printing for gdb",
26 | "text": "-enable-pretty-printing",
27 | "ignoreFailures": true
28 | },
29 | {
30 | "description": "Set Disassembly Flavor to Intel",
31 | "text": "-gdb-set disassembly-flavor intel",
32 | "ignoreFailures": true
33 | }
34 | ]
35 | },
36 | {
37 | "name": "(gdb) streamer - FTX",
38 | "type": "cppdbg",
39 | "request": "launch",
40 | "program": "${workspaceFolder}/build/bin/streamer",
41 | "args":
42 | [ "--exchange", "ftx"
43 | , "--symbols", "BTC-PERP", "SOL-PERP"
44 | ],
45 | "stopAtEntry": false,
46 | "cwd": "${fileDirname}",
47 | "environment": [],
48 | "externalConsole": false,
49 | "MIMode": "gdb",
50 | "setupCommands": [
51 | {
52 | "description": "Enable pretty-printing for gdb",
53 | "text": "-enable-pretty-printing",
54 | "ignoreFailures": true
55 | },
56 | {
57 | "description": "Set Disassembly Flavor to Intel",
58 | "text": "-gdb-set disassembly-flavor intel",
59 | "ignoreFailures": true
60 | }
61 | ]
62 | },
63 | {
64 | "name": "(gdb) algo - FTX - SimpleMR",
65 | "type": "cppdbg",
66 | "request": "launch",
67 | "program": "${workspaceFolder}/build/bin/algo",
68 | "args":
69 | [ "--algo=SimpleMR"
70 | , "--exchange=ftx"
71 | , "--api_key=${env:FTX_API_KEY}"
72 | , "--api_secret=${env:FTX_API_SECRET}"
73 | , "--lookback=50"
74 | , "--reversion_level=2"
75 | , "--base_quantity=0.0025"
76 | , "--symbols=BTC-PERP"
77 | ],
78 | "stopAtEntry": false,
79 | "cwd": "${workspaceFolder}",
80 | "environment": [],
81 | "externalConsole": false,
82 | "MIMode": "gdb",
83 | "setupCommands": [
84 | {
85 | "description": "Enable pretty-printing for gdb",
86 | "text": "-enable-pretty-printing",
87 | "ignoreFailures": true
88 | },
89 | {
90 | "description": "Set Disassembly Flavor to Intel",
91 | "text": "-gdb-set disassembly-flavor intel",
92 | "ignoreFailures": true
93 | }
94 | ],
95 | // "preLaunchTask": "CMake build project",
96 | "miDebuggerPath": "/usr/bin/gdb",
97 | },
98 | {
99 | "name": "(gdb) algo - FTX - Damped",
100 | "type": "cppdbg",
101 | "request": "launch",
102 | "program": "${workspaceFolder}/build/bin/algo",
103 | "args":
104 | [ "--algo=Damped"
105 | , "--exchange=ftx"
106 | , "--api_key=${env:FTX_API_KEY}"
107 | , "--api_secret=${env:FTX_API_SECRET}"
108 | , "--sub_account=Webinar"
109 | , "--lookback=50"
110 | , "--reversion_level=2"
111 | , "--base_quantity=0.0025"
112 | , "--damping=2.5"
113 | , "--symbols=ETH-PERP"
114 | ],
115 | "stopAtEntry": false,
116 | "cwd": "${workspaceFolder}",
117 | "environment": [],
118 | "externalConsole": false,
119 | "MIMode": "gdb",
120 | "setupCommands": [
121 | {
122 | "description": "Enable pretty-printing for gdb",
123 | "text": "-enable-pretty-printing",
124 | "ignoreFailures": true
125 | },
126 | {
127 | "description": "Set Disassembly Flavor to Intel",
128 | "text": "-gdb-set disassembly-flavor intel",
129 | "ignoreFailures": true
130 | }
131 | ],
132 | // "preLaunchTask": "CMake build project",
133 | "miDebuggerPath": "/usr/bin/gdb",
134 | },
135 | {
136 | "name": "(gdb) experiment",
137 | "type": "cppdbg",
138 | "request": "launch",
139 | "program": "${workspaceFolder}/build/bin/experiment",
140 | "args":
141 | [ "--name", "test"
142 | , "--er_period", "8"
143 | ],
144 | "stopAtEntry": false,
145 | "cwd": "${fileDirname}",
146 | "environment": [],
147 | "externalConsole": false,
148 | "MIMode": "gdb",
149 | "setupCommands": [
150 | {
151 | "description": "Enable pretty-printing for gdb",
152 | "text": "-enable-pretty-printing",
153 | "ignoreFailures": true
154 | },
155 | {
156 | "description": "Set Disassembly Flavor to Intel",
157 | "text": "-gdb-set disassembly-flavor intel",
158 | "ignoreFailures": true
159 | }
160 | ]
161 | },
162 | ]
163 | }
--------------------------------------------------------------------------------
/.vscode/settings.json:
--------------------------------------------------------------------------------
1 | {
2 | "files.associations": {
3 | "*.in": "cpp",
4 | "array": "cpp",
5 | "cctype": "cpp",
6 | "clocale": "cpp",
7 | "cmath": "cpp",
8 | "csignal": "cpp",
9 | "cstdarg": "cpp",
10 | "cstddef": "cpp",
11 | "cstdio": "cpp",
12 | "cstdlib": "cpp",
13 | "cstring": "cpp",
14 | "ctime": "cpp",
15 | "cwchar": "cpp",
16 | "cwctype": "cpp",
17 | "*.ipp": "cpp",
18 | "any": "cpp",
19 | "atomic": "cpp",
20 | "strstream": "cpp",
21 | "bit": "cpp",
22 | "*.tcc": "cpp",
23 | "bitset": "cpp",
24 | "cfenv": "cpp",
25 | "chrono": "cpp",
26 | "codecvt": "cpp",
27 | "compare": "cpp",
28 | "complex": "cpp",
29 | "concepts": "cpp",
30 | "condition_variable": "cpp",
31 | "coroutine": "cpp",
32 | "cstdint": "cpp",
33 | "deque": "cpp",
34 | "list": "cpp",
35 | "map": "cpp",
36 | "set": "cpp",
37 | "unordered_map": "cpp",
38 | "unordered_set": "cpp",
39 | "vector": "cpp",
40 | "exception": "cpp",
41 | "algorithm": "cpp",
42 | "functional": "cpp",
43 | "iterator": "cpp",
44 | "memory": "cpp",
45 | "memory_resource": "cpp",
46 | "numeric": "cpp",
47 | "optional": "cpp",
48 | "random": "cpp",
49 | "ratio": "cpp",
50 | "source_location": "cpp",
51 | "string": "cpp",
52 | "string_view": "cpp",
53 | "system_error": "cpp",
54 | "tuple": "cpp",
55 | "type_traits": "cpp",
56 | "utility": "cpp",
57 | "rope": "cpp",
58 | "slist": "cpp",
59 | "fstream": "cpp",
60 | "future": "cpp",
61 | "initializer_list": "cpp",
62 | "iomanip": "cpp",
63 | "iosfwd": "cpp",
64 | "iostream": "cpp",
65 | "istream": "cpp",
66 | "limits": "cpp",
67 | "mutex": "cpp",
68 | "new": "cpp",
69 | "numbers": "cpp",
70 | "ostream": "cpp",
71 | "ranges": "cpp",
72 | "shared_mutex": "cpp",
73 | "span": "cpp",
74 | "sstream": "cpp",
75 | "stdexcept": "cpp",
76 | "stop_token": "cpp",
77 | "streambuf": "cpp",
78 | "thread": "cpp",
79 | "cinttypes": "cpp",
80 | "typeindex": "cpp",
81 | "typeinfo": "cpp",
82 | "valarray": "cpp",
83 | "variant": "cpp",
84 | "regex": "cpp",
85 | "semaphore": "cpp",
86 | "cassert": "cpp",
87 | "cerrno": "cpp",
88 | "ciso646": "cpp",
89 | "climits": "cpp",
90 | "filesystem": "cpp",
91 | "ios": "cpp",
92 | "locale": "cpp",
93 | "queue": "cpp",
94 | "stack": "cpp",
95 | "version": "cpp"
96 | }
97 | }
--------------------------------------------------------------------------------
/.vscode/tasks.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": "2.0.0",
3 | "tasks": [
4 | {
5 | "type": "shell",
6 | "label": "CMake build project",
7 | "options": {
8 | "cwd": "${workspaceFolder}/build"
9 | },
10 | "command": "cmake -DCMAKE_BUILD_TYPE=Debug .. && cmake --build . 2>&1|tee cmake.out",
11 | "group": {
12 | "kind": "build",
13 | "isDefault": true
14 | },
15 | "problemMatcher": []
16 | }
17 | ]
18 | }
--------------------------------------------------------------------------------
/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.27)
2 |
3 | # set the project name
4 | project(cpp_crypto_algos LANGUAGES CXX VERSION 2.0)
5 |
6 | include(FetchContent)
7 |
8 | FetchContent_Declare(
9 | ccapi
10 | GIT_REPOSITORY https://github.com/profitviews/ccapi.git
11 | GIT_TAG windows-msvc
12 | )
13 | FetchContent_Declare(
14 | websocketpp
15 | GIT_REPOSITORY https://github.com/zaphoyd/websocketpp.git
16 | GIT_TAG develop
17 | )
18 | FetchContent_Declare(
19 | csv2
20 | GIT_REPOSITORY https://github.com/p-ranav/csv2
21 | GIT_TAG master
22 | )
23 | FetchContent_MakeAvailable(ccapi websocketpp csv2)
24 |
25 | list(APPEND CMAKE_MODULE_PATH ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/cmake )
26 | find_package(Boost REQUIRED)
27 | find_package(fmt REQUIRED)
28 | find_package(OpenSSL REQUIRED)
29 | find_package(RapidJSON REQUIRED)
30 | find_package(Threads REQUIRED)
31 |
32 | set(CMAKE_CXX_STANDARD 20)
33 | set(CMAKE_CXX_STANDARD_REQUIRED ON)
34 | set(CMAKE_CXX_EXTENSIONS OFF)
35 |
36 | configure_file(cmake/cpp_crypto_algos_config.hpp.in cpp_crypto_algos_config.hpp)
37 |
38 | include(clang_format)
39 | add_subdirectory(src)
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2021 Richard Hickling
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Heisenberg Algo Trading
2 |
3 |
4 |
5 | ## C++ Crypto Algos
6 |
7 | ### Build steps
8 |
9 | Linux or MacOS. See [here](./windows.md) for Windows.
10 |
11 | * Clone project
12 | ```bash
13 | git clone https://github.com/profitviews/heisenberg.git heisenberg
14 | cd heisenberg
15 | ```
16 |
17 | * Install and Configure Conan and Ninja
18 | ```bash
19 | python3 -m venv .venv # Create a Python virtual env
20 | source ./.venv/bin/activate # Activate the virtual env
21 | pip install -r ./requirements.txt # Install Conan and Ninja
22 | conan profile detect --force # Generate a default configuration with the local machine settings
23 | conan config install ./.conan # Install supported build profiles from ./.conan to ./conan2
24 | ```
25 |
26 | * Standard Build
27 | Installing Conan dependencies and configuring CMake presets.
28 | The sample build below is choosing the `Release` configuration:
29 | ```bash
30 | mkdir build
31 | conan install ./ -pr:h .conan2/profiles/gcc/12/x64-libstdc++11-release -pr:b .conan2/profiles/gcc/12/x64-libstdc++11-release -of ./build --build missing
32 | source build/conanbuild.sh
33 | cmake --preset conan-release
34 | cmake --build --preset conan-release
35 | ```
36 |
37 | * Ninja Multi-Config Build
38 |
39 | Multi-config builds allow you to create a build folder containing sub-folders for different build configurations and build them side-by-side.
40 | To generate all the configurations we run the `conan-default` preset which configures CMake for these configurations `Release` and `Debug`. The sample build below is choosing the `Release` configuration:
41 | ```bash
42 | conan install ./ -pr:h .conan2/profiles/gcc/12/x64-libstdc++11-release -pr:b .conan2/profiles/gcc/12/x64-libstdc++11-release -of ./build --build missing -c tools.cmake.cmaketoolchain:generator="Ninja Multi-Config"
43 | source build/conanbuild.sh
44 | cmake --preset conan-default # The configure stage for multi-config builds is conan-default
45 | cmake --build --preset conan-release # The build stage for multi-config builds is the conan-
46 | ```
47 |
48 | This will create:
49 |
50 | * `build/bin/algo` which will run a simple Mean Reversion algo on FTX or Coinbase
51 | * For example
52 | ```bash
53 | cd bin
54 | ./algo --exchange=coinbase --algo=SimpleMR --api_key=$COINBASE_API_KEY --api_secret=$COINBASE_API_SECRET --api_phrase=$COINBASE_API_PHRASE --lookback=50 --reversion_level=2 --base_quantity=0.0025 --symbol=ETH-BTC
55 | ```
56 |
--------------------------------------------------------------------------------
/assets/images/heisenberg_photo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profitviews/heisenberg/912c3f661afa274d70dfe869af92518c8a562cea/assets/images/heisenberg_photo.jpg
--------------------------------------------------------------------------------
/cmake/clang_format.cmake:
--------------------------------------------------------------------------------
1 | #[=======================================================================[.rst:
2 | clang_format_target
3 | ------------------
4 |
5 | Overview
6 | ^^^^^^^^
7 |
8 | Generates a target for running the clang-format executable on all of the source
9 | files in a target.
10 |
11 | .. code-block:: cmake
12 |
13 | clang_format_target(
14 | [TARGET ]
15 | )
16 | -- Call the specified command for the version of an exchange for specifed
17 | target type.
18 |
19 | ``TARGET`` specify the target containing the source files to run clang-format
20 | on.
21 |
22 | #]=======================================================================]
23 | function(clang_format_target)
24 | set(options QUIET)
25 | set(oneValueArgs TARGET CONFIG_FILE)
26 | set(multiValueArgs)
27 | cmake_parse_arguments(CLANG_FORMAT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )
28 |
29 | find_program(CLANG_FORMAT_PATH clang-format)
30 | if (NOT CLANG_FORMAT_PATH)
31 | message(WARNING "clang-format not found, disabling support.")
32 | return()
33 | endif()
34 |
35 | execute_process(COMMAND "${CLANG_FORMAT_PATH}" --version OUTPUT_VARIABLE CLANG_FORMAT_OUTPUT)
36 | string(REPLACE "\n" ";" CLANG_FORMAT_OUTPUT "${CLANG_FORMAT_OUTPUT}")
37 | foreach(line ${CLANG_FORMAT_OUTPUT})
38 | string(REGEX REPLACE "clang-format version ([\\.0-9]+)$" "\\1" CLANG_FORMAT_VERSION "${line}")
39 | if(CLANG_FORMAT_VERSION)
40 | break()
41 | endif()
42 | endforeach()
43 |
44 | if("${CLANG_FORMAT_VERSION}" VERSION_LESS 13.0.0)
45 | message(STATUS "Unsupported version of Clang-Format found. Version 13.0.0 requird, version ${CLANG_FORMAT_VERSION} found")
46 | endif()
47 |
48 | get_property(CLANG_FORMAT_QUIET_REPORTED GLOBAL PROPERTY clang_format_quiet_reported)
49 | if(NOT CLANG_FORMAT_QUIET AND NOT CLANG_FORMAT_QUIET_REPORTED)
50 | set_property(GLOBAL PROPERTY clang_format_quiet_reported TRUE)
51 | message(STATUS "Enabling Clang-Format support. Version: ${CLANG_FORMAT_VERSION}")
52 | endif()
53 |
54 | if(CLANG_FORMAT_TARGET)
55 | get_target_property(targetSources ${CLANG_FORMAT_TARGET} SOURCES)
56 | if (targetSources)
57 | list(APPEND targetAllSources ${targetSources})
58 | endif()
59 | get_target_property(targetInferfaceSources ${CLANG_FORMAT_TARGET} INTERFACE_SOURCES)
60 | if (targetInferfaceSources)
61 | list(APPEND targetAllSources ${targetInferfaceSources})
62 | endif()
63 | list(REMOVE_DUPLICATES targetAllSources)
64 | foreach(clangFormatSource ${targetAllSources})
65 | get_filename_component(clangFormatSource ${clangFormatSource} ABSOLUTE)
66 | list(APPEND clangFormatSources ${clangFormatSource})
67 | endforeach()
68 | endif()
69 |
70 | add_custom_target(clangformat_${CLANG_FORMAT_TARGET}
71 | COMMAND
72 | ${CLANG_FORMAT_PATH} -style=file -i ${clangFormatSources}
73 | WORKING_DIRECTORY
74 | ${CMAKE_SOURCE_DIR}
75 | COMMENT
76 | "Formatting ${CLANG_FORMAT_TARGET} files with ${CLANG_FORMAT_EXE}"
77 | )
78 |
79 | if(TARGET clangformat)
80 | add_dependencies(clangformat clangformat_${CLANG_FORMAT_TARGET})
81 | else()
82 | add_custom_target(clangformat DEPENDS clangformat_${CLANG_FORMAT_TARGET})
83 | endif()
84 | endfunction()
--------------------------------------------------------------------------------
/cmake/cpp_crypto_algos_config.hpp.in:
--------------------------------------------------------------------------------
1 | // the configured options and settings for Tutorial
2 | #define cpp_crypto_algos_VERSION_MAJOR @cpp_crypto_algos_VERSION_MAJOR@
3 | #define cpp_crypto_algos_VERSION_MINOR @cpp_crypto_algos_VERSION_MINOR@
--------------------------------------------------------------------------------
/conanfile.txt:
--------------------------------------------------------------------------------
1 | [requires]
2 | boost/1.80.0
3 | fmt/8.1.1
4 | openssl/1.1.1q
5 | rapidjson/cci.20211112
6 |
7 | [tool_requires]
8 | cmake/3.27.0
9 | ninja/1.11.1
10 |
11 | [generators]
12 | CMakeDeps
13 | CMakeToolchain
14 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | conan
2 | ninja
--------------------------------------------------------------------------------
/resources/ComputationalFinanceInCPPWithDomainArchitectures.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profitviews/heisenberg/912c3f661afa274d70dfe869af92518c8a562cea/resources/ComputationalFinanceInCPPWithDomainArchitectures.pdf
--------------------------------------------------------------------------------
/resources/MLInvestmentMethodology.pptx:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profitviews/heisenberg/912c3f661afa274d70dfe869af92518c8a562cea/resources/MLInvestmentMethodology.pptx
--------------------------------------------------------------------------------
/resources/UniqueOptionPricingMeasureWithNeitherDynamicHedging_nor_CompleteMarkets.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profitviews/heisenberg/912c3f661afa274d70dfe869af92518c8a562cea/resources/UniqueOptionPricingMeasureWithNeitherDynamicHedging_nor_CompleteMarkets.pdf
--------------------------------------------------------------------------------
/resources/optimising_c_code_for_low_latency__1659984565.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profitviews/heisenberg/912c3f661afa274d70dfe869af92518c8a562cea/resources/optimising_c_code_for_low_latency__1659984565.pdf
--------------------------------------------------------------------------------
/resources/qanda.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/profitviews/heisenberg/912c3f661afa274d70dfe869af92518c8a562cea/resources/qanda.pdf
--------------------------------------------------------------------------------
/src/.clang-format:
--------------------------------------------------------------------------------
1 | Language: Cpp
2 | # BasedOnStyle: Maven
3 | Standard: Latest
4 |
5 | ColumnLimit: 120
6 | IndentWidth: 4
7 | UseTab: Never
8 |
9 | BreakBeforeBraces: Custom
10 | BraceWrapping:
11 | AfterCaseLabel: true
12 | AfterClass: true
13 | AfterControlStatement: Always
14 | AfterEnum: true
15 | AfterFunction: true
16 | AfterNamespace: true
17 | AfterStruct: true
18 | AfterUnion: true
19 | AfterExternBlock: true
20 | BeforeCatch: true
21 | BeforeElse: true
22 | BeforeLambdaBody: true
23 | BeforeWhile: true
24 | IndentBraces: false
25 | SplitEmptyFunction: false
26 | SplitEmptyRecord: false
27 | SplitEmptyNamespace: false
28 | BreakBeforeBinaryOperators: None
29 | BreakBeforeTernaryOperators: true
30 | BreakBeforeConceptDeclarations: true
31 | BreakConstructorInitializers: BeforeComma
32 | BreakInheritanceList: BeforeComma
33 | ConstructorInitializerAllOnOneLineOrOnePerLine: false
34 | ConstructorInitializerIndentWidth: 4
35 | ContinuationIndentWidth: 4
36 | Cpp11BracedListStyle: true
37 |
38 | EmptyLineBeforeAccessModifier: LogicalBlock
39 | IncludeBlocks: Preserve
40 |
41 | IndentCaseBlocks: false
42 | IndentCaseLabels: false
43 | IndentWrappedFunctionNames: true
44 | IndentExternBlock: Indent
45 | IndentPPDirectives: AfterHash
46 | IndentRequires: true
47 | LambdaBodyIndentation: Signature
48 | MaxEmptyLinesToKeep: 1
49 | NamespaceIndentation: Inner
50 |
51 | SpaceAfterTemplateKeyword: false
52 | SpaceAroundPointerQualifiers: Default
53 | SpaceBeforeCaseColon: false
54 | SpaceBeforeCpp11BracedList: false
55 | SpaceBeforeCtorInitializerColon: true
56 | SpaceBeforeInheritanceColon: true
57 | SpaceBeforeParens: ControlStatements
58 | SpaceBeforeRangeBasedForLoopColon: true
59 | SpaceBeforeSquareBrackets: false
60 | SpaceInEmptyBlock: false
61 | SpaceInEmptyParentheses: false
62 | SpacesBeforeTrailingComments: 4
63 | SpacesInCStyleCastParentheses: false
64 | SpacesInConditionalStatement: false
65 | SpacesInContainerLiterals: false
66 | SpacesInParentheses: false
67 | SpacesInSquareBrackets: false
68 |
69 | SortIncludes: CaseSensitive
70 | SortUsingDeclarations: true
71 |
72 | AccessModifierOffset: -4
73 | PointerAlignment: Left
74 | AlignAfterOpenBracket: AlwaysBreak
75 | AlignArrayOfStructures: Left
76 | AlignConsecutiveAssignments: None
77 | AlignConsecutiveBitFields: AcrossComments
78 | AlignConsecutiveDeclarations: None
79 | AlignConsecutiveMacros: None
80 | AlignEscapedNewlines: Left
81 | AlignOperands: AlignAfterOperator
82 | AlignTrailingComments: true
83 | AllowShortBlocksOnASingleLine: Always
84 | AllowAllParametersOfDeclarationOnNextLine: true
85 | AllowShortCaseLabelsOnASingleLine: true
86 | AllowShortEnumsOnASingleLine: true
87 | AllowShortFunctionsOnASingleLine: All
88 | AllowShortIfStatementsOnASingleLine: Never
89 | AllowShortLambdasOnASingleLine: All
90 | AllowShortLoopsOnASingleLine: false
91 | AlwaysBreakTemplateDeclarations: Yes
92 | BinPackArguments: false
93 | BinPackParameters: false
94 | BitFieldColonSpacing: After
95 |
96 | CompactNamespaces: true
97 | FixNamespaceComments: true
--------------------------------------------------------------------------------
/src/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_library(cpp_crypto_algos_lib
2 | INTERFACE
3 | cc_simple_mr.hpp
4 | cc_kaufman.hpp
5 | cc_damped_mr.hpp
6 | cc_trade_handler.hpp
7 | cc_trade_stream.hpp
8 | ccex_order_executor.hpp
9 | enum.hpp
10 | exchange.hpp
11 | order_executor.hpp
12 | order_type.hpp
13 | program_options.hpp
14 | side.hpp
15 | trade_data.hpp
16 | trade_stream.hpp
17 | trade_stream_exception.hpp
18 | trade_stream_maker.hpp
19 | utils.hpp
20 | wscc_trade_stream.hpp
21 | )
22 |
23 | target_link_libraries(cpp_crypto_algos_lib
24 | INTERFACE
25 | Boost::headers
26 | Boost::log
27 | Boost::program_options
28 | fmt::fmt
29 | OpenSSL::SSL
30 | OpenSSL::Crypto
31 | rapidjson
32 | Threads::Threads
33 | )
34 |
35 | target_include_directories(cpp_crypto_algos_lib
36 | INTERFACE
37 | ${PROJECT_BINARY_DIR}
38 | ${PROJECT_SOURCE_DIR}/src
39 | ${PROJECT_SOURCE_DIR}/ccapi_executor
40 | ${ccapi_SOURCE_DIR}/include
41 | ${websocketpp_SOURCE_DIR}
42 | ${csv2_SOURCE_DIR}/include
43 | )
44 |
45 | target_compile_definitions(cpp_crypto_algos_lib
46 | INTERFACE
47 | CCAPI_ENABLE_SERVICE_EXECUTION_MANAGEMENT
48 | CCAPI_ENABLE_SERVICE_MARKET_DATA
49 | CCAPI_ENABLE_EXCHANGE_BITMEX
50 | CCAPI_ENABLE_EXCHANGE_FTX
51 | CCAPI_ENABLE_EXCHANGE_COINBASE
52 | )
53 |
54 | target_compile_options(cpp_crypto_algos_lib
55 | INTERFACE
56 | $<$:-fexperimental-library>
57 | $<$:-Wno-terminate>
58 | $<$:/bigobj>
59 | )
60 | set_property(TARGET cpp_crypto_algos_lib PROPERTY CPP_VISIBILITY_PRESET ON)
61 | set_property(TARGET cpp_crypto_algos_lib PROPERTY VISIBILITY_INLINES_HIDDEN ON)
62 |
63 | clang_format_target(TARGET cpp_crypto_algos_lib)
64 | add_subdirectory(apps)
--------------------------------------------------------------------------------
/src/algo.hpp:
--------------------------------------------------------------------------------
1 | #pragma once
2 |
3 | #include
4 |
5 | namespace profitview
6 | {
7 |
8 | BOOST_DEFINE_ENUM(Algo, Kaufman, SimpleMR, Damped)
9 |
10 | }
--------------------------------------------------------------------------------
/src/apps/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_subdirectory(algo)
2 | add_subdirectory(execute_order)
3 | add_subdirectory(streamer)
4 | add_subdirectory(experiment)
--------------------------------------------------------------------------------
/src/apps/algo/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_executable(algo)
2 | target_sources(algo
3 | PRIVATE
4 | algo.cpp
5 | )
6 |
7 | target_link_libraries(algo
8 | PRIVATE
9 | cpp_crypto_algos_lib
10 | )
11 |
12 | set_target_properties(algo
13 | PROPERTIES
14 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
15 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
16 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
17 | )
18 |
19 | clang_format_target(TARGET algo)
--------------------------------------------------------------------------------
/src/apps/algo/algo.cpp:
--------------------------------------------------------------------------------
1 | #include "algo.hpp"
2 | #include "cc_damped_mr.hpp"
3 | #include "cc_kaufman.hpp"
4 | #include "cc_simple_mr.hpp"
5 |
6 | #include "ccex_order_executor.hpp"
7 | #include "trade_stream_maker.hpp"
8 | #include "utils.hpp"
9 |
10 | #include "program_options.hpp"
11 |
12 | #include
13 | #include
14 | #include
15 |
16 | namespace profitview
17 | {
18 |
19 | struct ProgramArgs
20 | {
21 | std::string algo;
22 | std::string exchange;
23 | std::string api_key;
24 | std::string api_secret;
25 | std::string api_phrase;
26 | std::string sub_account;
27 | int lookback = 0;
28 | double reversion_level = 0.0;
29 | double base_quantity = 0.0;
30 | int er_period = 0, fast_sc = 0, slow_sc = 0, kama_trend = 0;
31 | double damping = 0.0;
32 | std::vector symbols;
33 |
34 | void addOptions(boost::program_options::options_description& options)
35 | {
36 | namespace po = boost::program_options;
37 | // clang-format off
38 | options.add_options()
39 | ("algo", po::value(&algo)->required(), "Algo to use")
40 | ("exchange", po::value(&exchange)->required(), "Crypto Exchange to execute on.")
41 | ("api_key", po::value(&api_key)->required(), "API key for Cypto exchange.")
42 | ("api_secret", po::value(&api_secret)->required(), "API secret for Cypto exchange.")
43 | ("api_phrase", po::value(&api_phrase), "API phrase for Cypto exchange.")
44 | ("sub_account", po::value(&sub_account), "Subaccount on Cypto exchange.")
45 | ("lookback", po::value(&lookback)->required(), "Time period to look back")
46 | ("reversion_level", po::value(&reversion_level), "Mean reversion level.")
47 | ("base_quantity", po::value(&base_quantity)->required(), "Quantity to trade.")
48 | ("er_period", po::value(&er_period), "Efficiency Ratio base period for Kaufman")
49 | ("fast_sc", po::value(&fast_sc), "Fast exponential moving average smoothing period")
50 | ("slow_sc", po::value(&slow_sc), "Slow exponential moving average smoothing period")
51 | ("kama_trend", po::value(&kama_trend), "Kaufman trend prediction period")
52 | ("damping", po::value(&damping), "Standard deviation damping limit")
53 | ("symbols", po::value(&symbols)->multitoken()->required(), "Symbols for cypto assets to trade.");
54 | // clang-format on
55 | }
56 | };
57 |
58 | } // namespace profitview
59 |
60 | int main(int argc, char* argv[])
61 | {
62 | using namespace profitview;
63 | ProgramArgs options;
64 | auto const result = parseProgramOptions(argc, argv, options);
65 | if (result)
66 | return result.value();
67 |
68 | const std::map algos{
69 | {"SimpleMR", SimpleMR},
70 | {"Kaufman", Kaufman },
71 | {"Damped", Damped }
72 | };
73 |
74 | CcexOrderExecutor executor{options.exchange, options.api_key, options.api_secret, options.api_phrase, options.sub_account};
75 |
76 | switch (algos.at(options.algo))
77 | {
78 | case SimpleMR:
79 | TradeStreamMaker::register_stream>(
80 | options.algo, &executor, options.lookback, options.reversion_level, options.base_quantity);
81 | break;
82 | case Kaufman:
83 | TradeStreamMaker::register_stream>(
84 | options.algo,
85 | &executor,
86 | options.lookback,
87 | options.base_quantity,
88 | options.er_period,
89 | options.fast_sc,
90 | options.slow_sc,
91 | options.kama_trend);
92 | break;
93 | case Damped:
94 | TradeStreamMaker::register_stream>(
95 | options.algo, &executor, options.lookback, options.reversion_level, options.base_quantity, options.damping);
96 | break;
97 | default:
98 | BOOST_LOG_TRIVIAL(error) << "Unknown algo" << std::endl; return 2;
99 | }
100 |
101 | TradeStreamMaker::get(options.algo).subscribe(options.exchange, options.symbols);
102 |
103 | std::cout << "Press enter to quit" << std::endl;
104 | std::cin.get();
105 |
106 | enum
107 | {
108 | OrderId,
109 | Symbol,
110 | OrderSide,
111 | Size,
112 | Price,
113 | Time,
114 | Status
115 | };
116 | for (const auto& [cid, details] : executor.get_open_orders())
117 | BOOST_LOG_TRIVIAL(info) << "cid: " << cid << ", Order Id: " << std::get(details)
118 | << ", Symbol: " << std::get(details) << ", Status: " << std::get(details)
119 | << std::endl;
120 |
121 | return 0;
122 | }
--------------------------------------------------------------------------------
/src/apps/execute_order/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | add_executable(execute_order)
2 | target_sources(execute_order
3 | PRIVATE
4 | execute_order.cpp
5 | )
6 |
7 | target_link_libraries(execute_order
8 | PRIVATE
9 | cpp_crypto_algos_lib
10 | )
11 |
12 | set_target_properties(execute_order
13 | PROPERTIES
14 | ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
15 | LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib
16 | RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin
17 | )
18 |
19 | clang_format_target(TARGET execute_order)
--------------------------------------------------------------------------------
/src/apps/execute_order/execute_order.cpp:
--------------------------------------------------------------------------------
1 | #include "ccex_order_executor.hpp"
2 | #include "program_options.hpp"
3 |
4 | #include
5 |
6 | #include
7 | #include
8 | #include
9 | #include
10 |
11 | #include
12 | #include