Skip to main content

Python wrapper for a high-performance Rust orderbook CLI

Project description

hft-lob

Python library for reading NSE binary market feed files and reconstructing a Limit Order Book (LOB).


Install

pip install hft-lob

Configure (once)

Tell the library where your file is and which token to read:

cat > ~/.hft_lob << 'EOF'
FILE=/nas/50.30/NSE_CM/Feed_CM_StreamID_2_29_12_2025.bin
TOKEN=1333
EOF

For multiple tokens, use comma-separated values:

TOKEN=1333,2885,5900

Run

hft-lob get_next

Prints the next LOB message as a CSV row.

hft-lob get_all

Prints all LOB messages, one CSV row per line.

hft-lob eof

Prints True if no messages available, False if messages exist.


Python API

from hft_lob.cli import Reader

r = Reader("/path/to/feed.bin", tokens=1333)

r.get_next_message()    # returns one CSV string, or None
r.get_all_messages()    # returns list of all CSV strings
r.is_end_of_file()      # returns True / False
r.header                # CSV column names

Multiple tokens:

r = Reader("/path/to/feed.bin", tokens=[1333, 2885, 5900])
msgs = r.get_all_messages()
print(f"Total: {len(msgs)}")

CSV Output Format

23 fields per row:

Field Description
local_ts Local timestamp (nanoseconds)
exch_ts Exchange timestamp (nanoseconds)
mid_price (best bid + best ask) / 2
bid_price_0..4 Bid price at depth level 0–4
bid_qty_0..4 Bid quantity at depth level 0–4
ask_price_0..4 Ask price at depth level 0–4
ask_qty_0..4 Ask quantity at depth level 0–4

Load into pandas

import io, pandas as pd
from hft_lob.cli import Reader

r = Reader("/path/to/feed.bin", tokens=1333)
msgs = r.get_all_messages()
df = pd.read_csv(io.StringIO(r.header + "\n" + "\n".join(msgs)))
print(df.head())

Platform

Linux x86_64 only. The Rust binary is bundled — no extra install needed.


License

MIT

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

hft_lob-0.2.3.tar.gz (221.0 kB view details)

Uploaded Source

Built Distribution

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

hft_lob-0.2.3-py3-none-any.whl (220.7 kB view details)

Uploaded Python 3

File details

Details for the file hft_lob-0.2.3.tar.gz.

File metadata

  • Download URL: hft_lob-0.2.3.tar.gz
  • Upload date:
  • Size: 221.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for hft_lob-0.2.3.tar.gz
Algorithm Hash digest
SHA256 379c2f2c8c11e0dc14e3d17def4dbac2726a8a8364a21db4b4dacb12d583a3b9
MD5 da721d8d602e069aa9c1307b183e26dd
BLAKE2b-256 967a7a90133b9abe501083d5928537d3b4bb2719532d6a1132d7286259a33082

See more details on using hashes here.

File details

Details for the file hft_lob-0.2.3-py3-none-any.whl.

File metadata

  • Download URL: hft_lob-0.2.3-py3-none-any.whl
  • Upload date:
  • Size: 220.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.14

File hashes

Hashes for hft_lob-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d1e2f6ad3f56dba4ea52d572ec227c1a068e733dd5bbddef19a163ad9d395d81
MD5 5c5e4b536d58d81f98d86ee5e2a86b28
BLAKE2b-256 3cb6166f008c75935d89af9561e220a0dfc9c20685f9662c5dbc4ff4b45ed407

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