Giter Site home page Giter Site logo

binance's Introduction

Binance

A wrapper for the Binance REST and WebSocket APIs. 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
    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
const binanceWS = new api.BinanceWS();

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

/*
 * onUserData requires an instance of BinanceRest in order to make the necessary startUserDataStream and  
 * keepAliveUserDataStream calls
 */
binanceWS.onUserData(binanceRest, (data) => {
    console.log(data);
}, 60000); // Optional, how often the keep alive should be sent in milliseconds

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

REST APIs

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])

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

binance's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.