diff --git a/Cron/index.js b/Cron/index.js index ebee2d3..52cb5ea 100644 --- a/Cron/index.js +++ b/Cron/index.js @@ -6,6 +6,7 @@ const symbols = require("../Model/Symbols") + //set up default mongoose connection mongoose.connect(config.DataBaseURI, {useNewUrlParser:true, useUnifiedTopology:true}) @@ -49,6 +50,8 @@ cron.schedule('0 * * * *', () => { symbolsObj.totalPositions = element.totalPositions symbolsObj.avgShortPrice = element.avgShortPrice symbolsObj.avgLongPrice = element.avgLongPrice + symbolsObj.date = new Date() + symbolsObj.timeStamp = Date.now() symbolsObj.save() diff --git a/Model/Symbols.js b/Model/Symbols.js index 6d54c4c..094b94f 100644 --- a/Model/Symbols.js +++ b/Model/Symbols.js @@ -1,6 +1,6 @@ const mongoose = require('mongoose') -let date = new Date() + const Symbols = new mongoose.Schema({ name : {type:String, default : ""}, @@ -13,7 +13,7 @@ const Symbols = new mongoose.Schema({ totalPositions : {type:Number, default : 0}, avgShortPrice : {type:Number, default : 0}, avgLongPrice : {type:Number, default : 0}, - date : {type:Date, default : date}, + date : {type:Date, default : new Date()}, timeStamp: {type:Number, default : Date.now()} }) diff --git a/README.md b/README.md index a0e640e..871e592 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ This webserver collects hourly data on trader sentiments from the [myfxbook](https://www.myfxbook.com/) and stores them in a mongodb # config -goto the Config forder create a file dev.js under the forder and insert the code below into the file dev.js + Goto the Config forder create a file dev.js under the forder and insert the code below into the file dev.js ```javascript @@ -15,10 +15,12 @@ module.exports = { ``` +## npm install + To install all the app dependency ## npm start -runs the app on `localhost:5000` + Runs the app on `localhost:5100` diff --git a/index.js b/index.js index 7f853d1..a5c777f 100644 --- a/index.js +++ b/index.js @@ -19,16 +19,37 @@ const db = mongoose.connection //Bind connection to error event (to get notification of connection errors) db.on('error', console.error.bind(console, 'MongoDB connection error:')) + + app.get("/", (req, res) => { - symbols.find((err, data)=>{ + symbols.distinct("name", (err, symbol)=>{ + + console.log(symbol) + + symbols.find((err, data)=>{ + + console.log(data) + + res.send([symbol, data]) + + }) + + }) + + +}) + +app.get("/symbol", (req, res) => { + + symbols.find({name:"EURUSD"}, (err, data)=>{ console.log(data) res.send(data) }) - + }) app.get("/ping", (req, res) => { @@ -41,6 +62,6 @@ app.get("/ping", (req, res) => { //check if there is an environment port -const PORT = process.env.PORT || 6000 +const PORT = process.env.PORT || 5100 app.listen(PORT) \ No newline at end of file