Skip to main content

Python bindings for opendeviationbar: Non-lookahead open deviation bar construction for cryptocurrency trading

Project description

[//]: # SSoT-OK

opendeviationbar-py

High-performance open deviation bar construction for quantitative trading, with Python bindings via PyO3/maturin.

PyPI License: MIT Python

Resource URL
PyPI https://pypi.org/project/opendeviationbar/
Repository https://github.com/terrylica/opendeviationbar-py
Performance Dashboard https://terrylica.github.io/opendeviationbar-py/
API Reference docs/api/INDEX.md
Issues https://github.com/terrylica/opendeviationbar-py/issues

Installation

pip install opendeviationbar

Pre-built wheels: Linux (x86_64), macOS (ARM64), Python 3.13. Source build requires Rust toolchain and maturin.

Quick Start

from opendeviationbar import get_open_deviation_bars

# Fetch data and generate open deviation bars in one call
df = get_open_deviation_bars("BTCUSDT", "2024-01-01", "2024-06-30")

# Use with backtesting.py
from backtesting import Backtest, Strategy
bt = Backtest(df, MyStrategy, cash=10000, commission=0.0002)
stats = bt.run()

Output: pandas DataFrame with DatetimeIndex and OHLCV columns, compatible with backtesting.py.

API Overview

Function Use Case
get_open_deviation_bars() Date-bounded, auto-fetch
get_n_open_deviation_bars() Exact N bars (ML training)
process_trades_polars() Polars DataFrames (2-3x faster)
process_trades_chunked() Large datasets (>10M trades)
populate_cache_resumable() Long ranges (>30 days)
run_sidecar() Real-time streaming sidecar
# Count-bounded (ML training)
from opendeviationbar import get_n_open_deviation_bars
df = get_n_open_deviation_bars("BTCUSDT", n_bars=10000)

# Polars (2-3x faster)
import polars as pl
from opendeviationbar import process_trades_polars
bars = process_trades_polars(pl.scan_parquet("trades.parquet"), threshold_decimal_bps=250)

# With microstructure features (57 columns: OFI, Kyle lambda, Hurst, etc.)
df = get_open_deviation_bars("BTCUSDT", "2024-01-01", "2024-06-30", include_microstructure=True)

# Real-time streaming sidecar
from opendeviationbar import run_sidecar, SidecarConfig
config = SidecarConfig(symbol="BTCUSDT", threshold_decimal_bps=250)
run_sidecar(config)

Designed for Claude Code

This repository uses a CLAUDE.md network that provides comprehensive project context for AI-assisted development via Anthropic's Claude Code CLI.

npm install -g @anthropic-ai/claude-code
cd opendeviationbar-py
claude

Claude Code reads the CLAUDE.md files automatically and understands the full architecture, API, build system, and development workflow.

Development

git clone https://github.com/terrylica/opendeviationbar-py.git
cd opendeviationbar-py
mise install          # Setup tools (Rust, Python, zig)
mise run build        # maturin develop
mise run test         # Rust tests
mise run test-py      # Python tests

Requirements

Runtime: Python >= 3.13, pandas >= 2.0, numpy >= 1.24, polars >= 1.0

Build: Rust toolchain, maturin >= 1.7

License

MIT License. See LICENSE.

Citation

@software{opendeviationbar-py,
  title = {opendeviationbar-py: High-performance open deviation bar construction for quantitative trading},
  author = {Terry Li},
  url = {https://github.com/terrylica/opendeviationbar-py}
}

Project details


Release history Release notifications | RSS feed

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

opendeviationbar-12.65.1.tar.gz (13.5 MB view details)

Uploaded Source

Built Distributions

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

opendeviationbar-12.65.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

opendeviationbar-12.65.1-cp313-cp313-macosx_11_0_arm64.whl (4.2 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

File details

Details for the file opendeviationbar-12.65.1.tar.gz.

File metadata

  • Download URL: opendeviationbar-12.65.1.tar.gz
  • Upload date:
  • Size: 13.5 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.12

File hashes

Hashes for opendeviationbar-12.65.1.tar.gz
Algorithm Hash digest
SHA256 e78b251c0f80830df3a24128379cdec8a44677aa93169edab344ccbfd0a3ae22
MD5 3af429594c5359daf8fd7948a45d2287
BLAKE2b-256 2f5ddf553e0a5bac11c9a6e02aeb6aa0725dde48efcb639e4b1a71d5ca677f51

See more details on using hashes here.

File details

Details for the file opendeviationbar-12.65.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for opendeviationbar-12.65.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 69d9ecc7d39dafbefa14a3329eb4980912b911884bc2a0419b80a075dd7acae1
MD5 0df7a3c3646331729bead4acb3ac7073
BLAKE2b-256 fffe1e96fec03e3b79d8ed3e730d2ab030b71bcfc5c6dff2eec0bcd6ed9cfc58

See more details on using hashes here.

File details

Details for the file opendeviationbar-12.65.1-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for opendeviationbar-12.65.1-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9fc4172b7fa8b4567e0f03f3a043bb5d9571f31e8cf8a89ac5af2aad19416600
MD5 a3fc02f082170e4e71a08cc8fd06f75b
BLAKE2b-256 0bb136ba034b62ec75a6a32a87e5dc4355032f01a52d9ee54ac50f56ea372684

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