diff --git a/v2/pkg/price_filler/price_filler.go b/v2/pkg/price_filler/price_filler.go index 1eeca00..f7ce8bf 100644 --- a/v2/pkg/price_filler/price_filler.go +++ b/v2/pkg/price_filler/price_filler.go @@ -3,6 +3,8 @@ package pricefiller import ( "context" "errors" + "fmt" + "net" "strings" "sync" "time" @@ -170,25 +172,21 @@ func (p *PriceFiller) runBackFillTradelogPriceRoutine() { func (p *PriceFiller) fullFillTradeLog(tradeLog storageTypes.TradeLog) (storageTypes.TradeLog, error) { makerPrice, makerUsdAmount, err := p.getPriceAndAmountUsd(strings.ToLower(tradeLog.MakerToken), tradeLog.MakerTokenAmount, int64(tradeLog.Timestamp)) - if err != nil { - if err.Error() != invalidSymbolErrString { - p.l.Errorw("Failed to getPriceAndAmountUsd for maker", "err", err) - return tradeLog, err - } + if isConnectionRefusedError(err) { + p.l.Errorw("Failed to getPriceAndAmountUsd for maker", "err", err) + return tradeLog, err } - tradeLog.MakerTokenPrice = &makerPrice - tradeLog.MakerUsdAmount = &makerUsdAmount - takerPrice, takerUsdAmount, err := p.getPriceAndAmountUsd(strings.ToLower(tradeLog.TakerToken), tradeLog.TakerTokenAmount, int64(tradeLog.Timestamp)) - if err != nil { - if err.Error() != invalidSymbolErrString { - p.l.Errorw("Failed to getPriceAndAmountUsd for taker", "err", err) - return tradeLog, err - } + if isConnectionRefusedError(err) { + p.l.Errorw("Failed to getPriceAndAmountUsd for taker", "err", err) + return tradeLog, err } + tradeLog.MakerTokenPrice = &makerPrice + tradeLog.MakerUsdAmount = &makerUsdAmount + tradeLog.TakerTokenPrice = &takerPrice tradeLog.TakerUsdAmount = &takerUsdAmount @@ -225,11 +223,9 @@ func (p *PriceFiller) getSumAmountUsd(address, rawAmt []string, at int64) (float var sumAmount, price float64 for i := range address { pr, usdAmount, err := p.getPriceAndAmountUsd(address[i], rawAmt[i], at) - if err != nil { - if err.Error() != invalidSymbolErrString { - p.l.Errorw("Failed to getPriceAndAmountUsd for address", "err", err) - return 0, 0, err - } + if isConnectionRefusedError(err) { + p.l.Errorw("Failed to getPriceAndAmountUsd for address", "err", err) + return 0, 0, err } sumAmount += usdAmount price = pr @@ -248,11 +244,7 @@ func (p *PriceFiller) getPriceAndAmountUsd(address, rawAmt string, at int64) (fl if coin.Decimals == 0 { decimals, symbol, err := p.getDecimalsAndSymbol(address) if err != nil { - if errors.Is(err, ErrWeirdTokenCatalogResp) { - return 0, 0, nil - } - p.l.Errorw("Failed to getDecimals", "err", err, "address", address) - return 0, 0, err + return 0, 0, fmt.Errorf("failed to get decimals: %w", err) } coin.Decimals = decimals coin.Coin = symbol @@ -266,8 +258,7 @@ func (p *PriceFiller) getPriceAndAmountUsd(address, rawAmt string, at int64) (fl } price, err := p.getPrice(address, at) if err != nil { - p.l.Errorw("Failed to getPrice", "err", err, "coin", coin.Coin, "at", at) - return 0, 0, err + return 0, 0, fmt.Errorf("failed to get price mtm: %w", err) } return price, calculateAmountUsd(rawAmt, coin.Decimals, price), nil @@ -337,3 +328,16 @@ func (p *PriceFiller) insertTokens() error { } return nil } + +func isConnectionRefusedError(err error) bool { + if err == nil { + return false + } + var netErr *net.OpError + if errors.As(err, &netErr) { + if strings.Contains(netErr.Err.Error(), "connection refused") { + return true + } + } + return false +}