-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from howdyAnkit/fix-02
Fix 02
- Loading branch information
Showing
3 changed files
with
180 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// View Routes | ||
//jshint esversion:8 | ||
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); | ||
let AssetType = data["AssetType"]; | ||
let assetName = data["Name"]; | ||
let assetExchange = data["Exchange"]; | ||
let Currency = data['Currency']; | ||
let Country = data['Country']; | ||
let Sector = data['Sector']; | ||
let MarketCap = data['MarketCap']; | ||
let Ebitda = data['EBITDA']; | ||
let PERatio = data['PERatio']; | ||
|
||
// console.log(data); | ||
alpha.data | ||
.intraday(symbol) | ||
.then((data) => { | ||
const intraDay = data["Time Series (1min)"]; | ||
|
||
const assetInformation = data["Meta Data"]['1. Information']; | ||
const lastRefreshed = data["Meta Data"]['3. Last Refreshed']; | ||
|
||
|
||
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", {symbol, data, dates, opening, closing, highs, lows, volumes, AssetType, assetName,assetExchange,Currency,Country,Sector,MarketCap,Ebitda,PERatio} | ||
); | ||
}) | ||
.catch((err) => { | ||
// Handle the error | ||
console.log(err); | ||
}); | ||
}); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Tradebyte</title> | ||
<link href="https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css" rel="stylesheet"> | ||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/Chart.min.js"></script> | ||
</head> | ||
|
||
<body> | ||
|
||
<form action="/" method="POST" class="flex flex-col sm:flex-row justify-center"> | ||
<label for="cityInput" class="mt-2 px-3 py-2">stockName: </label> | ||
<input type="text" name="stockName" id="stockInput" class="mt-2 px-3 py-2 shadow border rounded-lg w-4/6 px-3 py-2 text-gray-700 focus:bg-blue-100 | ||
placeholder-indigo-300"> | ||
<button type="submit" | ||
class="m-4 bg-indigo-200 border-b-4 border-t-4 border-indigo-800 px-4 py-1 mt-2 px-3 py-2">Search</button> | ||
</form> | ||
|
||
<canvas id="chart"></canvas> | ||
<table class="justify-start sm:justify-center lg:justify-center table-auto border-2 border-gray-600"> | ||
<thead> | ||
<tr> | ||
<th class="px-4 py-2">AssetType</th> | ||
<th class="px-4 py-2">assetExchange</th> | ||
<th class="px-4 py-2">assetExchange</th> | ||
<th class="px-4 py-2">Currency</th> | ||
<th class="px-4 py-2">Country</th> | ||
<th class="px-4 py-2">Sector</th> | ||
<th class="px-4 py-2">MarketCap</th> | ||
<th class="px-4 py-2">Earnings</th> | ||
<th class="px-4 py-2">PERatio</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td class="border-b-2 px-4 py-2 "><%- AssetType %></td> | ||
<td class="border-b-2 px-4 py-2"><%- assetExchange %></td> | ||
<td class="border-b-2 px-4 py-2"><%- assetExchange %></td> | ||
<td class="border-b-2 px-4 py-2"><%- Currency %></td> | ||
<td class="border-b-2 px-4 py-2"><%- Country %></td> | ||
<td class="border-b-2 px-4 py-2"><%- Sector %></td> | ||
<td class="border-b-2 px-4 py-2"><%- MarketCap %></td> | ||
<td class="border-b-2 px-4 py-2"><%- Ebitda %></td> | ||
<td class="border-b-2 px-4 py-2"><%- PERatio %></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
|
||
<%for(var i=0; i<=5; i++){%> | ||
<table class="justify-start sm:justify-center lg:justify-center table-auto border-2 border-gray-600"> | ||
<thead> | ||
<tr> | ||
<th class="px-4 py-2">Date</th> | ||
<th class="px-4 py-2">opening</th> | ||
<th class="px-4 py-2">closing</th> | ||
<th class="px-4 py-2">highs</th> | ||
<th class="px-4 py-2">lows</th> | ||
<th class="px-4 py-2">volumes</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<tr> | ||
<td class="border-b-2 px-4 py-2 "><%- dates[i] %></td> | ||
<td class="border-b-2 px-4 py-2"><%- opening[i] %></td> | ||
<td class="border-b-2 px-4 py-2"><%- closing[i] %></td> | ||
<td class="border-b-2 px-4 py-2"><%- highs[i] %></td> | ||
<td class="border-b-2 px-4 py-2"><%- lows[i] %></td> | ||
<td class="border-b-2 px-4 py-2"><%- volumes[i] %></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
<%}%> | ||
|
||
<script> | ||
var datesList = <%- JSON.stringify(dates) %>; | ||
var closingList = <%- JSON.stringify(closing) %> ; | ||
var ctx = document.getElementById('chart').getContext('2d'); | ||
var myChart = new Chart(ctx, { | ||
type: 'line', | ||
data: { | ||
labels: datesList,closingList, | ||
datasets: [{ | ||
label: <%- JSON.stringify(symbol) %>, | ||
data: closingList, | ||
borderColor: "#3e95cd", | ||
backgroundColor: "rgba(118,152,255,0.4)" | ||
}] | ||
}, | ||
options: { | ||
responsive:true, | ||
maintainAspectRatio: true, | ||
}, | ||
}); | ||
</script> | ||
|
||
|
||
</body> | ||
|
||
</html> |