PyAlgoEngine
High-Performance Algorithmic Trading Engine in Python, Cython, and C
PyAlgoEngine is a low-latency trading engine for HFT (High-Frequency Trading) systems. It provides C-level market data structures, shared-memory buffers, an event-driven engine architecture, backtesting with simulated order matching, exchange calendar profiles, and web-based visualization — all with Cython acceleration for latency-critical paths.
Features
| Category | Capabilities |
|---|---|
| Market Data | TickData, TickDataLite, BarData, DailyBar, OrderBook, TransactionData, OrderData, TradeData — all C-backed via Cython |
| Buffers | MarketDataBuffer, MarketDataRingBuffer, MarketDataConcurrentBuffer, MarketDataBufferCache |
| Engines | EVENT_ENGINE (pub/sub), MDS (Market Data Service), ALGO_ENGINE (algo lifecycle), trade engine (DMA, positions, risk) |
| Exchange Profiles | CN (A-share) and default global calendars, session phases, holidays via PROFILE, PROFILE_CN, PROFILE_DEFAULT |
| Backtesting | SimpleReplay, ProgressReplay, SimMatch (simulated matching), TradeMetrics |
| Strategy Framework | StrategyEngine, AlgoTemplate, global singletons (BALANCE, DMA, STRATEGY_ENGINE) |
| Web Apps | Flask + Bokeh dashboards, candlestick charts, strategy tester UI |
| Compile-Time Config | BOOK_SIZE, ID_SIZE, LONG_ID_SIZE, MD_BUF_PTR_DEFAULT_CAP, MD_BUF_DATA_DEFAULT_CAP via env vars |
Quick Install
git clone https://github.com/BolunHan/PyAlgoEngine.git
cd PyAlgoEngine
./build.sh -i
Requires Python 3.12+ and a C compiler (GCC, Clang, or MSVC). See the Setup Guide for detailed instructions, compile-time configuration, and optional dependencies.
Quick Verify
import algo_engine
print(algo_engine.__version__)
from algo_engine.base import CONFIG
print(CONFIG) # compile-time and runtime configuration
Documentation
Build locally:
cd docs && ./update_docs.sh
# open build/html/index.html
Deploy to Read the Docs
- Sign up at readthedocs.org and import this repo
- The included
.readthedocs.yamlhandles the build — it compiles Cython extensions, installs the package, and builds with Sphinx + Furo - RTD auto-builds on every push to
main; enable the GitHub webhook in Admin → Integrations on your RTD project dashboard
Architecture
┌──────────────────────────────────────────────────────┐
│ apps/ Web visualization (Flask, Bokeh) │
├──────────────────────────────────────────────────────┤
│ strategy/ Strategy framework, global singletons│
├──────────────────────────────────────────────────────┤
│ engine/ Event, Market, Algo, Trade engines │
├──────────────────────────────────────────────────────┤
│ backtest/ Replay, SimMatch, Metrics │
├──────────────────────────────────────────────────────┤
│ base/ Market data types, buffers (Cython/C)│
├──────────────────────────────────────────────────────┤
│ exchange_profile/ Calendars, sessions (CN + global)│
├──────────────────────────────────────────────────────┤
│ monitor/ Synthetic order book, bar monitor │
├──────────────────────────────────────────────────────┤
│ utils/ Time-series indices, fake data │
└──────────────────────────────────────────────────────┘
Build System
| Command | Description |
|---|---|
./build.sh -i |
Clean, build Cython extensions in-place, install |
make build |
Clean and build extensions in-place |
make install |
Build + pip install |
./build.sh -l |
List all compile-time macros and defaults |
make list-args |
Same as above |
Override compile-time constants:
BOOK_SIZE=20 ./build.sh -i
Dependencies
- Runtime: numpy, pandas, exchange_calendars, PyCyBase, PyEventEngine, Cython
- Web (optional): flask, waitress, bokeh
- Docs (optional): sphinx, sphinx-rtd-theme
License
MIT — Han Bolun
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyalgoengine-0.12.0.post2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyalgoengine-0.12.0.post2-cp314-cp314t-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.5 MB
- Tags: CPython 3.14t, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2e532143c466885fae0d5b70713a93ccf5873d041040dabec7a4d0faf5b17868
|
|
| MD5 |
93d331efa512eebeb0003a7e5ad5d178
|
|
| BLAKE2b-256 |
fe1c469bb021840c150468ccd961678d6421cc1d8800c5c4c32e2cfeab1b2903
|
File details
Details for the file pyalgoengine-0.12.0.post2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyalgoengine-0.12.0.post2-cp314-cp314-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.14, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c9e8e4004b9f15e2a4a5557aa4b2efa956ba1e10ef4187ac9e7eee408553468
|
|
| MD5 |
a0e6f61847668126c3118e486fa9aabb
|
|
| BLAKE2b-256 |
c0eb5b37037ec98d77787508c0ab65b4d4b89bc71e0a772874597e04172d8f50
|
File details
Details for the file pyalgoengine-0.12.0.post2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyalgoengine-0.12.0.post2-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.13, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93cbfcd8f2ab498f32c47307183159dd5ef686904c63cd86256842e6fc2a2e1c
|
|
| MD5 |
ba9a5c3de2e00ced613911051df0b9ec
|
|
| BLAKE2b-256 |
9c6e4853b59f470d4373277e4a79e9c28e8df1f31fff155812af477138b53641
|
File details
Details for the file pyalgoengine-0.12.0.post2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.
File metadata
- Download URL: pyalgoengine-0.12.0.post2-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
- Upload date:
- Size: 8.4 MB
- Tags: CPython 3.12, manylinux: glibc 2.17+ x86-64, manylinux: glibc 2.28+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.14.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
406ef3428e89d3b03c65f4936e5c6416088cec9285f879410534995a27cbb3f9
|
|
| MD5 |
b82f2e649a279f76b1b72f6a03fef8b6
|
|
| BLAKE2b-256 |
b23e110b6d3e215b753aca64f756589ca49a3f25315e167f1b972f2c723a00a7
|