Various improvements

This commit is contained in:
Adrian Gallagher
2018-01-03 18:36:13 +11:00
parent 301257427e
commit 2446007b03
6 changed files with 31 additions and 17 deletions

View File

@@ -65,7 +65,9 @@ func (c CurrencyPair) Display(delimiter string, uppercase bool) CurrencyItem {
// Equal compares two currency pairs and returns whether or not they are equal
func (c CurrencyPair) Equal(p CurrencyPair) bool {
if c.FirstCurrency.Upper() == p.FirstCurrency.Upper() &&
c.SecondCurrency.Upper() == p.SecondCurrency.Upper() {
c.SecondCurrency.Upper() == p.SecondCurrency.Upper() ||
c.FirstCurrency.Upper() == p.SecondCurrency.Upper() &&
c.SecondCurrency.Upper() == p.FirstCurrency.Upper() {
return true
}
return false

View File

@@ -1,6 +1,8 @@
package pair
import "testing"
import (
"testing"
)
func TestLower(t *testing.T) {
t.Parallel()
@@ -127,6 +129,16 @@ func TestEqual(t *testing.T) {
actual, expected,
)
}
secondPair = NewCurrencyPair("USD", "BTC")
actual = pair.Equal(secondPair)
expected = true
if actual != expected {
t.Errorf(
"Test failed. Equal(): %v was not equal to expected value: %v",
actual, expected,
)
}
}
func TestNewCurrencyPair(t *testing.T) {

View File

@@ -196,7 +196,6 @@ func (g *GDAX) GetTicker(currencyPair string) (Ticker, error) {
path := fmt.Sprintf(
"%s/%s/%s", g.APIUrl+gdaxProducts, currencyPair, gdaxTicker)
log.Println(path)
return ticker, common.SendHTTPGetRequest(path, true, g.Verbose, &ticker)
}

View File

@@ -127,6 +127,8 @@ func (g *Gemini) Setup(exch config.ExchangeConfig) {
g.EnabledPairs = common.SplitStrings(exch.EnabledPairs, ",")
if exch.UseSandbox {
g.APIUrl = geminiSandboxAPIURL
} else {
g.APIUrl = geminiAPIURL
}
err := g.SetCurrencyPairFormat()
if err != nil {

View File

@@ -54,20 +54,19 @@ func (k *Kraken) UpdateTicker(p pair.CurrencyPair, assetType string) (ticker.Pri
}
for _, x := range pairs {
var tp ticker.Price
tick, ok := k.Ticker[x.Pair().String()]
if !ok {
continue
for y, z := range k.Ticker {
if common.StringContains(y, x.FirstCurrency.Upper().String()) && common.StringContains(y, x.SecondCurrency.Upper().String()) {
var tp ticker.Price
tp.Pair = x
tp.Last = z.Last
tp.Ask = z.Ask
tp.Bid = z.Bid
tp.High = z.High
tp.Low = z.Low
tp.Volume = z.Volume
ticker.ProcessTicker(k.GetName(), x, tp, assetType)
}
}
tp.Pair = x
tp.Last = tick.Last
tp.Ask = tick.Ask
tp.Bid = tick.Bid
tp.High = tick.High
tp.Low = tick.Low
tp.Volume = tick.Volume
ticker.ProcessTicker(k.GetName(), x, tp, assetType)
}
return ticker.GetTicker(k.GetName(), p, assetType)
}

View File

@@ -34,7 +34,7 @@ func (l *LocalBitcoins) UpdateTicker(p pair.CurrencyPair, assetType string) (tic
currency := x.SecondCurrency.String()
var tp ticker.Price
tp.Pair = x
tp.Last = tick[currency].Rates.Last
tp.Last = tick[currency].Avg24h
tp.Volume = tick[currency].VolumeBTC
ticker.ProcessTicker(l.GetName(), x, tp, assetType)
}