Skip to main content

token_prices

Schema: public

Description

The token_prices table is used to store data on the USD prices of various tokens in the cryptocurrency market. It contains information such as the quote time, token name, price, source, and market cap. This table is useful for tracking the performance of different tokens and analyzing trends in the market.

Also, if less granular prices over time are needed, a continuous aggregate view named daily_token_prices also exists; this aggregate records the open, high, low, and close prices for each day.

Columns

Granular prices

NameTypeDescriptionDefault
idcharacterUnique identifier for each rowNone
quote_timetimestamptzTime at which the price was quotedNone
tokentextName of the tokenNone
pricenumericCurrent price of the token (in USD)None
sourcetextSource of the price data (e.g. CoinGecko, CoinMarketCap, etc.)None
market_capnumericMarket cap of the token; not provided for all sources/tokensNone (nullable)

Daily prices

NameTypeDescriptionDefault
quote_daytimestamptzThe day which the price was quotedNone
tokentextName of the tokenNone
sourcetextSource of the price data (e.g. CoinGecko, CoinMarketCap, etc.)None
first_pricenumericThe first price recorded for the day (i.e. "Open" price)None
last_pricenumericThe last price recorded for the day (i.e. "Close" price)None
maximum_pricenumericThe highest price recorded for the day (i.e. "High" price)None
minimum_pricenumericThe lowest price recorded for the day (i.e. "Low" price)None

Examples

Last week of KAVA prices
select *
from token_prices
where token = 'KAVA'
and quote_time > now() - '1 week'::interval
order by quote_time;
Last known price for KAVA, ATOM, and USDC
select
token,
max(quote_time),
last(source, quote_time),
last(price, quote_time)
from token_prices
where token in ('KAVA', 'ATOM', 'USDC')
and quote_time > now() - '1 week'::interval
group by token;
Get a year's worth of OHLC (candlestick) data using daily price aggregate
select
token,
quote_day,
source,
first_price,
maximum_price,
minimum_price,
last_price
from daily_token_prices
where token = 'USDC'
and quote_day > now() - '1 year'::interval;