freemartianOpen Position Table
Updated 2023-02-21
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
›
⌄
--closeposition
with Close_Position AS (
SELECT
tx_hash,
block_timestamp,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
topics[1] AS PositionID,
CONCAT('0x', substr(topics[2] :: STRING, 27, 42)) AS User_Address,
ethereum.public.udf_hex_to_int(segmented_data [2] :: STRING)/pow(10,8) AS Margin,
ethereum.public.udf_hex_to_int(segmented_data [3] :: STRING)/pow(10,8) AS Leverage,
ethereum.public.udf_hex_to_int(segmented_data [4] :: STRING)/pow(10,8) AS Fee,
ethereum.public.udf_hex_to_int(segmented_data [5] :: STRING)/pow(10,8) AS PNL,
ethereum.public.udf_hex_to_int(segmented_data [6] :: STRING)/pow(10,8) AS Funding,
ethereum.public.udf_hex_to_int(segmented_data [7] :: STRING)/pow(10,8) AS Liquidation_Status
FROM
optimism.core.fact_event_logs
WHERE topics[0] IN ('0x980658f6b65b51ce7d353bc2f9110e33617a69ab8dd85ed76e70546542ebea25')),
execute_close_position as (
SELECT
tx_hash,
block_timestamp,
regexp_substr_all(SUBSTR(DATA, 3, len(DATA)), '.{64}') AS segmented_data,
CONCAT('0x', substr(topics[1] :: STRING, 27, 42)) AS User_Address,
ethereum.public.udf_hex_to_int(segmented_data [0] :: STRING) AS ProductID,
ethereum.public.udf_hex_to_int(segmented_data [1] :: STRING)/pow(10,8) AS Execution_Fee,
ethereum.public.udf_hex_to_int(segmented_data [2] :: STRING) AS Direction
FROM
optimism.core.fact_event_logs
WHERE topics[0] IN ('0x2046b424b7127be8956b05668e8428ddce5e695b9e5f9958d304faf72cc58104')),
close_table AS (
select
cp.tx_hash,
cp.block_timestamp,
Run a query to Download Data