Skip to main content

High-performance exchange feed parser and orderflow analytics engine with Rust and Python bindings

Project description

fastreader

High-performance Rust + PyO3 library for reading binary market data and generating order book snapshots directly from Python.

fastreader is designed for Python quant developers who need:

  • Fast binary message parsing
  • Order and trade message inspection
  • Token-level filtering
  • Sequential message streaming
  • Order book reconstruction
  • Top-of-book / depth snapshot generation

The library is implemented in Rust for speed and exposed to Python using PyO3.


Features

  • Parse binary market feed files
  • Read order and trade messages
  • Filter data by token/instrument
  • Sequential message iteration
  • Generate order book snapshots
  • Configurable market depth
  • Fast memory-efficient Rust backend
  • Python-friendly API

Installation

Build Using maturin

pip install maturin
maturin develop --release

OR build wheel:

maturin build --release

Python Import

import fastreader

Main Classes

Class Description
BinaryDataLoader Loads and reads binary market data
OrderBookGenerator Generates order book snapshots

BinaryDataLoader

The BinaryDataLoader class loads binary feed data into memory and provides utilities to inspect messages.


Constructor

BinaryDataLoader(path, token=None)

Parameters

Parameter Type Description
path str Path to binary market data file
token int or None Optional instrument token filter

Example

from fastreader import BinaryDataLoader

loader = BinaryDataLoader(
    path="data/feed.bin",
    token=26000
)

BinaryDataLoader Functions


total_messages()

Returns total number of messages loaded.

Returns

int

Example

count = loader.total_messages()
print(count)

total_orders()

Returns total order messages.

Returns

int

Example

orders = loader.total_orders()
print(orders)

total_trades()

Returns total trade messages.

Returns

int

Example

trades = loader.total_trades()
print(trades)

summary()

Returns formatted dataset summary.

Returns

str

Example

print(loader.summary())

Sample Output

Total Messages: 250000
Total Orders: 180000
Total Trades: 70000

reset_cursor()

Resets internal sequential message cursor.

Useful when using get_next_message().

Example

loader.reset_cursor()

get_all_messages(limit=None)

Returns all messages as formatted strings.

Parameters

Parameter Type Description
limit int or None Maximum messages to return

Returns

List[str]

Example

messages = loader.get_all_messages(limit=5)

for msg in messages:
    print(msg)

Sample Output

Order Message: SeqNo1, msg_len64 ...
Trade Message: SeqNo2, msg_len48 ...

get_order_messages(limit=None)

Returns only order messages.

Parameters

Parameter Type Description
limit int or None Maximum messages to return

Returns

List[str]

Example

orders = loader.get_order_messages(limit=10)

for order in orders:
    print(order)

get_trade_messages(limit=None)

Returns only trade messages.

Parameters

Parameter Type Description
limit int or None Maximum messages to return

Returns

List[str]

Example

trades = loader.get_trade_messages(limit=10)

for trade in trades:
    print(trade)

get_next_message()

Returns next message sequentially.

Internal cursor automatically moves forward after each call.

Returns

str

Returns:

  • Message string
  • "END" when all messages are consumed

Example

while True:
    msg = loader.get_next_message()

    if msg == "END":
        break

    print(msg)

OrderBookGenerator

The OrderBookGenerator reconstructs order books from order/trade messages.

It produces snapshot rows with configurable market depth.


Constructor

OrderBookGenerator(depth=5)

Parameters

Parameter Type Description
depth int Number of bid/ask levels

Example

from fastreader import OrderBookGenerator

ob = OrderBookGenerator(depth=5)

OrderBookGenerator Functions


reset()

Resets internal order book state.

Example

ob.reset()

header()

Returns CSV-style order book header.

Returns

str

Example

print(ob.header())

Sample Output

local_ts,exch_ts,mid_price,bid_price_0,bid_qty_0,ask_price_0,ask_qty_0

create_orderbook(store)

Default order book generation method.

Internally calls:

create_orderbook_from_all_messages()

Parameters

Parameter Type Description
store BinaryDataLoader Loaded binary dataset

Returns

List[str]

Example

rows = ob.create_orderbook(loader)

for row in rows[:5]:
    print(row)

create_orderbook_from_all_messages(store)

Generates order book snapshots using:

  • Order messages
  • Trade messages

Parameters

Parameter Type Description
store BinaryDataLoader Loaded binary dataset

