-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8f8474
commit f073348
Showing
5 changed files
with
118 additions
and
1 deletion.
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,28 @@ | ||
# Stock Market API Web App | ||
|
||
This project is a simple web application that fetches stock market data for a given stock symbol using a public API. | ||
|
||
## Features | ||
|
||
- Fetch and display current stock price, symbol, and price change. | ||
- User-friendly interface with input field and button. | ||
|
||
## Technologies Used | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Setup and Usage | ||
|
||
1. Clone the repository or download the files. | ||
2. Open `index.html` in a web browser. | ||
3. Enter a stock symbol (e.g., `AAPL` for Apple) and click "Get Stock Data" to fetch the stock data. | ||
|
||
## API Key | ||
|
||
To use this project, you'll need to sign up for an API key from a stock market data provider like Alpha Vantage, Finnhub, etc. Replace `'your_api_key'` in `script.js` with your actual API key. | ||
|
||
## License | ||
|
||
This project is open source and available under the MIT License. |
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,19 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Stock Market API</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Stock Market API</h1> | ||
<input type="text" id="stock-symbol" placeholder="Enter Stock Symbol"> | ||
<button id="fetch-data">Get Stock Data</button> | ||
<div id="stock-data"></div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
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,23 @@ | ||
document.getElementById('fetch-data').addEventListener('click', () => { | ||
const stockSymbol = document.getElementById('stock-symbol').value.toUpperCase(); | ||
const apiKey = 'your_api_key'; // Replace with your actual API key | ||
const apiUrl = `https://api.example.com/stock/${stockSymbol}?apikey=${apiKey}`; | ||
|
||
fetch(apiUrl) | ||
.then(response => response.json()) | ||
.then(data => { | ||
const stockDataDiv = document.getElementById('stock-data'); | ||
if (data.error) { | ||
stockDataDiv.innerHTML = `<p>${data.error}</p>`; | ||
} else { | ||
stockDataDiv.innerHTML = ` | ||
<p><strong>Symbol:</strong> ${data.symbol}</p> | ||
<p><strong>Price:</strong> $${data.price}</p> | ||
<p><strong>Change:</strong> ${data.change}%</p> | ||
`; | ||
} | ||
}) | ||
.catch(error => { | ||
console.error('Error fetching stock data:', error); | ||
}); | ||
}); |
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,46 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
background-color: #f4f4f4; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
} | ||
|
||
.container { | ||
background: white; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1); | ||
text-align: center; | ||
} | ||
|
||
h1 { | ||
margin-bottom: 20px; | ||
color: #333; | ||
} | ||
|
||
input { | ||
padding: 10px; | ||
border: 1px solid #ddd; | ||
border-radius: 4px; | ||
margin-right: 10px; | ||
} | ||
|
||
button { | ||
padding: 10px 15px; | ||
background-color: #28a745; | ||
color: white; | ||
border: none; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #218838; | ||
} | ||
|
||
#stock-data { | ||
margin-top: 20px; | ||
} |