Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2842,12 +2842,14 @@ symbol-link-template: https://www.google.com/search?tbm=nws&q={SYMBOL}
```

###### Properties for each market
| Name | Type | Required |
| ---- | ---- | -------- |
| symbol | string | yes |
| name | string | no |
| symbol-link | string | no |
| chart-link | string | no |
| Name | Type | Required | Default |
| ---- | ---- | -------- | ------- |
| symbol | string | yes | |
| name | string | no | |
| symbol-link | string | no | |
| chart-link | string | no | |
| range | string | no | `1mo` |
| interval | string | no | `1d` |

`symbol`

Expand All @@ -2865,6 +2867,17 @@ The link to go to when clicking on the symbol.

The link to go to when clicking on the chart.

`range`

The time range of historical data shown in the chart. Valid values: `1d` `5d` `1mo` `3mo` `6mo` `1y` `2y` `5y` `10y` `ytd` `max`.

`interval`

The interval between data points in the chart. Valid values: `1m` `2m` `5m` `15m` `30m` `60m` `90m` `1h` `4h` `1d` `5d` `1wk` `1mo` `3mo`.

> [!NOTE]
> Not all range/interval combinations are supported by Yahoo Finance. Generally, shorter intervals (e.g. `1m`) are only available for shorter ranges (e.g. `1d` or `5d`).

### Twitch Channels
Display a list of channels from Twitch.

Expand Down
33 changes: 32 additions & 1 deletion internal/glance/widget-markets.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,18 @@ func (widget *marketsWidget) initialize() error {
if widget.SymbolLinkTemplate != "" && m.SymbolLink == "" {
m.SymbolLink = strings.ReplaceAll(widget.SymbolLinkTemplate, "{SYMBOL}", m.Symbol)
}

if m.Range == "" {
m.Range = "1mo"
} else if !marketValidRanges[m.Range] {
return fmt.Errorf("invalid range %q for symbol %s, valid values: 1d 5d 1mo 3mo 6mo 1y 2y 5y 10y ytd max", m.Range, m.Symbol)
}

if m.Interval == "" {
m.Interval = "1d"
} else if !marketValidIntervals[m.Interval] {
return fmt.Errorf("invalid interval %q for symbol %s, valid values: 1m 2m 5m 15m 30m 60m 90m 1h 4h 1d 5d 1wk 1mo 3mo", m.Interval, m.Symbol)
}
}

return nil
Expand Down Expand Up @@ -72,6 +84,8 @@ type marketRequest struct {
Symbol string `yaml:"symbol"`
ChartLink string `yaml:"chart-link"`
SymbolLink string `yaml:"symbol-link"`
Range string `yaml:"range"`
Interval string `yaml:"interval"`
}

type market struct {
Expand Down Expand Up @@ -126,7 +140,13 @@ func fetchMarketsDataFromYahoo(marketRequests []marketRequest) (marketList, erro
requests := make([]*http.Request, 0, len(marketRequests))

for i := range marketRequests {
request, _ := http.NewRequest("GET", fmt.Sprintf("https://query1.finance.yahoo.com/v8/finance/chart/%s?range=1mo&interval=1d", marketRequests[i].Symbol), nil)
url := fmt.Sprintf(
"https://query1.finance.yahoo.com/v8/finance/chart/%s?range=%s&interval=%s",
marketRequests[i].Symbol,
marketRequests[i].Range,
marketRequests[i].Interval,
)
request, _ := http.NewRequest("GET", url, nil)
setBrowserUserAgentHeader(request)
requests = append(requests, request)
}
Expand Down Expand Up @@ -232,3 +252,14 @@ var currencyToSymbol = map[string]string{
"PLN": "zł",
"PHP": "₱",
}

var marketValidRanges = map[string]bool{
"1d": true, "5d": true, "1mo": true, "3mo": true, "6mo": true,
"1y": true, "2y": true, "5y": true, "10y": true, "ytd": true, "max": true,
}

var marketValidIntervals = map[string]bool{
"1m": true, "2m": true, "5m": true, "15m": true, "30m": true,
"60m": true, "90m": true, "1h": true, "4h": true,
"1d": true, "5d": true, "1wk": true, "1mo": true, "3mo": true,
}