Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion: Fetch Condition ID from Market Name #107

Open
abhishekmittal15 opened this issue Dec 27, 2024 · 0 comments
Open

Discussion: Fetch Condition ID from Market Name #107

abhishekmittal15 opened this issue Dec 27, 2024 · 0 comments

Comments

@abhishekmittal15
Copy link

abhishekmittal15 commented Dec 27, 2024

Overview

Knowing the condition id of the market is crucial for order placement, historical prices etc.
But I havent been able to figure out an easy way to fetch the condition ID given the market name on the website.
I'd be really glad if someone can help me out.

Description

As an example, consider this market -> https://polymarket.com/event/elon-musk-of-tweets-december-20-27?tid=1735302776150
I know the market name(roughly not exactly, because the market name would also contain the tweets range), but now how do I get the condition ID for this market.

At the moment, I implemented the following to get hold of all markets with Elon Musk in it

import requests
import json


def getClosestMarkets(searchDescription):

    baseURL = "https://clob.polymarket.com/"
    endpoint = baseURL + "markets"
    nextCursor = None

    possibleMarkets = []
    numFetchedMarkets = 0
    while True:
        url = endpoint
        if nextCursor:
            url += f"?next_cursor={nextCursor}"
        res = requests.get(url).json()
        markets, nextCursor = res.get("data", []), res.get("next_cursor", None)
        if nextCursor is None:
            break
        numFetchedMarkets += res.get("count", 0)
        print(f"Fetched {numFetchedMarkets} markets uptill now")
        for market in markets:
            flag = True
            for word in searchDescription.split():
                if word not in market["question"].split():
                    flag = False
            if flag:
                possibleMarkets.append(market)

    return possibleMarkets


if __name__ == "__main__":

    searchDesc = "Elon Musk"
    markets = getClosestMarkets(searchDescription=searchDesc)
    with open("elon_markets.json", "w") as f:
        json.dump(markets, f)

But the list of markets returned by this snippet doesnt include the market I linked earlier, indicating that this is not a full proof method of fetching markets.

Likely, I'm being really silly, and there is a trivial way to do this, because it sounds like an obvious feature to have. So please if any one has any insights, do share them with me.

Action Items

  • Discussion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant