(feat) update orchestration pages

This commit is contained in:
cardosofede
2024-07-23 15:02:31 +03:00
parent 4fb0d86d96
commit 44816d0238
5 changed files with 29 additions and 19 deletions

View File

@@ -1,8 +1,6 @@
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, get_backend_api_client
import streamlit as st import streamlit as st
from frontend.st_utils import get_backend_api_client, initialize_st_page
initialize_st_page(title="Credentials", icon="🔑") initialize_st_page(title="Credentials", icon="🔑")
@@ -15,6 +13,7 @@ NUM_COLUMNS = 4
def get_all_connectors_config_map(): def get_all_connectors_config_map():
return client.get_all_connectors_config_map() return client.get_all_connectors_config_map()
# Section to display available accounts and credentials # Section to display available accounts and credentials
accounts = client.get_accounts() accounts = client.get_accounts()
all_connector_config_map = get_all_connectors_config_map() all_connector_config_map = get_all_connectors_config_map()
@@ -58,7 +57,8 @@ with c1:
with c2: with c2:
# Section to delete an existing account # Section to delete an existing account
st.header("Delete an Account") st.header("Delete an Account")
delete_account_name = st.selectbox("Select Account to Delete", options=accounts if accounts else ["No accounts available"], ) delete_account_name = st.selectbox("Select Account to Delete",
options=accounts if accounts else ["No accounts available"], )
if st.button("Delete Account"): if st.button("Delete Account"):
if delete_account_name and delete_account_name != "No accounts available": if delete_account_name and delete_account_name != "No accounts available":
response = client.delete_account(delete_account_name) response = client.delete_account(delete_account_name)
@@ -69,11 +69,14 @@ with c2:
with c3: with c3:
# Section to delete a credential from an existing account # Section to delete a credential from an existing account
st.header("Delete Credential") st.header("Delete Credential")
delete_account_cred_name = st.selectbox("Select the credentials account", options=accounts if accounts else ["No accounts available"],) delete_account_cred_name = st.selectbox("Select the credentials account",
options=accounts if accounts else ["No accounts available"], )
creds_for_account = [credential.split(".")[0] for credential in client.get_credentials(delete_account_cred_name)] creds_for_account = [credential.split(".")[0] for credential in client.get_credentials(delete_account_cred_name)]
delete_cred_name = st.selectbox("Select a Credential to Delete", options=creds_for_account if creds_for_account else ["No credentials available"]) delete_cred_name = st.selectbox("Select a Credential to Delete",
options=creds_for_account if creds_for_account else ["No credentials available"])
if st.button("Delete Credential"): if st.button("Delete Credential"):
if (delete_account_cred_name and delete_account_cred_name != "No accounts available") and (delete_cred_name and delete_cred_name != "No credentials available"): if (delete_account_cred_name and delete_account_cred_name != "No accounts available") and \
(delete_cred_name and delete_cred_name != "No credentials available"):
response = client.delete_credential(delete_account_cred_name, delete_cred_name) response = client.delete_credential(delete_account_cred_name, delete_cred_name)
st.warning(response) st.warning(response)
else: else:
@@ -88,7 +91,8 @@ with c1:
account_name = st.selectbox("Select Account", options=accounts if accounts else ["No accounts available"]) account_name = st.selectbox("Select Account", options=accounts if accounts else ["No accounts available"])
with c2: with c2:
all_connectors = list(all_connector_config_map.keys()) all_connectors = list(all_connector_config_map.keys())
binance_perpetual_index = all_connectors.index("binance_perpetual") if "binance_perpetual" in all_connectors else None binance_perpetual_index = all_connectors.index(
"binance_perpetual") if "binance_perpetual" in all_connectors else None
connector_name = st.selectbox("Select Connector", options=all_connectors, index=binance_perpetual_index) connector_name = st.selectbox("Select Connector", options=all_connectors, index=binance_perpetual_index)
config_map = all_connector_config_map[connector_name] config_map = all_connector_config_map[connector_name]

View File

@@ -1,4 +1,5 @@
from types import SimpleNamespace from types import SimpleNamespace
import streamlit as st import streamlit as st
from streamlit_elements import elements, mui from streamlit_elements import elements, mui

View File

