-
Notifications
You must be signed in to change notification settings - Fork 0
/
gold-price.html
61 lines (57 loc) · 1.62 KB
/
gold-price.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Live Gold Prices</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f9f9f9;
margin: 0;
padding: 0;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #333;
}
#gold-price {
font-size: 24px;
font-weight: bold;
color: #e67e22;
text-align: center;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Live Gold Price</h1>
<p id="gold-price">Loading...</p>
</div>
<script>
// Fetch live gold price data
fetch("https://api.metalpriceapi.com/v1/latest
?api_key=42d7525ec901b628596a2157206ef40c
&base=USD
¤cies=EUR,XAU,XAG")
.then(response => response.json())
.then(data => {
const goldPrice = data.rates.XAU;
document.getElementById("gold-price").textContent = `Gold Price: $${goldPrice.toFixed(2)}`;
})
.catch(error => {
console.error("Error fetching data:", error);
document.getElementById("gold-price").textContent = "Error fetching data";
});
</script>
</body>
</html>