mirror of
https://github.com/ArvinLovegood/go-stock.git
synced 2025-07-19 00:00:09 +08:00
feat(app): 增加港股交易时间判断并更新相关功能
- 在 app.go 中添加 IsHKTradingTime 函数,用于判断当前时间是否在港股交易时间内 - 更新股票监控逻辑,使其在港股交易时间也能正常运行 - 在前端 stock 组件中添加股票代码标签,并根据股票代码动态显示货币符号 - 新增 app_test.go 文件,添加 IsHKTradingTime函数的单元测试
This commit is contained in:
parent
2bf7d1e31f
commit
fbb8b00315
28
app.go
28
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)
|
||||
|
15
app_test.go
Normal file
15
app_test.go
Normal file
@ -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)
|
||||
}
|
@ -730,7 +730,7 @@ AI赋能股票分析:自选股行情获取,成本盈亏展示,涨跌报警
|
||||
<n-grid :cols="1" :y-gap="6">
|
||||
<n-gi>
|
||||
<n-text :type="result.type" >
|
||||
<n-number-animation :duration="1000" :precision="2" :from="result['上次当前价格']" :to="Number(result['当前价格'])" />
|
||||
<n-number-animation :duration="1000" :precision="2" :from="result['上次当前价格']" :to="Number(result['当前价格'])" />
|
||||
</n-text>
|
||||
<n-text style="padding-left: 10px;" :type="result.type">
|
||||
<n-number-animation :duration="1000" :precision="3" :from="0" :to="result.changePercent" />%
|
||||
@ -755,6 +755,7 @@ AI赋能股票分析:自选股行情获取,成本盈亏展示,涨跌报警
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
<template #header-extra>
|
||||
<n-tag size="small" :bordered="false">{{result['股票代码']}}</n-tag>
|
||||
<n-button size="tiny" secondary type="primary" @click="removeMonitor(result['股票代码'],result['股票名称'],result.key)">
|
||||
取消关注
|
||||
</n-button>
|
||||
@ -813,7 +814,7 @@ AI赋能股票分析:自选股行情获取,成本盈亏展示,涨跌报警
|
||||
<n-form-item label="股票成本" path="costPrice">
|
||||
<n-input-number v-model:value="formModel.costPrice" min="0" placeholder="请输入股票成本" >
|
||||
<template #suffix>
|
||||
¥
|
||||
{{formModel.code.indexOf("hk")>=0?"HK$":"¥"}}
|
||||
</template>
|
||||
</n-input-number>
|
||||
</n-form-item>
|
||||
@ -834,7 +835,7 @@ AI赋能股票分析:自选股行情获取,成本盈亏展示,涨跌报警
|
||||
<n-form-item label="股价提醒" path="alarmPrice">
|
||||
<n-input-number v-model:value="formModel.alarmPrice" min="0" placeholder="请输入股价报警值(¥)" >
|
||||
<template #suffix>
|
||||
¥
|
||||
{{formModel.code.indexOf("hk")>=0?"HK$":"¥"}}
|
||||
</template>
|
||||
</n-input-number>
|
||||
</n-form-item>
|
||||
|
Loading…
x
Reference in New Issue
Block a user