Skip to content

# feat: multi-source price averaging (Binance + CoinGecko + Kraken) instead of single-source fallback #1

Description

@Vagalam88

Current behavior

SatConverter fetches the BTC price exclusively from CoinGecko, with no fallback if the request fails. If CoinGecko is down, rate-limiting, or slow, the app falls back to the last cached price immediately.

Proposed change

Replace the single CoinGecko fetch with three parallel requests (Binance, CoinGecko, Kraken) and compute a simple average of all sources that successfully respond.

const results = await Promise.allSettled([
  fetchBinance(),   // BTCEUR + BTCUSDT
  fetchCoinGecko(), // existing endpoint, unchanged
  fetchKraken(),    // XBTEUR + XBTUSD
]);
const valid = results.filter(r => r.status === 'fulfilled').map(r => r.value);
const avgEur = valid.reduce((s, v) => s + v.eur, 0) / valid.length;

Why this is better than a fallback chain

A fallback chain (A → B → C) means you always display one source's price — whichever happened to respond first. That source might have a stale feed, a brief data anomaly, or a slightly wider spread.

Averaging across sources gives a consensus price that is:

  • More resistant to a single API returning a bad tick
  • Still functional if 1 or 2 sources are down (degrades gracefully)
  • Transparent — the status bar can show which sources contributed (e.g. live · avg Binance+CoinGecko+Kraken)

What doesn't change

  • The sparkline still comes from CoinGecko (only source providing 24h chart data on a free, keyless endpoint)
  • The 24h change still comes from CoinGecko (usd_24h_change)
  • Offline fallback to localStorage cache is unchanged
  • No API keys required on any of the three sources
  • No new Rust/backend code — purely a main.js change

CSP impact

tauri.conf.json would need two additional allowed origins:

connect-src 'self' https://api.coingecko.com https://api.binance.com https://api.kraken.com

Open questions for maintainers

  • Is the added complexity (3 fetches vs 1) worth it for a utility tool?
  • Any preference on which sources to include or exclude?
  • Should the source label in the status bar be opt-in or always shown?

Happy to submit a PR with a full implementation if the direction sounds good.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions