Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function get(ticker, amount, ticker2, depth){
- var amountInBtc; var returnText; if (amount || !depth) depth = 999999;
- $.get( "https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_"+ticker+"&depth="+depth, function(orderBook) {
- price = parseFloat((+orderBook.asks[0][0] + +orderBook.bids[0][0]) / 2).toFixed(8);
- Object.keys(orderBook).forEach(function(key,index) {
- if (key == 'seq' || key == 'isFrozen') return; amountInBtc = 0; totalBtc = 0; totalTicker = 0;
- Array.from(orderBook[key]).forEach(function (c) {
- if (+totalTicker > +amount && amount != 0) return;
- totalTicker = parseFloat(+totalTicker + c[1]).toFixed(8); totalBtc = parseFloat(+totalBtc + c[0]*c[1]).toFixed(8);
- if (+totalTicker >= +amount) {
- amountInBtc = parseFloat(totalBtc - (totalTicker - amount) * c[0]).toFixed(8);
- if (ticker2 && key == 'bids') {
- $.get( "https://poloniex.com/public?command=returnOrderBook¤cyPair=BTC_"+ticker2+"&depth="+depth, function(orderBook) {
- totalBtc = 0; totalTicker2 = 0; amountTicker2 = 0;
- orderBook.asks.forEach(function(c) {
- if (+totalBtc > +amountInBtc) { return; }
- totalTicker2 = parseFloat(+totalTicker2 + c[1]).toFixed(8); totalBtc = parseFloat(+totalBtc + c[0]*c[1]).toFixed(8);
- if (+totalBtc >= +amountInBtc) amountTicker2 = parseFloat(totalTicker2 - ((totalBtc - amountInBtc) * c[0])).toFixed(8);
- });
- console.log(amount + ' ' + ticker + ' gives you ' + amountTicker2 + ' ' + ticker2 + '.');
- })
- }
- }
- });
- if (amount && !ticker2) {
- console.log((key == 'asks' ? 'Buying ' : 'Selling ') + amount + ' ' + ticker + ' at current books ' + (key == 'asks' ? 'costs ' : 'gives ') + amountInBtc + ' BTC.\n');
- } else if (!ticker2) {
- if (depth === 999999) {
- if (key == 'asks') { returnText = ticker + ' price is ' + price +'.\n'; console.log(returnText) }
- console.log('People are ' + (key == 'asks' ? 'selling ' : 'buying ') + totalTicker + ' ' + ticker + '. (worth ' + totalBtc + ' BTC)\n');
- } else { console.log('Total ' + (key == 'asks' ? 'on sale ' : 'being bought ') + 'at depth ' + depth + ' is ' + totalTicker + '. (worth ' + totalBtc + ' BTC)\n') }
- }
- });
- });
- return 'Loading...';
- }; ''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement