Skip to main content

Python ctypes binding for the Orderflow C API

Project description

Python Binding (ctypes)

This package wraps crates/of_ffi_c through ctypes.

Build the native library

From workspace root:

cargo build -p of_ffi_c

Default lookup path is target/debug/libof_ffi_c.so (Linux), with platform-specific suffix handling.

You can override lookup with:

export ORDERFLOW_LIBRARY_PATH=/absolute/path/to/libof_ffi_c.so

Install package (editable)

From bindings/python:

python -m pip install -e .

Quick usage

from orderflow import BookAction, Engine, EngineConfig, ExternalFeedPolicy, Side, Symbol, StreamKind

cfg = EngineConfig(instance_id="py-client", config_path="")

with Engine(cfg) as eng:
    sym = Symbol("CME", "ESM6", depth_levels=10)
    eng.subscribe(sym, StreamKind.ANALYTICS)
    eng.subscribe(sym, StreamKind.HEALTH, callback=lambda ev: print("health", ev))
    eng.configure_external_feed(ExternalFeedPolicy(stale_after_ms=2_000, enforce_sequence=True))
    eng.poll_once()
    eng.ingest_book(sym, side=Side.BID, level=0, price=504900, size=20, action=BookAction.UPSERT)
    eng.ingest_trade(sym, price=505000, size=7, aggressor_side=Side.ASK)
    eng.unsubscribe(sym)
    print(eng.analytics_snapshot(sym))
    print(eng.signal_snapshot(sym))
    print(eng.metrics())

Notes

  • config_path can point to runtime .toml or .json config consumed by Rust runtime.
  • ORDERFLOW_LIBRARY_PATH is honored when library_path is not passed to Engine(...).
  • Optional callback is supported on subscribe(...) and fires during poll_once(...) and external ingest_* calls.
  • StreamKind.HEALTH emits only on health state changes and includes fields like health_seq, connected, degraded, reconnect_state, quality_flags, and protocol_info.
  • Engine.reset_symbol_session(symbol) resets per-session analytics/profile context for a symbol.
  • Engine.ingest_trade(...) and Engine.ingest_book(...) let you inject external feed events directly without using a market-data adapter stream.
  • Engine.configure_external_feed(...), Engine.set_external_reconnecting(...), and Engine.external_health_tick() provide uniform sequence-gap/stale/reconnect supervision for external feeds.

Examples

  • bindings/python/examples/basic.py
  • bindings/python/examples/health_example.py
  • bindings/python/examples/external_ingest.py

Run:

python bindings/python/examples/health_example.py

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

orderflow_gregorian09-0.1.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

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

orderflow_gregorian09-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file orderflow_gregorian09-0.1.0.tar.gz.

File metadata

  • Download URL: orderflow_gregorian09-0.1.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for orderflow_gregorian09-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b6bd13ba3a405ce0173010f5bb7fde2e641d664ccbd55291f978050162ad2ec
MD5 451472bd0f4f358256dd5353ec36aca7
BLAKE2b-256 191881d366c09c8c5bf8af069160fd4885969c694779b8a4d982928a1a5c288d

See more details on using hashes here.

File details

Details for the file orderflow_gregorian09-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for orderflow_gregorian09-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fdddc8d4a476386d102388135e69283c7a523442246d85a514b77be00c1912e
MD5 b7407e08ad687e4fec2c3121736b0a6f
BLAKE2b-256 f0e96cb427053be0009205dde4443b84d1e8c081f082a4a6cad32dd1417379d5

See more details on using hashes here.

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