-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.go
77 lines (65 loc) · 1.94 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
75
76
77
package main
import (
"fmt"
_ "github.com/go-sql-driver/mysql"
"github.com/joho/godotenv"
"gitlab.com/open-soft/go-crypto-bot/src/client"
"gitlab.com/open-soft/go-crypto-bot/src/config"
"gitlab.com/open-soft/go-crypto-bot/src/model"
"log"
"os"
)
func main() {
pwd, _ := os.Getwd()
if _, err := os.Stat(fmt.Sprintf("%s/.env", pwd)); err == nil {
log.Println(".env is found, loading variables...")
err = godotenv.Load()
if err != nil {
log.Println(err)
}
}
container := config.InitServiceContainer()
container.PingDB()
defer container.Db.Close()
defer container.DbSwap.Close()
container.PythonMLBridge.Initialize()
defer container.PythonMLBridge.Finalize()
container.StartHttpServer()
log.Printf("Bot [%s] is initialized successfully", container.CurrentBot.BotUuid)
usdtBalance, err := container.BalanceService.GetAssetBalance("USDT", false)
if err != nil {
log.Printf("Balance check error: %s", err.Error())
// todo: `Invalid account.`
if err.Error() == model.BinanceErrorInvalidAPIKeyOrPermissions {
log.Println("Notify SaaS system about error")
container.CallbackManager.Error(
*container.CurrentBot,
model.BinanceErrorInvalidAPIKeyOrPermissions,
"Please check API Key permissions or IP address binding",
true,
)
}
os.Exit(0)
}
log.Printf("API Key permission check passed, balance is: %.2f", usdtBalance)
container.PythonMLBridge.StartAutoLearn()
if binance, ok := container.Binance.(*client.Binance); ok {
binance.APIKeyCheckCompleted = true
}
if binance, ok := container.Binance.(*client.ByBit); ok {
binance.APIKeyCheckCompleted = true
}
container.MakerService.RecoverOrders()
if container.IsMasterBot {
container.MakerService.UpdateSwapPairs()
go func() {
container.MarketSwapListener.ListenAll()
}()
go func() {
container.MCListener.ListenAll()
}()
}
container.TimeService.WaitSeconds(10)
container.MakerService.StartTrade()
container.MarketTradeListener.ListenAll()
}