tiingo

package module
v0.0.0-...-044f420 Latest Latest
Warning

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

Go to latest
Published: May 26, 2026 License: MIT Imports: 15 Imported by: 0

README

Golang Tiingo Client

Full-featured Tiingo client that offers CSV and JSON unmarshalling from Tiingo to Golang types.

Installation

go get github.com/the-trader-dev/tiin-go

Usage

Maximum flexibility is offered with three primary ways to use tiin-go:

  1. As a Tiingo frontend client
  2. As a url builder
  3. Steal the types
Tiingo Frontend Client

Using tiin-go as a frontend client for the Tiingo api is the simplest way to use this package. It offers a few advantages over just using the query building & type capabilities:

  1. Centralized rate limiting
  2. Automatic authentication
  3. Request logging
  4. Automatic response body lifecycle management
package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log/slog"
	"net/http"
	"os"
	"time"

	tiingo "github.com/the-trader-dev/tiin-go"
	"golang.org/x/time/rate"
)

func main() {
	ctx := context.Background()

	// Initialize client
	c := tiingo.NewClient(os.Getenv("YOUR_TIINGO_TOKEN"),
		// You can optionally set a rate limiter, enable logging, and change the
		// default http client
		tiingo.WithLogger(slog.Default()),
		tiingo.WithHttpClient(&http.Client{}),
		tiingo.WithRateLimiter(rate.NewLimiter(10, 1)),
	)

	// Get typed data with whatever the Tiingo default params are
	fiveMinuteCandles, err := c.IexHistory(ctx, "AAPL", nil)
	if err != nil {
		panic(err)
	}

	// Get typed data with custom params
	oneMinuteCandles, err := c.IexHistory(ctx, "AAPL", &tiingo.IexHistoryParams{
		StartDate:    time.Date(2024, 01, 02, 14, 30, 0, 0, time.UTC),
		EndDate:      time.Date(2024, 01, 02, 15, 00, 0, 0, time.UTC),
		ResampleFreq: tiingo.OneMin,
		AfterHours:   false,
		ForceFill:    true,
		RespFormat:   tiingo.CSV,
	})
	if err != nil {
		panic(err)
	}

	// Or get the raw bytes and store/handle yourself
	rawJsonBytes, err := c.IexHistoryRaw(ctx, "AAPL", &tiingo.IexHistoryParams{
		StartDate:    time.Date(2024, 01, 02, 14, 30, 0, 0, time.UTC),
		EndDate:      time.Date(2024, 01, 02, 15, 00, 0, 0, time.UTC),
		ResampleFreq: tiingo.FifteenMin,
	})
	if err != nil {
		panic(err)
	}
	var fifteenMinuteCandles []tiingo.IexPrice
	if err = json.Unmarshal(rawJsonBytes, &fiveMinuteCandles); err != nil {
		panic(err)
	}

	fmt.Println("One minute candles:", oneMinuteCandles)
	fmt.Println("Five minute candles:", fiveMinuteCandles)
	fmt.Println("Fifteen minute candles:", fifteenMinuteCandles)
}

URL Builder

Using tiin-go purely as a url builder offers the best balance of control & ease. You pass in the wanted parameters into the given url function and the valid corresponding url is returned. You then do the actual request however you want. Once the request is made, you can then unmarshal the response into one of the predefined types.

NOTE: no token query param is added, you must handle authentication yourself

package main

import (
    "encoding/json"
    "fmt"
    "io"
    "net/http"

    tiingo "github.com/the-trader-dev/tiin-go"
)

func main() {
    // Build url
    url := tiingo.EodMetadataUrl("AAPL")

    // Build request
    req, err := http.NewRequest(http.MethodGet, url, nil)
    if err != nil {
        panic(err)
    }

    // Add auth
    req.Header.Set("Authorization", "Token {your_token}")

    // Make request
    resp, err := http.DefaultClient.Do(req)
    if err != nil {
        panic(err)
    }
    defer func() {
        if err = resp.Body.Close(); err != nil {
            panic(err)
        }
    }()

    // Read body
    rawBytes, err := io.ReadAll(resp.Body)
    if err != nil {
        panic(err)
    }

    // Unmarshal
    var metadata tiingo.EodMetadata
    if err = json.Unmarshal(rawBytes, &metadata); err != nil {
        panic(err)
    }

    fmt.Println("Apple's metadata:", metadata)
}
Steal the types

This usage pattern offers the most control. You handle the entire request lifecycle and simply steal the one-to-one matching Tiingo to Golang types for easier marshalling & unmarshalling.

package main

import (
    "encoding/json"
    "fmt"

    "github.com/gocarina/gocsv"
    tiingo "github.com/the-trader-dev/tiin-go"
)

