Skip to content

Commit

Permalink
fix: refetch fiat balance after purchase
Browse files Browse the repository at this point in the history
  • Loading branch information
Primexz committed Jul 31, 2024
1 parent 0f05e83 commit f21245c
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions bot/bot.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,7 @@ func (b *Bot) StartBot() {
}

func (b *Bot) run() {
if fiatAmnt, err := b.krakenApi.GetFiatBalance(); err == nil {
b.fiatAmount = fiatAmnt
} else {
b.log.Error("Error getting fiat balance: ", err)
if err := b.updateFiatBalance(); err != nil {
return
}

Expand Down Expand Up @@ -87,6 +84,11 @@ func (b *Bot) run() {
b.log.Info("Placing bitcoin purchase order. ₿")

b.krakenApi.BuyBtc()

if err := b.updateFiatBalance(); err != nil {
return
}

b.calculateTimeOfNextOrder()
}

Expand All @@ -98,6 +100,16 @@ func (b *Bot) run() {
}).Info("Next order in")
}

func (b *Bot) updateFiatBalance() error {
if fiatAmnt, err := b.krakenApi.GetFiatBalance(); err == nil {
b.fiatAmount = fiatAmnt
return nil
} else {
b.log.Error("Error getting fiat balance: ", err)
return err
}
}

func (b *Bot) updateMetrics() {
metrics.Metrics.NextOrder = b.timeOfNextOrder.Unix()
}

0 comments on commit f21245c

Please sign in to comment.