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

  1. Import Required Packages:
  2. We import the necessary packages, including "fmt", "net/http", and "io/ioutil".

  3. Main Function:

  4. We define the main function as the entry point of the program.

  5. HTTP GET Request:

  6. 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.

  7. Handle Error:

  8. We check if there's an error during the HTTP request and print an error message if necessary.

  9. Read Response Body:

  10. We read the response body and handle any potential errors.

  11. Print Data:

  12. 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.