func main() {
    // Raw bytes from some endpoint you requested yourself
    var jsonBytes []byte
    var csvBytes []byte

    // Unmarshal
    var jsonPrices []tiingo.EodPrice
    if err := json.Unmarshal(jsonBytes, &jsonPrices); err != nil {
        panic(err)
    }
    var csvPrices []tiingo.EodPrice
    if err := gocsv.UnmarshalBytes(csvBytes, &csvPrices); err != nil {
        panic(err)
    }

    fmt.Println("prices from json:", jsonPrices)
    fmt.Println("prices from csv:", csvPrices)
}

Types

All implemented endpoints have corresponding Golang types that allow for automatic marshalling and unmarshalling both with CSV & JSON responses.

JSON

Any package that knows how to read json struct tags should be able to marshal/unmarshal successfully. However, it has only been tested with the standard library encoding/json package.

err := json.Unmarshal(rawJsonBytes, &TiingoGolangType)
CSV

Any package that knows how to read csv struct tags should be able to marshal/unmarshal successfully. However, it has only been tested with & internally uses with gocsv.

The use of gocsv is not set in stone. I do not like having dependencies just to have them. The goal is to have custom csv marshalling/unmarshalling at some point, however gocsv is a good alternative until then. If gocsv is ever removed, it will not be a breaking api change & csv tags will still be kept to keep some level of backwards compatability.

err := gocsv.UnmarshaBytes(rawCsvBytes, &TiingoGolangType)

API Surface

Complete

The following Tiingo endpoints have been implemented:

  • End-of-Day
  • IEX
  • Fundamentals
  • Search
Incomplete

The following Tiingo endpoints are not yet implemented:

  • Crypto
  • Forex
  • Fund Fees
  • Dividends
  • Splits

Contributions

Contributions are welcome!

All I ask is that if you implement any of the needed endpoints, follow the same pattern as the completed ones to keep the api consistent (url builder, client method, valid csv/json parsing)

Documentation

Index

Constants

View Source
const (
	JSON Format = "json"
	CSV  Format = "csv"

	Daily    EodFreq = "daily"
	Weekly   EodFreq = "weekly"
	Monthly  EodFreq = "monthly"
	Annually EodFreq = "annually"

	OneMin     IexFreq = "1min"
	FiveMin    IexFreq = "5min"
	FifteenMin IexFreq = "15min"
	ThirtyMin  IexFreq = "30min"
	OneHour    IexFreq = "1hour"
	TwoHour    IexFreq = "2hour"
	FourHour   IexFreq = "4hour"
	OneDay     IexFreq = "1day"

	DateAsc         Sort = "date"
	DateDesc        Sort = "-date"
	OpenAsc         Sort = "open"
	OpenDesc        Sort = "-open"
	HighAsc         Sort = "high"
	HighDesc        Sort = "-high"
	LowAsc          Sort = "low"
	LowDesc         Sort = "-low"
	CloseAsc        Sort = "close"
	CloseDesc       Sort = "-close"
	VolumeAsc       Sort = "volume"
	VolumeDesc      Sort = "-volume"
	AdjOpenAsc      Sort = "adjOpen"
	AdjOpenDesc     Sort = "-adjOpen"
	AdjHighAsc      Sort = "adjHigh"
	AdjHighDesc     Sort = "-adjHigh"
	AdjLowAsc       Sort = "adjLow"
	AdjLowDesc      Sort = "-adjLow"
	AdjCloseAsc     Sort = "adjClose"
	AdjCloseDesc    Sort = "-adjClose"
	AdjVolumeAsc    Sort = "adjVolume"
	AdjVolumeDesc   Sort = "-adjVolume"
	DivCashAsc      Sort = "divCash"
	DivCashDesc     Sort = "-divCash"
	SplitFactorAsc  Sort = "splitFactor"
	SplitFactorDesc Sort = "-splitFactor"
	MktCapAsc       Sort = "marketCap"
	MktCapDesc      Sort = "-marketCap"
	EntValAsc       Sort = "enterpriseVal"
	EntValDesc      Sort = "-enterpriseVal"
	PERatioAsc      Sort = "peRatio"
	PERatioDesc     Sort = "-peRatio"
	PBRatioAsc      Sort = "pbRatio"
	PBRatioDesc     Sort = "-pbRatio"
	TrailPEGAsc     Sort = "trailingPEG1Y"
	TrailPEGDesc    Sort = "-trailingPEG1Y"
)

Variables

This section is empty.

Functions

func CryptoMetadataUrl

func CryptoMetadataUrl(ticker []string) string

CryptoMetadataUrl returns a built url for the given ticker from the [Crypto].2.3.3 Meta Endpoint.

func CryptoPriceUrl

func CryptoPriceUrl(ticker []string, queryParams *CryptoPriceParams) string

CryptoPriceUrl returns a built url for the given ticker with the provided params from the [Crypto].2.3.2 Endpoint Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func DailyFundamentalUrl

func DailyFundamentalUrl(ticker string, queryParams *DailyFundamentalParams) string

