import buyandhold strategy

This commit is contained in:
c9s 2020-10-22 16:04:37 +08:00
parent aea6a7c03d
commit 9c751f377a
3 changed files with 12 additions and 8 deletions

View File

@ -14,12 +14,14 @@ import (
"github.com/c9s/bbgo/pkg/config" "github.com/c9s/bbgo/pkg/config"
"github.com/c9s/bbgo/pkg/notifier/slacknotifier" "github.com/c9s/bbgo/pkg/notifier/slacknotifier"
"github.com/c9s/bbgo/pkg/slack/slacklog" "github.com/c9s/bbgo/pkg/slack/slacklog"
_ "github.com/c9s/bbgo/pkg/strategy/buyandhold"
) )
var errSlackTokenUndefined = errors.New("slack token is not defined.") var errSlackTokenUndefined = errors.New("slack token is not defined.")
func init() { func init() {
runCmd.Flags().String("config", "", "strategy config file") runCmd.Flags().String("config", "config/bbgo.yaml", "strategy config file")
runCmd.Flags().String("since", "", "pnl since time") runCmd.Flags().String("since", "", "pnl since time")
RootCmd.AddCommand(runCmd) RootCmd.AddCommand(runCmd)
} }
@ -56,7 +58,6 @@ var runCmd = &cobra.Command{
log.AddHook(slacklog.NewLogHook(slackToken, viper.GetString("slack-error-channel"))) log.AddHook(slacklog.NewLogHook(slackToken, viper.GetString("slack-error-channel")))
// TODO: load channel from config file
var notifier = slacknotifier.New(slackToken, viper.GetString("slack-channel")) var notifier = slacknotifier.New(slackToken, viper.GetString("slack-channel"))
db, err := cmdutil.ConnectMySQL() db, err := cmdutil.ConnectMySQL()
@ -71,11 +72,13 @@ var runCmd = &cobra.Command{
for _, entry := range userConfig.ExchangeStrategies { for _, entry := range userConfig.ExchangeStrategies {
for _, mount := range entry.Mounts { for _, mount := range entry.Mounts {
log.Infof("attaching strategy %T on %s...", entry.Strategy, mount)
trader.AttachStrategyOn(mount, entry.Strategy) trader.AttachStrategyOn(mount, entry.Strategy)
} }
} }
for _, strategy := range userConfig.CrossExchangeStrategies { for _, strategy := range userConfig.CrossExchangeStrategies {
log.Infof("attaching strategy %T", strategy)
trader.AttachCrossExchangeStrategy(strategy) trader.AttachCrossExchangeStrategy(strategy)
} }

View File

@ -100,6 +100,7 @@ func loadExchangeStrategies(stash Stash) (strategies []SingleExchangeStrategyCon
exchangeStrategiesConf, ok := stash["exchangeStrategies"] exchangeStrategiesConf, ok := stash["exchangeStrategies"]
if !ok { if !ok {
return strategies, nil return strategies, nil
// return nil, errors.New("exchangeStrategies is not defined")
} }
configList, ok := exchangeStrategiesConf.([]interface{}) configList, ok := exchangeStrategiesConf.([]interface{})