siaga/modules/tickerInfo.go
zhangkun9038@dingtalk.com ce81a83eeb tickerInfo id
2024-12-23 14:39:28 +08:00

82 lines
2.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package module
import (
// "errors"
"fmt"
"github.com/phyer/core"
// "math"
"os"
"strconv"
)
type MyTickerInfo struct {
core.TickerInfo
}
func (mti *MyTickerInfo) Process(cr *core.Core) {
ti := mti.TickerInfo
go func() {
// 无需发布出去, 下面内容注释 2024-12-15
// tickerPush := os.Getenv("SIAGA_TICKERPUSH") == "true"
// if !tickerPush {
// return
// }
// err := AddToGeneralTickerChnl(ti)
// if err != nil {
// logrus.Warn("tickerPush err:", err, ti)
// }
}()
go func() {
torqueSorted := os.Getenv("SIAGA_TORQUESORTED") == "true"
if !torqueSorted {
return
}
// 这个功能貌似很有意思,以后可以考虑打开
// ti.MakePriceSorted(cr, "2m")
// ti.MakePriceSorted(cr, "4m")
// ti.MakePriceSorted(cr, "8m")
//用这个方法保证事件在每个周期只发生一次
}()
go func() {
tickerToCandle := os.Getenv("SIAGA_TICKERTOCANDLE") == "true"
if tickerToCandle {
fmt.Println("tickerToCandle: ", ti)
cd := mti.ConvertToCandle(cr, "1m")
cr.CandlesProcessChan <- cd
}
}()
go func() {
ti.SetToKey(cr)
// 流出时间让下面的函数进行比对
// time.Sleep(50 * time.Millisecond)
// snapshot 先关掉 2024-12-15
// ti.MakeSnapShot(cr)
}()
}
// TODO 当前这个版本的实现里开盘价最高价最低价都不重要主要是收盘价用来算ma7ma30这个就够了以后需要的话再细化
func (mti *MyTickerInfo) ConvertToCandle(cr *core.Core, period string) *core.Candle {
ti := mti.TickerInfo
hn := os.Getenv("HOSTNAME")
lst := strconv.FormatFloat(ti.Last, 'f', -1, 64)
tmi := ti.Ts
tmi = tmi - tmi%60000
cd := core.Candle{
InstID: ti.InstID,
Period: period,
Data: []interface{}{
strconv.FormatInt(tmi, 10), //开始时间Unix时间戳的毫秒数格式如 1597026383085
"-1", //o String 开盘价格
"-1", //h String 最高价格
"-1", //l String 最低价格
lst, //c String 收盘价格
"-1", //c String 成交量
"-1", //c String 成交美元数
},
From: "tickerInfo|" + hn,
}
return &cd
}