<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Dexoryn</title>
    <description>The latest articles on DEV Community by Dexoryn (@dexoryn).</description>
    <link>https://dev.to/dexoryn</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3576365%2F665987ca-c804-4d63-aac7-dec53205a1a7.png</url>
      <title>DEV Community: Dexoryn</title>
      <link>https://dev.to/dexoryn</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dexoryn"/>
    <language>en</language>
    <item>
      <title>Build a Simple Polymarket Market Scanner With Python</title>
      <dc:creator>Dexoryn</dc:creator>
      <pubDate>Tue, 22 Sep 2026 16:23:12 +0000</pubDate>
      <link>https://dev.to/dexoryn/build-a-simple-polymarket-market-scanner-with-python-19e0</link>
      <guid>https://dev.to/dexoryn/build-a-simple-polymarket-market-scanner-with-python-19e0</guid>
      <description>&lt;p&gt;Prediction markets are interesting from a developer's perspective because the data is not just a number.&lt;/p&gt;

&lt;p&gt;A market has a question.&lt;/p&gt;

&lt;p&gt;It has possible outcomes.&lt;/p&gt;

&lt;p&gt;It has prices. &lt;/p&gt;

&lt;p&gt;It has an order book.&lt;/p&gt;

&lt;p&gt;It has liquidity.&lt;/p&gt;

&lt;p&gt;And all of those things can change while you are looking at them.&lt;/p&gt;

&lt;p&gt;That makes Polymarket a surprisingly interesting dataset to work with.&lt;/p&gt;

&lt;p&gt;Instead of manually opening markets and scrolling through them, you can use the API to build a small research tool that finds markets, extracts their data, and gives you a cleaner starting point for analysis.&lt;/p&gt;

&lt;p&gt;In this tutorial, we'll build a simple version in Python.&lt;/p&gt;

&lt;p&gt;The goal isn't to build a trading bot.&lt;/p&gt;

&lt;p&gt;The goal is to build something more useful for research:&lt;/p&gt;

&lt;p&gt;Find a market, inspect its data, inspect its order book, then decide whether it deserves deeper research.&lt;/p&gt;

&lt;p&gt;How Polymarket's APIs fit together&lt;/p&gt;

&lt;p&gt;Polymarket separates its market data across different APIs.&lt;/p&gt;

&lt;p&gt;The Gamma API is useful for discovering markets and retrieving market metadata.&lt;/p&gt;

&lt;p&gt;The CLOB API is where you'll find order-book and pricing information.&lt;/p&gt;

&lt;p&gt;There is also a Data API for things such as trades and positions.&lt;/p&gt;

&lt;p&gt;For our small research tool, we mainly need Gamma and CLOB.&lt;/p&gt;

&lt;p&gt;A simple way to think about the workflow is:&lt;/p&gt;

&lt;p&gt;Gamma API&lt;br&gt;
Find markets&lt;br&gt;
Get market metadata&lt;br&gt;
Get YES / NO token IDs&lt;/p&gt;

&lt;p&gt;CLOB API&lt;br&gt;
Get prices&lt;br&gt;
Get order book&lt;br&gt;
Analyze the market&lt;/p&gt;

&lt;p&gt;The important part is that the market metadata gives you the token IDs you need to query the CLOB.&lt;/p&gt;

&lt;p&gt;Polymarket's documentation and Institute examples show this workflow directly.&lt;/p&gt;

&lt;p&gt;Step 1: Get some active markets&lt;/p&gt;

&lt;p&gt;Let's start by asking Gamma for active markets.&lt;/p&gt;

&lt;p&gt;import requests&lt;/p&gt;

&lt;p&gt;url = "&lt;a href="https://gamma-api.polymarket.com/markets" rel="noopener noreferrer"&gt;https://gamma-api.polymarket.com/markets&lt;/a&gt;"&lt;/p&gt;

