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:
Jack Forgash 2022-06-02 12:17:34 -06:00 committed by GitHub
parent a005424621
commit 19841544e8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 277 additions and 1 deletions

View 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

View 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

View 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

View File

@ -0,0 +1,5 @@
{% docs asset_id %}
Identifier used by the CoinMarketCap or CoinGecko APIs.
{% enddocs %}

View File

@ -0,0 +1,5 @@
{% docs market_cap %}
Total market cap of the token, where available, in USD.
{% enddocs %}

View File

@ -0,0 +1,5 @@
{% docs price_usd %}
Asset price, in USD.
{% enddocs %}

View 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 %}

View 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 %}

View File

@ -0,0 +1,5 @@
{% docs symbol %}
Short-name symbol for the crypto token, e.g. BLT.
{% enddocs %}

View 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 %}

View File

@ -0,0 +1,5 @@
{% docs token %}
Friendly name of the crypto token, e.g. Blocto Token.
{% enddocs %}

View 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

View 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

View File

@ -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