Skip to content

Commit

Permalink
first use before notified price for checking, to avoid notify every i…
Browse files Browse the repository at this point in the history
…nterval

Signed-off-by: Toby Yan <me@tobyan.com>
  • Loading branch information
toby1991 committed Jun 22, 2019
1 parent 04b7bb7 commit fd664a4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions app/console/commands/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit fd664a4

Please sign in to comment.