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

@xapy/orderbook

v0.1.21

Published

Lightweight multi-exchange orderbook SDK — REST snapshot + WS maintained stream

Downloads

600

Readme

@xapy/orderbook

Lightweight multi-exchange orderbook SDK — REST snapshot + WebSocket maintained stream.

Install

npm i @xapy/orderbook
# Optional, only needed on Node < 22:
npm i ws

Usage

import { BybitClient } from "@xapy/orderbook/bybit";

const bybit = new BybitClient({ market: "perpetual" });

// One-shot REST snapshot
const snapshot = await bybit.fetchOrderbook("BTC/USDT", { depth: 50 });
console.log(snapshot.bids[0], snapshot.asks[0]);

// Maintained live stream (snapshot + deltas → always the latest book)
const stream = bybit.streamOrderbook("BTC/USDT", { depth: 50 });
stream.on("update", (book) => {
  console.log(book.exchange, book.symbol, book.bids[0], book.asks[0]);
});
stream.on("reconnecting", (attempt, waitMs) => {
  console.log(`reconnect attempt ${attempt} in ${waitMs}ms`);
});

// Or async-iterator
for await (const book of stream.iter()) {
  console.log(book.sequence, book.bids[0]);
}

stream.close();

Browser + CORS

Several exchanges block direct browser requests. Use transformUrl to route through your proxy:

const bybit = new BybitClient({
  market: "perpetual",
  transformUrl: (url) =>
    `https://my-proxy.example/${url.replace(/^https?:\/\//, "")}`,
});

WebSocket connections are not subject to CORS and work directly in the browser.

What you get

  • Maintained orderbook — the lib applies WS deltas internally; consumers always see a sorted, latest snapshot.
  • Gap recovery — sequence numbers are verified; on a gap the lib re-fetches a REST snapshot and resumes without you noticing.
  • Auto-reconnect — exponential backoff with jitter; the subscription replays on each reconnect.
  • Cross-runtime — Node ≥ 18 (with ws peer for < 22) and modern browsers.
  • Tree-shakeableimport "@xapy/orderbook/bybit" doesn't pull in other adapters.

Supported exchanges

| Exchange | Spot | Perpetual | Status | | --- | --- | --- | --- | | Bybit | ✅ | ✅ | available (0.1) | | OKX | | | planned (0.2) | | Bitget | | | planned (0.2) | | Gate | | | planned (0.3) | | CoinEx | | | planned (0.3) | | BingX | | | planned (0.4) | | Huobi | | | planned (0.4) | | KuCoin | | | planned (0.5) |

API

new BybitClient(options)

interface ClientOptions {
  market: "spot" | "perpetual";
  transformUrl?: (url: string) => string;
  timeoutMs?: number; // default 10_000
}

client.fetchOrderbook(symbol, opts?)

REST snapshot. Returns a Promise<Orderbook>.

client.streamOrderbook(symbol, opts?)

WebSocket stream. Returns an OrderbookStream exposing:

stream.on("update",       (book: Orderbook) => {});
stream.on("connected",    () => {});
stream.on("disconnected", (reason?: string) => {});
stream.on("reconnecting", (attempt: number, waitMs: number) => {});
stream.on("error",        (err: Error) => {});

for await (const book of stream.iter()) { /* … */ }

stream.close();

Orderbook shape

interface Orderbook {
  exchange: ExchangeName;
  symbol: string;          // "BTC/USDT"
  market: "spot" | "perpetual";
  bids: { price: number; size: number }[]; // descending
  asks: { price: number; size: number }[]; // ascending
  timestamp: number;       // ms epoch
  sequence: number;        // last applied seq
}

Sizes are in base coin (e.g. BTC). Conversion to quote (USDT) is left to the caller.

Development

npm install
npm run build
npm test

License

MIT