Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

binance

Package Overview
Dependencies
Maintainers
1
Versions
171
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binance

node.js wrapper for the Binance REST and WebSocket APIs

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2K
decreased by-3.29%
Maintainers
1
Weekly downloads
 
Created
Source

Binance

A wrapper for the Binance REST and WebSocket APIs. Uses both promises and callbacks, and beautifies the binance API responses that normally use lots of one letter property names. For more information on the API and parameters for requests visit https://www.binance.com/restapipub.html

Usage/Example

const api = require('binance');
const binanceRest = new api.BinanceRest({
    key: 'api-key', // Get this from your account on binance.com
    secret: 'api-secret', // Same for this
    timeout: 15000, // Optional, defaults to 15000, is the request time out in milliseconds
    recvWindow: 10000, // Optional, defaults to 5000, increase if you're getting timestamp errors
    disableBeautification: false
    /*
     * Optional, default is false. Binance's API returns objects with lots of one letter keys.  By
     * default those keys will be replaced with more descriptive, longer ones.
     */
});

// You can use promises
binanceRest.allOrders({
        symbol: 'BNBBTC'  // Object is transformed into a query string, timestamp is automatically added
    })
    .then((data) => {
        console.log(data);
    })
    .catch((err) => {
        console.error(err);
    });

/*
 * Or you can provide a callback.  Also, instead of passing an object as the query, routes
 * that only mandate a symbol, or symbol and timestamp, can be passed a string.
 */
binanceRest.allOrders('BNBBTC', (err, data) => {
    if (err) {
        console.error(err);
    } else {
        console.log(data);
    }
});

/*
 * WebSocket API
 *
 * Each call to onXXXX initiates a new websocket for the specified route, and calls your callback with
 * the payload of each message received.  Each call to onXXXX returns the instance of the websocket
 * client if you want direct access(https://www.npmjs.com/package/ws).
 */
const binanceWS = new api.BinanceWS();

binanceWS.onDepthUpdate('BNBBTC', (data) => {
    console.log(data);
});

binanceWS.onAggTrade('BNBBTC', (data) => {
    console.log(data);
});

binanceWS.onKline('BNBBTC', '1m', (data) => {
    console.log(data);
});

/*
 * onUserData requires an instance of BinanceRest in order to make the necessary startUserDataStream and
 * keepAliveUserDataStream calls.  The webSocket instance is returned by promise rather than directly
 * due to needing to request a listenKey from the server first.
 */
binanceWS.onUserData(binanceRest, (data) => {
        console.log(data);
    }, 60000) // Optional, how often the keep alive should be sent in milliseconds
    .then((ws) => {
        // websocket instance available here
    });

REST APIs

allPrices([callback function])

allBookTickersTi([callback function])

ping([callback function])

time([callback function])

depth(query object|string, [callback function])

aggTrades(query object|string, [callback function])

klines(query object, [callback function])

ticker24hr(query object|string, [callback function])

newOrder(query object, [callback function])

testOrder(query object, [callback function]) - If this ends up making a real order it's the API, not this library

queryOrder(query object|string, [callback function])

cancelOrder(query object|string, [callback function])

openOrders(query object|string, [callback function])

allOrders(query object|string, [callback function])

account(query object, [callback function])

myTrades(query object|string, [callback function])

withdraw(query object|string, [callback function])

withdrawHistory(query object|string, [callback function])

depositHistory(query object|string, [callback function])

depositAddress(query object|string, [callback function])

startUserDataStream([callback function])

keepAliveUserDataStream(query object|string, [callback function])

closeUserDataStream(query object|string, [callback function])

WebSocket APIs

onDepthUpdate(symbol, eventHandler) - Returns the websocket, an instance of https://www.npmjs.com/package/ws

onKline(symbol, interval, eventHandler) - Returns the websocket, an instance of https://www.npmjs.com/package/ws

onAggTrade(symbol, eventHandler) - Returns the websocket, an instance of https://www.npmjs.com/package/ws

onUserData(binanceRest, eventHandler, [interval]) - Will return the websocket via promise, interval defaults to 60000, is the amount of time between calls made to keep the user stream alive, binanceRest should be an instance of BinanceRest that will be used to get the listenKey and keep the stream alive

License

MIT

Keywords

FAQs

Package last updated on 20 Dec 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc