From fd664a44a05dcba2cb4d00089b8fb2c800d4bda5 Mon Sep 17 00:00:00 2001 From: Toby Yan Date: Sat, 22 Jun 2019 10:30:32 +0800 Subject: [PATCH] first use before notified price for checking, to avoid notify every interval Signed-off-by: Toby Yan --- app/console/commands/alert.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/app/console/commands/alert.go b/app/console/commands/alert.go index 344e4f8..2d7ce90 100644 --- a/app/console/commands/alert.go +++ b/app/console/commands/alert.go @@ -136,10 +136,8 @@ func (hw *Alert) Handler(arg *cmd.Arg) error { } func (hw *Alert) notify(direction Direction, nowData *TickData) { - // every minute should notify once - if cache.Has(hw.cacheKey(zone.Now())+"_notified"){ - return - } + + cache.Put(hw.cacheKey(zone.Now())+"_notified", nowData.Price.String(), zone.Now().Add(hw.duration)) diff, _ := strconv.ParseFloat(hw.difference, 64) @@ -156,7 +154,6 @@ func (hw *Alert) notify(direction Direction, nowData *TickData) { }, }).Biu() - cache.Put(hw.cacheKey(zone.Now())+"_notified", true, zone.Now().Add(hw.duration+5*zone.Minute)) } func nowData(resp *response) *TickData { @@ -203,9 +200,12 @@ func (hw *Alert) initDifference() error { } func (hw *Alert) checkDirection(nowPrice *bigfloat.BigFloat) (Direction, error) { - beforePrice := cache.Get(hw.cacheKey(zone.Now().Add(-hw.duration))) + beforePrice := cache.Get(hw.cacheKey(zone.Now().Add(-hw.duration))+"_notified") // beforeNotifiedPrice first use before notified price for checking, to avoid notify every interval if beforePrice == nil { - return Draw, errors.New("not enough history data") + beforePrice = cache.Get(hw.cacheKey(zone.Now().Add(-hw.duration))) + if beforePrice == nil { + return Draw, errors.New("not enough history data") + } } //debug.Dump(beforePrice)