Metadata-Version: 2.4
Name: hft-lob
Version: 0.2.3
Summary: Python wrapper for a high-performance Rust orderbook CLI
Home-page: https://github.com/pratima/hft_lob
Author: Pratima Kumari
Author-email: Pratima Kumari <pratimarmoney@gmail.com>
License-Expression: MIT
Project-URL: Homepage, https://github.com/pratima/hft_lob
Requires-Python: >=3.7
Description-Content-Type: text/markdown
Dynamic: author
Dynamic: home-page
Dynamic: requires-python

# hft-lob

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

---

## Install

```bash
pip install hft-lob
```

---

## Configure (once)

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

```bash
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:

```bash
TOKEN=1333,2885,5900
```

---

## Run

```bash
hft-lob get_next
```
Prints the next LOB message as a CSV row.

```bash
hft-lob get_all
```
Prints all LOB messages, one CSV row per line.

```bash
hft-lob eof
```
Prints `True` if no messages available, `False` if messages exist.

---

## Python API

```python
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:

```python
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

```python
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
