Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix handle error when get price mtm #107

Merged
merged 4 commits into from
Dec 12, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 15 additions & 22 deletions v2/pkg/price_filler/price_filler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pricefiller
import (
"context"
"errors"
"fmt"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -170,25 +171,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 err != nil && strings.Contains(err.Error(), "connection refuse") {
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 err != nil && strings.Contains(err.Error(), "connection refuse") {
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

Expand Down Expand Up @@ -225,11 +222,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 err != nil && strings.Contains(err.Error(), "connection refuse") {
p.l.Errorw("Failed to getPriceAndAmountUsd for address", "err", err)
return 0, 0, err
iostream1308 marked this conversation as resolved.
Show resolved Hide resolved
}
sumAmount += usdAmount
price = pr
Expand All @@ -251,8 +246,7 @@ func (p *PriceFiller) getPriceAndAmountUsd(address, rawAmt string, at int64) (fl
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)
iostream1308 marked this conversation as resolved.
Show resolved Hide resolved
}
coin.Decimals = decimals
coin.Coin = symbol
Expand All @@ -266,8 +260,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
Expand Down
Loading