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

Commit 39e969d

Browse files
author
Jon Eyrick
authored
v0.8.5
2 parents 73f5656 + 1d959dd commit 39e969d

5 files changed

Lines changed: 91 additions & 5 deletions

File tree

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
global.ticker = {};
2+
global.balance = {};
3+
global.minimums = {};
4+
// Get exchangeInfo on startup
5+
//minNotional = minimum order value (price * quantity)
6+
binance.exchangeInfo((error, data) => {
7+
if ( error ) console.error(error);
8+
let minimums = {};
9+
for ( let obj of data.symbols ) {
10+
let filters = {status: obj.status};
11+
for ( let filter of obj.filters ) {
12+
if ( filter.filterType == "MIN_NOTIONAL" ) {
13+
filters.minNotional = filter.minNotional;
14+
} else if ( filter.filterType == "PRICE_FILTER" ) {
15+
filters.minPrice = filter.minPrice;
16+
filters.maxPrice = filter.maxPrice;
17+
filters.tickSize = filter.tickSize;
18+
} else if ( filter.filterType == "LOT_SIZE" ) {
19+
filters.stepSize = filter.stepSize;
20+
filters.minQty = filter.minQty;
21+
filters.maxQty = filter.maxQty;
22+
}
23+
}
24+
//filters.baseAssetPrecision = obj.baseAssetPrecision;
25+
//filters.quoteAssetPrecision = obj.quoteAssetPrecision;
26+
filters.orderTypes = obj.orderTypes;
27+
filters.icebergAllowed = obj.icebergAllowed;
28+
minimums[obj.symbol] = filters;
29+
}
30+
//console.log(minimums);
31+
global.minimums = minimums;
32+
//fs.writeFile("json/minimums.json", JSON.stringify(minimums, null, 4), (err)=>{});
33+
34+
// Get ticker prices
35+
binance.prices((error, ticker) => {
36+
if ( error ) console.error(error);
37+
for ( let symbol in ticker ) {
38+
global.ticker[symbol] = parseFloat(ticker[symbol]);
39+
}
40+
// Get balance on a timer every 5 seconds
41+
setInterval(function(){ balance(); }, 5000);
42+
balance();
43+
});
44+
});
45+
46+
// Get your balances
47+
function balance() {
48+
binance.balance((error, balances) => {
49+
if ( error ) console.error(error);
50+
let btc = 0.00;
51+
for ( let asset in balances ) {
52+
let obj = balances[asset];
53+
obj.available = parseFloat(obj.available);
54+
//if ( !obj.available ) continue;
55+
obj.onOrder = parseFloat(obj.onOrder);
56+
obj.btcValue = 0;
57+
obj.btcTotal = 0;
58+
if ( asset == 'BTC' ) obj.btcValue = obj.available;
59+
else if ( asset == 'USDT' ) obj.btcValue = obj.available / global.ticker.BTCUSDT;
60+
else obj.btcValue = obj.available * global.ticker[asset+'BTC'];
61+
if ( asset == 'BTC' ) obj.btcTotal = obj.available + obj.onOrder;
62+
else if ( asset == 'USDT' ) obj.btcTotal = (obj.available + obj.onOrder) / global.ticker.BTCUSDT;
63+
else obj.btcTotal = (obj.available + obj.onOrder) * global.ticker[asset+'BTC'];
64+
if ( isNaN(obj.btcValue) ) obj.btcValue = 0;
65+
if ( isNaN(obj.btcTotal) ) obj.btcTotal = 0;
66+
btc+= obj.btcTotal;
67+
global.balance[asset] = obj;
68+
}
69+
//fs.writeFile("json/balance.json", JSON.stringify(global.balance, null, 4), (err)=>{});
70+
});
71+
}

examples/websocket-ticker.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
const Binance = require( 'node-binance-api' );
2+
const binance = new Binance();
3+
global.ticker = {};
4+
5+
// Show contents of BNBUSDT ticker object once per second
6+
setInterval( () => {
7+
if ( !global.ticker.BNBUSDT ) return;
8+
console.log( global.ticker.BNBUSDT );
9+
console.log( `BNB ask: ${global.ticker.BNBUSDT.bestAsk} bid: ${global.ticker.BNBUSDT.bestBid}` );
10+
}, 1000 );
11+
12+
// Get 24h price change statistics for all symbols
13+
binance.websockets.prevDay( false, function ( error, obj ) {
14+
global.ticker[obj.symbol] = obj;
15+
} );

node-binance-api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ let api = function Binance() {
819819
*/
820820
roundStep: function (qty, stepSize) {
821821
const precision = stepSize.toString().split('.')[1].length || 0;
822-
return (((qty / stepSize) | 0) * stepSize).toFixed(precision);
822+
return ((Math.round(qty / stepSize) | 0) * stepSize).toFixed(precision);
823823
},
824824

825825
/**

package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-binance-api",
3-
"version": "0.8.4",
3+
"version": "0.8.5",
44
"description": "Binance API for node https://github.com/jaggedsoft/node-binance-api",
55
"main": "node-binance-api.js",
66
"dependencies": {

0 commit comments

Comments
 (0)