2 Star 7 Fork 11

王布衣/engine

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
dataset_trans_count.go 1.94 KB
一键复制 编辑 原始数据 按行查看 历史
王布衣 提交于 2024-02-06 20:51 . 迁移成交数据常量到exchange
package factors
import (
"gitee.com/quant1x/exchange"
"gitee.com/quant1x/gotdx/quotes"
)
// CountInflow 统计指定日期的内外盘
func CountInflow(list []quotes.TickTransaction, securityCode string, date string) (summary TurnoverDataSummary) {
if len(list) == 0 {
return
}
securityCode = exchange.CorrectSecurityCode(securityCode)
lastPrice := float64(0)
for _, v := range list {
tm := v.Time
direction := int32(v.BuyOrSell)
price := v.Price
if lastPrice == 0 {
lastPrice = price
}
vol := int64(v.Vol)
if direction != quotes.TDX_TICK_BUY && direction != quotes.TDX_TICK_SELL {
switch {
case price > lastPrice:
direction = quotes.TDX_TICK_BUY
case price < lastPrice:
direction = quotes.TDX_TICK_SELL
}
}
// 统计内外盘数据
if direction == quotes.TDX_TICK_BUY {
// 买入
summary.OuterVolume += vol
summary.OuterAmount += float64(vol) * price
} else if direction == quotes.TDX_TICK_SELL {
// 卖出
summary.InnerVolume += vol
summary.InnerAmount += float64(vol) * price
} else {
// 可能存在中性盘2, 最近又发现有类型是3, 暂时还是按照中性盘来处理
vn := vol
buyOffset := vn / 2
sellOffset := vn - buyOffset
// 买入
summary.OuterVolume += buyOffset
summary.OuterAmount += float64(buyOffset) * price
// 卖出
summary.InnerVolume += sellOffset
summary.InnerAmount += float64(sellOffset) * price
}
// 计算开盘竞价数据
if tm >= exchange.HistoricalTransactionDataFirstTime && tm < exchange.HistoricalTransactionDataStartTime {
summary.OpenVolume += vol
}
// 计算收盘竞价数据
if tm > exchange.HistoricalTransactionDataFinalBiddingTime && tm <= exchange.HistoricalTransactionDataLastTime {
summary.CloseVolume += vol
}
lastPrice = price
}
f10 := GetL5F10(securityCode, date)
if f10 != nil {
summary.OpenTurnZ = f10.TurnZ(summary.OpenVolume)
summary.CloseTurnZ = f10.TurnZ(summary.CloseVolume)
}
return
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quant1x/engine.git
git@gitee.com:quant1x/engine.git
quant1x
engine
engine
v1.8.36

搜索帮助