How to use node-binance-api - 10 common examples

To help you get started, we’ve selected a few node-binance-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dalinhuang99 / betify / app.js View on Github external
// The connection was closed
    stream.on('close', function() {
      clients.splice(clients.indexOf(stream), 1);
      console.log('Closed connection ');
    });
  });

});



// ===============================================================================
// Binance API / webSocket

const binance = require('node-binance-api');
binance.options({
  APIKEY: '',
  APISECRET: '',
  useServerTime: true, // If you get timestamp errors, synchronize to server time at startup
  test: false // If you want to use sandbox mode where orders are simulated
});


// --------- BTCUSDT ---------
var gameTimeCounter = 0;
var startBtcPrice = 0;
var endBtcPrice = 0;
// For a specific symbol:
binance.websockets.prevDay('BTCUSDT', (error, response) => {
  // var t = new Date( response.eventTime );
  // var formatted = t.format("dd.mm.yyyy hh:MM:ss");
github dalinhuang99 / betify / app.js View on Github external
const binance = require('node-binance-api');
binance.options({
  APIKEY: '',
  APISECRET: '',
  useServerTime: true, // If you get timestamp errors, synchronize to server time at startup
  test: false // If you want to use sandbox mode where orders are simulated
});


// --------- BTCUSDT ---------
var gameTimeCounter = 0;
var startBtcPrice = 0;
var endBtcPrice = 0;
// For a specific symbol:
binance.websockets.prevDay('BTCUSDT', (error, response) => {
  // var t = new Date( response.eventTime );
  // var formatted = t.format("dd.mm.yyyy hh:MM:ss");

  // save to database
  if(response.symbol && response.close && response.closeTime && response.closeQty){

    let closeTime = moment(response.closeTime).format("HH:mm:ss");
    let closePrice = response.close;

    // game loop counter
    if(gameTimeCounter == 0) {
      startBtcPrice = response.close;
      gameTimeCounter++;
    } else if(gameTimeCounter == 9){
      gameTimeCounter = 0;
      endBtcPrice = closePrice;
github dalinhuang99 / betify / app / controllers / binanceapicontroller.js View on Github external
module.exports = function(models,clients){

  const binance = require('node-binance-api')().options({
    APIKEY: '',
    APISECRET: '',
    useServerTime: true, // If you get timestamp errors, synchronize to server time at startup
    test: false // If you want to use sandbox mode where orders are simulated
  })

  // --------- BTCUSDT ---------
  const BTCUSDT_20 = 10;

  var Btcusdt = models.btcusdt_table;

  var initTimer = new Date().getTime() + BTCUSDT_20*1000;
  var thisGameId = Math.round(initTimer/1000);
  var nextGameId = thisGameId+BTCUSDT_20;
  var gameStartBtcPrice = 0;
  var gameEndBtcPrice = 0;
github andresilvasantos / bitprophet / exchange_utils.js View on Github external
normalizeAmount: function(pair, amount, price) {
        // Set minimum order amount with minQty
        if ( amount < vars.pairsInfo[pair].filters.minQty ) amount = vars.pairsInfo[pair].filters.minQty;
        // Set minimum order amount with minNotional
        if (price && price * amount < vars.pairsInfo[pair].filters.minNotional ) {
            amount = vars.pairsInfo[pair].filters.minNotional / price;
        }
        // Round to stepSize
        return binance.roundStep(amount, vars.pairsInfo[pair].filters.stepSize);
    },
    fixPrice: function(pair, price) {
github bmino / binance-triangle-arbitrage / routes / BinanceController.js View on Github external
if (!isPresent(index)) {
                UNFILLED.push(symbol);
                console.log('Added ' + symbol + ' (' + askDepth + '/' + bidDepth + ') - ' + UNFILLED.length);
            }
        } else if (isPresent(index)) {
            UNFILLED.splice(index, 1);
            console.log('Removed ' + symbol + ' (' + askDepth + '/' + bidDepth + ') - ' + UNFILLED.length);
        }

        sockets.emit('depth:new', {
            ticker: symbol,
            unfilled: UNFILLED,
            time: new Date().getTime(),
            bid: bids,
            ask: asks,
            market: (parseFloat(binance.first(bids)) + parseFloat(binance.first(asks))) / 2
        });
    }, LIMIT);
github bmino / binance-triangle-arbitrage / routes / BinanceController.js View on Github external
binance.websockets.depthCache(tickers, function(symbol, depth) {
        var bids = binance.sortBids(depth.bids);
        var asks = binance.sortAsks(depth.asks);
        var askDepth = Object.keys(asks).length;
        var bidDepth = Object.keys(bids).length;
        var index = UNFILLED.indexOf(symbol);

        if (askDepth < MIN_THRESHOLD && bidDepth < MIN_THRESHOLD) {
            if (!isPresent(index)) {
                UNFILLED.push(symbol);
                console.log('Added ' + symbol + ' (' + askDepth + '/' + bidDepth + ') - ' + UNFILLED.length);
            }
        } else if (isPresent(index)) {
            UNFILLED.splice(index, 1);
            console.log('Removed ' + symbol + ' (' + askDepth + '/' + bidDepth + ') - ' + UNFILLED.length);
        }

        sockets.emit('depth:new', {
            ticker: symbol,
github bmino / binance-triangle-arbitrage / routes / BinanceController.js View on Github external
binance.websockets.depthCache(tickers, function(symbol, depth) {
        var bids = binance.sortBids(depth.bids);
        var asks = binance.sortAsks(depth.asks);
        var askDepth = Object.keys(asks).length;
        var bidDepth = Object.keys(bids).length;
        var index = UNFILLED.indexOf(symbol);

        if (askDepth < MIN_THRESHOLD && bidDepth < MIN_THRESHOLD) {
            if (!isPresent(index)) {
                UNFILLED.push(symbol);
                console.log('Added ' + symbol + ' (' + askDepth + '/' + bidDepth + ') - ' + UNFILLED.length);
            }
        } else if (isPresent(index)) {
            UNFILLED.splice(index, 1);
            console.log('Removed ' + symbol + ' (' + askDepth + '/' + bidDepth + ') - ' + UNFILLED.length);
        }

        sockets.emit('depth:new', {
github gmverdon / TradingBot / src / scenes / Home / index.js View on Github external
componentDidMount() {
    var self = this;
    binance.websockets.candlesticks(['BTCUSDT'], "1m", (candlesticks) => {
      let { e:eventType, E:eventTime, s:symbol, k:ticks } = candlesticks;
    	let { o:open, h:high, l:low, c:close, v:volume, n:trades, i:interval, x:isFinal, q:quoteVolume, V:buyVolume, Q:quoteBuyVolume } = ticks;
    	//console.log(symbol+" "+interval+" candlestick update");
      self.setState({
        currentPrice: close
      })
    });
  }
github bmino / trading-with-trends / src / main / service / MarketDataService.js View on Github external
function watch(tickers, interval='1m') {
    if (!tickers) throw 'No tickers provided';
    if (typeof tickers === 'string') tickers = [tickers];
    tickers.forEach(clearCandles);
    console.log(`Opening websocket connection for ${tickers} ...`);
    binance.websockets.candlesticks(tickers, interval, processTick);
}
github bmino / binance-triangle-arbitrage / routes / BinanceController.js View on Github external
function depthCache(tickers, sockets) {
    console.log('Opening depth websockets for ' + tickers.length + ' tickers');

    binance.websockets.depthCache(tickers, function(symbol, depth) {
        var bids = binance.sortBids(depth.bids);
        var asks = binance.sortAsks(depth.asks);
        var askDepth = Object.keys(asks).length;
        var bidDepth = Object.keys(bids).length;
        var index = UNFILLED.indexOf(symbol);

        if (askDepth < MIN_THRESHOLD && bidDepth < MIN_THRESHOLD) {
            if (!isPresent(index)) {
                UNFILLED.push(symbol);
                console.log('Added ' + symbol + ' (' + askDepth + '/' + bidDepth + ') - ' + UNFILLED.length);
            }
        } else if (isPresent(index)) {
            UNFILLED.splice(index, 1);
            console.log('Removed ' + symbol + ' (' + askDepth + '/' + bidDepth + ') - ' + UNFILLED.length);
        }