-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmain.go
67 lines (50 loc) · 1.6 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
package main
import (
"fmt"
"sync"
"time"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/MatejLach/bnc-trading-bot/bot"
)
func init() {
zerolog.TimeFieldFormat = time.RFC3339
zerolog.SetGlobalLevel(zerolog.DebugLevel)
}
func main() {
botClient := bot.New()
wg := sync.WaitGroup{}
for _, cfg := range botClient.Config.Sell {
symbolPriceC, closeC, err := botClient.GetCurrentCryptoPrice(fmt.Sprintf("%s%s", cfg.SellHoldingSymbol, cfg.SellForSymbol))
if err != nil {
log.Warn().Err(err).Msgf("failed getting initial price of %s, skipping...", cfg.SellHoldingSymbol)
continue
}
wg.Add(1)
go func(sellCfg bot.SellConfig) {
defer wg.Done()
err := botClient.SellIfIncreaseByPercent(symbolPriceC, closeC, sellCfg)
if err != nil {
symbol := fmt.Sprintf("%s%s", sellCfg.SellHoldingSymbol, sellCfg.SellForSymbol)
log.Warn().Err(err).Msgf("failed executing sell order for '%s', skipping...", symbol)
}
}(cfg)
}
for _, cfg := range botClient.Config.Buy {
symbolPriceC, closeC, err := botClient.GetCurrentCryptoPrice(fmt.Sprintf("%s%s", cfg.BuySymbol, cfg.BuyWithHoldingSymbol))
if err != nil {
log.Warn().Err(err).Msgf("failed getting initial price of %s, skipping...", cfg.BuySymbol)
continue
}
wg.Add(1)
go func(buyCfg bot.BuyConfig) {
defer wg.Done()
err := botClient.BuyIfDecreaseByPercent(symbolPriceC, closeC, buyCfg)
if err != nil {
symbol := fmt.Sprintf("%s%s", buyCfg.BuySymbol, buyCfg.BuyWithHoldingSymbol)
log.Warn().Err(err).Msgf("failed executing purchase order for '%s', skipping...", symbol)
}
}(cfg)
}
wg.Wait()
}