feat: show open grid lots

This commit is contained in:
王鹏
2026-07-09 11:17:51 +08:00
parent fe11929aa0
commit 5d66423895
8 changed files with 338 additions and 1 deletions

View File

@@ -258,3 +258,43 @@ def test_service_returns_empty_grid_levels_without_realtime_price(tmp_path):
instrument = service.add_instrument(Instrument(id=None, code="510300", name="沪深300ETF", market="ETF"))
assert service.get_grid_level_suggestions(instrument.id, levels=10) == []
def test_service_returns_open_grid_lots_with_suggested_sell_price(tmp_path):
service = TradingService(tmp_path / "grid.db", quote_provider=FakeQuoteProvider())
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, 7),
side=TradeSide.BUY,
price=Decimal("4.00"),
quantity=1000,
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("4.12"),
quantity=400,
trade_group=TradeGroup.GRID,
)
)
service.refresh_quotes()
[lot] = service.get_open_grid_lots(instrument.id, as_of=date(2026, 7, 9))
assert lot.buy_price == Decimal("4.00")
assert lot.remaining_quantity == 600
assert lot.suggested_sell_price == Decimal("4.12")
assert lot.current_price == Decimal("4.12")
assert lot.status == "可卖"