From 7925a0168b7ceb0e1badf8ed417c7d34bf61d0de Mon Sep 17 00:00:00 2001 From: zhangkun Date: Wed, 4 Dec 2024 15:38:12 +0800 Subject: [PATCH] =?UTF-8?q?tickerInfo=20=E4=B8=8A=E6=8A=A5=E5=88=B0elastic?= =?UTF-8?q?search?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/candle.go | 6 +++--- core/const.go | 2 +- core/ticker.go | 2 ++ main.go | 6 ++++++ 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/core/candle.go b/core/candle.go index 2f20400..bb1a2c0 100644 --- a/core/candle.go +++ b/core/candle.go @@ -174,7 +174,7 @@ func Daoxu(arr []interface{}) { arr[length-1-i] = temp } } -func hashString(input string) string { +func HashString(input string) string { // 计算SHA-256哈希值 hash := sha256.Sum256([]byte(input)) // 转换为十六进制字符串 @@ -278,13 +278,13 @@ func (mx *MaX) SetToKey() ([]interface{}, error) { // 保证同一个 period, keyName ,在一个周期里,SaveToSortSet只会被执行一次 func (core *Core) SaveUniKey(period string, keyName string, extt time.Duration, tsi int64, cl *Candle) { did := cl.InstId + cl.Period + cl.Data[0].(string) - cl.Id = hashString(did) + cl.Id = HashString(did) cl.ToStruct(core) cd, _ := json.Marshal(cl) wg := WriteLog{ Content: cd, Tag: "sardine.log.candle." + cl.Period, - Id: hashString(did), + Id: cl.Id, } core.WriteLogChan <- &wg diff --git a/core/const.go b/core/const.go index 5f6f475..4612b45 100644 --- a/core/const.go +++ b/core/const.go @@ -4,7 +4,7 @@ const MAIN_ALLCOINS_PERIOD_MINUTES = 1 const MAIN_ALLCOINS_ONCE_COUNTS = 3 const MAIN_ALLCOINS_BAR_PERIOD = "3m" const ALLCANDLES_PUBLISH = "allCandles|publish" -const ALLCANDLES_INNER_PUBLISH = "allCandlesiInner|publish" +const ALLCANDLES_INNER_PUBLISH = "allCandlesInner|publish" const ORDER_PUBLISH = "private|order|publish" const TICKERINFO_PUBLISH = "tickerInfo|publish" const CCYPOSISTIONS_PUBLISH = "ccyPositions|publish" diff --git a/core/ticker.go b/core/ticker.go index b97f158..650b26d 100644 --- a/core/ticker.go +++ b/core/ticker.go @@ -7,6 +7,7 @@ import ( ) type TickerInfo struct { + Id string `json:"_id"` InstId string `json:"instId"` Last float64 `json:"last"` InstType string `json:"instType"` @@ -24,6 +25,7 @@ type TickerInfoResp struct { func (tir *TickerInfoResp) Convert() TickerInfo { ti := TickerInfo{ + Id: HashString(tir.InstId + tir.Ts), InstId: tir.InstId, InstType: tir.InstType, Last: ToFloat64(tir.Last), diff --git a/main.go b/main.go index 498826c..8d6da20 100644 --- a/main.go +++ b/main.go @@ -74,6 +74,12 @@ func RestTicker(cr *core.Core, dura time.Duration) { } for _, v := range allTicker { 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() } }