Skip to content

Conversation

@Okazakee
Copy link
Contributor

@Okazakee Okazakee commented Dec 9, 2025

  • Reduce data sources from 9 to 4 (Kraken, CoinGecko, Yadio, Exir)
  • Add automatic fallback system (Kraken/Yadio → CoinGecko)
  • Add 17 new currencies (VND, PKR, BDT, MMK, EGP, MAD, DZD, JOD, PEN, CRC, DOP, GTQ, BOB, BGN, GEL, KZT, BYN)
  • Migrate 26 currencies to appropriate sources
  • Remove unused Source variants and error types

Closes #129

@Okazakee Okazakee requested a review from Copilot December 9, 2025 11:11
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR consolidates the MarketAPI implementation by reducing the number of data sources from 9 to 4 (Kraken, CoinGecko, Yadio, Exir) and introduces an automatic fallback system. The changes migrate 26 existing currencies to appropriate sources, add 17 new currency entries, and remove unused code for deprecated sources.

Key Changes:

  • Implemented automatic fallback mechanism (Kraken/Yadio → CoinGecko) to improve data retrieval reliability
  • Removed 5 unused data sources and their associated error types
  • Added 17 new currency configurations to expand geographic coverage

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
rates/src/lib.rs Removed 5 source variants and error types, implemented fallback logic with new fallback() method, refactored price fetching to support fallback chain
assets/fiatUnits.json Migrated 26 currencies from deprecated sources to Kraken/CoinGecko, added 17 new currency entries with CoinGecko as source

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


match Self::parse_price_json(&text, source, key) {
Ok(parsed) => Ok(Some(parsed)),
Err(_) => Ok(None), // Parsing failed, treat as source failure for fallback
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error from parsing is being silently discarded. Consider logging the parse error before returning None to aid debugging when fallback occurs.

Suggested change
Err(_) => Ok(None), // Parsing failed, treat as source failure for fallback
Err(e) => {
log::warn!(
"Failed to parse price JSON from source {} with key {}: {}",
source,
key,
e
);
Ok(None) // Parsing failed, treat as source failure for fallback
}

Copilot uses AI. Check for mistakes.
Comment on lines +176 to +180
async fn fetch_price_with_source(
&self,
source: &Source,
key: &str,
) -> Result<Option<String>, RatesError> {
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This new function lacks documentation. Add a doc comment explaining its purpose, parameters, return value, and the None return case for parse failures.

Copilot uses AI. Check for mistakes.
}

impl Source {
/// Returns the next fallback source in the hierarchy, if any.
Copy link

Copilot AI Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add documentation for the fallback method explaining the fallback hierarchy and when None is returned (i.e., for sources with no fallback).

Suggested change
/// Returns the next fallback source in the hierarchy, if any.
/// Returns the next fallback source in the hierarchy, if any.
///
/// # Fallback Hierarchy
/// - `Kraken` and `Yadio` fallback to `CoinGecko`.
/// - `Exir` and `CoinGecko` have no fallback and return `None`.
///
/// # Returns
/// - `Some(Source)` if a fallback source exists.
/// - `None` for sources with no fallback.

Copilot uses AI. Check for mistakes.
- Reduce data sources from 9 to 4 (Kraken, CoinGecko, Yadio, Exir)
- Add automatic fallback system (Kraken/Yadio → CoinGecko)
- Add 14 new currencies (VND, PKR, BDT, MMK, EGP, MAD, DZD, JOD, PEN, CRC, DOP, GTQ, BOB, BGN, GEL, KZT, BYN)
- Remove 3 unsupported currencies (AMD, HRK, MZN)
- Migrate currencies to appropriate sources based on API support
- Remove unused Source variants and error types

Final distribution: Kraken (7), CoinGecko (36), Yadio (31), Exir (2)

Closes #129
@Okazakee Okazakee force-pushed the feat/marketapi-rework branch from 5c45208 to e9720d7 Compare December 9, 2025 11:18
@unldenis unldenis added the rates rates crate label Dec 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

rates rates crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Optimize MarketAPI: Consolidate Sources & Add Missing Currencies

3 participants