-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (52 loc) · 1.25 KB
/
main.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package main
import (
"context"
"github.com/aws/aws-lambda-go/lambda"
"github.com/bwmarrin/discordgo"
"github.com/piquette/finance-go/quote"
"os"
)
type Request struct {
}
func main() {
//err := godotenv.Load()
//if err != nil {
// log.Fatal("Error loading .env file")
//}
//tips, _ := getStockTips()
//fmt.Println(tips)
lambda.Start(HandleRequest)
}
func HandleRequest(ctx context.Context, request Request) (string, error) {
tips, err := getStockTips()
postToDiscordChanel(tips)
return tips, err
}
func getStockTips() (string, error) {
symbolChunks := Symbols{}.getSymbolChunks(500)
stockValidator := Validator{
minPrice: .01, // 10 cents
maxPrice: 5.0, // $5
minGrowth: .10, // 10 percent
}
var results Results
for _, chunk := range symbolChunks {
quotes := quote.List(chunk)
for quotes.Next() {
q := quotes.Quote()
if stockValidator.isValid(q) {
results = append(results, Result{}.New(q))
}
}
}
report := results.sortByPGrowth().asString(10)
return report, nil
}
func postToDiscordChanel(message string) {
if os.Getenv("DISCORD_BOT_TOKEN") != "" {
dg, _ := discordgo.New("Bot " + os.Getenv("DISCORD_BOT_TOKEN"))
dg.Open()
dg.ChannelMessageSend(os.Getenv("DISCORD_CHANNEL_ID"), message)
dg.Close()
}
}