Skip to content

Quote a buy (Python)

Tested on BSC testnet before every release

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, exactly as our tests run it on testnet. Point it at testnet with MM_API, or leave it for mainnet.

quote.py
# What a buy gets right now, in Python. Reads only.
# TOKEN=0x… python3 quote.py
import json
import os
import urllib.request
API = os.environ.get("MM_API", "https://marketmayhem.co/api/v1")
token = os.environ["TOKEN"]
with urllib.request.urlopen(f"{API}/quote?token={token}&side=buy&amount=0.01") as res:
q = json.load(res)
print(f"0.01 {q['pay']['symbol']} buys about {q['receive']['amount']} {q['receive']['symbol']}")
print(f"price impact {q['priceImpactPct']}%")
print("RESULT", json.dumps({"receive": q["receive"]["amount"]}))