Returns

List[str]

Example

rows = ob.create_orderbook_from_all_messages(loader)

create_orderbook_from_trade_messages(store)

Generates snapshots using only trade messages.

Parameters

Parameter Type Description
store BinaryDataLoader Loaded binary dataset

Returns

List[str]

Example

trade_rows = ob.create_orderbook_from_trade_messages(loader)

create_orderbook_from_next_messages(store)

Generates order book sequentially using cursor-based streaming.

Useful for:

  • Streaming simulations
  • Backtesting engines
  • Sequential replay systems

Parameters

Parameter Type Description
store BinaryDataLoader Loaded binary dataset

Returns

List[str]

Example

loader.reset_cursor()

rows = ob.create_orderbook_from_next_messages(loader)

row_count_from_all_messages(store)

Returns total generated snapshot rows.

Parameters

Parameter Type Description
store BinaryDataLoader Loaded binary dataset

Returns

int

Example

count = ob.row_count_from_all_messages(loader)
print(count)

Complete Python Example

from fastreader import BinaryDataLoader
from fastreader import OrderBookGenerator

# Load binary feed
loader = BinaryDataLoader(
    path="data/feed.bin",
    token=26000
)

# Dataset information
print(loader.summary())

# Print first 5 messages
messages = loader.get_all_messages(limit=5)

for msg in messages:
    print(msg)

# Create order book generator
ob = OrderBookGenerator(depth=5)

# Generate snapshots
rows = ob.create_orderbook(loader)

# Print first rows
for row in rows[:10]:
    print(row)

Order Book Output Format

Each snapshot row contains:

Field Description
local_ts Local receive timestamp
exch_ts Exchange timestamp
mid_price Mid market price
bid_price_n Bid price at level n
bid_qty_n Bid quantity at level n
ask_price_n Ask price at level n
ask_qty_n Ask quantity at level n

Performance Notes

Since parsing and processing are implemented in Rust:

  • Much faster than pure Python
  • Lower memory overhead
  • Efficient sequential processing
  • Suitable for HFT and quant research workflows

Error Handling

If binary parsing fails:

RuntimeError

Typical reasons:

  • Invalid file path
  • Corrupted binary file
  • Unsupported binary structure

Suggested Project Structure

project/
│
├── data/
│   └── feed.bin
│
├── scripts/
│   └── analysis.py
│
└── fastreader/

Example Workflow for Quant Developers

from fastreader import BinaryDataLoader
from fastreader import OrderBookGenerator
import pandas as pd

loader = BinaryDataLoader("data/feed.bin")

ob = OrderBookGenerator(depth=5)

rows = ob.create_orderbook(loader)

header = rows[0].split(",")
data = [r.split(",") for r in rows[1:]]

# Convert to DataFrame
book_df = pd.DataFrame(data, columns=header)

print(book_df.head())

Future Improvements

Possible future extensions:

  • Direct NumPy output
  • Pandas integration
  • Multi-threaded parsing
  • Async streaming
  • Arrow/Parquet export
  • Zero-copy Python buffers
  • Real-time feed support

License

MIT License

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

orderpulse-0.2.22.tar.gz (19.4 kB view details)

Uploaded Source

Built Distribution

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

orderpulse-0.2.22-cp312-cp312-manylinux_2_34_x86_64.whl (248.9 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64

File details

Details for the file orderpulse-0.2.22.tar.gz.

File metadata

  • Download URL: orderpulse-0.2.22.tar.gz
  • Upload date:
  • Size: 19.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for orderpulse-0.2.22.tar.gz
Algorithm Hash digest
SHA256 97ae0a603beef455a952f7fcc51689ea1674d55c7c73f74760c7f85b28fc7d37
MD5 7b4fb0758a9d74e359add624819d77f7
BLAKE2b-256 3fb95442bf3c5aa03630bba0f9a46279dc0e5ce2b6c1135177ece31a9e61956b

See more details on using hashes here.

File details

Details for the file orderpulse-0.2.22-cp312-cp312-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for orderpulse-0.2.22-cp312-cp312-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 17f336816d0cffbc886b1a065cf9d68909d0066a17a1c17edae20f5de22cd3e2
MD5 234984c110866f26187c7a9102dc1c39
BLAKE2b-256 9d7a728131461e78236214bb21e37edc1e09e8db9b8704b9819e13d5b8ee706b

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