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赋能股票分析:自选股行情获取,成本盈亏展示,涨跌报警