Skip to main content

News (Go SDK)

  • Last updated
  • View as Markdown

Retrieve news articles for a stock symbol.

Beta Endpoint

The news endpoint is currently in beta. Features and response formats may change.

Making Requests​

Both call styles live on the Stocks service (client.Stocks). Use GetNews for the simplest call, or News when you also need the raw response and rate-limit metadata.

MethodReturnDescription
GetNews(symbol, opts...)([]NewsArticle, error)Convenience wrapper; uses context.Background() and discards the response metadata.
News(ctx, symbol, opts...)([]NewsArticle, *response.Response, error)Context-aware; also returns the raw response + rate-limit metadata.

News​

func (s *Service) News(ctx context.Context, symbol string, opts ...NewsOption) ([]NewsArticle, *response.Response, error)
func (s *Service) GetNews(symbol string, opts ...NewsOption) ([]NewsArticle, error)

Fetch news articles for one symbol. With no options the API returns its default set of recent articles.

Parameters​

  • ctx (context.Context) — controls cancellation and deadlines (context method only).
  • symbol (string) — the stock ticker symbol, e.g. "AAPL". Required; an empty string returns a validation error without making a request.
  • Options (stocks.NewsOption):
    • stocks.WithNewsWindow(w DateWindow) — set the publication date range as a single DateWindow value. Build the window with any of the shared date-window constructors, for example stocks.OnDate(d) or stocks.Between(from, to).

Returns​

  • []NewsArticle — the matching articles.
  • *response.Response — raw response + rate-limit metadata (context method only).
  • error — non-nil on request/validation failure.

Notes​

  • Only the calendar date of each time.Time in a window is used; the time-of-day and zone are ignored.
  • If the API responds with 404 because no data is available, News returns a nil slice, a nil error, and a non-nil *response.Response whose NoData field is true.
package main

import (
"fmt"
"log"

"github.com/MarketDataApp/sdk-go/v2/marketdata"
)

func main() {
client, err := marketdata.NewClient(marketdata.WithToken("YOUR_TOKEN"))
if err != nil {
log.Fatal(err)
}
defer client.Close()

articles, err := client.Stocks.GetNews("AAPL")
if err != nil {
log.Fatal(err)
}

for _, a := range articles {
fmt.Printf("%s %s\n", a.PublicationDate.Format("2006-01-02"), a.Headline)
fmt.Printf(" %s\n", a.Source)
}
}

Output

2024-01-25 Apple Reports Record Q1 Earnings
https://www.reuters.com/technology/...
2024-01-24 Apple Unveils New Product Lineup
https://www.bloomberg.com/...

Date Windows​

stocks.WithNewsWindow takes a DateWindow — the same sealed-union value used by Candles and Earnings. Build one with exactly one constructor:

ConstructorSelectsAPI parameters
stocks.OnDate(d)a single calendar daydate=d
stocks.Between(from, to)an explicit closed range (inclusive)from=from&to=to
stocks.Since(from)everything from a day onwardfrom=from
stocks.Until(to)up to and including a dayto=to
stocks.LastN(n)the n most recent articlescountback=n
stocks.LastNUntil(n, to)the n articles ending at a daycountback=n&to=to

NewsArticle​

type NewsArticle struct {
Symbol string `json:"symbol"` // Stock ticker symbol
Headline string `json:"headline"` // Article headline
Content string `json:"content"` // Article content (may be partial)
Source string `json:"source"` // URL where the article was published
PublicationDate time.Time `json:"publicationDate"` // When the article was published (US Eastern)
}

Represents a single news article about a stock. Timestamps are normalized to US Eastern time.

Fields​

  • Symbol — the stock ticker symbol the article relates to.
  • Headline — the article headline/title.
  • Content — the article content, which may be partial and may include captions or copyright notices.
  • Source — the URL where the article was published.
  • PublicationDate — when the article was published.

Helper Methods​

  • String() string — a one-line summary of the article.