From 2acf7b0c0701e9facf827180d22b57f473456e91 Mon Sep 17 00:00:00 2001 From: Troy Date: Thu, 21 Dec 2023 15:42:21 -0700 Subject: [PATCH 1/3] add hourly and daily setting --- .../modules/base_goerli/perp_integrators.py | 40 +++++++++----- dashboard/modules/base_goerli/perp_monitor.py | 53 +++++++++++-------- .../modules/base_mainnet/perp_integrators.py | 40 +++++++++----- .../modules/base_mainnet/perp_monitor.py | 51 ++++++++++-------- 4 files changed, 112 insertions(+), 72 deletions(-) diff --git a/dashboard/modules/base_goerli/perp_integrators.py b/dashboard/modules/base_goerli/perp_integrators.py index 18a77d63..5b701dff 100644 --- a/dashboard/modules/base_goerli/perp_integrators.py +++ b/dashboard/modules/base_goerli/perp_integrators.py @@ -14,7 +14,14 @@ def fetch_data(): db = get_connection() # get account data - df_stats = pd.read_sql_query( + df_hourly_stats = pd.read_sql_query( + f""" + SELECT * FROM base_goerli.fct_perp_tracking_stats_hourly + """, + db, + ) + + df_daily_stats = pd.read_sql_query( f""" SELECT * FROM base_goerli.fct_perp_tracking_stats_daily """, @@ -24,33 +31,34 @@ def fetch_data(): db.close() return { - "stats": df_stats, + "hourly_stats": df_hourly_stats, + "daily_stats": df_daily_stats, } @st.cache_data(ttl=1) -def make_charts(data): +def make_charts(data, settings): + df_stats = data[f"{settings['resolution']}_stats"] + return { "accounts": chart_bars( - data["stats"], "ts", ["accounts"], "Accounts", color="tracking_code" + df_stats, "ts", ["accounts"], "Accounts", color="tracking_code" ), "volume": chart_bars( - data["stats"], "ts", ["volume"], "Volume", color="tracking_code" + df_stats, "ts", ["volume"], "Volume", color="tracking_code" ), "volume_pct": chart_bars( - data["stats"], "ts", ["volume_share"], "Volume %", color="tracking_code" + df_stats, "ts", ["volume_share"], "Volume %", color="tracking_code" ), "trades": chart_bars( - data["stats"], "ts", ["trades"], "Trades", color="tracking_code" + df_stats, "ts", ["trades"], "Trades", color="tracking_code" ), "trades_pct": chart_bars( - data["stats"], "ts", ["trades_share"], "Trades %", color="tracking_code" - ), - "fees": chart_bars( - data["stats"], "ts", ["fees"], "Fees", color="tracking_code" + df_stats, "ts", ["trades_share"], "Trades %", color="tracking_code" ), + "fees": chart_bars(df_stats, "ts", ["fees"], "Fees", color="tracking_code"), "fees_pct": chart_bars( - data["stats"], "ts", ["fees_share"], "Volume %", color="tracking_code" + df_stats, "ts", ["fees_share"], "Volume %", color="tracking_code" ), } @@ -59,10 +67,14 @@ def main(): ## fetch data data = fetch_data() - ## do some lighter transforms + ## inputs + with st.expander("Settings") as expander: + resolution = st.radio("Resolution", ["daily", "hourly"]) + + settings = {"resolution": resolution} ## make the charts - charts = make_charts(data) + charts = make_charts(data, settings) ## display st.markdown("## Perps V3 Integrators") diff --git a/dashboard/modules/base_goerli/perp_monitor.py b/dashboard/modules/base_goerli/perp_monitor.py index c172caee..d75fcd86 100644 --- a/dashboard/modules/base_goerli/perp_monitor.py +++ b/dashboard/modules/base_goerli/perp_monitor.py @@ -28,11 +28,21 @@ def fetch_data(): "SELECT * FROM base_goerli.fct_perp_liq_position", db ) - # create hourly data + # hourly data df_hourly_market = pd.read_sql_query( "SELECT * FROM base_goerli.fct_perp_market_stats_hourly", db ) - df_hourly = pd.read_sql_query("SELECT * FROM base_goerli.fct_perp_stats_hourly", db) + df_hourly_stats = pd.read_sql_query( + "SELECT * FROM base_goerli.fct_perp_stats_hourly", db + ) + + # daily data + df_daily_market = pd.read_sql_query( + "SELECT * FROM base_goerli.fct_perp_market_stats_daily", db + ) + df_daily_stats = pd.read_sql_query( + "SELECT * FROM base_goerli.fct_perp_stats_daily", db + ) db.close() @@ -43,34 +53,35 @@ def fetch_data(): "account_liq": df_account_liq, "position_liq": df_position_liq, "hourly_market": df_hourly_market, - "hourly": df_hourly, + "hourly_stats": df_hourly_stats, + "daily_market": df_daily_market, + "daily_stats": df_daily_stats, } @st.cache_data(ttl=1) -def make_charts(data): +def make_charts(data, settings): + df_market = data[f"{settings['resolution']}_market"] + df_stats = data[f"{settings['resolution']}_stats"] + return { - "volume": chart_bars( - data["hourly_market"], "ts", ["volume"], "Volume", "market_symbol" - ), + "volume": chart_bars(df_market, "ts", ["volume"], "Volume", "market_symbol"), "exchange_fees": chart_bars( - data["hourly_market"], "ts", ["fees"], "Exchange Fees", "market_symbol" - ), - "trades": chart_bars( - data["hourly_market"], "ts", ["trades"], "Trades", "market_symbol" + df_market, "ts", ["fees"], "Exchange Fees", "market_symbol" ), + "trades": chart_bars(df_market, "ts", ["trades"], "Trades", "market_symbol"), "position_liquidations": chart_bars( - data["hourly_market"], + df_market, "ts", ["liquidations"], "Position Liquidations", "market_symbol", ), "account_liquidations": chart_bars( - data["hourly"], "ts", ["liquidated_accounts"], "Account Liquidations" + df_stats, "ts", ["liquidated_accounts"], "Account Liquidations" ), "liquidation_rewards": chart_bars( - data["hourly"], "ts", ["liquidation_rewards"], "Liquidation Rewards" + df_stats, "ts", ["liquidation_rewards"], "Liquidation Rewards" ), } @@ -86,18 +97,16 @@ def main(): ) ## inputs - filt_col1, filt_col2 = st.columns(2) - with filt_col1: - start_date = st.date_input("Start", datetime.today().date() - timedelta(days=3)) - - with filt_col2: - end_date = st.date_input("End", datetime.today().date()) - with st.expander("Filter markets"): assets_filter = st.multiselect("Select markets", assets, default=assets) + with st.expander("Settings") as expander: + resolution = st.radio("Resolution", ["daily", "hourly"]) + + settings = {"resolution": resolution} + ## make the charts - charts = make_charts(data) + charts = make_charts(data, settings) ## display col1, col2 = st.columns(2) diff --git a/dashboard/modules/base_mainnet/perp_integrators.py b/dashboard/modules/base_mainnet/perp_integrators.py index 2478e0ac..f4a979ee 100644 --- a/dashboard/modules/base_mainnet/perp_integrators.py +++ b/dashboard/modules/base_mainnet/perp_integrators.py @@ -14,7 +14,14 @@ def fetch_data(): db = get_connection() # get account data - df_stats = pd.read_sql_query( + df_hourly_stats = pd.read_sql_query( + f""" + SELECT * FROM base_mainnet.fct_perp_tracking_stats_hourly + """, + db, + ) + + df_daily_stats = pd.read_sql_query( f""" SELECT * FROM base_mainnet.fct_perp_tracking_stats_daily """, @@ -24,33 +31,34 @@ def fetch_data(): db.close() return { - "stats": df_stats, + "hourly_stats": df_hourly_stats, + "daily_stats": df_daily_stats, } @st.cache_data(ttl=1) -def make_charts(data): +def make_charts(data, settings): + df_stats = data[f"{settings['resolution']}_stats"] + return { "accounts": chart_bars( - data["stats"], "ts", ["accounts"], "Accounts", color="tracking_code" + df_stats, "ts", ["accounts"], "Accounts", color="tracking_code" ), "volume": chart_bars( - data["stats"], "ts", ["volume"], "Volume", color="tracking_code" + df_stats, "ts", ["volume"], "Volume", color="tracking_code" ), "volume_pct": chart_bars( - data["stats"], "ts", ["volume_share"], "Volume %", color="tracking_code" + df_stats, "ts", ["volume_share"], "Volume %", color="tracking_code" ), "trades": chart_bars( - data["stats"], "ts", ["trades"], "Trades", color="tracking_code" + df_stats, "ts", ["trades"], "Trades", color="tracking_code" ), "trades_pct": chart_bars( - data["stats"], "ts", ["trades_share"], "Trades %", color="tracking_code" - ), - "fees": chart_bars( - data["stats"], "ts", ["fees"], "Fees", color="tracking_code" + df_stats, "ts", ["trades_share"], "Trades %", color="tracking_code" ), + "fees": chart_bars(df_stats, "ts", ["fees"], "Fees", color="tracking_code"), "fees_pct": chart_bars( - data["stats"], "ts", ["fees_share"], "Volume %", color="tracking_code" + df_stats, "ts", ["fees_share"], "Volume %", color="tracking_code" ), } @@ -59,10 +67,14 @@ def main(): ## fetch data data = fetch_data() - ## do some lighter transforms + ## inputs + with st.expander("Settings") as expander: + resolution = st.radio("Resolution", ["daily", "hourly"]) + + settings = {"resolution": resolution} ## make the charts - charts = make_charts(data) + charts = make_charts(data, settings) ## display st.markdown("## Perps V3 Integrators") diff --git a/dashboard/modules/base_mainnet/perp_monitor.py b/dashboard/modules/base_mainnet/perp_monitor.py index 439f36b1..9ecb7180 100644 --- a/dashboard/modules/base_mainnet/perp_monitor.py +++ b/dashboard/modules/base_mainnet/perp_monitor.py @@ -28,14 +28,22 @@ def fetch_data(): "SELECT * FROM base_mainnet.fct_perp_liq_position", db ) - # create hourly data + # hourly data df_hourly_market = pd.read_sql_query( "SELECT * FROM base_mainnet.fct_perp_market_stats_hourly", db ) - df_hourly = pd.read_sql_query( + df_hourly_stats = pd.read_sql_query( "SELECT * FROM base_mainnet.fct_perp_stats_hourly", db ) + # daily data + df_daily_market = pd.read_sql_query( + "SELECT * FROM base_mainnet.fct_perp_market_stats_daily", db + ) + df_daily_stats = pd.read_sql_query( + "SELECT * FROM base_mainnet.fct_perp_stats_daily", db + ) + db.close() return { @@ -45,34 +53,35 @@ def fetch_data(): "account_liq": df_account_liq, "position_liq": df_position_liq, "hourly_market": df_hourly_market, - "hourly": df_hourly, + "hourly_stats": df_hourly_stats, + "daily_market": df_daily_market, + "daily_stats": df_daily_stats, } @st.cache_data(ttl=1) -def make_charts(data): +def make_charts(data, settings): + df_market = data[f"{settings['resolution']}_market"] + df_stats = data[f"{settings['resolution']}_stats"] + return { - "volume": chart_bars( - data["hourly_market"], "ts", ["volume"], "Volume", "market_symbol" - ), + "volume": chart_bars(df_market, "ts", ["volume"], "Volume", "market_symbol"), "exchange_fees": chart_bars( - data["hourly_market"], "ts", ["fees"], "Exchange Fees", "market_symbol" - ), - "trades": chart_bars( - data["hourly_market"], "ts", ["trades"], "Trades", "market_symbol" + df_market, "ts", ["fees"], "Exchange Fees", "market_symbol" ), + "trades": chart_bars(df_market, "ts", ["trades"], "Trades", "market_symbol"), "position_liquidations": chart_bars( - data["hourly_market"], + df_market, "ts", ["liquidations"], "Position Liquidations", "market_symbol", ), "account_liquidations": chart_bars( - data["hourly"], "ts", ["liquidated_accounts"], "Account Liquidations" + df_stats, "ts", ["liquidated_accounts"], "Account Liquidations" ), "liquidation_rewards": chart_bars( - data["hourly"], "ts", ["liquidation_rewards"], "Liquidation Rewards" + df_stats, "ts", ["liquidation_rewards"], "Liquidation Rewards" ), } @@ -88,18 +97,16 @@ def main(): ) ## inputs - filt_col1, filt_col2 = st.columns(2) - with filt_col1: - start_date = st.date_input("Start", datetime.today().date() - timedelta(days=3)) - - with filt_col2: - end_date = st.date_input("End", datetime.today().date()) - with st.expander("Filter markets"): assets_filter = st.multiselect("Select markets", assets, default=assets) + with st.expander("Settings") as expander: + resolution = st.radio("Resolution", ["daily", "hourly"]) + + settings = {"resolution": resolution} + ## make the charts - charts = make_charts(data) + charts = make_charts(data, settings) ## display col1, col2 = st.columns(2) From 5072c2f1c6fe982c24c328947004f6691e803153 Mon Sep 17 00:00:00 2001 From: Troy Date: Thu, 21 Dec 2023 15:43:25 -0700 Subject: [PATCH 2/3] remove date filter --- dashboard/modules/base_goerli/perp_account.py | 9 --------- dashboard/modules/base_mainnet/perp_account.py | 9 --------- 2 files changed, 18 deletions(-) diff --git a/dashboard/modules/base_goerli/perp_account.py b/dashboard/modules/base_goerli/perp_account.py index 2c4d8692..b48bb31e 100644 --- a/dashboard/modules/base_goerli/perp_account.py +++ b/dashboard/modules/base_goerli/perp_account.py @@ -110,15 +110,6 @@ def main(): if len(account_numbers) > 0: st.dataframe(account_numbers, hide_index=True) - filt_col1, filt_col2 = st.columns(2) - with filt_col1: - start_date = st.date_input( - "Start", datetime.today().date() - timedelta(days=30) - ) - - with filt_col2: - end_date = st.date_input("End", datetime.today().date()) - accounts = data["accounts"]["id"].unique() accounts = sorted(list([int(_) for _ in accounts])) account = st.selectbox("Select account", accounts, index=0) diff --git a/dashboard/modules/base_mainnet/perp_account.py b/dashboard/modules/base_mainnet/perp_account.py index abe42f65..eba0b123 100644 --- a/dashboard/modules/base_mainnet/perp_account.py +++ b/dashboard/modules/base_mainnet/perp_account.py @@ -110,15 +110,6 @@ def main(): if len(account_numbers) > 0: st.dataframe(account_numbers, hide_index=True) - filt_col1, filt_col2 = st.columns(2) - with filt_col1: - start_date = st.date_input( - "Start", datetime.today().date() - timedelta(days=30) - ) - - with filt_col2: - end_date = st.date_input("End", datetime.today().date()) - accounts = data["accounts"]["id"].unique() accounts = sorted(list([int(_) for _ in accounts])) account = st.selectbox("Select account", accounts, index=0) From c5c67613923d40a32261187659abe1a95006af17 Mon Sep 17 00:00:00 2001 From: Troy Date: Thu, 21 Dec 2023 15:56:51 -0700 Subject: [PATCH 3/3] fix account ids --- dashboard/modules/base_goerli/perp_account.py | 257 +++++++++--------- dashboard/modules/base_goerli/perp_monitor.py | 10 +- .../modules/base_mainnet/perp_account.py | 28 +- .../modules/base_mainnet/perp_monitor.py | 10 +- .../core/fct_core_account_delegation.sql | 4 +- .../marts/perp/fct_perp_liq_account.sql | 4 +- .../marts/perp/fct_perp_liq_position.sql | 4 +- .../models/marts/perp/fct_perp_orders.sql | 4 +- .../models/marts/perp/fct_perp_trades.sql | 4 +- 9 files changed, 182 insertions(+), 143 deletions(-) diff --git a/dashboard/modules/base_goerli/perp_account.py b/dashboard/modules/base_goerli/perp_account.py index b48bb31e..e25f681b 100644 --- a/dashboard/modules/base_goerli/perp_account.py +++ b/dashboard/modules/base_goerli/perp_account.py @@ -9,7 +9,7 @@ ## data @st.cache_data(ttl=1) -def fetch_data(account_id="NULL"): +def fetch_data(account_id=""): # initialize connection db = get_connection() @@ -22,36 +22,42 @@ def fetch_data(account_id="NULL"): ) df_order_expired = pd.read_sql_query( f""" - SELECT * FROM base_goerli.perp_previous_order_expired - WHERE account_id = {account_id} + SELECT + cast(account_id as text) as clean_account_id, + * + FROM base_goerli.perp_previous_order_expired + WHERE account_id = {account_id if account_id else 'NULL'} """, db, ) df_trade = pd.read_sql_query( f""" SELECT * FROM base_goerli.fct_perp_trades - WHERE account_id = {account_id} + WHERE account_id = '{account_id}' """, db, ) df_transfer = pd.read_sql_query( f""" - SELECT * FROM base_goerli.perp_collateral_modified - WHERE account_id = {account_id} + SELECT + cast(account_id as text) as clean_account_id, + * + FROM base_goerli.perp_collateral_modified + WHERE account_id = {account_id if account_id else 'NULL'} """, db, ) df_account_liq = pd.read_sql_query( f""" SELECT * FROM base_goerli.fct_perp_liq_account - WHERE account_id = {account_id} + WHERE account_id = '{account_id}' """, db, ) df_position_liq = pd.read_sql_query( f""" SELECT * FROM base_goerli.fct_perp_liq_position - WHERE account_id = {account_id} + WHERE account_id = '{account_id}' """, db, ) @@ -59,7 +65,7 @@ def fetch_data(account_id="NULL"): df_hourly = pd.read_sql_query( f""" SELECT * FROM base_goerli.fct_perp_account_stats_hourly - WHERE account_id = {account_id} + WHERE account_id = '{account_id}' """, db, ) @@ -114,145 +120,150 @@ def main(): accounts = sorted(list([int(_) for _ in accounts])) account = st.selectbox("Select account", accounts, index=0) - data = fetch_data(account_id=account) + if account: + data = fetch_data(account_id=account) - ## do some lighter transforms - df_open_positions = ( - data["trade"] - .sort_values("ts") - .groupby(["account_id", "market_id"]) - .last() - .reset_index() - ) - df_open_positions = df_open_positions[df_open_positions["position_size"].abs() > 0] + ## do some lighter transforms + df_open_positions = ( + data["trade"] + .sort_values("ts") + .groupby(["account_id", "market_id"]) + .last() + .reset_index() + ) + df_open_positions = df_open_positions[ + df_open_positions["position_size"].abs() > 0 + ] - ## make the charts - charts = make_charts(data) + ## make the charts + charts = make_charts(data) - ## display - # Open positions - df_open_account = df_open_positions[df_open_positions["account_id"] == account] + ## display + # Open positions + df_open_account = df_open_positions[df_open_positions["account_id"] == account] - last_liq = ( - data["account_liq"] - .loc[data["account_liq"]["account_id"] == account, "ts"] - .max() - ) + last_liq = ( + data["account_liq"] + .loc[data["account_liq"]["account_id"] == account, "ts"] + .max() + ) - # this is a hack to handle the case where there are no liquidations - last_liq = last_liq if pd.isna(last_liq) == False else "2023-01-01 00:00:00+00:00" + # this is a hack to handle the case where there are no liquidations + last_liq = ( + last_liq if pd.isna(last_liq) == False else "2023-01-01 00:00:00+00:00" + ) - df_open_account = df_open_account.loc[ - df_open_account["ts"] > last_liq, - ["account_id", "market_symbol", "position_size", "notional_position_size"], - ] + df_open_account = df_open_account.loc[ + df_open_account["ts"] > last_liq, + ["account_id", "market_symbol", "position_size", "notional_position_size"], + ] - st.markdown( - """ - ### Open Positions - """ - ) - if len(df_open_account) > 0: - df_open_account - else: st.markdown( """ - No open positions + ### Open Positions """ ) + if len(df_open_account) > 0: + df_open_account + else: + st.markdown( + """ + No open positions + """ + ) - col1, col2 = st.columns(2) + col1, col2 = st.columns(2) - with col1: - st.plotly_chart(charts["cumulative_volume"], use_container_width=True) - pass + with col1: + st.plotly_chart(charts["cumulative_volume"], use_container_width=True) + pass - with col2: - st.plotly_chart(charts["cumulative_fees"], use_container_width=True) - pass + with col2: + st.plotly_chart(charts["cumulative_fees"], use_container_width=True) + pass - # Recent trades - st.markdown( + # Recent trades + st.markdown( + """ + ### Recent Trades """ - ### Recent Trades - """ - ) + ) - st.dataframe( - data["trade"][ - [ - "ts", - "account_id", - "market_symbol", - "position_size", - "trade_size", - "notional_trade_size", - "fill_price", - "total_fees", - "accrued_funding", - "tracking_code", + st.dataframe( + data["trade"][ + [ + "ts", + "account_id", + "market_symbol", + "position_size", + "trade_size", + "notional_trade_size", + "fill_price", + "total_fees", + "accrued_funding", + "tracking_code", + ] ] - ] - .sort_values("ts", ascending=False) - .head(50), - use_container_width=True, - hide_index=True, - ) + .sort_values("ts", ascending=False) + .head(50), + use_container_width=True, + hide_index=True, + ) - # Recent transfers - st.markdown( + # Recent transfers + st.markdown( + """ + ### Recent Transfers """ - ### Recent Transfers - """ - ) + ) - st.dataframe( - data["transfer"][ - [ - "block_timestamp", - "account_id", - "synth_market_id", - "amount_delta", + st.dataframe( + data["transfer"][ + [ + "block_timestamp", + "clean_account_id", + "synth_market_id", + "amount_delta", + ] ] - ] - .sort_values("block_timestamp", ascending=False) - .head(50), - use_container_width=True, - hide_index=True, - ) + .sort_values("block_timestamp", ascending=False) + .head(50), + use_container_width=True, + hide_index=True, + ) - # Account liquidations table - st.markdown( + # Account liquidations table + st.markdown( + """ + ### Liquidations """ - ### Liquidations - """ - ) + ) - st.dataframe( - data["account_liq"][["ts", "account_id", "total_reward"]] - .sort_values("ts", ascending=False) - .head(25), - use_container_width=True, - hide_index=True, - ) + st.dataframe( + data["account_liq"][["ts", "account_id", "total_reward"]] + .sort_values("ts", ascending=False) + .head(25), + use_container_width=True, + hide_index=True, + ) - # Expired orders table - st.markdown( + # Expired orders table + st.markdown( + """ + ### Expired Orders """ - ### Expired Orders - """ - ) + ) - st.dataframe( - data["order_expired"][ - [ - "block_timestamp", - "account_id", - "market_id", - "acceptable_price", - "commitment_time", - ] - ], - use_container_width=True, - hide_index=True, - ) + st.dataframe( + data["order_expired"][ + [ + "block_timestamp", + "clean_account_id", + "market_id", + "acceptable_price", + "commitment_time", + ] + ], + use_container_width=True, + hide_index=True, + ) diff --git a/dashboard/modules/base_goerli/perp_monitor.py b/dashboard/modules/base_goerli/perp_monitor.py index d75fcd86..f1124b89 100644 --- a/dashboard/modules/base_goerli/perp_monitor.py +++ b/dashboard/modules/base_goerli/perp_monitor.py @@ -15,7 +15,13 @@ def fetch_data(): # read data df_order_expired = pd.read_sql_query( - "SELECT * FROM base_goerli.perp_previous_order_expired", db + f""" + SELECT + cast(account_id as text) as clean_account_id, + * + FROM base_goerli.perp_previous_order_expired + """, + db, ) df_trade = pd.read_sql_query("SELECT * FROM base_goerli.fct_perp_trades", db) df_market_updated = pd.read_sql_query( @@ -182,7 +188,7 @@ def main(): [ "block_number", "block_timestamp", - "account_id", + "clean_account_id", "market_id", "acceptable_price", "commitment_time", diff --git a/dashboard/modules/base_mainnet/perp_account.py b/dashboard/modules/base_mainnet/perp_account.py index eba0b123..4e663adf 100644 --- a/dashboard/modules/base_mainnet/perp_account.py +++ b/dashboard/modules/base_mainnet/perp_account.py @@ -9,7 +9,7 @@ ## data @st.cache_data(ttl=1) -def fetch_data(account_id="NULL"): +def fetch_data(account_id=""): # initialize connection db = get_connection() @@ -22,36 +22,42 @@ def fetch_data(account_id="NULL"): ) df_order_expired = pd.read_sql_query( f""" - SELECT * FROM base_mainnet.perp_previous_order_expired - WHERE account_id = {account_id} + SELECT + cast(account_id as text) as clean_account_id, + * + FROM base_mainnet.perp_previous_order_expired + WHERE account_id = {account_id if account_id else 'NULL'} """, db, ) df_trade = pd.read_sql_query( f""" SELECT * FROM base_mainnet.fct_perp_trades - WHERE account_id = {account_id} + WHERE account_id = '{account_id}' """, db, ) df_transfer = pd.read_sql_query( f""" - SELECT * FROM base_mainnet.perp_collateral_modified - WHERE account_id = {account_id} + SELECT + cast(account_id as text) as clean_account_id, + * + FROM base_mainnet.perp_collateral_modified + WHERE account_id = {account_id if account_id else 'NULL'} """, db, ) df_account_liq = pd.read_sql_query( f""" SELECT * FROM base_mainnet.fct_perp_liq_account - WHERE account_id = {account_id} + WHERE account_id = '{account_id}' """, db, ) df_position_liq = pd.read_sql_query( f""" SELECT * FROM base_mainnet.fct_perp_liq_position - WHERE account_id = {account_id} + WHERE account_id = '{account_id}' """, db, ) @@ -59,7 +65,7 @@ def fetch_data(account_id="NULL"): df_hourly = pd.read_sql_query( f""" SELECT * FROM base_mainnet.fct_perp_account_stats_hourly - WHERE account_id = {account_id} + WHERE account_id = '{account_id}' """, db, ) @@ -215,7 +221,7 @@ def main(): data["transfer"][ [ "block_timestamp", - "account_id", + "clean_account_id", "synth_market_id", "amount_delta", ] @@ -252,7 +258,7 @@ def main(): data["order_expired"][ [ "block_timestamp", - "account_id", + "clean_account_id", "market_id", "acceptable_price", "commitment_time", diff --git a/dashboard/modules/base_mainnet/perp_monitor.py b/dashboard/modules/base_mainnet/perp_monitor.py index 9ecb7180..98d600d0 100644 --- a/dashboard/modules/base_mainnet/perp_monitor.py +++ b/dashboard/modules/base_mainnet/perp_monitor.py @@ -15,7 +15,13 @@ def fetch_data(): # read data df_order_expired = pd.read_sql_query( - "SELECT * FROM base_mainnet.perp_previous_order_expired", db + f""" + SELECT + cast(account_id as text) as clean_account_id, + * + FROM base_mainnet.perp_previous_order_expired + """, + db, ) df_trade = pd.read_sql_query("SELECT * FROM base_mainnet.fct_perp_trades", db) df_market_updated = pd.read_sql_query( @@ -182,7 +188,7 @@ def main(): [ "block_number", "block_timestamp", - "account_id", + "clean_account_id", "market_id", "acceptable_price", "commitment_time", diff --git a/transformers/synthetix/models/marts/core/fct_core_account_delegation.sql b/transformers/synthetix/models/marts/core/fct_core_account_delegation.sql index ce6e4526..337d8341 100644 --- a/transformers/synthetix/models/marts/core/fct_core_account_delegation.sql +++ b/transformers/synthetix/models/marts/core/fct_core_account_delegation.sql @@ -32,7 +32,9 @@ cumulative_delegation AS ( ) SELECT block_timestamp AS ts, - account_id, + CAST( + account_id AS text + ) AS account_id, pool_id, collateral_type, cumulative_amount_delegated AS amount_delegated diff --git a/transformers/synthetix/models/marts/perp/fct_perp_liq_account.sql b/transformers/synthetix/models/marts/perp/fct_perp_liq_account.sql index 1114be30..31c61ae1 100644 --- a/transformers/synthetix/models/marts/perp/fct_perp_liq_account.sql +++ b/transformers/synthetix/models/marts/perp/fct_perp_liq_account.sql @@ -20,7 +20,9 @@ WITH liquidation_events AS ( ), cumulative_rewards AS ( SELECT - le.account_id, + CAST( + le.account_id AS text + ) AS account_id, le.block_timestamp, le.reward, le.full_liquidation, diff --git a/transformers/synthetix/models/marts/perp/fct_perp_liq_position.sql b/transformers/synthetix/models/marts/perp/fct_perp_liq_position.sql index 5b09a536..120d0686 100644 --- a/transformers/synthetix/models/marts/perp/fct_perp_liq_position.sql +++ b/transformers/synthetix/models/marts/perp/fct_perp_liq_position.sql @@ -23,7 +23,9 @@ SELECT l.ts, l.block_number, l.transaction_hash, - l.account_id, + CAST( + l.account_id AS text + ) AS account_id, l.market_id, m.market_symbol, l.amount_liquidated, diff --git a/transformers/synthetix/models/marts/perp/fct_perp_orders.sql b/transformers/synthetix/models/marts/perp/fct_perp_orders.sql index 623000af..2e8ab419 100644 --- a/transformers/synthetix/models/marts/perp/fct_perp_orders.sql +++ b/transformers/synthetix/models/marts/perp/fct_perp_orders.sql @@ -7,7 +7,9 @@ WITH base AS ( oc.contract, oc.market_id, markets.market_symbol, - oc.account_id, + CAST( + oc.account_id AS text + ) AS account_id, oc.order_type, {{ convert_wei('oc.size_delta') }} AS SIZE, {{ convert_wei('oc.acceptable_price') }} AS acceptable_price, diff --git a/transformers/synthetix/models/marts/perp/fct_perp_trades.sql b/transformers/synthetix/models/marts/perp/fct_perp_trades.sql index 325ea8c4..13564fdf 100644 --- a/transformers/synthetix/models/marts/perp/fct_perp_trades.sql +++ b/transformers/synthetix/models/marts/perp/fct_perp_trades.sql @@ -7,7 +7,9 @@ WITH base AS ( pos.contract, pos.market_id, markets.market_symbol, - pos.account_id, + CAST( + pos.account_id AS text + ) AS account_id, {{ convert_wei('fill_price') }} AS fill_price, {{ convert_wei('pnl') }} AS pnl, {{ convert_wei('accrued_funding') }} AS accrued_funding,