Rujira.Prices behaviour (rujira_ex v0.0.4)

Copy Markdown View Source

Behaviour and configurable delegator for asset price lookups.

Ships with two built-in implementations:

Consumers can override via application env:

config :rujira_ex, prices: MyApp.CustomPrices

Defaults to Rujira.Prices.Default.

Cache TTL

The default implementation memoizes prices using the global cache TTL. See Rujira.cache_ttl/0.

Summary

Functions

Fetches the USD price for an asset.

Callbacks

get(t)

@callback get(String.t()) :: {:ok, Decimal.t()} | {:error, term()}

value_usd(t, integer, integer)

@callback value_usd(String.t(), integer(), integer()) :: integer()

Functions

get(ticker)

@spec get(String.t()) :: {:ok, Decimal.t()} | {:error, term()}

Fetches the USD price for an asset.

ticker must be the bare ticker from Rujira.Assets.Asset.ticker (e.g. "USDC"), not the full symbol (e.g. "USDC-0xAbc...").

value_usd(ticker, amount, decimals \\ 8)

@spec value_usd(String.t(), integer(), integer()) :: integer()