feat: 优化界面并补充网格成交分析
This commit is contained in:
@@ -3,8 +3,13 @@ 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, QuoteSnapshot, Trade, TradeGroup, TradeSide
|
||||
from grid_trading.domain.calculations import (
|
||||
CalculationError,
|
||||
calculate_account_summary,
|
||||
calculate_positions,
|
||||
estimate_fees,
|
||||
)
|
||||
from grid_trading.domain.models import Account, FeeRules, Instrument, QuoteSnapshot, Trade, TradeGroup, TradeSide
|
||||
|
||||
|
||||
def make_trade(
|
||||
@@ -175,6 +180,39 @@ def test_missing_quote_does_not_use_manual_or_last_trade_price_for_current_price
|
||||
assert summary.floating_pnl is None
|
||||
|
||||
|
||||
def test_account_summary_caps_capital_usage_when_cash_is_negative():
|
||||
today = date(2026, 7, 8)
|
||||
account = Account(id=1, name="主账户", initial_cash=Decimal("100"))
|
||||
instrument = Instrument(id=1, code="600588", name="用友网络")
|
||||
trades = [
|
||||
make_trade(
|
||||
trade_id=1,
|
||||
trade_date=today,
|
||||
side=TradeSide.BUY,
|
||||
price="1.50",
|
||||
quantity=100,
|
||||
trade_group=TradeGroup.BASE,
|
||||
)
|
||||
]
|
||||
quotes = {
|
||||
1: QuoteSnapshot(
|
||||
symbol="sh600588",
|
||||
code="600588",
|
||||
name="用友网络",
|
||||
price=Decimal("1.00"),
|
||||
source="tencent",
|
||||
)
|
||||
}
|
||||
|
||||
positions = calculate_positions([instrument], trades, as_of=today, quote_snapshots=quotes)
|
||||
summary = calculate_account_summary(account, positions, [], trades)
|
||||
|
||||
assert summary.cash == Decimal("-50.00")
|
||||
assert summary.market_value == Decimal("100.00")
|
||||
assert summary.total_assets == Decimal("50.00")
|
||||
assert summary.capital_usage_rate == Decimal("1.0000")
|
||||
|
||||
|
||||
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