Skip to content

Commit

Permalink
add usd-based volume filter to tbs on testspace.
Browse files Browse the repository at this point in the history
  • Loading branch information
jppade committed Jul 25, 2023
1 parent 17c411f commit fbaef56
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cmd/services/tradesBlockService/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/diadata-org/diadata/services/tradesBlockService
go 1.17

require (
github.com/diadata-org/diadata v1.4.312-rc-2
github.com/diadata-org/diadata v1.4.315-rc-1
github.com/segmentio/kafka-go v0.4.35
github.com/sirupsen/logrus v1.8.1
)
Expand Down
28 changes: 17 additions & 11 deletions internal/pkg/tradesBlockService/tradesBlockService.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ func init() {
log.Error("Parse TRADE_VOLUME_THRESHOLD_EXPONENT: ", err)
}
tradeVolumeThreshold = math.Pow(10, -tradeVolumeThresholdExponent)
tradeVolumeThresholdUSDExponent, err := strconv.ParseFloat(utils.Getenv("TRADE_VOLUME_THRESHOLD_USD_EXPONENT", ""), 64)
if err != nil {
log.Error("Parse TRADE_VOLUME_THRESHOLD_USD_EXPONENT: ", err)
}
tradeVolumeThresholdUSD = math.Pow(10, -tradeVolumeThresholdUSDExponent)
}

var (
Expand All @@ -73,16 +78,17 @@ var (
TUSD.Identifier(): "",
}

tol = float64(0.04)
log *logrus.Logger
batchTimeSeconds int
tradeVolumeThreshold float64
volumeUpdateSeconds = 60 * 10
volumeThreshold float64
blueChipThreshold float64
smallX float64
normalX float64
checkTradesDuplicate = make(map[string]struct{})
tol = float64(0.04)
log *logrus.Logger
batchTimeSeconds int
tradeVolumeThreshold float64
tradeVolumeThresholdUSD float64
volumeUpdateSeconds = 60 * 10
volumeThreshold float64
blueChipThreshold float64
smallX float64
normalX float64
checkTradesDuplicate = make(map[string]struct{})
)

type TradesBlockService struct {
Expand Down Expand Up @@ -302,7 +308,7 @@ func (s *TradesBlockService) process(t dia.Trade) {
} else {
if price > 0.0 {
t.EstimatedUSDPrice = t.Price * price
if t.EstimatedUSDPrice > 0 {
if t.USDVolume() > tradeVolumeThresholdUSD {
verifiedTrade = true
}
}
Expand Down
5 changes: 5 additions & 0 deletions pkg/dia/Messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"database/sql/driver"
"encoding/json"
"errors"
"math"
"math/big"
"time"

Expand Down Expand Up @@ -474,6 +475,10 @@ type Trade struct {
VerifiedPair bool `json:"VerifiedPair"` // will be filled by the pairDiscoveryService
}

func (t *Trade) USDVolume() float64 {
return t.EstimatedUSDPrice * math.Abs(t.Volume)
}

// SynthAssetSupply is a container for data on synthetic assets such as aUSDC.
// https://etherscan.io/address/0xbcca60bb61934080951369a648fb03df4f96263c
type SynthAssetSupply struct {
Expand Down

0 comments on commit fbaef56

Please sign in to comment.