DailyFundamentalUrl returns a built url for with the provided params from the [Fundamentals].2.6.4 daily Data Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func EodMetadataUrl

func EodMetadataUrl(ticker string) string

EodMetadataUrl returns a built url for the given ticker from the [End-of-Day].2.1.3 Meta Endpoint.

func EodPriceUrl

func EodPriceUrl(ticker string, queryParams *EodPriceParams) string

EodPriceUrl returns a built url for the given ticker with the provided params from the [End-of-Day].2.1.2 End-of-Day Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func FundamentalMetadataUrl

func FundamentalMetadataUrl(queryParams *FundamentalMetadataParams) string

FundamentalMetadataUrl returns a built url for with the provided params from the [Fundamentals].2.6.5 MetaData Endpoint

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func IexHistoryUrl

func IexHistoryUrl(ticker string, queryParams *IexHistoryParams) string

IexHistoryUrl returns a built url for the given ticker with the provided params from the [IEX].2.5.3 Historical Intraday Prices Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func IexTopOfBookUrl

func IexTopOfBookUrl(queryParams *IexTopOfBookParams) string

IexTopOfBookUrl returns a built url for the given tickers from the [IEX].2.5.2 Top-of-Book & Last Price Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func Parse

func Parse[T any](rawBytes []byte, format Format) (T, error)

Parse takes in raw bytes and parses them according to the format. Valid formats are CSV or JSON (an empty string defaults to JSON).

func SearchUrl

func SearchUrl(query string, queryParams *SearchParams) string

SearchUrl returns a built url for the given query from the [Utility].4.1.2 Search Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func StmtDataUrl

func StmtDataUrl(ticker string, queryParams *StmtDataParams) string

StmtDataUrl returns a built url for with the provided params from the [Fundamentals].2.6.3 Statement Data Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func StmtDefsUrl

func StmtDefsUrl(queryParams *StmtDefsParams) string

StmtDefsUrl returns a built url for with the provided params from the [Fundamentals].2.6.2 Definitions Data Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func WithHttpClient

func WithHttpClient(client *http.Client) func(*Client)

WithHttpClient sets the *Client's *http.Client's all requests get routed through as provided client.

func WithLogger

func WithLogger(l *slog.Logger) func(*Client)

WithLogger sets the *Client's *slog.Logger as the provided logger.

func WithRateLimiter

func WithRateLimiter(l RateLimiter) func(*Client)

WithRateLimiter sets the *Client's RateLimiter as the provided limiter.

Types

type Client

type Client struct {
	HttpClient  *http.Client // default client that all tiingo requests are routed through
	RateLimiter RateLimiter  // rate limits request speed
	Logger      *slog.Logger // default logger
	// contains filtered or unexported fields
}

func NewClient

func NewClient(apiToken string, options ...func(*Client)) *Client

NewClient initializes a new Tiingo client.

Specific config options can be set by providing options funcs that will be applied to the new client. The following are already pre-defined:

  • WithRateLimiter
  • WithLogger
  • WithHttpClient

If no options are specified, these are the default options:

  • No RateLimiter
  • *slog.Logger that sends all logs to io.Discard
  • *http.DefaultClient

func (*Client) CryptoMetadata

func (c *Client) CryptoMetadata(ctx context.Context, ticker []string) (CryptoMetadata, error)

CryptoMetadata returns the eod metadata response data for a given ticker from the [Crypto].2.3.3 Meta Endpoint

func (*Client) CryptoMetadataRaw

func (c *Client) CryptoMetadataRaw(ctx context.Context, ticker []string) ([]byte, error)

CryptoMetadataRaw functions the same as CryptoMetadata, except the raw response bytes are returned instead of the parsed type.

func (*Client) CryptoPrice

func (c *Client) CryptoPrice(ctx context.Context, ticker []string,
	queryParams *CryptoPriceParams) ([]CryptoResult, error)

CryptoPrice returns the daily close price response data for a given ticker with the provided params from the [Crypto].2.3.2 Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) CryptoPriceRaw

func (c *Client) CryptoPriceRaw(ctx context.Context, ticker []string,
	queryParams *CryptoPriceParams) ([]byte, error)

CryptoPriceRaw functions the same as EodPrice, except the raw response bytes are returned instead of the parsed type.

func (*Client) DailyFundamental

func (c *Client) DailyFundamental(ctx context.Context, ticker string,
	queryParams *DailyFundamentalParams) ([]DailyFundamental, error)

DailyFundamental returns the daily fundamental response data for the given ticker with the provided params from the [Fundamentals].2.6.4 daily Data Endpoint.

Any zero value arguments will be left off the query string & whatever Tiingo's default for an empty query string will be returned.

func (*Client) DailyFundamentalRaw

func (c *Client) DailyFundamentalRaw(ctx context.Context, ticker string,
	queryParams *DailyFundamentalParams) ([]byte, error)

