Skip to content
Igor Sazonov edited this page Sep 23, 2026 · 2 revisions

Welcome to the defillama-go wiki!

defillama-go

defillama-go is an idiomatic, dependency-free Go client for the DefiLlama Free and Pro APIs. Version 0.1.0 exposes the 132 GET operations in the repository's pinned OpenAPI snapshot through a single concurrency-safe Client and 21 focused services. It supports protocol TVL, token prices, stablecoins, yields, volumes, fees, bridges, real-world assets, equities, and the broader Pro API surface.2

The client is a transport layer rather than financial advice. DefiLlama defines the meaning and methodology of the data. Monetary values and percentages are decoded as float64; applications that need exact financial arithmetic should convert those values to an appropriate decimal representation.2

Start here

The following program creates a client, lists protocols, and retrieves Bitcoin's current USD price. New performs no network I/O; every request method takes a context.Context.

package main

import (
    "context"
    "fmt"
    "log"
    "time"

    defillama "github.com/tigusigalpa/defillama-go"
)

func main() {
    ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second)
    defer cancel()

    client, err := defillama.New(defillama.WithTimeout(10 * time.Second))
    if err != nil {
        log.Fatal(err)
    }

    protocols, err := client.TVL().GetProtocols(ctx)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("protocols: %d\n", len(protocols))

    prices, err := client.Prices().GetCurrentPrices(ctx, []string{"coingecko:bitcoin"})
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("BTC: $%.2f\n", prices["coingecko:bitcoin"].Price)
}

Install the module with:

go get github.com/tigusigalpa/defillama-go

Go 1.22 or later is required.2

Wiki map

Page Use it for
Getting Started Installation, first Free API request, service access, and identifiers.
Authentication and Configuration Pro keys, timeouts, custom HTTP clients, retries, and routing.
Protocols and TVL Protocol discovery, chain TVL, protocol details, and TVL charts.
Token Prices Current and historical prices, price charts, percentage changes, and blocks.
Stablecoins and Yields Stablecoin supply data and Free/Pro yield endpoints.
Market Data DEX and options volumes, fees, derivatives, bridges, ETFs, and narratives.
Pro API Pro-only services for ecosystem, metrics, equities, RWA, and more.
Data Models and Options Typed models, Raw payloads, option structs, and Ptr.
Error Handling and Reliability Typed errors, rate limits, retries, contexts, and safe logging.
API Reference Complete operation-to-method index for all 132 routes.
Development Local checks, contributions, route-generation rules, and security reporting.

Client design at a glance

The top-level Client owns lightweight service accessors such as TVL(), Prices(), and Yields(). Construct one client for the chosen configuration and share it across goroutines. It holds no request-level state, and each request is controlled by the context passed to the service method.2

Free operations work without an API key and use the route-specific DefiLlama origin declared in the API specification. Pro operations require a key. When configured, the SDK places that key in the URL path required by DefiLlama and redacts it from diagnostic URLs and HTTP error data.2

Stable response shapes are exposed through typed Go models. For endpoints whose payloads are intentionally flexible or evolving, the library returns map[string]any or []any. Typed models also preserve the complete decoded payload in a Raw field, which lets an application inspect new upstream fields without waiting for a library release.2

References

Clone this wiki locally