-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
70 lines (57 loc) · 1.26 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
65
66
67
68
69
70
package main
import (
"log"
"time"
swissknife "github.com/Sagleft/swiss-knife"
"github.com/Sagleft/uexchange-go"
"github.com/fatih/color"
simplecron "github.com/sagleft/simple-cron"
)
func main() {
swissknife.PrintIntroMessage(previewTitle, donateAddress)
b := newBot()
if err := swissknife.CheckErrors(
b.parseConfig,
b.verifyConfig,
b.auth,
b.verifyTradePair,
b.loadPairData,
b.verifyPairData,
b.verifyBalance,
b.runCheckExchangeCron,
); err != nil {
color.Red(err.Error())
return
}
log.Println("bot started")
swissknife.RunInBackground()
}
func newBot() *bot {
return &bot{
Client: uexchange.NewClient(),
}
}
func (b *bot) auth() error {
debug("connect to exchange..")
if _, err := b.Client.Auth(uexchange.Credentials{
AccountPublicKey: b.Config.Exchange.Pubkey,
Password: b.Config.Exchange.Password,
}); err != nil {
return err
}
success("exchange connected")
return nil
}
func (b *bot) runCheckExchangeCron() error {
debug("setup cron..")
go simplecron.NewCronHandler(
func() {
if err := b.checkExchange(); err != nil {
color.Red("check exchange: %s", err.Error())
}
},
time.Duration(b.Config.IntervalTimeoutSeconds)*time.Second,
).Run(b.Config.NoWait)
success("crone initiated")
return nil
}