-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalidator.go
29 lines (22 loc) · 926 Bytes
/
validator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package main
import "github.com/piquette/finance-go"
type Validator struct {
minPrice float64
maxPrice float64
minGrowth float64
}
func (v Validator) isValid(quote *finance.Quote) bool {
return v.hasValidExchange(quote) && v.priceIsBetweenMinAndMax(quote) && v.isTrendingUp(quote) && v.hasMinimumGrowthPotential(quote)
}
func (v Validator) priceIsBetweenMinAndMax(quote *finance.Quote) bool {
return quote.RegularMarketPrice > v.minPrice && quote.RegularMarketPrice <= v.maxPrice
}
func (v Validator) isTrendingUp(quote *finance.Quote) bool {
return quote.RegularMarketPreviousClose < quote.RegularMarketPrice && quote.RegularMarketPrice > quote.FiftyDayAverage
}
func (v Validator) hasMinimumGrowthPotential(quote *finance.Quote) bool {
return Result{}.getPotentialGrowth(quote) >= v.minGrowth
}
func (v Validator) hasValidExchange(quote *finance.Quote) bool {
return quote.FullExchangeName != "Other OTC"
}