From 60578d176d7ec4956f04c8ca4ae106ca80719da7 Mon Sep 17 00:00:00 2001 From: cardosofede Date: Wed, 29 May 2024 01:48:33 -0500 Subject: [PATCH] (feat) add portfolio page --- .../pages/orchestration/portfolio/README.md | 19 ++++++ .../pages/orchestration/portfolio/__init__.py | 0 frontend/pages/orchestration/portfolio/app.py | 58 +++++++++++++++++++ 3 files changed, 77 insertions(+) create mode 100644 frontend/pages/orchestration/portfolio/README.md create mode 100644 frontend/pages/orchestration/portfolio/__init__.py create mode 100644 frontend/pages/orchestration/portfolio/app.py diff --git a/frontend/pages/orchestration/portfolio/README.md b/frontend/pages/orchestration/portfolio/README.md new file mode 100644 index 0000000..18f4d94 --- /dev/null +++ b/frontend/pages/orchestration/portfolio/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/portfolio/__init__.py b/frontend/pages/orchestration/portfolio/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/frontend/pages/orchestration/portfolio/app.py b/frontend/pages/orchestration/portfolio/app.py new file mode 100644 index 0000000..286bc1b --- /dev/null +++ b/frontend/pages/orchestration/portfolio/app.py @@ -0,0 +1,58 @@ +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 + +initialize_st_page(title="Portfolio", icon="💰") + +# Page content +client = BackendAPIClient.get_instance(host=BACKEND_API_HOST, port=BACKEND_API_PORT) +NUM_COLUMNS = 4 + +@st.cache_data +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) +c1, c2 = st.columns([1, 1]) +with c1: + st.header("Current Balances") +with c2: + st.header("Aggregated Balances") + +c1, c2, c3, c4 = st.columns([2.5, 1.5, 1.5, 1.1]) +with c1: + # Display balances + st.subheader("All Balances") + st.dataframe(df_balances) + +with c2: + # Aggregation at the account level + account_agg = df_balances.groupby(["Account", "Token"])["Amount"].sum().reset_index() + st.subheader("Account Level") + st.dataframe(account_agg) + +with c3: + # Aggregation at the exchange level + exchange_agg = df_balances.groupby(["Exchange", "Token"])["Amount"].sum().reset_index() + st.subheader("Exchange Level") + st.dataframe(exchange_agg) + +with c4: + # Overall holdings + overall_agg = df_balances.groupby("Token")["Amount"].sum().reset_index() + st.subheader("Token Level") + st.write(overall_agg)