fix(FEAT-MO-001): 校验相邻行情日期
This commit is contained in:
@@ -61,6 +61,40 @@ describe('TDX 行情映射', () => {
|
||||
expect(result[0]).toMatchObject({ price: 2105, changePercent: null, direction: 'flat' });
|
||||
});
|
||||
|
||||
it.each([
|
||||
['非法公历日期', ['20269999', '20260818']],
|
||||
['重复日期', ['20260818', '20260818']],
|
||||
['倒序日期', ['20260819', '20260818']],
|
||||
])('前一根 K 线为%s时保留指数当前价但不计算涨跌', (_caseName, dates) => {
|
||||
const result = mapIndexQuotes(
|
||||
{
|
||||
ErrorId: '0',
|
||||
Value: {
|
||||
'000001.SH': {
|
||||
Date: dates,
|
||||
Open: ['100', '200'],
|
||||
High: ['100', '200'],
|
||||
Low: ['100', '200'],
|
||||
Close: ['100', '200'],
|
||||
Amount: ['1', '1'],
|
||||
Volume: ['1', '1'],
|
||||
},
|
||||
},
|
||||
},
|
||||
[{ code: '000001.SH', name: '上证指数' }],
|
||||
);
|
||||
|
||||
expect(result).toEqual([
|
||||
expect.objectContaining({
|
||||
code: '000001.SH',
|
||||
price: 200,
|
||||
changePercent: null,
|
||||
direction: 'flat',
|
||||
tradeDate: '20260818',
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it('市场宽度映射只汇总可用的上涨和下跌家数', () => {
|
||||
expect(
|
||||
mapBreadthSnapshots([
|
||||
@@ -206,6 +240,28 @@ describe('TDX 行情映射', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('板块前一根 K 线日期无效时不进入强弱排序', () => {
|
||||
expect(
|
||||
mapSectorQuotes(
|
||||
{
|
||||
ErrorId: '0',
|
||||
Value: {
|
||||
'881001.SH': {
|
||||
Date: ['20269999', '20260818'],
|
||||
Open: ['100', '200'],
|
||||
High: ['100', '200'],
|
||||
Low: ['100', '200'],
|
||||
Close: ['100', '200'],
|
||||
Amount: ['1', '1'],
|
||||
Volume: ['1', '1'],
|
||||
},
|
||||
},
|
||||
},
|
||||
[{ code: '881001.SH', name: '畸形日期行业' }],
|
||||
),
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it('板块混合交易日时只保留最新交易日,避免把不同日期混排', () => {
|
||||
const series = (dates: string[], close: string[]) => ({
|
||||
Date: dates,
|
||||
|
||||
@@ -60,9 +60,13 @@ function mapIndexQuote(series: TdxKlineSeries, definition: IndexDefinition): Ind
|
||||
const previousPrice = toNumber(series.Close[lastIndex - 1]);
|
||||
const tradeDate = toTradeDate(series.Date[lastIndex]);
|
||||
if (price === null || !tradeDate) return null;
|
||||
const previousTradeDate = toTradeDate(series.Date[lastIndex - 1]);
|
||||
|
||||
const changePercent =
|
||||
previousPrice === null || previousPrice === 0
|
||||
previousPrice === null ||
|
||||
previousPrice === 0 ||
|
||||
previousTradeDate === null ||
|
||||
previousTradeDate >= tradeDate
|
||||
? null
|
||||
: Math.round(((price - previousPrice) / previousPrice) * 100 * 100) / 100;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user