Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
v0.8.5
Browse files Browse the repository at this point in the history
  • Loading branch information
Jon Eyrick authored Oct 23, 2018
2 parents 73f5656 + 1d959dd commit 39e969d
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 5 deletions.
71 changes: 71 additions & 0 deletions examples/balances-and-exchangeInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
global.ticker = {};
global.balance = {};
global.minimums = {};
// Get exchangeInfo on startup
//minNotional = minimum order value (price * quantity)
binance.exchangeInfo((error, data) => {
if ( error ) console.error(error);
let minimums = {};
for ( let obj of data.symbols ) {
let filters = {status: obj.status};
for ( let filter of obj.filters ) {
if ( filter.filterType == "MIN_NOTIONAL" ) {
filters.minNotional = filter.minNotional;
} else if ( filter.filterType == "PRICE_FILTER" ) {
filters.minPrice = filter.minPrice;
filters.maxPrice = filter.maxPrice;
filters.tickSize = filter.tickSize;
} else if ( filter.filterType == "LOT_SIZE" ) {
filters.stepSize = filter.stepSize;
filters.minQty = filter.minQty;
filters.maxQty = filter.maxQty;
}
}
//filters.baseAssetPrecision = obj.baseAssetPrecision;
//filters.quoteAssetPrecision = obj.quoteAssetPrecision;
filters.orderTypes = obj.orderTypes;
filters.icebergAllowed = obj.icebergAllowed;
minimums[obj.symbol] = filters;
}
//console.log(minimums);
global.minimums = minimums;
//fs.writeFile("json/minimums.json", JSON.stringify(minimums, null, 4), (err)=>{});

// Get ticker prices
binance.prices((error, ticker) => {
if ( error ) console.error(error);
for ( let symbol in ticker ) {
global.ticker[symbol] = parseFloat(ticker[symbol]);
}
// Get balance on a timer every 5 seconds
setInterval(function(){ balance(); }, 5000);
balance();
});
});

// Get your balances
function balance() {
binance.balance((error, balances) => {
if ( error ) console.error(error);
let btc = 0.00;
for ( let asset in balances ) {
let obj = balances[asset];
obj.available = parseFloat(obj.available);
//if ( !obj.available ) continue;
obj.onOrder = parseFloat(obj.onOrder);
obj.btcValue = 0;
obj.btcTotal = 0;
if ( asset == 'BTC' ) obj.btcValue = obj.available;
else if ( asset == 'USDT' ) obj.btcValue = obj.available / global.ticker.BTCUSDT;
else obj.btcValue = obj.available * global.ticker[asset+'BTC'];
if ( asset == 'BTC' ) obj.btcTotal = obj.available + obj.onOrder;
else if ( asset == 'USDT' ) obj.btcTotal = (obj.available + obj.onOrder) / global.ticker.BTCUSDT;
else obj.btcTotal = (obj.available + obj.onOrder) * global.ticker[asset+'BTC'];
if ( isNaN(obj.btcValue) ) obj.btcValue = 0;
if ( isNaN(obj.btcTotal) ) obj.btcTotal = 0;
btc+= obj.btcTotal;
global.balance[asset] = obj;
}
//fs.writeFile("json/balance.json", JSON.stringify(global.balance, null, 4), (err)=>{});
});
}
15 changes: 15 additions & 0 deletions examples/websocket-ticker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
const Binance = require( 'node-binance-api' );
const binance = new Binance();
global.ticker = {};

// Show contents of BNBUSDT ticker object once per second
setInterval( () => {
if ( !global.ticker.BNBUSDT ) return;
console.log( global.ticker.BNBUSDT );
console.log( `BNB ask: ${global.ticker.BNBUSDT.bestAsk} bid: ${global.ticker.BNBUSDT.bestBid}` );
}, 1000 );

// Get 24h price change statistics for all symbols
binance.websockets.prevDay( false, function ( error, obj ) {
global.ticker[obj.symbol] = obj;
} );
2 changes: 1 addition & 1 deletion node-binance-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -819,7 +819,7 @@ let api = function Binance() {
*/
roundStep: function (qty, stepSize) {
const precision = stepSize.toString().split('.')[1].length || 0;
return (((qty / stepSize) | 0) * stepSize).toFixed(precision);
return ((Math.round(qty / stepSize) | 0) * stepSize).toFixed(precision);
},

/**
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-binance-api",
"version": "0.8.4",
"version": "0.8.5",
"description": "Binance API for node https://github.com/jaggedsoft/node-binance-api",
"main": "node-binance-api.js",
"dependencies": {
Expand Down

0 comments on commit 39e969d

Please sign in to comment.