feat: show open grid lots
This commit is contained in:
@@ -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 == "可卖"
|
||||
|
||||
Reference in New Issue
Block a user