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
63 changes: 63 additions & 0 deletions bitbot/finance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package bitbot

import (
"fmt"
"strings"
"time"

"github.com/markcheno/go-quote"
"github.com/whyrusleeping/hellabot"
log "gopkg.in/inconshreveable/log15.v2"
)

var StockTrigger = NamedTrigger{
ID: "stockQuotes",
Help: "$SYMBOL to get current price for a stock symbol",
Condition: func(irc *hbot.Bot, m *hbot.Message) bool {
return m.Command == "PRIVMSG" && strings.HasPrefix(m.Content, "$")
},
Action: func(irc *hbot.Bot, m *hbot.Message) bool {
var q quote.Quote
var err error
symbol := strings.TrimPrefix(m.Content, "$")
if len(symbol) > 1 {
q, err = getStockSymbol(symbol)
} else {
log.Error("Error: Empty symbol provided to symbol lookup")
return true
}

if err != nil {
log.Error("Got an error during quote lookup!")
irc.Reply(m, fmt.Sprintf("Got an error during quote lookup: %s", err.Error()))
return true
}

replyWithQuote(irc, m, q)
return true
},
}

func getStockSymbol(symbol string) (quote.Quote, error) {
var (
q quote.Quote
err error
)

today := time.Now().Format("2006-01-02")
fmt.Println(today)
// has to be a 24 hour span over a trading day. error handling is overrated
q, err = quote.NewQuoteFromYahoo(symbol, "2019-10-30", "2019-10-31", quote.Daily, true)
if err != nil {
return q, err
}
log.Info(fmt.Sprintf("%+v", q))
return q, err
}

func replyWithQuote(irc *hbot.Bot, m *hbot.Message, q quote.Quote) {
irc.Reply(m, fmt.Sprintf("%s open: \t%2f", q.Symbol, q.Open[0]))
irc.Reply(m, fmt.Sprintf("%s high: \t%2f", q.Symbol, q.High[0]))
irc.Reply(m, fmt.Sprintf("%s low: \t%2f", q.Symbol, q.Low[0]))
irc.Reply(m, fmt.Sprintf("%s close: \t%2f", q.Symbol, q.Close[0]))
}
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ go 1.12

require (
github.com/bbriggs/quotes v0.0.0-20190225011706-ef48dc0c0ec7
github.com/go-stack/stack v1.8.0 // indirect
github.com/inconshreveable/log15 v0.0.0-20180818164646-67afb5ed74ec // indirect
github.com/justinian/dice v0.0.0-20170728002755-6a18b51d929c
github.com/leanovate/gopter v0.2.4
github.com/markcheno/go-quote v0.0.0-20190813122547-65145e8af89f
github.com/mattn/go-colorable v0.1.4 // indirect
github.com/mattn/go-isatty v0.0.10 // indirect
github.com/mb-14/gomarkov v0.0.0-20190125094512-044dd0dcb5e7
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/mudler/sendfd v0.0.0-20150620134918-f0fc74c13877 // indirect
github.com/prometheus/client_golang v1.2.1
github.com/spf13/cobra v0.0.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ github.com/leanovate/gopter v0.2.4 h1:U4YLBggDFhJdqQsG4Na2zX7joVTky9vHaj/AGEwSuX
github.com/leanovate/gopter v0.2.4/go.mod h1:gNcbPWNEWRe4lm+bycKqxUYoH5uoVje5SkOJ3uoLer8=
github.com/magiconair/properties v1.8.0 h1:LLgXmsheXeRoUOBOjtwPQCWIYqM/LU1ayDtDePerRcY=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/markcheno/go-quote v0.0.0-20190813122547-65145e8af89f h1:EbpTIlqfOCMc8cbymn8DL9W75F+LLSoGdxBpHF4HU1o=
github.com/markcheno/go-quote v0.0.0-20190813122547-65145e8af89f/go.mod h1:cDo3FVvBpEI83B1KazdWnVAh4K2F0ing4aCEEanmh9o=
github.com/mattn/go-colorable v0.1.1 h1:G1f5SKeVxmagw/IyvzvtZE4Gybcc4Tr1tf7I8z0XgOg=
github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcnceauSikq3lYCQ=
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
Expand Down