From 4e19145672b923a7555a39c74e0e63764f10e85d Mon Sep 17 00:00:00 2001 From: howdyAnkit Date: Sat, 8 Aug 2020 00:39:06 +0530 Subject: [PATCH 1/2] alphaVantage live market stocks update --- app.js | 2 +- config/config.env.example | 5 --- package-lock.json | 5 +++ package.json | 1 + routes/api/view.js | 67 ++++++++++++++++++++++++++++++ views/view.ejs | 85 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 159 insertions(+), 6 deletions(-) delete mode 100644 config/config.env.example create mode 100644 routes/api/view.js create mode 100644 views/view.ejs diff --git a/app.js b/app.js index 73aafec..0c27403 100644 --- a/app.js +++ b/app.js @@ -78,7 +78,7 @@ app.use("/", require("./routes/api/index")); app.use("/auth", require("./routes/api/auth")); app.use("/portfolio", require("./routes/api/portfolio")); app.use("/market", require("./routes/api/market")); - +app.use("/view", require("./routes/api/view")); // Port: Love You 3000 const PORT = process.env.PORT || 3000; diff --git a/config/config.env.example b/config/config.env.example deleted file mode 100644 index fd34f79..0000000 --- a/config/config.env.example +++ /dev/null @@ -1,5 +0,0 @@ -PORT = 3000 -MONGO_URI = xxxxx -ALPHA_VANTAGE_KEY = xxxxx -GOOGLE_CLIENT_ID = xxxxx -GOOGLE_CLIENT_SECRET = xxxxx \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index d82fd40..292e3a7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1163,6 +1163,11 @@ } } }, + "mongoose-float": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mongoose-float/-/mongoose-float-1.0.4.tgz", + "integrity": "sha512-0IMn9yADWithih3QEiwiqx+gYAEx5ZIQgKrIaLTX76jfJIq5WRzifGT/KDGqGm5q9NI5WLsgt7oblM3hNv/llw==" + }, "mongoose-legacy-pluralize": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", diff --git a/package.json b/package.json index 573c175..a9c5b40 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "lodash": "^4.17.19", "method-override": "^3.0.0", "mongoose": "^5.9.25", + "mongoose-float": "^1.0.4", "morgan": "^1.10.0", "npm": "^6.14.7", "passport": "^0.4.1", diff --git a/routes/api/view.js b/routes/api/view.js new file mode 100644 index 0000000..c214697 --- /dev/null +++ b/routes/api/view.js @@ -0,0 +1,67 @@ +// View Routes + +const express = require("express"); +const router = express.Router(); +const alpha = require("alphavantage")({ + key: process.env.ALPHA_VANTAGE_KEY +}); + +const getOverview = require("../../helpers/getOverview"); +const { + ensureAuth +} = require("../../middleware/auth"); + +// @desc View Page +// @route GET /view/:symbol +// @access Private +router.get("/:symbol", ensureAuth, async (req, res) => { + const symbol = req.params.symbol; + let data = await getOverview(symbol); + + alpha.data + .intraday(symbol) + .then((data) => { + const intraDay = data["Time Series (1min)"]; + let dates = []; + let opening = []; + let closing = []; + let highs = []; + let lows = []; + let volumes = []; + const keys = Object.getOwnPropertyNames(intraDay); + + for (let i = 0; i < 100; i++) { + dates.push(keys[i]); + opening.push(intraDay[keys[i]]["1. open"]); + highs.push(intraDay[keys[i]]["2. high"]); + lows.push(intraDay[keys[i]]["3. low"]); + closing.push(intraDay[keys[i]]["4. close"]); + volumes.push(intraDay[keys[i]]["5. volume"]); + } + // reverse so dates appear from left to right + dates.reverse(); + closing.reverse(); + // dates = JSON.stringify(dates); + // closing = JSON.stringify(closing); + + res + .status(200) + .render( + "view", { + data, + dates, + opening, + closing, + highs, + lows, + volumes + } + ); + }) + .catch((err) => { + // Handle the error + console.log(err); + }); +}); + +module.exports = router; \ No newline at end of file diff --git a/views/view.ejs b/views/view.ejs new file mode 100644 index 0000000..db9f5c9 --- /dev/null +++ b/views/view.ejs @@ -0,0 +1,85 @@ + + + + + + + WeatherApp + + + + + + + +
+ + + +
+ + + + + <%for(var i=0; i<=5; i++){%> + + + + + + + + + + + + + + + + + + + + + +
Dateopeningclosinghighslowsvolumes
<%- dates[i] %><%- opening[i] %><%- closing[i] %><%- highs[i] %><%- lows[i] %><%- volumes[i] %>
+ + <%}%> + + + + + + + \ No newline at end of file From c01c532ba2bc267a349a54fc0fe152326bd100d4 Mon Sep 17 00:00:00 2001 From: howdyAnkit Date: Sat, 8 Aug 2020 00:50:00 +0530 Subject: [PATCH 2/2] alphaVantage live market stocks update --- routes/api/view.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api/view.js b/routes/api/view.js index c214697..aa3d438 100644 --- a/routes/api/view.js +++ b/routes/api/view.js @@ -1,5 +1,5 @@ // View Routes - +//jshint esversion:8 const express = require("express"); const router = express.Router(); const alpha = require("alphavantage")({