up
This commit is contained in:
@@ -43,6 +43,37 @@ func (c *Client) MarketNews() ([]NewsItem, error) {
|
||||
return c.fetchNews(url)
|
||||
}
|
||||
|
||||
// NextEarningsDate retourne la prochaine date d'annonce des résultats (90 jours max).
|
||||
func (c *Client) NextEarningsDate(symbol string) (string, error) {
|
||||
from := time.Now().Format("2006-01-02")
|
||||
to := time.Now().AddDate(0, 3, 0).Format("2006-01-02")
|
||||
url := fmt.Sprintf("%s/calendar/earnings?from=%s&to=%s&symbol=%s&token=%s",
|
||||
baseURL, from, to, symbol, c.apiKey)
|
||||
|
||||
resp, err := c.http.Get(url)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
if resp.StatusCode != 200 {
|
||||
return "", fmt.Errorf("finnhub earnings: HTTP %d", resp.StatusCode)
|
||||
}
|
||||
|
||||
var result struct {
|
||||
EarningsCalendar []struct {
|
||||
Date string `json:"date"`
|
||||
Symbol string `json:"symbol"`
|
||||
} `json:"earningsCalendar"`
|
||||
}
|
||||
if err := json.NewDecoder(resp.Body).Decode(&result); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if len(result.EarningsCalendar) == 0 {
|
||||
return "", nil
|
||||
}
|
||||
return result.EarningsCalendar[0].Date, nil
|
||||
}
|
||||
|
||||
func (c *Client) Ping() error {
|
||||
url := fmt.Sprintf("%s/news?category=general&minId=999999999&token=%s", baseURL, c.apiKey)
|
||||
resp, err := c.http.Get(url)
|
||||
|
||||
Reference in New Issue
Block a user