coinbase

package
v0.1.2 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 coinbase is the library behind the coinbase command line: the HTTP client, request shaping, and the typed data models for the Coinbase public v2 API (api.coinbase.com/v2). No API key is required for the read-only endpoints this package uses.

Index

Constants

View Source
const BaseURL = "https://api.coinbase.com/v2"

BaseURL is the Coinbase v2 API base.

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

DefaultUserAgent identifies the client to Coinbase.

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

Host is the Coinbase API host (used by the URI driver).

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP      *http.Client
	UserAgent string
	Rate      time.Duration
	Retries   int
	// contains filtered or unexported fields
}

Client talks to the Coinbase public v2 API over HTTPS.

func NewClient

func NewClient() *Client

NewClient returns a Client with sensible defaults.

func (*Client) Buy added in v0.1.1

func (c *Client) Buy(ctx context.Context, pair string) (*Price, error)

Buy returns the buy price for a currency pair such as "BTC-USD".

func (*Client) CryptoCurrencies added in v0.1.2

func (c *Client) CryptoCurrencies(ctx context.Context) ([]Currency, error)

CryptoCurrencies returns all supported crypto currencies from /v2/currencies/crypto. The endpoint uses a different wire shape (code/name, no min_size) so we map it to the shared Currency type.

func (*Client) Currencies

func (c *Client) Currencies(ctx context.Context) ([]Currency, error)

Currencies returns all supported fiat currencies from /v2/currencies.

func (*Client) Get

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

Get fetches url and returns the response body, pacing and retrying as configured.

func (*Client) Rates added in v0.1.1

func (c *Client) Rates(ctx context.Context, currency string) ([]Rate, error)

Rates returns exchange rates for a base currency such as "BTC". Each returned Rate has Base, Target, and Rate fields.

func (*Client) Spot added in v0.1.1

func (c *Client) Spot(ctx context.Context, pair string) (*Price, error)

Spot returns the spot price for a currency pair such as "BTC-USD".

type Config

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

Config holds optional overrides for NewClient.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Currency

type Currency struct {
	ID      string `kit:"id" json:"id"`
	Name    string `json:"name"`
	MinSize string `json:"min_size"`
}

Currency is one entry from /v2/currencies.

type Domain

type Domain struct{}

Domain is the coinbase driver.

func (Domain) Classify

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

Classify turns any accepted input into the canonical (type, id). A pair like "BTC-USD" maps to ("pair", "BTC-USD"); a bare currency like "BTC" maps to ("currency", "BTC").

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 Price

type Price struct {
	Base      string `kit:"id" json:"base"`
	Currency  string `json:"currency"`
	Amount    string `json:"amount"`
	PriceType string `json:"price_type"` // "spot", "buy", or "sell"
}

Price holds spot or buy price data from /v2/prices/<pair>/<type>.

type Rate added in v0.1.1

type Rate struct {
	Base   string `kit:"id" json:"base"`
	Target string `json:"target"`
	Rate   string `json:"rate"`
}

Rate is one exchange-rate row from /v2/exchange-rates.

Jump to

Keyboard shortcuts

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