1
0
mirror of https://github.com/taigrr/wtf synced 2025-01-18 04:03:14 -08:00
wtf/modules/stocks/yfinance/settings.go
Antoine Meillet 9fb57845ed
Add Yahoo Finance module (#1066)
* Move finnhub to a stocks folder

As I am preparing an other stocks data provider, let's move `finnhub` to
a stocks folder that will host the others providers.

* Use go-pretty v6

Will be used by the new stock provider module, so let's just upgrade
this one to reduce the number of dependencies.

* Add Yahoo Finance module

Yahoo Finance provides an API for which `piquette/finance-go` is a
powerful client. This new module leverages this module to integrate all
indices provided by Yahoo Finance (international stocks, crypto,
options, currencies...)

Sample config:
```yaml
    yfinance:
      title: "Stocks 🚀"
      symbols:
        - "MSFT"
        - "GC=F"
        - "ORA.PA"
      sort: true
      enabled: true
      refreshInterval: 60
      position:
        top: 1
        left: 0
        height: 1
        width: 1
```
2021-03-27 13:42:28 -07:00

46 lines
1.3 KiB
Go

package yfinance
import (
"github.com/olebedev/config"
"github.com/wtfutil/wtf/cfg"
"github.com/wtfutil/wtf/utils"
)
const (
defaultFocusable = false
defaultTitle = "Yahoo Finance"
)
type colors struct {
bigup string
up string
drop string
bigdrop string
}
// Settings defines the configuration properties for this module
type Settings struct {
common *cfg.Common
colors colors
sort bool
symbols []string `help:"An array of Yahoo Finance symbols (for example: DOCN, GME, GC=F)"`
}
// NewSettingsFromYAML creates a new settings instance from a YAML config block
func NewSettingsFromYAML(name string, ymlConfig *config.Config, globalConfig *config.Config) *Settings {
settings := Settings{
common: cfg.NewCommonSettingsFromModule(name, defaultTitle, defaultFocusable, ymlConfig, globalConfig),
// RefreshInterval: ,
}
settings.common.RefreshInterval = ymlConfig.UInt("refreshInterval", 60)
settings.colors.bigup = ymlConfig.UString("colors.bigup", "greenyellow")
settings.colors.up = ymlConfig.UString("colors.up", "green")
settings.colors.drop = ymlConfig.UString("colors.drop", "firebrick")
settings.colors.bigdrop = ymlConfig.UString("colors.bigdrop", "red")
settings.sort = ymlConfig.UBool("sort", false)
settings.symbols = utils.ToStrs(ymlConfig.UList("symbols"))
return &settings
}