37172-vm/algo_trader/ui/dashboard.py
2025-12-27 04:26:41 +00:00

65 lines
2.6 KiB
Python

from PySide6.QtWidgets import QWidget, QLabel, QVBoxLayout, QGridLayout
from PySide6.QtCore import Qt
class DashboardPanel(QWidget):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
layout = QVBoxLayout(self)
# Title
title_label = QLabel("Dashboard")
title_label.setAlignment(Qt.AlignCenter)
title_label.setStyleSheet("font-size: 24px; font-weight: bold; margin-bottom: 20px;")
layout.addWidget(title_label)
# Metrics Grid
metrics_grid = QGridLayout()
metrics_grid.setSpacing(15)
# Account Balance
self.account_balance_label = self._create_metric_label("Account Balance:", "$100,000.00")
metrics_grid.addWidget(self.account_balance_label[0], 0, 0)
metrics_grid.addWidget(self.account_balance_label[1], 0, 1)
# Today's P&L
self.pnl_label = self._create_metric_label("Today's P&L:", "+$500.00 (0.5%)")
metrics_grid.addWidget(self.pnl_label[0], 1, 0)
metrics_grid.addWidget(self.pnl_label[1], 1, 1)
# Open Positions
self.open_positions_label = self._create_metric_label("Open Positions:", "5")
metrics_grid.addWidget(self.open_positions_label[0], 2, 0)
metrics_grid.addWidget(self.open_positions_label[1], 2, 1)
# Pending Orders
self.pending_orders_label = self._create_metric_label("Pending Orders:", "2")
metrics_grid.addWidget(self.pending_orders_label[0], 3, 0)
metrics_grid.addWidget(self.pending_orders_label[1], 3, 1)
# Last Tick
self.last_tick_label = self._create_metric_label("Last Tick:", "N/A")
metrics_grid.addWidget(self.last_tick_label[0], 4, 0)
metrics_grid.addWidget(self.last_tick_label[1], 4, 1)
layout.addLayout(metrics_grid)
layout.addStretch(1) # Pushes content to the top
self.setLayout(layout)
def _create_metric_label(self, title, value):
title_label = QLabel(title)
title_label.setStyleSheet("font-weight: bold;")
value_label = QLabel(value)
return title_label, value_label
def update_market_data(self, tick_data):
# Example: Update Last Tick label with relevant info
if "symbol" in tick_data and "ltp" in tick_data:
self.last_tick_label[1].setText(f"{tick_data['symbol']}: {tick_data['ltp']}")
elif isinstance(tick_data, dict):
# Fallback for any other dict data
self.last_tick_label[1].setText(str(tick_data))
else:
self.last_tick_label[1].setText(str(tick_data))