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.1.tar.gz (8.3 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.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: orderflow_gregorian09-0.1.1.tar.gz
  • Upload date:
  • Size: 8.3 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.1.tar.gz
Algorithm Hash digest
SHA256 8033ba3bda5d461b7114b95a0a47d3f316bee451ffb3455e8e5d549d329e2eb4
MD5 e9485b92234c693dde757ca5837d2bd8
BLAKE2b-256 1ca690d822c6e268455a57f19a6ea7a284f57915842f0360818edff2bac76e9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for orderflow_gregorian09-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 645301adba4b3072c5c815e75c76766905a15473590fc4d773b247e9ca943972
MD5 30f108cbc0d002e2ebbe67363ecc7165
BLAKE2b-256 9ec0536b3a87bb6fae856a419ffe4201303ef5ccf824a7497ca2852286f6084a

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