代码拉取完成,页面将自动刷新
package models
import (
"gitee.com/quant1x/engine/factors"
"gitee.com/quant1x/exchange"
"gitee.com/quant1x/gotdx"
"gitee.com/quant1x/gotdx/quotes"
"gitee.com/quant1x/gox/api"
"gitee.com/quant1x/gox/logger"
"gitee.com/quant1x/num"
)
func QuoteSnapshotFromProtocol(v quotes.Snapshot) factors.QuoteSnapshot {
snapshot := factors.QuoteSnapshot{}
_ = api.Copy(&snapshot, &v)
securityCode := exchange.GetSecurityCode(v.Market, v.Code)
snapshot.Code = securityCode
snapshot.OpeningChangeRate = num.NetChangeRate(snapshot.LastClose, snapshot.Open)
snapshot.ChangeRate = num.NetChangeRate(snapshot.LastClose, snapshot.Price)
snapshot.PremiumRate = num.NetChangeRate(snapshot.Open, snapshot.Price)
snapshot.OpenBiddingDirection, snapshot.OpenVolumeDirection = v.CheckDirection()
// 涨跌力度
snapshot.ChangePower = float64(snapshot.OpenVolume) / snapshot.OpeningChangeRate
snapshot.AverageBiddingVolume = v.AverageBiddingVolume()
// 补全F10相关
f10 := factors.GetL5F10(securityCode)
if f10 != nil {
snapshot.Name = f10.SecurityName
snapshot.Capital = f10.Capital
snapshot.FreeCapital = f10.FreeCapital
snapshot.OpenTurnZ = f10.TurnZ(snapshot.OpenVolume)
}
// 补全扩展相关
history := factors.GetL5History(securityCode)
if history != nil && history.MV5 > 0 {
lastMinuteVolume := history.GetMV5()
snapshot.OpenQuantityRatio = float64(snapshot.OpenVolume) / lastMinuteVolume
minuteVolume := float64(snapshot.Vol) / float64(exchange.Minutes(snapshot.Date))
snapshot.QuantityRatio = minuteVolume / lastMinuteVolume
}
return snapshot
}
// BatchSnapShot 批量获取即时行情数据快照
func BatchSnapShot(codes []string) []factors.QuoteSnapshot {
tdxApi := gotdx.GetTdxApi()
list := []factors.QuoteSnapshot{}
var err error
var hq []quotes.Snapshot
retryTimes := 0
for retryTimes < quotes.DefaultRetryTimes {
hq, err = tdxApi.GetSnapshot(codes)
if err == nil && hq != nil {
break
}
retryTimes++
}
if err != nil {
logger.Errorf("获取即时行情数据失败", err)
return list
}
for _, v := range hq {
if v.State != quotes.TDX_SECURITY_TRADE_STATE_NORMAL {
// 非正常交易的记录忽略掉
continue
}
snapshot := QuoteSnapshotFromProtocol(v)
list = append(list, snapshot)
}
return list
}
// GetTick 获取一只股票的tick数据
//
// 该函数用于测试
func GetTick(securityCode string) *factors.QuoteSnapshot {
list := BatchSnapShot([]string{securityCode})
if len(list) > 0 {
v := list[0]
return &v
}
return nil
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。