&lt;p&gt;params = {&lt;br&gt;
    "active": "true",&lt;br&gt;
    "closed": "false",&lt;br&gt;
    "limit": 10&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;response = requests.get(url, params=params)&lt;br&gt;
response.raise_for_status()&lt;/p&gt;

&lt;p&gt;markets = response.json()&lt;/p&gt;

&lt;p&gt;for market in markets:&lt;br&gt;
    print(market.get("question"))&lt;/p&gt;

&lt;p&gt;That's already useful.&lt;/p&gt;

&lt;p&gt;Instead of manually browsing Polymarket, your program can now retrieve a list of markets.&lt;/p&gt;

&lt;p&gt;But a list of questions isn't enough.&lt;/p&gt;

&lt;p&gt;We want to know what each market is trading at.&lt;/p&gt;

&lt;p&gt;Step 2: Look at the market data&lt;/p&gt;

&lt;p&gt;A market response contains metadata that can help you understand what you're looking at.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;for market in markets:&lt;br&gt;
    print("Question:", market.get("question"))&lt;br&gt;
    print("Liquidity:", market.get("liquidity"))&lt;br&gt;
    print("Volume:", market.get("volume"))&lt;br&gt;
    print()&lt;/p&gt;

&lt;p&gt;You can also inspect the complete response while developing:&lt;/p&gt;

&lt;p&gt;print(markets[0])&lt;/p&gt;

&lt;p&gt;This is a good habit when working with an API you haven't used before.&lt;/p&gt;

&lt;p&gt;Don't assume the field names or structure.&lt;/p&gt;

&lt;p&gt;Look at the actual response.&lt;/p&gt;

&lt;p&gt;Then build your code around it.&lt;/p&gt;

&lt;p&gt;Step 3: Get the outcome token IDs&lt;/p&gt;

&lt;p&gt;This is where things get more interesting.&lt;/p&gt;

&lt;p&gt;Polymarket markets have outcome tokens, and the CLOB uses the relevant token ID when you request order-book or price information.&lt;/p&gt;

&lt;p&gt;For a binary market, you'll typically have YES and NO outcomes.&lt;/p&gt;

&lt;p&gt;The market response exposes the CLOB token IDs.&lt;/p&gt;

&lt;p&gt;Depending on the API response, some fields may arrive as JSON-encoded strings, so make sure you inspect and parse them correctly.&lt;/p&gt;

&lt;p&gt;For example:&lt;/p&gt;

&lt;p&gt;import json&lt;/p&gt;

&lt;p&gt;market = markets[0]&lt;/p&gt;

&lt;p&gt;token_ids = market.get("clobTokenIds")&lt;/p&gt;

&lt;p&gt;if isinstance(token_ids, str):&lt;br&gt;
    token_ids = json.loads(token_ids)&lt;/p&gt;

&lt;p&gt;print(token_ids)&lt;/p&gt;

&lt;p&gt;Now you have the identifiers needed to query the CLOB.&lt;/p&gt;

&lt;p&gt;Step 4: Get the current price&lt;/p&gt;

&lt;p&gt;Let's take the first token and ask the CLOB for its current price.&lt;/p&gt;

&lt;p&gt;token_id = token_ids[0]&lt;/p&gt;

&lt;p&gt;url = "&lt;a href="https://clob.polymarket.com/price" rel="noopener noreferrer"&gt;https://clob.polymarket.com/price&lt;/a&gt;"&lt;/p&gt;

&lt;p&gt;params = {&lt;br&gt;
    "token_id": token_id,&lt;br&gt;
    "side": "BUY"&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;response = requests.get(url, params=params)&lt;br&gt;
response.raise_for_status()&lt;/p&gt;

&lt;p&gt;price_data = response.json()&lt;/p&gt;

&lt;p&gt;print(price_data)&lt;/p&gt;

&lt;p&gt;The CLOB API provides price information for a specific token and side.&lt;/p&gt;

&lt;p&gt;Now we have something much more useful than a market title.&lt;/p&gt;

&lt;p&gt;We have a market and a current executable price.&lt;/p&gt;

&lt;p&gt;But there is still a problem.&lt;/p&gt;

&lt;p&gt;One price doesn't tell you much about liquidity.&lt;/p&gt;

&lt;p&gt;Step 5: Read the order book&lt;/p&gt;

&lt;p&gt;This is where the project becomes more interesting.&lt;/p&gt;

&lt;p&gt;The order book shows the bids and asks currently sitting in the market.&lt;/p&gt;

&lt;p&gt;url = "&lt;a href="https://clob.polymarket.com/book" rel="noopener noreferrer"&gt;https://clob.polymarket.com/book&lt;/a&gt;"&lt;/p&gt;

&lt;p&gt;params = {&lt;br&gt;
    "token_id": token_id&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;response = requests.get(url, params=params)&lt;br&gt;
response.raise_for_status()&lt;/p&gt;

&lt;p&gt;book = response.json()&lt;/p&gt;

&lt;p&gt;print("Bids:")&lt;br&gt;
print(book.get("bids"))&lt;/p&gt;

&lt;p&gt;print("Asks:")&lt;br&gt;
print(book.get("asks"))&lt;/p&gt;

&lt;p&gt;Now you can inspect the actual market structure.&lt;/p&gt;

&lt;p&gt;For example, imagine you find something like:&lt;/p&gt;

&lt;p&gt;Bids&lt;br&gt;
0.47 → 100 shares&lt;br&gt;
0.46 → 250 shares&lt;br&gt;
0.45 → 500 shares&lt;/p&gt;

&lt;p&gt;Asks&lt;br&gt;
0.53 → 80 shares&lt;br&gt;
0.54 → 150 shares&lt;br&gt;
0.55 → 400 shares&lt;/p&gt;

&lt;p&gt;The displayed probability might look like roughly 50%.&lt;/p&gt;

&lt;p&gt;But the order book tells you something more important.&lt;/p&gt;

&lt;p&gt;There is a meaningful gap between what buyers are offering and what sellers are asking.&lt;/p&gt;

&lt;p&gt;That is the spread.&lt;/p&gt;

&lt;p&gt;And if you want to trade, the spread matters.&lt;/p&gt;

&lt;p&gt;Turn the order book into something readable&lt;/p&gt;

&lt;p&gt;Raw API responses are useful for debugging.&lt;/p&gt;

&lt;p&gt;They're not particularly useful for humans.&lt;/p&gt;

&lt;p&gt;Let's extract the best bid and best ask.&lt;/p&gt;

&lt;p&gt;bids = book.get("bids", [])&lt;br&gt;
asks = book.get("asks", [])&lt;/p&gt;

&lt;p&gt;best_bid = max(&lt;br&gt;
    float(order["price"])&lt;br&gt;
    for order in bids&lt;br&gt;
) if bids else None&lt;/p&gt;

&lt;p&gt;best_ask = min(&lt;br&gt;
    float(order["price"])&lt;br&gt;
    for order in asks&lt;br&gt;
) if asks else None&lt;/p&gt;

&lt;p&gt;print("Best bid:", best_bid)&lt;br&gt;
print("Best ask:", best_ask)&lt;/p&gt;

&lt;p&gt;if best_bid is not None and best_ask is not None:&lt;br&gt;
    spread = best_ask - best_bid&lt;br&gt;
    print("Spread:", spread)&lt;/p&gt;

&lt;p&gt;Now your script can answer a much more useful question:&lt;/p&gt;

&lt;p&gt;What does the market actually look like right now?&lt;/p&gt;

&lt;p&gt;Not just what the headline says.&lt;/p&gt;

&lt;p&gt;Not just what the displayed probability says.&lt;/p&gt;

&lt;p&gt;But what buyers and sellers are actually offering.&lt;/p&gt;

&lt;p&gt;Add a simple market filter&lt;/p&gt;

&lt;p&gt;Now let's turn this into something closer to a scanner.&lt;/p&gt;

&lt;p&gt;Suppose you only want to investigate markets with enough liquidity.&lt;/p&gt;

&lt;p&gt;You can create a basic filter:&lt;/p&gt;

&lt;p&gt;MIN_LIQUIDITY = 10000&lt;/p&gt;

&lt;p&gt;for market in markets:&lt;br&gt;
    liquidity = float(market.get("liquidity") or 0)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if liquidity &amp;gt;= MIN_LIQUIDITY:
    print(
        market.get("question"),
        "Liquidity:",
        liquidity
    )
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This isn't a trading strategy.&lt;/p&gt;

&lt;p&gt;It's simply a way to reduce the number of markets you need to manually inspect.&lt;/p&gt;

&lt;p&gt;And that's an important distinction.&lt;/p&gt;

&lt;p&gt;A scanner should help you find things worth researching.&lt;/p&gt;

&lt;p&gt;It shouldn't pretend to know which trade will win.&lt;/p&gt;

&lt;p&gt;You can take this much further&lt;/p&gt;

&lt;p&gt;Once you have the basic pipeline working, there are several directions you can take it.&lt;/p&gt;

&lt;p&gt;You could collect historical prices and calculate how quickly markets move after major events.&lt;/p&gt;

&lt;p&gt;You could monitor changes in spreads.&lt;/p&gt;

&lt;p&gt;You could compare market prices against your own probability model.&lt;/p&gt;

&lt;p&gt;You could rank markets by liquidity.&lt;/p&gt;

&lt;p&gt;You could detect unusually large changes in price.&lt;/p&gt;

&lt;p&gt;You could build a dashboard showing the most interesting markets.&lt;/p&gt;

&lt;p&gt;You could even send yourself an alert when a market meets a set of conditions.&lt;/p&gt;

&lt;p&gt;Polymarket's CLOB API also exposes historical price data, which makes time-series analysis possible rather than limiting you to the current snapshot.&lt;/p&gt;

&lt;p&gt;One thing I would not do&lt;/p&gt;

&lt;p&gt;Don't jump straight from:&lt;/p&gt;

&lt;p&gt;API&lt;br&gt;
Signal&lt;br&gt;
Automatic trade&lt;/p&gt;

&lt;p&gt;That's where a fun data project becomes a very different problem.&lt;/p&gt;

&lt;p&gt;A price moving from 40¢ to 45¢ doesn't automatically mean you've discovered an opportunity.&lt;/p&gt;

&lt;p&gt;You still need to understand the question.&lt;/p&gt;

&lt;p&gt;You need to understand the resolution rules.&lt;/p&gt;

&lt;p&gt;You need to understand liquidity and execution.&lt;/p&gt;

&lt;p&gt;And you need a reason for believing your estimate is different from the market's.&lt;/p&gt;

&lt;p&gt;The API gives you data.&lt;/p&gt;

&lt;p&gt;It doesn't give you a thesis.&lt;/p&gt;

&lt;p&gt;The interesting part isn't the bot&lt;/p&gt;

&lt;p&gt;That's probably the biggest lesson from building something like this.&lt;/p&gt;

&lt;p&gt;The interesting part isn't automatically placing trades.&lt;/p&gt;

&lt;p&gt;It's being able to turn a prediction market into structured data that you can actually investigate.&lt;/p&gt;

&lt;p&gt;Instead of opening twenty tabs, you can write a script that asks:&lt;/p&gt;

&lt;p&gt;What markets are active?&lt;/p&gt;

&lt;p&gt;Which ones have meaningful liquidity?&lt;/p&gt;

&lt;p&gt;What are they currently priced at?&lt;/p&gt;

&lt;p&gt;What does the order book look like?&lt;/p&gt;

&lt;p&gt;How has the price moved?&lt;/p&gt;

&lt;p&gt;Which markets deserve human attention?&lt;/p&gt;

&lt;p&gt;That is a much better starting point for building.&lt;/p&gt;

&lt;p&gt;And once you have that foundation, you can experiment.&lt;/p&gt;

&lt;p&gt;Build a dashboard.&lt;/p&gt;

&lt;p&gt;Build a notification system.&lt;/p&gt;

&lt;p&gt;Build a historical analysis tool.&lt;/p&gt;

&lt;p&gt;Build your own probability model.&lt;/p&gt;

&lt;p&gt;Or eventually connect the research layer to a trading system.&lt;/p&gt;

&lt;p&gt;But start with the data.&lt;/p&gt;

&lt;p&gt;Because before you build a trading bot, you should probably build something that helps you understand the market first.&lt;/p&gt;

&lt;p&gt;**The best automated trading systems don't start with an order.&lt;/p&gt;

&lt;p&gt;They start with better information.**&lt;/p&gt;

</description>
      <category>python</category>
      <category>api</category>
      <category>webdev</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
