From 93e548d8a73c0267b589f49621cb73e16a128107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E9=B9=8F?= Date: Wed, 8 Jul 2026 22:03:57 +0800 Subject: [PATCH] feat: refresh Tencent quotes from GUI --- src/grid_trading/ui/main_window.py | 10 +++++++++- tests/test_ui.py | 3 ++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/grid_trading/ui/main_window.py b/src/grid_trading/ui/main_window.py index a3c326c..d6dedeb 100644 --- a/src/grid_trading/ui/main_window.py +++ b/src/grid_trading/ui/main_window.py @@ -159,7 +159,7 @@ class MainWindow(QMainWindow): def _create_toolbar(self) -> QHBoxLayout: layout = QHBoxLayout() buttons = [ - ("刷新", self.refresh_all), + ("刷新行情", self._refresh_quotes), ("账户设置", self._edit_account), ("添加标的", self._add_instrument), ("录入成交", self._add_trade), @@ -187,6 +187,14 @@ class MainWindow(QMainWindow): self._fill_holdings_table() self._refresh_details() + def _refresh_quotes(self) -> None: + try: + self.service.refresh_quotes() + except Exception as exc: + QMessageBox.warning(self, "行情刷新失败", str(exc)) + return + self.refresh_all() + def _fill_holdings_table(self) -> None: self.holdings_table.setRowCount(len(self._positions)) for row, position in enumerate(self._positions): diff --git a/tests/test_ui.py b/tests/test_ui.py index 9a2b3d4..6b26e62 100644 --- a/tests/test_ui.py +++ b/tests/test_ui.py @@ -14,7 +14,7 @@ def test_formatters_render_money_percent_and_empty_values(): def test_main_window_can_be_constructed_offscreen(tmp_path, monkeypatch): monkeypatch.setenv("QT_QPA_PLATFORM", "offscreen") - from PySide6.QtWidgets import QApplication + from PySide6.QtWidgets import QApplication, QPushButton from grid_trading.services.trading_service import TradingService from grid_trading.ui.main_window import MainWindow @@ -25,6 +25,7 @@ def test_main_window_can_be_constructed_offscreen(tmp_path, monkeypatch): assert window.windowTitle() == "Grid Trading Manager" assert window.holdings_table.columnCount() > 0 + assert any(button.text() == "刷新行情" for button in window.findChildren(QPushButton)) window.close() service.close()