All postsAutomation & Coding

Build a Python Cross-Venue Price Monitor for Polymarket and Kalshi

PMA Research · · 6 min read · Updated

Build a Python Cross-Venue Price Monitor for Polymarket and Kalshi — article illustration

A read-only price monitor is a useful first project for studying cross-venue prediction markets. It can compare actual purchase prices without connecting a wallet or placing orders. It cannot prove that two contracts settle identically or that quotes will still exist when an order arrives. This guide builds an educational snapshot checker with Python's standard library and makes those limitations explicit.

Key takeaways

  • Use executable asks for the outcomes you would actually buy, not last-trade prices or midpoints.
  • Kalshi's order-book response supplies bids. A best NO bid implies a YES ask of one dollar minus that bid.
  • Polymarket outcome identifiers are decimal integers, not Ethereum wallet addresses. Current discovery documentation distinguishes CTF token identifiers from Protocol V2 position identifiers.
  • Compare quantities and include both legs' purchase costs and fees. A positive model result is not an executable or guaranteed profit.

What should the mapping contain?

Start by manually reviewing one event on each venue. Record the exact Kalshi ticker and the Polymarket trading identifier for the opposing outcome. A mapping table should contain the Kalshi ticker, Polymarket NO asset identifier, source agency, deadline, and review date. Fill those fields with identifiers from the real markets you have checked; do not copy an invented ticker or a wallet address from a tutorial.

Market titles are insufficient. Compare the outcome definition, observation period, time zone, official source, cancellation rules, and unusual-resolution provisions. If one venue's YES and the other's NO can both lose, the pair is not a simple matched hedge. A human-reviewed mapping still needs maintenance when rules change.

How do the public data interfaces differ?

Kalshi documents a public market-data API under its v2 Trade API. Its order-book response uses an orderbook_fp object with dollar-denominated price strings, including no_dollars. Because a NO bid at $0.60 corresponds to an implied YES offer at $0.40, the highest positive-size NO bid determines the best implied YES ask. An empty opposite book means no observable ask, not a zero-cost contract.

Polymarket separates market discovery from order-book reads. Gamma discovery data identifies the outcomes; the trading API returns the book for the selected asset identifier. Current documentation distinguishes clobTokenIds for CTF markets and positionIds for Protocol V2 markets. Follow the market's version and outcome mapping rather than assuming the first identifier is always YES. The documented order-book interface accepts the selected trading identifier as token_id.

Current Polymarket documentation describes bids in ascending order and asks in descending order. The example does not depend on that ordering: it explicitly selects the minimum positive-size ask. It uses Decimal because converting decimal money strings to binary floating point can introduce avoidable rounding artifacts.

What does a minimal snapshot checker look like?

This example uses public reads only. Run it locally, provide a real reviewed Kalshi ticker and the opposing Polymarket NO identifier, and choose a quantity no larger than the displayed best levels. Fee inputs are assumptions to verify against the actual market, not values discovered automatically by this script.

import json
import urllib.request
from urllib.parse import quote, urlencode
from decimal import Decimal, ROUND_HALF_UP

D = Decimal

def get_json(url):
    req = urllib.request.Request(url, headers={"User-Agent": "read-only-research/1.0"})
    with urllib.request.urlopen(req, timeout=10) as response:
        return json.load(response)

ticker = input("Reviewed Kalshi ticker: ").strip()
asset_id = input("Reviewed Polymarket NO asset identifier: ").strip()
if not ticker or not asset_id.isdecimal():
    raise ValueError("Supply a ticker and a decimal outcome identifier.")

kalshi_url = "https://external-api.kalshi.com/trade-api/v2/markets/"
kalshi = get_json(kalshi_url + quote(ticker, safe="") + "/orderbook")
poly_url = "https://clob.polymarket.com/book?" + urlencode({"token_id": asset_id})
poly = get_json(poly_url)

