品种增加每点价值字段,PNL计算支持不同品种差异化配置
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -74,7 +74,12 @@ def open_trade(
|
||||
):
|
||||
code = contract_code.upper()
|
||||
contract = db.query(Contract).filter(Contract.code == code).first()
|
||||
product_code = contract.product.code if contract else code[:2]
|
||||
if contract:
|
||||
product = contract.product
|
||||
else:
|
||||
product = db.query(Product).filter(Product.code == code[:2]).first()
|
||||
product_code = product.code if product else code[:2]
|
||||
point_value = product.point_value if product else 20
|
||||
|
||||
t = Trade(
|
||||
product_code=product_code,
|
||||
@@ -83,6 +88,7 @@ def open_trade(
|
||||
open_date=date.fromisoformat(open_date),
|
||||
open_price=open_price,
|
||||
open_fee=open_fee,
|
||||
point_value=point_value,
|
||||
status="open",
|
||||
)
|
||||
db.add(t)
|
||||
@@ -127,7 +133,12 @@ def edit_trade(
|
||||
if t:
|
||||
code = contract_code.upper()
|
||||
contract = db.query(Contract).filter(Contract.code == code).first()
|
||||
t.product_code = contract.product.code if contract else code[:2]
|
||||
if contract:
|
||||
product = contract.product
|
||||
else:
|
||||
product = db.query(Product).filter(Product.code == code[:2]).first()
|
||||
t.product_code = product.code if product else code[:2]
|
||||
t.point_value = product.point_value if product else 20
|
||||
t.contract_code = code
|
||||
t.direction = direction
|
||||
t.open_date = date.fromisoformat(open_date)
|
||||
|
||||
Reference in New Issue
Block a user