Skip to main content

ohlc-bar-matching-engine

Minimalist, zero-dependency Python & JavaScript intrabar matching engine (~100 LOC) for historical OHLC candlestick replay and paper-trading simulators: handles limit/stop orders, take-profit / stop-loss priority, opening price gaps (prevClose → open), and isolated/cross forced liquidation.


Python Installation & Quick Start

pip install ohlc-bar-matching-engine
from ohlc_bar_matching_engine import create_account, fill, process_bar

acct = create_account(wallet=10000, leverage=10, mode="isolated")
fill(acct, side="buy", qty=0.1, price=100000)
acct["pos"]["tp"] = 105000
process_bar(acct, {"o": 100500, "l": 99800, "h": 105500, "c": 104000}, prev_close=100000)

The Intrabar Ordering Problem

Historical candlestick APIs provide only [open, high, low, close] without tick timestamps. When a single candle spans both a long position's Take-Profit and Stop-Loss (or crosses multiple resting orders across an opening gap), a deterministic path and priority rule is required:

  1. Gap Segment (prevClose → open): Every resting trigger crossed between the prior close and the new open executes at open without advancing the cursor past subsequent resting orders in the same gap.
  2. Intrabar Path:
    • Bullish bar (close >= open): open → low → high → close
    • Bearish bar (close < open): open → high → low → close
  3. Trigger Priority: Distance-first along each segment; ties place Stop-Loss ahead of Liquidation so valid protective stops fire before forced liquidation.

Quick Start

import { createAccount, fill, processBar } from './src/engine.mjs';

const acct = createAccount({ wallet: 10000, leverage: 10, mode: 'isolated' });
fill(acct, { side: 'buy', qty: 0.1, price: 100000, liquidity: 'taker' });
acct.pos.tp = 103000;
acct.pos.sl = 96000;

processBar(acct, { o: 100000, h: 104200, l: 98500, c: 103500 }, 100000);
console.log(acct);

License

MIT © HoldWins

Metadata

Release files for ohlc-bar-matching-engine 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ohlc-bar-matching-engine 1.0.0
File Size Uploaded Provenance Actions
ohlc_bar_matching_engine-1.0.0.tar.gz 4.8 kB Without provenance Details for ohlc_bar_matching_engine-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ohlc-bar-matching-engine 1.0.0
File Interpreter ABI Platform Actions
ohlc_bar_matching_engine-1.0.0-py3-none-any.whl Python 3 none any Details for ohlc_bar_matching_engine-1.0.0-py3-none-any.whl

Total release size: 10.9 kB

Release files / ohlc_bar_matching_engine-1.0.0.tar.gz

Download URL ohlc_bar_matching_engine-1.0.0.tar.gz
Size 4.8 kB
Tags Source
SHA-256 checksum
How to use checksums
ebcbe5d2090610d733d975b460f9fedee03ce211f44b8c2bbde825e1a1c2fb34
BLAKE2b-256 checksum
How to use checksums
e4e228bd411f527c0a36806031233cb4aa453dfb4d6df52d3b47445f3fdc110e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / ohlc_bar_matching_engine-1.0.0-py3-none-any.whl

Download URL ohlc_bar_matching_engine-1.0.0-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8d0317830b89939f72ebed5665012b676fb01107af2db24a8167d0230646c558
BLAKE2b-256 checksum
How to use checksums
f6bd53785b45c6103efff15e1bc9232d6f66f8a26c53aa92a8796c1d8c23b247
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.0 {"installer":{"name":"uv","version":"0.11.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for ohlc-bar-matching-engine 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page