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

@evanshortiss/binance.js

v0.1.2

Published

No nonsense wrapper for the Binance API, written in TypeScript

Readme

Binance.js - Binance API Wrapper

https://travis-ci.org/evanshortiss/binance.js npm version https://coveralls.io/repos/github/evanshortiss/binance.js TypeScript

Node.js and Browser friendly wrapper for the Binance API, written using TypeScript.

  • Support for the Binance REST API (WebSockets would be nice too!)
  • Compatible with Node.js (v5 and above) and Web Browsers.
  • First class TypeScript support.
  • Decent documentation.
  • High code and test coverage.
  • Support for Promises and Async/Await.
  • Uses the native crypto module when used with Node.js to greatly improve performance of HMAC generation vs. other modules.
  • Straightforward. Doesn't alter the responses from Binance unless otherwise noted.
  • Lightweight wrapper. No wrapper Classes or large frameworks are forced on you.

Node.js Quickstart

Install

npm install @evanshortiss/binance.js --save

Example

This is a Node.js example using ES5 syntax, but you can use ES6 and TypeScript too.

'use strict'

const Binance = require('@evanshortiss/binance.js')

const client = new Binance.RestClient({
  apikey: 'YOUR KEY GOES HERE',
  apisecret: 'YOUR KEY GOES HERE'
})

client.getAccountInformation()
  .then((balances) => {
    // Do something with your account balance information
  })

API

Errors

This module throws Error subclasses so you can easily detect the type of an error and handle it accordingly.

The MalformedRequestError, RequestResultUnknownError, and InternalRequestError have the following properties:

  • response (Object) - This is the response data from Binance. Cointains code and msg properties per the Binance API Docs.
  • statusCode (Number) - The HTTP status code returned by Binance
  • statusText (String) - Description of the returned HTTP status code

Some examples are shown below.

HttpError

If a protocol or connection error occurs then this error is thrown, e.g ETIMEDOUT or ECONNREFUSED. Also thrown if the internal HTTP module (Axios) encounters an error.

MissingCredentialsError

If you attempt to call an endpoint that requires SIGNED or API-KEY permissions, but didn't provide the apikey and/or apisecret when creating a Binance.RestClient this error is thrown.

MalformedRequestError

If the Binance API returns a 4xx status code then this error is thrown.

const Binance = require('@evanshortiss/binance.js')

const client = new Binance.RestClient()

// Deliberately pass a bad symbol to get a 4xx error
client.getOrderBook('BADSYMBOL')
  .then((book) => doSomething(book))
  .catch((err) => {
    if (err instanceof Binance.Errors.MalformedRequestError) {
      // We can inspect the error to find a root cause. Error has properties
      // like those shown below
      // {
      //   response: { code: -1121, msg: 'Invalid symbol.' },
      //   statusText: 'Bad Request',
      //   statusCode: 400,
      //   name: 'BinanceMalformedRequestError' }
      // }
    } else {
      // Some other type of error
    }
  })

RequestResultUnknownError

This error is reserved for when Binance return a HTTP 504 to us. This means they got your request, but didn't generate a response within their timeout period.

Don't treat this as a failure since the request might have been a success.

Read their API Docs for more info.

InternalRequestError

When Binance return a 5xx status code other than 504 this is thrown.

RestClient(options)

The RestClient allows you to perform HTTPS requests against the Biance API. It supports the following options:

  • [optional] apikey - Your Binance API key
  • [optional] apisecret - Your Binance API secret
  • [optional] axiosOptions - Overrides to pass to each API request. For more details, check the Axios Docs

RestClient behaviours:

  1. RestClient instance functions return Promises. This means they can be used with Async/Await.
  2. Most instance functions return the plain result from the Binance API. Functions that alter the data into a friendlier format are noted below. to save you the trouble of continuously typing response.result.
  3. If a request returns a status code that isn't between 200 and 399 an error is thrown, so be sure to use .catch() function on Promises and try/catch if using Async/Await.

All of the following functions and the returned data types are detailed in the Binance API docs. For details of the types shown below visit the src/models folder in this repo and read the Binance API docs.

Public methods are detailed below. Optional parameters are denoted using the ? character. Return types are between the angled braces, e.g <ReturnType>. If the return type is followed by braces then it means an array containing entries of that type will be returned, e.g <ReturnType[]>

http(uri: string, options?: AxiosRequestConfig): AxiosPromise

Perform a HTTPS request to the Binance API. You should only provide the relative path, e.g /public/getmarkets since this library will create the fully formed url.

Resolves the Promise with an AxiosResponse Object.

// Example call to the Binance API
client.http('/v1/ping', { timeout: 5000 })
  .then((result) => {})
  .catch((error) => {})

pingServer(): Promise

getServerTime(): Promise<RestApiResponses.Time>

getOrderBook(symbol: string, limit?: number): Promise<RestApiResponses.OrderBook>

Returns the order book for a given symbol. This is one of the few functions where data is changed from the Binance format to another format for ease of use.

Data will look similar to this:

{
  lastUpdateId: number
  bids: [
    {
      price: string
      quantity: string
    }
  ]
  asks: [
    {
      price: string
      quantity: string
    },
    {
      price: string
      quantity: string
    }
  ]
}

getAllPrices(): Promise<RestApiResponses.Account>

order(data: RestApiParams.NewOrder): Promise<RestApiResponses.NewOrder>

getAllAccountOrders(opts: RestApiParams.AllOrders): Promise<RestApiResponses.Order[]>

getAccountInformation(params?: RestApiParams.Account): Promise<RestApiResponses.Account>