Skip to content

Conversation

@takenagain
Copy link
Collaborator

@takenagain takenagain commented Sep 17, 2025

Binance has per-coin quote currency lists that differ greatly, so this PR

  • Uses the asset-specific quote currencies list in the supports check, and
  • Adds a mapping from USDT to other USD stable coins like USDC

Summary by CodeRabbit

  • New Features

    • Adds automatic USD stablecoin fallback for quote currencies when direct USD pairs aren’t available.
    • Exposes a read-only USD stablecoin priority list for reference.
    • Improves error messages when assets or suitable quote currencies aren’t available.
  • Tests

    • Significantly expands coverage for USD fallback behavior, price/24h change retrieval, non-USD currencies, and error handling.
    • Adds comprehensive exchange info fixtures to simulate real-world and edge cases.
  • Refactor

    • Cleans up imports in the CoinGecko repository to rely on existing type availability.

@takenagain takenagain self-assigned this Sep 17, 2025
@takenagain takenagain added the bug Something isn't working label Sep 17, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 17, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds USD stablecoin fallback selection in BinanceRepository, introducing helpers to derive an effective quote currency and a public getter for the USD stablecoin priority. Refactors symbol and price retrieval to use the effective quote. Expands Binance tests and fixtures accordingly. Removes an unused model import in CoinGecko repository.

Changes

Cohort / File(s) Summary
Binance USD-stablecoin fallback & quote resolution
packages/komodo_cex_market_data/lib/src/binance/data/binance_repository.dart
Adds USD stablecoin priority (public getter, private list), implements effective quote resolution with fallback to USD stablecoins, updates symbol building and API use across getCoinOhlc/getCoinFiatPrice/getCoinFiatPrices/getCoin24hrPriceChange/supports, and improves error messages.
CoinGecko import cleanup
packages/komodo_cex_market_data/lib/src/coingecko/data/coingecko_repository.dart
Removes explicit CoinHistoricalData import; relies on alternative availability or re-export.
Binance tests expansion
packages/komodo_cex_market_data/test/binance/binance_repository_test.dart
Large suite covering USD fallback behavior, error cases, 24h change, OHLC/price with fallback, public getter validation, and real-world symbol scenarios; removes two direct model imports.
Binance test helpers
packages/komodo_cex_market_data/test/binance/binance_test_helpers.dart
Extends comprehensive exchange info; adds builders for fallback-stablecoin scenarios and real-world examples; adds symbols for VIA, TEST, and various USD-stablecoin permutations.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant Repo as BinanceRepository
  participant Prov as BinanceProvider
  participant Eff as EffectiveQuoteResolver

  Client->>Repo: getCoinFiatPrice(assetId, quote: USD)
  Repo->>Prov: fetchExchangeInfo()
  Prov-->>Repo: exchangeInfo (symbols)
  Repo->>Eff: _getEffectiveQuoteCurrency(coin, USD)
  alt Direct USD/USDT supported
    Eff-->>Repo: USD/USDT
  else Fallback to USD-stablecoin
    Eff-->>Repo: Best of [USDT,BUSD,USDC,...] or null
  end
  alt Effective quote found
    Repo->>Prov: fetchPrice(symbol: BASE+EFFECTIVE_QUOTE)
    Prov-->>Repo: price/klines/24h data
    Repo-->>Client: Decimal price / change
  else No effective quote
    Repo-->>Client: Error (no suitable quote currency)
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~30 minutes

Possibly related PRs

Suggested reviewers

  • CharlVS
  • smk762

Poem

I hop through pairs where dollars hide,
From USDT to BUSD I ride.
If USD is shy, I sniff a clue—USDC might do!
Symbols stitched, quotes aligned,
My whiskers twitch when tests are fine.
Thump-thump—fallbacks, verified. 🐇💱

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change: replacing the global cache with per-coin supported quote currency lists for Binance logic (used in supports and symbol construction). The raw_summary and PR objectives confirm changes that compute effective per-coin quote currencies, update supports to use asset-specific lists, and adjust symbol/price paths accordingly, so the title matches the main code intent. It is concise, specific, and informative for teammates scanning history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@takenagain
Copy link
Collaborator Author

@coderabbitai review

@takenagain takenagain marked this pull request as ready for review September 17, 2025 22:39
Copilot AI review requested due to automatic review settings September 17, 2025 22:39
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Sep 17, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Contributor

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 fixes a bug in Binance integration where the global currency cache was used instead of per-coin supported quote currencies. The fix implements a per-coin currency check with fallback logic for USD stablecoins.

  • Replaces global currency cache with per-coin quote currency lists for the supports check
  • Adds USD stablecoin fallback mapping (USDT → USDC → BUSD → etc.) when exact quote currency not available
  • Comprehensive test coverage for the new fallback behavior and edge cases

Reviewed Changes

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

