Query editor
-- DefiLlama open interest daily breakdown by protocolWITH oi_json AS (SELECT json_parse(http_get('https://api.llama.fi/overview/open-interest')) AS j),oi_arr AS (SELECT COALESCE(json_extract(j, '$.openInterestChartBreakdown'),json_extract(j, '$.totalOpenInterestChartBreakdown'),json_extract(j, '$.totalDataChartBreakdown')) AS arrFROM oi_json),daily_raw AS (SELECTdate_trunc('day', from_unixtime(CAST(json_extract_scalar(item, '$[0]') AS bigint))) AS day,json_extract(item, '$[1]') AS kv_jsonFROM oi_arrCROSS JOIN UNNEST(CAST(json_extract(arr, '$') AS array(json))) AS t(item)),daily_oi AS (SELECTday,regexp_replace(regexp_replace(regexp_replace(regexp_replace(lower(key),'(?:\\s+perps?|\\s+protocol|\\s+perpetuals?|\\s+pro)\\s*$', ''),'\\s+v[0-9]+\\s*$', ''),'\\s+', ' '),'[^a-z0-9 ]', '') AS protocol,CAST(value AS double) AS oi_valueFROM daily_rawCROSS JOIN UNNEST(CAST(kv_json AS map(varchar, double))) AS t(key, value)WHERE value IS NOT NULL)SELECTday,protocol,oi_value AS daily_oiFROM daily_oiORDER BY day, protocol