forked from saniales/golang-crypto-trading-bot
/
slack_integration.go
64 lines (59 loc) · 2.11 KB
/
slack_integration.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
// Copyright © 2017 Alessandro Sanino <saninoale@gmail.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package strategies
import (
"log"
"time"
"github.com/nlopes/slack"
"github.com/saniales/golang-crypto-trading-bot/environment"
"github.com/saniales/golang-crypto-trading-bot/exchanges"
"github.com/saniales/golang-crypto-trading-bot/strategies"
"github.com/shomali11/slacker"
"github.com/sirupsen/logrus"
)
var slackBot *slacker.Slacker
// The following slack integration allows to send messages as a strategy.
// RTM not supported (and usually not requested when trading, this is an automated slackBot).
var slackIntegrationExample = strategies.IntervalStrategy{
Model: strategies.StrategyModel{
Name: "slackIntegrationExample",
Setup: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
// connect slack token
slackBot = slacker.NewClient("YOUR-TOKEN-HERE")
slackBot.Init(func() {
log.Println("Slack BOT Connected")
})
slackBot.Err(func(err string) {
log.Println("Error during slack slackBot connection: ", err)
})
go func() {
err := slackBot.Listen()
if err != nil {
log.Fatal(err)
}
}()
return nil
},
OnUpdate: func([]exchanges.ExchangeWrapper, []*environment.Market) error {
//if updates has requirements
_, _, err := slackBot.Client.PostMessage("DESIRED-CHANNEL", "OMG something happening!!!!!", slack.PostMessageParameters{})
return err
},
OnError: func(err error) {
logrus.Errorf("I Got an error %s", err)
},
},
Interval: time.Second * 10,
}