# Connecting to Polymarket Markets

PaperMarket does not connect to a wallet and does not require any on chain permissions.\
Instead it connects to Polymarket at the data level and uses public APIs to read information about markets that you choose.

To work with a market you first load it into the app by passing a link or a slug from Polymarket.

### Supported inputs

On the main page you will see an input field for a Polymarket market.\
You can paste

* a full Polymarket URL from your browser address bar
* or the slug part of the URL

Both event level links and direct market links are supported as long as they point to a Polymarket market that has YES and NO tokens.

Examples of valid inputs include

* an event URL that contains several markets under one question
* a direct URL to a single market within that event
* the market slug copied from the end of the URL

### What happens when you submit a link

When you press the button to load the market the frontend sends your input string to a backend endpoint.

The backend then

1. parses the URL or slug and extracts the relevant path segments
2. calls the Polymarket API to fetch event and market data for that slug
3. selects the specific market that will be used in the simulation
4. reads the market question event slug market slug and token identifiers for YES and NO
5. stores basic metadata about this market in the PaperMarket database if it is new
6. returns a simplified market object to the frontend

The app then shows the question and identifies the YES and NO tokens that will be used for order books trades and positions.

### Events with multiple markets

Some Polymarket event pages contain more than one market under the same question.\
In these cases the backend uses the slug or id from your input to select one concrete market.

Once the market is resolved the app treats it as a single trading venue with two tokens

* YES for the positive outcome
* NO for the opposite outcome

All further operations in PaperMarket for this screen refer exactly to that chosen market.

### Handling errors

If the backend cannot match your input to a valid Polymarket market it returns an error to the frontend.

Common reasons include

* the link does not belong to Polymarket
* the slug no longer exists or the market was removed
* the endpoint used to fetch the market data is temporarily unavailable

In this case the app will show an error message and keep the previous state.\
You can correct the link or choose a different market and try again.

### After the market is connected

When a market is successfully loaded PaperMarket knows

* which question you are looking at
* which YES and NO tokens belong to this market
* which URLs can be used to jump back to the original Polymarket page

From this point the app can request live order books and history for the selected tokens and you can start placing virtual trades against that market.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://papermarket.gitbook.io/papermarket/using-papermarket/connecting-to-polymarket-markets.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
