-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
402 lines (377 loc) ยท 10.1 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
package main
import (
"context"
"fmt"
"log"
"time"
"github.com/mum4k/termdash"
"github.com/mum4k/termdash/align"
"github.com/mum4k/termdash/cell"
"github.com/mum4k/termdash/container"
"github.com/mum4k/termdash/linestyle"
"github.com/mum4k/termdash/terminal/termbox"
"github.com/mum4k/termdash/terminal/terminalapi"
"github.com/mum4k/termdash/widgets/button"
"github.com/mum4k/termdash/widgets/linechart"
"github.com/mum4k/termdash/widgets/sparkline"
"github.com/mum4k/termdash/widgets/text"
"github.com/mum4k/termdash/widgets/barchart"
"github.com/mum4k/termdash/widgets/donut"
"github.com/applegreengrape/finnhub-terminal/finnhub/data"
"github.com/applegreengrape/finnhub-terminal/widgets"
"github.com/applegreengrape/finnhub-terminal/yahoo"
)
func main() {
// new terminal
t, err := termbox.New()
if err != nil {
log.Fatal(err)
}
defer t.Close()
// new ctx sessions
ctx, cancel := context.WithCancel(context.Background())
// update time
timeNow, err := text.New()
if err != nil {
log.Fatal(err)
}
go widgets.UpdateTime(ctx, timeNow)
// update stocks
stk, err := text.New()
if err != nil {
log.Fatal(err)
}
go widgets.UpdateStockPrice(ctx, stk)
// stock line chart
cfg := yahoo.NewSettingFromConfig()
const redrawInterval = 250 * time.Millisecond
lc, err := linechart.New(
linechart.YAxisAdaptive(),
linechart.AxesCellOpts(cell.FgColor(cell.ColorRed)),
linechart.YLabelCellOpts(cell.FgColor(cell.ColorGreen)),
linechart.XLabelCellOpts(cell.FgColor(cell.ColorCyan)),
)
if err != nil {
log.Fatal(err)
}
go widgets.StockLineChart(ctx, lc, redrawInterval/3)
// volume spark chart
volchart, err := sparkline.New(
sparkline.Label(fmt.Sprintf("%s volume chart", cfg.Stocks[0]), cell.FgColor(cell.ColorGreen)),
sparkline.Color(cell.ColorYellow),
)
if err != nil {
log.Fatal(err)
}
go widgets.VolumeSparkChart(ctx, volchart, redrawInterval)
//RollingEarningsCalendar Widgest
earningCals, err := text.New(text.RollContent(), text.WrapAtWords())
if err != nil {
log.Fatal(err)
}
go widgets.RollingEarningsCalendar(ctx, earningCals)
// RollingMtkNews Widgest
news, err := text.New(text.RollContent(), text.WrapAtWords())
if err != nil {
log.Fatal(err)
}
go widgets.RollingNews(ctx, news)
//RollingCompanyNews Widgest
companyNewsRoll, err := text.New(text.RollContent(), text.WrapAtWords())
if err != nil {
log.Fatal(err)
}
go widgets.RollingCompanyNews(ctx, companyNewsRoll)
// update basic financials
basicFinancials, err := text.New()
if err != nil {
log.Fatal(err)
}
go widgets.UpdateBasicFinancials(ctx, basicFinancials)
// export all basic financials to csv button
triggers := make(chan bool)
go data.ExportAllBFs(triggers)
export1, err := button.New(
"Export all to csv",
func() error {
triggers <- true
return nil
},
button.GlobalKey('e'),
button.FillColor(cell.ColorNumber(220)),
button.WidthFor("Export all to csv"),
)
if err != nil {
log.Fatal(err)
}
// export all financial reports to csv button
triggers2 := make(chan bool)
go data.ExportAllFRs(triggers2)
export2, err := button.New(
"Export all to csv",
func() error {
triggers2 <- true
return nil
},
button.GlobalKey('e'),
button.FillColor(cell.ColorNumber(220)),
button.WidthFor("Export all to csv"),
)
if err != nil {
log.Fatal(err)
}
// update financial reports
financialReports, err := text.New()
if err != nil {
log.Fatal(err)
}
go widgets.UpdateFinancialReports(ctx, financialReports)
// target news sentiment donut
tnTrend, err := donut.New(
donut.CellOpts(cell.FgColor(cell.ColorGreen)),
donut.Label("๐ฎ bullish %", cell.FgColor(cell.ColorGreen)),
)
if err != nil {
panic(err)
}
go widgets.UpdateSentimentDonut(ctx, tnTrend, "target")
// peers news sentiment donut
pnTrend, err := donut.New(
donut.CellOpts(cell.FgColor(cell.ColorGreen)),
donut.Label("๐ฎ bullish %", cell.FgColor(cell.ColorGreen)),
)
if err != nil {
panic(err)
}
go widgets.UpdateSentimentDonut(ctx, pnTrend, "peers")
// target bar chart
bcTarget, err := barchart.New(
barchart.BarColors([]cell.Color{
cell.ColorGreen,
cell.ColorGreen,
cell.ColorYellow,
cell.ColorRed,
cell.ColorRed,
}),
barchart.ValueColors([]cell.Color{
cell.ColorWhite,
cell.ColorWhite,
cell.ColorCyan,
cell.ColorWhite,
cell.ColorWhite,
}),
barchart.ShowValues(),
barchart.BarWidth(8),
barchart.Labels([]string{
"๐ฎ๐ฎ",
"๐ฎ ",
"โ",
"๐ป ",
"๐ป๐ป",
}),
)
if err != nil {
panic(err)
}
go widgets.UpdateTrendBarChart(ctx, bcTarget, "target")
// peers bar chart
bcPeers, err := barchart.New(
barchart.BarColors([]cell.Color{
cell.ColorGreen,
cell.ColorGreen,
cell.ColorYellow,
cell.ColorRed,
cell.ColorRed,
}),
barchart.ValueColors([]cell.Color{
cell.ColorWhite,
cell.ColorWhite,
cell.ColorCyan,
cell.ColorWhite,
cell.ColorWhite,
}),
barchart.ShowValues(),
barchart.BarWidth(8),
barchart.Labels([]string{
"๐ฎ๐ฎ",
"๐ฎ ",
"โ",
"๐ป ",
"๐ป๐ป",
}),
)
if err != nil {
panic(err)
}
go widgets.UpdateTrendBarChart(ctx, bcPeers, "peers")
notes, err := text.New()
if err != nil {
panic(err)
}
if err := notes.Write("Legend: ๐ฎ๐ฎ: strong buy, ๐ฎ: buy, โ: hold, ๐ป: sell, ๐ป ๐ป :strong sell "); err != nil {
panic(err)
}
// container outlay
c, err := container.New(
t,
container.Border(linestyle.Light),
container.BorderTitle("๐ PRESS Q TO QUIT"),
container.SplitVertical(
container.Left(
container.SplitHorizontal(
container.Top(
container.SplitHorizontal(
container.Top(
container.PlaceWidget(timeNow),
),
container.Bottom(
container.SplitHorizontal(
container.Top(
container.Border(linestyle.Light),
container.BorderTitle("๐ stock prices by yahoo finance "),
container.PlaceWidget(stk),
),
container.Bottom(
container.SplitHorizontal(
container.Top(
container.Border(linestyle.Light),
container.BorderTitle(fmt.Sprintf("%s stock price by yahoo finance", cfg.Stocks[0])),
container.PlaceWidget(lc),
),
container.Bottom(
container.PlaceWidget(volchart),
),
container.SplitPercent(70),
),
),
container.SplitPercent(30),
),
),
container.SplitPercent(5),
),
),
container.Bottom(
container.SplitHorizontal(
container.Top(
container.Border(linestyle.Light),
container.BorderTitle("๐
earning calendars by finnhub.io "),
container.PlaceWidget(earningCals),
),
container.Bottom(
container.SplitHorizontal(
container.Top(
container.Border(linestyle.Light),
container.BorderTitle("๐จ company news by finnhub.io "),
container.PlaceWidget(companyNewsRoll),
),
container.Bottom(
container.Border(linestyle.Light),
container.BorderTitle("๐ฌ market news by finnhub.io "),
container.PlaceWidget(news),
),
),
),
container.SplitPercent(30),
),
),
container.SplitPercent(45),
),
),
container.Right(
container.SplitHorizontal(
container.Top(
//container.Border(linestyle.Light),
container.SplitHorizontal(
container.Top(
container.SplitHorizontal(
container.Top(
container.Border(linestyle.Light),
container.BorderTitle("๐ basic financials by finnhub.io "),
container.PlaceWidget(basicFinancials),
),
container.Bottom(
//container.Border(linestyle.Light), //"download as csv button"
container.PlaceWidget(export1),
container.AlignHorizontal(align.HorizontalRight),
),
container.SplitPercent(85),
),
),
container.Bottom(
container.SplitHorizontal(
container.Top(
container.Border(linestyle.Light),
container.BorderTitle(fmt.Sprintf("๐๏ธ [%s] financials as reported by finnhub.io ", cfg.Stocks[0])),
container.PlaceWidget(financialReports),
),
container.Bottom(
//container.Border(linestyle.Light), //"download as csv button"
container.PlaceWidget(export2),
container.AlignHorizontal(align.HorizontalRight),
),
container.SplitPercent(85),
),
),
),
),
container.Bottom(
container.Border(linestyle.Light),
container.BorderTitle("๐๏ธ stock estimates by finnhub.io "),
container.SplitVertical(
container.Left(
container.SplitVertical(
container.Left(
container.Border(linestyle.Light),
container.BorderTitle(fmt.Sprintf(" [%s] news sentiment", cfg.Stocks[0])),
container.PlaceWidget(tnTrend),
),
container.Right(
container.Border(linestyle.Light),
container.BorderTitle(" avg peers news sentiment"),
container.PlaceWidget(pnTrend),
),
),
),
container.Right(
container.SplitHorizontal(
container.Top(
container.SplitVertical(
container.Left(
container.Border(linestyle.Light),
container.BorderTitle(fmt.Sprintf(" [%s] latest analyst recommendation", cfg.Stocks[0])),
container.PlaceWidget(bcTarget),
),
container.Right(
container.Border(linestyle.Light),
container.BorderTitle(" avg peers latest analyst recommendation"),
container.PlaceWidget(bcPeers),
),
),
),
container.Bottom(
container.PlaceWidget(notes),
),
container.SplitPercent(95),
),
),
),
),
container.SplitPercent(80),
),
),
container.SplitPercent(30),
),
)
if err != nil {
log.Fatal(err)
}
// define the quitter
quitter := func(k *terminalapi.Keyboard) {
if k.Key == 'q' || k.Key == 'Q' {
cancel()
}
}
if err := termdash.Run(ctx, t, c, termdash.KeyboardSubscriber(quitter)); err != nil {
log.Fatal(err)
}
}