gitee.com/quant1x/engine@v1.8.4/factors/dataset_trans_count.go (about) 1 package factors 2 3 import ( 4 "gitee.com/quant1x/exchange" 5 "gitee.com/quant1x/gotdx/quotes" 6 ) 7 8 // CountInflow 统计指定日期的内外盘 9 func CountInflow(list []quotes.TickTransaction, securityCode string, date string) (summary TurnoverDataSummary) { 10 if len(list) == 0 { 11 return 12 } 13 securityCode = exchange.CorrectSecurityCode(securityCode) 14 lastPrice := float64(0) 15 for _, v := range list { 16 tm := v.Time 17 direction := int32(v.BuyOrSell) 18 price := v.Price 19 if lastPrice == 0 { 20 lastPrice = price 21 } 22 vol := int64(v.Vol) 23 if direction != quotes.TDX_TICK_BUY && direction != quotes.TDX_TICK_SELL { 24 switch { 25 case price > lastPrice: 26 direction = quotes.TDX_TICK_BUY 27 case price < lastPrice: 28 direction = quotes.TDX_TICK_SELL 29 } 30 } 31 // 统计内外盘数据 32 if direction == quotes.TDX_TICK_BUY { 33 // 买入 34 summary.OuterVolume += vol 35 summary.OuterAmount += float64(vol) * price 36 } else if direction == quotes.TDX_TICK_SELL { 37 // 卖出 38 summary.InnerVolume += vol 39 summary.InnerAmount += float64(vol) * price 40 } else { 41 // 可能存在中性盘2, 最近又发现有类型是3, 暂时还是按照中性盘来处理 42 vn := vol 43 buyOffset := vn / 2 44 sellOffset := vn - buyOffset 45 // 买入 46 summary.OuterVolume += buyOffset 47 summary.OuterAmount += float64(buyOffset) * price 48 // 卖出 49 summary.InnerVolume += sellOffset 50 summary.InnerAmount += float64(sellOffset) * price 51 } 52 // 计算开盘竞价数据 53 if tm >= exchange.HistoricalTransactionDataFirstTime && tm < exchange.HistoricalTransactionDataStartTime { 54 summary.OpenVolume += vol 55 } 56 // 计算收盘竞价数据 57 if tm > exchange.HistoricalTransactionDataFinalBiddingTime && tm <= exchange.HistoricalTransactionDataLastTime { 58 summary.CloseVolume += vol 59 } 60 lastPrice = price 61 } 62 f10 := GetL5F10(securityCode, date) 63 if f10 != nil { 64 summary.OpenTurnZ = f10.TurnZ(summary.OpenVolume) 65 summary.CloseTurnZ = f10.TurnZ(summary.CloseVolume) 66 } 67 68 return 69 }