Metadata-Version: 2.4
Name: rithmic-bridge
Version: 1.0.1
Summary: Rithmic R|API+ MBO & Trade Data Bridge - ZeroMQ PUB/SUB bridge system
Project-URL: Homepage, https://github.com/akivajp/rithmic-bridge
Project-URL: Repository, https://github.com/akivajp/rithmic-bridge
Author-email: Akiva Miura <akiva.miura@gmail.com>
License: MIT
Keywords: bridge,market-data,mbo,rithmic,trading,zeromq
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Office/Business :: Financial :: Investment
Requires-Python: >=3.10
Requires-Dist: python-dotenv>=1.0
Requires-Dist: pythonnet==3.0.5; platform_system == 'Windows'
Requires-Dist: pyzmq>=25.0
Requires-Dist: rich>=13.0
Provides-Extra: client
Requires-Dist: numpy>=1.24; extra == 'client'
Provides-Extra: dev
Requires-Dist: pytest-asyncio>=0.21; extra == 'dev'
Requires-Dist: pytest>=7.0; extra == 'dev'
Provides-Extra: publisher
Requires-Dist: pythonnet==3.0.5; extra == 'publisher'
Provides-Extra: rl
Requires-Dist: numpy>=1.24; extra == 'rl'
Requires-Dist: torch>=2.0; extra == 'rl'
Description-Content-Type: text/markdown

# Rithmic MBO & Trade Data Bridge

[![PyPI version](https://badge.fury.io/py/rithmic-bridge.svg)](https://badge.fury.io/py/rithmic-bridge)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)

A high-performance market data bridge that connects to Rithmic via R|API+ (.NET) and publishes MBO (Market-by-Order) and Trade data over ZeroMQ. Designed for low-latency algorithmic trading and RL (Reinforcement Learning) environments.

[日本語版はこちら (Japanese version)](README.ja.md)

## Architecture

```mermaid
sequenceDiagram
    participant Client as Client Application (WSL2/Linux/Python)
    participant Publisher as Rithmic Bridge Publisher (Windows)
    participant Rithmic as Rithmic Infrastructure (R|API+)

    Note over Publisher, Rithmic: Connects via Plugin Mode (Port 56000)
    Publisher->>Rithmic: Subscribe(Symbol, Exchange)
    Rithmic-->>Publisher: Market Data (MBO/Trade)
    Publisher-->>Client: ZeroMQ PUB (Stream Data)
    Client->>Publisher: ZeroMQ REQ (Dynamic Subscription)
```

## Features

- **Dynamic Subscription**: Subscribe to symbols on-the-fly without restarting the server.
- **MBO Support**: Real-time Order Book reconstruction (Level 3 data).
- **ZeroMQ Distribution**: Publish data to multiple clients over the network (e.g., from Windows to WSL2).
- **Python Library**: Ready-to-use `RithmicClient` class for easy integration.
- **Low Latency**: Optimized queue management and data serialization.

## Prerequisites

- **Windows 10/11** (for the Publisher)
- **R | API+ (.NET)** from Rithmic
- **R | Trader Pro** (for Plugin Mode connection)
- **Python 3.10+**

## Installation

### 1. R | API+ (.NET) Setup

This project requires the Rithmic API library `rapiplus.dll`. **Redistribution of this DLL is prohibited.**

1.  **Request the API**: Visit [https://www.rithmic.com/api-request](https://www.rithmic.com/api-request) and request the **R | API (.NET)**.
2.  **Installation**: Place the `rapiplus.dll` from the downloaded package into the standard Rithmic path:
    `C:\Program Files (x86)\Rithmic\Rithmic Trader Pro\rapiplus.dll`

### 2. Install the Bridge

```bash
pip install rithmic-bridge

# Recommended for local editable CLI usage
uv tool install --editable .
```

## Quick Start

### 1. Launch the Publisher (Windows)

Launch the publisher in R|API mode. You can provide credentials via command-line arguments:

```bash
uvx rithmic-bridge publish --mode rapi --user YOUR_USER --password YOUR_PASS --symbol GCJ6 --exchange COMEX
```

*Note: Use `--mode dummy` for testing without a Rithmic account.*

### 2. Use the Client Library (Client/WSL2)

```python
from rithmic_bridge.client.library import RithmicClient

# Connect to the publisher on Windows
client = RithmicClient(host="192.168.x.x")

# Define callbacks
def on_mbo(event):
    print(f"MBO: {event.price} x {event.size}")

def on_trade(event):
    print(f"TRADE: {event.price} @ {event.size}")

client.on_mbo(on_mbo)
client.on_trade(on_trade)

client.connect()
client.subscribe("GCJ6", "COMEX")

# Keep the script running
import time
while True:
    time.sleep(1)
```

### 3. CLI Client

You can also use the built-in CLI client for quick monitoring:

```bash
uvx rithmic-bridge client --host 192.168.x.x --symbol GCJ6 --exchange COMEX
```

## Configuration

The system can be configured via command-line arguments (recommended) or a `.env` file.

| Argument | Description | Default |
|:---|:---|:---|
| `--mode` | `rapi` or `dummy` | `dummy` |
| `--user` | Rithmic username | - |
| `--password` | Rithmic password | - |
| `--symbol` | Default symbol | `GCJ6` |
| `--exchange` | Exchange | `COMEX` |
| `--bind` | ZMQ bind address | `tcp://*:5555` |
| `--dll-dir` | Path to `rapiplus.dll` | (Standard paths) |

## Development

We use `uv` for dependency management.

```bash
git clone https://github.com/akivajp/rithmic-bridge
cd rithmic-bridge
uv sync
```

## License

MIT License
