You can find the best price/path for your swaps on Uniswap or compatible DEXes while managing your RPC provider rate limit!
This new version allows you to define a rate limit policy for your SmartPath
. It uses the async
library credit-rate-limit under the hood. Meaning you can manage rate limits for API that use credits, CUPS (computational units per second) or request units, as well as number of requests per time unit.
Example for APIs that use credits, CUPS or request units:
from uniswap_smart_path import SmartPath, SmartRateLimiter
credit_limiter = SmartRateLimiter(
max_credits=300, # Define a credit limiter allowing 300 credits
interval=1, # for every 1 second
method_credits={"eth_call": 20} # The method 'eth_call' costs 20 credits.
)
smart_path = await SmartPath.create(w3, smart_rate_limiter=credit_limiter)
Example for APIs that just count the number of requests per time unit:
from uniswap_smart_path import SmartPath, SmartRateLimiter
# Define a count limiter allowing 5 requests per second.
count_limiter = SmartRateLimiter(interval=1, max_count=5)
smart_path = await SmartPath.create(w3, smart_rate_limiter=count_limiter)
And that's it! No more "Too Many Requests" errors!
Also, the library now supports Python 3.12 & 3.13 and web3.py v7. Here is the full release note.
Feel free to share any feedback, or ask questions about this library! :)