koishi-plugin-stock 2.0.13 → 2.0.14

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.
Files changed (3) hide show
  1. package/README.md +5 -0
  2. package/lib/index.js +16 -12
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -61,6 +61,11 @@ npm install koishi-plugin-stock
61
61
 
62
62
  ## 更新日志
63
63
 
64
+ ### v2.0.14 (2026-02-28)
65
+ - 优化交易日判断:使用stock.svip886.com提供的专业交易日API替代timor.tech节假日接口
66
+ - 改进API调用:直接解析JSON响应,提高判断准确性
67
+ - 增强错误处理:API请求失败时默认跳过任务,确保安全性
68
+
64
69
  ### v2.0.13 (2026-02-25)
65
70
  - 根治编码问题:将心法数据直接嵌入TypeScript代码,避免JSON文件跨平台编码兼容性问题
66
71
  - 简化部署:不再依赖外部JSON文件,减少文件读取和解析开销
package/lib/index.js CHANGED
@@ -265,24 +265,28 @@ function apply(ctx, config) {
265
265
  logger.info(`[任务触发] 命中 ${activeTasks.length} 个广播任务 (时间: ${currentTime})`);
266
266
  try {
267
267
  const shanghaiDate = new Date(now.toLocaleString('en-US', { timeZone: 'Asia/Shanghai' }));
268
- const isWeekend = (shanghaiDate.getDay() === 0 || shanghaiDate.getDay() === 6);
269
- const year = shanghaiDate.getFullYear();
270
- const month = (shanghaiDate.getMonth() + 1).toString().padStart(2, '0');
271
- const day = shanghaiDate.getDate().toString().padStart(2, '0');
272
- const dateStr = `${year}-${month}-${day}`;
273
- let tradingDay = !isWeekend;
268
+ //判断是否为交易日
269
+ let tradingDay = false;
274
270
  try {
275
- const holidayData = await ctx.http.get(`https://timor.tech/api/holiday/info/${dateStr}`);
276
- if (holidayData && typeof holidayData === 'object' && holidayData.type) {
277
- const typeCode = holidayData.type.type;
278
- tradingDay = (typeCode === 0 || typeCode === 3);
271
+ const tradingResponse = await ctx.http.get('https://stock.svip886.com/api/is_trading_day');
272
+ //检查响应结构
273
+ if (tradingResponse && typeof tradingResponse === 'object' && tradingResponse.success === true) {
274
+ tradingDay = tradingResponse.is_trading_day === true;
275
+ logger.info(`[交易日判断] 日期: ${tradingResponse.date}, 是否交易日: ${tradingDay}, 最近交易日: ${tradingResponse.latest_trade_date}`);
276
+ }
277
+ else {
278
+ logger.error('[交易日判断] API返回格式异常');
279
+ return;
279
280
  }
280
281
  }
281
282
  catch (e) {
282
- logger.warn(`节假日API请求失败: ${e.message}`);
283
+ logger.error(`[交易日判断] API请求失败: ${e.message}`);
284
+ //请求失败时,默认不执行任务以保证安全
285
+ logger.warn('[交易日判断] 请求失败,默认跳过任务');
286
+ return;
283
287
  }
284
288
  if (!tradingDay) {
285
- logger.info(`[定时任务跳过] ${dateStr} 非交易日`);
289
+ logger.info(`[定时任务跳过] 今日非交易日`);
286
290
  return;
287
291
  }
288
292
  for (const task of activeTasks) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "koishi-plugin-stock",
3
- "version": "2.0.13",
3
+ "version": "2.0.14",
4
4
  "description": "A Koishi plugin that fetches stock data and provides market analysis, including active market cap, stock alerts, limit-up board, stock selection features, and heart method card drawing with configurable blacklists for each command.",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",