From 491d54a8df28d5e5c4daec2e91da92c90eb1837a Mon Sep 17 00:00:00 2001 From: cardosofede Date: Wed, 29 May 2024 01:48:27 -0500 Subject: [PATCH] (feat) add credentials page --- .../pages/orchestration/credentials/README.md | 19 +++++ .../orchestration/credentials/__init__.py | 0 .../pages/orchestration/credentials/app.py | 83 +++++++++++++++++++ 3 files changed, 102 insertions(+) create mode 100644 frontend/pages/orchestration/credentials/README.md create mode 100644 frontend/pages/orchestration/credentials/__init__.py create mode 100644 frontend/pages/orchestration/credentials/app.py diff --git a/frontend/pages/orchestration/credentials/README.md b/frontend/pages/orchestration/credentials/README.md new file mode 100644 index 0000000..18f4d94 --- /dev/null +++ b/frontend/pages/orchestration/credentials/README.md @@ -0,0 +1,19 @@ +### Description + +This page helps you deploy and manage Hummingbot instances: + +- Starting and stopping Hummingbot Broker +- Creating, starting and stopping bot instances +- Managing strategy and script files that instances run +- Fetching status of running instances + +### Maintainers + +This page is maintained by Hummingbot Foundation as a template other pages: + +* [cardosfede](https://github.com/cardosfede) +* [fengtality](https://github.com/fengtality) + +### Wiki + +See the [wiki](https://github.com/hummingbot/dashboard/wiki/%F0%9F%90%99-Bot-Orchestration) for more information. \ No newline at end of file diff --git a/frontend/pages/orchestration/credentials/__init__.py b/frontend/pages/orchestration/credentials/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/frontend/pages/orchestration/credentials/app.py b/frontend/pages/orchestration/credentials/app.py new file mode 100644 index 0000000..88ae1cb --- /dev/null +++ b/frontend/pages/orchestration/credentials/app.py @@ -0,0 +1,83 @@ +from CONFIG import BACKEND_API_HOST, BACKEND_API_PORT +from backend.services.backend_api_client import BackendAPIClient +from frontend.st_utils import initialize_st_page +import streamlit as st +import pandas as pd +import plotly.express as px + +initialize_st_page(title="Account Balances", icon="💰") + +# Page content +client = BackendAPIClient.get_instance(host=BACKEND_API_HOST, port=BACKEND_API_PORT) + +@st.cache_data(ttl=60) +def get_all_balances(): + return client.get_all_balances() + +# Fetch all balances +balances = get_all_balances() + +# Convert balances to a DataFrame for easier manipulation +def balances_to_df(balances): + data = [] + for account, exchanges in balances.items(): + for exchange, tokens in exchanges.items(): + for token, amount in tokens.items(): + data.append({"Account": account, "Exchange": exchange, "Token": token, "Amount": amount}) + return pd.DataFrame(data) + +df_balances = balances_to_df(balances) + +# Aggregation at different levels +account_agg = df_balances.groupby(["Account", "Token"])["Amount"].sum().reset_index() +exchange_agg = df_balances.groupby(["Exchange", "Token"])["Amount"].sum().reset_index() +overall_agg = df_balances.groupby("Token")["Amount"].sum().reset_index() + +# Display balances +st.header("Current Balances") +st.write(df_balances) + +# Aggregated Balances +st.header("Aggregated Balances") +st.write(account_agg) + +# Displaying account level balances +st.subheader("Account Level") +for account in account_agg["Account"].unique(): + st.write(f"**{account}**") + df = account_agg[account_agg["Account"] == account] + st.write(df) + +# Displaying exchange level balances +st.subheader("Exchange Level") +for exchange in exchange_agg["Exchange"].unique(): + st.write(f"**{exchange}**") + df = exchange_agg[exchange_agg["Exchange"] == exchange] + st.write(df) + +# Overall holdings +st.subheader("Overall Holdings") +st.write(overall_agg) + +# Visualizations +st.header("Visualizations") + +# Account level pie chart +st.subheader("Account Level Balances") +for account in account_agg["Account"].unique(): + df = account_agg[account_agg["Account"] == account] + fig = px.pie(df, names='Token', values='Amount', title=f"Account: {account}") + st.plotly_chart(fig) + +# Exchange level bar chart +st.subheader("Exchange Level Balances") +for exchange in exchange_agg["Exchange"].unique(): + df = exchange_agg[exchange_agg["Exchange"] == exchange] + fig = px.bar(df, x='Token', y='Amount', title=f"Exchange: {exchange}") + st.plotly_chart(fig) + +# Overall holdings pie chart +st.subheader("Overall Holdings by Token") +fig = px.pie(overall_agg, names='Token', values='Amount', title="Overall Holdings by Token") +st.plotly_chart(fig) +