nokia stock
Fetching Nokia Stock Data using Go
package main
import (
"fmt"
"net/http"
"io/ioutil"
)
func main() {
resp, err := http.Get("https://api.twelvedata.com/time_series?symbol=NOK&interval=1min&apikey=YOUR_API_KEY")
if err != nil {
fmt.Println("Error fetching data:", err)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("Error reading response:", err)
return
}
fmt.Println(string(body))
}
Explanation
- Import Required Packages:
We import the necessary packages, including "fmt", "net/http", and "io/ioutil".
Main Function:
We define the main function as the entry point of the program.
HTTP GET Request:
We send an HTTP GET request to the Twelve Data API to retrieve the time series data for Nokia stock (NOK) with a 1-minute interval. Replace "YOUR_API_KEY" with your actual API key.
Handle Error:
We check if there's an error during the HTTP request and print an error message if necessary.
Read Response Body:
We read the response body and handle any potential errors.
Print Data:
- We print the stock data received from the API in the console.
This Go program uses the "net/http" package to make an HTTP GET request to the Twelve Data API, retrieves the stock data for Nokia, and prints it to the console.