DailyFundamentalRaw functions the same as DailyFundamental, except the raw response bytes are returned instead of the parsed type.

func (*Client) DefaultSymbolList

func (c *Client) DefaultSymbolList(ctx context.Context) ([]byte, error)

DefaultSymbolList returns the full list of SymbolRespItem's from the [End-of-Day].2.1.3.supported_tickers.zip Endpoint

Note: This returns the raw zipped csv bytes from the endpoint, you must unzip before unmarshalling the csv bytes (or pass the raw bytes into FilteredSymbolList or ParseSymbolListCSV).

func (*Client) EodMetadata

func (c *Client) EodMetadata(ctx context.Context, ticker string) (EodMetadata, error)

EodMetadata returns the eod metadata response data for a given ticker from the [End-of-Day].2.1.3 Meta Endpoint

func (*Client) EodMetadataRaw

func (c *Client) EodMetadataRaw(ctx context.Context, ticker string) ([]byte, error)

EodMetadataRaw functions the same as EodMetadata, except the raw response bytes are returned instead of the parsed type.

func (*Client) EodPrice

func (c *Client) EodPrice(ctx context.Context, ticker string,
	queryParams *EodPriceParams) ([]EodPrice, error)

EodPrice returns the daily price response data for a given ticker with the provided params from the [End-of-Day].2.1.2 End-of-Day Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) EodPriceRaw

func (c *Client) EodPriceRaw(ctx context.Context, ticker string,
	queryParams *EodPriceParams) ([]byte, error)

EodPriceRaw functions the same as EodPrice, except the raw response bytes are returned instead of the parsed type.

func (*Client) FilteredSymbolList

func (c *Client) FilteredSymbolList(ctx context.Context, f SymbolFilterFunc) ([]SymbolItem, error)

FilteredSymbolList returns a filtered list of SymbolRespItem's from the [End-of-Day].2.1.3.supported_tickers.zip Endpoint

func (*Client) FundamentalMetadata

func (c *Client) FundamentalMetadata(ctx context.Context,
	queryParams *FundamentalMetadataParams) ([]FundamentalMetadata, error)

FundamentalMetadata returns the daily fundamental metadata for the given ticker(s) with the provided params from the [Fundamentals].2.6.5 MetaData Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) FundamentalMetadataRaw

func (c *Client) FundamentalMetadataRaw(ctx context.Context,
	queryParams *FundamentalMetadataParams) ([]byte, error)

FundamentalMetadataRaw functions the same as FundamentalMetadata, except the raw response bytes are returned instead of the parsed type.

func (*Client) IexHistory

func (c *Client) IexHistory(ctx context.Context, ticker string, queryParams *IexHistoryParams) ([]IexPrice, error)

IexHistory returns the intraday price response data for a given ticker with the provided params from the [IEX].2.5.3 Historical Intraday Prices Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) IexHistoryRaw

func (c *Client) IexHistoryRaw(ctx context.Context, ticker string, queryParams *IexHistoryParams) ([]byte, error)

IexHistoryRaw functions the same as IexHistory, except the raw response bytes are returned instead of the parsed type.

func (*Client) IexTopOfBook

func (c *Client) IexTopOfBook(ctx context.Context, queryParams *IexTopOfBookParams) ([]IexTopOfBook, error)

IexTopOfBook returns the last price item for the specified tickers from the [IEX].2.5.2 Top-of-Book & Last Price Endpoints.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) IexTopOfBookRaw

func (c *Client) IexTopOfBookRaw(ctx context.Context, queryParams *IexTopOfBookParams) ([]byte, error)

IexTopOfBookRaw functions the same as IexTopOfBook, except the raw response bytes are returned instead of the parsed type.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, queryParams *SearchParams) ([]SearchResult, error)

Search returns the search result response for a given query from the [Utility].4.1.2 Search Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) SearchRaw

func (c *Client) SearchRaw(ctx context.Context, query string, queryParams *SearchParams) ([]byte, error)

SearchRaw functions the same as Search, except the raw response bytes are returned instead of the parsed type.

func (*Client) StmtDataFlat

func (c *Client) StmtDataFlat(ctx context.Context, ticker string,
	queryParams *StmtDataParams) ([]StmtDataFlat, error)

StmtDataFlat returns the statement values response data for the given ticker with the provided params from the [Fundamentals].2.6.3 Statement Data Endpoint.

A CSV response format must be used to get the flat data structure, if the provided StmtDataParams.RespFormat is not CSV, it will be changed to that.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) StmtDataNested

func (c *Client) StmtDataNested(ctx context.Context, ticker string,
	queryParams *StmtDataParams) ([]StmtDataNested, error)

StmtDataNested returns the statement values response data for the given ticker with the provided params from the [Fundamentals].2.6.3 Statement Data Endpoint.

