stock rsi push to elasticsearch
This commit is contained in:
		
							parent
							
								
									737228f319
								
							
						
					
					
						commit
						fb0d242307
					
				
							
								
								
									
										3
									
								
								main.go
									
									
									
									
									
								
							
							
						
						
									
										3
									
								
								main.go
									
									
									
									
									
								
							@ -79,6 +79,9 @@ func main() {
 | 
				
			|||||||
	go func() {
 | 
						go func() {
 | 
				
			||||||
		md.RsisProcess(&cr)
 | 
							md.RsisProcess(&cr)
 | 
				
			||||||
	}()
 | 
						}()
 | 
				
			||||||
 | 
						go func() {
 | 
				
			||||||
 | 
							md.StockRsisProcess(&cr)
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// 这些暂时不运行, 以后要不要运行再说
 | 
						// 这些暂时不运行, 以后要不要运行再说
 | 
				
			||||||
	// go func() {
 | 
						// go func() {
 | 
				
			||||||
 | 
				
			|||||||
@ -298,30 +298,43 @@ func MakeRsi(cr *core.Core, cl *core.Candle, count int) (error, int) {
 | 
				
			|||||||
		fmt.Println("Error calculating RSI:", err)
 | 
							fmt.Println("Error calculating RSI:", err)
 | 
				
			||||||
		return err, 0
 | 
							return err, 0
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	percentK, percentD, err := CalculateStochRSI(rsiList, count, 3, 3)
 | 
						rsi := core.Rsi{
 | 
				
			||||||
	if err != nil {
 | 
					 | 
				
			||||||
		fmt.Println("Error calculating StochRSI:", err)
 | 
					 | 
				
			||||||
		return err, 0
 | 
					 | 
				
			||||||
	}
 | 
					 | 
				
			||||||
	rsi := core.StockRsi{
 | 
					 | 
				
			||||||
		InstID:     cl.InstID,
 | 
							InstID:     cl.InstID,
 | 
				
			||||||
		Period:     cl.Period,
 | 
							Period:     cl.Period,
 | 
				
			||||||
		Timestamp:  cl.Timestamp,
 | 
							Timestamp:  cl.Timestamp,
 | 
				
			||||||
		Ts:         tsi,
 | 
							Ts:         tsi,
 | 
				
			||||||
		Count:      count,
 | 
							Count:      count,
 | 
				
			||||||
		LastUpdate: time.Now(),
 | 
							LastUpdate: time.Now(),
 | 
				
			||||||
		KVol:       percentK[0],
 | 
							RsiVol:     rsiList[len(rsiList)-1],
 | 
				
			||||||
		DVol:       percentD[0],
 | 
					 | 
				
			||||||
		Confirm:    false,
 | 
							Confirm:    false,
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	periodMins, err := cr.PeriodToMinutes(cl.Period)
 | 
						periodMins, err := cr.PeriodToMinutes(cl.Period)
 | 
				
			||||||
 | 
					 | 
				
			||||||
	duration := rsi.LastUpdate.Sub(cl.Timestamp) // 获取时间差
 | 
						duration := rsi.LastUpdate.Sub(cl.Timestamp) // 获取时间差
 | 
				
			||||||
	//最后更新时间差不多大于一个周期,判定为已完成
 | 
						//最后更新时间差不多大于一个周期,判定为已完成
 | 
				
			||||||
	if duration > time.Duration(periodMins-1)*time.Minute {
 | 
						if duration > time.Duration(periodMins-1)*time.Minute {
 | 
				
			||||||
		rsi.Confirm = true
 | 
							rsi.Confirm = true
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	cr.StockRsiProcessChan <- &rsi
 | 
						cr.RsiProcessChan <- &rsi
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						percentK, percentD, err := CalculateStochRSI(rsiList, count, 3, 3)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error calculating StochRSI:", err)
 | 
				
			||||||
 | 
							return err, 0
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						srsi := core.StockRsi{
 | 
				
			||||||
 | 
							InstID:     cl.InstID,
 | 
				
			||||||
 | 
							Period:     cl.Period,
 | 
				
			||||||
 | 
							Timestamp:  cl.Timestamp,
 | 
				
			||||||
 | 
							Ts:         tsi,
 | 
				
			||||||
 | 
							Count:      count,
 | 
				
			||||||
 | 
							LastUpdate: time.Now(),
 | 
				
			||||||
 | 
							KVol:       percentK[len(percentK)-1],
 | 
				
			||||||
 | 
							DVol:       percentD[len(percentD)-1],
 | 
				
			||||||
 | 
							Confirm:    true,
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						cr.StockRsiProcessChan <- &srsi
 | 
				
			||||||
	return nil, 0
 | 
						return nil, 0
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
func MakeMaX(cr *core.Core, cl *core.Candle, count int) (error, int) {
 | 
					func MakeMaX(cr *core.Core, cl *core.Candle, count int) (error, int) {
 | 
				
			||||||
@ -506,6 +519,19 @@ func MaXsProcess(cr *core.Core) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
func RsisProcess(cr *core.Core) {
 | 
					func RsisProcess(cr *core.Core) {
 | 
				
			||||||
 | 
						for {
 | 
				
			||||||
 | 
							rsi := <-cr.RsiProcessChan
 | 
				
			||||||
 | 
							// logrus.Debug("mx: ", mx)
 | 
				
			||||||
 | 
							go func(rsi *core.Rsi) {
 | 
				
			||||||
 | 
								mrs := MyRsi{
 | 
				
			||||||
 | 
									Rsi: *rsi,
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								mrs.Process(cr)
 | 
				
			||||||
 | 
							}(rsi)
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func StockRsisProcess(cr *core.Core) {
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		srsi := <-cr.StockRsiProcessChan
 | 
							srsi := <-cr.StockRsiProcessChan
 | 
				
			||||||
		// logrus.Debug("mx: ", mx)
 | 
							// logrus.Debug("mx: ", mx)
 | 
				
			||||||
@ -517,7 +543,6 @@ func RsisProcess(cr *core.Core) {
 | 
				
			|||||||
		}(srsi)
 | 
							}(srsi)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					 | 
				
			||||||
func TickerInfoProcess(cr *core.Core) {
 | 
					func TickerInfoProcess(cr *core.Core) {
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		ti := <-cr.TickerInforocessChan
 | 
							ti := <-cr.TickerInforocessChan
 | 
				
			||||||
 | 
				
			|||||||
@ -17,6 +17,17 @@ import (
 | 
				
			|||||||
	// logrus "github.com/sirupsen/logrus"
 | 
						// logrus "github.com/sirupsen/logrus"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type MyRsi struct {
 | 
				
			||||||
 | 
						core.Rsi
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (mrsi *MyRsi) Process(cr *core.Core) {
 | 
				
			||||||
 | 
						rsi := mrsi.Rsi
 | 
				
			||||||
 | 
						go func() {
 | 
				
			||||||
 | 
							rsi.PushToWriteLogChan(cr)
 | 
				
			||||||
 | 
						}()
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MyStockRsi struct {
 | 
					type MyStockRsi struct {
 | 
				
			||||||
	core.StockRsi
 | 
						core.StockRsi
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user