alternativeme

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 alternativeme is the library behind the alternativeme command line: the HTTP client, request shaping, and the typed data models for the Alternative.me Crypto Fear & Greed Index.

The Client sets a real User-Agent, paces requests to stay polite, and retries transient failures (429 and 5xx). Build your endpoint calls and JSON decoding on top of it.

Index

Constants

View Source
const BaseURL = "https://api.alternative.me"

BaseURL is the root every request is built from.

View Source
const Host = "api.alternative.me"

Host is the API hostname.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTP *http.Client
	// contains filtered or unexported fields
}

Client talks to alternative.me over HTTP.

func NewClient

func NewClient() *Client

NewClient returns a Client configured with DefaultConfig.

func NewClientFromConfig

func NewClientFromConfig(cfg Config) *Client

NewClientFromConfig builds a Client from the given Config.

func (*Client) GetFearGreed

func (c *Client) GetFearGreed(ctx context.Context, limit int) ([]FearGreedRecord, error)

GetFearGreed fetches limit days of the Crypto Fear & Greed Index. Limit 1 returns today's reading only. The timestamp is converted from a Unix second string to "2006-01-02" format; value is converted from a JSON string ("18") to int.

type Config

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

Config holds all tunables for a Client.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Domain

type Domain struct{}

Domain is the alternativeme driver. It carries no state; the per-run client is built by the factory Register hands kit.

func (Domain) Classify

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

Classify turns any accepted input into (uriType, id). "feargreed" or "index" maps to ("index", "feargreed"). A bare date like "2024-01-01" maps to ("date", "2024-01-01").

func (Domain) Info

func (Domain) Info() kit.DomainInfo

Info describes the scheme and identity for both the binary and the URI driver.

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 operations onto app.

type FearGreedRecord

type FearGreedRecord struct {
	Timestamp      string `json:"timestamp" kit:"id"`
	Value          int    `json:"value"`
	Classification string `json:"classification"`
}

FearGreedRecord is one day's Fear & Greed reading.

Jump to

Keyboard shortcuts

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