Documentation
¶
Overview ¶
Package coinlore is the library behind the coinlore command line: the HTTP client, request shaping, and the typed data models for CoinLore.
The Client here is the spine every command shares. It sets a real User-Agent, paces requests so a busy session stays polite, and retries the transient failures (429 and 5xx) that any public API throws under load.
Index ¶
- Constants
- type Client
- func (c *Client) Get(ctx context.Context, url string) ([]byte, error)
- func (c *Client) GetCoin(ctx context.Context, id string) (*Coin, error)
- func (c *Client) GetGlobal(ctx context.Context) (*GlobalStats, error)
- func (c *Client) GetMarkets(ctx context.Context, id string, limit int) ([]Market, error)
- func (c *Client) ListCoins(ctx context.Context, limit, start int) ([]Coin, error)
- type Coin
- type Domain
- type GlobalStats
- type Market
Constants ¶
const BaseURL = "https://" + Host
BaseURL is the root every request is built from.
const DefaultUserAgent = "coinlore-cli/dev (+https://github.com/tamnd/coinlore-cli)"
DefaultUserAgent identifies the client to CoinLore.
const Host = "api.coinlore.net"
Host is the API host this client talks to.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
HTTP *http.Client
UserAgent string
// Rate is the minimum gap between requests. Zero means no pacing.
Rate time.Duration
Retries int
// contains filtered or unexported fields
}
Client talks to CoinLore over HTTP.
func NewClient ¶
func NewClient() *Client
NewClient returns a Client with sensible defaults: a 30s timeout, a 300ms minimum gap between requests, and five retries on transient errors.
func (*Client) Get ¶
Get fetches url and returns the response body. It paces and retries according to the client's settings. The caller owns nothing extra; the body is read fully and closed here.
func (*Client) GetGlobal ¶
func (c *Client) GetGlobal(ctx context.Context) (*GlobalStats, error)
GetGlobal fetches the global crypto market overview.
func (*Client) GetMarkets ¶
GetMarkets fetches the exchange markets for a coin by its numeric ID. limit truncates the result client-side; the API returns up to 50.
type Coin ¶
type Coin struct {
ID string `kit:"id" json:"id"`
Symbol string `json:"symbol"`
Name string `json:"name"`
Rank int `json:"rank"`
PriceUSD string `json:"price_usd"`
PercentChange1h string `json:"percent_change_1h"`
PercentChange24h string `json:"percent_change_24h"`
PercentChange7d string `json:"percent_change_7d"`
MarketCapUSD string `json:"market_cap_usd"`
Volume24 float64 `json:"volume24"`
CirculatingSupply string `json:"csupply"`
TotalSupply string `json:"tsupply"`
}
Coin holds the per-coin data returned by the tickers and ticker endpoints.
type Domain ¶
type Domain struct{}
Domain is the coinlore driver.
func (Domain) Classify ¶
Classify turns a numeric coin ID or ticker symbol into a canonical (type, id). Pure numeric input → ("coin", id); letters+digits (ticker like BTC) → ("symbol", id); otherwise → ("query", 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.
type GlobalStats ¶
type GlobalStats struct {
CoinsCount int `kit:"id" json:"coins_count"`
ActiveMarkets int `json:"active_markets"`
TotalMcap float64 `json:"total_mcap"`
TotalVolume float64 `json:"total_volume"`
BTCDominance string `json:"btc_d"`
ETHDominance string `json:"eth_d"`
McapChange string `json:"mcap_change"`
VolumeChange string `json:"volume_change"`
}
GlobalStats holds the global crypto market overview.
type Market ¶
type Market struct {
Name string `kit:"id" json:"name"`
Base string `json:"base"`
Quote string `json:"quote"`
Price float64 `json:"price"`
PriceUSD float64 `json:"price_usd"`
Volume float64 `json:"volume"`
VolumeUSD float64 `json:"volume_usd"`
}
Market holds a single exchange market for a coin.