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

[SAO FT7-PP-W5D3] Marcela & Rhaysa #646

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Binary file added .DS_Store
Binary file not shown.
83 changes: 83 additions & 0 deletions public/javascripts/financial-data.js
@@ -0,0 +1,83 @@
const key = "demo";
const functionName = "TIME_SERIES_DAILY";
const symbolName = "MSFT";
// const apiUrl = `https://www.alphavantage.co/query?function=${functionName}&symbol=${symbolName}&apikey=${key}`;


const minMax = (elem, value) => {
console.log(`entrando`, value)
switch (elem) {
case 'min':
const mathMin = Math.min(...value);
console.log(mathMin)
return mathMin
break;
case 'max':
return Math.max(...value);
break;
}
}

const print = (inputStart, inputEnd, currency) => {
let apiPrint = ""
const apiUrl = "http://api.coindesk.com/v1/bpi/historical/close.json"
const apiSearch = `http://api.coindesk.com/v1/bpi/historical/close.json?start=${inputStart}&end=${inputEnd}&currency=${currency}`
// if(inputStart !== '' && inputEnd !== '') {
// apiPrint = apiSearch
// } else {
// apiPrint = apiUrl
// }

axios
.get(apiSearch)
.then(responseFromAPI => {
// console.log("The response from API: ", responseFromAPI.data);
printTheChart(responseFromAPI.data.bpi);
})
.catch(err => {
console.log("Error while getting the data: ", err);
});
}



function printTheChart(stockData) {
// const dailyData = stockData["Time Series (Daily)"];

const stockDates = Object.keys(stockData);
const stockPrices = stockDates.map(date => {
return stockData[date];
});

const ctx = document.getElementById("myChart").getContext("2d");
const chart = new Chart(ctx, {
type: "line",
data: {
labels: stockDates,
datasets: [
{
label: 'Bitcoin Price',
backgroundColor: "rgba(202, 202, 202, 0.315)",
borderColor: "rgb(202, 202, 202)",
data: stockPrices
}
]
}
})
// let spred = [...stockPrices]
document.getElementById('min-value').innerHTML = minMax('min', stockPrices);
document.getElementById('max-value').innerHTML = minMax('max', stockPrices);
}


document.addEventListener("change", () => {
const inputStart = document.getElementById('start')
const inputEnd = document.getElementById('end')
const currency = document.getElementById('currency')
// const min = document.getElementById('min-value')
// const max = document.getElementById('max-value')

print(inputStart.value, inputEnd.value, currency.value)

})

18 changes: 16 additions & 2 deletions views/index.hbs
Expand Up @@ -7,6 +7,20 @@
<body>
<h1> {{title}} </h1>
<p>Welcome to {{title}} </p>
</body>
<script src="/javascripts/financial-data.js" charset="utf-8"></script>
<input id="start" type="date" value="2020-03-01">
<input id="end" type="date" value="2020-03-31">

<select id="currency">
<option value="USD">USD</option>
<option value="EUR">EUR</option>
</select>
<div></div><p>Max value</p><p id="max-value"></p></div>
<div><p>Min value</p><p id="min-value"></p></div>


<canvas id="myChart"></canvas>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.4.0/Chart.min.js"></script>
<script src="../javascripts/financial-data.js" charset="utf-8"></script>
</body>
</html>