Documentation
¶
Overview ¶
Package markets provides market status information from the Market Data API's /v1/markets/status/ endpoint. It reports whether a market was open, closed, or closed early on a given trading day. Service.Status answers the question for a single date (today by default), while Service.StatusHistory returns a MarketStatus for each day in a date range.
The two methods take separate, sealed option families so that a method-specific parameter cannot be passed to the wrong method: Status takes StatusOption values (WithDate, WithCountry) and StatusHistory takes HistoryOption values (WithHistoryWindow, WithCountry). The history range is a single HistoryWindow value built with Between, Since, Until, LastN, or LastNUntil, so the API's mutually-exclusive range parameters can never be combined by mistake. WithCountry applies to both methods.
See https://www.marketdata.app/docs/api/markets/status for the endpoint's API documentation.
Index ¶
- type CSVService
- type CountryOption
- type HistoryOption
- type HistoryWindow
- type MarketStatus
- type Service
- func (s *Service) AsCSV() *CSVService
- func (s *Service) GetStatus(opts ...StatusOption) (*MarketStatus, error)
- func (s *Service) GetStatusHistory(opts ...HistoryOption) ([]MarketStatus, error)
- func (s *Service) Status(ctx context.Context, opts ...StatusOption) (*MarketStatus, *response.Response, error)
- func (s *Service) StatusHistory(ctx context.Context, opts ...HistoryOption) ([]MarketStatus, *response.Response, error)
- type StatusOption
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CSVService ¶
type CSVService struct {
// contains filtered or unexported fields
}
CSVService is the CSV facet of markets, reached through Service.AsCSV. Service.Status returns a response.CSVResponse carrying the API's raw CSV text — see ADR-018. Service.StatusHistory has no CSV facet.
func (*CSVService) Status ¶
func (s *CSVService) Status(ctx context.Context, opts ...StatusOption) (*response.CSVResponse, error)
Status fetches the market status for a single day as CSV. See Service.Status for parameter details.
type CountryOption ¶
type CountryOption struct {
// contains filtered or unexported fields
}
CountryOption is the option returned by WithCountry. It satisfies both StatusOption and HistoryOption, which is why a single WithCountry call can be passed to either Service.Status or Service.StatusHistory. It is exported only so that its dual role has a name; construct it with WithCountry rather than as a literal.
func WithCountry ¶
func WithCountry(country string) CountryOption
WithCountry selects which country's market to query, using a two-letter ISO 3166-1 alpha-2 code such as "US". An empty string leaves the parameter unset and the API defaults to the United States. The returned CountryOption satisfies both StatusOption and HistoryOption, so WithCountry applies to both Service.Status and Service.StatusHistory.
type HistoryOption ¶
type HistoryOption interface {
// contains filtered or unexported methods
}
HistoryOption is a functional option for Service.StatusHistory, which reports the market status for each day in a range. Options are applied in the order given, so a later option overrides an earlier one that sets the same parameter. Create options with WithHistoryWindow (the date range) and WithCountry. HistoryOption is a sealed interface: only this package can implement it, and its range is a single HistoryWindow value, so the single-date parameter used by Service.Status cannot be passed here by mistake.
func WithHistoryWindow ¶
func WithHistoryWindow(w HistoryWindow) HistoryOption
WithHistoryWindow sets the date range for Service.StatusHistory as a single HistoryWindow value (for example markets.Between(from, to) or markets.LastN(5)). Omitting it lets the API return its default recent range. WithHistoryWindow is a StatusHistory-only option: it cannot be passed to Service.Status, whose single day is selected with WithDate.
type HistoryWindow ¶
type HistoryWindow interface {
// contains filtered or unexported methods
}
HistoryWindow selects the date range for Service.StatusHistory. It is a sealed union: build it with exactly one of the mode constructors below. Because a HistoryWindow is a single value, the API's mutually-exclusive range parameters (from, to, countback) can never be combined by mistake — an illegal pairing such as "from plus countback" is not expressible.
The constructors mirror the ways the status-history endpoint accepts a range:
Between(from, to) // an explicit closed range -> from=from&to=to Since(from) // everything since a day -> from=from Until(to) // up to and including a day -> to=to LastN(n) // the n most recent days -> countback=n LastNUntil(n, to) // the n days ending at a day -> countback=n&to=to
There is deliberately no single-date mode here: a single calendar day is a Service.Status concept, selected with WithDate. Only the calendar date of each time.Time is used; the time-of-day and zone are ignored.
func Between ¶
func Between(from, to time.Time) HistoryWindow
Between selects an explicit closed date range from..to (inclusive).
func LastN ¶
func LastN(n int) HistoryWindow
LastN selects the n most recent days (the API's countback parameter).
This endpoint returns n+1 rows, consistently at every n — verified live 2026-08-20 with countback 1, 2, 3, 5 and 10 returning 2, 3, 4, 6 and 11, with and without a to anchor. Every other endpoint's countback is exact. The SDK does not compensate: it already adjusts for two sibling countback defects, but in both of those the API IGNORES the parameter, whereas here it honors it with an off-by-one — so subtracting one would break silently the day the API is corrected. Tracked in integration/discrepancy_test.go; slice the result if you need exactly n.
func LastNUntil ¶
func LastNUntil(n int, to time.Time) HistoryWindow
LastNUntil selects the n days ending at the given day.
func Since ¶
func Since(from time.Time) HistoryWindow
Since selects everything from the given day onward, letting the API default the end of the range to the most recent day.
func Until ¶
func Until(to time.Time) HistoryWindow
Until selects data up to and including the given day.
type MarketStatus ¶
type MarketStatus struct {
// Date is the date of this status
Date time.Time `json:"date"`
// Open indicates if the market was/is open on this date
Open bool `json:"open"`
// Status is the API's status string: "open" or "closed" (early-close
// days are reported as "open"). It is empty for days outside the
// calendar's coverage.
Status string `json:"status"`
}
MarketStatus represents the status of the market on a given day.
func (*MarketStatus) IsClosed ¶
func (m *MarketStatus) IsClosed() bool
IsClosed reports whether this is a closed market day (Status == "closed"). A day outside the calendar's coverage carries an empty Status and is neither open nor closed: IsOpen and IsClosed both return false then.
func (*MarketStatus) IsOpen ¶
func (m *MarketStatus) IsOpen() bool
IsOpen reports whether this is an open market day (Status == "open"). Early-close days count as open: the API's status vocabulary is strictly "open"/"closed", and shortened sessions are reported as "open".
func (MarketStatus) String ¶
func (m MarketStatus) String() string
String returns a summary of the market status.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides methods for accessing market status data.
func NewService ¶
NewService creates a new markets service.
func (*Service) AsCSV ¶
func (s *Service) AsCSV() *CSVService
AsCSV returns the CSV facet of this service.
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/MarketDataApp/sdk-go/v2/marketdata"
)
func main() {
client, err := marketdata.NewClient()
if err != nil {
log.Fatal(err)
}
defer func() { _ = client.Close() }()
csv, err := client.Markets.AsCSV().Status(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Print(csv.CSV())
}
Output:
func (*Service) GetStatus ¶
func (s *Service) GetStatus(opts ...StatusOption) (*MarketStatus, error)
GetStatus is a convenience wrapper around Service.Status that uses context.Background() and discards the response metadata. It accepts the same functional options and has the same no-data behavior: when the API returns 404 for the requested date, GetStatus returns a nil MarketStatus and a nil error. Use Status directly when you need request cancellation, deadlines, or access to the Response.
API documentation: https://www.marketdata.app/docs/api/markets/status
Example ¶
package main
import (
"fmt"
"log"
"time"
"github.com/MarketDataApp/sdk-go/v2/marketdata"
"github.com/MarketDataApp/sdk-go/v2/marketdata/markets"
)
func main() {
client, err := marketdata.NewClient()
if err != nil {
log.Fatal(err)
}
defer func() { _ = client.Close() }()
status, err := client.Markets.GetStatus(markets.WithDate(time.Date(2024, time.July, 4, 0, 0, 0, 0, time.UTC)))
if err != nil {
log.Fatal(err)
}
fmt.Println(status)
}
Output:
func (*Service) GetStatusHistory ¶
func (s *Service) GetStatusHistory(opts ...HistoryOption) ([]MarketStatus, error)
GetStatusHistory is a convenience wrapper for Service.StatusHistory that uses context.Background and discards the per-request response.Response. Because the response metadata is discarded, a 404 no-data result is returned as a nil slice with a nil error. Use StatusHistory directly when you need request cancellation, deadlines, or access to the Response.
API documentation: https://www.marketdata.app/docs/api/markets/status
func (*Service) Status ¶
func (s *Service) Status(ctx context.Context, opts ...StatusOption) (*MarketStatus, *response.Response, error)
Status fetches the market status for a single day from the /v1/markets/status/ endpoint. With no options it reports today's status for the United States; use WithDate to query a different day and WithCountry to query a different country by its two-letter ISO code. The date is sent to the API in YYYY-MM-DD form, so any time-of-day component is ignored. Status accepts only single-day StatusOption values; for a range of days, use Service.StatusHistory with WithHistoryWindow.
The returned MarketStatus carries the date (normalized to US Eastern), the raw status string, and an Open flag derived from it. When the API responds 404 because no status exists for the requested date, Status returns a nil MarketStatus and a nil error; the returned Response has its NoData field set to true.
API documentation: https://www.marketdata.app/docs/api/markets/status
Example:
status, _, err := client.Markets.Status(ctx)
if err != nil {
log.Fatal(err)
}
if status != nil && status.Open {
fmt.Println("Market is open!")
}
Example ¶
package main
import (
"context"
"fmt"
"log"
"github.com/MarketDataApp/sdk-go/v2/marketdata"
"github.com/MarketDataApp/sdk-go/v2/marketdata/markets"
)
func main() {
client, err := marketdata.NewClient()
if err != nil {
log.Fatal(err)
}
defer func() { _ = client.Close() }()
status, _, err := client.Markets.Status(context.Background(),
markets.WithCountry("US"),
)
if err != nil {
log.Fatal(err)
}
fmt.Println(status)
}
Output:
func (*Service) StatusHistory ¶
func (s *Service) StatusHistory(ctx context.Context, opts ...HistoryOption) ([]MarketStatus, *response.Response, error)
StatusHistory fetches the market status for a range of days from the /v1/markets/status/ endpoint, returning one MarketStatus per day. Select the range with WithHistoryWindow using a single HistoryWindow value, for example markets.Between(startDate, endDate) or markets.LastN(5) to request a fixed number of days counting back from the end of the range. WithCountry chooses the market by its two-letter ISO code, defaulting to the United States. Dates are sent to the API in YYYY-MM-DD form, so any time-of-day component is ignored. StatusHistory accepts only range HistoryOption values; for a single day, use Service.Status with WithDate.
When the API responds 404 because no data exists for the requested range, StatusHistory returns a nil slice and a nil error; the returned Response has its NoData field set to true.
API documentation: https://www.marketdata.app/docs/api/markets/status
Example:
statuses, _, err := client.Markets.StatusHistory(ctx,
markets.WithHistoryWindow(markets.Between(startDate, endDate)),
)
Example ¶
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/MarketDataApp/sdk-go/v2/marketdata"
"github.com/MarketDataApp/sdk-go/v2/marketdata/markets"
)
func main() {
client, err := marketdata.NewClient()
if err != nil {
log.Fatal(err)
}
defer func() { _ = client.Close() }()
statuses, _, err := client.Markets.StatusHistory(context.Background(),
markets.WithHistoryWindow(markets.Between(
time.Date(2024, time.December, 1, 0, 0, 0, 0, time.UTC),
time.Date(2024, time.December, 31, 0, 0, 0, 0, time.UTC),
)),
markets.WithCountry("US"),
)
if err != nil {
log.Fatal(err)
}
for _, status := range statuses {
fmt.Println(status)
}
}
Output:
type StatusOption ¶
type StatusOption interface {
// contains filtered or unexported methods
}
StatusOption is a functional option for Service.Status and Service.GetStatus, which report the market status for a single day. Options are applied in the order given, so a later option overrides an earlier one that sets the same parameter. Create options with WithDate (single calendar day) and WithCountry. StatusOption is a sealed interface: only this package can implement it, and its date parameter is a single day, so the range parameters used by Service.StatusHistory cannot be passed here by mistake.
func WithDate ¶
func WithDate(d time.Time) StatusOption
WithDate sets the specific day whose market status is requested by Service.Status. The date is sent to the API in YYYY-MM-DD form, so any time-of-day component of d is ignored; a zero time leaves the parameter unset and the API reports today's status. WithDate is a Status-only option: it cannot be passed to Service.StatusHistory, whose date range is selected with WithHistoryWindow.