ynab-portfolio-monitor/providers/staticjsonFinnhub/quote.go

27 lines
645 B
Go
Raw Normal View History

2023-11-13 07:33:22 +00:00
package staticjsonFinnhub
import (
"fmt"
"net/url"
)
type quote struct {
C float64 `json:"c"` // Current price
H float64 `json:"h"` // High price of the day
L float64 `json:"l"` // Low price of the day
O float64 `json:"O"` // Open price of the day
Pc float64 `json:"pc"` // Previous close price
T int `json:"t"` // ?
}
func (c client) getQuote(symbol string) (int, error) {
quoteResponse := &quote{}
query := url.Values{}
query.Add("symbol", symbol)
err := c.get("/quote", quoteResponse, query)
if err != nil {
return 0, fmt.Errorf("http get request error: %v", err)
}
return int(quoteResponse.C * 1000), nil
}