rebuild(audit): complete entity detail and market preview

This commit is contained in:
leefer
2026-07-30 09:25:52 +08:00
parent d1b3b977d2
commit 4fc8691eee
27 changed files with 946 additions and 35 deletions
+81
View File
@@ -204,6 +204,87 @@ def test_latest_daily_chart_drops_empty_premarket_bar(tmp_path) -> None:
assert series.points[-1].amount == 13320
def test_entity_detail_uses_selected_bar_previous_close_and_complete_stock_sections(
tmp_path,
) -> None:
market = gateway(tmp_path)
database = market._database
repository = MarketRepository()
with database.transaction() as connection:
connection.execute(
"UPDATE market_summaries SET payload_json = ? WHERE trade_date = ?",
(
json.dumps(
{
"overview": {},
"limits": [
{
"identifier": "000001.SZ", "code": "000001",
"reason": "银行板块走强", "streak": 1,
"first_time": "09:35", "last_time": "14:20", "open_times": 0,
}
],
}
),
"2026-07-29",
),
)
snapshot_id = connection.execute(
"""
INSERT INTO screener_factor_snapshots
(trade_date, version, observed_at, state, source_set_json,
coverage_json, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?)
"""
,
(
"2026-07-29",
"detail-v1",
"2026-07-29T15:05:00+08:00",
"final",
'["tushare"]',
"{}",
"2026-07-29T15:05:00+08:00",
),
).lastrowid
connection.execute(
"""
INSERT INTO screener_factor_values
(snapshot_id, identifier, code, name, sector, listed_days, is_st, payload_json)
VALUES (?, '000001.SZ', '000001', '平安银行', '银行', 1000, 0, ?)
""",
(
snapshot_id,
json.dumps(
{
"name": "平安银行", "sector": "银行", "turnover_rate": 2.5,
"return_5d": 3.2, "return_20d": 8.6, "total_mv_billion": 2100,
"circ_mv_billion": 1900, "net_flow_million": 12.5,
"large_flow_million": 8.1, "net_flow_5d_million": 35.2,
"flow_to_circ_mv_5d": 0.0185,
}
),
),
)
detail = MarketSnapshotService(database, repository, market).entity_detail(
"stock", "000001.SZ", "2026-07-29"
)
assert detail["trade_date"] == "2026-07-29"
assert detail["price"] == 11.1
assert detail["previous_close"] == 10.8
assert detail["change"] == pytest.approx(2.7778)
assert detail["entity"]["name"] == "平安银行"
assert detail["money_flow"]["available"] is True
assert detail["money_flow"]["net_million"] == 12.5
assert detail["event"] == {
"status": "涨停", "reason": "银行板块走强", "streak": 1,
"first_time": "09:35", "last_time": "14:20", "open_times": 0,
"seal_amount": None,
}
def test_minute_chart_contract_has_real_session_bounds_and_hides_source(tmp_path) -> None:
application = create_application(Settings.for_test(tmp_path))