Skip to content

Commit

Permalink
add sorting to feed info endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
jppade committed May 13, 2022
1 parent 6571387 commit f02b4aa
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion cmd/http/restServer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.14

require (
github.com/appleboy/gin-jwt/v2 v2.6.4
github.com/diadata-org/diadata v1.4.1-rc-150
github.com/diadata-org/diadata v1.4.1-rc-166
github.com/gin-contrib/cache v1.1.0
github.com/gin-gonic/contrib v0.0.0-20201101042839-6a891bf89f19
github.com/gin-gonic/gin v1.7.2
Expand Down
2 changes: 1 addition & 1 deletion cmd/services/feedInfoService/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/diadata-org/diadata/cmd/services/feedInfoService
go 1.14

require (
github.com/diadata-org/diadata v1.4.1-rc-165
github.com/diadata-org/diadata v1.4.1-rc-166
github.com/sirupsen/logrus v1.8.1
)
7 changes: 6 additions & 1 deletion cmd/services/feedInfoService/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func main() {

func updateStatsPerAsset(asset dia.Asset, tFinal time.Time, numRanges int, datastore *models.DB, relDB *models.RelDB) {

log.Info("start processing data for %s -- %s....", asset.Blockchain, asset.Address)
log.Infof("start processing data for %s -- %s....", asset.Blockchain, asset.Address)

tInit := tFinal.Add(-time.Duration(LOOKBACK_SECONDS * time.Second))
// Make time ranges for batching the trades getter.
Expand Down Expand Up @@ -218,6 +218,11 @@ func computePairStats(
basetoken, err := getBasetoken(basetokenMap, trade.BaseToken, relDB)
if err != nil {
log.Errorf("get basetoken %v: %v", trade.BaseToken, err)
basetoken.Address = trade.BaseToken.Address
basetoken.Blockchain = trade.BaseToken.Blockchain
basetoken.Symbol = trade.BaseToken.Symbol
basetoken.Name = trade.BaseToken.Name
basetoken.Decimals = trade.BaseToken.Decimals
}
pair := dia.Pair{
QuoteToken: quotetoken,
Expand Down
4 changes: 3 additions & 1 deletion pkg/http/restServer/diaApi/diaApi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2044,9 +2044,9 @@ func (env *Env) GetFeedStats(c *gin.Context) {
Timestamp time.Time
TotalVolume float64
Price float64
TradesDistribution localDistType
ExchangeVolumes []dia.ExchangeVolume
PairVolumes []dia.PairVolume
TradesDistribution localDistType
}

var retVal []localReturn
Expand All @@ -2055,11 +2055,13 @@ func (env *Env) GetFeedStats(c *gin.Context) {
for i := range exchVolumes {
var l localReturn
var price float64
sort.Slice(exchVolumes[i].Volumes, func(m, n int) bool { return exchVolumes[i].Volumes[m].Volume > exchVolumes[i].Volumes[n].Volume })
l.ExchangeVolumes = exchVolumes[i].Volumes
// Compute total volume.
for _, vol := range l.ExchangeVolumes {
l.TotalVolume += vol.Volume
}
sort.Slice(pairVolumes[i].Volumes, func(m, n int) bool { return pairVolumes[i].Volumes[m].Volume > pairVolumes[i].Volumes[n].Volume })
l.PairVolumes = pairVolumes[i].Volumes
l.Timestamp = exchVolumes[i].Timestamp
// Get Price.
Expand Down

0 comments on commit f02b4aa

Please sign in to comment.