Skip to content

Commit

Permalink
Merge pull request #54 from KyberNetwork/Fixbub/ToLowerCase_for_addre…
Browse files Browse the repository at this point in the history
…ss_and_logger

Fixbub/ToLowerCase_for_address_and_logger
  • Loading branch information
Haiss2 authored Jul 10, 2024
2 parents 2ec9905 + cdd944b commit a055ce1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/tradelogs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func run(c *cli.Context) error {
}

binanceClient := binance.NewClient(c.String(pricefiller.BinanceAPIKeyFlag.Name), c.String(pricefiller.BinanceSecretKeyFlag.Name))
priceFiller, err := pricefiller.NewPriceFiller(binanceClient, s)
priceFiller, err := pricefiller.NewPriceFiller(l, binanceClient, s)
if err != nil {
l.Errorw("Error while init price filler")
return err
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
UPDATE tradelogs SET state='new' WHERE state='processed';
11 changes: 7 additions & 4 deletions pkg/pricefiller/price_fillter.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,10 @@ type PriceFiller struct {
mappedCoinInfo map[string]CoinInfo // address - coinInfo
}

func NewPriceFiller(binanceClient *binance.Client, s *storage.Storage) (*PriceFiller, error) {
func NewPriceFiller(l *zap.SugaredLogger, binanceClient *binance.Client,
s *storage.Storage) (*PriceFiller, error) {
p := &PriceFiller{
l: zap.S(),
l: l,
s: s,
ksClient: NewKsClient(),
binanceClient: binanceClient,
Expand Down Expand Up @@ -141,7 +142,8 @@ func (p *PriceFiller) runBackFillTradelogPriceRoutine() {
}

func (p *PriceFiller) fullFillTradeLog(tradeLog storage.TradeLog) (storage.TradeLog, error) {
makerPrice, makerUsdAmount, err := p.getPriceAndAmountUsd(tradeLog.MakerToken, tradeLog.MakerTokenAmount, int64(tradeLog.Timestamp))
makerPrice, makerUsdAmount, err := p.getPriceAndAmountUsd(strings.ToLower(tradeLog.MakerToken),
tradeLog.MakerTokenAmount, int64(tradeLog.Timestamp))
if err != nil {
p.l.Errorw("Failed to getPriceAndAmountUsd for maker", "err", err)
return tradeLog, err
Expand All @@ -150,7 +152,8 @@ func (p *PriceFiller) fullFillTradeLog(tradeLog storage.TradeLog) (storage.Trade
tradeLog.MakerTokenPrice = makerPrice
tradeLog.MakerUsdAmount = makerUsdAmount

takerPrice, takerUsdAmount, err := p.getPriceAndAmountUsd(tradeLog.TakerToken, tradeLog.TakerTokenAmount, int64(tradeLog.Timestamp))
takerPrice, takerUsdAmount, err := p.getPriceAndAmountUsd(strings.ToLower(tradeLog.TakerToken),
tradeLog.TakerTokenAmount, int64(tradeLog.Timestamp))
if err != nil {
p.l.Errorw("Failed to getPriceAndAmountUsd for taker", "err", err)
return tradeLog, err
Expand Down
3 changes: 2 additions & 1 deletion pkg/pricefiller/price_fillter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ import (
"github.com/KyberNetwork/go-binance/v2"
"github.com/KyberNetwork/tradelogs/pkg/storage"
"github.com/test-go/testify/require"
"go.uber.org/zap"
)

// go test -v -timeout 30s -run ^TestFillPrice$ github.com/KyberNetwork/tradelogs/pkg/pricefiller
func TestFillPrice(t *testing.T) {
t.Skip("Need to add Binance credentials")
bClient := binance.NewClient("", "")
filler, err := NewPriceFiller(bClient, nil)
filler, err := NewPriceFiller(zap.S(), bClient, nil)
if err != nil {
require.NoError(t, err)
}
Expand Down

0 comments on commit a055ce1

Please sign in to comment.