A JSON response format must be used to get the nested data structure, if the provided StmtDataParams.RespFormat is not JSON, it will be changed to that.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) StmtDataRaw

func (c *Client) StmtDataRaw(ctx context.Context, ticker string,
	queryParams *StmtDataParams) ([]byte, error)

StmtDataRaw functions the same as StmtDataFlat and StmtDataNested, except the raw response bytes are returned instead of the parsed type.

func (*Client) StmtDefs

func (c *Client) StmtDefs(ctx context.Context, queryParams *StmtDefsParams) ([]StmtDef, error)

StmtDefs returns the statement definition response data with the provided params from the [Fundamentals].2.6.2 Definitions Data Endpoint.

If queryParams is non-nil, any non-zero struct values will be applied to the url. Zero value items will be left out and Tiingo defaults will be used. A nil queryParams results in all Tiingo defaults.

func (*Client) StmtDefsRaw

func (c *Client) StmtDefsRaw(ctx context.Context, queryParams *StmtDefsParams) ([]byte, error)

StmtDefsRaw functions the same as StmtDefs, except the raw response bytes are returned instead of the parsed type.

type CryptoMetadata

type CryptoMetadata struct {
	Ticker        string `json:"ticker,omitempty" csv:"ticker,omitempty"`
	BaseCurrency  string `json:"baseCurrency,omitempty" csv:"baseCurrency,omitempty"`
	QuoteCurrency string `json:"quoteCurrency,omitempty" csv:"quoteCurrency,omitempty"`
	Name          string `json:"name,omitempty" csv:"name,omitempty"`
	Description   string `json:"description,omitempty" csv:"description,omitempty"`
}

CryptoMetadata corresponds to the [Crypto].2.3.3 Meta Endpoint

type CryptoPriceParams

type CryptoPriceParams struct {
	Exchanges    []string
	StartDate    time.Time
	EndDate      time.Time
	ResampleFreq IexFreq
}

CrytoPriceParams represents the query parameters for the [Crypto].2.3.2 Endpoint

type CryptoResult

type CryptoResult struct {
	Ticker        string      `json:"ticker,omitempty"`
	BaseCurrency  string      `json:"baseCurrency,omitempty"`
	QuoteCurrency string      `json:"quoteCurrency,omitempty"`
	PriceData     []PriceData `json:"priceData,omitempty"`
}

CryptoResults corresponds to the [Crypto].2.3.2 Crypto Endpoint

type DailyFundamental

type DailyFundamental struct {
	Date                 time.Time `json:"date,omitempty" csv:"date,omitempty"`
	MarketCap            float64   `json:"marketCap,omitempty" csv:"marketCap,omitempty"`
	EnterpriseValue      float64   `json:"enterpriseVal,omitempty" csv:"enterpriseVal,omitempty"`
	PriceToEarningsRatio float64   `json:"peRatio,omitempty" csv:"peRatio,omitempty"`
	PriceToBookRatio     float64   `json:"pbRatio,omitempty" csv:"pbRatio,omitempty"`
	TrailingYearPEG      float64   `json:"trailingPEG1Y,omitempty" csv:"trailingPEG1Y,omitempty"`
}

DailyFundamental corresponds to the [Fundamentals].2.6.4 Daily Data Endpoint

func (*DailyFundamental) UnmarshalCSVWithFields

func (d *DailyFundamental) UnmarshalCSVWithFields(key, value string) error

type DailyFundamentalParams

type DailyFundamentalParams struct {
	StartDate  time.Time
	EndDate    time.Time
	Sort       Sort
	RespFormat Format
}

type EodFreq

type EodFreq = string

EodFreq is the eod price frequency requested. Possible predefined constants are:

  • Daily
  • Weekly
  • Monthly
  • Annually

type EodMetadata

type EodMetadata struct {
	Ticker       string    `json:"ticker,omitempty" csv:"ticker,omitempty"`
	Name         string    `json:"name,omitempty" csv:"name,omitempty"`
	ExchangeCode string    `json:"exchangeCode,omitempty" csv:"exchangeCode,omitempty"`
	Description  string    `json:"description,omitempty" csv:"description,omitempty"`
	StartDate    time.Time `json:"startDate,omitempty" csv:"startDate,omitempty"`
	EndDate      time.Time `json:"endDate,omitempty" csv:"endDate,omitempty"`
}

EodMetadata corresponds to the [End-of-Day].2.1.3 Meta Endpoint

func (*EodMetadata) UnmarshalCSVWithFields

func (e *EodMetadata) UnmarshalCSVWithFields(key, value string) error

func (*EodMetadata) UnmarshalJSON

func (e *EodMetadata) UnmarshalJSON(bytes []byte) error

type EodPrice

