coinbase

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 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 website 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) BuyPrice

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

BuyPrice returns the buy price for a currency pair.

func (*Client) Currencies

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

Currencies returns all supported currencies from /v2/currencies.

func (*Client) ExchangeRates

func (c *Client) ExchangeRates(ctx context.Context, currency string) (*ExchangeRate, error)

ExchangeRates returns exchange rates for a base currency such as "BTC".

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

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

SellPrice returns the sell price for a currency pair.

func (*Client) SpotPrice

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

SpotPrice 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 ExchangeRate

type ExchangeRate struct {
	BaseCurrency string            `kit:"id" json:"base_currency"`
	Rates        map[string]string `json:"rates"`
}

ExchangeRate holds the rates from /v2/exchange-rates.

type Price

type Price struct {
	Pair     string `kit:"id" json:"pair"`
	Amount   string `json:"amount"`
	Currency string `json:"currency"`
	Type     string `json:"type"` // "spot", "buy", or "sell"
}

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

Jump to

Keyboard shortcuts

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