Skip to content

Commit

Permalink
minor improvements of getfeed graphql endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
jppade committed Aug 3, 2023
1 parent 0fde4f0 commit eaf16f6
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/http/graphqlServer/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module graphqlServer
go 1.17

require (
github.com/diadata-org/diadata v1.4.316
github.com/diadata-org/diadata v1.4.320
github.com/graph-gophers/graphql-go v1.1.0
github.com/sirupsen/logrus v1.8.1
)
Expand Down
2 changes: 0 additions & 2 deletions cmd/http/graphqlServer/schema/quotation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ type FilterPointExtended {
Symbol: String
Time: Time
Value: Float
Address: String
Blockchain: String
Pools: [String!]
Pairs: [String!]
TradesCount: Int
Expand Down
20 changes: 20 additions & 0 deletions pkg/dia/Messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"math"
"math/big"
"strings"
"time"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -480,6 +481,25 @@ func (t *Trade) VolumeUSD() float64 {
return t.EstimatedUSDPrice * math.Abs(t.Volume)
}

// NormalizeSymbols normalizes @t.Symbol and @t.Pair in a trade struct to
// upper case letters like so A@pairSplitterB. For instance, btcusdt will be BTC-USDT.
func (t *Trade) NormalizeSymbols(upperCase bool, pairSplitter string) error {
symbols, err := GetPairSymbols(ExchangePair{Exchange: t.Source, ForeignName: t.Pair, Symbol: t.Symbol})
if err != nil {
return err
}
if len(symbols) == 2 {
if upperCase {
t.Pair = strings.ToUpper(symbols[0] + pairSplitter + symbols[1])
t.Symbol = strings.ToUpper(symbols[0])
} else {
t.Pair = strings.ToLower(symbols[0] + pairSplitter + symbols[1])
t.Symbol = strings.ToLower(symbols[0])
}
}
return nil
}

// SynthAssetSupply is a container for data on synthetic assets such as aUSDC.
// https://etherscan.io/address/0xbcca60bb61934080951369a648fb03df4f96263c
type SynthAssetSupply struct {
Expand Down
8 changes: 8 additions & 0 deletions pkg/dia/helpers/queryHelper/blockgenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ var (
EXCHANGES = scrapers.Exchanges
)

const (
PAIR_SPLITTER = "-"
)

type Block struct {
Trades []dia.Trade
TimeStamp int64
Expand All @@ -27,6 +31,10 @@ func (b *Block) GetBlockSources() (pairs []dia.ExchangePair, pools []dia.Pool) {

for _, t := range b.Trades {
if EXCHANGES[t.Source].Centralized {
err := t.NormalizeSymbols(true, PAIR_SPLITTER)
if err != nil {
log.Errorf("NormalizeSymbols on pair %s and exchange %s: %v", t.Pair, t.Source, err)
}
if _, ok := pairsCheckMap[t.Source+t.Pair]; !ok {
pairs = append(pairs, dia.ExchangePair{Exchange: t.Source, ForeignName: t.Pair})
pairsCheckMap[t.Source+t.Pair] = struct{}{}
Expand Down
8 changes: 0 additions & 8 deletions pkg/graphql/resolver/feedresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,6 @@ func (qr *FilterPointExtendedResolver) Value(ctx context.Context) (*float64, err
return &qr.q.FilterPoint.Value, nil
}

func (qr *FilterPointExtendedResolver) Address(ctx context.Context) (*string, error) {
return &qr.q.FilterPoint.Asset.Address, nil
}

func (qr *FilterPointExtendedResolver) Blockchain(ctx context.Context) (*string, error) {
return &qr.q.FilterPoint.Asset.Blockchain, nil
}

func (qr *FilterPointExtendedResolver) Pools(ctx context.Context) (*[]string, error) {
pools := []string{}
for _, p := range qr.q.Pools {
Expand Down

0 comments on commit eaf16f6

Please sign in to comment.