feat: 优化界面并补充网格成交分析
This commit is contained in:
@@ -2,7 +2,7 @@ from datetime import date, timedelta
|
||||
from decimal import Decimal
|
||||
|
||||
from grid_trading.domain.models import Trade, TradeGroup, TradeSide
|
||||
from grid_trading.domain.open_grid_lots import calculate_open_grid_lots
|
||||
from grid_trading.domain.open_grid_lots import calculate_grid_trade_matches, calculate_open_grid_lots
|
||||
|
||||
|
||||
def make_trade(
|
||||
@@ -80,6 +80,52 @@ def test_calculate_open_grid_lots_fifo_matches_grid_sells_against_grid_buys():
|
||||
assert lot.status == "可卖"
|
||||
|
||||
|
||||
def test_calculate_grid_trade_matches_splits_sell_against_fifo_buy_lots():
|
||||
today = date(2026, 7, 9)
|
||||
trades = [
|
||||
make_trade(
|
||||
trade_id=1,
|
||||
trade_date=today - timedelta(days=3),
|
||||
side=TradeSide.BUY,
|
||||
price="10.00",
|
||||
quantity=300,
|
||||
),
|
||||
make_trade(
|
||||
trade_id=2,
|
||||
trade_date=today - timedelta(days=2),
|
||||
side=TradeSide.BUY,
|
||||
price="9.50",
|
||||
quantity=200,
|
||||
),
|
||||
make_trade(
|
||||
trade_id=3,
|
||||
trade_date=today - timedelta(days=1),
|
||||
side=TradeSide.SELL,
|
||||
price="10.30",
|
||||
quantity=350,
|
||||
),
|
||||
]
|
||||
|
||||
matches = calculate_grid_trade_matches(trades, as_of=today)
|
||||
|
||||
assert len(matches) == 2
|
||||
assert matches[0].sell_trade_id == 3
|
||||
assert matches[0].sell_date == today - timedelta(days=1)
|
||||
assert matches[0].sell_price == Decimal("10.30")
|
||||
assert matches[0].buy_trade_id == 1
|
||||
assert matches[0].buy_date == today - timedelta(days=3)
|
||||
assert matches[0].buy_price == Decimal("10.00")
|
||||
assert matches[0].matched_quantity == 300
|
||||
assert matches[0].buy_amount == Decimal("3000.00")
|
||||
assert matches[0].sell_amount == Decimal("3090.00")
|
||||
assert matches[0].gross_profit == Decimal("90.00")
|
||||
assert matches[1].buy_trade_id == 2
|
||||
assert matches[1].matched_quantity == 50
|
||||
assert matches[1].buy_amount == Decimal("475.00")
|
||||
assert matches[1].sell_amount == Decimal("515.00")
|
||||
assert matches[1].gross_profit == Decimal("40.00")
|
||||
|
||||
|
||||
def test_calculate_open_grid_lots_reports_not_reached_and_missing_quote_statuses():
|
||||
today = date(2026, 7, 9)
|
||||
trades = [
|
||||
|
||||
Reference in New Issue
Block a user