fix(wrtc-price-bot): DexScreener parse always returns None (float / str divide)#7973
Open
Vyacheslav-Tomashevskiy wants to merge 1 commit into
Conversation
DexScreener returns every numeric field as a JSON string, which is why the
surrounding lines all wrap float(). The sol_price_usd line divided the raw
value instead: price_usd / pair.get('priceNative', 1) is float / str, raising
TypeError. The broad 'except Exception' swallowed it, so fetch_dexscreener_price
returned None on a perfectly valid API response and get_price silently fell back
to Jupiter, which hardcodes change_24h/liquidity/price_sol to 0.
Cast priceNative once and reuse it. The 'or 0' plus the post-cast truthiness
check also close a latent ZeroDivisionError: the string '0' is truthy, so a
zero-priced pair would have divided by zero once the type issue was resolved.
Contributor
|
Welcome to RustChain! Thanks for your first pull request. Before we review, please make sure:
Bounty tiers: Micro (1-10 RTC) | Standard (20-50) | Major (75-100) | Critical (100-150) A maintainer will review your PR soon. Thanks for contributing! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
DexScreener returns every numeric field as a JSON string (
"priceUsd": "0.25","priceNative": "0.002") — which is exactly why every other field on the surrounding lines is wrapped infloat(). One line divides the raw value:float / strraisesTypeError, the broadexcept Exceptionswallows it, andfetch_dexscreener_price()returnsNoneon a valid API response. So the primary price source never returns anything, andget_price()silently degrades to the Jupiter fallback — which hardcodeschange_24h: 0,liquidity: 0,price_sol: 0.Downstream that means the bot reports "24h Change: +0.00%" and "Liquidity: N/A" permanently, and
check_price_alert()can never fire, since every history entry carries an identical unchanged basis. It fails closed and logs nothing a user would read as an error.That the sibling implementation in
bridge/dashboard_api.py:513-524parses the same endpoint withfloat()on every field is what convinced me this is an oversight rather than intent.Fix
Cast
priceNativeonce and reuse it. Theor 0and the post-cast truthiness check also close a latentZeroDivisionError: the string"0"is truthy, so the original guard would have let a zero-priced pair through to a divide-by-zero once the type issue was fixed.Test —
tests/test_wrtc_price_bot_dexscreener.pyOn current main (payload mirrors the real API shape, all-strings):
The captured stdout names the exact division. With the fix, these plus the existing
tests/test_wrtc_price_bot.pyandwrtc_price_bot/test_price_fetch.py→ 6 passed.Branched off clean current main; touches only the bot and the new test.
RTC payout address: RTCd1554f0f35576faf01d386a6be1c947f560dd0b7