mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
* 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
```
62 lines
1.2 KiB
Go
62 lines
1.2 KiB
Go
package finnhub
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/jedib0t/go-pretty/v6/table"
|
|
"github.com/rivo/tview"
|
|
"github.com/wtfutil/wtf/view"
|
|
)
|
|
|
|
// Widget ..
|
|
type Widget struct {
|
|
view.TextWidget
|
|
*Client
|
|
|
|
settings *Settings
|
|
}
|
|
|
|
// NewWidget ..
|
|
func NewWidget(tviewApp *tview.Application, settings *Settings) *Widget {
|
|
widget := Widget{
|
|
Client: NewClient(settings.symbols, settings.apiKey),
|
|
TextWidget: view.NewTextWidget(tviewApp, nil, settings.Common),
|
|
|
|
settings: settings,
|
|
}
|
|
|
|
return &widget
|
|
}
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func (widget *Widget) Refresh() {
|
|
if widget.Disabled() {
|
|
return
|
|
}
|
|
|
|
widget.Redraw(widget.content)
|
|
}
|
|
|
|
/* -------------------- Unexported Functions -------------------- */
|
|
|
|
func (widget *Widget) content() (string, string, bool) {
|
|
quotes, err := widget.Client.Getquote()
|
|
|
|
title := widget.CommonSettings().Title
|
|
t := table.NewWriter()
|
|
t.AppendHeader(table.Row{"#", "Stock", "Current Price", "Open Price", "Change"})
|
|
wrap := false
|
|
if err != nil {
|
|
wrap = true
|
|
} else {
|
|
for idx, q := range quotes {
|
|
t.AppendRows([]table.Row{
|
|
{idx, q.Stock, q.C, q.O, fmt.Sprintf("%.4f", (q.C-q.O)/q.C)},
|
|
})
|
|
}
|
|
}
|
|
|
|
return title, t.Render(), wrap
|
|
}
|