This repository has been archived by the owner on Oct 30, 2023. It is now read-only.
forked from carlosmiei/node-binance-api
-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
91 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)=>{}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters