Skip to content

Commit

Permalink
chore(purchase_watcher): only query latest purchases when we have > 5…
Browse files Browse the repository at this point in the history
…0 in db
  • Loading branch information
Primexz committed Jun 25, 2024
1 parent ceb3106 commit 762c6ed
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/Primexz/Kraken-InvestMetrics
go 1.22

require (
github.com/Primexz/go_kraken v0.1.7
github.com/Primexz/go_kraken v0.1.8
github.com/btcsuite/btcd v0.24.0
github.com/btcsuite/btcd/btcutil v1.1.5
github.com/jackc/pgx/v5 v5.5.5
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/Primexz/go_kraken v0.1.6 h1:MsiwfrAyDZemWh8AWEryPRrrDmp/4HoTwnBBbgJMV
github.com/Primexz/go_kraken v0.1.6/go.mod h1:T3DC9V+nbaIf3q2KCvCrf6RA81N1HEptRZg5PW4/6Gg=
github.com/Primexz/go_kraken v0.1.7 h1:bKe6fJ1hPGChuJOOGzNp7Qqhn1Fe9WKnb2ViQYumPUU=
github.com/Primexz/go_kraken v0.1.7/go.mod h1:T3DC9V+nbaIf3q2KCvCrf6RA81N1HEptRZg5PW4/6Gg=
github.com/Primexz/go_kraken v0.1.8 h1:If7YktK4HblVheFHYJspiYcOu2kaT6Jh9w2knlx8A7w=
github.com/Primexz/go_kraken v0.1.8/go.mod h1:T3DC9V+nbaIf3q2KCvCrf6RA81N1HEptRZg5PW4/6Gg=
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
Expand Down
6 changes: 3 additions & 3 deletions modules/kraken/kraken.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (k *KrakenApi) GetPendingEuroOnKraken() (decimal.Decimal, error) {
}

func (k *KrakenApi) GetCachePayedToKraken() (float64, error) {
ledgerInfo, err := k.api.GetLedgersInfo("", 0, 0, "ZEUR")
ledgerInfo, err := k.api.GetLedgersInfo("", 0, 0, false, "ZEUR")
if err != nil {
return 0, err
}
Expand All @@ -62,8 +62,8 @@ func (k *KrakenApi) GetCachePayedToKraken() (float64, error) {
return totalCachePayedToKraken, nil
}

func (k *KrakenApi) GetAllBtcOrders() ([]rest.Ledger, error) {
ledgers, err := k.api.GetLedgersInfo("", 0, 0, "XXBT")
func (k *KrakenApi) GetAllBtcOrders(latestOnly bool) ([]rest.Ledger, error) {
ledgers, err := k.api.GetLedgersInfo("", 0, 0, latestOnly, "XXBT")
if err != nil {
return nil, err
}
Expand Down
13 changes: 12 additions & 1 deletion updateWatchers/watchers/purchaseWatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func (pw *PurchaseWatcher) StartRoutine() {
func (pw *PurchaseWatcher) UpdateData() {
pw.log.Info("Updating Purchase Watcher")

purchases, err := pw.api.GetAllBtcOrders()
//if the row count is greater than 50, then we only want to get the last 50 purchases
purchases, err := pw.api.GetAllBtcOrders(pw.getPurchasesRowCount() > 50)
if err != nil {
pw.log.Error(err)
return
Expand All @@ -49,3 +50,13 @@ func (pw *PurchaseWatcher) UpdateData() {
}
}
}

func (pw *PurchaseWatcher) getPurchasesRowCount() int {
var count int
err := timescale.ConnectionPool.QueryRow(timescale.Context, "SELECT COUNT(*) FROM purchases").Scan(&count)
if err != nil {
pw.log.Error("failed to get row count", err)
}

return count
}

0 comments on commit 762c6ed

Please sign in to comment.