New communications package

Support for Slack, SMSGlobal, SMTP and Telegram

Supersedes: https://github.com/thrasher-/gocryptotrader/pull/126
This commit is contained in:
Ryan O'Hara-Reid
2018-05-21 17:08:44 +10:00
committed by Adrian Gallagher
parent d34fc9aae8
commit 9d0616d8cf
26 changed files with 2748 additions and 868 deletions

27
main.go
View File

@@ -15,19 +15,19 @@ import (
"github.com/thrasher-/gocryptotrader/currency/forexprovider"
"github.com/thrasher-/gocryptotrader/common"
"github.com/thrasher-/gocryptotrader/communications"
"github.com/thrasher-/gocryptotrader/config"
"github.com/thrasher-/gocryptotrader/exchanges"
"github.com/thrasher-/gocryptotrader/portfolio"
"github.com/thrasher-/gocryptotrader/smsglobal"
)
// Bot contains configuration, portfolio, exchange & ticker data and is the
// overarching type across this code base.
type Bot struct {
config *config.Config
smsglobal *smsglobal.Base
portfolio *portfolio.Base
exchanges []exchange.IBotExchange
comms *communications.Communications
shutdown chan bool
dryRun bool
configFile string
@@ -82,21 +82,9 @@ func main() {
log.Printf("Bot '%s' started.\n", bot.config.Name)
log.Printf("Bot dry run mode: %v.\n", common.IsEnabled(bot.dryRun))
if bot.config.SMS.Enabled {
bot.smsglobal = smsglobal.New(bot.config.SMS.Username, bot.config.SMS.Password,
bot.config.Name, bot.config.SMS.Contacts)
log.Printf(
"SMS support enabled. Number of SMS contacts %d.\n",
bot.smsglobal.GetEnabledContacts(),
)
} else {
log.Println("SMS support disabled.")
}
log.Printf(
"Available Exchanges: %d. Enabled Exchanges: %d.\n",
len(bot.config.Exchanges), bot.config.CountEnabledExchanges(),
)
log.Printf("Available Exchanges: %d. Enabled Exchanges: %d.\n",
len(bot.config.Exchanges),
bot.config.CountEnabledExchanges())
common.HTTPClient = common.NewHTTPClientWithTimeout(bot.config.GlobalHTTPTimeout)
log.Printf("Global HTTP request timeout: %v.\n", common.HTTPClient.Timeout)
@@ -106,6 +94,10 @@ func main() {
log.Fatalf("No exchanges were able to be loaded. Exiting")
}
log.Println("Starting communication mediums..")
bot.comms = communications.NewComm(bot.config.GetCommunicationsConfig())
bot.comms.GetEnabledCommunicationMediums()
log.Printf("Fiat display currency: %s.", bot.config.Currency.FiatDisplayCurrency)
currency.BaseCurrency = bot.config.Currency.FiatDisplayCurrency
currency.FXProviders = forexprovider.StartFXService(bot.config.GetCurrencyConfig().ForexProviders)
@@ -124,6 +116,7 @@ func main() {
bot.portfolio = &portfolio.Portfolio
bot.portfolio.SeedPortfolio(bot.config.Portfolio)
SeedExchangeAccountInfo(GetAllEnabledExchangeAccountInfo().Data)
go portfolio.StartPortfolioWatcher()
go TickerUpdaterRoutine()
go OrderbookUpdaterRoutine()