I am new to Go
lang have created a REST client that consumes the alphavantage API
The JSON
structure which comes up after I make a GET
request looks as below. I only need the Time Series
key data so that I do my own calculations. How do I get the data from the Time Series
and save it so that I do my own manipulations of the data?
JSON
{
"Meta Data": {
"1. Information": "Intraday (1min) prices and volumes",
"2. Symbol": "MSFT",
"3. Last Refreshed": "2018-05-25 16:00:00",
"4. Interval": "1min",
"5. Output Size": "Compact",
"6. Time Zone": "US/Eastern"
},
"Time Series (1min)": {
"2018-05-25 16:00:00": {
"1. open": "98.2700",
"2. high": "98.4400",
"3. low": "98.2650",
"4. close": "98.3600",
"5. volume": "2466507"
}
}
}
code for REST Client
package main
import (
"net/http"
"fmt"
"io/ioutil"
//encode and decode JSON streams
"encoding/json"
)
func main() {
response, err := http.Get("https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo")
if err!=nil{
fmt.Println(err)
return
}
defer response.Body.Close()
contents, err := ioutil.ReadAll(response.Body)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(string(contents))
}