Skip to content

Commit

Permalink
gofmt
Browse files Browse the repository at this point in the history
Signed-off-by: Toby Yan <me@tobyan.com>
  • Loading branch information
toby1991 committed Jul 18, 2019
1 parent 9589364 commit 4d6b4b6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 24 deletions.
5 changes: 1 addition & 4 deletions app/console/commands/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func init() {
cmd.Add(&Alert{})
}


type Alert struct {
}

Expand All @@ -28,7 +27,6 @@ func (hw *Alert) Description() string {
return "Alert crypto ticker"
}


func (hw *Alert) Handler(arg *cmd.Arg) error {
pair, err := arg.Get("pair")
if err != nil {
Expand Down Expand Up @@ -57,12 +55,11 @@ func (hw *Alert) Handler(arg *cmd.Arg) error {
if err != nil {
return err
}
a, err := alert.New(*pair, zone.Duration(durationInt64) * zone.Minute, *difference)
a, err := alert.New(*pair, zone.Duration(durationInt64)*zone.Minute, *difference)
if err != nil {
return err
}

// you can diy your own Fetchers or Notifiers
return a.Fetch(new(fetchers.HuoBi), new(notifiers.Pushover))
}

16 changes: 7 additions & 9 deletions app/logics/alert/alert.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@ import (
"strings"
)


type alert struct {
pair string
duration zone.Duration
difference string
pair string
duration zone.Duration
difference string

upDifference bigfloat.BigFloat
downDifference bigfloat.BigFloat
}
Expand All @@ -30,7 +29,6 @@ func New(pair string, duration zone.Duration, difference string) (*alert, error)
return a, err
}


type Response struct {
Status string `json:"status"`
Ch string `json:"ch"`
Expand All @@ -50,7 +48,7 @@ type TickData struct {
Direction string `json:"direction"`
}

func (alert *alert)Fetch(fetcher Fetcher, notifier Notifier) error {
func (alert *alert) Fetch(fetcher Fetcher, notifier Notifier) error {
resp, err := fetcher.Fetch(alert.pair)
if err != nil {
return err
Expand All @@ -76,13 +74,13 @@ func (alert *alert)Fetch(fetcher Fetcher, notifier Notifier) error {

func (alert *alert) notify(notifier Notifier, direction Direction, nowData *TickData) error {

cache.Put(alert.pair + "_notified", nowData.Price.String(), zone.Now().Add(alert.duration))
cache.Put(alert.pair+"_notified", nowData.Price.String(), zone.Now().Add(alert.duration))

diff, _ := strconv.ParseFloat(alert.difference, 64)

dataStr, _ := json.Marshal(nowData)

return notifier.Notify( strings.ToUpper(alert.pair), direction, fmt.Sprintf("%.2f%%", diff * 100), nowData.Price.String(), string(dataStr))
return notifier.Notify(strings.ToUpper(alert.pair), direction, fmt.Sprintf("%.2f%%", diff*100), nowData.Price.String(), string(dataStr))
}

func nowData(resp *Response) *TickData {
Expand Down
4 changes: 1 addition & 3 deletions app/logics/alert/fetchers/huobi.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,14 @@ import (
"totoval/app/logics/alert"
)


const (
HuobiMarketTradeBaseUrl = "https://api.huobi.pro/market/trade"
)

type HuoBi struct {

}

func (hb *HuoBi)Fetch(pair string)(resp *alert.Response, err error){
func (hb *HuoBi) Fetch(pair string) (resp *alert.Response, err error) {
statusCode, err := biu.Ready(biu.MethodGet, HuobiMarketTradeBaseUrl, &biu.Options{
ProxyUrl: config.GetString("alert.proxy"),
UrlParam: &biu.UrlParam{
Expand Down
15 changes: 8 additions & 7 deletions app/logics/alert/notifiers/pushover.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,29 @@ import (
"github.com/totoval/framework/config"
"totoval/app/logics/alert"
)

const (
PushOverMessageUrl = "https://api.pushover.net/1/messages.json"
)

type Pushover struct {

}
func (po *Pushover)Notify(pair string, direction alert.Direction, differencePercentage string, price string, rawDataStr string) error {

func (po *Pushover) Notify(pair string, direction alert.Direction, differencePercentage string, price string, rawDataStr string) error {
directionStr := "-"
if direction == alert.Up {
directionStr = "📈"
}else{
} else {
directionStr = "📉"
}

_, err := biu.Ready(biu.MethodPost, PushOverMessageUrl, &biu.Options{
Body: &biu.Body{
"token": config.GetString("pushover.token"),
"user": config.GetString("pushover.user"),
"device": config.GetString("pushover.device"),
"token": config.GetString("pushover.token"),
"user": config.GetString("pushover.user"),
"device": config.GetString("pushover.device"),

"title": fmt.Sprintf("[%s] %s %s !!! {%s}", pair, directionStr, differencePercentage, price),
"title": fmt.Sprintf("[%s] %s %s !!! {%s}", pair, directionStr, differencePercentage, price),
"message": string(rawDataStr),
},
}).Biu().Status()
Expand Down
2 changes: 1 addition & 1 deletion bootstrap/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"github.com/totoval/framework/cache"
"github.com/totoval/framework/helpers/zone"
"github.com/totoval/framework/logs"
"github.com/totoval/framework/validator"
"github.com/totoval/framework/sentry"
"github.com/totoval/framework/validator"

"totoval/config"
"totoval/resources/lang"
Expand Down

0 comments on commit 4d6b4b6

Please sign in to comment.