diff --git a/asyncData.js b/asyncData.js index 9db6d9a..dbb3251 100644 --- a/asyncData.js +++ b/asyncData.js @@ -1,10 +1,6 @@ var express = require('express'); var app = express(); -var fs = require('fs'); -var _ = require('lodash'); var math = require('mathjs'); -var moment = require('moment'); -var colors = require('colors'); //=============================================================================================================================== diff --git a/bot.js b/bot.js index 0b1cc47..6297978 100644 --- a/bot.js +++ b/bot.js @@ -24,7 +24,6 @@ var numeral = require('numeral'); // MLAB DATABASE CONFIG //=============================================================================================================================== - const dbRoute = process.env.MLAB; mongoose.connect(dbRoute, { useNewUrlParser: true}); let db = mongoose.connection; @@ -32,12 +31,10 @@ let db = mongoose.connection; db.once('open', () => console.log('db connected')); db.on('error', console.error.bind(console, 'monogdb connection error:')); - //=============================================================================================================================== // Binance CONFIG //=============================================================================================================================== - const binance = require('node-binance-api')().options({ APIKEY: process.env.APIKEY, APISECRET: process.env.APISECRET, @@ -45,45 +42,22 @@ const binance = require('node-binance-api')().options({ test: false // If you want to use sandbox mode where orders are simulated }); - -//=============================================================================================================================== -// BodyParser + MethodOverride + EJS CONFIG -//=============================================================================================================================== - - -app.set("view engine", "ejs"); -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ - extended: true -})); -app.use(methodOverride("_method")); -app.use(express.static(__dirname + "/public")); - -//=============================================================================================================================== -// CoinMarketCap API -//=============================================================================================================================== - -// const CoinMarketCap = require('coinmarketcap-api'); - -// const apiKey = 'process.env.CoinMarketCap'; -// const client = new CoinMarketCap(apiKey); - -// setInterval( - -// client.getQuotes({symbol: ['BTC', 'ETH']}).then(console.log).catch(console.error) - -// , 10000); - //=============================================================================================================================== // Binance API - IOTA ETH BOT //=============================================================================================================================== -let tradePair = 'IOTAETH'; -let tradeQty = 5; +let tradePair = 'IOTAETH'; // Pair you want to trade. +let tradeQty = 10; // Qty you want to trade. let timeFrame = '15m'; // Trading Period: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M let decimalPlaces = 0.00000001; // Number of decimal places on tradingPair let tradeInterval = 10000; // Interval of milliseconds bot will analyse price changes. Needs to be > 1000, due to Exchange API limits. -let totalETHInvested = 0.43; // ETH invested 2/19/2019 +let totalETHInvested = 4.1; // Total invested. +let sinceInception = moment("20190618", "YYYYMMDD").fromNow(); // Date you started investing. + +// Function to eliminate fl +function strip(number) { + return (parseFloat(number).toPrecision(6)); +} setInterval(function() { @@ -100,7 +74,7 @@ setInterval(function() { arrayVolume.push(+ticks[i][5]); } - // Available parameters to use with Trading strategy (RSI, BolingerBand, SMA, etc...) Look at the technical indicators library for more indicators. + // Available parameters to use with Trading strategy (RSI, BolingerBand, SMA, etc...) Google npm technical indicators library for more indicators. var fivePeriodCandlestickInput = { open: [+ticks[194][1], +ticks[195][1], +ticks[196][1], +ticks[197][1], +ticks[198][1]], high: [+ticks[194][2], +ticks[195][2], +ticks[196][2], +ticks[197][2], +ticks[198][2]], @@ -126,6 +100,7 @@ setInterval(function() { values: array200Period, stdDev: 3 }; + //Calculate RSI (Relative Strength Index), BollingerBands, SMA (Simple Moving Average), ROC (Rate of Change). var rsi = RSI.calculate(inputRSI)[RSI.calculate(inputRSI).length - 1]; var bollingerBands1 = BB.calculate(inputBB1); @@ -163,10 +138,11 @@ setInterval(function() { return result; })().then((result) => { - var optimalBuyPrice = math.max(lastPrice, +result.bidAsk.bidPrice + +decimalPlaces); - var optimalSellPrice = math.min(lastPrice, +result.bidAsk.askPrice - +decimalPlaces); + // Optimal Buy & Sell Prices. + var optimalBuyPrice = strip(math.max(lastPrice, +result.bidAsk.bidPrice + +decimalPlaces)); + var optimalSellPrice = strip(math.min(lastPrice, +result.bidAsk.askPrice - +decimalPlaces)); - // STRATEGY STARTS HERE! Example below....use the node-binance-api functions on the README.md file to create strategy. + // STRATEGY STARTS HERE! Once condition is met, current order is canceled and new order is placed. if (lastPrice < lower && rsi < 38) { setTimeout(function() { @@ -194,7 +170,7 @@ setInterval(function() { console.log(symbol + " cancel response:", response); }); console.log(colors.cyan('Strong Buy: RSI < 20')); - binance.buy(tradePair, tradeQty * 3, +result.bidAsk.askPrice); + binance.buy(tradePair, tradeQty * 3, strip(+result.bidAsk.askPrice)); }, 500); } else if (lastPrice > upper && rsi > 60) { @@ -214,7 +190,7 @@ setInterval(function() { console.log(symbol + " cancel response:", response); }); console.log(colors.cyan('Strong Sell: RSI > 80')); - binance.sell(tradePair, tradeQty * 3, +result.bidAsk.bidPrice); + binance.sell(tradePair, tradeQty * 3, strip(+result.bidAsk.bidPrice)); }, 500); } else if (+result.balances.ETH.available < 0.02 ) { @@ -224,11 +200,11 @@ setInterval(function() { console.log(symbol + " cancel response:", response); }); console.log(colors.cyan('Sell: reduce risk, overbought')); - binance.sell(tradePair, +(+result.balances.IOTA.available * 0.15).toFixed(0), +result.bidAsk.askPrice - +decimalPlaces); + binance.sell(tradePair, +(+result.balances.IOTA.available * 0.25).toFixed(0), strip(+result.bidAsk.askPrice - +decimalPlaces)); }, 500); - // STRATEGY ENDS HERE. - + + // Place BNB order for exchange fees. } else if (+result.balances.BNB.available < 0.5 ) { setTimeout(function() { @@ -239,6 +215,7 @@ setInterval(function() { binance.buy('BNBETH', 0.5, +result.bidAsk.askPrice - +decimalPlaces); }, 500); + // Logs all information to the console. } else { console.log('============================================================'); console.log(new Date().toLocaleString()); @@ -278,7 +255,7 @@ setInterval(function() { `Total Qty Sold: ${result.tradeHistoryData[4]} \n` + `Weighted Buy Price: ${result.tradeHistoryData[0]} \n` + `Weighted Sell Price: ${result.tradeHistoryData[3]} \n` + - 'Total Profit/Loss: ' + ((+result.tradeHistoryData[3] - +result.tradeHistoryData[0]) * Math.min(Number(math.sum(+result.tradeHistoryData[4])), Number(math.sum(+result.tradeHistoryData[1])))).toFixed(4) + ' ETH'); + 'Total Profit/Loss: Ξ ' + ((+result.tradeHistoryData[3] - +result.tradeHistoryData[0]) * Math.min(Number(math.sum(+result.tradeHistoryData[4])), Number(math.sum(+result.tradeHistoryData[1])))).toFixed(4)); var mktMakerProfitOrLoss = Number((((((result.tradeHistoryData[3]) / result.tradeHistoryData[0]) - 1) * 100) - 0.2).toFixed(2)); if (mktMakerProfitOrLoss > 0) { @@ -288,17 +265,18 @@ setInterval(function() { } console.log('------------------------------------------------------------' + "\n"); console.log(colors.underline.cyan('Account Data =>').bgBlack.bold); - console.log(`ETH balance: ${numeral(result.balances.ETH.available).format('0.000')}`); - console.log(`IOTA balance: ${numeral(result.balances.IOTA.available).format('0.0')} or ${(result.balances.IOTA.available*lastPrice).toFixed(2)} ETH`); - console.log(`Total ETH Invested: ${totalETHInvested}`); + console.log(`ETH balance: Ξ ${numeral(result.balances.ETH.available).format('0.000')}`); + console.log(`IOTA balance: ${numeral(result.balances.IOTA.available).format('0.0')} miota || Ξ ${(result.balances.IOTA.available*lastPrice).toFixed(2)}`); + console.log(`Total Invested: Ξ ${totalETHInvested}`); var totalETHBalance = (+result.balances.ETH.available + +result.balances.IOTA.available*lastPrice).toFixed(3); - console.log(`Total ETH balance: ${totalETHBalance}`); + console.log(`Total balance: Ξ ${totalETHBalance} || $ ${(totalETHBalance * result.prices.ETHUSDT).toFixed(0)} USD`); console.log(`Total BNB balance: ${numeral(+result.balances.BNB.available).format('0.00')}`); if(((+totalETHBalance/+totalETHInvested)-1) < 0) { console.log(`ROI: ${colors.red(numeral((+totalETHBalance/+totalETHInvested)-1).format('%0.000')).bold}`); } else { console.log(`ROI: ${colors.green(numeral((+totalETHBalance/+totalETHInvested)-1).format('%0.000')).bold}`); } + console.log(`Since Inception: ${sinceInception}`); console.log('------------------------------------------------------------' + "\n"); binance.openOrders(false, (error, openOrders) => { @@ -315,75 +293,74 @@ setInterval(function() { //=============================================================================================================================== -// COLLECT DATA +// COLLECT DATA - NOT IN USE //=============================================================================================================================== -setInterval(()=> { - // Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M - binance.candlesticks(tradePair, timeFrame, (error, ticks, symbol) => { - let last_tick = ticks[ticks.length - 1]; - let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; +// setInterval(()=> { +// // Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M +// binance.candlesticks(tradePair, timeFrame, (error, ticks, symbol) => { +// let last_tick = ticks[ticks.length - 1]; +// let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; - var newData = new Data15m(); +// var newData = new Data15m(); - newData.date = moment.unix(+time/1000).format("YYYY-MM-DD"); - newData.time = moment.unix(+time/1000).format('LTS'); - newData.closeTime = moment.unix(+closeTime/1000).format('LTS'); - newData.open = open; - newData.high = high; - newData.low = low; - newData.close = close; - newData.assetVolume = assetVolume; - newData.trades = trades; - newData.buyBaseVolume = buyBaseVolume; - newData.buyAssetVolume = buyAssetVolume; +// newData.date = moment.unix(+time/1000).format("YYYY-MM-DD"); +// newData.time = moment.unix(+time/1000).format('LTS'); +// newData.closeTime = moment.unix(+closeTime/1000).format('LTS'); +// newData.open = open; +// newData.high = high; +// newData.low = low; +// newData.close = close; +// newData.assetVolume = assetVolume; +// newData.trades = trades; +// newData.buyBaseVolume = buyBaseVolume; +// newData.buyAssetVolume = buyAssetVolume; - // newData.data = ticks; +// // newData.data = ticks; - newData.save((err, docs) => { - if(err) { - console.log(err); - } else { - return docs; - } - }); +// newData.save((err, docs) => { +// if(err) { +// console.log(err); +// } else { +// return docs; +// } +// }); - }, {limit: 500, endTime: Date.now() }); -}, 1000*60*15); - -Data15mLast500.deleteMany({}, (err, result)=>{ - if(err) { - console.log(err); - } else { - console.log(result); - } -}); - -// Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M -binance.candlesticks(tradePair, timeFrame, (error, ticks, symbol) => { - let last_tick = ticks[ticks.length - 1]; - let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; +// }, {limit: 500, endTime: Date.now() }); +// }, 1000*60*15); + +// Data15mLast500.deleteMany({}, (err, result)=>{ +// if(err) { +// console.log(err); +// } else { +// console.log(result); +// } +// }); + +// // Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M +// binance.candlesticks(tradePair, timeFrame, (error, ticks, symbol) => { +// let last_tick = ticks[ticks.length - 1]; +// let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; - var newData = new Data15mLast500(); +// var newData = new Data15mLast500(); - newData.data = ticks; +// newData.data = ticks; - newData.save((err, docs) => { - if(err) { - console.log(err); - } else { - return docs; - } - }); +// newData.save((err, docs) => { +// if(err) { +// console.log(err); +// } else { +// return docs; +// } +// }); -}, {limit: 500, endTime: Date.now() }); +// }, {limit: 500, endTime: Date.now() }); //=============================================================================================================================== // SERVER START //=============================================================================================================================== - app.listen(8081, process.env.IP, function() { console.log('server start...' + process.env.IP + ":" + 8081); }); \ No newline at end of file diff --git a/bot2.js b/bot2.js index db1667a..dab4e9a 100644 --- a/bot2.js +++ b/bot2.js @@ -24,7 +24,6 @@ var numeral = require('numeral'); // MLAB DATABASE CONFIG //=============================================================================================================================== - const dbRoute = process.env.MLAB; mongoose.connect(dbRoute, { useNewUrlParser: true}); let db = mongoose.connection; @@ -32,12 +31,10 @@ let db = mongoose.connection; db.once('open', () => console.log('db connected')); db.on('error', console.error.bind(console, 'monogdb connection error:')); - //=============================================================================================================================== // Binance CONFIG //=============================================================================================================================== - const binance = require('node-binance-api')().options({ APIKEY: process.env.APIKEY, APISECRET: process.env.APISECRET, @@ -45,45 +42,22 @@ const binance = require('node-binance-api')().options({ test: false // If you want to use sandbox mode where orders are simulated }); - -//=============================================================================================================================== -// BodyParser + MethodOverride + EJS CONFIG -//=============================================================================================================================== - - -app.set("view engine", "ejs"); -app.use(bodyParser.json()); -app.use(bodyParser.urlencoded({ - extended: true -})); -app.use(methodOverride("_method")); -app.use(express.static(__dirname + "/public")); - -//=============================================================================================================================== -// CoinMarketCap API -//=============================================================================================================================== - -// const CoinMarketCap = require('coinmarketcap-api'); - -// const apiKey = 'process.env.CoinMarketCap'; -// const client = new CoinMarketCap(apiKey); - -// setInterval( - -// client.getQuotes({symbol: ['BTC', 'ETH']}).then(console.log).catch(console.error) - -// , 10000); - //=============================================================================================================================== // Binance API - IOTA ETH BOT //=============================================================================================================================== -let tradePair = 'IOTAETH'; -let tradeQty = 5; +let tradePair = 'IOTAETH'; // Pair you want to trade. +let tradeQty = 10; // Qty you want to trade. let timeFrame = '15m'; // Trading Period: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M let decimalPlaces = 0.00000001; // Number of decimal places on tradingPair let tradeInterval = 10000; // Interval of milliseconds bot will analyse price changes. Needs to be > 1000, due to Exchange API limits. -let totalETHInvested = 0.43; // ETH invested +let totalETHInvested = 4.1; // Total invested. +let sinceInception = moment("20190618", "YYYYMMDD").fromNow(); // Date you started investing. + +// Function to eliminate fl +function strip(number) { + return (parseFloat(number).toPrecision(6)); +} setInterval(function() { @@ -100,7 +74,7 @@ setInterval(function() { arrayVolume.push(+ticks[i][5]); } - // Available parameters to use with Trading strategy (RSI, BolingerBand, SMA, etc...) Look at the technical indicators library for more indicators. + // Available parameters to use with Trading strategy (RSI, BolingerBand, SMA, etc...) Google npm technical indicators library for more indicators. var fivePeriodCandlestickInput = { open: [+ticks[194][1], +ticks[195][1], +ticks[196][1], +ticks[197][1], +ticks[198][1]], high: [+ticks[194][2], +ticks[195][2], +ticks[196][2], +ticks[197][2], +ticks[198][2]], @@ -126,6 +100,7 @@ setInterval(function() { values: array200Period, stdDev: 3 }; + //Calculate RSI (Relative Strength Index), BollingerBands, SMA (Simple Moving Average), ROC (Rate of Change). var rsi = RSI.calculate(inputRSI)[RSI.calculate(inputRSI).length - 1]; var bollingerBands1 = BB.calculate(inputBB1); @@ -163,10 +138,11 @@ setInterval(function() { return result; })().then((result) => { - var optimalBuyPrice = math.max(lastPrice, +result.bidAsk.bidPrice + +decimalPlaces); - var optimalSellPrice = math.min(lastPrice, +result.bidAsk.askPrice - +decimalPlaces); + // Optimal Buy & Sell Prices. + var optimalBuyPrice = strip(math.max(lastPrice, +result.bidAsk.bidPrice + +decimalPlaces)); + var optimalSellPrice = strip(math.min(lastPrice, +result.bidAsk.askPrice - +decimalPlaces)); - // STRATEGY STARTS HERE! Example below....use the node-binance-api functions on the README.md file to create strategy. + // STRATEGY STARTS HERE! Once condition is met, current order is canceled and new order is placed. if (lastPrice < lower && rsi < 38) { setTimeout(function() { @@ -194,7 +170,7 @@ setInterval(function() { console.log(symbol + " cancel response:", response); }); console.log(colors.cyan('Strong Buy: RSI < 20')); - binance.buy(tradePair, tradeQty * 3, +result.bidAsk.askPrice); + binance.buy(tradePair, tradeQty * 3, strip(+result.bidAsk.askPrice)); }, 500); } else if (lastPrice > upper && rsi > 60) { @@ -203,7 +179,7 @@ setInterval(function() { binance.cancelOrders(tradePair, (error, response, symbol) => { console.log(symbol + " cancel response:", response); }); - console.log(colors.cyan('Sell: last price < lower limit @ 2sigma')); + console.log(colors.cyan('Sell: last price > upper limit @ 2sigma')); binance.sell(tradePair, tradeQty, optimalSellPrice); }, 500); @@ -214,21 +190,21 @@ setInterval(function() { console.log(symbol + " cancel response:", response); }); console.log(colors.cyan('Strong Sell: RSI > 80')); - binance.sell(tradePair, tradeQty * 3, +result.bidAsk.bidPrice); + binance.sell(tradePair, tradeQty * 3, strip(+result.bidAsk.bidPrice)); }, 500); - } else if (+result.balances.ETH.available < 0.04 ) { + } else if (+result.balances.ETH.available < 0.02 ) { setTimeout(function() { binance.cancelOrders(tradePair, (error, response, symbol) => { console.log(symbol + " cancel response:", response); }); console.log(colors.cyan('Sell: reduce risk, overbought')); - binance.sell(tradePair, +(+result.balances.IOTA.available * 0.15).toFixed(0), +result.bidAsk.askPrice - +decimalPlaces); + binance.sell(tradePair, +(+result.balances.IOTA.available * 0.25).toFixed(0), strip(+result.bidAsk.askPrice - +decimalPlaces)); }, 500); - // STRATEGY ENDS HERE. - + + // Place BNB order for exchange fees. } else if (+result.balances.BNB.available < 0.5 ) { setTimeout(function() { @@ -239,6 +215,7 @@ setInterval(function() { binance.buy('BNBETH', 0.5, +result.bidAsk.askPrice - +decimalPlaces); }, 500); + // Logs all information to the console. } else { console.log('============================================================'); console.log(new Date().toLocaleString()); @@ -278,7 +255,7 @@ setInterval(function() { `Total Qty Sold: ${result.tradeHistoryData[4]} \n` + `Weighted Buy Price: ${result.tradeHistoryData[0]} \n` + `Weighted Sell Price: ${result.tradeHistoryData[3]} \n` + - 'Total Profit/Loss: ' + ((+result.tradeHistoryData[3] - +result.tradeHistoryData[0]) * Math.min(Number(math.sum(+result.tradeHistoryData[4])), Number(math.sum(+result.tradeHistoryData[1])))).toFixed(4) + ' ETH'); + 'Total Profit/Loss: Ξ ' + ((+result.tradeHistoryData[3] - +result.tradeHistoryData[0]) * Math.min(Number(math.sum(+result.tradeHistoryData[4])), Number(math.sum(+result.tradeHistoryData[1])))).toFixed(4)); var mktMakerProfitOrLoss = Number((((((result.tradeHistoryData[3]) / result.tradeHistoryData[0]) - 1) * 100) - 0.2).toFixed(2)); if (mktMakerProfitOrLoss > 0) { @@ -288,19 +265,20 @@ setInterval(function() { } console.log('------------------------------------------------------------' + "\n"); console.log(colors.underline.cyan('Account Data =>').bgBlack.bold); - console.log(`ETH balance: ${numeral(result.balances.ETH.available).format('0.000')}`); - console.log(`IOTA balance: ${numeral(result.balances.IOTA.available).format('0.0')} or ${(result.balances.IOTA.available*lastPrice).toFixed(2)} ETH`); - console.log(`Total ETH Invested: ${totalETHInvested}`); + console.log(`ETH balance: Ξ ${numeral(result.balances.ETH.available).format('0.000')}`); + console.log(`IOTA balance: ${numeral(result.balances.IOTA.available).format('0.0')} miota || Ξ ${(result.balances.IOTA.available*lastPrice).toFixed(2)}`); + console.log(`Total Invested: Ξ ${totalETHInvested}`); var totalETHBalance = (+result.balances.ETH.available + +result.balances.IOTA.available*lastPrice).toFixed(3); - console.log(`Total ETH balance: ${totalETHBalance}`); + console.log(`Total balance: Ξ ${totalETHBalance} || $ ${(totalETHBalance * result.prices.ETHUSDT).toFixed(0)} USD`); console.log(`Total BNB balance: ${numeral(+result.balances.BNB.available).format('0.00')}`); if(((+totalETHBalance/+totalETHInvested)-1) < 0) { console.log(`ROI: ${colors.red(numeral((+totalETHBalance/+totalETHInvested)-1).format('%0.000')).bold}`); } else { console.log(`ROI: ${colors.green(numeral((+totalETHBalance/+totalETHInvested)-1).format('%0.000')).bold}`); } + console.log(`Since Inception: ${sinceInception}`); console.log('------------------------------------------------------------' + "\n"); - + binance.openOrders(false, (error, openOrders) => { console.log("openOrders()", openOrders); }); @@ -315,75 +293,74 @@ setInterval(function() { //=============================================================================================================================== -// COLLECT DATA +// COLLECT DATA - NOT IN USE //=============================================================================================================================== -setInterval(()=> { - // Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M - binance.candlesticks(tradePair, timeFrame, (error, ticks, symbol) => { - let last_tick = ticks[ticks.length - 1]; - let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; +// setInterval(()=> { +// // Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M +// binance.candlesticks(tradePair, timeFrame, (error, ticks, symbol) => { +// let last_tick = ticks[ticks.length - 1]; +// let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; - var newData = new Data15m(); +// var newData = new Data15m(); - newData.date = moment.unix(+time/1000).format("YYYY-MM-DD"); - newData.time = moment.unix(+time/1000).format('LTS'); - newData.closeTime = moment.unix(+closeTime/1000).format('LTS'); - newData.open = open; - newData.high = high; - newData.low = low; - newData.close = close; - newData.assetVolume = assetVolume; - newData.trades = trades; - newData.buyBaseVolume = buyBaseVolume; - newData.buyAssetVolume = buyAssetVolume; +// newData.date = moment.unix(+time/1000).format("YYYY-MM-DD"); +// newData.time = moment.unix(+time/1000).format('LTS'); +// newData.closeTime = moment.unix(+closeTime/1000).format('LTS'); +// newData.open = open; +// newData.high = high; +// newData.low = low; +// newData.close = close; +// newData.assetVolume = assetVolume; +// newData.trades = trades; +// newData.buyBaseVolume = buyBaseVolume; +// newData.buyAssetVolume = buyAssetVolume; - // newData.data = ticks; +// // newData.data = ticks; - newData.save((err, docs) => { - if(err) { - console.log(err); - } else { - return docs; - } - }); +// newData.save((err, docs) => { +// if(err) { +// console.log(err); +// } else { +// return docs; +// } +// }); - }, {limit: 500, endTime: Date.now() }); -}, 1000*60*15); - -Data15mLast500.deleteMany({}, (err, result)=>{ - if(err) { - console.log(err); - } else { - console.log(result); - } -}); - -// Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M -binance.candlesticks(tradePair, timeFrame, (error, ticks, symbol) => { - let last_tick = ticks[ticks.length - 1]; - let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; +// }, {limit: 500, endTime: Date.now() }); +// }, 1000*60*15); + +// Data15mLast500.deleteMany({}, (err, result)=>{ +// if(err) { +// console.log(err); +// } else { +// console.log(result); +// } +// }); + +// // Intervals: 1m,3m,5m,15m,30m,1h,2h,4h,6h,8h,12h,1d,3d,1w,1M +// binance.candlesticks(tradePair, timeFrame, (error, ticks, symbol) => { +// let last_tick = ticks[ticks.length - 1]; +// let [time, open, high, low, close, volume, closeTime, assetVolume, trades, buyBaseVolume, buyAssetVolume, ignored] = last_tick; - var newData = new Data15mLast500(); +// var newData = new Data15mLast500(); - newData.data = ticks; +// newData.data = ticks; - newData.save((err, docs) => { - if(err) { - console.log(err); - } else { - return docs; - } - }); +// newData.save((err, docs) => { +// if(err) { +// console.log(err); +// } else { +// return docs; +// } +// }); -}, {limit: 500, endTime: Date.now() }); +// }, {limit: 500, endTime: Date.now() }); //=============================================================================================================================== // SERVER START //=============================================================================================================================== - -app.listen(8081, process.env.IP, function() { - console.log('server start...' + process.env.IP + ":" + 8081); +app.listen(8082, process.env.IP, function() { + console.log('server start...' + process.env.IP + ":" + 8082); }); \ No newline at end of file diff --git a/index.js b/index.js index 6ca871c..7f89bd3 100644 --- a/index.js +++ b/index.js @@ -1,10 +1,8 @@ var express = require('express'); var app = express(); -var fs = require('fs'); var bodyParser = require('body-parser'); var methodOverride = require('method-override'); var _ = require('lodash'); -var math = require('mathjs'); var moment = require('moment'); var numeral = require('numeral'); var mongoose = require('mongoose'); diff --git a/package-lock.json b/package-lock.json index 3dc019d..5a54337 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1102,13 +1102,13 @@ "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" }, "fsevents": { - "version": "1.2.4", - "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.4.tgz", - "integrity": "sha512-z8H8/diyk76B7q5wg+Ud0+CqzcAF3mBBI/bA5ne5zrRUUIvNkJY//D3BqyH571KuAC4Nr7Rw7CjWX4r0y9DvNg==", + "version": "1.2.9", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-1.2.9.tgz", + "integrity": "sha512-oeyj2H3EjjonWcFjD5NvZNE9Rqe4UW+nQBU2HNeKw0koVLEFIhtyETyAakeAM3de7Z/SW5kcA+fZUait9EApnw==", "optional": true, "requires": { - "nan": "^2.9.2", - "node-pre-gyp": "^0.10.0" + "nan": "^2.12.1", + "node-pre-gyp": "^0.12.0" }, "dependencies": { "abbrev": { @@ -1127,7 +1127,7 @@ "optional": true }, "are-we-there-yet": { - "version": "1.1.4", + "version": "1.1.5", "bundled": true, "optional": true, "requires": { @@ -1150,7 +1150,7 @@ } }, "chownr": { - "version": "1.0.1", + "version": "1.1.1", "bundled": true, "optional": true }, @@ -1175,15 +1175,15 @@ "optional": true }, "debug": { - "version": "2.6.9", + "version": "4.1.1", "bundled": true, "optional": true, "requires": { - "ms": "2.0.0" + "ms": "^2.1.1" } }, "deep-extend": { - "version": "0.5.1", + "version": "0.6.0", "bundled": true, "optional": true }, @@ -1226,7 +1226,7 @@ } }, "glob": { - "version": "7.1.2", + "version": "7.1.3", "bundled": true, "optional": true, "requires": { @@ -1244,11 +1244,11 @@ "optional": true }, "iconv-lite": { - "version": "0.4.21", + "version": "0.4.24", "bundled": true, "optional": true, "requires": { - "safer-buffer": "^2.1.0" + "safer-buffer": ">= 2.1.2 < 3" } }, "ignore-walk": { @@ -1305,16 +1305,16 @@ "optional": true }, "minipass": { - "version": "2.2.4", + "version": "2.3.5", "bundled": true, "optional": true, "requires": { - "safe-buffer": "^5.1.1", + "safe-buffer": "^5.1.2", "yallist": "^3.0.0" } }, "minizlib": { - "version": "1.1.0", + "version": "1.2.1", "bundled": true, "optional": true, "requires": { @@ -1330,32 +1330,38 @@ } }, "ms": { - "version": "2.0.0", + "version": "2.1.1", "bundled": true, "optional": true }, + "nan": { + "version": "2.14.0", + "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.0.tgz", + "integrity": "sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==", + "optional": true + }, "needle": { - "version": "2.2.0", + "version": "2.3.0", "bundled": true, "optional": true, "requires": { - "debug": "^2.1.2", + "debug": "^4.1.0", "iconv-lite": "^0.4.4", "sax": "^1.2.4" } }, "node-pre-gyp": { - "version": "0.10.0", + "version": "0.12.0", "bundled": true, "optional": true, "requires": { "detect-libc": "^1.0.2", "mkdirp": "^0.5.1", - "needle": "^2.2.0", + "needle": "^2.2.1", "nopt": "^4.0.1", "npm-packlist": "^1.1.6", "npmlog": "^4.0.2", - "rc": "^1.1.7", + "rc": "^1.2.7", "rimraf": "^2.6.1", "semver": "^5.3.0", "tar": "^4" @@ -1371,12 +1377,12 @@ } }, "npm-bundled": { - "version": "1.0.3", + "version": "1.0.6", "bundled": true, "optional": true }, "npm-packlist": { - "version": "1.1.10", + "version": "1.4.1", "bundled": true, "optional": true, "requires": { @@ -1443,11 +1449,11 @@ "optional": true }, "rc": { - "version": "1.2.7", + "version": "1.2.8", "bundled": true, "optional": true, "requires": { - "deep-extend": "^0.5.1", + "deep-extend": "^0.6.0", "ini": "~1.3.0", "minimist": "^1.2.0", "strip-json-comments": "~2.0.1" @@ -1475,15 +1481,15 @@ } }, "rimraf": { - "version": "2.6.2", + "version": "2.6.3", "bundled": true, "optional": true, "requires": { - "glob": "^7.0.5" + "glob": "^7.1.3" } }, "safe-buffer": { - "version": "5.1.1", + "version": "5.1.2", "bundled": true, "optional": true }, @@ -1498,7 +1504,7 @@ "optional": true }, "semver": { - "version": "5.5.0", + "version": "5.7.0", "bundled": true, "optional": true }, @@ -1544,16 +1550,16 @@ "optional": true }, "tar": { - "version": "4.4.1", + "version": "4.4.8", "bundled": true, "optional": true, "requires": { - "chownr": "^1.0.1", + "chownr": "^1.1.1", "fs-minipass": "^1.2.5", - "minipass": "^2.2.4", - "minizlib": "^1.1.0", + "minipass": "^2.3.4", + "minizlib": "^1.1.1", "mkdirp": "^0.5.0", - "safe-buffer": "^5.1.1", + "safe-buffer": "^5.1.2", "yallist": "^3.0.2" } }, @@ -1563,11 +1569,11 @@ "optional": true }, "wide-align": { - "version": "1.1.2", + "version": "1.1.3", "bundled": true, "optional": true, "requires": { - "string-width": "^1.0.2" + "string-width": "^1.0.2 || 2" } }, "wrappy": { @@ -1576,7 +1582,7 @@ "optional": true }, "yallist": { - "version": "3.0.2", + "version": "3.0.3", "bundled": true, "optional": true } @@ -2009,9 +2015,9 @@ "integrity": "sha1-+eIwPUUH9tdDVac2ZNFED7Wg71k=" }, "jquery": { - "version": "3.3.1", - "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.3.1.tgz", - "integrity": "sha512-Ubldcmxp5np52/ENotGxlLe6aGMvmF4R8S6tZjsP6Knsaxd/xp3Zrh50cG93lR6nPXyUFwzN3ZSOQI0wRJNdGg==" + "version": "3.4.1", + "resolved": "https://registry.npmjs.org/jquery/-/jquery-3.4.1.tgz", + "integrity": "sha512-36+AdBzCL+y6qjw5Tx7HgzeGCzC81MDDgaUP8ld2zhx58HdqXGoBd+tHdrBMiyjGQs0Hxs/MLZTu/eHNJJuWPw==" }, "jsbn": { "version": "0.1.1", diff --git a/package.json b/package.json index 1e5d391..a312c34 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,7 @@ "dotenv": "^6.2.0", "ejs": "^2.6.1", "express": "^4.16.4", - "jquery": "^3.3.1", + "jquery": "^3.4.1", "lodash": "^4.17.11", "mathjs": "^5.3.1", "method-override": "^3.0.0",