|
|
|
@ -30,6 +30,7 @@ type stock struct {
|
|
|
|
|
lastRise float64
|
|
|
|
|
nowRise float64
|
|
|
|
|
nowRiseStr string
|
|
|
|
|
needSend bool
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (s *stock) Code() string {
|
|
|
|
@ -59,6 +60,7 @@ func (s *stock) notify() bool {
|
|
|
|
|
s.nowRiseStr = fmt.Sprintf("%.2f%%", s.nowRise)
|
|
|
|
|
if (s.lastRise == 0 && rs != 0) || rs-s.lastRise >= cfg.ThresholdValue || s.lastRise-rs >= cfg.ThresholdValue {
|
|
|
|
|
s.lastRise = rs
|
|
|
|
|
s.needSend = true
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
return false
|
|
|
|
@ -250,12 +252,32 @@ func (sk *stocks) Update() error {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (sk *stocks) Notify() bool {
|
|
|
|
|
sk.mx.RLock()
|
|
|
|
|
defer sk.mx.RUnlock()
|
|
|
|
|
var notify bool
|
|
|
|
|
for _, s := range sk.stkMap {
|
|
|
|
|
if s.notify() {
|
|
|
|
|
notify = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return notify
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (sk *stocks) FinishSendAll() {
|
|
|
|
|
sk.mx.Lock()
|
|
|
|
|
defer sk.mx.Unlock()
|
|
|
|
|
for _, s := range sk.stkMap {
|
|
|
|
|
s.needSend = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (sk *stocks) Msg() string {
|
|
|
|
|
sk.mx.RLock()
|
|
|
|
|
defer sk.mx.RUnlock()
|
|
|
|
|
var resp string
|
|
|
|
|
for _, s := range sk.stkMap {
|
|
|
|
|
if s.notify() {
|
|
|
|
|
if s.needSend {
|
|
|
|
|
msg := s.Msg()
|
|
|
|
|
resp = resp + msg + "\n"
|
|
|
|
|
}
|
|
|
|
|