-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
49 lines (40 loc) · 960 Bytes
/
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
package main
import (
"fmt"
"log"
"os"
"strings"
"github.com/nsf/termbox-go"
)
func main() {
symbols := os.Args[1:]
if len(symbols) == 0 {
fmt.Println("./stockings [tickers]")
os.Exit(1)
}
for i, symbol := range symbols {
symbols[i] = strings.ToUpper(symbol)
}
if err := termbox.Init(); err != nil {
log.Panicln(err)
}
defer termbox.Close()
states, err := GetStates(symbols)
if err != nil {
log.Panicln(err)
}
eventQueue := make(chan termbox.Event)
go PollEvents(eventQueue)
endpoint := fmt.Sprintf("https://api.iextrading.com/1.0/stock/market/batch?symbols=%s&types=price", strings.Join(symbols, ","))
quotesQueue := make(chan Quotes)
go PollQuotes(endpoint, quotesQueue)
for {
select {
case quotes := <-quotesQueue:
// TODO: Probably force a render every iteration if key presses are going to affect the UI.
RenderQuotes(symbols, quotes, states)
case event := <-eventQueue:
HandleEvent(event)
}
}
}