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.3.tar.gz (43.7 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.3-cp313-cp313-win_amd64.whl (498.1 kB view details)

Uploaded CPython 3.13Windows x86-64

flox_py-0.5.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (939.1 kB view details)

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

flox_py-0.5.3-cp313-cp313-macosx_14_0_arm64.whl (562.1 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

flox_py-0.5.3-cp312-cp312-win_amd64.whl (498.1 kB view details)

Uploaded CPython 3.12Windows x86-64

flox_py-0.5.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (939.5 kB view details)

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

flox_py-0.5.3-cp312-cp312-macosx_14_0_arm64.whl (562.0 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

flox_py-0.5.3-cp311-cp311-win_amd64.whl (497.0 kB view details)

Uploaded CPython 3.11Windows x86-64

flox_py-0.5.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (936.6 kB view details)

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

flox_py-0.5.3-cp311-cp311-macosx_14_0_arm64.whl (557.0 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

flox_py-0.5.3-cp310-cp310-win_amd64.whl (496.1 kB view details)

Uploaded CPython 3.10Windows x86-64

flox_py-0.5.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (936.7 kB view details)

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

flox_py-0.5.3-cp310-cp310-macosx_14_0_arm64.whl (555.8 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: flox_py-0.5.3.tar.gz
  • Upload date:
  • Size: 43.7 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.3.tar.gz
Algorithm Hash digest
SHA256 1bb91f37ea295f325c0303d39b0dcfe503b2dcf97bb729efafb79bb56c1a9227
MD5 09b3c55ee4500ffccaed8ea16ca0938b
BLAKE2b-256 7736772f93518a0df5f31e7a79c3cba6348ee8d93aac5586e67a129873663c43

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3.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.3-cp313-cp313-win_amd64.whl.

File metadata

  • Download URL: flox_py-0.5.3-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 498.1 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.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 f9be6c12b303a19bdaa80cce693c4e4fd5f7e9e6b5e10d281ebb320b81a7238a
MD5 d0cd2ef396e2a11739d1ba47a6c8951e
BLAKE2b-256 d4e8db7c82a12385666013ec01c7d2660ffeab3c50878f78e68a316ee20482df

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.3-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4fd7c67457d93f358a59177d96060e140ae8f8c5a12b8484d18398243e9949f7
MD5 253f8d9d9364f17f335505a1d3fa9a61
BLAKE2b-256 a30148bae08df12b286c1f0230faeb4b7d2817f6ef67003c1b30c0d90273b708

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp313-cp313-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.3-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ebd3d34fb43abdb7fc543bed008abd2a5aaa7bcaed61e5c8c4aa40fc56673016
MD5 f17a6606dd33deaf886717e9852afb16
BLAKE2b-256 17979a25079a5bcf7f59400e5bfb1f115e9af23cf95c0a625d0005dd2512970e

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp312-cp312-win_amd64.whl.

File metadata

  • Download URL: flox_py-0.5.3-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 498.1 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.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 75ced4fc54fbdf5774638667e655dd5710b6ecea1817d98b1fb863655da4534a
MD5 2fc1fe1eb12c5ff0833e75abf3b96839
BLAKE2b-256 3f310630fec8aadeb09ecfda2e6e310fe81fd9c59c73f4e41873b0cda97593d6

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.3-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 f3ea49739dfe0e295931816aa3407f0766cbd1ed95cf87fc32ab4f126d88eb43
MD5 faa7f08d10e7375e927889b52f02f2a5
BLAKE2b-256 e4dc31ec7bf62fa5f787a6e341a26804d28ca2e46ea8fa505f7662ef36d4bd7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp312-cp312-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.3-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 24c886d5a2cbd07d8bcd018c470b0078a42baa048bf2be10a50fd15e94f6bb03
MD5 d10e8c6892e6d2cbe6e39d00210dda57
BLAKE2b-256 96c79810ed9744d3cdb3ac1a3f96fc6ba25d8e00df4b144d1da05f958f97acd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp311-cp311-win_amd64.whl.

File metadata

  • Download URL: flox_py-0.5.3-cp311-cp311-win_amd64.whl
  • Upload date:
  • Size: 497.0 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.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 51a20395a695ed2f1ff2a7215a3b7828d4524cf0d65f27779b0433c1c35fcf4d
MD5 ec20a8c8f935d3568533b24260ac7754
BLAKE2b-256 c2e22ef3480a71c5f67b9ec9475a742b1d2ec078e3f4234022855e708c2a35dc

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.3-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 75c861b26f11545859970102b778ebb0caeb1af7dbb52efb8eb1ce0514eaa51c
MD5 15b2c1126d451e4f8e448990bb6b84e0
BLAKE2b-256 9876398352bc851734de97ee5f81bbda23e2b00aaf36e81ad33dd8db71de2351

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.3-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 9bfa0321d07e0936bad3c20230b7f8d7e10864becfc5fbc04b6f7aac8e9c8b71
MD5 966f7f9f730d599dae9956139a46c32c
BLAKE2b-256 cc2a62c776595715400e6347ba1ece415a0a39eddb31f5257078a49f70dad650

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: flox_py-0.5.3-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 496.1 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.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 4d3f3a539aeab40da4cb29a54c04d9c9bb52df72ec6db1477ad8966a32060a22
MD5 2cb9d95891185b9554785f542a66a0dd
BLAKE2b-256 24ea22950661419f2a9407dc12f1c0e78248aacc5f0cb40407a1ff1c51fb95b2

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.3-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 65d39d7a5c24be10b72be7a64a9864e7d1e51bb8f5a405b34deaae72c85aa226
MD5 92fad9c23c6130aff1a4edca786baa92
BLAKE2b-256 176d0acb182a422e2a57c4b4d286a9240ca2241af850903c3f1f02d554ae75fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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.3-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for flox_py-0.5.3-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 5242b1290c922d826dff209f5421557a756c73d244a32fc2b0436c183591bf5a
MD5 b5f2d7b8d5d5304f1b418336a10e1d57
BLAKE2b-256 22962aca62925a1109041142cc6640c99955453dcb1e7bc33f7e6c5d7160fed1

See more details on using hashes here.

Provenance

The following attestation bundles were made for flox_py-0.5.3-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