From 6fd06db338dd2d1c6b17a5918a6bb56a22a43f42 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Mon, 4 Jun 2018 05:31:38 +0430 Subject: [PATCH 1/7] added bittrex module --- cryptoexchanges/bittrex/bittrex.go | 49 ++++++++ cryptoexchanges/bittrex/display.go | 65 ++++++++++ cryptoexchanges/bittrex/widget.go | 187 +++++++++++++++++++++++++++++ wtf.go | 3 + 4 files changed, 304 insertions(+) create mode 100644 cryptoexchanges/bittrex/bittrex.go create mode 100644 cryptoexchanges/bittrex/display.go create mode 100644 cryptoexchanges/bittrex/widget.go diff --git a/cryptoexchanges/bittrex/bittrex.go b/cryptoexchanges/bittrex/bittrex.go new file mode 100644 index 00000000..d4f4eed4 --- /dev/null +++ b/cryptoexchanges/bittrex/bittrex.go @@ -0,0 +1,49 @@ +package bittrex + +type summaryList struct { + items []*fCurrency +} + +// fCurrency From Currency +type fCurrency struct { + name string + displayName string + to []*tCurrency +} + +// tCurrency To Currency +type tCurrency struct { + name string + summaryInfo +} + +type summaryInfo struct { + Low string + High string + Volume string + Last string + OpenSellOrders string + OpenBuyOrders string +} + +type summaryResponse struct { + Success bool `json:"success"` + Message string `json:"message"` + Result []struct { + MarketName string `json:"MarketName"` + High float64 `json:"High"` + Low float64 `json:"Low"` + Last float64 `json:"Last"` + Volume float64 `json:"Volume"` + OpenSellOrders int `json:"OpenSellOrders"` + OpenBuyOrders int `json:"OpenBuyOrders"` + } `json:"result"` +} + +func (list *summaryList) addSummaryItem(name, displayName string, toList []*tCurrency) { + list.items = append(list.items, &fCurrency{ + name: name, + displayName: displayName, + to: toList, + }) +} diff --git a/cryptoexchanges/bittrex/display.go b/cryptoexchanges/bittrex/display.go new file mode 100644 index 00000000..28c368e5 --- /dev/null +++ b/cryptoexchanges/bittrex/display.go @@ -0,0 +1,65 @@ +package bittrex + +import ( + "bytes" + "fmt" + "text/template" +) + +func (widget *Widget) display() { + if ok == false { + widget.View.SetText(fmt.Sprintf("%s", errorText)) + return + } + + str := "" + str += summaryText(&widget.summaryList, &widget.TextColors) + + widget.View.SetText(fmt.Sprintf("%s", str)) +} + +func summaryText(list *summaryList, colors *TextColors) string { + str := "" + + for _, fromCurrency := range list.items { + str += fmt.Sprintf("[%s]%s[%s](%s):\n", colors.base.displayName, fromCurrency.displayName, colors.base.name, fromCurrency.name) + + resultTemplate := template.New("bittrex") + + for _, toCurrency := range fromCurrency.to { + writer := new(bytes.Buffer) + strTemplate, _ := resultTemplate.Parse( + "\t[{{.nameColor}}]{{.mName}}\n" + + formatableText("High", "High") + + formatableText("Low", "Low") + + formatableText("Last", "Last") + + formatableText("Volume", "Volume") + + formatableText("OpenSellOrders", "OpenSellOrders") + + formatableText("OpenBuyOrders", "OpenBuyOrders"), + ) + + strTemplate.Execute(writer, map[string]string{ + "nameColor": colors.market.name, + "fieldColor": colors.market.field, + "valueColor": colors.market.value, + "mName": toCurrency.name, + "High": toCurrency.High, + "Low": toCurrency.Low, + "Last": toCurrency.Last, + "Volume": toCurrency.Volume, + "OpenSellOrders": toCurrency.OpenSellOrders, + "OpenBuyOrders": toCurrency.OpenBuyOrders, + }) + + str += writer.String() + } + + } + + return str + +} + +func formatableText(key, value string) string { + return fmt.Sprintf("\t\t[{{.fieldColor}}]%s: [{{.valueColor}}]{{.%s}}\n", key, value) +} diff --git a/cryptoexchanges/bittrex/widget.go b/cryptoexchanges/bittrex/widget.go new file mode 100644 index 00000000..9f5039dd --- /dev/null +++ b/cryptoexchanges/bittrex/widget.go @@ -0,0 +1,187 @@ +package bittrex + +import ( + "encoding/json" + "fmt" + "time" + + "net/http" + + "github.com/olebedev/config" + "github.com/senorprogrammer/wtf/wtf" +) + +// Config is a pointer to the global config object +var Config *config.Config + +type TextColors struct { + base struct { + name string + displayName string + } + market struct { + name string + field string + value string + } +} + +var ok = true +var errorText = "" +var started = false +var baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary" + +// Widget define wtf widget to register widget later +type Widget struct { + wtf.TextWidget + summaryList + updateInterval int + TextColors +} + +// NewWidget Make new instance of widget +func NewWidget() *Widget { + + widget := Widget{ + TextWidget: wtf.NewTextWidget(" $ Bittrex ", "bittrex", false), + summaryList: summaryList{}, + updateInterval: Config.UInt("wtf.mods.bittrex.updateInterval", 10), + } + + started = false + ok = true + errorText = "" + + widget.config() + widget.setSummaryList() + + return &widget +} + +func (widget *Widget) config() { + widget.TextColors.base.name = Config.UString("wtf.mods.bittrex.colors.base.name", "red") + widget.TextColors.base.displayName = Config.UString("wtf.mods.bittrex.colors.base.displayName", "grey") + widget.TextColors.market.name = Config.UString("wtf.mods.bittrex.colors.market.name", "red") + widget.TextColors.market.field = Config.UString("wtf.mods.bittrex.colors.market.field", "coral") + widget.TextColors.market.value = Config.UString("wtf.mods.bittrex.colors.market.value", "white") +} + +func (widget *Widget) setSummaryList() { + sCurrencies, _ := Config.Map("wtf.mods.bittrex.summary") + for fromCurrencyName := range sCurrencies { + displayName, _ := Config.String("wtf.mods.bittrex.summary." + fromCurrencyName + ".displayName") + toCurrencyList := makeSummaryToList(fromCurrencyName) + widget.summaryList.addSummaryItem(fromCurrencyName, displayName, toCurrencyList) + } +} + +func makeSummaryToList(currencyName string) []*tCurrency { + tCurrencyList := []*tCurrency{} + + configToList, _ := Config.List("wtf.mods.bittrex.summary." + currencyName + ".market") + for _, toCurrencyName := range configToList { + tCurrencyList = append(tCurrencyList, makeToCurrency(toCurrencyName.(string))) + } + + return tCurrencyList +} + +func makeToCurrency(name string) *tCurrency { + return &tCurrency{ + name: name, + summaryInfo: summaryInfo{ + High: "-1", + Low: "-1", + Volume: "-1", + Last: "-1", + OpenBuyOrders: "-1", + OpenSellOrders: "-1", + }, + } +} + +/* -------------------- Exported Functions -------------------- */ + +// Refresh & update after interval time +func (widget *Widget) Refresh() { + if widget.Disabled() { + return + } + + if started == false { + go func() { + for { + widget.updateSummary() + time.Sleep(time.Second * time.Duration(widget.updateInterval)) + } + }() + started = true + } + + widget.UpdateRefreshedAt() + + widget.display() + +} + +/* -------------------- Unexported Functions -------------------- */ + +func (widget *Widget) updateSummary() { + client := &http.Client{ + Timeout: time.Duration(5 * time.Second), + } + + for _, fromCurrency := range widget.summaryList.items { + for _, toCurrency := range fromCurrency.to { + request := makeRequest(fromCurrency.name, toCurrency.name) + response, err := client.Do(request) + + if err != nil { + ok = false + errorText = "Please Check Your Internet Connection!" + break + } else { + ok = true + errorText = "" + } + + if response.StatusCode != http.StatusOK { + errorText = response.Status + ok = false + break + } else { + ok = true + errorText = "" + } + + defer response.Body.Close() + jsonResponse := summaryResponse{} + decoder := json.NewDecoder(response.Body) + decoder.Decode(&jsonResponse) + + if !jsonResponse.Success { + ok = false + errorText = fmt.Sprintf("%s-%s: %s", fromCurrency.name, toCurrency.name, jsonResponse.Message) + break + } + ok = true + errorText = "" + + toCurrency.Last = fmt.Sprintf("%f", jsonResponse.Result[0].Last) + toCurrency.High = fmt.Sprintf("%f", jsonResponse.Result[0].High) + toCurrency.Low = fmt.Sprintf("%f", jsonResponse.Result[0].Low) + toCurrency.Volume = fmt.Sprintf("%f", jsonResponse.Result[0].Volume) + toCurrency.OpenBuyOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenBuyOrders) + toCurrency.OpenSellOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenSellOrders) + } + } + + widget.display() +} + +func makeRequest(fName, tName string) *http.Request { + url := fmt.Sprintf("%s?market=%s-%s", baseURL, fName, tName) + request, _ := http.NewRequest("GET", url, nil) + + return request +} diff --git a/wtf.go b/wtf.go index ed36b454..5ba51d4e 100644 --- a/wtf.go +++ b/wtf.go @@ -13,6 +13,7 @@ import ( "github.com/senorprogrammer/wtf/bamboohr" "github.com/senorprogrammer/wtf/clocks" "github.com/senorprogrammer/wtf/cmdrunner" + "github.com/senorprogrammer/wtf/cryptoexchanges/bittrex" "github.com/senorprogrammer/wtf/cryptoexchanges/cryptolive" "github.com/senorprogrammer/wtf/gcal" "github.com/senorprogrammer/wtf/git" @@ -175,6 +176,7 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { prettyweather.Config = Config wtf.Config = Config cryptolive.Config = Config + bittrex.Config = Config Widgets = []wtf.Wtfable{ bamboohr.NewWidget(), @@ -196,6 +198,7 @@ func makeWidgets(app *tview.Application, pages *tview.Pages) { weather.NewWidget(app, pages), cryptolive.NewWidget(), prettyweather.NewWidget(), + bittrex.NewWidget(), } FocusTracker = wtf.FocusTracker{ From 7ed874b4dde2c820b476c77091fa5109aede122f Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Mon, 4 Jun 2018 06:19:42 +0430 Subject: [PATCH 2/7] add module to docs --- docs/posts/modules/bittrex/index.html | 243 ++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 docs/posts/modules/bittrex/index.html diff --git a/docs/posts/modules/bittrex/index.html b/docs/posts/modules/bittrex/index.html new file mode 100644 index 00000000..13817360 --- /dev/null +++ b/docs/posts/modules/bittrex/index.html @@ -0,0 +1,243 @@ + + + + + + + + + + + + + Module: Bittrex | WTF - A Terminal Dashboard + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+

