Skip to content

Data Models and Options

Igor Sazonov edited this page Sep 23, 2026 · 1 revision

The library uses typed Go models where a response shape is stable and returns map[string]any or []any for evolving payloads. Every typed response model preserves the complete decoded JSON object in Raw, so callers can inspect fields added by DefiLlama without losing access to them.1

Typed response models

Model Selected fields Returned by
Protocol ID, Name, Symbol, Category, Chains, TVL, ChainTVLs, Change1d, Change7d, Raw TVL().GetProtocols
ProtocolDetails Raw; accessors Name(), Slug(), TVLHistory(), ChainTVLs() TVL().GetProtocol
Chain GeckoID, TVL, TokenSymbol, CmcID, Name, ChainID, Raw TVL().GetChains
CoinPrice Price, Symbol, Timestamp, Decimals, Confidence, Raw Price methods
Block Height, Timestamp, Raw Prices().GetBlockAtTimestamp
Stablecoin ID, Name, Symbol, PegType, PegMechanism, Circulating, Chains, Price, Raw Stablecoins().GetStablecoins
YieldPool Pool, Chain, Project, Symbol, TVLUsd, APY, APYBase, APYReward, Stablecoin, IlRisk, Exposure, RewardTokens, Predictions, Raw Yields().GetPools
APIUsage Raw; helper CreditsLeft() Account().GetUsage
EquityCompany Ticker, CompanyName, Country, CountryName, Raw Equities().GetCompaniesList
PreIPOCompany ID, Name, Description, Website, Sector, valuation/funding fields, Raw PreIPO().GetCompaniesList
RWAAsset ID, Ticker, AssetName, AssetGroup, Issuer, Chain, Category, OnChainMcap, Price, Stablecoin, Governance, Raw RWA asset methods

All monetary, TVL, APY, confidence, and percentage-like transport values are decoded as float64. Float values are convenient for display and ordinary comparisons, but a caller should convert to a decimal type before computations where exact financial rounding matters.1

Use Raw safely

Raw contains decoded JSON values. JSON numbers are normally float64, arrays are []any, and objects are map[string]any. Test both presence and dynamic type before using an optional field.

protocol, err := client.TVL().GetProtocol(ctx, "aave")
if err != nil {
    return err
}

if description, ok := protocol.Raw["description"].(string); ok {
    fmt.Println(description)
}

if history, ok := protocol.Raw["tvl"].([]any); ok {
    fmt.Println("history records:", len(history))
}

Do not treat a zero-valued typed field as proof that the API returned zero when the distinction between absent and zero matters. Consult the model's Raw map in that situation.1

Pointer-based optional values

Option structs use pointers for optional query parameters. A nil field is omitted, whereas a non-nil pointer lets the caller intentionally send a zero value or false. The generic helper defillama.Ptr keeps these literals readable.

chart, err := client.Prices().GetChart(ctx,
    []string{"coingecko:bitcoin"},
    &defillama.ChartOptions{
        Start:  defillama.Ptr(float64(1735689600)),
        End:    defillama.Ptr(float64(1735776000)),
        Span:   defillama.Ptr(30.0),
        Period: defillama.Ptr("1d"),
    },
)
_ = chart
_ = err

Option types

Option type Fields Used by
OverviewOptions ExcludeTotalDataChart, ExcludeTotalDataChartBreakdown, DataType DEX/options/open-interest/derivatives and fee overviews. The first two fields are required Boolean flags.
ChartOptions Start, End, Span, Period Price charts.
PercentageOptions Timestamp, LookForward, Period Price percentage changes.
StablecoinsListOptions IncludePrices Stablecoin list.
StablecoinChartOptions Stablecoin Stablecoin chart and dominance methods.
DimensionOptions DataType Fee summaries and generic dimension metrics/charts.
TVLChartOptions Key, Currency Pro protocol TVL charts.
TreasuryChartOptions Key, Currency Pro treasury charts.
EarnPoolsQuery Chain, protocol, risk, TVL, and pagination filters Pro earn-pool query.
HistoryRangeOptions Range Pro earn/borrow history.
BridgesOptions IncludeChains Pro bridge list.
BridgeVolumeOptions ID Pro bridge volume and day stats.
BridgeTransactionsOptions Time, chain, address, and Limit filters Pro bridge transactions.
EquitiesQuery Ticker, Country, Timeframe Pro equity detail methods.
PreIPOQuery Company Pro pre-IPO detail methods.
RWAChartOptions Key, stablecoin/governance flags Pro RWA chain-breakdown charts.

Local validation

The generated route metadata validates required query fields and declared enums before a request. Relevant constraints include the following:

Input Accepted values or range
TVLChartOptions.Key all, staking, borrowed, vesting, pool2
TVLChartOptions.Currency and TreasuryChartOptions.Currency usd, token, raw
TreasuryChartOptions.Key OwnTokens, all
HistoryRangeOptions.Range 30d, 90d, max
RWAChartOptions.Key onChainMcap, activeMcap, defiActiveTvl
BridgeTransactionsOptions.Limit Integer from 1 through 6000
EquitiesQuery.Timeframe 1D, 7D, 1W, 1M, 3M, 6M, YTD, 1Y, 5Y, MAX

A local validation error is a regular Go error. It is returned before the HTTP request is built, so applications can correct a query without consuming network time or API capacity.2

References

Clone this wiki locally