flox-py
Python bindings for FLOX — an AI-native framework for building trading systems.
AI agents discover the surface and drive it end-to-end through an MCP control plane. One strategy class runs backtest, paper, and live.
Install
pip install flox-py
Scaffold a new project
flox new my-strategy # research scaffold (default)
flox new my-bot --template=live # live trading via CcxtBroker
flox new my-indicators --template=indicator-library # publishable indicator package
flox templates # list templates
flox new ships with the wheel; see docs/how-to/flox-new.md for what each template lays down.
Quick start
import flox_py as flox
registry = flox.SymbolRegistry()
btc = registry.add_symbol("binance", "BTCUSDT", tick_size=0.01)
class SMACross(flox.Strategy):
def __init__(self, symbols):
super().__init__(symbols)
self.fast = flox.SMA(10)
self.slow = flox.SMA(30)
def on_trade(self, ctx, trade):
f = self.fast.update(trade.price)
s = self.slow.update(trade.price)
if f is None or s is None:
return
if f > s and ctx.is_flat():
self.market_buy(0.01)
elif f < s and ctx.is_long():
self.close_position()
def on_signal(sig):
print(sig.side, sig.order_type, sig.quantity, sig.price)
runner = flox.Runner(registry, on_signal)
runner.add_strategy(SMACross([btc]))
runner.start()
# feed market data:
# runner.on_trade(btc, price, qty, is_buy, ts_ns)
# runner.on_book_snapshot(btc, bid_prices, bid_qtys, ask_prices, ask_qtys, ts_ns)
runner.stop()
Run a paper engine in one command
For tier-5/6 control (live order placement, position queries, kill switch over HTTP), flox engine sim boots a Runner + SimulatedExecutor + ControlServer + state-snapshot writer:
flox engine sim --strategy strategy.py --tape ./tape
Prints the engine URL and a copy-pasteable flox-mcp init --engine-url URL --token T command for wiring into AI tools.
AI companion
flox-mcp is a Model Context Protocol server that gives coding agents (Claude Code, Cursor, Cline) grounded access to indicators, error codes, the C-API surface, and full-text doc search:
pip install flox-mcp
flox-mcp init # writes ./.mcp.json for the current project
See the flox-mcp README for the tool list.
Symbol and SymbolRegistry
registry = flox.SymbolRegistry()
btc = registry.add_symbol("binance", "BTCUSDT", tick_size=0.01)
btc.id # int, e.g. 1
btc.name # "BTCUSDT"
btc.exchange # "binance"
btc.tick_size # 0.01
int(btc) # 1
print(btc) # Symbol(binance:BTCUSDT, id=1)
# Symbol objects work transparently as int anywhere an ID is expected
Strategy
Subclass flox.Strategy and override the callbacks you need.
class MyStrategy(flox.Strategy):
def __init__(self, symbols):
super().__init__(symbols) # symbols: list[Symbol | int]
def on_start(self): ...
def on_stop(self): ...
def on_trade(self, ctx, trade): ... # ctx: SymbolContext, trade: TradeData
def on_book_update(self, ctx): ...
def on_bar(self, ctx, bar): ...
# Order-event hooks (fires on the strategy's own emitted orders).
def on_fill(self, ctx, ev): ... # status PARTIALLY_FILLED or FILLED
def on_order_update(self, ctx, ev): ... # every status change including fills
Order emission (shorthand, uses first symbol by default)
| Method | Description |
|---|---|
market_buy(qty, symbol=None) |
Market buy |
market_sell(qty, symbol=None) |
Market sell |
limit_buy(price, qty, symbol=None) |
Limit buy |
limit_sell(price, qty, symbol=None) |
Limit sell |
stop_market(side, trigger, qty, symbol=None) |
Stop market |
close_position(symbol=None) |
Close position (reduce-only) |
SymbolContext
| Property | Type | Description |
|---|---|---|
position |
float |
Current position quantity |
last_trade_price |
float |
Last trade price |
best_bid |
float |
Best bid |
best_ask |
float |
Best ask |
mid_price |
float |
Mid price |
is_flat() |
bool |
No position |
is_long() |
bool |
Long position |
is_short() |
bool |
Short position |
TradeData
| Property | Type | Description |
|---|---|---|
symbol |
int |
Symbol ID |
price |
float |
Trade price |
quantity |
float |
Trade quantity |
is_buy |
bool |
Buy-side aggressor |
timestamp_ns |
int |
Timestamp (nanoseconds) |
OrderEvent (passed to on_fill / on_order_update)
| Property | Type | Description |
|---|---|---|
order_id |
int |
Engine order ID |
status |
str |
"FILLED" / "PARTIALLY_FILLED" / "REJECTED" / "CANCELED" / ... |
side |
str |
"buy" or "sell" |
fill_qty |
float |
Last-fill quantity |
fill_price |
float |
Last-fill price |
reject_reason |
str | None |
Set when status == REJECTED |
Runner
runner = flox.Runner(registry, on_signal) # synchronous
runner = flox.Runner(registry, on_signal, threaded=True) # Disruptor background thread
runner.add_strategy(strategy)
runner.start()
runner.on_trade(btc, price, qty, is_buy, ts_ns)
runner.on_book_snapshot(btc, bid_prices, bid_qtys, ask_prices, ask_qtys, ts_ns)
runner.stop()
The on_signal callback receives Signal objects:
| Property | Type | Description |
|---|---|---|
side |
str |
"buy" or "sell" |
quantity |
float |
Order quantity |
price |
float |
Limit price (0 for market) |
order_type |
str |
"market", "limit", etc. |
order_id |
int |
Internal order ID |
BacktestRunner
bt = flox.BacktestRunner(registry, fee_rate=0.0004, initial_capital=10_000)
bt.set_strategy(MyStrategy([btc]))
stats = bt.run_csv("data.csv") # auto-detects symbol from registry
stats = bt.run_csv("data.csv", "BTCUSDT") # explicit symbol name
stats = bt.run_tape("./tape") # replay a recorded `.floxlog` directory
equity = bt.equity_curve() # numpy arrays: timestamp_ns, equity, drawdown_pct
trades = bt.trades() # numpy arrays: per-trade detail
from flox_py.report import write_html
write_html("report.html", stats=stats, equity_curve=equity, trades=trades)
The same risk-gate stack as the live Runner plugs into the backtest. Reduce-only / flatten orders bypass the gate by design (so a tightening cap cannot strand a position):
bt.set_risk_manager(my_risk_manager) # IRiskManager: .allow(order)
bt.set_kill_switch(my_kill_switch) # IKillSwitch: .check(order), .is_triggered()
bt.set_order_validator(my_validator) # IOrderValidator: .validate(order, reason)
bt.set_pnl_tracker(my_pnl_tracker) # IPnLTracker: .on_order_filled(order)
Stats dict
| Key | Description |
|---|---|
return_pct |
Net return percentage |
net_pnl |
Net P&L after fees |
total_trades |
Round-trip trade count |
win_rate |
Winning trade fraction |
sharpe_ratio |
Annualized Sharpe ratio |
max_drawdown_pct |
Peak-to-trough drawdown (%) |
Walk-forward and grid search
wf = flox.WalkForwardRunner(
registry, fee_rate=0.0004, initial_capital=10_000,
mode="anchored", train_size=180, test_size=30,
)
wf.set_strategy_factory(lambda fold_idx: MyStrategy([btc]))
folds = wf.run_csv("data.csv", "BTCUSDT")
grid = flox.GridSearch()
grid.add_axis([5, 10, 20]) # fast period
grid.add_axis([30, 50, 100]) # slow period
def factory(params):
fast, slow = params
bt = flox.BacktestRunner(registry, fee_rate=0.0004, initial_capital=10_000)
bt.set_strategy(MyStrategy([btc])) # configure with fast / slow as needed
return bt.run_csv("data.csv", "BTCUSDT")
grid.set_factory(factory)
results = grid.run() # list of {index, params, stats}
Render a heatmap with flox_py.report.heatmap_html(...) /
write_heatmap(...). Run a multiple-comparison-aware significance
test with flox.whites_reality_check(returns, num_bootstrap=10_000).
MLflow
from flox_py import mlflow as flox_mlflow
flox_mlflow.log_backtest(
stats, equity_curve=equity, trades=trades,
params={"fast": 10, "slow": 30},
run_name="sma-2025-01",
)
mlflow is optional — install with pip install mlflow.
Modules
| Module | Description |
|---|---|
| Strategy / Runner | Event-driven live and backtest strategies |
| Engine | Batch backtest engine (signal arrays, parallel runs) |
| Indicators | EMA, SMA, RSI, MACD, ATR, Bollinger, ADX, Stochastic, CCI, VWAP, CVD, Correlation, AutoCorrelation, and more |
| Aggregators | Time, tick, volume, range, renko, Heikin-Ashi bars |
| Order Books | N-level, L3, cross-exchange CompositeBookMatrix |
| Profiles | Footprint bars, volume profile, market profile |
| Positions | Position tracking with FIFO/LIFO/average cost basis |
| Replay | Binary log reader/writer, market data recorder |
All compute-heavy operations release the GIL for true parallelism.
Full API reference at flox-foundation.github.io/flox/reference/python.
Release files for flox-py 0.10.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flox_py-0.10.0.tar.gz | 463.6 kB | Details |
Built distributions (wheels)
Total release size: 25.4 MB
Release files / flox_py-0.10.0.tar.gz
| Download URL | flox_py-0.10.0.tar.gz |
|---|---|
| Size | 463.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ff566da0e006883a8f5312c9e7f51dd7b6a648587db08b6e016ac408b6ea803a
|
|
BLAKE2b-256 checksum How to use checksums |
e19ab490679c74df13ec2120a65ad6551f730125a4f7382621002bf8e027c4b1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp313-cp313-win_amd64.whl
| Download URL | flox_py-0.10.0-cp313-cp313-win_amd64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.13 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
3b5f4d72b9e84f838700379bc7b123e0f28916e1b83eac824218f772708249fd
|
|
BLAKE2b-256 checksum How to use checksums |
ac5ee3260e1abdd06f2d85cf60b4fc156a3a8ca238df79dcfcc10d33cdf16d33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | flox_py-0.10.0-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.13 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
3a32966e061d73d3a136c6e7dd90f659acc3efd27fb8a66531fd14def80985bd
|
|
BLAKE2b-256 checksum How to use checksums |
d5aed87599d9a94236e60f31ec6c140fe358467162ef1b1d044536db590c8c2b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp313-cp313-macosx_14_0_arm64.whl
| Download URL | flox_py-0.10.0-cp313-cp313-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.13 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
90b125d8efa6aeb9ab93e81f228a017c4907647304f3e80960ce772e2f3d11b7
|
|
BLAKE2b-256 checksum How to use checksums |
0d1b8dadc420a76e4bc6827715e57263fb2bcd1e62c8858edfb0a6b06d3cb8ef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp312-cp312-win_amd64.whl
| Download URL | flox_py-0.10.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
4925bc5618ec7bbc8d0c2584632871ad0b47a0b39306cee605d66ae73c46e366
|
|
BLAKE2b-256 checksum How to use checksums |
475df3282c964cdc1823108906be4e9fa3b91d41a726e6421545c7507dd876dc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | flox_py-0.10.0-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.12 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
f9f43aa26f8e07b46309bee023f30d85a22936fadc769fcc2b7060b7391186dd
|
|
BLAKE2b-256 checksum How to use checksums |
00596f0ea416d07d2d2c3444961e5478d184a8585fbe15e82ed3542c34cc4f13
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp312-cp312-macosx_14_0_arm64.whl
| Download URL | flox_py-0.10.0-cp312-cp312-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.9 MB |
| Tags | CPython 3.12 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
3e15ff65c161a3f9b9142a6529806e7a0912265d6de8cd5c1d6e219a06054d7a
|
|
BLAKE2b-256 checksum How to use checksums |
7723fd5468655fa82d03bcbfcf700f440e6cb986d26cdd11b5813bb6b9e760bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp311-cp311-win_amd64.whl
| Download URL | flox_py-0.10.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
6b12c286731e78866232b549528f0ac060934dfbeffe61d793b10aa7f1d362fe
|
|
BLAKE2b-256 checksum How to use checksums |
e967be61cd5e4fd97c53337e6f5bbcc7f62ebffb667babfd033ef5648bf94140
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | flox_py-0.10.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.11 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
f19fd56b65bbb8ca73c04525adaf80bb81962807f58728f6ac687286c3015045
|
|
BLAKE2b-256 checksum How to use checksums |
ea252eca6dbde11cd0ad40de3bb0e2ee7c1161c92c513d140e4234ae3221b796
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp311-cp311-macosx_14_0_arm64.whl
| Download URL | flox_py-0.10.0-cp311-cp311-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.11 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
e0d5a257cc2f4d39f15603b97773d1a13433fc1d25614d641c94c408e6813567
|
|
BLAKE2b-256 checksum How to use checksums |
648af8d3464b57ac5d0baf6cead35704f960ba217fef299fa4924494c68e2f83
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp310-cp310-win_amd64.whl
| Download URL | flox_py-0.10.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 1.6 MB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
30877cb58aea0c3a560bf99cbeeac48568ca9ae9d80cb408312cbf273a189232
|
|
BLAKE2b-256 checksum How to use checksums |
4a0bfd566f5aa1bc3c3cb16170b1a1b5dc8d4d617c5305001e7d111454a8691c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
| Download URL | flox_py-0.10.0-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl |
|---|---|
| Size | 2.8 MB |
| Tags | CPython 3.10 Linux glibc 2.27+ x86-64 Linux glibc 2.28+ x86-64 |
|
SHA-256 checksum How to use checksums |
62d7d395f5dd20bbdcc9010c2624e47abaceef09fa236be5a077186abbff2f85
|
|
BLAKE2b-256 checksum How to use checksums |
90bb5492b1fb29129f2fddd07d21aaf202b0d07b3e12a7a8d01392f533af6249
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency logRelease files / flox_py-0.10.0-cp310-cp310-macosx_14_0_arm64.whl
| Download URL | flox_py-0.10.0-cp310-cp310-macosx_14_0_arm64.whl |
|---|---|
| Size | 1.8 MB |
| Tags | CPython 3.10 macOS 14.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
d8cdfc4e8856f4a35e5df9169d660742b8823914bfb6def0b6c259ddb9116aa5
|
|
BLAKE2b-256 checksum How to use checksums |
769b89c21351b898e5c974f94bb32c6a33ea0a32ad4f31a7ab4d5d10bfa2f9a5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 24, 2026.
Transparency log