mirror of
https://github.com/FlipsideCrypto/flow-models.git
synced 2026-02-06 13:41:55 +00:00
AN-1344/prices (#24)
* cmc prices * gecko prices * adjust $ * core view, no description yet pending swap prices * prices * price to price_usd * address nulls and del mcap * tests * test fix
This commit is contained in:
parent
a005424621
commit
19841544e8
34
models/bronze/bronze__prices.sql
Normal file
34
models/bronze/bronze__prices.sql
Normal file
@ -0,0 +1,34 @@
|
||||
{{ config(
|
||||
materialized = 'view'
|
||||
) }}
|
||||
|
||||
WITH token_prices AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ source(
|
||||
'silver',
|
||||
'prices_v2'
|
||||
) }}
|
||||
WHERE
|
||||
asset_id IN (
|
||||
'4558',
|
||||
-- Flow
|
||||
'6993',
|
||||
-- Revv
|
||||
'12182',
|
||||
-- Blocto Token
|
||||
'15139',
|
||||
-- Starly
|
||||
'flow',
|
||||
'revv',
|
||||
'starly',
|
||||
'blocto-token'
|
||||
)
|
||||
AND provider IS NOT NULL
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
token_prices
|
||||
20
models/core/core__fact_prices.sql
Normal file
20
models/core/core__fact_prices.sql
Normal file
@ -0,0 +1,20 @@
|
||||
{{ config(
|
||||
materialized = 'view'
|
||||
) }}
|
||||
|
||||
WITH prices AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('silver__prices') }}
|
||||
)
|
||||
SELECT
|
||||
recorded_at AS TIMESTAMP,
|
||||
asset_id,
|
||||
token,
|
||||
symbol,
|
||||
price_usd,
|
||||
source
|
||||
FROM
|
||||
prices
|
||||
63
models/core/core__fact_prices.yml
Normal file
63
models/core/core__fact_prices.yml
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: core__fact_prices
|
||||
description: |-
|
||||
This table provides token price data for FLOW tokens.
|
||||
|
||||
columns:
|
||||
- name: timestamp
|
||||
description: "{{ doc('timestamp') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
|
||||
- name: asset_id
|
||||
description: "{{ doc('asset_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- NUMBER
|
||||
- VARCHAR
|
||||
|
||||
- name: token
|
||||
description: "{{ doc('token') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: symbol
|
||||
description: "{{ doc('symbol') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: price_usd
|
||||
description: "{{ doc('price_usd') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- DOUBLE
|
||||
- FLOAT
|
||||
|
||||
- name: source
|
||||
description: "{{ doc('source') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
5
models/descriptions/asset_id.md
Normal file
5
models/descriptions/asset_id.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs asset_id %}
|
||||
|
||||
Identifier used by the CoinMarketCap or CoinGecko APIs.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/market_cap.md
Normal file
5
models/descriptions/market_cap.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs market_cap %}
|
||||
|
||||
Total market cap of the token, where available, in USD.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/price_usd.md
Normal file
5
models/descriptions/price_usd.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs price_usd %}
|
||||
|
||||
Asset price, in USD.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/recorded_at.md
Normal file
5
models/descriptions/recorded_at.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs recorded_at %}
|
||||
|
||||
Timestamp of when the data was recorded from the API or from on-chain data, depending on the source.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/source.md
Normal file
5
models/descriptions/source.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs source %}
|
||||
|
||||
Data source for the record in question. E.g. for the prices table, this may be an API.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/symbol.md
Normal file
5
models/descriptions/symbol.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs symbol %}
|
||||
|
||||
Short-name symbol for the crypto token, e.g. BLT.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/timestamp.md
Normal file
5
models/descriptions/timestamp.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs timestamp %}
|
||||
|
||||
Timestamp of when the data was recorded from the API or from on-chain data, depending on the source.
|
||||
|
||||
{% enddocs %}
|
||||
5
models/descriptions/token.md
Normal file
5
models/descriptions/token.md
Normal file
@ -0,0 +1,5 @@
|
||||
{% docs token %}
|
||||
|
||||
Friendly name of the crypto token, e.g. Blocto Token.
|
||||
|
||||
{% enddocs %}
|
||||
49
models/silver/silver__prices.sql
Normal file
49
models/silver/silver__prices.sql
Normal file
@ -0,0 +1,49 @@
|
||||
{{ config(
|
||||
materialized = 'incremental',
|
||||
incremental_strategy = 'delete+insert',
|
||||
cluster_by = ['recorded_at'],
|
||||
unique_key = "concat_ws( '-', recorded_at, asset_id )"
|
||||
) }}
|
||||
|
||||
WITH token_prices AS (
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
{{ ref('bronze__prices') }}
|
||||
|
||||
{% if is_incremental() %}
|
||||
WHERE
|
||||
recorded_at :: DATE >= CURRENT_DATE - 2
|
||||
{% endif %}
|
||||
),
|
||||
prices AS (
|
||||
SELECT
|
||||
recorded_at,
|
||||
asset_id,
|
||||
NAME AS token,
|
||||
SPLIT(
|
||||
symbol,
|
||||
'$'
|
||||
) AS symbol_split,
|
||||
symbol_split [array_size(symbol_split) - 1] :: STRING AS symbol,
|
||||
price,
|
||||
provider AS source
|
||||
FROM
|
||||
token_prices
|
||||
),
|
||||
FINAL AS (
|
||||
SELECT
|
||||
recorded_at,
|
||||
asset_id,
|
||||
token,
|
||||
symbol,
|
||||
price AS price_usd,
|
||||
source
|
||||
FROM
|
||||
prices
|
||||
)
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
FINAL
|
||||
63
models/silver/silver__prices.yml
Normal file
63
models/silver/silver__prices.yml
Normal file
@ -0,0 +1,63 @@
|
||||
|
||||
version: 2
|
||||
|
||||
models:
|
||||
- name: silver__prices
|
||||
description: |-
|
||||
This table provides token price data for FLOW tokens.
|
||||
|
||||
columns:
|
||||
- name: recorded_at
|
||||
description: "{{ doc('recorded_at') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- TIMESTAMP_NTZ
|
||||
|
||||
- name: asset_id
|
||||
description: "{{ doc('asset_id') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- NUMBER
|
||||
- VARCHAR
|
||||
|
||||
- name: token
|
||||
description: "{{ doc('token') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: symbol
|
||||
description: "{{ doc('symbol') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
|
||||
- name: price_usd
|
||||
description: "{{ doc('price_usd') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- NUMBER
|
||||
- FLOAT
|
||||
- DOUBLE
|
||||
|
||||
- name: source
|
||||
description: "{{ doc('source') }}"
|
||||
tests:
|
||||
- not_null
|
||||
- dbt_expectations.expect_column_values_to_be_in_type_list:
|
||||
column_type_list:
|
||||
- STRING
|
||||
- VARCHAR
|
||||
@ -12,4 +12,11 @@ sources:
|
||||
database: flipside_prod_db
|
||||
schema: crosschain
|
||||
tables:
|
||||
- name: address_labels
|
||||
- name: address_labels
|
||||
|
||||
- name: silver
|
||||
database: flipside_prod_db
|
||||
schema: silver
|
||||
tables:
|
||||
- name: market_asset_metadata
|
||||
- name: prices_v2
|
||||
|
||||
Loading…
Reference in New Issue
Block a user