Skip to content

Commit

Permalink
feat: price-feeder: add missing candles warning (#625) (#626)
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Mar 8, 2022
1 parent 16236d5 commit 14eb8a3
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions price-feeder/oracle/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,25 +234,6 @@ func (o *Oracle) SetPrices(ctx context.Context, acceptList oracletypes.DenomList
o.logger.Debug().Err(err).Msg("failed to get ticker prices from provider")
}

reportedRates := make(map[string]struct{})
for _, providers := range providerPrices {
for base := range providers {
if _, ok := reportedRates[base]; !ok {
reportedRates[base] = struct{}{}
}
}
}

// warn the user of any missing prices
if len(reportedRates) != len(requiredRates) {
return fmt.Errorf("unable to get prices for all exchange rates")
}
for base := range requiredRates {
if _, ok := reportedRates[base]; !ok {
return fmt.Errorf("reported rates were not equal to required rates")
}
}

filteredCandles, err := o.filterCandleDeviations(providerCandles)
if err != nil {
return err
Expand All @@ -277,8 +258,46 @@ func (o *Oracle) SetPrices(ctx context.Context, acceptList oracletypes.DenomList
return err
}

// warn the user of any missing prices
reportedPrices := make(map[string]struct{})
for _, providers := range filteredProviderPrices {
for base := range providers {
if _, ok := reportedPrices[base]; !ok {
reportedPrices[base] = struct{}{}
}
}
}

if len(reportedPrices) != len(requiredRates) {
return fmt.Errorf("unable to get prices for all exchange prices")
}
for base := range requiredRates {
if _, ok := reportedPrices[base]; !ok {
return fmt.Errorf("reported prices were not equal to required rates")
}
}

o.prices = vwapPrices
} else {
// warn the user of any missing candles
reportedCandles := make(map[string]struct{})
for _, providers := range filteredCandles {
for base := range providers {
if _, ok := reportedCandles[base]; !ok {
reportedCandles[base] = struct{}{}
}
}
}

if len(reportedCandles) != len(requiredRates) {
return fmt.Errorf("unable to get prices for all exchange candles")
}
for base := range requiredRates {
if _, ok := reportedCandles[base]; !ok {
return fmt.Errorf("reported candles were not equal to required rates")
}
}

o.prices = tvwapPrices
}

Expand Down

0 comments on commit 14eb8a3

Please sign in to comment.