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