Skip to content

Commit

Permalink
retrieve exchange rate immediately with Kraken/CoinGecko sources so w…
Browse files Browse the repository at this point in the history
…e don't have to wait for refresh delay to happen to start getting prices
  • Loading branch information
chris124567 committed Jan 15, 2025
1 parent 1b2248c commit 1fc8b56
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
3 changes: 3 additions & 0 deletions exchangerates/coingecko.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ func (c *coinGecko) Start(ctx context.Context) {
ticker := time.NewTicker(c.refresh)
defer ticker.Stop()

c.mu.Lock()
c.rate, c.err = c.client.ticker(ctx, c.currency, c.token)
c.mu.Unlock()
for {
select {
case <-ticker.C:
Expand Down
3 changes: 3 additions & 0 deletions exchangerates/kraken.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,9 @@ func (k *kraken) Start(ctx context.Context) {
ticker := time.NewTicker(k.refresh)
defer ticker.Stop()

k.mu.Lock()
k.rate, k.err = k.client.ticker(ctx, k.pair)
k.mu.Unlock()
for {
select {
case <-ticker.C:
Expand Down

0 comments on commit 1fc8b56

Please sign in to comment.