### SanAPI Common Queries Source: https://academy.santiment.net/labels/whale Examples of frequently used queries to help you get started with the SanAPI. ```APIDOC ## Common Queries ### Description Pre-defined examples for retrieving common data points like price, social volume, and transaction count. ### Method GET ### Endpoint `/api/v1/getMetric` ### Parameters See 'Fetching Metrics' for general parameters. ### Request Example 1. **Get historical ETH price:** ```bash curl "https://api.santiment.net/api/v1/getMetric?apiKey=YOUR_API_KEY&metric=price_usd&slug=ethereum&from=2023-01-01&to=2023-01-10" ``` 2. **Get daily social volume for BTC:** ```bash curl "https://api.santiment.net/api/v1/getMetric?apiKey=YOUR_API_KEY&metric=social_volume&slug=bitcoin&interval=1d" ``` ### Response #### Success Response (200) - **data** (array) - Array of metric values. #### Response Example (Responses vary based on the metric requested.) ``` -------------------------------- ### Install and Use sanpy Python Library Source: https://academy.santiment.net/sanapi/accessing-the-api This snippet shows how to install the `sanpy` Python library using pip and then use it to fetch Ethereum development activity data. The library returns data as a pandas DataFrame. Ensure you have Python and pip installed. ```bash pip install sanpy ``` ```python import sanpy as san san.get( "dev_activity/ethereum", from_date="2019-01-01T00:00:00Z", to_date="2019-01-07T00:00:00Z", interval="1d" ) ``` -------------------------------- ### Python Library (sanpy) Source: https://academy.santiment.net/sanapi/accessing-the-api Utilize the 'sanpy' Python library for simplified API interactions. Install it using 'pip install sanpy'. ```APIDOC ## Python Library (sanpy) ### Description The `sanpy` library provides a Pythonic way to interact with the Santiment GraphQL API. ### Installation ```bash pip install sanpy ``` ### Usage Example ```python import sanpy san = sanpy.Sanpy() response = san.get( "dev_activity/ethereum", from_date="2019-01-01T00:00:00Z", to_date="2019-01-07T00:00:00Z", interval="1d" ) print(response) ``` ### Response Example (Pandas DataFrame) ``` activity datetime 2019-01-01 00:00:00+00:00 44.0 2019-01-02 00:00:00+00:00 89.0 2019-01-03 00:00:00+00:00 140.0 2019-01-04 00:00:00+00:00 177.0 2019-01-05 00:00:00+00:00 46.0 2019-01-06 00:00:00+00:00 22.0 ``` ``` -------------------------------- ### Get Average Price USD (5m intervals) Source: https://academy.santiment.net/metrics/price Retrieves the average price in USD over five-minute intervals for a given slug within a specified date range. ```APIDOC ## POST /graphql ### Description Retrieves the average price in USD over five-minute intervals for a given slug within a specified date range. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters None #### Request Body ```json { "query": "query GetPriceUSD5m($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_usd_5m\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "5m" } } ``` ### Request Example ```json { "query": "query GetPriceUSD5m($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_usd_5m\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "5m" } } ``` ### Response #### Success Response (200) - **timeseriesDataJson** (string) - JSON string containing the timeseries data. #### Response Example ```json { "data": { "getMetric": { "timeseriesDataJson": "[{\"datetime\":\"2020-04-01T00:00:00Z\",\"value\":134.9609252861263},\"datetime\":\"2020-04-01T00:05:00Z\",\"value\":135.0000000000000},\...]" } } } ``` ``` -------------------------------- ### Get Balance Delta per Label and Owner using SanAPI Source: https://academy.santiment.net/metrics/labeled-balance This example queries the balance delta of an asset for a specific owner and label. It requires the metric name, asset slug, owner, label, date range, and interval, with results returned as JSON. ```graphql { getMetric(metric: "balance_per_label_and_owner_delta") { timeseriesDataJson( selector: { slug: "uniswap" owner: "1inch" label: "decentralized_exchange" } from: "2023-12-10T00:00:00Z" to: "2023-12-11T00:00:00Z" interval: "1h" ) } } ``` -------------------------------- ### Example Table Structure Definition Source: https://academy.santiment.net/santiment-queries/exploration This SQL statement defines the structure of the `intraday_metrics` table. It specifies columns such as `asset_id`, `metric_id`, `dt`, `value`, and `computed_at`, along with their data types and storage codecs. The table is set to use the `ReplicatedReplacingMergeTree` engine, partitioned by month, and ordered by asset, metric, and timestamp. ```sql CREATE TABLE default.intraday_metrics ( `asset_id` UInt64 CODEC(DoubleDelta, LZ4), `metric_id` UInt64 CODEC(DoubleDelta, LZ4), `dt` DateTime CODEC(DoubleDelta, LZ4), `value` Float64, `computed_at` DateTime ) ENGINE = ReplicatedReplacingMergeTree('/clickhouse/tables/global/intraday_metrics_v2', '{hostname}', computed_at) PARTITION BY toYYYYMM(dt) ORDER BY (asset_id, metric_id, dt) SETTINGS index_granularity = 8192 ``` -------------------------------- ### Basic Query Example Source: https://academy.santiment.net/for-developers/metrics-exported-s3 Demonstrates how to query metrics data by joining the metrics data file with the assets and metrics lookup tables using ClickHouse SQL and the S3 Table Function. This allows for human-readable asset and metric names in the results. ```APIDOC ## Basic Query Example ### Description This example demonstrates how to query metrics data with proper asset and metric name resolution. ### Method N/A (SQL Query) ### Endpoint N/A (SQL Query targeting S3 files) ### Parameters N/A (Parameters are part of the SQL query and S3 access credentials) ### Request Example ```sql SELECT assets.name AS asset, metrics.name AS metric, dt, value FROM s3( url='s3://santiment-metrics/metrics/intraday/price_usd/2024/01/data.parquet', access_key_id='YOUR_KEY_ID', secret_access_key='YOUR_KEY_SECRET', format='Parquet' ) AS data LEFT JOIN ( SELECT asset_id, name FROM s3( url='s3://santiment-metrics/assets.parquet', access_key_id='YOUR_KEY_ID', secret_access_key='YOUR_KEY_SECRET', format='Parquet' ) ) AS assets USING asset_id LEFT JOIN ( SELECT metric_id, name FROM s3( url='s3://santiment-metrics/metrics.parquet', access_key_id='YOUR_KEY_ID', secret_access_key='YOUR_KEY_SECRET', format='Parquet' ) ) AS metrics ON metrics.metric_id = data.metric_id; ``` ### Response #### Success Response (200) - **asset** (STRING) - The name of the asset. - **metric** (STRING) - The name of the metric. - **dt** (TIMESTAMP) - The date and time of the measurement. - **value** (DOUBLE) - The metric value. #### Response Example ```json { "asset": "Bitcoin", "metric": "price_usd", "dt": "2024-01-01 00:00:00", "value": 42280.23527619226 } ``` ``` -------------------------------- ### Get Price USDT Source: https://academy.santiment.net/metrics/price Retrieves the daily historical price data in USDT for a given slug within a specified date range. ```APIDOC ## POST /graphql ### Description Retrieves the daily historical price data in USDT for a given slug within a specified date range. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters None #### Request Body ```json { "query": "query GetPriceUSDT($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_usdt\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "1d" } } ``` ### Request Example ```json { "query": "query GetPriceUSDT($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_usdt\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "1d" } } ``` ### Response #### Success Response (200) - **timeseriesDataJson** (string) - JSON string containing the timeseries data. #### Response Example ```json { "data": { "getMetric": { "timeseriesDataJson": "[{\"datetime\":\"2020-04-01T00:00:00Z\",\"value\":1.0000000000000000},\"datetime\":\"2020-04-02T00:00:00Z\",\"value\":1.0000000000000000}, ...]" } } } ``` ``` -------------------------------- ### SQL Query Example Source: https://academy.santiment.net/santiment-queries/api-access This SQL query fetches daily metric values for a specified asset and metric over the last N days. It demonstrates dynamic parameterization using placeholders like {{slug}}, {{metric}}, and {{last_n_days}}. ```sql SELECT get_metric_name(metric_id) AS metric, get_asset_name(asset_id) AS asset, dt, argMax(value, computed_at) AS value FROM daily_metrics_v2 WHERE asset_id = get_asset_id('bitcoin') AND metric_id = get_metric_id('nvt') AND dt >= now() - INTERVAL 7 DAY GROUP BY dt, metric_id, asset_id ORDER BY dt ASC ``` -------------------------------- ### Get Price BTC Source: https://academy.santiment.net/metrics/price Retrieves the daily historical price data in BTC for a given slug within a specified date range. ```APIDOC ## POST /graphql ### Description Retrieves the daily historical price data in BTC for a given slug within a specified date range. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters None #### Request Body ```json { "query": "query GetPriceBTC($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_btc\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "1d" } } ``` ### Request Example ```json { "query": "query GetPriceBTC($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_btc\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "1d" } } ``` ### Response #### Success Response (200) - **timeseriesDataJson** (string) - JSON string containing the timeseries data. #### Response Example ```json { "data": { "getMetric": { "timeseriesDataJson": "[{\"datetime\":\"2020-04-01T00:00:00Z\",\"value\":0.02155502016645416},\"datetime\":\"2020-04-02T00:00:00Z\",\"value\":0.02167398268912271}, ...]" } } } ``` ``` -------------------------------- ### Sansheets - Setup and Usage Source: https://academy.santiment.net/metrics Instructions for setting up and using Sansheets, a tool that integrates Santiment data directly into Google Sheets and Excel. ```APIDOC ## Sansheets ### Description This guide covers the setup and usage of Sansheets, allowing users to pull Santiment data directly into their spreadsheets (Google Sheets and Excel) for analysis. ### Setting Up Step-by-step instructions on how to get Sansheets installed and ready for use. ### Adding an API Key Guidance on how to connect your Santiment API key to Sansheets to authenticate your data requests. ### Correlation Matrix Information on using Sansheets to generate correlation matrices for assets. ### Asset Activity Matrix Details on how to create and interpret asset activity matrices using Sansheets. ### Functions Documentation for the specific functions available within Sansheets to fetch and manipulate Santiment data. ### PRO Templates Information on pre-built professional templates available for use with Sansheets. ``` -------------------------------- ### Get Price USD Source: https://academy.santiment.net/metrics/price Retrieves the daily historical price data in USD for a given slug within a specified date range. ```APIDOC ## POST /graphql ### Description Retrieves the daily historical price data in USD for a given slug within a specified date range. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters None #### Request Body ```json { "query": "query GetPriceUSD($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_usd\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "1d" } } ``` ### Request Example ```json { "query": "query GetPriceUSD($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_usd\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "1d" } } ``` ### Response #### Success Response (200) - **timeseriesDataJson** (string) - JSON string containing the timeseries data. #### Response Example ```json { "data": { "getMetric": { "timeseriesDataJson": "[{\"datetime\":\"2020-04-01T00:00:00Z\",\"value\":134.9609252861263},\"datetime\":\"2020-04-02T00:00:00Z\",\"value\":135.5567868738707}, ...]" } } } ``` ``` -------------------------------- ### Get OHLC Data Source: https://academy.santiment.net/metrics/price Retrieves the Open, High, Low, and Close (OHLC) data for a given slug within a specified date range and interval. ```APIDOC ## POST /graphql ### Description Retrieves the Open, High, Low, and Close (OHLC) data for a given slug within a specified date range and interval. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters None #### Request Body ```json { "query": "query GetOHLC($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_usd\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval, aggregation: OHLC)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "1d" } } ``` ### Request Example ```json { "query": "query GetOHLC($slug: String!, $from: DateTime!, $to: DateTime!, $interval: String!) {\n getMetric(metric: \"price_usd\") {\n timeseriesDataJson(slug: $slug, from: $from, to: $to, interval: $interval, aggregation: OHLC)\n }\n}", "variables": { "slug": "ethereum", "from": "2020-04-01T00:00:00Z", "to": "2020-04-07T00:00:00Z", "interval": "1d" } } ``` ### Response #### Success Response (200) - **timeseriesDataJson** (string) - JSON string containing the OHLC timeseries data. #### Response Example ```json { "data": { "getMetric": { "timeseriesDataJson": "[{\"datetime\":\"2020-04-01T00:00:00Z\",\"open\":134.9609252861263,\"high\":136.898767131727,\"low\":134.14124710000001,\"close\":135.5567868738707},\"datetime\":\"2020-04-02T00:00:00Z\",\"open\":135.5567868738707,\"high\":137.4798759137261,\"low\":135.11396519291707,\"close\":137.1647891731533}, ...]" } } } ``` ``` -------------------------------- ### Example NFT Tables Source: https://academy.santiment.net/santiment-queries/nft-tables This shows the expected output after running the 'SHOW TABLES LIKE '%nft%'' query. It lists three specific tables that store NFT trading and metadata information: `nft_trades`, `nft_tokens_metadata`, and `intraday_nft_metrics`. ```text ┌─name───────────────────┐ │ nft_trades │ │ nft_tokens_metadata │ │ intraday_nft_metrics │ └────────────────────────┘ ``` -------------------------------- ### Get Thermocap Metric Data from SanAPI Source: https://academy.santiment.net/metrics/thermocap Retrieves time-series data for the 'thermocap' metric using SanAPI. Requires specifying the cryptocurrency slug, start and end dates, and the desired interval. The output is in JSON format. ```graphql { getMetric(metric: "thermocap"){ timeseriesDataJson( slug: "bitcoin" from: "2025-11-01T00:00:00Z" to: "2025-11-10T00:00:00Z" interval: "1d") } } ``` -------------------------------- ### Get MCTC Metric Data from SanAPI Source: https://academy.santiment.net/metrics/thermocap Retrieves time-series data for the 'mctc' metric using SanAPI. This endpoint requires the cryptocurrency slug, start and end dates, and the data interval. The results are returned as a JSON object. ```graphql { getMetric(metric: "mctc"){ timeseriesDataJson( slug: "bitcoin" from: "2025-11-01T00:00:00Z" to: "2025-11-10T00:00:00Z" interval: "1d") } } ``` -------------------------------- ### Santiment Queries - Writing SQL Queries Source: https://academy.santiment.net/metrics A guide on writing SQL queries to extract data from Santiment's databases, covering exploration, available tables, and query costs. ```APIDOC ## Santiment Queries ### Description This section provides guidance on writing SQL queries to access and analyze data within Santiment's data warehouse. It covers the process from initial exploration to understanding specific table structures and managing query credits. ### Introduction An overview of Santiment's query capabilities and the purpose of the SQL interface. ### Exploration Strategies and tips for exploring the available datasets and understanding the data schema. ### Writing SQL Queries Detailed instructions and best practices for constructing effective SQL queries to retrieve desired information. ### API Access Information on how to access the SQL query interface, potentially through an API. ### Rate Limits and Credits Cost Explanation of how queries are limited and the cost associated with running them in terms of credits. ### Prices Tables Documentation for tables containing historical and real-time pricing data for various assets. ### Metric Tables Information on tables that store specific on-chain and social metrics. ### Bridge Transactions Details on tables related to bridge transactions across different blockchains. ### Lending Pools Documentation for tables concerning lending pool data. ### DEX Pools Information on tables related to decentralized exchange (DEX) pool data. ### NFT Tables Details on tables containing data related to Non-Fungible Tokens (NFTs). ### XRPL Tables Specific documentation for tables related to the XRP Ledger (XRPL). ``` -------------------------------- ### Get Aggregated Transaction Volume Source: https://academy.santiment.net/sansheets/functions/onchain Returns the aggregated transaction volume for a project slug over a specified period. This function provides a summary of total token transfers. It requires the project slug, start and end dates, and the aggregation method. ```javascript SAN_TRANSACTION_VOLUME_AGGREGATED(projectSlug, from, to, aggregation) ``` -------------------------------- ### Retrieve All Projects using Sanpy Source: https://academy.santiment.net/glossary/asset This Python code snippet demonstrates how to import the Sanpy library and use its `get` method to fetch a list of all available projects. This is useful for integrating Santiment data into Python applications. ```python import san san.get("projects/all") ``` -------------------------------- ### Query Fraxlend Total New Debt (USD) with SanAPI Source: https://academy.santiment.net/metrics/lending-and-borrowing-protocols/fraxlend This code example shows how to fetch the `fraxlend_total_new_debt_usd` metric via SanAPI. It includes parameters for the asset slug, date range, and interval. This metric represents the total amount of borrowings on the Fraxlend protocol in USD. ```graphql { getMetric(metric: "fraxlend_total_new_debt_usd"){ timeseriesDataJson( slug: "frax" from: "2024-01-10T00:00:00Z" to: "2024-01-12T00:00:00Z" includeIncompleteData: true interval: "1h") } } ``` -------------------------------- ### GraphQL Field: getMetric with aggregatedTimeseriesData Source: https://academy.santiment.net/glossary Shows how to use the `aggregatedTimeseriesData` field with the `getMetric` query to get aggregated time-series data. This example includes arguments for slug, time range, and aggregation type. ```APIDOC ## POST /graphql ### Description Retrieves aggregated time-series data for a given metric and asset. ### Method POST ### Endpoint /graphql ### Request Body #### Query - **query** (string) - Required - The GraphQL query string. ### Request Example ```json { "query": "{\n getMetric(metric: \"active_addresses_24h\") {\n aggregatedTimeseriesData(\n slug: \"ethereum\" from: \"2019-01-01T00:00:00Z\" to: \"2019-01-01T03:00:00Z\" aggregation: AVG )\n }\n}" } ``` ### Response #### Success Response (200) - **data** (object) - The data returned by the query. - **getMetric** (object) - **aggregatedTimeseriesData** (array) - Aggregated time-series data. - **datetime** (string) - Timestamp of the aggregated data point. - **value** (number) - The aggregated value. #### Response Example ```json { "data": { "getMetric": { "aggregatedTimeseriesData": [ { "datetime": "2019-01-01T00:00:00Z", "value": 1025 } ] } } } ``` ``` -------------------------------- ### Get Transaction Volume Source: https://academy.santiment.net/sansheets/functions/onchain Fetches the transaction volume for a given project slug over a specified time interval. Transaction volume represents the total number of tokens transferred on a blockchain. Requires project slug, start and end dates, and the data interval. ```javascript SAN_TRANSACTION_VOLUME(projectSlug, from, to, interval) ``` -------------------------------- ### List Projects and GitHub Links in an Ecosystem (GraphQL) Source: https://academy.santiment.net/metrics/development-activity/development-activity This snippet demonstrates how to query for all projects belonging to a specific ecosystem, like 'Ethereum'. It returns the project's slug and its associated GitHub repository links, which is useful for understanding the components of an ecosystem. ```graphql { getEcosystems(ecosystems: ["Ethereum"] tehdä name projects{ slug githubLinks } } } ``` -------------------------------- ### Using the Python Library (sanpy) Source: https://academy.santiment.net/santiment-queries/api-access This section demonstrates how to use the `sanpy` Python library to interact with the `runRawSqlQuery` API. It simplifies executing queries and retrieving data as a Pandas DataFrame. ```APIDOC ## Using the Python library `sanpy` ### Description The `sanpy` Python library provides a convenient `execute_sql` function to interact with the `runRawSqlQuery` API. It handles query execution and returns the results as a Pandas DataFrame. ### Installation ```bash pip install sanpy ``` ### Usage ```python import san san.ApiConfig.api_key = 'YOUR_OWN_API_KEY' # Replace with your actual API key response = san.execute_sql( query=""" SELECT get_metric_name(metric_id) AS metric, get_asset_name(asset_id) AS asset, dt, argMax(value, computed_at) AS value FROM daily_metrics_v2 WHERE asset_id = get_asset_id({{slug}}) AND metric_id = get_metric_id({{metric}}) AND dt >= now() - INTERVAL {{last_n_days}} DAY GROUP BY dt, metric_id, asset_id ORDER BY dt ASC """, parameters={ 'slug': 'bitcoin', 'metric': 'nvt', 'last_n_days': 7 }, set_index="dt" ) # The 'response' variable will contain a Pandas DataFrame with the query results. print(response.head()) ``` ### Parameters for `execute_sql` - **query** (String) - Required - The SQL query to execute. Supports named parameters. - **parameters** (Dict) - Optional - A dictionary containing key-value pairs for the named parameters in the query. - **set_index** (String) - Optional - The column name to set as the index of the resulting DataFrame. ``` -------------------------------- ### Get Trading Volume Source: https://academy.santiment.net/sansheets/functions/onchain Fetches the trading volume for a specific project slug within a given date range and currency. The data can be retrieved at specified intervals. Requires project slug, start and end dates, desired currency (USD), and the data interval. ```javascript SAN_TRADING_VOLUME(projectSlug, from, to, currency, interval) ``` -------------------------------- ### Direct API Call - runRawSqlQuery Source: https://academy.santiment.net/santiment-queries/api-access This section details how to execute raw SQL queries directly against the Santiment GraphQL API. It includes the structure of the GraphQL mutation, an example of how to parameterize queries, and a `curl` command for making the request. ```APIDOC ## POST /graphql ### Description Executes a raw SQL query against the Santiment API, allowing for direct data retrieval and manipulation. ### Method POST ### Endpoint `/graphql` ### Parameters #### Request Body - **sqlQueryText** (String) - Required - The SQL query string to be executed. Supports templated parameters. - **sqlQueryParameters** (String) - Optional - A JSON string representing the parameters to be substituted into the `sqlQueryText`. ### Request Example ```json { "runRawSqlQuery": { "sqlQueryText": "SELECT\n get_metric_name(metric_id) AS metric,\n get_asset_name(asset_id) AS asset,\n dt,\n argMax(value, computed_at) AS value\n FROM daily_metrics_v2\n WHERE\n asset_id = get_asset_id({{slug}}) AND\n metric_id = get_metric_id({{metric}}) AND\n dt >= now() - INTERVAL {{last_n_days}} DAY\n GROUP BY dt, metric_id, asset_id\n ORDER BY dt ASC", "sqlQueryParameters": "{\"slug\": \"bitcoin\", \"last_n_days\": 7, \"metric\": \"nvt\"}" } } ``` ### Response #### Success Response (200) - **columns** (Array) - An array of column names returned by the query. - **columnTypes** (Array) - An array of data types corresponding to the columns. - **rows** (Array) - An array of objects, where each object represents a row of data. #### Response Example ```json { "data": { "runRawSqlQuery": { "columns": ["metric", "asset", "dt", "value"], "columnTypes": ["String", "String", "Date", "Float"], "rows": [ {"metric": "nvt", "asset": "bitcoin", "dt": "2023-10-20", "value": 1.5}, {"metric": "nvt", "asset": "bitcoin", "dt": "2023-10-21", "value": 1.6} ] } } } ``` ### Curl Example ```bash curl 'https://api.santiment.net/graphql' \ -X POST \ -H 'Content-Type: application/graphql' \ -H 'Authorization: Apikey ' \ --data '{runRawSqlQuery(sqlQueryText: "SELECT get_metric_name(metric_id) AS metric, get_asset_name(asset_id) AS asset, dt, argMax(value, computed_at) AS value FROM daily_metrics_v2 WHERE asset_id = get_asset_id({{slug}}) AND metric_id = get_metric_id({{metric}}) AND dt >= now() - INTERVAL {{last_n_days}} DAY GROUP BY dt, metric_id, asset_id ORDER BY dt ASC", sqlQueryParameters: "{\"slug\": \"bitcoin\", \"metric\": \"nvt\", \"last_n_days\": 7}"){columns columnTypes rows}}' ``` ``` -------------------------------- ### Get Aggregated Trading Volume Source: https://academy.santiment.net/sansheets/functions/onchain Returns the aggregated trading volume for a project slug over a specified period and currency. This function is useful for obtaining a single summary value for trading volume. It requires the project slug, start and end dates, currency, and the aggregation method. ```javascript SAN_TRADING_VOLUME_AGGREGATED(projectSlug, from, to, currency, aggregation) ``` -------------------------------- ### Query Fraxlend Protocol Total Supplied (USD) with SanAPI Source: https://academy.santiment.net/metrics/lending-and-borrowing-protocols/fraxlend This code example demonstrates how to retrieve the `fraxlend_protocol_total_supplied_usd` metric through SanAPI. It allows specifying the asset slug, date range, and interval. This metric represents the total amount supplied across all assets on the Fraxlend protocol in USD. ```graphql { getMetric(metric: "fraxlend_protocol_total_supplied_usd"){ timeseriesDataJson( slug: "frax" from: "2024-11-01T00:00:00Z" to: "2024-11-07T00:00:00Z" includeIncompleteData: true interval: "5m") } } ``` -------------------------------- ### Get Top Holders Held On Exchange Source: https://academy.santiment.net/sansheets/functions/onchain Retrieves the amount of coins/tokens held exclusively by the top exchange holders for a specified project slug. The function requires the project slug, start and end dates, and the data interval. It returns an array with the relevant holding information. ```javascript SAN_TOP_HOLDERS_HELD_ON_EXCHANGE(projectSlug, from, to, interval) ``` -------------------------------- ### SQL: Calculate Total Deposits for a Platform Source: https://academy.santiment.net/santiment-queries/lending-pools Calculates the total deposits for a specific platform and token within the last 30 days. It filters events by project name, action type ('deposit'), and the input token address. ```sql SELECT SUM(amount_in) FROM lending_pools_events WHERE project_name = 'aave_v2' AND action = 'deposit' AND token_in = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' AND dt >= now() - interval 30 DAY ``` -------------------------------- ### Get All Projects Source: https://academy.santiment.net/sanapi/fetching-metrics Retrieve a list of all supported projects with their slugs, names, and tickers. ```APIDOC ## GET /graphql ### Description Fetches a list of all supported projects, including their unique slug, name, and ticker symbol. ### Method POST (GraphQL) ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - The GraphQL query string. ### Request Example ```json { "query": "{\n allProjects {\n slug\n name\n ticker\n }\n}" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the result of the query. - **allProjects** (Array of Objects) - List of projects. - **slug** (String) - The unique identifier for the project. - **name** (String) - The full name of the project. - **ticker** (String) - The ticker symbol for the project. ``` -------------------------------- ### Get Top Holders Held Off Exchange Source: https://academy.santiment.net/sansheets/functions/onchain Returns the amount of coins/tokens held exclusively by the top non-exchange holders for a given project slug. This function requires the project slug, start and end dates, and the desired data interval. The output is an array detailing the holdings. ```javascript SAN_TOP_HOLDERS_HELD_OFF_EXCHANGE(projectSlug, from, to, interval) ``` -------------------------------- ### Get Aggregated Token Circulation Source: https://academy.santiment.net/sansheets/functions/onchain Retrieves the aggregated token circulation for a specified project slug and time interval. It requires the project slug, start and end dates, a time bound, and an aggregation method. The function returns a single number representing the aggregated circulation. ```javascript SAN_TOKEN_CIRCULATION_AGGREGATED(projectSlug, from, to, timeBound, aggregation) ``` -------------------------------- ### Querying Santiment Metrics with Wildcards Source: https://academy.santiment.net/for-developers/metrics-exported-s3 This section details how to use wildcards in S3 paths to query multiple files at once for Santiment metrics. It covers wildcard usage for interval, metric name, year, and month, and provides a comprehensive SQL example to query intraday price data for a specific asset across all months in a given year. ```APIDOC ## Querying Santiment Metrics with Wildcards You can use wildcards in the S3 path to query multiple files at once. The following components support wildcard patterns: * **Interval** : `intraday` or `daily` * **Metric name** : `price_usd`, `active_addresses`, etc. * **Year** : `2024`, `2023`, etc. * **Month** : `01`, `02`, ..., `12` ### Example: Query all months in 2024 for a specific metric ```sql SELECT assets.name AS asset, metrics.name AS metric, dt, value FROM s3( url='s3://santiment-metrics/metrics/intraday/price_usd/2024/*/data.parquet', access_key_id='YOUR_KEY_ID', secret_access_key='YOUR_KEY_SECRET', format='Parquet' ) AS data LEFT JOIN ( SELECT asset_id, name FROM s3( url='s3://santiment-metrics/assets.parquet', access_key_id='YOUR_KEY_ID', secret_access_key='YOUR_KEY_SECRET', format='Parquet' ) ) AS assets USING asset_id LEFT JOIN ( SELECT metric_id, name FROM s3( url='s3://santiment-metrics/metrics.parquet', access_key_id='YOUR_KEY_ID', secret_access_key='YOUR_KEY_SECRET', format='Parquet' ) ) AS metrics ON metrics.metric_id = data.metric_id WHERE asset.name = 'bitcoin'; ``` ### Intraday vs Daily Metrics #### Intraday Metrics * **Path** : `s3://santiment-metrics/metrics/intraday/{metric_name}/{year}/{month}/data.parquet` * **Granularity** : 5-minute intervals * **Use cases** : Intraday trading, detailed analysis, real-time monitoring #### Daily Metrics * **Path** : `s3://santiment-metrics/metrics/daily/{metric_name}/{year}/{month}/data.parquet` * **Granularity** : Daily aggregated values * **Use cases** : Long-term trend analysis, reduced data volume, historical comparisons ``` -------------------------------- ### Get All Supported Projects Source: https://academy.santiment.net/sanapi/fetching-metrics Fetches a list of all supported projects (assets) including their slug, name, and ticker symbol. This information is essential for querying metrics related to specific assets. ```graphql { allProjects { slug name ticker } } ```