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 🙏

© 2024 – Pkg Stats / Ryan Hefner

bitmex-orderbook

v1.2.1

Published

BitMEX WebSocket-driven Orderbook

Downloads

6

Readme

BitMEX Order Book

The fastest order book implementation for the BitMEX WebSocket API.

  • Fast & unthrottled price updates from L2 table.
  • Automatically calculates cumulative prices.
  • Reuse an existing WebSocket connection.
  • Built-in heartbeats functionality.
  • Easy to use.

Install

yarn add bitmex-orderbook

Or you can use npm install.

Example

const OrderBook = require("bitmex-orderbook");

await OrderBook.open("XBTH18", {
  onUpdate(orderBook) {
    // Top 10 ask prices.
    const bestAskPrices = orderBook.getAskPrices(10);
    
    // Top 5 bid prices, skipping the first 2.
    const [thirdBestBid] = orderBook.getBidprices(5, 2); 
    
    thirdBestBid.side; // "Buy"
    thirdBestBid.price; // 17341.5
    thirdBestBid.size; // 400
    thirdBestBid.cumulative; // 57 + 372 + 400
    thirdBestBid.timestamp; // Date()
  },
});

Documentation

OrderBook.open(symbol, options = {}): Promise<OrderBook>

  • symbol : String - The instrument symbol. Required.
  • options.table : String - The order book table to subscribe to. Default: orderBookL2, the fastest table on BitMEX.
  • options.depth : Integer - Number of entries to remember for each side bid and ask. The worst prices are evicted. Default: 20.
  • options.cumulative : Boolean - Calculate cumulative sizes automatically at tiny processing cost. Default: true, it's very useful.
  • options.onUpdate : Function(OrderBook) - A function that is invoked whenever the prices are updated.
  • options.socket : WebSocket - An existing BitMEX WebSocket connection. If left empty a new WebSocket connection will be opened, and stored in orderBook._client.socket.
  • options.testmode : Boolean - Connect to the BitMEX test environment. Only used if options.socket is empty. Default: false.
  • options.heartbeat : Integer - Milliseconds between WebSocket connection pings. Default: 15000.
  • options.endpoint : String - Specifies the wss:// address for a new WebSocket connection. Only used if options.socket is empty. Default: wss://www.bitmex.com/realtime.

Returns a Promise that resolves when the connection is opened.

orderBook.getAskPrices(count, skip = 0) : OrderBookEntry

  • count: Integer - Max number of prices to return. Sorted by best price first. Default: options.depth.

  • skip: Integer - Number of best prices to skip. This is useful with highly volatile markets. Default: 0.

orderBook.getBidPrices(count, skip = 0) : OrderBookEntry

Same as orderBook.getAskPrices(). Sorted by best price first.

License

BSD 3-Clause license. Copyright © 2018 Rick Wong.