How to use the node-binance-api.websockets function in node-binance-api

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
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 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);
        }
github andresilvasantos / bitprophet / exchange_utils.js View on Github external
terminateWebsocket: function(websocketName) {
        var endpoints = Object.keys(binance.websockets.subscriptions())
        if(endpoints.indexOf(websocketName) != -1) {
             binance.websockets.terminate(websocketName);
        }
    }
}
github gmverdon / TradingBot / src / scenes / TradeHub / index.js View on Github external
  removeSocket = endpoint => binance.websockets.terminate(endpoint);
github andresilvasantos / bitprophet / bitprophet.js View on Github external
function initUserDataUpdates() {
		if(userDataWebsocket.connecting) return

		userDataWebsocket.connectionTimestamp = Date.now()
		userDataWebsocket.connecting = true
		binance.websockets.userData(balance_update, execution_update, function(listenKey) {
			userDataWebsocket.listenKey = listenKey
			userDataWebsocket.connecting = false
		})
	}
github gmverdon / TradingBot / src / scenes / TradeHub / index.js View on Github external
bindSocket = (symbol) => {
    binance.websockets.candlesticks([symbol], '1m', (candlesticks) => {
      const { k: ticks } = candlesticks;
      const { c: close } = ticks;
      const currentPrice = parseFloat(close);

      this.setState({ currentPrice });
      this.checkPrice(currentPrice);
    });
  };
github andresilvasantos / bitprophet / exchange_utils.js View on Github external
startChartUpdate: function(pairName, interval, next) {
        binance.websockets.chart(pairName, interval, (pairName, interval, chart) => {
            next(pairName, interval, chart)
        });
    },
    websocketActive: function(websocketName) {