type EodPrice struct {
	Date        time.Time `json:"date,omitempty" csv:"date"`
	Open        float64   `json:"open,omitempty" csv:"open"`
	High        float64   `json:"high,omitempty" csv:"high"`
	Low         float64   `json:"low,omitempty" csv:"low"`
	Close       float64   `json:"close,omitempty" csv:"close"`
	Volume      int64     `json:"volume,omitempty" csv:"volume"`
	AdjOpen     float64   `json:"adjOpen,omitempty" csv:"adjOpen"`
	AdjHigh     float64   `json:"adjHigh,omitempty" csv:"adjHigh"`
	AdjLow      float64   `json:"adjLow,omitempty" csv:"adjLow"`
	AdjClose    float64   `json:"adjClose,omitempty" csv:"adjClose"`
	AdjVolume   int64     `json:"adjVolume,omitempty" csv:"adjVolume"`
	DivCash     float64   `json:"divCash,omitempty" csv:"divCash"`
	SplitFactor float64   `json:"splitFactor,omitempty" csv:"splitFactor"`
}

EodPrice corresponds to the [End-of-Day].2.1.2 End-of-Day Endpoint

func (*EodPrice) UnmarshalCSVWithFields

func (e *EodPrice) UnmarshalCSVWithFields(key, value string) error

type EodPriceParams

type EodPriceParams struct {
	StartDate    time.Time
	EndDate      time.Time
	ResampleFreq EodFreq
	Sort         Sort
	RespFormat   Format
	Columns      []string
}

EodPriceParams represents the query parameters for the [End-of-Day].2.1.2 End-of-Day Endpoint

type Format

type Format = string

Format is the respFormat the response is sent in. Possible predefined constants are:

  • CSV
  • JSON

type FundamentalMetadata

type FundamentalMetadata struct {
	PermaTicker             string    `json:"permaTicker,omitempty" csv:"permaTicker,omitempty"`
	Ticker                  string    `json:"ticker,omitempty" csv:"ticker,omitempty"`
	Name                    string    `json:"name,omitempty" csv:"name,omitempty"`
	IsActive                bool      `json:"isActive,omitempty" csv:"isActive,omitempty"`
	IsADR                   bool      `json:"isADR,omitempty" csv:"isADR,omitempty"`
	Sector                  string    `json:"sector,omitempty" csv:"sector,omitempty"`
	Industry                string    `json:"industry,omitempty" csv:"industry,omitempty"`
	SicCode                 int32     `json:"sicCode,omitempty" csv:"sicCode,omitempty"`
	SicSector               string    `json:"sicSector,omitempty" csv:"sicSector,omitempty"`
	SicIndustry             string    `json:"sicIndustry,omitempty" csv:"sicIndustry,omitempty"`
	ReportingCurrency       string    `json:"reportingCurrency,omitempty" csv:"reportingCurrency,omitempty"`
	Location                string    `json:"location,omitempty" csv:"location,omitempty"`
	CompanyWebsite          string    `json:"companyWebsite,omitempty" csv:"companyWebsite,omitempty"`
	SecFilingWebsite        string    `json:"secFilingWebsite,omitempty" csv:"secFilingWebsite,omitempty"`
	StatementLastUpdated    time.Time `json:"statementLastUpdated,omitempty" csv:"statementLastUpdated,omitempty"`
	DailyLastUpdated        time.Time `json:"dailyLastUpdated,omitempty" csv:"dailyLastUpdated,omitempty"`
	DataProviderPermaTicker string    `json:"dataProviderPermaTicker,omitempty" csv:"dataProviderPermaTicker,omitempty"`
}

FundamentalMetadata corresponds to the [Fundamentals].2.6.5 Meta Data Endpoint

func (*FundamentalMetadata) UnmarshalCSVWithFields

func (f *FundamentalMetadata) UnmarshalCSVWithFields(key, value string) error

type FundamentalMetadataParams

type FundamentalMetadataParams struct {
	Tickers    []string
	RespFormat Format
}

type IexFreq

type IexFreq = string

IexFreq is the IexHistory price frequency requested. Possible predefined constants are:

  • OneMin
  • FiveMin
  • FifteenMin
  • ThirtyMin
  • OneHour
  • TwoHour
  • FourHour

type IexHistoryParams

type IexHistoryParams struct {
	StartDate    time.Time
	EndDate      time.Time
	ResampleFreq IexFreq
	AfterHours   bool
	ForceFill    bool
	RespFormat   Format
}

type IexPrice

type IexPrice struct {
	Date   time.Time `json:"date,omitempty" csv:"date,omitempty"`
	Open   float64   `json:"open,omitempty" csv:"open,omitempty"`
	High   float64   `json:"high,omitempty" csv:"high,omitempty"`
	Low    float64   `json:"low,omitempty" csv:"low,omitempty"`
	Close  float64   `json:"close,omitempty" csv:"close,omitempty"`
	Volume int64     `json:"volume,omitempty" csv:"volume,omitempty"`
}

