feat: use realtime quotes in summaries
This commit is contained in:
@@ -4,7 +4,7 @@ from decimal import Decimal
|
||||
import pytest
|
||||
|
||||
from grid_trading.domain.calculations import CalculationError, calculate_positions, estimate_fees
|
||||
from grid_trading.domain.models import FeeRules, Instrument, Trade, TradeGroup, TradeSide
|
||||
from grid_trading.domain.models import FeeRules, Instrument, QuoteSnapshot, Trade, TradeGroup, TradeSide
|
||||
|
||||
|
||||
def make_trade(
|
||||
@@ -111,6 +111,36 @@ def test_t_plus_one_available_quantity_excludes_today_buys():
|
||||
assert summary.available_quantity == 200
|
||||
|
||||
|
||||
def test_quote_snapshot_overrides_manual_price_for_position_value():
|
||||
today = date(2026, 7, 8)
|
||||
instrument = Instrument(id=1, code="510300", name="沪深300ETF", manual_price=Decimal("3.90"))
|
||||
trades = [
|
||||
make_trade(
|
||||
trade_id=1,
|
||||
trade_date=today - timedelta(days=1),
|
||||
side=TradeSide.BUY,
|
||||
price="4.00",
|
||||
quantity=1000,
|
||||
trade_group=TradeGroup.BASE,
|
||||
)
|
||||
]
|
||||
quotes = {
|
||||
1: QuoteSnapshot(
|
||||
symbol="sh510300",
|
||||
code="510300",
|
||||
name="沪深300ETF",
|
||||
price=Decimal("4.12"),
|
||||
source="tencent",
|
||||
)
|
||||
}
|
||||
|
||||
[summary] = calculate_positions([instrument], trades, as_of=today, quote_snapshots=quotes)
|
||||
|
||||
assert summary.current_price == Decimal("4.12")
|
||||
assert summary.price_source == "tencent"
|
||||
assert summary.market_value == Decimal("4120.00")
|
||||
|
||||
|
||||
def test_sell_more_than_group_position_raises():
|
||||
today = date(2026, 7, 8)
|
||||
instrument = Instrument(id=1, code="159915", name="创业板ETF")
|
||||
|
||||
Reference in New Issue
Block a user