bugfix: improve orderbook/ticker and currency logic

This commit is contained in:
Adrian Gallagher
2019-03-23 17:35:45 +11:00
parent 9c6c8f3341
commit 052b5c2f28
5 changed files with 19 additions and 5 deletions

View File

@@ -581,6 +581,10 @@ func (s *Storage) IsFiatCurrency(c Code) bool {
return c.Item.Role == Fiat
}
if c == USDT {
return false
}
t, _ := GetTranslation(c)
for _, d := range s.fiatCurrencies {
if d.Match(c) || d.Match(t) {
@@ -598,6 +602,10 @@ func (s *Storage) IsCryptocurrency(c Code) bool {
return c.Item.Role == Cryptocurrency
}
if c == USD {
return false
}
t, _ := GetTranslation(c)
for _, d := range s.cryptocurrencies {
if d.Match(c) || d.Match(t) {

View File

@@ -124,7 +124,6 @@ func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Bas
if !ok {
continue
}
orderBook.Pair = x
var obItems []orderbook.Item
for y := range data.Ask {
@@ -144,7 +143,7 @@ func (e *EXMO) UpdateOrderbook(p currency.Pair, assetType string) (orderbook.Bas
}
orderBook.Bids = obItems
orderBook.Pair = p
orderBook.Pair = x
orderBook.ExchangeName = e.GetName()
orderBook.AssetType = assetType

View File

@@ -97,7 +97,7 @@ func (k *Kraken) UpdateTicker(p currency.Pair, assetType string) (ticker.Price,
for _, x := range pairs {
for y, z := range tickers {
if !common.StringContains(y, x.Base.Upper().String()) &&
if !common.StringContains(y, x.Base.Upper().String()) ||
!common.StringContains(y, x.Quote.Upper().String()) {
continue
}

View File

@@ -115,7 +115,6 @@ func (p *Poloniex) UpdateOrderbook(currencyPair currency.Pair, assetType string)
if !ok {
continue
}
orderBook.Pair = x
var obItems []orderbook.Item
for y := range data.Bids {
@@ -132,7 +131,7 @@ func (p *Poloniex) UpdateOrderbook(currencyPair currency.Pair, assetType string)
orderbook.Item{Amount: obData.Amount, Price: obData.Price})
}
orderBook.Pair = currencyPair
orderBook.Pair = x
orderBook.Asks = obItems
orderBook.ExchangeName = p.GetName()
orderBook.AssetType = assetType

View File

@@ -168,6 +168,14 @@ func TestIsRelatablePairs(t *testing.T) {
if !result {
t.Fatal("Unexpected result")
}
// Test edge case between two pairs when currency translations were causing
// non-relational pairs to be relatable
result = IsRelatablePairs(currency.NewPairFromStrings("EUR", "USD"),
currency.NewPairFromStrings("BTC", "USD"), false)
if result {
t.Fatal("Unexpected result")
}
}
func TestGetRelatableCryptocurrencies(t *testing.T) {