Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 02 #25

Merged
merged 3 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Welcome to TradeByte

//jshint esversion: 8
// Includes
const path = require("path");
const express = require("express");
Expand All @@ -16,7 +16,7 @@ const MongoStore = require("connect-mongo")(session);
const connectDB = require("./config/db");

// Load config
dotenv.config({ path: "./config/config.env" });
dotenv.config({path: "./config/config.env"});

// Passport config
require("./config/passport")(passport);
Expand All @@ -28,7 +28,7 @@ connectDB();
const app = express();

// Body parser
app.use(express.urlencoded({ extended: false }));
app.use(express.urlencoded({extended: false}));
app.use(express.json());

// Method override
Expand Down Expand Up @@ -62,7 +62,7 @@ app.use(
secret: "keyboard cat",
resave: false,
saveUninitialized: false,
store: new MongoStore({ mongooseConnection: mongoose.connection }),
store: new MongoStore({mongooseConnection: mongoose.connection}),
})
);

Expand All @@ -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;

Expand Down
73 changes: 73 additions & 0 deletions routes/api/view.js
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;
102 changes: 102 additions & 0 deletions views/view.ejs
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>