Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
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 () {
// 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).
//
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;
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)
})
}
)