-
Notifications
You must be signed in to change notification settings - Fork 5
fix(binance): use the per-coin supported quote currency list instead of the global cache #224
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
allows for binance requests for assets without explicit USDT support
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the Note Other AI code review bot(s) detectedCodeRabbit 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. WalkthroughAdds 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches✅ Passed checks (3 passed)
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. Comment |
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
There was a problem hiding this 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
supportscheck - 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.
packages/komodo_cex_market_data/lib/src/binance/data/binance_repository.dart
Outdated
Show resolved
Hide resolved
packages/komodo_cex_market_data/test/binance/binance_repository_test.dart
Show resolved
Hide resolved
There was a problem hiding this 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
_fetchCoinListInternalor actually use it to speed up validations to avoid drift between code and intent.
267-276: Avoid mutating the caller’sdateslist.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
📒 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:supportsnow 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
usdStablecoinPriorityand detailedArgumentErrorchecks will prevent regressions.
Binance has per-coin quote currency lists that differ greatly, so this PR
supportscheck, andSummary by CodeRabbit
New Features
Tests
Refactor