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.6.tar.gz (47.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.6-cp313-cp313-win_amd64.whl (534.5 kB view details)

Uploaded CPython 3.13Windows x86-64

flox_py-0.5.6-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.6-cp313-cp313-macosx_14_0_arm64.whl (669.2 kB view details)

Uploaded CPython 3.13macOS 14.0+ ARM64

flox_py-0.5.6-cp312-cp312-win_amd64.whl (534.5 kB view details)

Uploaded CPython 3.12Windows x86-64

flox_py-0.5.6-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.6-cp312-cp312-macosx_14_0_arm64.whl (669.2 kB view details)

Uploaded CPython 3.12macOS 14.0+ ARM64

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

Uploaded CPython 3.11Windows x86-64

flox_py-0.5.6-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.6-cp311-cp311-macosx_14_0_arm64.whl (662.5 kB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

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

Uploaded CPython 3.10Windows x86-64

flox_py-0.5.6-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.6-cp310-cp310-macosx_14_0_arm64.whl (661.2 kB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

File details

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

File metadata

  • Download URL: flox_py-0.5.6.tar.gz
  • Upload date:
  • Size: 47.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.6.tar.gz
Algorithm Hash digest
SHA256 031b1700f01cf94a231f070702f6c9f54f3da890f1b361b5cd3c3e1bee061546
MD5 7167ceeeedf7fa56a482ca47d17ba958
BLAKE2b-256 07c6cef6defd60f0110630516a931561b9427fe6ca5fa255c7472f7250113d92

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: flox_py-0.5.6-cp313-cp313-win_amd64.whl
  • Upload date:
  • Size: 534.5 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.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c5662bba02e875147b335313ead770a7baf0dec1b44541e6392a6136f392a3e6
MD5 ceae6a7a84065e427bb7a4a741442e93
BLAKE2b-256 ab547fe5dc841cf09c09ce5e635efbf5f0488453d0c783ae3c340b08c8673ccd

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flox_py-0.5.6-cp313-cp313-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 8321f01e7ce21fbab1b25278319bd05c22814263be9467863885d3c77875394b
MD5 9943ccce35ccc498e2a9566b3fbfe74b
BLAKE2b-256 47801e1376a9b1c68001931df7f1dea276bde243e1a75b4eb6ba133426a8ba8c

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flox_py-0.5.6-cp313-cp313-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 80379a32a116b718156da5d20989da6bc5da35ac324b630f0d7d44a7892bf3e7
MD5 e61cff5567e82a1b3f5877aaebc4509b
BLAKE2b-256 5fa5d4a3c16b815d9fe39e8d92200286d13609fb489471c2b7456f7c589bb5bf

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: flox_py-0.5.6-cp312-cp312-win_amd64.whl
  • Upload date:
  • Size: 534.5 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.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 25f57c24bbe3feff6304eb2eaf497b4fa98ea9614c84feedb45de308956debdc
MD5 fefb5158e188f8f0e7e5c0504a51e2d2
BLAKE2b-256 e2b56d3514f4351243d3924762f93d4252dbf6931254a23b3da74294f8432287

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flox_py-0.5.6-cp312-cp312-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 34623a66078e48126110d73221a69139fe6179e1b322977485bd3af1b14a02e6
MD5 d9eff29857623fd38d0f65404281938b
BLAKE2b-256 bf4816e9df24e4a7d61dc0a6a53efbcdc9491b6794222dd4513d55bd2c629322

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flox_py-0.5.6-cp312-cp312-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 53a2251d58d890fa40b4fb2620401a0441a0cf90d53401d388bf4e4949f84c57
MD5 510faf20470a06fc5ddc2772df1c056d
BLAKE2b-256 a198b4a6113a04b1c77d2b84e1cb9941ab8caddc55f63834223dcac69dfa183f

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: flox_py-0.5.6-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.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 31e33f9ec166fac42102d36e8db6d5f224df12b04c6a6dc95db4a53a5589a75f
MD5 b3d4239b82b7681c12ea0286d5d300bd
BLAKE2b-256 3295b65608154103e204b6f9b60d77ae72cf4a74c3d3467ae4847a59f00648a0

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flox_py-0.5.6-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 802571459e9a2cb7afb21ffd88c4c4fe9c6710c1edc0f0299f0ffaa1bd58e148
MD5 e969988b478f1e44367dac32a7d774a8
BLAKE2b-256 9858e02e9f375a7b46e8b0bc219f05943e05cead4ddd75f3e278f123825f8740

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flox_py-0.5.6-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7a35d007c371b44ba4d5d809c7d3451328853844bc3587c121849bf8598e177f
MD5 1d7e4c6d25916886a4e49e47b56a930e
BLAKE2b-256 4179f381490188b97a48fb0a4827c713eab5855070f286eef719b1cc7fec91e9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: flox_py-0.5.6-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.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b742bc11facf3e508ec90f5adc0402cfd1bf97cee98dc86eaeaf3cd889601a7b
MD5 98e33b738c409306dec72d1d7b73a3e4
BLAKE2b-256 c4c3d1e7278e5a10e5b3ed1f9e04f70ed8382811206cfdd5f4bf20ab5470a3bf

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flox_py-0.5.6-cp310-cp310-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 73ba2dceedb445425f517699b322f6f026326425a347969141647d4976ec2a9d
MD5 fbd24e47767ff6f6faeeb991baeafd1a
BLAKE2b-256 7a6e19bd214371fad7aebe582a29668ee581dd1ad3d01a02508ea60e604ff89e

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for flox_py-0.5.6-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 ce8bc40c63312669f7fdeb069388b4d764f1a24fa1f94e50aeb5f01639688806
MD5 e6781fae05fa88597f8d1490ea74943b
BLAKE2b-256 ab814078039630ae48b667d4409f8cbd93a4fc38d1c05baf82637d5a21f304ab

See more details on using hashes here.

Provenance

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