我注意到许多 goroutines 仍在运行,即使程序应该等待它们全部完成。我的理解是添加一个等待组可以解决这个问题,但它没有。
if len(tf5) > 0 {
SplitUpAndSendEmbedToDiscord(5, tf5)
}
if len(tf15) > 0 {
SplitUpAndSendEmbedToDiscord(15, tf15)
}
if len(tf30) > 0 {
SplitUpAndSendEmbedToDiscord(30, tf30)
}
if len(tf60) > 0 {
SplitUpAndSendEmbedToDiscord(60, tf60)
}
}
// IntradayStratify - go routine to run during market hours
func IntradayStratify(ticker string, c chan request.StratNotification, wg *sync.WaitGroup) {
defer wg.Done()
candles := request.GetIntraday(ticker)
for _, tf := range timeframes {
chunkedCandles := request.DetermineTimeframes(tf, ticker, candles)
if len(chunkedCandles) > 1 {
highLows := request.CalculateIntraDayHighLow(chunkedCandles)
// logrus.Infof("%s Highlows calculated: %d", ticker, len(highLows))
// Should have more than 2 candles to start detecting patterns now
if len(highLows) > 2 {
bl, stratPattern := request.DetermineStratPattern(ticker, tf, highLows)
if bl {
c <- stratPattern
}
}
}
// otherwise return an empty channel
c <- request.StratNotification{}
}
}
func main() {
RunIntradayScanner()
}
for我期望程序在循环遍历符号后再次变成单线程。相反,stdout 如下所示,看起来 goroutines 仍在返回。结果应该是每行写着“ Pattern XX found for timeframe ”也将有一个相应的“ Sending to discord ”输出行。
缥缈止盈
相关分类