I want to find all etherium tokens which are relatively dead and don't show
big marcetcap
don't show trading activity
with
both_ways_trades as (
select
blockchain,
token_bought_address as token_contract_address,
block_date
from
dex.trades
where
blockchain = 'ethereum'
union all
select
blockchain,
token_sold_address as token_contract_address,
block_date
from
dex.trades
where
blockchain = 'ethereum'
)
select
blockchain,
token_contract_address,
min(block_date) as first_trade_date
from
both_ways_trades
group by
blockchain,
token_contract_address
order by
first_trade_date DESC
Assistant
Based on your query, you're retrieving Ethereum tokens along with their first trade date, ordered by the most recent first trade dates. This gives you a list of tokens and when they first appeared in the dex.trades table.
However, to identify tokens that are relatively dead—meaning they have low market capitalization and low trading activity—you'll need to adjust your query to include:
Market Capitalization: Incorporate market cap data for each token to filter out those with low market caps.
Trading Activity: Calculate recent trading volumes to identify tokens with minimal or no trading activity.
Here's how you can modify your query to achieve this:
sql
WITH both_ways_trades AS (
SELECT
blockchain,
token_bought_address AS token_contract_address,
block_date,
amount_usd
FROM
dex.trades
WHERE
blockchain = 'ethereum'
UNION ALL
SELECT
blockchain,
token_sold_address AS token_contract_address,
block_date,
amount_usd
FROM
dex.trades
WHERE
blockchain = 'ethereum'
),
recent_trades AS (
SELECT
blockchain,
token_contract_address,
amount_usd,
block_date
FROM
both_ways_trades
WHERE
block_date >= CURRENT_DATE - INTERVAL '30' DAY
),
token_statistics AS (
SELECT
blockchain,
token_contract_address,
MIN(block_date) AS first_trade_date,
SUM(amount_usd) AS total_volume_last_30_days
FROM
recent_trades
GROUP BY
blockchain,
token_contract_address
)
SELECT
ts.blockchain,
ts.token_contract_address,
ts.first_trade_date,
COALESCE(ts.total_volume_last_30_days, 0) AS total_volume_last_30_days,
COALESCE(tm.market_cap_usd, 0) AS market_cap_usd
FROM
token_statistics ts
LEFT JOIN
token_market_cap tm ON ts.token_contract_address = tm.token_contract_address
WHERE
(tm.market_cap_usd IS NULL OR tm.market_cap_usd < 1000000) -- Tokens with market cap less than $1 million
AND (ts.total_volume_last_30_days IS NULL OR ts.total_volume_last_30_days < 10000) -- Tokens with less than $10k trading volume in the last 30 days
ORDER BY
ts.first_trade_date DESC;
Explanation:
both_ways_trades: Combines trades where the token was either bought or sold, including the USD amount of each trade.
recent_trades: Filters trades that occurred in the last 30 days (you can adjust the interval as needed).
token_statistics: Calculates the first trade date and total trading volume over the last 30 days for each token.
token_market_cap: This is a table (or could be a subquery) that contains the latest market cap for each token. You'll need to have this data available in your database. If not, you might need to import it from an external source or API.
COALESCE: Ensures that if the trading volume or market cap is NULL (i.e., no data available), it defaults to 0 for filtering purposes.
Filtering Criteria:
Tokens with a market cap less than $1 million.
Tokens with less than $10,000 in trading volume over the last 30 days.
ORDER BY: Tokens are ordered by their first trade date in descending order, so the most recently traded tokens appear first.
Notes:
Adjust Thresholds: The thresholds for market cap ($1 million) and trading volume ($10,000) are arbitrary and should be adjusted based on your definition of "dead" tokens.
Data Availability: Ensure that you have the amount_usd field in your dex.trades table. If you're lacking USD amounts, you might need to convert token amounts based on price data.
Market Cap Data: If you don't have a token_market_cap table, you might need to fetch this data from a reliable source like CoinGecko or CoinMarketCap and integrate it into your database.
Alternative Approach Without Market Cap Data:
If you don't have access to market cap data, you can focus solely on trading activity:
sql
WITH both_ways_trades AS (
SELECT
blockchain,
token_bought_address AS token_contract_address,
block_date,
amount_usd
FROM
dex.trades
WHERE
blockchain = 'ethereum'
UNION ALL
SELECT
blockchain,
token_sold_address AS token_contract_address,
block_date,
amount_usd
FROM
dex.trades
WHERE
blockchain = 'ethereum'
),
token_statistics AS (
SELECT
blockchain,
token_contract_address,
MIN(block_date) AS first_trade_date,
SUM(CASE WHEN block_date >= CURRENT_DATE - INTERVAL '30' DAY THEN amount_usd ELSE 0 END) AS total_volume_last_30_days
FROM
both_ways_trades
GROUP BY
blockchain,
token_contract_address
)
SELECT
ts.blockchain,
ts.token_contract_address,
ts.first_trade_date,
ts.total_volume_last_30_days
FROM
token_statistics ts
WHERE
ts.total_volume_last_30_days < 10000 -- Tokens with less than $10k trading volume in the last 30 days
ORDER BY
ts.first_trade_date DESC;
In this version:
We calculate the total trading volume over the last 30 days directly in the token_statistics CTE.
We filter tokens based on trading volume only.
This approach is useful if market cap data is not available.
Steps to Proceed:
Determine Thresholds: Define what "big market cap" and "trading activity" mean for your use case.
Ensure Data Availability:
Verify that you have amount_usd for trades.
Obtain market cap data for tokens (if needed).
Run the Query: Execute the query and inspect the results.
Analyze Results: Review the list of tokens to confirm they meet your criteria for being "relatively dead."
Additional Tips:
Indexing: Ensure your tables are properly indexed on fields like block_date, token_contract_address, and blockchain for performance.
Data Freshness: If using external data for market caps, make sure it's up-to-date to get accurate results.
Validation: Cross-reference results with external sources or blockchain explorers to validate that the tokens are indeed inactive.
You can populate this table by importing data from APIs.
Schedule regular updates to keep the market cap data current.
Fetching Market Cap Data from External APIs (Python Example):
If you're able to use external tools like Python, you could fetch market cap data using APIs:
python
import requests
import pandas as pd
# Example using CoinGecko API
response = requests.get('https://api.coingecko.com/api/v3/coins/markets', params={
'vs_currency': 'usd',
'order': 'market_cap_desc',
'per_page': '250',
'page': '1',
'sparkline': 'false'
})
data = response.json()
df = pd.DataFrame(data)
# Process df to match your `token_market_cap` table schema
Final Remarks:
By enhancing your query to include market cap and recent trading volumes, you can effectively identify Ethereum tokens that are relatively inactive and meet your criteria. Adjust the thresholds and time frames as needed to refine your results.