diff --git a/model/tradingPair.go b/model/tradingPair.go index 8e7a6eb7a..1ad542ed3 100644 --- a/model/tradingPair.go +++ b/model/tradingPair.go @@ -48,14 +48,35 @@ func (p TradingPair) ToString(c *AssetConverter, delim string) (string, error) { // TradingPairFromString makes a TradingPair out of a string func TradingPairFromString(codeSize int8, c *AssetConverter, p string) (*TradingPair, error) { - base, e := c.FromString(p[0:codeSize]) + return TradingPairFromString2(codeSize, []*AssetConverter{c}, p) +} + +// TradingPairFromString2 makes a TradingPair out of a string +func TradingPairFromString2(codeSize int8, converters []*AssetConverter, p string) (*TradingPair, error) { + var base Asset + var quote Asset + var e error + + baseString := p[0:codeSize] + for _, c := range converters { + base, e = c.FromString(baseString) + if e == nil { + break + } + } if e != nil { - return nil, fmt.Errorf("base asset could not be converted: %s", e) + return nil, fmt.Errorf("base asset could not be converted using any of the converters in the list of %d converters: %s", len(converters), baseString) } - quote, e := c.FromString(p[codeSize : codeSize*2]) + quoteString := p[codeSize : codeSize*2] + for _, c := range converters { + quote, e = c.FromString(quoteString) + if e == nil { + break + } + } if e != nil { - return nil, fmt.Errorf("quote asset could not be converted: %s", e) + return nil, fmt.Errorf("quote asset could not be converted using any of the converters in the list of %d converters: %s", len(converters), quoteString) } return &TradingPair{Base: base, Quote: quote}, nil diff --git a/plugins/ieif.go b/plugins/ieif.go index 34f566c08..894302bfe 100644 --- a/plugins/ieif.go +++ b/plugins/ieif.go @@ -3,6 +3,7 @@ package plugins import ( "fmt" "log" + "strings" "github.com/stellar/go/clients/horizon" "github.com/stellar/kelp/api" @@ -168,15 +169,16 @@ func (ieif *IEIF) LogAllLiabilities(assetBase horizon.Asset, assetQuote horizon. } func (ieif *IEIF) logLiabilities(asset horizon.Asset, assetStr string) { + trimmedAssetStr := strings.TrimSpace(assetStr) l, e := ieif.assetLiabilities(asset) if e != nil { - log.Printf("could not fetch liability for asset '%s', error = %s\n", assetStr, e) + log.Printf("could not fetch liability for %s asset, error = %s\n", trimmedAssetStr, e) return } balance, e := ieif.assetBalance(asset) if e != nil { - log.Printf("cannot fetch balance for asset '%s', error = %s\n", assetStr, e) + log.Printf("cannot fetch balance for %s asset, error = %s\n", trimmedAssetStr, e) return } // TODO don't break out into vars diff --git a/plugins/krakenExchange.go b/plugins/krakenExchange.go index 4aadae595..f8149b50a 100644 --- a/plugins/krakenExchange.go +++ b/plugins/krakenExchange.go @@ -220,12 +220,13 @@ func (k *krakenExchange) GetOpenOrders(pairs []*model.TradingPair) (map[model.Tr return nil, e } + assetConverters := []*model.AssetConverter{k.assetConverterOpenOrders, model.Display} m := map[model.TradingPair][]model.OpenOrder{} for ID, o := range openOrdersResponse.Open { // kraken uses different symbols when fetching open orders! - pair, e := model.TradingPairFromString(3, k.assetConverterOpenOrders, o.Description.AssetPair) + pair, e := model.TradingPairFromString2(3, assetConverters, o.Description.AssetPair) if e != nil { - return nil, e + return nil, fmt.Errorf("error parsing trading pair '%s' in krakenExchange#GetOpenOrders: %s", o.Description.AssetPair, e) } if _, ok := pairsMap[*pair]; !ok { @@ -376,7 +377,7 @@ func (k *krakenExchange) getTradeHistory(tradingPair model.TradingPair, maybeCur var pair *model.TradingPair pair, e = model.TradingPairFromString(4, k.assetConverter, _pair) if e != nil { - return nil, e + return nil, fmt.Errorf("error parsing trading pair '%s' in krakenExchange#getTradeHistory: %s", _pair, e) } orderConstraints := k.GetOrderConstraints(pair) // for now use the max precision between price and volume for fee and cost