candle writetolog tostruct
This commit is contained in:
		
							parent
							
								
									24b4654865
								
							
						
					
					
						commit
						72e04d9f22
					
				@ -17,11 +17,16 @@ import (
 | 
				
			|||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Candle struct {
 | 
					type Candle struct {
 | 
				
			||||||
	core   *Core
 | 
						core      *Core
 | 
				
			||||||
	InstId string
 | 
						InstId    string
 | 
				
			||||||
	Period string
 | 
						Period    string
 | 
				
			||||||
	Data   []interface{}
 | 
						Data      []interface{}
 | 
				
			||||||
	From   string
 | 
						From      string
 | 
				
			||||||
 | 
						Timestamp time.Time
 | 
				
			||||||
 | 
						Open      float64
 | 
				
			||||||
 | 
						High      float64
 | 
				
			||||||
 | 
						Low       float64
 | 
				
			||||||
 | 
						Close     float64
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type MaX struct {
 | 
					type MaX struct {
 | 
				
			||||||
@ -178,6 +183,45 @@ func Daoxu(arr []interface{}) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (cl *Candle) ToStruct(core *Core) error {
 | 
				
			||||||
 | 
						// cl.Timestamp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						// 将字符串转换为 int64 类型的时间戳
 | 
				
			||||||
 | 
						ts, err := strconv.ParseInt(cl.Data[0].(string), 10, 64)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error parsing timestamp:", err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cl.Timestamp = time.Unix(ts/1000, (ts%1000)*1000000) // 纳秒级别
 | 
				
			||||||
 | 
						op, err := strconv.ParseFloat(cl.Data[1].(string), 64)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error parsing string to float64:", err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cl.Open = op
 | 
				
			||||||
 | 
						hi, err := strconv.ParseFloat(cl.Data[2].(string), 64)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error parsing string to float64:", err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cl.High = hi
 | 
				
			||||||
 | 
						lo, err := strconv.ParseFloat(cl.Data[3].(string), 64)
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error parsing string to float64:", err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cl.Low = lo
 | 
				
			||||||
 | 
						clse, err := strconv.ParseFloat(cl.Data[4].(string), 64)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if err != nil {
 | 
				
			||||||
 | 
							fmt.Println("Error parsing string to float64:", err)
 | 
				
			||||||
 | 
							return err
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						cl.Close = clse
 | 
				
			||||||
 | 
						cl.Data = nil
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
func (cl *Candle) SetToKey(core *Core) ([]interface{}, error) {
 | 
					func (cl *Candle) SetToKey(core *Core) ([]interface{}, error) {
 | 
				
			||||||
	data := cl.Data
 | 
						data := cl.Data
 | 
				
			||||||
	tsi, err := strconv.ParseInt(data[0].(string), 10, 64)
 | 
						tsi, err := strconv.ParseInt(data[0].(string), 10, 64)
 | 
				
			||||||
@ -239,6 +283,7 @@ func (core *Core) SaveUniKey(period string, keyName string, extt time.Duration,
 | 
				
			|||||||
	if len(refRes) != 0 {
 | 
						if len(refRes) != 0 {
 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						cl.ToStruct(core)
 | 
				
			||||||
	cd, _ := json.Marshal(cl)
 | 
						cd, _ := json.Marshal(cl)
 | 
				
			||||||
	wg := WriteLog{
 | 
						wg := WriteLog{
 | 
				
			||||||
		Content: cd,
 | 
							Content: cd,
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user