mirror of
https://github.com/d0zingcat/deploy.git
synced 2026-06-07 15:10:55 +00:00
(feat) update data
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
import streamlit as st
|
|
||||||
from datetime import datetime, time
|
from datetime import datetime, time
|
||||||
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.graph_objects as go
|
import plotly.graph_objects as go
|
||||||
|
import streamlit as st
|
||||||
|
|
||||||
from frontend.st_utils import initialize_st_page, get_backend_api_client
|
from frontend.st_utils import get_backend_api_client, initialize_st_page
|
||||||
|
|
||||||
# Initialize Streamlit page
|
# Initialize Streamlit page
|
||||||
initialize_st_page(title="Download Candles", icon="💾")
|
initialize_st_page(title="Download Candles", icon="💾")
|
||||||
@@ -11,7 +12,9 @@ backend_api_client = get_backend_api_client()
|
|||||||
|
|
||||||
c1, c2, c3, c4 = st.columns([2, 2, 2, 0.5])
|
c1, c2, c3, c4 = st.columns([2, 2, 2, 0.5])
|
||||||
with c1:
|
with c1:
|
||||||
connector = st.selectbox("Exchange", ["binance_perpetual", "binance", "gate_io", "gate_io_perpetual", "kucoin", "ascend_ex"], index=0)
|
connector = st.selectbox("Exchange",
|
||||||
|
["binance_perpetual", "binance", "gate_io", "gate_io_perpetual", "kucoin", "ascend_ex"],
|
||||||
|
index=0)
|
||||||
trading_pair = st.text_input("Trading Pair", value="BTC-USDT")
|
trading_pair = st.text_input("Trading Pair", value="BTC-USDT")
|
||||||
with c2:
|
with c2:
|
||||||
interval = st.selectbox("Interval", options=["1m", "3m", "5m", "15m", "1h", "4h", "1d", "1s"])
|
interval = st.selectbox("Interval", options=["1m", "3m", "5m", "15m", "1h", "4h", "1d", "1s"])
|
||||||
@@ -29,8 +32,8 @@ if get_data_button:
|
|||||||
connector=connector,
|
connector=connector,
|
||||||
trading_pair=trading_pair,
|
trading_pair=trading_pair,
|
||||||
interval=interval,
|
interval=interval,
|
||||||
start_time=int(start_datetime.timestamp()) * 1000,
|
start_time=int(start_datetime.timestamp()),
|
||||||
end_time=int(end_datetime.timestamp()) * 1000
|
end_time=int(end_datetime.timestamp())
|
||||||
)
|
)
|
||||||
|
|
||||||
candles_df = pd.DataFrame(candles)
|
candles_df = pd.DataFrame(candles)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import streamlit as st
|
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
|
import streamlit as st
|
||||||
|
|
||||||
import CONFIG
|
import CONFIG
|
||||||
from backend.services.coingecko_client import CoinGeckoClient
|
from backend.services.coingecko_client import CoinGeckoClient
|
||||||
from backend.services.miner_client import MinerClient
|
from backend.services.miner_client import MinerClient
|
||||||
@@ -11,22 +12,27 @@ initialize_st_page(title="Token Spreads", icon="🧙")
|
|||||||
cg_utils = CoinGeckoClient()
|
cg_utils = CoinGeckoClient()
|
||||||
miner_utils = MinerClient()
|
miner_utils = MinerClient()
|
||||||
|
|
||||||
|
|
||||||
@st.cache_data
|
@st.cache_data
|
||||||
def get_all_coins_df():
|
def get_all_coins_df():
|
||||||
return cg_utils.get_all_coins_df()
|
return cg_utils.get_all_coins_df()
|
||||||
|
|
||||||
|
|
||||||
@st.cache_data
|
@st.cache_data
|
||||||
def get_all_exchanges_df():
|
def get_all_exchanges_df():
|
||||||
return cg_utils.get_all_exchanges_df()
|
return cg_utils.get_all_exchanges_df()
|
||||||
|
|
||||||
|
|
||||||
@st.cache_data
|
@st.cache_data
|
||||||
def get_miner_stats_df():
|
def get_miner_stats_df():
|
||||||
return miner_utils.get_miner_stats_df()
|
return miner_utils.get_miner_stats_df()
|
||||||
|
|
||||||
|
|
||||||
@st.cache_data
|
@st.cache_data
|
||||||
def get_coin_tickers_by_id_list(coins_id: list):
|
def get_coin_tickers_by_id_list(coins_id: list):
|
||||||
return cg_utils.get_coin_tickers_by_id_list(coins_id)
|
return cg_utils.get_coin_tickers_by_id_list(coins_id)
|
||||||
|
|
||||||
|
|
||||||
with st.spinner(text='In progress'):
|
with st.spinner(text='In progress'):
|
||||||
exchanges_df = get_all_exchanges_df()
|
exchanges_df = get_all_exchanges_df()
|
||||||
coins_df = get_all_coins_df()
|
coins_df = get_all_coins_df()
|
||||||
@@ -43,7 +49,8 @@ tokens = st.multiselect(
|
|||||||
coins_id = coins_df.loc[coins_df["name"].isin(tokens), "id"].tolist()
|
coins_id = coins_df.loc[coins_df["name"].isin(tokens), "id"].tolist()
|
||||||
|
|
||||||
coin_tickers_df = get_coin_tickers_by_id_list(coins_id)
|
coin_tickers_df = get_coin_tickers_by_id_list(coins_id)
|
||||||
coin_tickers_df["coin_name"] = coin_tickers_df.apply(lambda x: coins_df.loc[coins_df["id"] == x.token_id, "name"].item(), axis=1)
|
coin_tickers_df["coin_name"] = coin_tickers_df.apply(
|
||||||
|
lambda x: coins_df.loc[coins_df["id"] == x.token_id, "name"].item(), axis=1)
|
||||||
|
|
||||||
exchanges = st.multiselect(
|
exchanges = st.multiselect(
|
||||||
"Select the exchanges to analyze:",
|
"Select the exchanges to analyze:",
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import streamlit as st
|
|
||||||
import pandas as pd
|
import pandas as pd
|
||||||
import plotly.express as px
|
import plotly.express as px
|
||||||
|
import streamlit as st
|
||||||
from defillama import DefiLlama
|
from defillama import DefiLlama
|
||||||
|
|
||||||
from frontend.st_utils import initialize_st_page
|
from frontend.st_utils import initialize_st_page
|
||||||
@@ -12,16 +12,21 @@ initialize_st_page(title="TVL vs Market Cap", icon="🦉")
|
|||||||
MIN_TVL = 1000000.
|
MIN_TVL = 1000000.
|
||||||
MIN_MCAP = 1000000.
|
MIN_MCAP = 1000000.
|
||||||
|
|
||||||
|
|
||||||
@st.cache_data
|
@st.cache_data
|
||||||
def get_tvl_mcap_data():
|
def get_tvl_mcap_data():
|
||||||
llama = DefiLlama()
|
llama = DefiLlama()
|
||||||
df = pd.DataFrame(llama.get_all_protocols())
|
df = pd.DataFrame(llama.get_all_protocols())
|
||||||
tvl_mcap_df = df.loc[(df["tvl"]>0) & (df["mcap"]>0), ["name", "tvl", "mcap", "chain", "category", "slug"]].sort_values(by=["mcap"], ascending=False)
|
tvl_mcap_df = df.loc[
|
||||||
return tvl_mcap_df[(tvl_mcap_df["tvl"] > MIN_TVL) & (tvl_mcap_df["mcap"]> MIN_MCAP)]
|
(df["tvl"] > 0) & (df["mcap"] > 0), ["name", "tvl", "mcap", "chain", "category", "slug"]].sort_values(
|
||||||
|
by=["mcap"], ascending=False)
|
||||||
|
return tvl_mcap_df[(tvl_mcap_df["tvl"] > MIN_TVL) & (tvl_mcap_df["mcap"] > MIN_MCAP)]
|
||||||
|
|
||||||
|
|
||||||
def get_protocols_by_chain_category(protocols: pd.DataFrame, group_by: list, nth: list):
|
def get_protocols_by_chain_category(protocols: pd.DataFrame, group_by: list, nth: list):
|
||||||
return protocols.sort_values('tvl', ascending=False).groupby(group_by).nth(nth).reset_index()
|
return protocols.sort_values('tvl', ascending=False).groupby(group_by).nth(nth).reset_index()
|
||||||
|
|
||||||
|
|
||||||
with st.spinner(text='In progress'):
|
with st.spinner(text='In progress'):
|
||||||
tvl_mcap_df = get_tvl_mcap_data()
|
tvl_mcap_df = get_tvl_mcap_data()
|
||||||
|
|
||||||
@@ -57,7 +62,8 @@ st.write("### SunBurst 🌞")
|
|||||||
groupby = st.selectbox('Group by:', [['chain', 'category'], ['category', 'chain']])
|
groupby = st.selectbox('Group by:', [['chain', 'category'], ['category', 'chain']])
|
||||||
nth = st.slider('Top protocols by Category', min_value=1, max_value=5)
|
nth = st.slider('Top protocols by Category', min_value=1, max_value=5)
|
||||||
|
|
||||||
proto_agg = get_protocols_by_chain_category(tvl_mcap_df[tvl_mcap_df["chain"].isin(chains)], groupby, np.arange(0, nth, 1).tolist())
|
proto_agg = get_protocols_by_chain_category(tvl_mcap_df[tvl_mcap_df["chain"].isin(chains)],
|
||||||
|
groupby, np.arange(0, nth, 1).tolist())
|
||||||
groupby.append("slug")
|
groupby.append("slug")
|
||||||
sunburst = px.sunburst(
|
sunburst = px.sunburst(
|
||||||
proto_agg,
|
proto_agg,
|
||||||
@@ -65,6 +71,6 @@ sunburst = px.sunburst(
|
|||||||
values='tvl',
|
values='tvl',
|
||||||
height=800,
|
height=800,
|
||||||
title="SunBurst",
|
title="SunBurst",
|
||||||
template="plotly_dark",)
|
template="plotly_dark", )
|
||||||
|
|
||||||
st.plotly_chart(sunburst, use_container_width=True)
|
st.plotly_chart(sunburst, use_container_width=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user