-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
101 lines (80 loc) · 2.16 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
package main
import (
"fmt"
"os"
"strconv"
"strings"
"gotrading/core"
"gotrading/exchanges"
"gotrading/graph"
"gotrading/reporting"
"gotrading/strategies/arbitrage"
"github.com/spf13/viper"
)
func main() {
viper.SetConfigName("config")
viper.AddConfigPath(".")
err := viper.ReadInConfig()
if err != nil {
panic(fmt.Errorf("Fatal error config file: %s \n", err))
}
factory := exchanges.Factory{}
exchanges := []core.Exchange{}
arbitrageSettings := viper.GetStringMapString("strategies.arbitrage")
exchangesEnabled := strings.Split(arbitrageSettings["exchanges_enabled"], ",")
for _, name := range exchangesEnabled {
exch := factory.BuildExchange(name)
exchanges = append(exchanges, exch)
}
mashup := core.ExchangeMashup{}
mashup.Init(exchanges)
from := core.Currency(arbitrageSettings["from_currency"])
to := core.Currency(arbitrageSettings["to_currency"])
depth, _ := strconv.Atoi(arbitrageSettings["shifts_count"])
treeOfPossibles, _, _, _ := graph.PathFinder(mashup, from, to, depth)
publisher := reporting.Publisher{}
publisher.Init(viper.GetStringMapString("strategies.arbitrage.reporting.publisher"))
defer publisher.Close()
manager := core.SharedPortfolioManager()
i := manager.CurrentPosition("Liqui", core.Currency("BTC"))
fmt.Println(i)
fmt.Println("----")
forceExecution := viper.GetBool("strategies.arbitrage.forceExecution")
for {
treeOfPossibles.DepthTraversing(func(hits []*core.Hit) {
sim := arbitrage.Simulation{}
sim.Init(hits)
sim.Run()
if forceExecution == true {
if sim.IsExecutable() == false {
return
}
exec := arbitrage.Execution{}
exec.Init(sim)
exec.Run()
valid := arbitrage.Validation{}
valid.Init(exec)
valid.Run()
publisher.Send(valid.Report)
os.Exit(3)
} else {
if sim.IsExecutable() == false {
return
}
go publisher.Send(sim.Report)
exec := arbitrage.Execution{}
exec.Init(sim)
exec.Run()
if exec.IsSuccessful() == false {
go publisher.Send(exec.Report)
// Recovery? Rollback?
return
}
valid := arbitrage.Validation{}
valid.Init(exec)
valid.Run()
publisher.Send(valid.Report)
}
})
}
}