IexPrice corresponds to the [IEX].2.5.3 Historical Intraday Prices Endpoint

func (*IexPrice) UnmarshalCSVWithFields

func (i *IexPrice) UnmarshalCSVWithFields(key, value string) error

type IexTopOfBook

type IexTopOfBook struct {
	Ticker            string    `json:"ticker,omitempty" csv:"ticker,omitempty"`
	Timestamp         time.Time `json:"timestamp,omitempty" csv:"timestamp,omitempty"`
	QuoteTimestamp    time.Time `json:"quoteTimestamp,omitempty" csv:"quoteTimestamp,omitempty"`
	LastSaleTimestamp time.Time `json:"lastSaleTimestamp,omitempty" csv:"lastSaleTimestamp,omitempty"`
	Last              float64   `json:"last,omitempty" csv:"last,omitempty"`
	LastSize          int32     `json:"lastSize,omitempty" csv:"lastSize,omitempty"`
	TngoLast          float64   `json:"tngoLast,omitempty" csv:"tngoLast,omitempty"`
	PrevClose         float64   `json:"prevClose,omitempty" csv:"prevClose,omitempty"`
	Open              float64   `json:"open,omitempty" csv:"open,omitempty"`
	High              float64   `json:"high,omitempty" csv:"high,omitempty"`
	Low               float64   `json:"low,omitempty" csv:"low,omitempty"`
	Mid               float64   `json:"mid,omitempty" csv:"mid,omitempty"`
	Volume            int64     `json:"volume,omitempty" csv:"volume,omitempty"`
	BidSize           float64   `json:"bidSize,omitempty" csv:"bidSize,omitempty"`
	BidPrice          float64   `json:"bidPrice,omitempty" csv:"bidPrice,omitempty"`
	AskSize           float64   `json:"askSize,omitempty" csv:"askSize,omitempty"`
	AskPrice          float64   `json:"askPrice,omitempty" csv:"askPrice,omitempty"`
}

IexTopOfBook corresponds to the [IEX].2.5.2 Top-of-Book and Last Price Endpoints

func (*IexTopOfBook) UnmarshalCSVWithFields

func (i *IexTopOfBook) UnmarshalCSVWithFields(key, value string) error

func (*IexTopOfBook) UnmarshalJSON

func (i *IexTopOfBook) UnmarshalJSON(bytes []byte) error

type IexTopOfBookParams

type IexTopOfBookParams struct {
	Tickers    []string
	RespFormat Format
}

IexTopOfBookParams represents the query parameters for the [IEX].2.5.2 Top-of-Book & Last Price Endpoints

type PriceData

type PriceData struct {
	Date           time.Time `json:"date,omitempty"`
	Open           float64   `json:"open,omitempty"`
	High           float64   `json:"high,omitempty"`
	Low            float64   `json:"low,omitempty"`
	Close          float64   `json:"close,omitempty"`
	TradesDone     float64   `json:"tradesDone,omitempty"`
	Volume         float64   `json:"volume,omitempty"`
	VolumeNotional float64   `json:"volumeNotional,omitempty"`
}

PriceData corresponds to the [Crypto].2.3.2 priceData Response

type RateLimiter

type RateLimiter interface {
	Wait(ctx context.Context) error
}

RateLimiter rate limits requests. It takes in a context, that if canceled, will stop the current waiting and return an error. If the context is not canceled, and the limiting time is reached, the returned error should be nil.

NOTE: this most seamlessly integrates with a rate.Limiter.

type SearchParams

type SearchParams struct {
	ExactMatch      bool
	IncludeDelisted bool
	Limit           int
	RespFormat      Format
	Columns         []string
}

type SearchResult

type SearchResult struct {
	Ticker            string `json:"ticker,omitempty" csv:"ticker,omitempty"`
	Name              string `json:"name,omitempty" csv:"name,omitempty"`
	AssetType         string `json:"assetType,omitempty" csv:"assetType,omitempty"`
	IsActive          bool   `json:"isActive,omitempty" csv:"isActive,omitempty"`
	PermaTicker       string `json:"permaTicker,omitempty" csv:"permaTicker,omitempty"`
	OpenFIGIComposite string `json:"openFIGIComposite,omitempty" csv:"openFIGIComposite,omitempty"`
	CountryCode       string `json:"countryCode" csv:"countryCode"`
}

SearchResult corresponds to [Utility].4.1.2 Search Endpoint

type Sort

type Sort = string

