tickerInfo 上报到elasticsearch

This commit is contained in:
zhangkun 2024-12-04 15:38:12 +08:00
parent 49fbe8c35c
commit 7925a0168b
4 changed files with 12 additions and 4 deletions

View File

@ -174,7 +174,7 @@ func Daoxu(arr []interface{}) {
arr[length-1-i] = temp arr[length-1-i] = temp
} }
} }
func hashString(input string) string { func HashString(input string) string {
// 计算SHA-256哈希值 // 计算SHA-256哈希值
hash := sha256.Sum256([]byte(input)) hash := sha256.Sum256([]byte(input))
// 转换为十六进制字符串 // 转换为十六进制字符串
@ -278,13 +278,13 @@ func (mx *MaX) SetToKey() ([]interface{}, error) {
// 保证同一个 period, keyName 在一个周期里SaveToSortSet只会被执行一次 // 保证同一个 period, keyName 在一个周期里SaveToSortSet只会被执行一次
func (core *Core) SaveUniKey(period string, keyName string, extt time.Duration, tsi int64, cl *Candle) { func (core *Core) SaveUniKey(period string, keyName string, extt time.Duration, tsi int64, cl *Candle) {
did := cl.InstId + cl.Period + cl.Data[0].(string) did := cl.InstId + cl.Period + cl.Data[0].(string)
cl.Id = hashString(did) cl.Id = HashString(did)
cl.ToStruct(core) cl.ToStruct(core)
cd, _ := json.Marshal(cl) cd, _ := json.Marshal(cl)
wg := WriteLog{ wg := WriteLog{
Content: cd, Content: cd,
Tag: "sardine.log.candle." + cl.Period, Tag: "sardine.log.candle." + cl.Period,
Id: hashString(did), Id: cl.Id,
} }
core.WriteLogChan <- &wg core.WriteLogChan <- &wg

View File

@ -4,7 +4,7 @@ const MAIN_ALLCOINS_PERIOD_MINUTES = 1
const MAIN_ALLCOINS_ONCE_COUNTS = 3 const MAIN_ALLCOINS_ONCE_COUNTS = 3
const MAIN_ALLCOINS_BAR_PERIOD = "3m" const MAIN_ALLCOINS_BAR_PERIOD = "3m"
const ALLCANDLES_PUBLISH = "allCandles|publish" const ALLCANDLES_PUBLISH = "allCandles|publish"
const ALLCANDLES_INNER_PUBLISH = "allCandlesiInner|publish" const ALLCANDLES_INNER_PUBLISH = "allCandlesInner|publish"
const ORDER_PUBLISH = "private|order|publish" const ORDER_PUBLISH = "private|order|publish"
const TICKERINFO_PUBLISH = "tickerInfo|publish" const TICKERINFO_PUBLISH = "tickerInfo|publish"
const CCYPOSISTIONS_PUBLISH = "ccyPositions|publish" const CCYPOSISTIONS_PUBLISH = "ccyPositions|publish"

View File

@ -7,6 +7,7 @@ import (
) )
type TickerInfo struct { type TickerInfo struct {
Id string `json:"_id"`
InstId string `json:"instId"` InstId string `json:"instId"`
Last float64 `json:"last"` Last float64 `json:"last"`
InstType string `json:"instType"` InstType string `json:"instType"`
@ -24,6 +25,7 @@ type TickerInfoResp struct {
func (tir *TickerInfoResp) Convert() TickerInfo { func (tir *TickerInfoResp) Convert() TickerInfo {
ti := TickerInfo{ ti := TickerInfo{
Id: HashString(tir.InstId + tir.Ts),
InstId: tir.InstId, InstId: tir.InstId,
InstType: tir.InstType, InstType: tir.InstType,
Last: ToFloat64(tir.Last), Last: ToFloat64(tir.Last),

View File

@ -74,6 +74,12 @@ func RestTicker(cr *core.Core, dura time.Duration) {
} }
for _, v := range allTicker { for _, v := range allTicker {
if v == ti.InstId { if v == ti.InstId {
wg := core.WriteLog{
Content: ab,
Tag: "sardine.log.ticker." + tir.InstId,
Id: ti.Id,
}
cr.WriteLogChan <- &wg
redisCli.Publish(core.TICKERINFO_PUBLISH+suffix, string(ab)).Result() redisCli.Publish(core.TICKERINFO_PUBLISH+suffix, string(ab)).Result()
} }
} }