-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgold_price_tracker.html
More file actions
107 lines (98 loc) · 3.59 KB
/
gold_price_tracker.html
File metadata and controls
107 lines (98 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Gold Price Tracker</title>
<style>
body {
background-color: #121212;
color: #ffffff;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
text-align: center;
max-width: 500px;
padding: 20px;
border: 1px solid #333;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.3);
background-color: #1e1e1e;
}
h1 {
color: #f9a825;
margin-bottom: 20px;
}
.price, .purchase, .result {
font-size: 1.2rem;
margin: 10px 0;
}
.price span, .purchase span, .result span {
font-weight: bold;
color: #f9a825;
}
.result {
margin-top: 20px;
font-size: 1.3rem;
}
.profit {
color: #4caf50;
}
.loss {
color: #f44336;
}
</style>
</head>
<body>
<div class="container">
<h1>Gold Price Tracker</h1>
<div id="goldPrices">
<p class="price">Current Gold (1 oz): <span id="goldOz">Loading...</span> BHD</p>
<p class="price">Current Gold (20g): <span id="gold20g">Loading...</span> BHD</p>
</div>
<div id="purchasePrices">
<p class="purchase">Purchase Price (1 oz): <span id="buyPriceOz">1023</span> BHD</p>
<p class="purchase">Purchase Price (20g): <span id="buyPrice20g">661</span> BHD</p>
</div>
<div class="result" id="profitLoss">Calculating...</div>
</div>
<script>
async function fetchGoldPrices() {
try {
const response = await fetch('http://127.0.0.1:5000/get-gold-prices');
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
const goldOz = data.gold_oz;
const gold20g = data.gold_20g;
document.getElementById('goldOz').textContent = goldOz.toFixed(2);
document.getElementById('gold20g').textContent = gold20g.toFixed(2);
const buyPriceOz = parseFloat(document.getElementById('buyPriceOz').textContent);
const buyPrice20g = parseFloat(document.getElementById('buyPrice20g').textContent);
const profitLossOz = goldOz - buyPriceOz;
const profitLoss20g = gold20g - buyPrice20g;
const totalProfitLoss = profitLossOz + profitLoss20g;
const resultDiv = document.getElementById('profitLoss');
if (totalProfitLoss > 0) {
resultDiv.textContent = `Profit: ${totalProfitLoss.toFixed(2)} BHD`;
resultDiv.className = 'result profit';
} else {
resultDiv.textContent = `Loss: ${Math.abs(totalProfitLoss).toFixed(2)} BHD`;
resultDiv.className = 'result loss';
}
} catch (error) {
console.error('Error fetching gold prices:', error);
document.getElementById('goldPrices').textContent = 'Failed to load prices.';
}
}
fetchGoldPrices();
</script>
</body>
</html>