-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
74 lines (62 loc) · 1.75 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
71
72
73
74
package main
import (
"flag"
"github.com/M1chlCZ/bingo-bot/bot"
"github.com/M1chlCZ/bingo-bot/client"
"github.com/M1chlCZ/bingo-bot/config"
sqlite "github.com/M1chlCZ/bingo-bot/db"
"github.com/M1chlCZ/bingo-bot/logger"
"github.com/M1chlCZ/bingo-bot/metrics"
"github.com/joho/godotenv"
"log"
"os"
"os/signal"
"syscall"
)
func main() {
// Set up logging
// Define a flag for log level
logFlag := flag.String("log", logger.EnvOrDefault("LOG_LEVEL", "info"), "Log level")
colorFlag := flag.Bool("color", logger.EnvOrDefaultBool("COLOR_ENABLED", true), "Enable color?")
flag.Parse()
logger.InitLogger(logFlag, colorFlag)
err := godotenv.Load()
if err != nil {
log.Fatalf("Error loading .env file: %v", err)
}
if os.Getenv("BINANCE_API_KEY") == "" || os.Getenv("BINANCE_API_SECRET") == "" {
log.Fatal("BINANCE_API_KEY or BINANCE_API_SECRET not set")
}
// Initialize database
err = sqlite.InitDB()
if err != nil {
log.Fatalf("Failed to initialize database: %v", err)
}
// Create Binance client
cl, err := client.NewBinanceClient(
os.Getenv("BINANCE_API_KEY"),
os.Getenv("BINANCE_API_SECRET"),
)
if err != nil {
log.Fatalf("Failed to create Binance client: %v", err)
}
conf := config.DefaultMultiTradingConfig()
// Load config from JSON
// conf, err := config.MultiTradingConfigFromJSON("config.json")
//if err != nil {
// log.Fatalf("Failed to load config: %v", err)
//}
//pr, err := utils.PrettyJson(conf)
//if err == nil {
// fmt.Println(pr)
//}
bt := bot.NewMultiPairTradingBot(cl, &conf)
go metrics.MonitorPerformance(cl)
go bt.StartTrading()
logger.Infof("/// Starting trading bot ///")
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt, syscall.SIGTERM)
<-stop
bt.Stop()
log.Println("Trading bot stopped")
}