Skip to content

Jennyfirrr/FoxLIB

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FoxLIB

header-only C++20 library for branchless fixed-point tick processing. zero dependencies (core), battle-tested against live Binance feeds.

extracted from a production crypto trading engine. the primitives are real, fast, and tested — arbitrary-precision fixed-point math, lock-free queues, online regression, multi-armed bandits, and more.

install

# from source
git clone https://github.com/Jennyfirrr/FoxLIB.git
cd FoxLIB
cmake -B build && sudo cmake --install build

# arch linux (AUR)
yay -S foxlib

use

# option 1: FetchContent (easiest, no install needed)
include(FetchContent)
FetchContent_Declare(foxlib
    GIT_REPOSITORY https://github.com/Jennyfirrr/FoxLIB.git
    GIT_TAG v0.1.0
)
FetchContent_MakeAvailable(foxlib)
target_link_libraries(my_app PRIVATE foxlib::foxlib)

# option 2: system install (after cmake --install or pacman -S foxlib)
find_package(foxlib REQUIRED)
target_link_libraries(my_app PRIVATE foxlib::foxlib)

# option 3: just copy the headers into your project and include them directly
#include <foxlib/fpn.hpp>
#include <foxlib/spsc.hpp>

// arbitrary-precision fixed-point math
auto price = FPN_FromDouble<64>(69420.50);
auto qty   = FPN_FromDouble<64>(0.001);
auto total = FPN_Mul(price, qty);  // branchless, no floats

// lock-free ring buffer (~3-5ns per op)
foxlib::SPSCRing<foxlib::Tick<64>, 1024> ring;
foxlib::SPSCRing_Init(&ring);

whats in it

core (zero deps)

header what
fpn.hpp arbitrary-width fixed-point arithmetic (64-4096+ bit)
fp64.hpp optimized Q64.64 fixed-point via __uint128_t
spsc.hpp cache-line separated SPSC lock-free ring buffer
buddy.hpp bitmap buddy allocator (16B-1MB blocks)
pool.hpp bitmap slot allocator (up to 64 fixed-size slots)
tick.hpp cache-line aligned tick struct
event.hpp cache-line aligned trade event struct
rdtsc.hpp cycle-accurate timing with proper serialization fences
bench.hpp percentile benchmarking harness

analytics (depends on fpn)

header what
rolling_stats.hpp windowed OLS regression, R^2, variance, VWAP
welford.hpp O(1) online mean/variance (unbounded streams)
regression.hpp single-feature OLS linear regression
regression3x.hpp rolling 8-sample OLS with R^2 tracking
ror.hpp regression-on-regression (trend acceleration)
confidence.hpp rolling Spearman IC, freshness decay, RMSE stability
bandit.hpp EXP3-IX multi-armed bandit with blending
vol_scaler.hpp volatility-inverse position sizing
cost_model.hpp spread + timing + market impact cost model
barrier_gate.hpp binary classifier combination gate
reward.hpp reward attribution ring buffer with CSV export

network (requires OpenSSL)

header what
websocket.hpp RFC 6455 WebSocket client over TLS

websocket is generic RFC 6455 framing — works with any WebSocket server over TLS. only tested against Binance as of 2026-04. ws_read_frame() gives you raw text/binary, you bring your own parser for whatever exchange format you're connecting to.

exchange-specific feed adapters (Binance, Coinbase, Kraken, etc.) that parse JSON into foxlib::Tick<F> are planned for a future release.

benchmarks

measured on the production engine (AMD Ryzen, Linux 6.x):

operation p50
SPSCRing push/pop ~3.7 ns
FPN<64> multiply ~5 ns
ExecutionCore tick ~26-36 ns

using without cmake

you don't need cmake at all. just copy the headers you want into your project and include them:

# grab just the engine + fixed-point math
cp include/foxlib/engine.hpp include/foxlib/fpn.hpp include/foxlib/tick.hpp \
   include/foxlib/spsc.hpp include/foxlib/fp64.hpp my_project/

# compile directly
g++ -std=c++20 -O2 -I my_project/ my_app.cpp -o my_app

every header either works standalone (zero deps) or only depends on other foxlib headers via relative includes. no cmake, no pkg-config, no build system required.

dependency map (→ means "requires"):

  • fpn.hpp — standalone
  • fp64.hpp — standalone
  • spsc.hpp — standalone
  • pool.hpp — standalone
  • buddy.hpp — standalone
  • rdtsc.hpp — standalone
  • tick.hpp → fpn
  • event.hpp → fpn
  • engine.hpp → fpn, tick, spsc
  • rolling_stats.hpp → fpn
  • welford.hpp → fpn
  • regression.hpp → fpn
  • regression3x.hpp → fpn
  • ror.hpp → regression3x → fpn
  • bench.hpp → rdtsc
  • websocket.hpp → OpenSSL (-lssl -lcrypto)
  • bandit.hpp, barrier_gate.hpp, confidence.hpp, cost_model.hpp, vol_scaler.hpp, reward.hpp — standalone

build options

cmake -B build                          # default (tests ON)
cmake -B build -DFOXLIB_BUILD_TESTS=OFF  # skip tests
cmake -B build -DFOXLIB_BUILD_EXAMPLES=ON # build examples

define USE_NATIVE_128 before including fpn.hpp to enable __uint128_t specializations for FPN<64> (uses fp64.hpp under the hood, slightly faster on x86-64).

license

MIT. see LICENSE.

About

header-only C++20 library for branchless fixed-point tick processing

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors