fix: separate trade price from realtime price

This commit is contained in:
王鹏
2026-07-09 10:45:27 +08:00
parent 5bbc4e607a
commit 15636fb910
9 changed files with 105 additions and 55 deletions

View File

@@ -1,7 +1,7 @@
from __future__ import annotations
from datetime import date
from decimal import Decimal, InvalidOperation
from decimal import Decimal
from PySide6.QtCore import QDate
from PySide6.QtWidgets import (
@@ -81,7 +81,6 @@ class InstrumentDialog(QDialog):
self.lot_size_edit = QSpinBox()
self.lot_size_edit.setRange(1, 1_000_000)
self.lot_size_edit.setValue(instrument.lot_size if instrument else 100)
self.manual_price_edit = QLineEdit(str(instrument.manual_price or "") if instrument else "")
self.allow_odd_lot_edit = QCheckBox("允许非整手")
self.allow_odd_lot_edit.setChecked(instrument.allow_odd_lot if instrument else False)
@@ -90,7 +89,6 @@ class InstrumentDialog(QDialog):
form.addRow("名称", self.name_edit)
form.addRow("市场", self.market_edit)
form.addRow("交易单位", self.lot_size_edit)
form.addRow("手动价格", self.manual_price_edit)
form.addRow("", self.allow_odd_lot_edit)
buttons = QDialogButtonBox(QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel)
@@ -102,14 +100,13 @@ class InstrumentDialog(QDialog):
layout.addWidget(buttons)
def to_instrument(self) -> Instrument:
manual_price = _optional_decimal(self.manual_price_edit.text().strip(), "手动价格")
return Instrument(
id=self._instrument.id if self._instrument else None,
code=self.code_edit.text().strip(),
name=self.name_edit.text().strip(),
market=self.market_edit.currentText(),
lot_size=self.lot_size_edit.value(),
manual_price=manual_price,
manual_price=None,
allow_odd_lot=self.allow_odd_lot_edit.isChecked(),
active=True,
)
@@ -227,7 +224,7 @@ class TradeDialog(QDialog):
form.addRow("日期", self.date_edit)
form.addRow("方向", self.side_edit)
form.addRow("分组", self.group_edit)
form.addRow("", self.price_edit)
form.addRow("成交", self.price_edit)
form.addRow("数量", self.quantity_edit)
form.addRow(fee_row)
form.addRow("备注", self.notes_edit)
@@ -291,10 +288,3 @@ def _percent_spinbox(value: Decimal) -> QDoubleSpinBox:
return spinbox
def _optional_decimal(raw: str, label: str) -> Decimal | None:
if not raw:
return None
try:
return Decimal(raw)
except InvalidOperation as exc:
raise ValueError(f"{label} 不是有效数字") from exc