mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
better variable names
This commit is contained in:
parent
40888fd29c
commit
78dec649e9
@ -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,
|
||||
})
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user