-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
162 lines (144 loc) · 5.55 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package main
import (
"flag"
"fmt"
"log"
"os"
"github.com/jeremyhahn/tradebot/common"
"github.com/jeremyhahn/tradebot/dao"
"github.com/jeremyhahn/tradebot/entity"
"github.com/jeremyhahn/tradebot/mapper"
"github.com/jeremyhahn/tradebot/service"
"github.com/jeremyhahn/tradebot/webservice"
//_ "github.com/jinzhu/gorm/dialects/mysql"
_ "github.com/jinzhu/gorm/dialects/sqlite"
"github.com/op/go-logging"
)
func main() {
wd, _ := os.Getwd()
defaultIpc := fmt.Sprintf("%s/%s", wd, "test/ethereum/blockchain/geth.ipc")
defaultKeystore := fmt.Sprintf("%s/%s", wd, "test/ethereum/blockchain/keystore")
defaultMode := "etherscan"
initDbFlag := flag.Bool("initdb", false, "Create / migrate database schema and exit")
portFlag := flag.Int("port", 8080, "Web server listen port")
sslFlag := flag.Bool("ssl", true, "Enable HTTPS / WSS over TLS")
ipcFlag := flag.String("ipc", defaultIpc, "Path to geth IPC socket")
keystoreFlag := flag.String("keystore", defaultKeystore, "Path to default Ethereum keystore")
debugFlag := flag.Bool("debug", false, "Enable debug level logging")
ethereumModeFlag := flag.String("mode", defaultMode, "Ethereum mode [native | etherscan] (default: etherscan)")
flag.Parse()
f, err := os.OpenFile("tradebot.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
if err != nil {
panic("Unable to open log file")
}
stdout := logging.NewLogBackend(os.Stdout, "", 0)
logfile := logging.NewLogBackend(f, "", log.Lshortfile)
//syslog, _ := logging.NewSyslogBackend(common.APPNAME)
backends := logging.MultiLogger(stdout, logfile)
logger := logging.MustGetLogger(common.APPNAME)
logging.SetBackend(backends)
if *debugFlag == false {
logging.SetLevel(logging.ERROR, "")
} else {
logger.Debug("Starting in debug mode...")
}
databaseManager := common.CreateDatabase("./db", "", *debugFlag)
ctx := &common.Ctx{
AppRoot: wd,
CoreDB: databaseManager.ConnectCoreDB(),
PriceDB: databaseManager.ConnectPriceDB(),
Logger: logger,
Debug: *debugFlag,
SSL: *sslFlag,
IPC: *ipcFlag,
Keystore: *keystoreFlag,
EthereumMode: *ethereumModeFlag}
defer ctx.Close()
if *initDbFlag {
InitDB(databaseManager, ctx)
os.Exit(0)
}
userDAO := dao.NewUserDAO(ctx)
pluginDAO := dao.NewPluginDAO(ctx)
userMapper := mapper.NewUserMapper()
pluginMapper := mapper.NewPluginMapper()
userExchangeMapper := mapper.NewUserExchangeMapper()
marketcapService := service.NewMarketCapService(ctx)
pluginService := service.NewPluginService(ctx, pluginDAO, pluginMapper)
exchangeService := service.NewExchangeService(ctx, userDAO, userMapper, userExchangeMapper, pluginService)
ethereumService, err := service.NewEthereumService(ctx, userDAO, userMapper, marketcapService, exchangeService)
if err != nil {
ctx.Logger.Fatalf(fmt.Sprintf("Error: %s", err.Error()))
}
jsonWebTokenService, err := service.NewJsonWebTokenService(ctx, databaseManager, ethereumService, common.NewJsonWriter())
if err != nil {
ctx.Logger.Fatalf(fmt.Sprintf("Error: %s", err.Error()))
}
ws := webservice.NewWebServer(ctx, *portFlag, ethereumService, jsonWebTokenService)
go ws.Start()
ws.Run()
/*
pluginDAO := dao.NewPluginDAO(ctx)
chartDAO := dao.NewChartDAO(ctx)
chartIndicatorDAO := dao.NewChartIndicatorDAO(ctx)
profitDAO := dao.NewProfitDAO(ctx)
tradeDAO := dao.NewTradeDAO(ctx)
chartStrategyDAO := dao.NewChartStrategyDAO(ctx)
chartMapper := mapper.NewChartMapper(ctx)
tradeMapper := mapper.NewTradeMapper()
pluginMapper := mapper.NewPluginMapper()
userExchangeMapper := mapper.NewUserExchangeMapper()
exchangeService := service.NewExchangeService(ctx, pluginDAO, userDAO, userMapper, userExchangeMapper)
pluginService := service.NewPluginService(ctx, pluginDAO, pluginMapper)
indicatorService := service.NewIndicatorService(ctx, chartIndicatorDAO, pluginService)
chartService := service.NewChartService(ctx, userDAO, chartDAO, exchangeService, indicatorService)
profitService := service.NewProfitService(ctx, profitDAO)
tradeService := service.NewTradeService(ctx, tradeDAO, tradeMapper)
strategyService := service.NewStrategyService(ctx, chartStrategyDAO, pluginService, indicatorService, chartMapper)
autoTradeService := service.NewAutoTradeService(ctx, exchangeService, chartService, profitService, tradeService, strategyService, userMapper)
err = autoTradeService.EndWorldHunger()
if err != nil {
ctx.Logger.Fatalf(fmt.Sprintf("Error: %s", err.Error()))
}
*/
}
func InitDB(databaseManager common.DatabaseManager, ctx common.Context) {
databaseManager.MigrateCoreDB()
databaseManager.MigratePriceDB()
pluginDAO := dao.NewPluginDAO(ctx)
pluginDAO.Create(&entity.Plugin{
Name: "GDAX",
Filename: "gdax.so",
Version: "0.0.1a",
Type: common.EXCHANGE_PLUGIN_TYPE})
pluginDAO.Create(&entity.Plugin{
Name: "Coinbase",
Filename: "coinbase.so",
Version: "0.0.1a",
Type: common.EXCHANGE_PLUGIN_TYPE})
pluginDAO.Create(&entity.Plugin{
Name: "Bittrex",
Filename: "bittrex.so",
Version: "0.0.1a",
Type: common.EXCHANGE_PLUGIN_TYPE})
pluginDAO.Create(&entity.Plugin{
Name: "Binance",
Filename: "binance.so",
Version: "0.0.1a",
Type: common.EXCHANGE_PLUGIN_TYPE})
pluginDAO.Create(&entity.Plugin{
Name: "BTC",
Filename: "btc.so",
Version: "0.0.1a",
Type: common.WALLET_PLUGIN_TYPE})
pluginDAO.Create(&entity.Plugin{
Name: "ETH",
Filename: "eth.so",
Version: "0.0.1a",
Type: common.WALLET_PLUGIN_TYPE})
pluginDAO.Create(&entity.Plugin{
Name: "XRP",
Filename: "xrp.so",
Version: "0.0.1a",
Type: common.WALLET_PLUGIN_TYPE})
}