diff --git a/helpers/getOverview.js b/helpers/getOverview.js index f484b82..f35b80c 100644 --- a/helpers/getOverview.js +++ b/helpers/getOverview.js @@ -1,8 +1,8 @@ // Stock Overview Helper Function - const axios = require("axios"); module.exports = async function getOverview(symbol) { + let data = await axios .get( `https://www.alphavantage.co/query?function=OVERVIEW&symbol=${symbol}&apikey=${process.env.ALPHA_VANTAGE_KEY}` @@ -14,6 +14,9 @@ module.exports = async function getOverview(symbol) { Exchange: resp.data.Exchange, Currency: resp.data.Currency, Country: resp.data.Country, + weeksHigh: resp.data['52WeekHigh'], + weeksLow: resp.data['52WeekLow'], + Desc: resp.data.Description, Sector: resp.data.Sector, MarketCap: new Intl.NumberFormat("en-US", { style: "currency", @@ -24,6 +27,12 @@ module.exports = async function getOverview(symbol) { currency: "USD", }).format(resp.data.EBITDA), PERatio: resp.data.PERatio, + PriceToBookRatio: resp.data.PriceToBookRatio, + EPS: resp.data.EPS, + DividendYield: resp.data.DividendYield, + BookValue: resp.data.BookValue, + ProfitMargin: resp.data.ProfitMargin, + RevenueTTM: resp.data.RevenueTTM })) .catch((err) => { console.log(err); diff --git a/helpers/getPrice.js b/helpers/getPrice.js index 59f20c5..18ae469 100644 --- a/helpers/getPrice.js +++ b/helpers/getPrice.js @@ -6,8 +6,10 @@ const alpha = require("alphavantage")({ module.exports = async function getPrice(symbol) { let stockPrice = alpha.data.quote(symbol).then((res) => { - let price = res["Global Quote"]["05. price"]; - return price; + let latestPrice = res["Global Quote"]["05. price"]; + let low = res["Global Quote"]["04. low"]; + let high = res["Global Quote"]["03. high"]; + return {latestPrice,high,low}; }); return stockPrice; }; diff --git a/public/css/style.css b/public/css/style.css index 2d24345..dc5f728 100644 --- a/public/css/style.css +++ b/public/css/style.css @@ -10,16 +10,3 @@ body { box-sizing: border-box; } -.data-table { - display: flex; - justify-content: center; - align-items: center; - margin: 50px 0 30px 0; -} - -.chartjs-container { - position: relative; - margin: auto; - height: 75vh; - width: 75vw; -} diff --git a/routes/api/cart.js b/routes/api/cart.js index 2b7322e..5f5f3ee 100644 --- a/routes/api/cart.js +++ b/routes/api/cart.js @@ -17,9 +17,8 @@ const getPrice = require("../../helpers/getPrice"); router.get("/:symbol", ensureAuth, async (req, res) => { const symbol = req.params.symbol; const price = await getPrice(symbol); - res - .status(200) - .render("cart", { layout: "layouts/app", symbol, price, href: "/market" }); + res.status(200).render("cart", { layout: "layouts/app", symbol, price, href: '/market', avatar: req.user.image }); + }); // @desc To buy diff --git a/routes/api/market.js b/routes/api/market.js index 63b9a32..11cc195 100644 --- a/routes/api/market.js +++ b/routes/api/market.js @@ -15,9 +15,7 @@ const { ensureAuth, ensureGuest } = require("../../middleware/auth"); // @route GET /Market // @access Private router.get("/", ensureAuth, async (req, res) => { - res - .status(200) - .render("market", { layout: "layouts/app", jsonData, href: "/market" }); + res.status(200).render("market", { layout: "layouts/app", jsonData, href: '/market', avatar: req.user.image }); }); module.exports = router; diff --git a/routes/api/view.js b/routes/api/view.js index 9dc4d15..cf634cf 100644 --- a/routes/api/view.js +++ b/routes/api/view.js @@ -4,6 +4,7 @@ const express = require("express"); const router = express.Router(); +const getPrice = require("../../helpers/getPrice"); const alpha = require("alphavantage")({ key: process.env.ALPHA_VANTAGE_KEY, }); @@ -17,6 +18,7 @@ const { ensureAuth } = require("../../middleware/auth"); router.get("/:symbol", ensureAuth, async (req, res) => { const symbol = req.params.symbol; let data = await getOverview(symbol); + let { latestPrice, low, high } = await getPrice(symbol); let AssetType = data["AssetType"]; let assetName = data["Name"]; let assetExchange = data["Exchange"]; @@ -26,6 +28,15 @@ router.get("/:symbol", ensureAuth, async (req, res) => { let MarketCap = data["MarketCap"]; let Ebitda = data["EBITDA"]; let PERatio = data["PERatio"]; + let PriceToBookRatio = data["PriceToBookRatio"]; + let EPS = data["EPS"]; + let DividendYield = data["DividendYield"]; + let BookValue = data["BookValue"]; + let ProfitMargin = data["ProfitMargin"]; + let RevenueTTM = data["RevenueTTM"]; + let Desc = data["Desc"]; + let weeksLow = data["weeksLow"]; + let weeksHigh = data["weeksHigh"]; // console.log(data); alpha.data @@ -35,7 +46,6 @@ router.get("/:symbol", ensureAuth, async (req, res) => { // const assetInformation = data["Meta Data"]["1. Information"]; // const lastRefreshed = data["Meta Data"]["3. Last Refreshed"]; - let dates = []; let opening = []; let closing = []; @@ -44,7 +54,7 @@ router.get("/:symbol", ensureAuth, async (req, res) => { let volumes = []; const keys = Object.getOwnPropertyNames(intraDay); - for (let i = 0; i < 50; i++) { + for (let i = 0; i < 40; i++) { dates.push(keys[i]); opening.push(intraDay[keys[i]]["1. open"]); highs.push(intraDay[keys[i]]["2. high"]); @@ -53,13 +63,15 @@ router.get("/:symbol", ensureAuth, async (req, res) => { 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", { + layout: "layouts/app", + href: '/market', + avatar: req.user.image, symbol, data, dates, @@ -77,11 +89,23 @@ router.get("/:symbol", ensureAuth, async (req, res) => { MarketCap, Ebitda, PERatio, + PriceToBookRatio, + EPS, + DividendYield, + BookValue, + ProfitMargin, + RevenueTTM, + Desc, + latestPrice, + high, + low, + weeksLow, + weeksHigh, }); }) .catch((err) => { - // Handle the error - console.log(err); + console.error(err); + res.render("error/500"); }); }); diff --git a/views/cart.ejs b/views/cart.ejs index 7c9a937..3be7e79 100644 --- a/views/cart.ejs +++ b/views/cart.ejs @@ -1,40 +1,106 @@ -
Product | ++ Qtd + Quantity + | +Unit price | +Total price | +||||
---|---|---|---|---|---|---|---|
+
+ Earphone + + + |
+
+
+
+
+
+
+ |
+ + + 10.00€ + + | ++ + 20.00€ + + | +||||
+ Tesla Model 3 + + |
+
+
+
+
+
+
+ |
+ + + 49,600.01€ + + | ++ + 148,800.03€ + + | +||||
+ Bic 4 colour pen + + |
+
+
+
-
+
+
+
|
+ + + 1.50€ + + | ++ + 7.50€ + + | +