C++ concurrency library
Loading...
Searching...
No Matches
C++ concurrency library

Exploring FIX processing and backtesting using the C++ concurrency library. See the repo and download some example FIX messages.

Prices

Get prices using the CryptoCompare API. Download as JSON and then converted to CSV for processing.

Thread safe logger

Report time added to log and backlog.

Order book

Generate an order book from a list of ticker names and order types. This involves multiple order generator threads updating a single order book.

FIX protocol tester

Test FIX protocol implementation against orders generated by OpenAI.

Examples generated by OpenAI

See turpin.cloud for the command line OpenAI script.

1. New Order Single (35=D)
8=FIX.4.4|9=100|35=D|34=1|49=CLIENT01|52=20210101-10:00:00.000|56=MARKET01|11=123456|55=AAPL|54=1|38=100|40=1|59=0|60=20210101-10:00:00.000|10=042|
2. Order Cancel Request (35=F)
8=FIX.4.4|9=100|35=F|34=2|49=CLIENT01|52=20210101-10:00:00.000|56=MARKET01|41=123456|11=123457|55=AAPL|54=1|60=20210101-10:00:00.000|10=042|
3. Order Cancel Replace Request (35=G)
8=FIX.4.4|9=100|35=G|34=3|49=CLIENT01|52=20210101-10:00:00.000|56=MARKET01|41=123456|11=123458|55=AAPL|54=1|38=100|40=1|59=0|60=20210101-10:00:00.000|10=042|
4. Execution Report (35=8)
8=FIX.4.4|9=100|35=8|34=4|49=MARKET01|52=20210101-10:00:00.000|56=CLIENT01|37=123456|11=123456|55=AAPL|54=1|38=100|40=1|150=2|151=100|14=0|6=100|60=20210101-10:00:00.000|10=042|
5. Order Status Request (35=H)
8=FIX.4.4|9=100|35=H|34=5|49=CLIENT01|52=20210101-10:00:00.000|56=MARKET01|41=123456|11=123459|55=AAPL|54=1|60=20210101-10:00:00.000|10=042|

Submit orders

Backtester

Arbitrage

References


Sun Mar 30 14:02:05 UTC 2025

