data grid WIP

This commit is contained in:
Michael Feng
2023-08-22 14:35:07 -07:00
parent 5b51071aa6
commit 58a01ed2c9

View File

@@ -4,12 +4,17 @@ from ui_components.dashboard import Dashboard
import streamlit as st
import time
from utils.os_utils import get_python_files_from_directory, get_yml_files_from_directory
import pandas as pd
def parse_orders(input_str):
# Check for "No active maker orders" in the string
if "No active maker orders" in input_str:
return "No active maker orders"
# Split the string by lines
lines = input_str.split("\n")
# Identify the line where the 'Orders:' section starts
for i, line in enumerate(lines):
if "Orders:" in line:
@@ -17,28 +22,57 @@ def parse_orders(input_str):
break
# Extract relevant lines after "Orders:"
order_lines = lines[start_idx:]
order_lines = lines[start_idx:]
# Determine the table type based on the header and extract order lines
table_type = None
for i, line in enumerate(order_lines):
if all(keyword in line for keyword in ['Exchange', 'Market', 'Side']):
table_type = 'simple_pmm'
start_idx = i + 1
order_lines_parsed = order_lines[start_idx:]
break
elif all(keyword in line for keyword in ['Level', 'Amount (Orig)']):
table_type = 'pmm'
start_idx = i + 1
order_lines_parsed = order_lines[start_idx:]
break
# Parse each order line into a list of dictionaries
orders = []
for order_line in order_lines:
for order_line in order_lines_parsed:
parts = order_line.split()
# Construct order dictionary from the split parts
order = {
"Exchange": parts[0],
"Market": parts[1],
"Side": parts[2],
"Price": parts[3],
"Amount": parts[4],
"Age": parts[5]
}
orders.append(order)
# Convert list of dictionaries to DataFrame
df_orders = pd.DataFrame(orders)
return df_orders
# Check table type and extract data accordingly
if table_type == 'simple_pmm':
if len(parts) < 5:
continue
order = {
"id": parts[2] + parts[3] + parts[4] + (parts[5] if len(parts) > 5 else ""),
"Exchange": parts[0],
"Market": parts[1],
"Side": parts[2],
"Price": parts[3],
"Amount": parts[4],
"Age": " ".join(parts[5:]) if len(parts) > 5 else None
}
orders.append(order)
elif table_type == 'pmm':
if len(parts) < 6:
continue
order = {
"id": parts[0] + parts[1] + parts[2] + parts[3] + parts[4] + (parts[6] if len(parts) > 6 else ""),
"Level": parts[0],
"Type": parts[1],
"Price": parts[2],
"Spread": parts[3],
"Amount (Adj)": parts[4],
"Amount (Orig)": parts[5],
"Age": " ".join(parts[6:]) if len(parts) > 6 else None
}
orders.append(order)
return orders
class BotPerformanceCard(Dashboard.Item):
@@ -88,8 +122,24 @@ class BotPerformanceCard(Dashboard.Item):
with mui.CardContent(sx={"flex": 1}):
with mui.Paper(elevation=2, sx={"padding": 2, "marginBottom": 2}):
mui.Typography("Status")
msg = parse_orders(bot_config["status"])
mui.Typography(msg, sx={"fontSize": "0.75rem"})
orders = parse_orders(bot_config["status"])
# mui.Typography(str(orders), sx={"fontSize": "0.75rem"})
# mui.Divider()
# Convert list of dictionaries to DataFrame
if orders != "No active maker orders":
df_orders = pd.DataFrame(orders)
rows = df_orders.to_dict(orient='records')
columns = [{'field': col, 'headerName': col} for col in df_orders.columns]
# rows, columns = df_orders.shape
mui.Typography(str(rows), sx={"fontSize": "0.75rem"})
mui.Divider()
mui.Typography(str(columns), sx={"fontSize": "0.75rem"})
mui.Divider()
mui.DataGrid(rows=rows, columns=columns)
else:
mui.Typography(str(orders), sx={"fontSize": "0.75rem"})
with mui.Accordion(sx={"padding": 2, "marginBottom": 2}):
with mui.AccordionSummary(expandIcon=""):
mui.Typography("Trades" + "(" + str(len(bot_config["trades"])) + ")")