params

package
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package params holds canonical, internal representations of Market Data API request parameters that are shared across resource packages. Its central type, Window, models the API's mutually-exclusive date-selection parameters (date / from / to / countback). Public resource packages wrap Window in their own sealed union types so that a caller can only ever express one valid date mode, making illegal combinations impossible to write. Window's fields are unexported and it can only be built through the constructors here, so the exclusivity rules cannot be bypassed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Window

type Window struct {
	// contains filtered or unexported fields
}

Window is the canonical, validated representation of the API's date-window parameters. Construct it only with the mode constructors (OnDate, Between, Since, Until, LastN, LastNUntil); the zero value is a valid "no date parameters" window.

func Between

func Between(from, to time.Time) Window

Between selects an explicit closed date range (from= & to=).

func LastN

func LastN(n int) Window

LastN selects the n most recent periods (countback=).

func LastNUntil

func LastNUntil(n int, to time.Time) Window

LastNUntil selects the n periods ending at to (countback= & to=).

func OnDate

func OnDate(d time.Time) Window

OnDate selects a single calendar date (date=). Time-of-day is ignored.

func Since

func Since(from time.Time) Window

Since selects an open-ended range starting at from (from=), letting the API default the end to the most recent period.

func Until

func Until(to time.Time) Window

Until selects a range ending at to (to=), letting the API default the count.

func (Window) AnchorCountback

func (w Window) AnchorCountback(to time.Time) Window

AnchorCountback returns the window unchanged unless it is a bare countback (KindCountback), in which case it returns the equivalent countback-ending-at-to window. It lets an endpoint pin the "n most recent periods" semantics with an explicit to= anchor on endpoints where the API silently ignores a countback that arrives without one.

func (Window) Apply

func (w Window) Apply(v url.Values)

Apply writes the window's parameters into v using the API's calendar-date format. It assumes the window has already passed Window.Validate.

func (Window) Chunk

func (w Window) Chunk(from, to time.Time) Window

Chunk derives a from/to sub-window bounded by the given dates. It lets a caller split a large range into smaller concurrent requests without needing to name this package.

func (Window) Countback

func (w Window) Countback() int

func (Window) Date

func (w Window) Date() time.Time

func (Window) From

func (w Window) From() time.Time

From, To, Date, and Countback expose the underlying values for callers that need them (for example, the candle range-splitting logic in stocks).

func (Window) IsRange

func (w Window) IsRange() bool

IsRange reports whether the window is an explicit closed from/to range, the only mode eligible for the stocks candle range-splitting optimization.

func (Window) IsZero

func (w Window) IsZero() bool

IsZero reports whether the window sends no date parameters.

func (Window) Kind

func (w Window) Kind() WindowKind

Kind reports which date mode the window carries.

func (Window) To

func (w Window) To() time.Time

func (Window) Validate

func (w Window) Validate() error

Validate checks the window's values before any request is built. It enforces the value-range rules that cannot be encoded in the type system: countback must be positive, dates present for their mode must be non-zero, and an explicit from must not be after to. It returns a sdkerrors.ValidationError on failure so callers can reject the request pre-network.

type WindowKind

type WindowKind uint8

WindowKind identifies which mutually-exclusive date mode a Window carries.

const (
	// KindNone is the zero Window: no date parameters are sent.
	KindNone WindowKind = iota
	// KindDate is a single calendar date (date=).
	KindDate
	// KindFromTo is an explicit closed range (from= & to=).
	KindFromTo
	// KindFrom is an open-ended range starting at from (from=).
	KindFrom
	// KindTo is a range ending at to (to=).
	KindTo
	// KindCountback is a fixed number of the most recent periods (countback=).
	KindCountback
	// KindCountbackTo is a fixed number of periods ending at to (countback= & to=).
	KindCountbackTo
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL