feat: 优化界面并补充网格成交分析

This commit is contained in:
王鹏
2026-07-14 16:21:32 +08:00
parent 8b51463387
commit b1eea9f5b4
12 changed files with 1014 additions and 66 deletions

View File

@@ -298,3 +298,55 @@ def test_service_returns_open_grid_lots_with_suggested_sell_price(tmp_path):
assert lot.suggested_sell_price == Decimal("4.12")
assert lot.current_price == Decimal("4.12")
assert lot.status == "可卖"
def test_service_returns_grid_trade_matches(tmp_path):
service = TradingService(tmp_path / "grid.db")
service.ensure_defaults()
account = service.get_active_account()
instrument = service.add_instrument(Instrument(id=None, code="510300", name="沪深300ETF", market="ETF"))
service.save_trade(
Trade(
id=None,
account_id=account.id,
instrument_id=instrument.id,
trade_date=date(2026, 7, 6),
side=TradeSide.BUY,
price=Decimal("10.00"),
quantity=300,
trade_group=TradeGroup.GRID,
)
)
service.save_trade(
Trade(
id=None,
account_id=account.id,
instrument_id=instrument.id,
trade_date=date(2026, 7, 7),
side=TradeSide.BUY,
price=Decimal("9.50"),
quantity=200,
trade_group=TradeGroup.GRID,
)
)
service.save_trade(
Trade(
id=None,
account_id=account.id,
instrument_id=instrument.id,
trade_date=date(2026, 7, 8),
side=TradeSide.SELL,
price=Decimal("10.30"),
quantity=400,
trade_group=TradeGroup.GRID,
)
)
matches = service.get_grid_trade_matches(instrument.id, as_of=date(2026, 7, 9))
assert len(matches) == 2
assert matches[0].buy_trade_id is not None
assert matches[0].matched_quantity == 300
assert matches[0].gross_profit == Decimal("90.00")
assert matches[1].matched_quantity == 100
assert matches[1].gross_profit == Decimal("80.00")