Ejemplo n.º 1
0
func checkFall(api *stocks.API, user *stocks.User, sd *stocks.StockDetail) {
	if !sd.Stock.NotifyFall || !sd.Stock.FallPercent.Valid {
		return
	}
	if !sd.Detail.CurrPrice.Valid || !sd.Detail.N1ClosePrice.Valid {
		return
	}

	// chg% = ((CurrPrice / N1ClosePrice) - 1) * 100
	log.Println("  Checking fall by %...")
	chg := ((stocks.RatToFloat(sd.Detail.CurrPrice.Value) / stocks.RatToFloat(sd.Detail.N1ClosePrice.Value)) - 1.0) * 100.0
	fall := -stocks.RatToFloat(sd.Stock.FallPercent.Value)
	if chg > fall {
		log.Printf("    change %.2f%% is not less than fall %.2f%%\n", chg, fall)
		return
	}
	log.Printf("    change %.2f%% is less than fall %.2f%%!\n", chg, fall)

	attemptEmailUser(api, user, sd, &sd.Stock.LastTimeFall, "fall")
}
Ejemplo n.º 2
0
func checkRise(api *stocks.API, user *stocks.User, sd *stocks.StockDetail) {
	if !sd.Stock.NotifyRise || !sd.Stock.RisePercent.Valid {
		return
	}
	if !sd.Detail.CurrPrice.Valid || !sd.Detail.N1ClosePrice.Valid {
		return
	}

	// chg% = ((CurrPrice / N1ClosePrice) - 1) * 100
	log.Println("  Checking rise by %...")
	chg := ((stocks.RatToFloat(sd.Detail.CurrPrice.Value) / stocks.RatToFloat(sd.Detail.N1ClosePrice.Value)) - 1.0) * 100.0
	rise := stocks.RatToFloat(sd.Stock.RisePercent.Value)
	if chg < rise {
		log.Printf("    change %.2f%% is not greater than rise %.2f%%\n", chg, rise)
		return
	}
	log.Printf("    change %.2f%% is greater than rise %.2f%%!\n", chg, rise)

	attemptEmailUser(api, user, sd, &sd.Stock.LastTimeRise, "rise")
}