tiingo

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2024 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"

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

func main() { 
    // Initialize client
    client := tiingo.NewClient(os.Getenv("YOUR_TIINGO_TOKEN"))

    // You can optionally set a rate limiter, enable logging, and change the
    // default http client
    client.RateLimiter = rate.NewLimiter(10, 1)
    client.Logger = slog.New(slog.NewTextHandler(os.Stdout, nil))
    client.HttpClient = &http.Client{}

    // Make request
    rawBytes, err := client.DefaultEodMetadata(context.Background(), "AAPL")
    if err != nil {
        panic(err)
    }

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

    fmt.Println("Apple's metadata:", metadata)
}
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", tiingo.JSON)

    // 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
    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.

Initially, the plan was to implement custom csv marshalling/unmarshalling to minimize dependencies. However, the vast quantity of types made compromising with an external dependency a lot more attractive in terms of the overall maintenance overhead.

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"

	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 = "enterpriseValue"
	EntValDesc      Sort = "-enterpriseValue"
	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 DailyFundamentalUrl

func DailyFundamentalUrl(ticker string, startDate, endDate time.Time, sort Sort, respFormat Format) string

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

Any zero value arguments will be left off the query string.

func EodMetadataUrl

func EodMetadataUrl(ticker string, respFormat Format) 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, startDate, endDate time.Time, resampleFreq EodFreq,
	sort Sort, respFormat Format, columns []string) 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.

Any zero value arguments will be left off the query string.

func FundamentalMetadataUrl

func FundamentalMetadataUrl(tickers []string, respFormat Format) string

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

Any zero value arguments will be left off the query string.

func IexHistoryUrl

func IexHistoryUrl(ticker string, startDate, endDate time.Time, resampleFreq IexFreq,
	afterHours, forceFill bool, respFormat Format) string

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

Any zero value arguments will be left off the query string.

func IexTopOfBookUrl

func IexTopOfBookUrl(tickers []string, respFormat Format) string

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

Any zero value arguments will be left off the query string.

func SearchUrl

func SearchUrl(query string, exactTickerMatch, includeDelisted bool, limit int,
	respFormat Format, columns []string) string

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

Any zero value arguments will be left off the query string.

func StmtDataUrl

func StmtDataUrl(ticker string, asReported bool, startDate, endDate time.Time,
	sort Sort, respFormat Format) string

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

Any zero value arguments will be left off the query string.

func StmtDefsUrl

func StmtDefsUrl(tickers []string, respFormat Format) string

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

Any zero value arguments will be left off the query string.

Types

type Client

type Client struct {
	HttpClient  *http.Client // default client that all tiingo requests are routed through
	RateLimiter Limiter      // 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 an options func that will be applied to the returned Client.

func (*Client) DailyFundamental

func (c *Client) DailyFundamental(ctx context.Context, ticker string,
	startDate, endDate time.Time, sort Sort, respFormat Format) ([]byte, 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) DefaultDailyFundamental added in v1.0.0

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

DefaultDailyFundamental returns the statement values response data for the given ticker from the [Fundamentals].2.6.4 daily Data Endpoint.

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

func (*Client) DefaultEodMetadata added in v1.0.0

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

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

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

func (*Client) DefaultEodPrice added in v1.0.0

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

DefaultEodPrice returns the daily price response data for the given ticker from the [End-of-Day].2.1.2 End-of-Day Endpoint.

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

func (*Client) DefaultFundamentalMetadata added in v1.0.0

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

DefaultFundamentalMetadata returns the statement values response data for the all tickers from the [Fundamentals].2.6.5 MetaData Endpoint.

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

func (*Client) DefaultIexHistory added in v1.0.0

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

DefaultIexHistory returns the intraday price response for the given ticker from the [IEX].2.5.3 Historical Intraday Prices Endpoint.

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

func (*Client) DefaultIexTopOfBook added in v1.0.0

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

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

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

func (*Client) DefaultSearch added in v1.0.0

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

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

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

func (*Client) DefaultStmtData added in v1.0.0

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

DefaultStmtData returns the statement values response data for the given ticker from the [Fundamentals].2.6.3 Statement Data Endpoint.

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

func (*Client) DefaultStmtDefs added in v1.0.0

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

DefaultStmtDefs returns the statement definition response data from the [Fundamentals].2.6.2 Definitions Data Endpoint.

Only the required params are added to the url & query string, everything else will be the Tiingo defaults.

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, respFormat Format) ([]byte, error)

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

func (*Client) EodPrice

func (c *Client) EodPrice(ctx context.Context, ticker string, startDate, endDate time.Time,
	resampleFreq EodFreq, sort Sort, respFormat Format, columns []string) ([]byte, 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.

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) 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, tickers []string, respFormat Format) ([]byte, error)

FundamentalMetadata returns the daily fundamental metadata for the given ticker(s) with the provided params from the [Fundamentals].2.6.5 MetaData 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) IexHistory

func (c *Client) IexHistory(ctx context.Context, ticker string, startDate, endDate time.Time,
	resampleFreq IexFreq, afterHours, forceFill bool, respFormat Format) ([]byte, 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.

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) IexTopOfBook

func (c *Client) IexTopOfBook(ctx context.Context, tickers []string, respFormat Format) ([]byte, error)

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

Any zero value arguments will be left off the query string.

func (*Client) Search

func (c *Client) Search(ctx context.Context, query string, exactMatch, includeDelisted bool,
	limit int, respFormat Format, columns []string) ([]byte, error)

Search returns the search result response for a given query from the [Utility].4.1.2 Search 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) StmtData added in v1.0.0

func (c *Client) StmtData(ctx context.Context, ticker string, asReported bool,
	startDate, endDate time.Time, sort Sort, respFormat Format) ([]byte, error)

StmtData returns the statement values response data for the given ticker with the provided params from the [Fundamentals].2.6.3 Statement 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) StmtDefs

func (c *Client) StmtDefs(ctx context.Context, tickers []string, respFormat Format) ([]byte, error)

StmtDefs returns the statement definition response data with the provided params from the [Fundamentals].2.6.2 Definitions 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.

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 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 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 IexFreq

type IexFreq = string

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

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

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 Limiter added in v1.0.0

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

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 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 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