Skip to content

Commit

Permalink
risk&tv
Browse files Browse the repository at this point in the history
  • Loading branch information
51bitquant committed Jun 10, 2023
1 parent 52b2fba commit 241b51b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion howtrader/app/risk_manager/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,4 +238,4 @@ def get_best_ask(self) -> float:
"""获取最低卖价"""
if not self.ask_prices:
return 0
return min(self.ask_prices.values())
return min(self.ask_prices.values())
26 changes: 10 additions & 16 deletions howtrader/app/tradingview/ui/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

from howtrader.event import EventEngine, Event
from howtrader.trader.engine import MainEngine
from howtrader.trader.ui import QtWidgets, QtCore
from howtrader.trader.utility import load_json, save_json
from ..engine import APP_NAME, TVEngine, EVENT_TV_LOG, EVENT_TV_STRATEGY
from howtrader.trader.ui import QtCore, QtGui, QtWidgets
from howtrader.trader.ui.widget import (
Expand All @@ -25,7 +23,7 @@ def __init__(self, main_engine: MainEngine, event_engine: EventEngine) -> None:
self.main_engine: MainEngine = main_engine
self.event_engine: EventEngine = event_engine
self.tv_engine: TVEngine = main_engine.get_engine(APP_NAME)
self.managers: StrategyManager = {}
self.managers = {}

self.init_ui()
self.register_event()
Expand Down Expand Up @@ -131,7 +129,7 @@ def add_strategy(self) -> None:
editor: SettingEditor = SettingEditor(parameters, class_name=class_name)
n: int = editor.exec_()

if n == editor.Accepted:
if n == QtWidgets.QDialog.DialogCode.Accepted:
setting: dict = editor.get_setting()
vt_symbol: str = setting.pop("vt_symbol")
strategy_name: str = setting.pop("strategy_name")
Expand All @@ -150,7 +148,6 @@ def show(self) -> None:
self.showMaximized()



class StrategyManager(QtWidgets.QFrame):
"""
Manager for a strategy
Expand All @@ -172,7 +169,7 @@ def __init__(
def init_ui(self) -> None:
""""""
self.setFixedHeight(300)
self.setFrameShape(self.Box)
self.setFrameShape(QtWidgets.QFrame.Shape.Box)
self.setLineWidth(1)

self.init_button: QtWidgets.QPushButton = QtWidgets.QPushButton("Init Strategy")
Expand Down Expand Up @@ -202,7 +199,7 @@ def init_ui(self) -> None:
f"{strategy_name} - {vt_symbol} - {tv_id} ({class_name} by {author})"
)
label: QtWidgets.QLabel = QtWidgets.QLabel(label_text)
label.setAlignment(QtCore.Qt.AlignCenter)
label.setAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)

self.parameters_monitor: DataMonitor = DataMonitor(self._data["parameters"])
self.variables_monitor: DataMonitor = DataMonitor(self._data["variables"])
Expand All @@ -222,7 +219,6 @@ def init_ui(self) -> None:
self.setLayout(vbox)

def update_data(self, data: dict) -> None:
""""""
self._data = data

self.parameters_monitor.update_data(data["parameters"])
Expand Down Expand Up @@ -257,18 +253,16 @@ def start_strategy(self) -> None:
self.tv_engine.start_strategy(self.strategy_name)

def stop_strategy(self) -> None:
""""""
self.tv_engine.stop_strategy(self.strategy_name)

def edit_strategy(self) -> None:
""""""
strategy_name: str = self._data["strategy_name"]

parameters: dict = self.tv_engine.get_strategy_parameters(strategy_name)
editor: SettingEditor = SettingEditor(parameters, strategy_name=strategy_name)
n: int = editor.exec_()

if n == editor.Accepted:
if n == QtWidgets.QDialog.DialogCode.Accepted:
setting: dict = editor.get_setting()
self.tv_engine.edit_strategy(strategy_name, setting)

Expand Down Expand Up @@ -303,16 +297,16 @@ def init_ui(self) -> None:

self.setRowCount(1)
self.verticalHeader().setSectionResizeMode(
QtWidgets.QHeaderView.Stretch
QtWidgets.QHeaderView.ResizeMode.Stretch
)
self.verticalHeader().setVisible(False)
self.setEditTriggers(self.NoEditTriggers)
self.setEditTriggers(QtWidgets.QAbstractItemView.EditTrigger.NoEditTriggers)

for column, name in enumerate(self._data.keys()):
value = self._data[name]

cell: QtWidgets.QTableWidgetItem = QtWidgets.QTableWidgetItem(str(value))
cell.setTextAlignment(QtCore.Qt.AlignCenter)
cell.setTextAlignment(QtCore.Qt.AlignmentFlag.AlignCenter)

self.setItem(0, column, cell)
self.cells[name] = cell
Expand Down Expand Up @@ -345,7 +339,7 @@ def init_ui(self) -> None:
super(LogMonitor, self).init_ui()

self.horizontalHeader().setSectionResizeMode(
1, QtWidgets.QHeaderView.Stretch
1, QtWidgets.QHeaderView.ResizeMode.Stretch
)

def insert_new_row(self, data) -> None:
Expand Down Expand Up @@ -441,4 +435,4 @@ def get_setting(self) -> dict:

setting[name] = value

return setting
return setting

0 comments on commit 241b51b

Please sign in to comment.