gitee.com/quant1x/engine@v1.8.4/services/task_realtime_kline.go (about)

     1  package services
     2  
     3  import (
     4  	"gitee.com/quant1x/engine/datasource/base"
     5  	"gitee.com/quant1x/engine/market"
     6  	"gitee.com/quant1x/engine/models"
     7  	"gitee.com/quant1x/exchange"
     8  	"gitee.com/quant1x/gox/coroutine"
     9  	"gitee.com/quant1x/gox/logger"
    10  	"gitee.com/quant1x/gox/progressbar"
    11  	"gitee.com/quant1x/gox/runtime"
    12  )
    13  
    14  // 任务 - 实时更新K线
    15  func jobRealtimeKLine() {
    16  	funcName := "jobRealtimeKLine"
    17  	updateInRealTime, status := exchange.CanUpdateInRealtime()
    18  	// 14:30:00~15:01:00之间更新数据
    19  	if updateInRealTime && IsTrading(status) {
    20  		realtimeUpdateOfKLine()
    21  	} else {
    22  		if runtime.Debug() {
    23  			realtimeUpdateOfKLine()
    24  		} else {
    25  			logger.Infof("%s, 非尾盘交易时段: %d", funcName, status)
    26  		}
    27  	}
    28  }
    29  
    30  // 更新K线
    31  func realtimeUpdateOfKLine() {
    32  	defer runtime.IgnorePanic("")
    33  	barIndex := barIndexRealtimeKLine
    34  	allCodes := market.GetCodeList()
    35  	wg := coroutine.NewRollingWaitGroup(5)
    36  	bar := progressbar.NewBar(barIndex, "执行[实时更新K线]", len(allCodes))
    37  	for _, code := range allCodes {
    38  		updateKLine := func(waitGroup *coroutine.RollingWaitGroup, securityCode string) {
    39  			defer waitGroup.Done()
    40  			bar.Add(1)
    41  			snapshot := models.GetTickFromMemory(securityCode)
    42  			if snapshot != nil {
    43  				base.BasicKLineForSnapshot(*snapshot)
    44  			}
    45  		}
    46  		wg.Add(1)
    47  		go updateKLine(wg, code)
    48  	}
    49  	wg.Wait()
    50  }