Skip to content

Commit

Permalink
add condition chainid and add fill-price-time-interval-flag
Browse files Browse the repository at this point in the history
  • Loading branch information
iostream1308 committed Dec 19, 2024
1 parent 8afe65b commit 3e37e5e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion v2/cmd/price_filler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func run(c *cli.Context) error {
l.Errorw("Error while init price filler")
return err
}
priceFiller.Run()
priceFiller.Run(c.Int(libapp.FillPriceTimeIntervalFlag.Name))
return nil
}

Expand Down
7 changes: 7 additions & 0 deletions v2/pkg/app/price_filler.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@ var BinanceSecretKeyFlag = cli.StringFlag{
Name: "binance-secret-key",
EnvVar: "BINANCE_SECRET_KEY",
}

var MarkToMarketURLFlag = cli.StringFlag{
Name: "mark-to-market-url",
EnvVar: "MARK_TO_MARKET_URL",
}

var FillPriceTimeIntervalFlag = cli.StringFlag{
Name: "fill-price-time-interval",
EnvVar: "FILL_PRICE_TIME_INTERVAL",
}

func PriceFillerFlags() []cli.Flag {
return []cli.Flag{
BinanceAPIKeyFlag,
BinanceSecretKeyFlag,
MarkToMarketURLFlag,
FillPriceTimeIntervalFlag,
}
}
8 changes: 4 additions & 4 deletions v2/pkg/price_filler/price_filler.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ func NewPriceFiller(l *zap.SugaredLogger,
return p, nil
}

func (p *PriceFiller) Run() {
func (p *PriceFiller) Run(fillPriceInterval int) {
go p.runUpdateAllCoinInfoRoutine()
p.runBackFillTradelogPriceRoutine()
p.runBackFillTradelogPriceRoutine(fillPriceInterval)
}

func (p *PriceFiller) getPrice(token string, timestamp int64) (float64, error) {
Expand Down Expand Up @@ -141,8 +141,8 @@ func (p *PriceFiller) runUpdateAllCoinInfoRoutine() {
}
}

func (p *PriceFiller) runBackFillTradelogPriceRoutine() {
ticker := time.NewTicker(backfillTradeLogsPriceInterval)
func (p *PriceFiller) runBackFillTradelogPriceRoutine(fillPriceInterval int) {
ticker := time.NewTicker(time.Duration(fillPriceInterval) * time.Minute)
defer ticker.Stop()

for ; ; <-ticker.C {
Expand Down
11 changes: 6 additions & 5 deletions v2/pkg/storage/promotees/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,21 @@ func (s *Storage) InsertPromoterName(promotees []Promotee) error {

func (s *Storage) CheckPromoteeExist(promotee string) (bool, error) {
builder := squirrel.StatementBuilder.PlaceholderFormat(squirrel.Dollar).
Select(promoteesColumns()...).
Select("COUNT(*)").
From(promoteesTable).
Where(squirrel.Eq{"promotee": promotee})
Where(squirrel.Eq{"promotee": promotee}).
Where(squirrel.Eq{"chain_id": "1"})

q, p, err := builder.ToSql()
if err != nil {
return false, err
}

var promotees []Promotee
if err := s.db.Select(&promotees, q, p...); err != nil {
var count int
if err := s.db.Get(&count, q, p...); err != nil {
return false, err
}
if len(promotees) >= 1 {
if count >= 1 {
return true, nil
}
return false, nil
Expand Down
2 changes: 1 addition & 1 deletion v2/pkg/storage/promotees/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ func TestInsert(t *testing.T) {
}

}
t.Log(s.CheckPromoteeExist("0xd1742b3c4fbb096990c8950fa635aec75b30781a"))
t.Log(s.CheckPromoteeExist("0x0b8a49d816cc709b6eadb09498030ae3416b66dc"))
}

0 comments on commit 3e37e5e

Please sign in to comment.