Module: Bittrex

+ +
+ +
+ +

Get the last 24 hour summary of cryptocurrencies market.

+ +

Source Code

+
+
wtf/bittrex/
+
+

Required ENV Variables

+ +

None.

+ +

Keyboard Commands

+ +

None.

+ +

Configuration

+
+
bittrex:
+  enabled: true
+  position:
+    top: 1
+    left: 2
+    height: 1
+    width: 1
+  updateInterval: 15
+  summary: 
+   BTC:
+     displayName: Bitcoin
+     market: 
+       - ETH
+       - LTC
+   ETH:
+     displayName: Ethereum
+     market: 
+       - LTC
+  colors: 
+   base: 
+     name: red
+     displayName: grey
+   market:
+     name: red
+     field: coral
+     value: white
+
+
+
+

Attributes

+ + + +

+ enabled +
Determines whether or not this module is executed and if its data displayed onscreen. +
Values: + true, + false.

+ +

+ position +
Defines where in the grid this module’s widget will be displayed. +
+

+ +

+ updateInterval +
How often, in seconds, this module will update its data. +
Values: A positive integer +
Default Value: 10

+ +

+ colors +
Sets color of texts. +
Values: A valid color +

+ +
+ + +
+ + + + \ No newline at end of file From 0386cf88ecc6e315bcd3865e22f2cd7fc05e8f3e Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Mon, 4 Jun 2018 06:29:58 +0430 Subject: [PATCH 3/7] avoid panics --- cryptoexchanges/bittrex/widget.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cryptoexchanges/bittrex/widget.go b/cryptoexchanges/bittrex/widget.go index 9f5039dd..dc85f3e2 100644 --- a/cryptoexchanges/bittrex/widget.go +++ b/cryptoexchanges/bittrex/widget.go @@ -127,6 +127,11 @@ func (widget *Widget) Refresh() { /* -------------------- Unexported Functions -------------------- */ func (widget *Widget) updateSummary() { + // In case if anything bad happened! + defer func() { + recover() + }() + client := &http.Client{ Timeout: time.Duration(5 * time.Second), } From f8a3b5741499b2266247e4c6cb2767943bdf27ba Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Mon, 4 Jun 2018 06:57:37 +0430 Subject: [PATCH 4/7] better variable names --- cryptoexchanges/bittrex/bittrex.go | 18 +++++------ cryptoexchanges/bittrex/display.go | 20 ++++++------- cryptoexchanges/bittrex/widget.go | 48 +++++++++++++++--------------- 3 files changed, 43 insertions(+), 43 deletions(-) diff --git a/cryptoexchanges/bittrex/bittrex.go b/cryptoexchanges/bittrex/bittrex.go index d4f4eed4..c06f65cb 100644 --- a/cryptoexchanges/bittrex/bittrex.go +++ b/cryptoexchanges/bittrex/bittrex.go @@ -1,18 +1,18 @@ package bittrex type summaryList struct { - items []*fCurrency + items []*bCurrency } -// fCurrency From Currency -type fCurrency struct { +// Base Currency +type bCurrency struct { name string displayName string - to []*tCurrency + markets []*mCurrency } -// tCurrency To Currency -type tCurrency struct { +// Market Currency +type mCurrency struct { name string summaryInfo } @@ -40,10 +40,10 @@ type summaryResponse struct { } `json:"result"` } -func (list *summaryList) addSummaryItem(name, displayName string, toList []*tCurrency) { - list.items = append(list.items, &fCurrency{ +func (list *summaryList) addSummaryItem(name, displayName string, marketList []*mCurrency) { + list.items = append(list.items, &bCurrency{ name: name, displayName: displayName, - to: toList, + markets: marketList, }) } diff --git a/cryptoexchanges/bittrex/display.go b/cryptoexchanges/bittrex/display.go index 28c368e5..29cc6124 100644 --- a/cryptoexchanges/bittrex/display.go +++ b/cryptoexchanges/bittrex/display.go @@ -21,12 +21,12 @@ func (widget *Widget) display() { func summaryText(list *summaryList, colors *TextColors) string { str := "" - for _, fromCurrency := range list.items { - str += fmt.Sprintf("[%s]%s[%s](%s):\n", colors.base.displayName, fromCurrency.displayName, colors.base.name, fromCurrency.name) + for _, baseCurrency := range list.items { + str += fmt.Sprintf("[%s]%s[%s](%s):\n", colors.base.displayName, baseCurrency.displayName, colors.base.name, baseCurrency.name) resultTemplate := template.New("bittrex") - for _, toCurrency := range fromCurrency.to { + for _, marketCurrency := range baseCurrency.markets { writer := new(bytes.Buffer) strTemplate, _ := resultTemplate.Parse( "\t[{{.nameColor}}]{{.mName}}\n" + @@ -42,13 +42,13 @@ func summaryText(list *summaryList, colors *TextColors) string { "nameColor": colors.market.name, "fieldColor": colors.market.field, "valueColor": colors.market.value, - "mName": toCurrency.name, - "High": toCurrency.High, - "Low": toCurrency.Low, - "Last": toCurrency.Last, - "Volume": toCurrency.Volume, - "OpenSellOrders": toCurrency.OpenSellOrders, - "OpenBuyOrders": toCurrency.OpenBuyOrders, + "mName": marketCurrency.name, + "High": marketCurrency.High, + "Low": marketCurrency.Low, + "Last": marketCurrency.Last, + "Volume": marketCurrency.Volume, + "OpenSellOrders": marketCurrency.OpenSellOrders, + "OpenBuyOrders": marketCurrency.OpenBuyOrders, }) str += writer.String() diff --git a/cryptoexchanges/bittrex/widget.go b/cryptoexchanges/bittrex/widget.go index dc85f3e2..fd5c04ed 100644 --- a/cryptoexchanges/bittrex/widget.go +++ b/cryptoexchanges/bittrex/widget.go @@ -68,26 +68,26 @@ func (widget *Widget) config() { func (widget *Widget) setSummaryList() { sCurrencies, _ := Config.Map("wtf.mods.bittrex.summary") - for fromCurrencyName := range sCurrencies { - displayName, _ := Config.String("wtf.mods.bittrex.summary." + fromCurrencyName + ".displayName") - toCurrencyList := makeSummaryToList(fromCurrencyName) - widget.summaryList.addSummaryItem(fromCurrencyName, displayName, toCurrencyList) + for baseCurrencyName := range sCurrencies { + displayName, _ := Config.String("wtf.mods.bittrex.summary." + baseCurrencyName + ".displayName") + mCurrencyList := makeSummaryMarketList(baseCurrencyName) + widget.summaryList.addSummaryItem(baseCurrencyName, displayName, mCurrencyList) } } -func makeSummaryToList(currencyName string) []*tCurrency { - tCurrencyList := []*tCurrency{} +func makeSummaryMarketList(currencyName string) []*mCurrency { + mCurrencyList := []*mCurrency{} - configToList, _ := Config.List("wtf.mods.bittrex.summary." + currencyName + ".market") - for _, toCurrencyName := range configToList { - tCurrencyList = append(tCurrencyList, makeToCurrency(toCurrencyName.(string))) + configMarketList, _ := Config.List("wtf.mods.bittrex.summary." + currencyName + ".market") + for _, mCurrencyName := range configMarketList { + mCurrencyList = append(mCurrencyList, makeMarketCurrency(mCurrencyName.(string))) } - return tCurrencyList + return mCurrencyList } -func makeToCurrency(name string) *tCurrency { - return &tCurrency{ +func makeMarketCurrency(name string) *mCurrency { + return &mCurrency{ name: name, summaryInfo: summaryInfo{ High: "-1", @@ -136,9 +136,9 @@ func (widget *Widget) updateSummary() { Timeout: time.Duration(5 * time.Second), } - for _, fromCurrency := range widget.summaryList.items { - for _, toCurrency := range fromCurrency.to { - request := makeRequest(fromCurrency.name, toCurrency.name) + for _, baseCurrency := range widget.summaryList.items { + for _, mCurrency := range baseCurrency.markets { + request := makeRequest(baseCurrency.name, mCurrency.name) response, err := client.Do(request) if err != nil { @@ -166,26 +166,26 @@ func (widget *Widget) updateSummary() { if !jsonResponse.Success { ok = false - errorText = fmt.Sprintf("%s-%s: %s", fromCurrency.name, toCurrency.name, jsonResponse.Message) + errorText = fmt.Sprintf("%s-%s: %s", baseCurrency.name, mCurrency.name, jsonResponse.Message) break } ok = true errorText = "" - toCurrency.Last = fmt.Sprintf("%f", jsonResponse.Result[0].Last) - toCurrency.High = fmt.Sprintf("%f", jsonResponse.Result[0].High) - toCurrency.Low = fmt.Sprintf("%f", jsonResponse.Result[0].Low) - toCurrency.Volume = fmt.Sprintf("%f", jsonResponse.Result[0].Volume) - toCurrency.OpenBuyOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenBuyOrders) - toCurrency.OpenSellOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenSellOrders) + mCurrency.Last = fmt.Sprintf("%f", jsonResponse.Result[0].Last) + mCurrency.High = fmt.Sprintf("%f", jsonResponse.Result[0].High) + mCurrency.Low = fmt.Sprintf("%f", jsonResponse.Result[0].Low) + mCurrency.Volume = fmt.Sprintf("%f", jsonResponse.Result[0].Volume) + mCurrency.OpenBuyOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenBuyOrders) + mCurrency.OpenSellOrders = fmt.Sprintf("%d", jsonResponse.Result[0].OpenSellOrders) } } widget.display() } -func makeRequest(fName, tName string) *http.Request { - url := fmt.Sprintf("%s?market=%s-%s", baseURL, fName, tName) +func makeRequest(baseName, marketName string) *http.Request { + url := fmt.Sprintf("%s?market=%s-%s", baseURL, baseName, marketName) request, _ := http.NewRequest("GET", url, nil) return request From 7cb395f61c42a22eb41beedbd2d8a8516f9a7b04 Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Mon, 4 Jun 2018 20:10:10 +0430 Subject: [PATCH 5/7] added bittrex to docs --- .../posts/modules/cryptocurrencies/bittrex.md | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 _site/content/posts/modules/cryptocurrencies/bittrex.md diff --git a/_site/content/posts/modules/cryptocurrencies/bittrex.md b/_site/content/posts/modules/cryptocurrencies/bittrex.md new file mode 100644 index 00000000..4e7316fa --- /dev/null +++ b/_site/content/posts/modules/cryptocurrencies/bittrex.md @@ -0,0 +1,85 @@ +--- +title: "Bittrex" +date: 2018-06-04T20:06:40-07:00 +draft: false +--- + +Added in `v0.0.5`. + +Get the last 24 hour summary of cryptocurrencies market using [Bittrex](https://bittrex.com). + +## Source Code + +```bash +wtf/cryptoexchanges/bittrex/ +``` + +## Required ENV Vars + +None. + +## Keyboard Commands + +None. + +## Configuration + +```yaml +bittrex: + enabled: true + position: + top: 1 + left: 2 + height: 3 + width: 1 + updateInterval: 5 + summary: + BTC: + displayName: Bitcoin + market: + - LTC + - ETH + colors: + base: + name: orange + displayName: red + market: + name: red + field: white + value: green +``` + +### Attributes + +`colors.base.name`
+Values: Any X11 +color name. + +`colors.base.dispayName`
+Values: Any X11 +color name. + +`colors.market.name`
+Values: Any X11 +color name. + +`colors.market.field`
+Values: Any X11 +color name. + +`colors.market.value`
+Values: Any X11 +color name. + +`summary`
+ +`enabled`
+Determines whether or not this module is executed and if its data displayed onscreen.
+Values: `true`, `false`. + +`position`
+Defines where in the grid this module's widget will be displayed.
+ +`updateInterval`
+How often, in seconds, this module will update its data.
+Values: A positive integer, `0..n`. From 887239b97f3704cc2247a3d3ad1354728a68a46f Mon Sep 17 00:00:00 2001 From: Hossein Mehrabi Date: Mon, 4 Jun 2018 20:59:07 +0430 Subject: [PATCH 6/7] replaced updateInterval with refreshInterval --- _site/content/posts/modules/cryptocurrencies/bittrex.md | 4 ++-- cryptoexchanges/bittrex/widget.go | 8 +++----- docs/posts/modules/bittrex/index.html | 2 +- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/_site/content/posts/modules/cryptocurrencies/bittrex.md b/_site/content/posts/modules/cryptocurrencies/bittrex.md index 4e7316fa..99fc7272 100644 --- a/_site/content/posts/modules/cryptocurrencies/bittrex.md +++ b/_site/content/posts/modules/cryptocurrencies/bittrex.md @@ -32,7 +32,7 @@ bittrex: left: 2 height: 3 width: 1 - updateInterval: 5 + refreshInterval: 5 summary: BTC: displayName: Bitcoin @@ -80,6 +80,6 @@ Values: `true`, `false`. `position`
Defines where in the grid this module's widget will be displayed.
-`updateInterval`
+`refreshInterval`
How often, in seconds, this module will update its data.
Values: A positive integer, `0..n`. diff --git a/cryptoexchanges/bittrex/widget.go b/cryptoexchanges/bittrex/widget.go index fd5c04ed..264b2cd3 100644 --- a/cryptoexchanges/bittrex/widget.go +++ b/cryptoexchanges/bittrex/widget.go @@ -35,7 +35,6 @@ var baseURL = "https://bittrex.com/api/v1.1/public/getmarketsummary" type Widget struct { wtf.TextWidget summaryList - updateInterval int TextColors } @@ -43,9 +42,8 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" $ Bittrex ", "bittrex", false), - summaryList: summaryList{}, - updateInterval: Config.UInt("wtf.mods.bittrex.updateInterval", 10), + TextWidget: wtf.NewTextWidget(" $ Bittrex ", "bittrex", false), + summaryList: summaryList{}, } started = false @@ -112,7 +110,7 @@ func (widget *Widget) Refresh() { go func() { for { widget.updateSummary() - time.Sleep(time.Second * time.Duration(widget.updateInterval)) + time.Sleep(time.Second * time.Duration(widget.RefreshInterval())) } }() started = true diff --git a/docs/posts/modules/bittrex/index.html b/docs/posts/modules/bittrex/index.html index 13817360..8ab9753c 100644 --- a/docs/posts/modules/bittrex/index.html +++ b/docs/posts/modules/bittrex/index.html @@ -180,7 +180,7 @@ left: 2 height: 1 width: 1 - updateInterval: 15 + refreshInterval: 15 summary: BTC: displayName: Bitcoin From 092419d5b2a0474497a45818d02c580e4699b610 Mon Sep 17 00:00:00 2001 From: Chris Cummer Date: Mon, 4 Jun 2018 20:45:33 -0700 Subject: [PATCH 7/7] Clean up the formatting of the text in Bittrex module --- cryptoexchanges/bittrex/display.go | 16 +++++++++------- cryptoexchanges/bittrex/widget.go | 14 +++++++------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cryptoexchanges/bittrex/display.go b/cryptoexchanges/bittrex/display.go index 29cc6124..2718e0f7 100644 --- a/cryptoexchanges/bittrex/display.go +++ b/cryptoexchanges/bittrex/display.go @@ -22,20 +22,22 @@ func summaryText(list *summaryList, colors *TextColors) string { str := "" for _, baseCurrency := range list.items { - str += fmt.Sprintf("[%s]%s[%s](%s):\n", colors.base.displayName, baseCurrency.displayName, colors.base.name, baseCurrency.name) + str += fmt.Sprintf(" [%s]%s[%s] (%s)\n\n", colors.base.displayName, baseCurrency.displayName, colors.base.name, baseCurrency.name) resultTemplate := template.New("bittrex") for _, marketCurrency := range baseCurrency.markets { writer := new(bytes.Buffer) + strTemplate, _ := resultTemplate.Parse( - "\t[{{.nameColor}}]{{.mName}}\n" + + " [{{.nameColor}}]{{.mName}}\n" + formatableText("High", "High") + formatableText("Low", "Low") + formatableText("Last", "Last") + formatableText("Volume", "Volume") + - formatableText("OpenSellOrders", "OpenSellOrders") + - formatableText("OpenBuyOrders", "OpenBuyOrders"), + "\n" + + formatableText("Open Buy", "OpenBuyOrders") + + formatableText("Open Sell", "OpenSellOrders"), ) strTemplate.Execute(writer, map[string]string{ @@ -47,11 +49,11 @@ func summaryText(list *summaryList, colors *TextColors) string { "Low": marketCurrency.Low, "Last": marketCurrency.Last, "Volume": marketCurrency.Volume, - "OpenSellOrders": marketCurrency.OpenSellOrders, "OpenBuyOrders": marketCurrency.OpenBuyOrders, + "OpenSellOrders": marketCurrency.OpenSellOrders, }) - str += writer.String() + str += writer.String() + "\n" } } @@ -61,5 +63,5 @@ func summaryText(list *summaryList, colors *TextColors) string { } func formatableText(key, value string) string { - return fmt.Sprintf("\t\t[{{.fieldColor}}]%s: [{{.valueColor}}]{{.%s}}\n", key, value) + return fmt.Sprintf("[{{.fieldColor}}]%12s: [{{.valueColor}}]{{.%s}}\n", key, value) } diff --git a/cryptoexchanges/bittrex/widget.go b/cryptoexchanges/bittrex/widget.go index 264b2cd3..3f6f4d92 100644 --- a/cryptoexchanges/bittrex/widget.go +++ b/cryptoexchanges/bittrex/widget.go @@ -42,7 +42,7 @@ type Widget struct { func NewWidget() *Widget { widget := Widget{ - TextWidget: wtf.NewTextWidget(" $ Bittrex ", "bittrex", false), + TextWidget: wtf.NewTextWidget(" Bittrex ", "bittrex", false), summaryList: summaryList{}, } @@ -88,12 +88,12 @@ func makeMarketCurrency(name string) *mCurrency { return &mCurrency{ name: name, summaryInfo: summaryInfo{ - High: "-1", - Low: "-1", - Volume: "-1", - Last: "-1", - OpenBuyOrders: "-1", - OpenSellOrders: "-1", + High: "", + Low: "", + Volume: "", + Last: "", + OpenBuyOrders: "", + OpenSellOrders: "", }, } }