Quote a buy (Python)
Example
This is an example. Every value in it (names, amounts, addresses) is there to show you how; change any of them to suit you. It’s quote.py from developers/examples, as it is. Anything that sends waits for SEND=1: there is no testnet, so a sent transaction spends real ETH.
# What 0.001 ETH buys of a coin right now, simulated through every route it trades on. Sends nothing.# COIN=0x… python3 quote.py (no COIN: the busiest coin on Robinhood Chain today)import json, os, urllib.request
API = os.environ.get("UPRALLY_API", "https://uprally.co/api/v1")
def get(path): try: with urllib.request.urlopen(API + path) as r: return json.load(r) except urllib.error.HTTPError as e: err = json.load(e)["error"] raise SystemExit(f"{err['code']}: {err['message']} {err.get('fix', '')}")
coin = os.environ.get("COIN") or get("/coins?sort=volume&limit=1")["coins"][0]["address"]q = get(f"/quote?token={coin}&side=buy&amount={os.environ.get('AMOUNT', '0.001')}")print(f"{q['amountIn']['amount']} ETH buys {q['amountOut']['amount']} {q['symbol']} (at least {q['minOut']['amount']})")print(f"RESULT {q['amountOut']['wei']}")