@@ -1,18 +1,19 @@
import time import time
from types import SimpleNamespace
import streamlit as st import streamlit as st
from streamlit_elements import elements, mui from streamlit_elements import elements, mui
from types import SimpleNamespace
from frontend.components.bot_performance_card import BotPerformanceCardV2 from frontend.components.bot_performance_card import BotPerformanceCardV2
from frontend.components.dashboard import Dashboard from frontend.components.dashboard import Dashboard
from frontend.st_utils import initialize_st_page, get_backend_api_client from frontend.st_utils import get_backend_api_client, initialize_st_page
# Constants for UI layout # Constants for UI layout
CARD_WIDTH = 12 CARD_WIDTH = 12
CARD_HEIGHT = 4 CARD_HEIGHT = 4
NUM_CARD_COLS = 1 NUM_CARD_COLS = 1
def get_grid_positions(n_cards: int, cols: int = NUM_CARD_COLS, card_width: int = CARD_WIDTH, card_height: int = CARD_HEIGHT): def get_grid_positions(n_cards: int, cols: int = NUM_CARD_COLS, card_width: int = CARD_WIDTH, card_height: int = CARD_HEIGHT):
rows = n_cards // cols + 1 rows = n_cards // cols + 1
x_y = [(x * card_width, y * card_height) for x in range(cols) for y in range(rows)] x_y = [(x * card_width, y * card_height) for x in range(cols) for y in range(rows)]
@@ -28,7 +29,9 @@ def update_active_bots(api_client):
new_bots = set(current_active_bots.keys()) - set(stored_bots.keys()) new_bots = set(current_active_bots.keys()) - set(stored_bots.keys())
removed_bots = set(stored_bots.keys()) - set(current_active_bots.keys()) removed_bots = set(stored_bots.keys()) - set(current_active_bots.keys())
for bot in removed_bots: for bot in removed_bots:
st.session_state.active_instances_board.bot_cards = [card for card in st.session_state.active_instances_board.bot_cards if card[1] != bot] st.session_state.active_instances_board.bot_cards = [card for card in
st.session_state.active_instances_board.bot_cards
if card[1] != bot]
positions = get_grid_positions(len(current_active_bots), NUM_CARD_COLS, CARD_WIDTH, CARD_HEIGHT) positions = get_grid_positions(len(current_active_bots), NUM_CARD_COLS, CARD_WIDTH, CARD_HEIGHT)
for bot, (x, y) in zip(new_bots, positions[:len(new_bots)]): for bot, (x, y) in zip(new_bots, positions[:len(new_bots)]):
card = BotPerformanceCardV2(st.session_state.active_instances_board.dashboard, x, y, CARD_WIDTH, CARD_HEIGHT) card = BotPerformanceCardV2(st.session_state.active_instances_board.dashboard, x, y, CARD_WIDTH, CARD_HEIGHT)

View File

@@ -1,7 +1,6 @@
from frontend.components.deploy_v2_with_controllers import LaunchV2WithControllers from frontend.components.deploy_v2_with_controllers import LaunchV2WithControllers
from frontend.st_utils import initialize_st_page from frontend.st_utils import initialize_st_page
initialize_st_page(title="Launch Bot ST", icon="🙌") initialize_st_page(title="Launch Bot ST", icon="🙌")

View File

@@ -1,8 +1,8 @@
from frontend.st_utils import initialize_st_page, get_backend_api_client
import streamlit as st
import pandas as pd import pandas as pd
import plotly.graph_objects as go
import plotly.express as px import plotly.express as px
import streamlit as st
from frontend.st_utils import get_backend_api_client, initialize_st_page
initialize_st_page(title="Portfolio", icon="💰") initialize_st_page(title="Portfolio", icon="💰")
@@ -91,7 +91,8 @@ for account in accounts:
filtered_account_state[account] = {} filtered_account_state[account] = {}
for exchange in exchanges: for exchange in exchanges:
if exchange in account_state[account]: if exchange in account_state[account]:
filtered_account_state[account][exchange] = [token_info for token_info in account_state[account][exchange] if token_info["token"] in tokens_available] filtered_account_state[account][exchange] = [token_info for token_info in account_state[account][exchange]
if token_info["token"] in tokens_available]
filtered_account_history = [] filtered_account_history = []
for record in account_history: for record in account_history:
@@ -101,7 +102,9 @@ for record in account_history:
filtered_record["state"][account] = {} filtered_record["state"][account] = {}
for exchange in exchanges: for exchange in exchanges:
if exchange in record["state"][account]: if exchange in record["state"][account]:
filtered_record["state"][account][exchange] = [token_info for token_info in record["state"][account][exchange] if token_info["token"] in tokens_available] filtered_record["state"][account][exchange] = [token_info for token_info in
record["state"][account][exchange] if
token_info["token"] in tokens_available]
filtered_account_history.append(filtered_record) filtered_account_history.append(filtered_record)
if len(filtered_account_state) > 0: if len(filtered_account_state) > 0: