|
brandleesee / terminalstocks Goto Github PK
View Code? Open in Web Editor NEWThis project forked from mop-tracker/mop
Pure terminal stock ticker for Windows.
This project forked from mop-tracker/mop
Pure terminal stock ticker for Windows.
I tried installing but run into the following error. I'm using go 1.8. Seems like it doesn't like the hyphen in the package name. Sadly that's about as far as I've gotten since I've never used Go.
go version go1.8 linux/amd64
go install -x github.com/brandleesee/Terminal-Stocks/cmd/Terminal-Stocks
WORK=/tmp/go-build667285282
mkdir -p $WORK/github.com/brandleesee/Terminal-Stocks/_obj/
mkdir -p $WORK/github.com/brandleesee/
cd /home/jacques/.local/src/github.com/brandleesee/Terminal-Stocks
/home/jacques/.linuxbrew/Cellar/go/1.8_1/libexec/pkg/tool/linux_amd64/compile -o $WORK/github.com/brandleesee/Terminal-Stocks.a -trimpath $WORK -p github.com/brandleesee/Terminal-Stocks -complete -buildid 1ba4fa3006fb0e62343f61a09d6e121a58346ba0 -D _/home/jacques/.local/src/github.com/brandleesee/Terminal-Stocks -I $WORK -pack ./cnn_market.go ./column_editor.go ./layout.go ./line_editor.go ./markup.go ./profile.go ./screen.go ./sorter.go ./yahoo_quotes.go
# github.com/brandleesee/Terminal-Stocks
./cnn_market.go:5: syntax error: unexpected -, expecting ;
make: *** [install] Error 2
In an effort to remove functionality that I consider unnecessary for my use case, I ended up obfuscating the software's ability to update the ticker values live in the terminal.
For reference, the functionalities that have been removed from the original code (https://github.com/mop-tracker/mop) are the date/time/timezone, the column sorting ability, the filters, the ability to add and remove tickers, the keyboard help screen, and the values for the index/commodity/currency designated as market
or Market
in the code.
Therefore, from this:
to this:
If my interpretation is correct, the various blocks of code that generate and refresh the time do not interfere with the refreshing of the quotes data. However, the same cannot be said when removing the page cnn_market.go
(https://github.com/mop-tracker/mop/blob/master/cnn_market.go) and all associated code blocks and snippets pointing towards it.
The following code blocks are taken from mop (upstream) in view that its refresh function works as intended. Among other code blocks within the program, the following seem to be directly related to my issue. I may be mistaken.
It seems that for the quotes to work some code from the market page is necessary, hence, the market blocks and snippets of code cannot be completely eliminated. The intention is to rid cnn_market.go
completely and introduce alternative code that refreshes the data of the tickers without the current dependency on the said market page.
Line 59 in mop/cmd/mop/main.go
(https://github.com/mop-tracker/mop/blob/master/cmd/mop/main.go)
quotes := mop.NewQuotes(market, profile)
//-----------------------------------------------------------------------------
func mainLoop(screen *mop.Screen, profile *mop.Profile) {
var lineEditor *mop.LineEditor
var columnEditor *mop.ColumnEditor
keyboardQueue := make(chan termbox.Event)
timestampQueue := time.NewTicker(1 * time.Second)
quotesQueue := time.NewTicker(5 * time.Second)
marketQueue := time.NewTicker(12 * time.Second)
showingHelp := false
paused := false
go func() {
for {
keyboardQueue <- termbox.PollEvent()
}
}()
market := mop.NewMarket()
quotes := mop.NewQuotes(market, profile)
screen.Draw(market, quotes)
loop:
for {
select {
case event := <-keyboardQueue:
switch event.Type {
case termbox.EventKey:
if lineEditor == nil && columnEditor == nil && !showingHelp {
if event.Key == termbox.KeyEsc || event.Ch == 'q' || event.Ch == 'Q' {
break loop
} else if event.Ch == '+' || event.Ch == '-' {
lineEditor = mop.NewLineEditor(screen, quotes)
lineEditor.Prompt(event.Ch)
} else if event.Ch == 'f' {
lineEditor = mop.NewLineEditor(screen, quotes)
lineEditor.Prompt(event.Ch)
} else if event.Ch == 'F' {
profile.SetFilter("")
} else if event.Ch == 'o' || event.Ch == 'O' {
columnEditor = mop.NewColumnEditor(screen, quotes)
} else if event.Ch == 'g' || event.Ch == 'G' {
if profile.Regroup() == nil {
screen.Draw(quotes)
}
} else if event.Ch == 'p' || event.Ch == 'P' {
paused = !paused
screen.Pause(paused).Draw(time.Now())
} else if event.Ch == '?' || event.Ch == 'h' || event.Ch == 'H' {
showingHelp = true
screen.Clear().Draw(help)
}
} else if lineEditor != nil {
if done := lineEditor.Handle(event); done {
lineEditor = nil
}
} else if columnEditor != nil {
if done := columnEditor.Handle(event); done {
columnEditor = nil
}
} else if showingHelp {
showingHelp = false
screen.Clear().Draw(market, quotes)
}
case termbox.EventResize:
screen.Resize()
if !showingHelp {
screen.Draw(market, quotes)
} else {
screen.Draw(help)
}
}
case <-timestampQueue.C:
if !showingHelp && !paused {
screen.Draw(time.Now())
}
case <-quotesQueue.C:
if !showingHelp && !paused {
screen.Draw(quotes)
}
case <-marketQueue.C:
if !showingHelp && !paused {
screen.Draw(market)
}
}
}
}
Lines 52-57 in mop/yahoo_quotes.go
(https://github.com/mop-tracker/mop/blob/master/yahoo_quotes.go)
// Quotes stores relevant pointers as well as the array of stock quotes for
// the tickers we are tracking.
type Quotes struct {
market *Market // Pointer to Market.
profile *Profile // Pointer to Profile.
stocks []Stock // Array of stock quote data.
errors string // Error string if any.
}
Lines 59-66 in mop/yahoo_quotes.go
(https://github.com/mop-tracker/mop/blob/master/yahoo_quotes.go)
// Sets the initial values and returns new Quotes struct.
func NewQuotes(market *Market, profile *Profile) *Quotes {
return &Quotes{
market: market,
profile: profile,
errors: ``,
}
}
Lines 125-130 in mop/yahoo_quotes.go
(https://github.com/mop-tracker/mop/blob/master/yahoo_quotes.go)
I removed this because I did not want any visual errors that the stock market is closed.
That is, it is not necessary for my use case.
I am well aware of what time the markets are open and closed so I considered this functionality as unnecessary.
// isReady returns true if we haven't fetched the quotes yet *or* the stock
// market is still open and we might want to grab the latest quotes. In both
// cases we make sure the list of requested tickers is not empty.
func (quotes *Quotes) isReady() bool {
return (quotes.stocks == nil || !quotes.market.IsClosed) && len(quotes.profile.Tickers) > 0
}
This issue may be closed once the quotes refresh automatically every 'n' seconds.
Unless mistaken, the code governing 'n' is the following:
Line 28 in mop/profile.go
(https://github.com/brandleesee/TerminalStocks/blob/master/profile.go)
profile.QuotesRefresh = 5 // Stock quotes get updated every 5 seconds (12 times per minute).
// Creates the profile and attempts to load the settings from ~/.TSrc file.
// If the file is not there it gets created with default values.
func NewProfile() *Profile {
profile := &Profile{}
data, err := ioutil.ReadFile(profile.defaultFileName())
if err != nil { // Set default values:
profile.QuotesRefresh = 5 // Stock quotes get updated every 5 seconds (12 times per minute).
profile.Tickers = []string{`0700.HK`, `1810.HK`, `AAPL`, `ABNB`, `AMD`, `AMZN`, `ATVI`, `BABA`, `C`, `DIS`, `FB`, `GOOG`, `IBM`, `INTC`, `KO`, `MA`, `MSFT`, `NFLX`, `NVDA`, `ORCL`, `PYPL`, `SONY`, `SQ`, `TSLA`, `V`, `BTC-USD`, `ETH-USD`}
profile.Save()
} else {
json.Unmarshal(data, profile)
}
profile.selectedColumn = -1
return profile
}
To note that for mop, the profile is saved as .moprc
while for TerminalStocks it is .TSrc
.
Thank you.
When I run TerminalStocks I get this error message:
Error fetching stock quotes...
http://download.finance.yahoo.com/d/quotes.csv?s=AAPL+C+GOOG+IBM+KO+ORCL+V&f
I think it's possible that the yahoo finance API may have changed. This could be an error on my end but I do not believe that to be the case.
WORK=/tmp/go-build056010193
mkdir -p $WORK/github.com/mattn/go-runewidth/_obj/
cd /opt/go/src/github.com/mattn/go-runewidth
/usr/lib/go/pkg/tool/linux_amd64/6g -o $WORK/github.com/mattn/go-runewidth/_obj/_go_.6 -p github.com/mattn/go-runewidth -D _/opt/go/src/github.com/mattn/go-runewidth -I $WORK ./runewidth.go ./runewidth_posix.go
# github.com/mattn/go-runewidth
../../mattn/go-runewidth/runewidth.go:823: function ends without a return statement
make: *** [install] Error 2
For awareness only, I've opened a ticket on mattn, will update this channel.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.