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

limit-order-book

v1.0.1

Published

Order book supporting limit and market orders

Downloads

229

Readme

limit-order-book

At time of publish in 2016 this was the only OSS limit order book on github

The order book has always been passing tests but with v1.0.0 the api has significantly improved

  • npm install limit-order-book
  • Suitable for matching engine
  • Supports limit and market orders
  • Floats as strings internally = always correct math

Usage

const { LimitOrderBook } = require('limit-order-book')
const { LimitOrder, MarketOrder } = require('limit-order-book')

const symbol = 'BTCUSDT'
const priceStep = '0.01'
const sizeStep = '0.001'
const book = new LimitOrderBook({ symbol, priceStep, sizeStep })

const order1 = new LimitOrder('order1', 'bid', '13.37', '10')
const order2 = new LimitOrder('order2', 'ask', '13.38', '10')
const order3 = new LimitOrder('order3', 'bid', '13.38', '5')

let result = book.add(order1)
result = book.add(order2)
result = book.add(order3)

const order4 = new MarketOrder('order4', 'bid', '2.5')
result = book.add(order4)

console.log(result)

const bestAskLevel = book.askLevels.queue[0]
const bestBidLevel = book.bidLevels.queue[0]

const bestAsk = bestAskLevel.queue[0].copy()
const bestBid = bestBidLevel.queue[0].copy()

console.log(`\nbest ask =`, bestAsk)
console.log(`\nbest bid =`, bestBid)

const Decimal = require('decimal.js')

const spread = new Decimal(bestAsk.price)
  .sub(bestBid.price)
  .toFixed()

console.log(`\nspread =`, spread)
Result {
  symbol: 'BTCUSDT',
  taker: {
    type: 'market',
    orderId: 'order4',
    side: 'bid',
    price: '0',
    size: '2.5',
    sizeRemaining: '0',
    filled: '2.5',
    filledValue: '33.45',
    funds: '0',
    fundsRemaining: '0'
  },
  makers: [
    {
      type: 'limit',
      orderId: 'order2',
      side: 'ask',
      price: '13.38',
      size: '10',
      sizeRemaining: '2.5',
      filled: '2.5',
      filledValue: '33.45'
    }
  ],
  filled: '2.5',
  filledValue: '33.45'
}

best ask = {
  type: 'limit',
  orderId: 'order2',
  side: 'ask',
  price: '13.38',
  size: '10',
  sizeRemaining: '2.5'
}

best bid = {
  type: 'limit',
  orderId: 'order1',
  side: 'bid',
  price: '13.37',
  size: '10',
  sizeRemaining: '10'
}

spread = 0.01

Api

book({ symbol, priceStep, sizeStep })
Constructor wants symbol, priceStep, sizeStep

book.config(opts)
Same as constructor

book.add(order)
Add a limit or market order to the book and get back result

book.reduce(orderId, size)
Reduce the size of an order to = size
Returns null or the updated order

book.remove(orderId)
Remove the order from the book
Returns null or the order

book.clear()
Remove all orders

Test

480 assertions passing

npm run test

License

Copyright 2025 - [email protected]

MIT