no_bids = [(D(x[0]), D(x[1])) for x in kalshi["orderbook_fp"]["no_dollars"] if D(x[1]) > 0]
asks = [(D(x["price"]), D(x["size"])) for x in poly["asks"] if D(x["size"]) > 0]
if not no_bids or not asks:
    raise ValueError("A required book side has no available liquidity.")

best_no = max(price for price, size in no_bids)
k_price = D("1") - best_no
p_price = min(price for price, size in asks)
k_size = sum((size for price, size in no_bids if price == best_no), D("0"))
p_size = sum((size for price, size in asks if price == p_price), D("0"))
quantity = D(input("Whole-contract quantity: "))
if quantity <= 0 or quantity != quantity.to_integral_value():
    raise ValueError("Use a positive whole-contract quantity in this example.")
if quantity > min(k_size, p_size):
    raise ValueError("Quantity exceeds a displayed best-price level.")

k_multiplier = D(input("Verified Kalshi taker multiplier: "))
p_rate = D(input("Verified Polymarket fee coefficient: "))
if k_multiplier < 0 or p_rate < 0:
    raise ValueError("Fee inputs must be nonnegative.")
k_raw = k_multiplier * D("0.07") * quantity * k_price * (D("1") - k_price)
p_raw = quantity * p_rate * p_price * (D("1") - p_price)
p_fee = p_raw.quantize(D("0.00001"), rounding=ROUND_HALF_UP)
purchases = quantity * (k_price + p_price)
modeled_cost = purchases + k_raw + p_fee
print("Kalshi YES ask:", k_price, "Polymarket NO ask:", p_price)
print("Modeled cost before Kalshi rounding:", modeled_cost)
print("Matched payout minus modeled cost:", quantity - modeled_cost)

The script intentionally stops on missing or unexpected data instead of substituting a zero price. HTTP failures, unavailable identifiers, and schema changes need investigation. Never reinterpret an error response as an opportunity. No credentials or signing keys are required for these documented public reads.

How should the fee output be interpreted?

Kalshi's general taker formula is M × 0.07 × quantity × price × (1 − price), with the applicable multiplier and rounding rules. The checker reports the raw formula amount, not an exact invoice. Use the current market-specific schedule and actual fill records to implement production fee precision.

Polymarket's documented taker fee is quantity × feeRate × price × (1 − price), rounded to five decimal places in USDC. Category coefficients differ, and the selected market's actual parameters control. Maker treatment does not apply merely because an order is a limit order: an immediately marketable limit order can take liquidity.

For a hypothetical 100-pair purchase at Kalshi $0.40 and Polymarket $0.55, purchases total $95. At a Kalshi multiplier of 1 and a hypothetical Polymarket coefficient of 0.04, fees are $1.68 raw and $0.99000 respectively. The modeled total is $97.67 and the matched $100 payout leaves $2.33 before Kalshi rounding and other costs. These inputs are illustrative, not observed quotes.

Why is this not a production arbitrage bot?

The HTTP requests happen sequentially, so the snapshots are not simultaneous. Displayed liquidity can cancel, prices can move, and the script does not walk deeper levels or send orders. It does not automatically verify contract equivalence, detect every stale snapshot, discover fees, or account for funding and withdrawal costs. Its output is a candidate for investigation.

For larger quantities, compute depth-weighted costs by consuming available levels and applying fees to the relevant fills. For continuous monitoring, consult current rate limits, use bounded requests and backoff after throttling, and consider documented streaming feeds. No arbitrary polling frequency is universally safe. A Fill-or-Kill instruction on one venue cannot make two separate venues execute atomically.

Frequently asked questions

Do I need private keys for this monitor?

No. Keep it read-only. Review our fake bot checklist before running unfamiliar software or installing dependencies.

Is the displayed result guaranteed profit?

No. It omits Kalshi venue rounding and other frictions, and requires complementary settlement. Use our fee calculator to explore sensitivity, not to replace venue terms.

Can blockchain logs reconstruct the historical order book?

Executed on-chain trades can validate some fills. They do not reveal every resting off-chain order or cancellation. Historical depth requires an appropriate archive.

Sources

Information only, not financial advice. Trading prediction markets involves risk of loss.