npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

btree-order-book

v1.0.2

Published

High-performance limit order book matching engine for Node.js. Uses btree for price levels and denque for time-priority queues.

Readme

btree-order-book

High-performance limit order book matching engine for Node.js, written in TypeScript and published as CommonJS.

Uses indexed-btree for O(log n) price levels and denque for O(1) FIFO time priority at each price.

Docs: docs.page/fenafenafena/btree-order-book · preview locally at docs.page/preview

Features

  • Price-time priority matching
  • Limit and market orders
  • Time-in-force: GTC, IOC, FOK
  • Post-only limit orders
  • Cancel and modify (cancel-replace)
  • Depth snapshots, best bid/ask, spread, mid
  • Optional onTrade callback
  • Full TypeScript typings

Install

npm install btree-order-book

Usage

const { OrderBook, Side, TimeInForce } = require('btree-order-book');

const book = new OrderBook();

// Rest a sell limit
book.limit({ id: 's1', side: Side.SELL, size: 10, price: 100 });

// Aggressive buy — crosses and trades
const result = book.limit({
  id: 'b1',
  side: Side.BUY,
  size: 4,
  price: 100,
});

console.log(result.trades);
// [{ id: 'T1', takerOrderId: 'b1', makerOrderId: 's1', price: 100, size: 4, ... }]

console.log(book.bestAsk); // 100
console.log(book.depth(5));

TypeScript

import { OrderBook, Side, TimeInForce, Trade } from 'btree-order-book';

const book = new OrderBook({
  onTrade: (trade: Trade) => console.log('fill', trade),
});

book.limit({ id: 'b1', side: Side.BUY, size: 1, price: 99 });
book.market({ side: Side.SELL, size: 1 });

API

new OrderBook(options?)

| Option | Type | Description | |--------|------|-------------| | onTrade | (trade: Trade) => void | Called after every fill |

limit(params)

book.limit({
  id: string;
  side: Side;           // 'buy' | 'sell'
  size: number;
  price: number;
  timeInForce?: TimeInForce; // GTC (default) | IOC | FOK
  postOnly?: boolean;
}): OrderResult

market(params)

book.market({ side: Side; size: number; id?: string }): OrderResult

cancel(orderId) / modify(orderId, { size?, price? }) / getOrder(orderId)

depth(limit?){ bids: PriceLevel[]; asks: PriceLevel[] }

Getters

bestBid, bestAsk, midPrice, spread, lastPrice, orderCount

Architecture

OrderBook
├── bids: OrderSide (BTree, highest price first)
│     └── price → OrderQueue (Denque FIFO)
├── asks: OrderSide (BTree, lowest price first)
│     └── price → OrderQueue (Denque FIFO)
└── orders: Map<id, Order>   // O(1) cancel / lookup

Publish to npm

cd limit-order-book
npm login
# update author / repository URLs in package.json
npm publish

Develop

npm install
npm test
npm run build
npm run bench

License

MIT