twelvedata

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 14, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package twelvedata exposes the Twelve Data financial API as a kit Domain: a driver that a multi-domain host (ant) enables with a single blank import,

import _ "github.com/tamnd/twelvedata-cli/twelvedata"

exactly as a database/sql program enables a driver with `import _ "github.com/lib/pq"`. The init below registers it; the host then dereferences twelvedata:// URIs by routing to the operations Register installs. The same Domain also builds the standalone twelvedata binary, so the binary and a host share one source of truth.

Package twelvedata is the library behind the twelvedata command line: the HTTP client, request shaping, and typed data models for the Twelve Data financial market API at https://api.twelvedata.com.

The API requires an API key appended as ?apikey={key} to every request. The "demo" key works for basic endpoints with limited symbols. Register a free key at https://twelvedata.com/pricing for broader access.

Index

Constants

View Source
const DefaultUserAgent = "twelvedata-cli/0.1 (tamnd87@gmail.com)"

DefaultUserAgent identifies the client to the API.

View Source
const Host = "api.twelvedata.com"

Host is the Twelve Data API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bar

type Bar struct {
	Datetime string `kit:"id" json:"datetime"`
	Open     string `json:"open"`
	High     string `json:"high"`
	Low      string `json:"low"`
	Close    string `json:"close"`
	Volume   string `json:"volume"`
}

Bar is one OHLCV candle in a time series.

type Client

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

Client is the Twelve Data HTTP client.

func NewClient

func NewClient(cfg Config) *Client

NewClient constructs a Client from cfg.

func (*Client) GetPrice

func (c *Client) GetPrice(ctx context.Context, symbol string) (*Price, error)

GetPrice fetches a real-time price for the given symbol.

func (*Client) GetQuote

func (c *Client) GetQuote(ctx context.Context, symbol string) (*Quote, error)

GetQuote fetches a full quote (OHLCV + 52-week range) for the given symbol.

func (*Client) GetTimeSeries

func (c *Client) GetTimeSeries(ctx context.Context, symbol, interval string, count int) ([]Bar, error)

GetTimeSeries fetches OHLCV bars for the given symbol, interval, and count. interval is one of: 1min, 5min, 15min, 30min, 1h, 4h, 1day, 1week, 1month.

func (*Client) ListExchanges

func (c *Client) ListExchanges(ctx context.Context) ([]Exchange, error)

ListExchanges returns all available market exchanges.

func (*Client) ListStocks

func (c *Client) ListStocks(ctx context.Context, exchange, country string, limit int) ([]Stock, error)

ListStocks returns available stock symbols, optionally filtered by exchange and country. limit caps the results client-side.

type Config

type Config struct {
	BaseURL   string
	UserAgent string
	APIKey    string
	Rate      time.Duration
	Timeout   time.Duration
	Retries   int
}

Config holds constructor parameters for Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns production defaults.

type Domain

type Domain struct{}

Domain is the Twelve Data driver.

func (Domain) Classify

func (Domain) Classify(input string) (uriType, id string, err error)

Classify turns any accepted input into the canonical (type, id).

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme, the hostnames a pasted link is matched against, and the identity reused for the binary's help and version.

func (Domain) Locate

func (Domain) Locate(uriType, id string) (string, error)

Locate is the inverse: the live https URL for a (type, id).

func (Domain) Register

func (Domain) Register(app *kit.App)

Register installs the client factory and every operation onto app.

type Exchange

type Exchange struct {
	Code     string `kit:"id" json:"code"`
	Name     string `json:"name"`
	Title    string `json:"title"`
	Country  string `json:"country"`
	Timezone string `json:"timezone"`
}

Exchange is a market exchange.

type Price

type Price struct {
	Symbol string `kit:"id" json:"symbol"`
	Price  string `json:"price"`
}

Price is a real-time price record for a symbol.

type Quote

type Quote struct {
	Symbol        string `kit:"id" json:"symbol"`
	Name          string `json:"name"`
	Exchange      string `json:"exchange"`
	Date          string `json:"date"`
	Open          string `json:"open"`
	High          string `json:"high"`
	Low           string `json:"low"`
	Close         string `json:"close"`
	Volume        string `json:"volume"`
	Change        string `json:"change"`
	ChangePercent string `json:"change_percent"`
	Week52Low     string `json:"week52_low"`
	Week52High    string `json:"week52_high"`
}

Quote is a full daily quote with OHLCV and 52-week range.

type Stock

type Stock struct {
	Symbol   string `kit:"id" json:"symbol"`
	Name     string `json:"name"`
	Exchange string `json:"exchange"`
	Country  string `json:"country"`
	Currency string `json:"currency"`
	Type     string `json:"type"`
}

Stock is an available stock listing.

Jump to

Keyboard shortcuts

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