-
Notifications
You must be signed in to change notification settings - Fork 1.4k
add columns to polymarket models #9107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 51 commits
b428969
836fb35
6dbe439
6621cfa
60c35bb
8c74bca
f25cda4
0f9c1ab
fe719c6
151497e
9113b9f
01ef68c
f898a34
e9e44e7
11daa3f
efa32af
7b143e8
85d8be5
259287a
351bda9
b025811
ea14ab4
1bcf5af
3be098b
c2ce5a4
8295e84
c269a9d
0c92d76
b40416f
3fe69d9
c6be77f
1f9bda4
23f755b
35f1eeb
2783ec6
6b32759
4185473
9592bca
3942db8
b2127f5
e69eb26
c45d3aa
d775b77
b633a4c
b35c67b
eaa70cd
2d09578
e7a8a76
7324138
86f5b7e
b3318b8
b9d73fa
1da6695
ab14d22
3c2b8b6
47f0c0a
35d467f
0d65573
2a36011
3190f2a
ba03028
65e2258
715b398
4e7fa7f
98f2b04
990ae43
039e4b9
4c6e5b7
464a8f5
1667e5b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -93,8 +93,14 @@ SELECT | |||||||||||||
| WHEN lower(neg_risk) = 'false' THEN get_href('https://polymarket.com/event/' || market_slug, market_slug) | ||||||||||||||
| WHEN lower(neg_risk) = 'true' THEN get_href('https://polymarket.com/event/' || replace(replace(replace(lower(neg_risk_market_name), ' ', '-'), '$', ''), '''',''), neg_risk_market_name) | ||||||||||||||
| END AS polymarket_link, | ||||||||||||||
| CASE | ||||||||||||||
| WHEN lower(neg_risk) = 'false' THEN market_slug | ||||||||||||||
| WHEN lower(neg_risk) = 'true' THEN replace(replace(replace(lower(neg_risk_market_name), ' ', '-'), '$', ''), '''','') | ||||||||||||||
| END AS polymarket_link_slug, | ||||||||||||||
| accepting_order_timestamp as market_start_time, | ||||||||||||||
| date_parse(SUBSTRING(accepting_order_timestamp FROM 1 FOR 19), '%Y-%m-%dT%H:%i:%s') as market_start_time_parsed, | ||||||||||||||
| end_date_iso as market_end_time, | ||||||||||||||
| date_parse(SUBSTRING(end_date_iso FROM 1 FOR 19), '%Y-%m-%dT%H:%i:%s') as market_end_time_parsed, | ||||||||||||||
|
||||||||||||||
| date_parse(SUBSTRING(accepting_order_timestamp FROM 1 FOR 19), '%Y-%m-%dT%H:%i:%s') as market_start_time_parsed, | |
| end_date_iso as market_end_time, | |
| date_parse(SUBSTRING(end_date_iso FROM 1 FOR 19), '%Y-%m-%dT%H:%i:%s') as market_end_time_parsed, | |
| try(date_parse(SUBSTRING(accepting_order_timestamp FROM 1 FOR 19), '%Y-%m-%dT%H:%i:%s')) as market_start_time_parsed, | |
| end_date_iso as market_end_time, | |
| try(date_parse(SUBSTRING(end_date_iso FROM 1 FOR 19), '%Y-%m-%dT%H:%i:%s')) as market_end_time_parsed, |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@dbt_subprojects/daily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_market_details.sql`
around lines 101 - 103, The date_parse calls for accepting_order_timestamp and
end_date_iso (which produce market_start_time_parsed and market_end_time_parsed)
can fail on malformed API timestamps; wrap each date_parse(...) expression in
try(...) so parsing errors return null instead of failing the model — i.e.,
replace the raw date_parse(SUBSTRING(...), '%Y-%m-%dT%H:%i:%s') usages for
accepting_order_timestamp and end_date_iso with try(date_parse(SUBSTRING(...),
'%Y-%m-%dT%H:%i:%s')) to make parsing resilient.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Normalize both sides of the outcome comparison for final_price.
LOWER(token_outcome) = outcome is still case-sensitive on outcome; mixed-case outcome values can be incorrectly priced as 0.
Proposed comparison fix
- WHEN LOWER(token_outcome) = outcome THEN 1
+ WHEN LOWER(token_outcome) = LOWER(outcome) THEN 1📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| CASE WHEN outcome = '50/50' THEN 0.5 | |
| WHEN LOWER(token_outcome) = outcome THEN 1 | |
| WHEN outcome != 'unresolved' THEN 0 END AS final_price | |
| CASE WHEN outcome = '50/50' THEN 0.5 | |
| WHEN LOWER(token_outcome) = LOWER(outcome) THEN 1 | |
| WHEN outcome != 'unresolved' THEN 0 END AS final_price |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In
`@dbt_subprojects/daily_spellbook/models/_projects/polymarket/polygon/polymarket_polygon_market_details.sql`
around lines 123 - 125, The final_price CASE uses LOWER(token_outcome) = outcome
which still compares against a case-sensitive outcome; update the comparison to
normalize both sides (e.g., compare LOWER(token_outcome) to LOWER(outcome)) so
mixed-case outcome values are matched correctly; update the conditional in the
CASE that sets final_price (referencing token_outcome and outcome) accordingly.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| {{ | ||
| config( | ||
| schema = 'polymarket_polygon', | ||
| alias = 'open_positions', | ||
| materialized = 'view', | ||
| post_hook = '{{ expose_spells(blockchains = \'["polygon"]\', | ||
| spell_type = "project", | ||
| spell_name = "polymarket", | ||
| contributors = \'["hildobby"]\') }}' | ||
| ) | ||
| }} | ||
|
|
||
| WITH latest_day AS ( | ||
| SELECT MAX(day) AS day | ||
| FROM {{ ref('polymarket_polygon_positions_raw') }} | ||
| ) | ||
|
|
||
| , open_positions AS ( | ||
| SELECT | ||
| p.address, | ||
| mm.unique_key, | ||
| p.token_id, | ||
| mm.token_outcome, | ||
| mm.token_outcome_name, | ||
| p.balance, | ||
| mm.question_id, | ||
| mm.question AS market_question, | ||
| mm.market_description, | ||
| mm.event_market_name, | ||
| mm.event_market_description, | ||
| mm.active, | ||
| mm.closed, | ||
| mm.accepting_orders, | ||
| mm.polymarket_link, | ||
| mm.polymarket_link_slug, | ||
| mm.market_start_time, | ||
| mm.market_start_time_parsed, | ||
| mm.market_end_time, | ||
| mm.market_end_time_parsed, | ||
| mm.outcome AS market_outcome, | ||
| mm.resolved_on_timestamp, | ||
| mm.final_price | ||
| FROM {{ ref('polymarket_polygon_positions_raw') }} p | ||
| INNER JOIN latest_day ld ON p.day = ld.day | ||
| INNER JOIN {{ ref('polymarket_polygon_market_details') }} mm ON p.token_id = mm.token_id | ||
| ) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Open positions view includes zero-balance closed positionsMedium Severity The |
||
|
|
||
| SELECT op.address, | ||
| op.unique_key, | ||
| token_id, | ||
| op.token_outcome, | ||
| op.token_outcome_name, | ||
| op.balance, | ||
| op.balance*(CASE WHEN op.market_end_time_parsed IS NULL | ||
| OR p.last_updated <= op.market_end_time_parsed | ||
| THEN p.latest_price | ||
| ELSE COALESCE(final_price, 0) | ||
| END) AS open_interest, | ||
| CASE WHEN op.market_end_time_parsed IS NULL | ||
| OR p.last_updated <=op.market_end_time_parsed | ||
| THEN p.latest_price | ||
| ELSE COALESCE(final_price, 0) | ||
| END AS latest_price, | ||
hildobby marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| op.question_id, | ||
| op.market_question, | ||
| op.market_description, | ||
| op.event_market_name, | ||
| op.event_market_description, | ||
| op.active, | ||
| op.closed, | ||
| op.accepting_orders, | ||
| op.polymarket_link, | ||
| op.polymarket_link_slug, | ||
| op.market_start_time, | ||
| op.market_start_time_parsed, | ||
| op.market_end_time, | ||
| op.market_end_time_parsed, | ||
| op.market_outcome, | ||
| op.resolved_on_timestamp | ||
| FROM open_positions op | ||
| LEFT JOIN {{ ref('polymarket_polygon_market_prices_latest') }} p USING (token_id) | ||
Uh oh!
There was an error while loading. Please reload this page.