@ysgroup/core 0.1.33 → 0.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/calendar.ts +70 -1
- package/src/index.ts +5 -0
package/package.json
CHANGED
package/src/calendar.ts
CHANGED
|
@@ -22,6 +22,72 @@ export interface YsCalendarDay {
|
|
|
22
22
|
workday?: boolean;
|
|
23
23
|
trading?: boolean;
|
|
24
24
|
covered?: boolean;
|
|
25
|
+
/** 交易所额外休市的原因(国务院安排是工作日、交易所另行休市,如 2024-02-09 除夕);不是时为空。 */
|
|
26
|
+
market_closed?: string;
|
|
27
|
+
/** 当晚有没有期货夜盘:只对交易日给出;下一交易日所在年份还没有安排时为 null(未知)。 */
|
|
28
|
+
night_session?: boolean | null;
|
|
29
|
+
/** 当晚夜盘归属的交易日(有夜盘时才有)。 */
|
|
30
|
+
night_trading_day?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 某一年日历数据的来源:auth Auth 下发、bundled 内置快照、unpublished 国务院还没发布、unknown 没有数据。 */
|
|
34
|
+
export type YsCalendarYearSource =
|
|
35
|
+
| "auth"
|
|
36
|
+
| "bundled"
|
|
37
|
+
| "unpublished"
|
|
38
|
+
| "unknown";
|
|
39
|
+
|
|
40
|
+
/** 一个数据源的核对结果(Auth calendar_years.checks)。 */
|
|
41
|
+
export interface YsCalendarCheck {
|
|
42
|
+
source: string;
|
|
43
|
+
label?: string;
|
|
44
|
+
kind?: string;
|
|
45
|
+
status:
|
|
46
|
+
| "agree"
|
|
47
|
+
| "differ"
|
|
48
|
+
| "unavailable"
|
|
49
|
+
| "no_data"
|
|
50
|
+
| "unpublished"
|
|
51
|
+
| "skipped";
|
|
52
|
+
status_label?: string;
|
|
53
|
+
covered_from?: string;
|
|
54
|
+
covered_to?: string;
|
|
55
|
+
differences?: string[];
|
|
56
|
+
message?: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** 一年的来源与核对状态(服务端 CalendarService.year_states() 的一行)。 */
|
|
60
|
+
export interface YsCalendarYearInfo {
|
|
61
|
+
year: number;
|
|
62
|
+
status: YsCalendarYearSource;
|
|
63
|
+
status_label?: string;
|
|
64
|
+
covered?: boolean;
|
|
65
|
+
/** 已与交易所数据核对且一致。 */
|
|
66
|
+
verified?: boolean;
|
|
67
|
+
checks?: YsCalendarCheck[];
|
|
68
|
+
checked_at?: number | null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export const YS_CALENDAR_SOURCE_LABELS: Record<YsCalendarYearSource, string> = {
|
|
72
|
+
auth: "Auth 下发",
|
|
73
|
+
bundled: "内置数据",
|
|
74
|
+
unpublished: "国务院还没发布",
|
|
75
|
+
unknown: "还没有数据",
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** 「Auth 下发 · 已与交易所核对」「内置数据 · 已核验」「Auth 下发 · 按国务院安排推算,未经交易所核对」。 */
|
|
79
|
+
export function ysCalendarYearText(
|
|
80
|
+
info: YsCalendarYearInfo | undefined,
|
|
81
|
+
): string {
|
|
82
|
+
if (!info) return "";
|
|
83
|
+
const base =
|
|
84
|
+
info.status_label || YS_CALENDAR_SOURCE_LABELS[info.status] || "";
|
|
85
|
+
if (info.status === "unpublished" || info.status === "unknown") return base;
|
|
86
|
+
const differ = info.checks?.some((item) => item.status === "differ");
|
|
87
|
+
if (differ) return `${base} · 数据源有差异`;
|
|
88
|
+
return info.verified
|
|
89
|
+
? `${base} · 已与交易所核对`
|
|
90
|
+
: `${base} · 按国务院安排推算,未经交易所核对`;
|
|
25
91
|
}
|
|
26
92
|
|
|
27
93
|
export interface YsMonthCell {
|
|
@@ -249,7 +315,7 @@ export function ysTradingMarks(
|
|
|
249
315
|
break;
|
|
250
316
|
}
|
|
251
317
|
if (isTrading(next)) break;
|
|
252
|
-
if (next.kind === "holiday") holiday = true;
|
|
318
|
+
if (next.kind === "holiday" || next.market_closed) holiday = true;
|
|
253
319
|
cursor = ysAddDays(cursor, step);
|
|
254
320
|
}
|
|
255
321
|
if (known && holiday) mark.tags.push(tag);
|
|
@@ -282,6 +348,8 @@ export interface YsMonthSummary {
|
|
|
282
348
|
closed: number;
|
|
283
349
|
holidays: number;
|
|
284
350
|
adjusted: number;
|
|
351
|
+
/** 交易所额外休市天数(国务院安排是工作日)。 */
|
|
352
|
+
marketClosed: number;
|
|
285
353
|
}
|
|
286
354
|
|
|
287
355
|
/** 一个月的工作日、交易日、休市、放假、调休上班天数。 */
|
|
@@ -302,6 +370,7 @@ export function ysMonthSummary(
|
|
|
302
370
|
closed: count((item) => !item.trading),
|
|
303
371
|
holidays: count((item) => item.kind === "holiday"),
|
|
304
372
|
adjusted: count((item) => item.kind === "adjusted"),
|
|
373
|
+
marketClosed: count((item) => Boolean(item.market_closed)),
|
|
305
374
|
};
|
|
306
375
|
}
|
|
307
376
|
|
package/src/index.ts
CHANGED
|
@@ -119,10 +119,12 @@ export {
|
|
|
119
119
|
type YsStatusOption,
|
|
120
120
|
} from "./status";
|
|
121
121
|
export {
|
|
122
|
+
YS_CALENDAR_SOURCE_LABELS,
|
|
122
123
|
YS_DAY_KIND_LABELS,
|
|
123
124
|
YS_TRADING_TAG_LABELS,
|
|
124
125
|
YS_WEEKDAY_LABELS,
|
|
125
126
|
ysAddDays,
|
|
127
|
+
ysCalendarYearText,
|
|
126
128
|
ysDateTitle,
|
|
127
129
|
ysDaysBetween,
|
|
128
130
|
ysDaysInMonth,
|
|
@@ -138,7 +140,10 @@ export {
|
|
|
138
140
|
ysDayDetail,
|
|
139
141
|
ysWeekday,
|
|
140
142
|
ysWeekdayLabel,
|
|
143
|
+
type YsCalendarCheck,
|
|
141
144
|
type YsCalendarDay,
|
|
145
|
+
type YsCalendarYearInfo,
|
|
146
|
+
type YsCalendarYearSource,
|
|
142
147
|
type YsDayDetail,
|
|
143
148
|
type YsDayOrdinal,
|
|
144
149
|
type YsMonthSummary,
|