Polyrankdocs

Python quickstart

x402[httpx] + eth-account — pay-per-request for quants.

Prerequisites

  • Python 3.11+
  • A throwaway EVM private key with ~$1 of USDC on Base (no ETH needed — transfers are gasless for the payer)
pip install "x402[httpx]" eth-account pandas

First paid call

positioning.py
import base64, json, os
import httpx
from eth_account import Account
from x402.clients.httpx import x402HttpxClient

account = Account.from_key(os.environ["AGENT_PK"])

CID = "0x…your-condition-id…"

async def main():
    async with x402HttpxClient(account=account, base_url="https://api.polyrank.app") as client:
        res = await client.get(f"/v1/agent/market/{CID}/positioning")
        data = res.json()

        receipt = json.loads(base64.b64decode(res.headers["x-payment-response"]))
        print(f"paid — https://basescan.org/tx/{receipt['transaction']}")
        return data

import asyncio
data = asyncio.run(main())

Do something quant with it

positioning returns the top-200 positioned wallets with average entry, unrealized P&L, and smart-money tags — load it straight into a DataFrame:

import pandas as pd

df = pd.DataFrame(data["rows"])
sharp = df[df["smart_money_tags"].apply(len) > 0]

exposure = sharp.groupby("outcome_side")["shares_held"].sum()
print("tagged-wallet net exposure:\n", exposure)

For 2¢ you know the entry price of the 200 sharpest wallets in a market.

Budget + cache pattern

MAX_SPEND_PER_RUN = 0.50  # USD
spent = 0.0

def guard(price_usd: float):
    global spent
    if spent + price_usd > MAX_SPEND_PER_RUN:
        raise RuntimeError("budget exhausted")
    spent += price_usd

Cache responses on disk keyed by endpoint + hour — re-runs of a notebook shouldn't repurchase identical data.

Endpoint catalog and prices: x402 Agent API. Wire-level detail (what the SDK does for you): Protocol.

On this page