feat(selection): show gold brick chart below volume in stock detail panel
Add an optional brick_chart series to the selection chart API, computed from the shared gold-brick formula when strategy=gold_brick, and render a fourth grid with red/green brick bars between the volume and J grids.
This commit is contained in:
@@ -9,6 +9,9 @@ from zhixing_server.modules.selection.application.chart import (
|
||||
GetSelectionChart,
|
||||
SelectionChartNotFound,
|
||||
)
|
||||
from zhixing_server.modules.selection.domain.gold_brick import (
|
||||
prepare_gold_brick_indicators,
|
||||
)
|
||||
from zhixing_server.modules.selection.domain.indicators import (
|
||||
compute_kdj,
|
||||
compute_zhixing_lines,
|
||||
@@ -100,6 +103,36 @@ def test_chart_filters_future_rows_and_preserves_nullable_points() -> None:
|
||||
assert chart.points[3].j is None
|
||||
|
||||
|
||||
def test_chart_skips_brick_series_by_default_and_computes_on_request() -> None:
|
||||
history = _history(260)
|
||||
reader = FakeReader(history)
|
||||
target = history.bars[-1].trade_date
|
||||
|
||||
default_chart = GetSelectionChart(reader).execute(history.ts_code, target)
|
||||
assert all(point.brick_chart is None for point in default_chart.points)
|
||||
|
||||
brick_chart = GetSelectionChart(reader).execute(
|
||||
history.ts_code,
|
||||
target,
|
||||
include_brick_chart=True,
|
||||
)
|
||||
|
||||
frame = pd.DataFrame(
|
||||
{
|
||||
"trade_date": [bar.trade_date for bar in history.bars],
|
||||
"open": [bar.open for bar in history.bars],
|
||||
"high": [bar.high for bar in history.bars],
|
||||
"low": [bar.low for bar in history.bars],
|
||||
"close": [bar.close for bar in history.bars],
|
||||
"volume": [bar.volume for bar in history.bars],
|
||||
}
|
||||
)
|
||||
expected = prepare_gold_brick_indicators(frame, history.ts_code)["brick_chart"]
|
||||
assert brick_chart.points[-1].brick_chart == pytest.approx(float(expected.iloc[-1]))
|
||||
assert brick_chart.points[0].trade_date == history.bars[10].trade_date
|
||||
assert brick_chart.points[0].brick_chart == pytest.approx(float(expected.iloc[10]))
|
||||
|
||||
|
||||
def test_chart_rejects_empty_history() -> None:
|
||||
reader = FakeReader(StockHistory(ts_code="000001.SZ", name="平安银行"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user