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-plus

v1.3.1

Published

BitMEX (un)authenticated REST and WebSocket helper methods

Downloads

5

Readme

bitmex-plus

This package provides several helper methods for the REST and WebSocket BitMEX APIs. You can think of it as a lightweight, easy to audit, combination of ccxt (which it doesn't use) and the official bitmex-realtime-api.

Features:

  • minimal dependencies
  • both authenticated and unauthenticated REST requests
  • real-time WebSocket API wrappers around the official bitmex-realtime-api library

The module works in Node, but not in the browser, because BitMEX doesn't serve CORS headers on the API.

Usage

npm install bitmex-plus

See the bitmex-realtime-api documentation for parameters.

import { BitMexPlus } from 'bitmex-plus';

const bitmex = new BitMexPlus({
  apiKeyID: '...',
  apiKeySecret: '...',
});

The API key constructor parameters are optional. You only need to specify them if you make authenticated requests.

The bitmex-realtime-api library that this module wraps will automatically connect to the web socket, so your script won't exit until all listeners are removed. If you only make REST requests, or when you're done with the WebSocket API, you can simply call process.exit(0).

Methods

makeRequest(verb, endpoint, data)

Make a GET/PUT/POST/DELETE request to the REST API. See the API explorer for available endpoints and parameters.

Sample unauthenticated request to get the bid/ask over the last minute:

import { BitMexPlus } from 'bitmex-plus';

const bitmex = new BitMexPlus();

(async function () => {
  const [bucket] = (await bitmex.makeRequest('GET', 'quote/bucketed', {
    binSize: '1m',
    symbol: 'XBTUSD',
    reverse: true,
    count: 1,
    columns: ['bidPrice', 'askPrice'],
  }));
  console.log(bucket);
}());

process.exit(0);

Authenticated request to get your XBTUSD position:

import { BitMexPlus } from 'bitmex-plus';

const bitmex = new BitMexPlus({
  // Get your API key at https://www.bitmex.com/app/apiKeys
  apiKeyID: 'REPLACE_ME',
  apiKeySecret: 'REPLACE_ME',
});

(async function () {
  const [pos] = (await bitmex.makeRequest('GET', 'position', {
    filter: { symbol: 'XBTUSD' },  // remove to get all positions
    // limit returned columns, except for several that are always returned:
    // account, symbol, currency, timestamp, simpleQty and markPrice
    columns: ['currentQty', 'liquidationPrice'],   }));
  console.log(pos);
}());

process.exit(0)

monitorStream(symbol, table, callback)

Add a stream and call the callback for each new data item added to the table (e.g. each new trade). This provides more granular processing than the official library, which calls the callback for chunks of data of unspecified length. The callback is passed a data parameter (e.g. a trade object).

Note that if you monitor the orderBookL2 stream, the callback will be called only once, without any parameters. This is because with order book entries, you need to deal with the entire data array returned by getData(), since orders might have been removed, changed, or inserted.

bitmex.monitorStream('XBTUSD', 'trade', data => console.log(data.price));

LICENSE

MIT. Copyright 2018 Ben Bomper.