File Description
binance_repository.dart Implements per-coin currency support check and USD stablecoin fallback logic
binance_test_helpers.dart Adds test data for fallback scenarios and real-world examples
binance_repository_test.dart Comprehensive test coverage for new fallback functionality
coingecko_repository.dart Removes unused import

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🧹 Nitpick comments (5)
packages/komodo_cex_market_data/lib/src/binance/data/binance_repository.dart (3)

38-53: Make USD-stablecoin priority configurable (and re-verify BUSD ordering).

Hard-coding priority is fine to start, but market reality changes (e.g., BUSD deprecation/delistings and FDUSD growth). Consider:

  • Reading this list from app-config/remote-config (with sane defaults here).
  • Re‑validating the order (USDT > USDC > BUSD > FDUSD …) against your current Binance ExchangeInfo in prod; you may want FDUSD ahead of BUSD now.

55-60: Remove or wire up _cachedFiatCurrencies.

It’s still populated but unused (explicitly ignored). Either drop the assignments in _fetchCoinListInternal or actually use it to speed up validations to avoid drift between code and intent.


267-276: Avoid mutating the caller’s dates list.

Sorting in place can surprise callers. Use a copied, sorted view and base range math on it.

-    dates.sort();
+    final sortedDates = List<DateTime>.from(dates)..sort();
 
-    if (dates.isEmpty) {
+    if (sortedDates.isEmpty) {
       return {};
     }
 
-    final startDate = dates.first.add(const Duration(days: -2));
-    final endDate = dates.last.add(const Duration(days: 2));
+    final startDate = sortedDates.first.add(const Duration(days: -2));
+    final endDate = sortedDates.last.add(const Duration(days: 2));
packages/komodo_cex_market_data/test/binance/binance_test_helpers.dart (1)

97-153: Consider aligning legacy symbols (PAX → USDP) and adding obscure USD stables behind a flag.

Some symbols like PAX are legacy aliases of USDP on Binance. If you want “unknown-but-USD-pegged” coins (e.g., USDS) to be considered, add them to a low-priority tail or gate them via a test-only toggle to avoid over-permissive prod behavior.

packages/komodo_cex_market_data/test/binance/binance_repository_test.dart (1)

505-531: Add a test for suffixed symbols (e.g., “-segwit”).

Given repository methods previously trimmed only in 24h path, add a test to ensure OHLC/price paths also handle suffixed trading symbols correctly after the proposed normalization.

I can contribute a focused test case if you want.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b0a6f1e and bfe5093.

📒 Files selected for processing (4)
  • packages/komodo_cex_market_data/lib/src/binance/data/binance_repository.dart (8 hunks)
  • packages/komodo_cex_market_data/lib/src/coingecko/data/coingecko_repository.dart (0 hunks)
  • packages/komodo_cex_market_data/test/binance/binance_repository_test.dart (2 hunks)
  • packages/komodo_cex_market_data/test/binance/binance_test_helpers.dart (2 hunks)
💤 Files with no reviewable changes (1)
  • packages/komodo_cex_market_data/lib/src/coingecko/data/coingecko_repository.dart
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: build_and_preview_playground_preview
  • GitHub Check: build_and_preview_sdk_example_preview
  • GitHub Check: Flutter tests (all packages)
🔇 Additional comments (7)
packages/komodo_cex_market_data/lib/src/binance/data/binance_repository.dart (3)

61-65: Public getter returns an immutable priority list — LGTM.

Exposes config safely without allowing mutation.


392-433: Fallback logic reads well and is easy to extend.

Iterating priority and checking membership keeps behavior predictable per coin; nice separation of concerns between selection and callers.


446-459: supports now mirrors effective-quote logic — LGTM.

Correctly derives coin and then the effective quote; good that invalid assets short-circuit to false.

packages/komodo_cex_market_data/test/binance/binance_test_helpers.dart (1)

45-51: Good targeted fixtures for edge-cases.

VIA without USDT pairs and TEST with only BUSD/USDC nicely exercise mapping and fallback.

packages/komodo_cex_market_data/test/binance/binance_repository_test.dart (3)

225-295: Great regression tests for “coin exists but USDT pair doesn’t.”

Catches the prior false-positive support; aligns with the new per-coin effective-quote logic.


532-843: USD-stablecoin fallback flow is well covered.

BUSD/USDC/FDUSD preference and symbol assertions via mocks look solid.


845-1209: Config visibility and error-shape assertions — nice.

Immutability of usdStablecoinPriority and detailed ArgumentError checks will prevent regressions.

@takenagain takenagain requested a review from CharlVS September 17, 2025 23:03
@CharlVS CharlVS merged commit 34dcd69 into dev Sep 18, 2025
4 of 8 checks passed
@CharlVS CharlVS deleted the bugfix/market-data-supports branch September 18, 2025 15:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants