github.com/wtfutil/wtf@v0.43.0/modules/stocks/yfinance/settings.go (about)

     1  package yfinance
     2  
     3  import (
     4  	"github.com/olebedev/config"
     5  	"github.com/wtfutil/wtf/cfg"
     6  	"github.com/wtfutil/wtf/utils"
     7  )
     8  
     9  const (
    10  	defaultFocusable = false
    11  	defaultTitle     = "Yahoo Finance"
    12  )
    13  
    14  type colors struct {
    15  	bigup   string
    16  	up      string
    17  	drop    string
    18  	bigdrop string
    19  }
    20  
    21  // Settings defines the configuration properties for this module
    22  type Settings struct {
    23  	common *cfg.Common
    24  
    25  	colors  colors
    26  	sort    bool
    27  	symbols []string `help:"An array of Yahoo Finance symbols (for example: DOCN, GME, GC=F)"`
    28  }
    29  
    30  // NewSettingsFromYAML creates a new settings instance from a YAML config block
    31  func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
    32  	settings := Settings{
    33  		common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
    34  		// RefreshInterval: ,
    35  	}
    36  
    37  	settings.common.RefreshInterval = cfg.ParseTimeString(ymlConfig, "refreshInterval", "60s")
    38  	settings.colors.bigup = ymlConfig.UString("colors.bigup", "greenyellow")
    39  	settings.colors.up = ymlConfig.UString("colors.up", "green")
    40  	settings.colors.drop = ymlConfig.UString("colors.drop", "firebrick")
    41  	settings.colors.bigdrop = ymlConfig.UString("colors.bigdrop", "red")
    42  	settings.sort = ymlConfig.UBool("sort", false)
    43  	settings.symbols = utils.ToStrs(ymlConfig.UList("symbols"))
    44  	return &settings
    45  }