How to use binance - 7 common examples

To help you get started, we’ve selected a few binance 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 tiagosiebler / TriangularArbitrage / index.js View on Github external
throw 'Error: Specify your binance API settings in a file called ".keys". The .keys-template can be used as a template for how the .keys file should look.';
}

logger.info('\n\n\n----- Bot Starting : -----\n\n\n');

var exchangeAPI = {};

logger.info('--- Loading Exchange API');

// make exchange module dynamic later
if (process.env.activeExchange == 'binance'){
  logger.info('--- \tActive Exchange:' + process.env.activeExchange);
  // activePairs = process.env.binancePairs;
  
  const api = require('binance');
  exchangeAPI = new api.BinanceRest({
    key: process.env.binance_key,
    secret: process.env.binance_secret,
    timeout: parseInt(process.env.restTimeout), // Optional, defaults to 15000, is the request time out in milliseconds
    recvWindow: parseInt(process.env.restRecvWindow), // Optional, defaults to 5000, increase if you're getting timestamp errors
    disableBeautification: process.env.restBeautify != 'true'
  });
  exchangeAPI.WS = new api.BinanceWS();
}

var botOptions = {
    UI: {
      title: 'Top Potential Arbitrage Triplets, via: ' + process.env.binanceColumns
    },
    arbitrage: {
      paths: process.env.binanceColumns.split(','),
      start: process.env.binanceStartingPoint
github tiagosiebler / TriangularArbitrage / index.js View on Github external
logger.info('--- Loading Exchange API');

// make exchange module dynamic later
if (process.env.activeExchange == 'binance'){
  logger.info('--- \tActive Exchange:' + process.env.activeExchange);
  // activePairs = process.env.binancePairs;
  
  const api = require('binance');
  exchangeAPI = new api.BinanceRest({
    key: process.env.binance_key,
    secret: process.env.binance_secret,
    timeout: parseInt(process.env.restTimeout), // Optional, defaults to 15000, is the request time out in milliseconds
    recvWindow: parseInt(process.env.restRecvWindow), // Optional, defaults to 5000, increase if you're getting timestamp errors
    disableBeautification: process.env.restBeautify != 'true'
  });
  exchangeAPI.WS = new api.BinanceWS();
}

var botOptions = {
    UI: {
      title: 'Top Potential Arbitrage Triplets, via: ' + process.env.binanceColumns
    },
    arbitrage: {
      paths: process.env.binanceColumns.split(','),
      start: process.env.binanceStartingPoint
    },
    storage: {
      logHistory: false
    },
    trading: {
      paperOnly: true,
      // only candidates with over x% gain potential are queued for trading
github victorbutler / binance-profit-calculator / lib / api / binance.js View on Github external
setupRest () {
    let self = this
    self.binanceRest = new binanceAPI.BinanceRest({
        key: self.publicKey, // Get this from your account on binance.com
        secret: self.secretKey, // Same for this
        timeout: 15000, // Optional, defaults to 15000, is the request time out in milliseconds
        recvWindow: 5000 // Optional, defaults to 5000, increase if you're getting timestamp errors
    })
  }
  pingUserData () {
github askmike / gekko / exchange / wrappers / binance.js View on Github external
// over a second, this tells binance
    // to bail out after 500ms.
    //
    // As discussed in binance API
    // telegram. TODO add link.
    recvWindow = 500;
  }

  this.pair = this.asset + this.currency;
  this.name = 'binance';

  this.market = _.find(Trader.getCapabilities().markets, (market) => {
    return market.pair[0] === this.currency && market.pair[1] === this.asset
  });

  this.binance = new Binance.BinanceRest({
    key: this.key,
    secret: this.secret,
    timeout: 15000,
    recvWindow,
    disableBeautification: false,
    handleDrift: true,
  });

  if(config.key && config.secret) {
    // Note non standard func:
    //
    // On binance we might pay fees in BNB
    // if we do we CANNOT calculate feePercent
    // since we don't track BNB price (when we
    // are not trading on a BNB market).
    //
github aloysius-pgast / crypto-exchanges-gateway / app / exchanges / binance / exchange.js View on Github external
constructor(exchangeId, exchangeName, config)
{
    super(exchangeId, exchangeType, exchangeName, supportedFeatures, config);
    let opt = {
        key:config.exchanges[exchangeId].key,
        secret:config.exchanges[exchangeId].secret,
        recvWindow:config.exchanges[exchangeId].recvWindow,
        timeout:15000,
        disableBeautification:true
    };
    this._restClient = new Api.BinanceRest(opt);
    // limiters
    this._limiterGlobal = this._getRateLimiter(config.exchanges[exchangeId].throttle.global.maxRequestsPerSecond);
    let weightedRate;
    // limiter for methods with a weight of 5
    weightedRate = parseInt(config.exchanges[exchangeId].throttle.global.maxRequestsPerSecond / 5);
    if (0 == weightedRate)
    {
        weightedRate = 1;
    }
    this._limiterWeight5 = this._getRateLimiter(weightedRate);
    this._limiterWeight5.chain(this._limiterGlobal);
    // limiter for methods with a weight of 10
    weightedRate = parseInt(config.exchanges[exchangeId].throttle.global.maxRequestsPerSecond / 10);
    if (0 == weightedRate)
    {
        weightedRate = 1;
github victorbutler / binance-profit-calculator / lib / api / binance.js View on Github external
constructor (config) {
    super()
    if (!config.publicKey || !config.secretKey) {
      this.emit('error', new BinanceError(BinanceError.KeysNotPresent, 'Public or secret key not supplied to the Binance module'))
    }
    this.publicKey = config.publicKey
    this.secretKey = config.secretKey
    this.reconnectOnDisconnected = config.reconnectOnDisconnected || false
    this.retriesMax = config.retriesMax || 5
    this.retryAttempts = 0

    this.udWebSocket = null
    this.retriesInterval = null
    this.setupRest()
    this.binanceWS = new binanceAPI.BinanceWS(true)
  }
  setupRest () {
github benmarten / CryptoETF / src / model / integrations / BinanceWallet.js View on Github external
return new Promise((resolve) => {
          const binance = new Binance.BinanceRest(credential)
          binance.account().then(function(account) {
            let result = []
            let balances = account.balances
            for (let index in balances) {
              let data = balances[index]
              let symbol = data.asset
              let amount = Number(data.free) + Number(data.locked)

              result.push(new Coin(symbol, amount, 'Binance'))
            }
            resolve(result)
          })
        }
    )

binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & end-to-end tests.

MIT
Latest version published 6 days ago

Package Health Score

81 / 100
Full package analysis

Popular binance functions