Skip to content

Commit

Permalink
Merge pull request #33 from Synthetixio/add-interest-rate
Browse files Browse the repository at this point in the history
Add interest rate
  • Loading branch information
Tburm authored Mar 28, 2024
2 parents 9db846d + aeb42ed commit 1d46493
Show file tree
Hide file tree
Showing 14 changed files with 823 additions and 31 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ reset-pw:
build:
docker compose build transformer

extract:
docker compose run extractors python main.py

wrap:
docker compose run transformer python scripts/wrap_tables.py

Expand Down
29 changes: 28 additions & 1 deletion dashboard/modules/base_mainnet/perp_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ def fetch_data(filters):
""",
db,
)
df_interest = pd.read_sql_query(
f"""
SELECT
block_timestamp,
transaction_hash,
cast(account_id as text) as account_id,
interest
FROM base_mainnet.perp_interest_charged
WHERE account_id = {account_id if account_id else 'NULL'}
and date(block_timestamp) >= '{start_date}' and date(block_timestamp) <= '{end_date}'
""",
db,
)

df_account_liq = pd.read_sql_query(
f"""
SELECT
Expand All @@ -92,7 +106,6 @@ def fetch_data(filters):
""",
db,
)

df_hourly = pd.read_sql_query(
f"""
SELECT
Expand All @@ -118,6 +131,7 @@ def fetch_data(filters):
return {
"accounts": df_accounts,
"order_expired": df_order_expired,
"interest": df_interest,
"trade": df_trade,
"transfer": df_transfer,
"account_liq": df_account_liq,
Expand Down Expand Up @@ -275,6 +289,19 @@ def main():
hide_index=True,
)

# Interest charged table
st.markdown(
"""
### Interest Charged
"""
)

st.dataframe(
data["interest"],
use_container_width=True,
hide_index=True,
)

## export
exports = [{"title": export, "df": data[export]} for export in data.keys()]
with st.expander("Exports"):
Expand Down
12 changes: 8 additions & 4 deletions dashboard/modules/base_mainnet/perp_markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def fetch_data(filters):
market_id,
market_symbol,
funding_rate,
interest_rate,
funding_rate_apr,
long_rate_apr,
short_rate_apr,
price,
skew,
size_usd,
Expand All @@ -54,11 +58,11 @@ def make_charts(data, asset):
df = data["market_history"][data["market_history"]["market_symbol"] == asset]

return {
"funding": chart_lines(
"rates": chart_lines(
df,
"ts",
["funding_rate"],
"Funding Rate per 24 hours",
["funding_rate_apr", "interest_rate", "long_rate_apr", "short_rate_apr"],
"Rates",
smooth=True,
y_format="%",
),
Expand Down Expand Up @@ -127,7 +131,7 @@ def main():

with col2:
st.plotly_chart(charts["oi_pct"], use_container_width=True)
st.plotly_chart(charts["funding"], use_container_width=True)
st.plotly_chart(charts["rates"], use_container_width=True)

## export
exports = [{"title": export, "df": data[export]} for export in data.keys()]
Expand Down
29 changes: 28 additions & 1 deletion dashboard/modules/base_sepolia/perp_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,20 @@ def fetch_data(filters):
""",
db,
)
df_interest = pd.read_sql_query(
f"""
SELECT
block_timestamp,
transaction_hash,
cast(account_id as text) as account_id,
interest
FROM base_sepolia.perp_interest_charged
WHERE account_id = {account_id if account_id else 'NULL'}
and date(block_timestamp) >= '{start_date}' and date(block_timestamp) <= '{end_date}'
""",
db,
)

df_account_liq = pd.read_sql_query(
f"""
SELECT
Expand All @@ -92,7 +106,6 @@ def fetch_data(filters):
""",
db,
)

df_hourly = pd.read_sql_query(
f"""
SELECT
Expand All @@ -118,6 +131,7 @@ def fetch_data(filters):
return {
"accounts": df_accounts,
"order_expired": df_order_expired,
"interest": df_interest,
"trade": df_trade,
"transfer": df_transfer,
"account_liq": df_account_liq,
Expand Down Expand Up @@ -275,6 +289,19 @@ def main():
hide_index=True,
)

# Interest charged table
st.markdown(
"""
### Interest Charged
"""
)

st.dataframe(
data["interest"],
use_container_width=True,
hide_index=True,
)

## export
exports = [{"title": export, "df": data[export]} for export in data.keys()]
with st.expander("Exports"):
Expand Down
12 changes: 8 additions & 4 deletions dashboard/modules/base_sepolia/perp_markets.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ def fetch_data(filters):
market_id,
market_symbol,
funding_rate,
interest_rate,
funding_rate_apr,
long_rate_apr,
short_rate_apr,
price,
skew,
size_usd,
Expand All @@ -54,11 +58,11 @@ def make_charts(data, asset):
df = data["market_history"][data["market_history"]["market_symbol"] == asset]

return {
"funding": chart_lines(
"rates": chart_lines(
df,
"ts",
["funding_rate"],
"Funding Rate per 24 hours",
["funding_rate_apr", "interest_rate", "long_rate_apr", "short_rate_apr"],
"Rates",
smooth=True,
y_format="%",
),
Expand Down Expand Up @@ -127,7 +131,7 @@ def main():

with col2:
st.plotly_chart(charts["oi_pct"], use_container_width=True)
st.plotly_chart(charts["funding"], use_container_width=True)
st.plotly_chart(charts["rates"], use_container_width=True)

## export
exports = [{"title": export, "df": data[export]} for export in data.keys()]
Expand Down
Loading

0 comments on commit 1d46493

Please sign in to comment.