core/rsi.go

89 lines
2.3 KiB
Go
Raw Permalink Normal View History

2024-12-20 23:11:06 +08:00
package core
import (
// "crypto/sha256"
// "encoding/hex"
// "encoding/json"
// "errors"
// "fmt"
// "math/rand"
// "os"
// "strconv"
// "strings"
2024-12-21 00:13:33 +08:00
"encoding/json"
2024-12-20 23:11:06 +08:00
"time"
// simple "github.com/bitly/go-simplejson"
// "github.com/go-redis/redis"
// "github.com/phyer/texus/utils"
2024-12-21 00:13:33 +08:00
logrus "github.com/sirupsen/logrus"
2024-12-20 23:11:06 +08:00
)
type Rsi struct {
Id string `json:"_id"`
core *Core
InstID string `json:"instID"`
Period string `json:"period"`
Timestamp time.Time `json:"timeStamp"`
2024-12-21 00:16:31 +08:00
Ts int64 `json:"ts"`
2024-12-21 01:50:01 +08:00
Count int `json:"count"`
2024-12-20 23:11:06 +08:00
LastUpdate time.Time `json:"lastUpdate"`
RsiVol float64 `json:"rsiVol"`
Confirm bool `json:"confirm"`
}
type RsiList struct {
Count int `json:"count,number"`
LastUpdateTime int64 `json:"lastUpdateTime"`
UpdateNickName string `json:"updateNickName"`
List []*Rsi `json:"list"`
}
2024-12-21 21:13:52 +08:00
type StockRsi struct {
Id string `json:"_id"`
core *Core
InstID string `json:"instID"`
Period string `json:"period"`
Timestamp time.Time `json:"timeStamp"`
Ts int64 `json:"ts"`
Count int `json:"count"`
LastUpdate time.Time `json:"lastUpdate"`
KVol float64 `json:"kVol"`
DVol float64 `json:"dVol"`
Confirm bool `json:"confirm"`
}
type StockRsiList struct {
Count int `json:"count,number"`
LastUpdateTime int64 `json:"lastUpdateTime"`
UpdateNickName string `json:"updateNickName"`
List []*StockRsi `json:"list"`
}
2024-12-21 00:13:33 +08:00
func (rsi *Rsi) PushToWriteLogChan(cr *Core) error {
did := rsi.InstID + rsi.Period + ToString(rsi.Ts)
rsi.Id = HashString(did)
cd, err := json.Marshal(rsi)
if err != nil {
logrus.Error("PushToWriteLog json marshal rsi err: ", err)
}
wg := WriteLog{
Content: cd,
Tag: "sardine.log.rsi." + rsi.Period,
Id: rsi.Id,
}
cr.WriteLogChan <- &wg
return nil
}
2024-12-21 21:13:52 +08:00
func (srsi *StockRsi) PushToWriteLogChan(cr *Core) error {
did := srsi.InstID + srsi.Period + ToString(srsi.Ts)
srsi.Id = HashString(did)
cd, err := json.Marshal(srsi)
if err != nil {
logrus.Error("PushToWriteLog json marshal rsi err: ", err)
}
wg := WriteLog{
Content: cd,
Tag: "sardine.log.stockRsi." + srsi.Period,
Id: srsi.Id,
}
cr.WriteLogChan <- &wg
return nil
}