Skip to main content

Python bindings for the Flox indicator library

Project description

flox-py

Python bindings for the FLOX trading framework.

Install

pip install flox-py

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()

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
        pass

    def on_book_update(self, ctx): ...

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)

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 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 Annualized Sharpe ratio
max_drawdown_pct Peak-to-trough drawdown (%)

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, 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

flox_py-0.5.5.tar.gz (46.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

flox_py-0.5.5-cp313-cp313-win_amd64.whl (534.6 kB view details)

Uploaded CPython 3.13Windows x86-64

flox_py-0.5.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

flox_py-0.5.5-cp313-cp313-macosx_14_0_arm64.whl (669.2 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

flox_py-0.5.5-cp312-cp312-win_amd64.whl (534.6 kB view details)

Uploaded CPython 3.12Windows x86-64

flox_py-0.5.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

flox_py-0.5.5-cp312-cp312-macosx_14_0_arm64.whl (669.1 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

flox_py-0.5.5-cp311-cp311-win_amd64.whl (535.3 kB view details)

Uploaded CPython 3.11Windows x86-64

flox_py-0.5.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

flox_py-0.5.5-cp311-cp311-macosx_14_0_arm64.whl (662.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

flox_py-0.5.5-cp310-cp310-win_amd64.whl (534.2 kB view details)

Uploaded CPython 3.10Windows x86-64

flox_py-0.5.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

flox_py-0.5.5-cp310-cp310-macosx_14_0_arm64.whl (661.0 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

Details for the file flox_py-0.5.5.tar.gz.

File metadata

  • Download URL: flox_py-0.5.5.tar.gz
  • Upload date:
  • Size: 46.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flox_py-0.5.5.tar.gz
Algorithm Hash digest
SHA256 df3635099badf402d2190e99fce57576f9f0ac415ba267a785a5d75fbcb70c8c
MD5 90fbfb489d655660826496c99ae67903
BLAKE2b-256 437efcee27e87067287e0d92822d8a4bc4505b640b293bc6916e0a4a7e86fca6

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5.tar.gz:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: flox_py-0.5.5-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 534.6 kB
  • Tags: CPython 3.13, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flox_py-0.5.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 2b71b09de20a2ee4fdc3e151cedf8b36b71c98255e24a16579ac5238a88c0992
MD5 79a1862332089ed922c86c10ff19b36b
BLAKE2b-256 dd9b197618fb2aef54634fc6212363561f8c3a86c7808c17f25e235db8d3a732

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp313-cp313-win_amd64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 a599d07fe080dc2040487e00f7e63f694ea34c3e27ef4e02a50c3be66cf7e35a
MD5 9f8442382aa86d2dc90a8b760c0bfb07
BLAKE2b-256 06254f44c5d7f0b3d9a6bc0addb5a314118699a194bd40f9e063e930e3fdd5e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.5-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0c9d45f3cb22c9d3b9cda7426ae35a0ba5da7862e07e996744daa3473c4f2459
MD5 f1069783c6927ff9c22876e9f42e3a50
BLAKE2b-256 2d138e8869ed11fb09b2a2ab2706186a17649a15a2f400982c398e936d551c5e

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp313-cp313-macosx_14_0_arm64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: flox_py-0.5.5-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 534.6 kB
  • Tags: CPython 3.12, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flox_py-0.5.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8eaa5503417654e1b4318de320a58e5f6ea16db4fb794f25272a657ccf063e40
MD5 86f1051453b125806e229be22ab5f672
BLAKE2b-256 5db3d217e3a1a7291fb53227465eb1d4d98be8a786a01e73ad099705f1331482

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp312-cp312-win_amd64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 6ff5de2c7f092265b3fb958c48f070e954829b5e80e48892a8dfaf0e27705567
MD5 3ea8cf05bc0180b13af7468d314fa357
BLAKE2b-256 105549dbc4854eaba05a03d7d0bd3362b8d2c2136967e3601929ce5e925566c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.5-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f1d65c9d39fa9bd010201df95e627ae27d7e6caa74f607427b2fdc8a071daec0
MD5 3225ae90c465b68d5cb11d8d7c818fed
BLAKE2b-256 5e44bd2d5e4273fbd770dd0a62c7577f07293e78ab1482b048bee6dc1bed7896

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp312-cp312-macosx_14_0_arm64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: flox_py-0.5.5-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 535.3 kB
  • Tags: CPython 3.11, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flox_py-0.5.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 837e6b04e42be7d504dc57c631cfb5d1e41f1b8a79bde64211d0beddb82759fc
MD5 ecf28111bdb76f4e18c52268856de479
BLAKE2b-256 5c66731fec3332e667b23555115307eeb49c2852489d36fc8a62b4b9b39d2bdd

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp311-cp311-win_amd64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 dd985e9a9c7d55fc5ec9e732dda728938111129a8bd6878ec1847745981cffc8
MD5 3254b41b5a878fef0fd764146a76df6b
BLAKE2b-256 e6d7da3a2e98ef41bed0e760fa1fe1ea4b03720b1d3669e3a372cc8c1193d949

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.5-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 75848beaca405383b08c6fe30119601ec394846c2da5f393e7a83e55f9c5b8e6
MD5 8a7cb7f7bfc5a97fbe17d3c003d718b1
BLAKE2b-256 2108a4a54775bc4f8ce6ff7af06cd27e79d83803916f555ca973b7c84182eb41

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp311-cp311-macosx_14_0_arm64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: flox_py-0.5.5-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 534.2 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for flox_py-0.5.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 40c22f10cef4e0028f18bac539192b595a9bca0c375cdae634fdb1646fa97901
MD5 fc9ab2c57236b4489715359020c34214
BLAKE2b-256 1d6349dffc0463f92136563c00dd471dcfc22ec267fda041df80114070846919

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp310-cp310-win_amd64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f2a79b07bef274965250629bb6616d441b7659e4d687a2d2b07f21168166a560
MD5 f05898799fb4c26f85c04a07b70249ab
BLAKE2b-256 6c96af597f0ee1b6bf4e3f5e33e826737ccf588f0199c322cce8a314effd5959

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file flox_py-0.5.5-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.5-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 f2e8c7d6694ac9b6c5d930ebdd994b54889a4e3837b901133a7c16714a47adc4
MD5 95c3cfb7358d777b6af9debbf4de2f9f
BLAKE2b-256 6ca3c246469c503b8242b9f4b5322375fbaa504cfb84b05f9d6e63a7c453c791

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.5-cp310-cp310-macosx_14_0_arm64.whl:

Publisher: python-wheels.yml on FLOX-Foundation/flox

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page