Skip to content

Commit

Permalink
add wait time to velar liquidity scraper.
Browse files Browse the repository at this point in the history
  • Loading branch information
jppade committed Jan 10, 2025
1 parent 586e3eb commit 48d7472
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 20 deletions.
2 changes: 1 addition & 1 deletion cmd/liquidityScraper/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/diadata-org/diadata/liquidityScraper
go 1.22

require (
github.com/diadata-org/diadata v1.4.560
github.com/diadata-org/diadata v1.4.565
github.com/sirupsen/logrus v1.9.3
)

Expand Down
47 changes: 28 additions & 19 deletions pkg/dia/scraper/liquidity-scrapers/VelarScraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/hex"
"math/big"
"strconv"
"strings"
"time"

Expand All @@ -16,16 +17,17 @@ import (
)

type VelarLiquidityScraper struct {
logger *logrus.Entry
api *stackshelper.StacksClient
velarClient *velarhelper.VelarClient
poolChannel chan dia.Pool
doneChannel chan bool
blockchain string
exchangeName string
relDB *models.RelDB
datastore *models.DB
handlerType string
logger *logrus.Entry
api *stackshelper.StacksClient
velarClient *velarhelper.VelarClient
poolChannel chan dia.Pool
doneChannel chan bool
blockchain string
exchangeName string
sleepTimeMilliseconds int
relDB *models.RelDB
datastore *models.DB
handlerType string
}

// NewVelarLiquidityScraper returns a new VelarLiquidityScraper initialized with default values.
Expand Down Expand Up @@ -54,16 +56,21 @@ func NewVelarLiquidityScraper(exchange dia.Exchange, relDB *models.RelDB, datast
isDebug,
)

sleepTime, err := strconv.Atoi(utils.Getenv("SLEEP_TIME_MILLISECONDS", "1000"))
if err != nil {
log.Error("parse SLEEP_TIME_MILLISECONDS: ", err)
}
s := &VelarLiquidityScraper{
poolChannel: make(chan dia.Pool),
doneChannel: make(chan bool),
exchangeName: exchange.Name,
blockchain: exchange.BlockChain.Name,
api: stacksClient,
velarClient: velarClient,
relDB: relDB,
datastore: datastore,
handlerType: "liquidity",
poolChannel: make(chan dia.Pool),
doneChannel: make(chan bool),
exchangeName: exchange.Name,
blockchain: exchange.BlockChain.Name,
sleepTimeMilliseconds: sleepTime,
api: stacksClient,
velarClient: velarClient,
relDB: relDB,
datastore: datastore,
handlerType: "liquidity",
}

s.logger = logrus.
Expand All @@ -85,6 +92,8 @@ func (s *VelarLiquidityScraper) fetchPools() {
}

for _, t := range tickers {
time.Sleep(time.Duration(s.sleepTimeMilliseconds) * time.Millisecond)

balances, err := s.fetchPoolBalances(t.PoolID)
if err != nil {
s.logger.WithError(err).Error("failed to fetch velar pool balances")
Expand Down

0 comments on commit 48d7472

Please sign in to comment.