curl --silent -L turpin.cloud/makefile --output /tmp/makefile
# Scripts
make --directory=fix_generator
make[1]: Entering directory '/builds/germs-dev/threads/fix_generator'
bash process.sh
8=FIX.4.2|9=75|35=D|49=SENDER|56=RECEIVER|34=1|52=20210506-09:30:00|11=ORDER123|55=AAPL|54=1|38=100|40=2|44=150|59=0|10=032| Explanation: - 8=FIX.4.2: This is the FIX protocol version used. - 9=75: This is the length of the message in number of characters. - 35=D: This is the message type, where D indicates a New Order Single message. - 49=SENDER: This is the sender's ID. - 56=RECEIVER: This is the receiver's ID. - 34=1: This is the message sequence number, used for message sequencing and identification. - 52=20210506-09:30:00: This is the date and time of the message in UTC. - 11=ORDER123: This is the unique ID for the order. - 55=AAPL: This is the symbol or instrument being traded, in this case Apple stock. - 54=1: This is the side of the trade, with 1 indicating a Buy order. - 38=100: This is the order quantity, in this case 100 shares. - 40=2: This is the order type, with 2 indicating a Limit order. - 44=150: This is the limit price for the order, in this case $150. - 59=0: This is the time in force, where 0 indicates a Day order. - 10=032: This is the checksum, used for message integrity and validation.
wc -l fix.txt
58 fix.txt
make[1]: Leaving directory '/builds/germs-dev/threads/fix_generator'
make --directory=prices
make[1]: Entering directory '/builds/germs-dev/threads/prices'
bash get_prices.sh
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 324k 0 324k 0 0 304k 0 --:--:-- 0:00:01 --:--:-- 304k
make[1]: Leaving directory '/builds/germs-dev/threads/prices'
# Compilations
make -j 2 run --directory=fix2 --makefile=/tmp/makefile
make[1]: Entering directory '/builds/germs-dev/threads/fix2'
curl -L turpin.cloud/main.cxx --output /tmp/main.cxx
g++ -c test.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 64 100 64 0 0 7885 0 --:--:-- --:--:-- --:--:-- 8000
100 405 100 405 0 0 2164 0 --:--:-- --:--:-- --:--:-- 2164
100 405 100 405 0 0 2076 0 --:--:-- --:--:-- --:--:-- 0
g++ -o app.o /tmp/main.cxx test.o -lfmt -lgtest -lbenchmark -lpthread -ltbb -std=c++23
timeout 60 ./app.o --benchmark_filter=
Failed to match any benchmarks against regex: .
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from fixi
[ RUN ] fixi.string_split
8=FIX.4.4
9=148
35=D
34=1080
49=TESTBUY1
52=20180920-18:14:19.508
56=TESTSELL1
11=636730640278898634
15=USD
21=2
38=7000
40=1
54=1
55=MSFT
60=20180920-18:14:19.492
10=092
[ OK ] fixi.string_split (0 ms)
[----------] 1 test from fixi (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.
make[1]: Leaving directory '/builds/germs-dev/threads/fix2'
make -j 2 run --directory=logger --makefile=/tmp/makefile
make[1]: Entering directory '/builds/germs-dev/threads/logger'
g++ -c logger.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
g++ -c threads.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
g++ -o app.o /tmp/main.cxx logger.o threads.o -lfmt -lgtest -lbenchmark -lpthread -ltbb -std=c++23
timeout 60 ./app.o --benchmark_filter=
2025-03-30T14:02:22+00:00
Running ./app.o
Run on (2 X 2450 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x1)
L1 Instruction 32 KiB (x1)
L2 Unified 512 KiB (x1)
L3 Unified 32768 KiB (x1)
Load Average: 1.09, 0.48, 0.18
***WARNING*** Library was built as DEBUG. Timings may be affected.
--------------------------------------------------------
Benchmark Time CPU Iterations
--------------------------------------------------------
noop_baseline 0.000 ns 0.000 ns 1000000000000
noop_async 43612 ns 26289 ns 28369
noop_thread 41687 ns 25248 ns 27152
noop_jthread 40941 ns 24875 ns 28077
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from log
[ RUN ] log.init
hello1 (2)
hello2 (2)
hello3 (2)
hello4 (2)
hello5 (1)
hello6 (0)
[ OK ] log.init (0 ms)
[----------] 1 test from log (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.
make[1]: Leaving directory '/builds/germs-dev/threads/logger'
make -j 2 run --directory=order_book --makefile=/tmp/makefile
make[1]: Entering directory '/builds/germs-dev/threads/order_book'
g++ -c containers.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
g++ -c order_book.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
g++ -o app.o /tmp/main.cxx containers.o order_book.o -lfmt -lgtest -lbenchmark -lpthread -ltbb -std=c++23
timeout 60 ./app.o --benchmark_filter=
2025-03-30T14:02:32+00:00
Running ./app.o
Run on (2 X 2450 MHz CPU s)
CPU Caches:
L1 Data 32 KiB (x1)
L1 Instruction 32 KiB (x1)
L2 Unified 512 KiB (x1)
L3 Unified 32768 KiB (x1)
Load Average: 1.23, 0.53, 0.20
***WARNING*** Library was built as DEBUG. Timings may be affected.
------------------------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------------------------
vector_insert_at_front 12.2 ns 12.2 ns 57233183
vector_insert_at_back 12.7 ns 12.7 ns 57616142
vector_insert_at_front_with_reserve 13.3 ns 13.3 ns 48760040
vector_insert_at_back_with_reserve 13.0 ns 13.0 ns 53503561
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from order_book
[ RUN ] order_book.init
[ OK ] order_book.init (0 ms)
[----------] 1 test from order_book (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test suite ran. (0 ms total)
[ PASSED ] 1 test.
make[1]: Leaving directory '/builds/germs-dev/threads/order_book'
make -j 2 run --directory=order_book2 --makefile=/tmp/makefile
make[1]: Entering directory '/builds/germs-dev/threads/order_book2'
g++ -c orders.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
g++ -c test.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
g++ -o app.o /tmp/main.cxx orders.o test.o -lfmt -lgtest -lbenchmark -lpthread -ltbb -std=c++23
timeout 60 ./app.o --benchmark_filter=
Failed to match any benchmarks against regex: .
[==========] Running 4 tests from 1 test suite.
[----------] Global test environment set-up.
[----------] 4 tests from orders
[ RUN ] orders.string_conversion
[ OK ] orders.string_conversion (0 ms)
[ RUN ] orders.generation
[ OK ] orders.generation (0 ms)
[ RUN ] orders.declare_tickers
Tickers: ["FEL", "SIM", "TIG", "PRI", "WHI", "OSC", "SHA", "LUN", "SMO", "COC"]
Full names: ["Felix", "Simba", "Tiger", "Princess", "Whiskers", "Oscar", "Shadow", "Luna", "Smokey", "Coco"]
[ OK ] orders.declare_tickers (0 ms)
[ RUN ] orders.types
[ OK ] orders.types (0 ms)
[----------] 4 tests from orders (0 ms total)
[----------] Global test environment tear-down
[==========] 4 tests from 1 test suite ran. (0 ms total)
[ PASSED ] 4 tests.
make[1]: Leaving directory '/builds/germs-dev/threads/order_book2'
make -j 2 --directory=exchange --makefile=/tmp/makefile
make[1]: Entering directory '/builds/germs-dev/threads/exchange'
g++ -c atomics.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
g++ -c test.cxx -std=c++23 -O2 --all-warnings --extra-warnings --pedantic-errors -Werror -Wconversion -Wuninitialized -Weffc++ -Wunused -Wunused-variable -Wunused-function -Wshadow -Wfloat-equal -Wdelete-non-virtual-dtor -g -pg -march=native -mtune=native
g++ -o app.o /tmp/main.cxx atomics.o test.o -lfmt -lgtest -lbenchmark -lpthread -ltbb -std=c++23
make[1]: Leaving directory '/builds/germs-dev/threads/exchange'