From fbb8b00315d6e95c59c060f71b4b5dab2c07dd67 Mon Sep 17 00:00:00 2001 From: ArvinLovegood Date: Mon, 24 Feb 2025 10:12:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(app):=20=E5=A2=9E=E5=8A=A0=E6=B8=AF?= =?UTF-8?q?=E8=82=A1=E4=BA=A4=E6=98=93=E6=97=B6=E9=97=B4=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E5=B9=B6=E6=9B=B4=E6=96=B0=E7=9B=B8=E5=85=B3=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 app.go 中添加 IsHKTradingTime 函数,用于判断当前时间是否在港股交易时间内 - 更新股票监控逻辑,使其在港股交易时间也能正常运行 - 在前端 stock 组件中添加股票代码标签,并根据股票代码动态显示货币符号 - 新增 app_test.go 文件,添加 IsHKTradingTime函数的单元测试 --- app.go | 28 +++++++++++++++++++++++++++- app_test.go | 15 +++++++++++++++ frontend/src/components/stock.vue | 7 ++++--- 3 files changed, 46 insertions(+), 4 deletions(-) create mode 100644 app_test.go diff --git a/app.go b/app.go index 0c33346..d2fc8f0 100644 --- a/app.go +++ b/app.go @@ -103,7 +103,7 @@ func (a *App) domReady(ctx context.Context) { ticker := time.NewTicker(time.Second * time.Duration(interval)) defer ticker.Stop() for range ticker.C { - if isTradingTime(time.Now()) { + if isTradingTime(time.Now()) || IsHKTradingTime(time.Now()) { MonitorStockPrices(a) } } @@ -202,6 +202,32 @@ func isTradingTime(date time.Time) bool { return false } +// IsHKTradingTime 判断当前时间是否在港股交易时间内 +func IsHKTradingTime(date time.Time) bool { + hour, minute, _ := date.Clock() + + // 开市前竞价时段:09:00 - 09:30 + if (hour == 9 && minute >= 0) || (hour == 9 && minute <= 30) { + return true + } + + // 上午持续交易时段:09:30 - 12:00 + if (hour == 9 && minute > 30) || (hour >= 10 && hour < 12) || (hour == 12 && minute == 0) { + return true + } + + // 下午持续交易时段:13:00 - 16:00 + if (hour == 13 && minute >= 0) || (hour >= 14 && hour < 16) || (hour == 16 && minute == 0) { + return true + } + + // 收市竞价交易时段:16:00 - 16:10 + if (hour == 16 && minute >= 0) || (hour == 16 && minute <= 10) { + return true + } + return false +} + func MonitorStockPrices(a *App) { dest := &[]data.FollowedStock{} db.Dao.Model(&data.FollowedStock{}).Find(dest) diff --git a/app_test.go b/app_test.go new file mode 100644 index 0000000..458fab9 --- /dev/null +++ b/app_test.go @@ -0,0 +1,15 @@ +package main + +import ( + "testing" + "time" +) + +// @Author spark +// @Date 2025/2/24 9:35 +// @Desc +// ----------------------------------------------------------------------------------- +func TestIsHKTradingTime(t *testing.T) { + f := IsHKTradingTime(time.Now()) + t.Log(f) +} diff --git a/frontend/src/components/stock.vue b/frontend/src/components/stock.vue index a56e73e..af8b476 100644 --- a/frontend/src/components/stock.vue +++ b/frontend/src/components/stock.vue @@ -730,7 +730,7 @@ AI赋能股票分析:自选股行情获取,成本盈亏展示,涨跌报警 - + % @@ -755,6 +755,7 @@ AI赋能股票分析:自选股行情获取,成本盈亏展示,涨跌报警