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
- type Bar
- type Client
- func (c *Client) GetPrice(ctx context.Context, symbol string) (*Price, error)
- func (c *Client) GetQuote(ctx context.Context, symbol string) (*Quote, error)
- func (c *Client) GetTimeSeries(ctx context.Context, symbol, interval string, count int) ([]Bar, error)
- func (c *Client) ListExchanges(ctx context.Context) ([]Exchange, error)
- func (c *Client) ListStocks(ctx context.Context, exchange, country string, limit int) ([]Stock, error)
- type Config
- type Domain
- type Exchange
- type Price
- type Quote
- type Stock
Constants ¶
const DefaultUserAgent = "twelvedata-cli/0.1 (tamnd87@gmail.com)"
DefaultUserAgent identifies the client to the API.
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 (*Client) GetQuote ¶
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 ¶
ListExchanges returns all available market exchanges.
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.
type Domain ¶
type Domain struct{}
Domain is the Twelve Data driver.
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.
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 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.