Sort defines the sorting order of the response data. Possible predefined constants are:

  • DateAsc
  • DateDesc
  • OpenAsc
  • OpenDesc
  • HighAsc
  • HighDesc
  • LowAsc
  • LowDesc
  • CloseAsc
  • CloseDesc
  • VolumeAsc
  • VolumeDesc
  • AdjOpenAsc
  • AdjOpenDesc
  • AdjHighAsc
  • AdjHighDesc
  • AdjLowAsc
  • AdjLowDesc
  • AdjCloseAsc
  • AdjCloseDesc
  • AdjVolumeAsc
  • AdjVolumeDesc
  • DivCashAsc
  • DivCashDesc
  • SplitFactorAsc
  • SplitFactorDesc
  • MktCapAsc
  • MktCapDesc
  • EntValAsc
  • EntValDesc
  • PERatioAsc
  • PERatioDesc
  • PBRatioAsc
  • PBRatioDesc
  • TrailPEGAsc
  • TrailPEGDesc

type StmtDataField

type StmtDataField struct {
	DataCode string  `json:"dataCode,omitempty"`
	Value    float64 `json:"value,omitempty"`
}

StmtDataField corresponds to the [Fundamentals].2.6.3 Statement Data Endpoint statement data fields

type StmtDataFlat

type StmtDataFlat struct {
	Date          time.Time `json:"date" csv:"date"`
	Year          int       `json:"year" csv:"year"`
	Quarter       int       `json:"quarter" csv:"quarter"`
	StatementType string    `json:"statementType" csv:"statementType"`
	DataCode      string    `json:"dataCode" csv:"dataCode"`
	Value         float64   `json:"value" csv:"value"`
}

StmtDataFlat corresponds to the [Fundamentals].2.6.3 Statement Data Endpoint when a csv respFormat is requested

func (*StmtDataFlat) UnmarshalCSVWithFields

func (s *StmtDataFlat) UnmarshalCSVWithFields(key, value string) error

type StmtDataNested

type StmtDataNested struct {
	Date          time.Time `json:"date,omitempty"`
	Year          int32     `json:"year,omitempty"`
	Quarter       int32     `json:"quarter,omitempty"`
	StatementData struct {
		BalanceSheet    []StmtDataField
		IncomeStatement []StmtDataField
		CashFlow        []StmtDataField
		Overview        []StmtDataField
	}
}

StmtDataNested corresponds to the [Fundamentals].2.6.3 Statement Data Endpoint when a json respFormat is requested

func (*StmtDataNested) UnmarshalJSON

func (s *StmtDataNested) UnmarshalJSON(bytes []byte) error

type StmtDataParams

type StmtDataParams struct {
	AsReported bool
	StartDate  time.Time
	EndDate    time.Time
	Sort       Sort
	RespFormat Format
}

type StmtDef

type StmtDef struct {
	DataCode      string `json:"dataCode,omitempty" csv:"dataCode,omitempty"`
	Name          string `json:"name,omitempty" csv:"name,omitempty"`
	Description   string `json:"description,omitempty" csv:"description,omitempty"`
	StatementType string `json:"statementType,omitempty" csv:"statementType,omitempty"`
	Units         string `json:"units,omitempty" csv:"units,omitempty"`
}

StmtDef corresponds to the [Fundamentals].2.6.2 Definitions Data Endpoint

type StmtDefsParams

type StmtDefsParams struct {
	Tickers    []string
	RespFormat Format
}

type SymbolFilterFunc

type SymbolFilterFunc func(asset SymbolItem) bool

SymbolFilterFunc is a function that takes in a SymbolRespItem and returns a boolean for if that ticker item should be added to the overall ticker list. A value of nil will return every SymbolRespItem from the list.

Example: Only include NYSE & NASDAQ stocks that have a startDate & endDate date

func(asset SymbolRespItem) bool {
	if asset.Exchange != "NYSE" && asset.Exchange != "NASDAQ" {
		return false
	}
	if asset.AssetType != "stock" {
		return false
	}
	if asset.StartDate.IsZero() || asset.EndDate.IsZero() {
		return false
	}

	return true
}

type SymbolItem

type SymbolItem struct {
	Ticker        string    `json:"ticker,omitempty" csv:"ticker,omitempty"`
	Exchange      string    `json:"exchange,omitempty" csv:"exchange,omitempty"`
	AssetType     string    `json:"assetType,omitempty" csv:"assetType,omitempty"`
	PriceCurrency string    `json:"priceCurrency,omitempty" csv:"priceCurrency,omitempty"`
	StartDate     time.Time `json:"startDate,omitempty" csv:"startDate,omitempty"`
	EndDate       time.Time `json:"EndDate,omitempty" csv:"EndDate,omitempty"`
}

SymbolItem corresponds to [End-of-Day].2.1.3.supported_tickers.zip

func ParseSymbolListCSV

func ParseSymbolListCSV(rawData []byte) ([]SymbolItem, error)

ParseSymbolListCSV accepts the raw zipped csv bytes returned from the End-of-Day].2.1.3.supported_tickers.zip Endpoint and parses them into a list of the individual SymbolItem

func (*SymbolItem) UnmarshalCSVWithFields

func (s *SymbolItem) UnmarshalCSVWithFields(key, value string) error

Jump to

Keyboard shortcuts

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