Skip to content

Instantly share code, notes, and snippets.

@ryqndev
Last active May 6, 2023 22:54
Show Gist options
  • Save ryqndev/493bb266f5c2238760cfeabd308c0724 to your computer and use it in GitHub Desktop.
Save ryqndev/493bb266f5c2238760cfeabd308c0724 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="./script.js"></script>
</head>
<body>
<input type="text" id="user-input" />
<button onclick="clicked()">click me</button>
<div id="display"></div>
</body>
</html>
let POLYGON_API = 'replace-this-with-your-api';
function clicked() {
// gets the user typed value
let userStock = document.getElementById('user-input').value;
// fetches data from the api
fetch(
'https://api.polygon.io/v2/aggs/ticker/' + userStock + '/range/1/day/2023-01-09/2023-01-09?apiKey=' + POLYGON_API,
)
.then(response => response.json())
.then(response => {
// prints out the response
console.log(response);
// sets the value in the website to be stock value
document.getElementById('display').innerHTML = response['results'][0]['c'];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment