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

nl-bitmex

v0.1.0

Published

My own bitmex library

Downloads

3

Readme

BitMex library

npm version

My own bitmex library. Reference library here

Installing

npm i nl-bitmex --save

Contributing

All contributions are welcome and appreciated. Open Source is a meritocracy who doesn't care who you are.

Example code

Initializing

const bitmex = require('nl-bitmex');

Custom Requests

// Get the contents of the users bitcoin wallet
bitmex.customprivate({siteprefix: "www", endpoint: "user/wallet", querystring: "currency=XBt", apikey: "r", apisecret: ""}, (cb) => {
  console.log(cb);
});

// Get deposit addresss
bitmex.customprivate({siteprefix: "www", endpoint: "user/depositAddress", apikey: "", apisecret: ""}, (cb) => {
  console.log(cb);
});

Orders

Get Open orders

Parameters
  • apikey (but can use environment variable too)
  • apisecret (but can use environment variable too)
  • siteprefix (Defaults to 'testnet')
Example code
bitmex.orders({siteprefix: "www"}, function(c) {
  console.log(c);
});

Adjust leverage

bitmex.customprivate({siteprefix: "testnet", endpoint: "position/leverage", method: "POST", symbol: "ETHM17", leverage: 50,  apikey: "", apisecret: ""}, (cb) => {
  if (cb.message == "Done") {
    console.log(cb.result);
  } else if (cb.message == "Error") {
    console.log(cb.error);
  } else {
    console.log(cb.message);
  }
});

Place an order

bitmex.customprivate({siteprefix: "www", endpoint: "order", method: "POST", symbol: "XBTUSD", orderQty: 1, apikey: "", apisecret: ""}, (cb) => {
  console.log(cb);
});

Place orders in bulk

bitmex.customprivate({siteprefix: "testnet", endpoint: "order/bulk", method: "POST", orders: JSON.stringify([{symbol: "ETHM17", orderQty: 1, ordType: "Market", side: "Buy"}, {symbol: "ETHM17", orderQty: 1, ordType: "Market", side: "Buy"}]),  apikey: "xpdWaDC-40cQFxeJVzGqBsl9", apisecret: ""}, (cb) => {
  if (cb.message == "Done") {
    console.log(cb.result);
  } else if (cb.message == "Error") {
    console.log(cb.error);
  } else {
    console.log(cb.message);
  }
});

Place a stop market

bitmex.customprivate({siteprefix: "testnet", endpoint: "order", method: "POST", symbol: "ETHM17", orderQty: -5, ordType: "Stop", stopPx: "0.141", side: "Sell",  apikey: "", apisecret: ""}, (cb) => {
  if (cb.message == "Done") {
    console.log(cb.result);
  } else if (cb.message == "Error") {
    console.log(cb.error);
  } else {
    console.log(cb.message);
  }
});

Place a take profit market Sell

bitmex.customprivate({siteprefix: "testnet", endpoint: "order", method: "POST", symbol: "ETHM17", orderQty: -5, ordType: "MarketIfTouched", stopPx: "0.145", side: "Sell",  apikey: "", apisecret: ""}, (cb) => {
  if (cb.message == "Done") {
    console.log(cb.result);
  } else if (cb.message == "Error") {
    console.log(cb.error);
  } else {
    console.log(cb.message);
  }
});

Cancel an Order (As long as its not filled)

bitmex.customprivate({siteprefix: "www", endpoint: "order", method: "DELETE", querystring: "orderID=THEORDERID", apikey: "", apisecret: ""}, (cb) => {
  console.log(cb);
});

Trading Positions

Useful for determining whether to close out a position early or not.

Get Position

This gets the positions of open and closed orders, or open only.

Parameters
  • apikey (but can use environment variable too)
  • apisecret (but can use environment variable too)
  • siteprefix (Defaults to 'testnet')
  • isopen (Defaults to false, which will show all positions open and closed)
Example code

The below code grabs the current open positions

bitmex.position({siteprefix: "www", isopen: true}, function(c) {
  if (c.message == "Done") {
    for (var i = 0; i < c.position.length; i++) {
      var row = c.position[i];

      var symbol = row["symbol"];
      var currency = row["currency"];
      var underlyingCurrency = row["underlying"];
      var contractsCount = row["currentQty"];
      var realisedPnl = row["realisedPnl"];
      var unrealisedPnl = row["unrealisedPnl"];
      var openStatus = row["isOpen"];
      var costPrice = row["avgCostPrice"];
      var breakEvenPrice = row["breakEvenPrice"];
      var lastPrice = row["lastPrice"];
      var leverage = row["leverage"]

      console.log("Instrument (#" + (i + 1).toString() + "): " + symbol + " (" + underlyingCurrency + " bought with " + currency + ") QTY=" + contractsCount.toString() + " Open=" + openStatus.toString() + " bought at=" + costPrice.toString() + " currently: " + lastPrice.toString() + " (P/L: Realised: " + (realisedPnl / 100000).toString() + " mBTC Unrealised: " + (unrealisedPnl / 100000).toString() + " mBTC)");
    }
  } else if (c.message == "Error") {
    console.log("An error has occured: " + c.error);
  } else {
    console.log(c.message);
  }
});