coinlore

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: 9 Imported by: 0

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

View Source
const BaseURL = "https://" + Host

BaseURL is the root every request is built from.

View Source
const DefaultUserAgent = "coinlore-cli/dev (+https://github.com/tamnd/coinlore-cli)"

DefaultUserAgent identifies the client to CoinLore.

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

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

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

func (c *Client) GetCoin(ctx context.Context, id string) (*Coin, error)

GetCoin fetches a single coin by its numeric ID (e.g. "90" for Bitcoin).

func (*Client) GetGlobal

func (c *Client) GetGlobal(ctx context.Context) (*GlobalStats, error)

GetGlobal fetches the global crypto market overview.

func (*Client) GetMarkets

func (c *Client) GetMarkets(ctx context.Context, id string, limit int) ([]Market, error)

GetMarkets fetches the exchange markets for a coin by its numeric ID. limit truncates the result client-side; the API returns up to 50.

func (*Client) ListCoins

func (c *Client) ListCoins(ctx context.Context, limit, start int) ([]Coin, error)

ListCoins fetches a paginated list of coins by market rank. limit controls how many coins to return (max 100); start is the offset.

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

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

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.

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

Jump to

Keyboard shortcuts

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