Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/dev-168-market-event-url.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@polymarket/client": patch
---

Accept copied `/event/{slug}` market URLs when fetching markets by URL.
2 changes: 1 addition & 1 deletion packages/client/src/actions/markets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ export const FetchMarketError = makeErrorGuard(
* });
*
* const marketByUrl = await fetchMarket(client, {
* url: 'https://polymarket.com/market/some-market-slug',
* url: 'https://polymarket.com/event/some-market-slug',
* });
*
* // market === Market
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/decorators/discovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ export type DiscoveryActions = {
* });
*
* const marketByUrl = await client.fetchMarket({
* url: 'https://polymarket.com/market/some-market-slug',
* url: 'https://polymarket.com/event/some-market-slug',
* });
* ```
*/
Expand Down
10 changes: 10 additions & 0 deletions packages/client/src/polymarket-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export function parsePolymarketSlugUrl(
const [actualResource, slug, ...extraSegments] = url.pathname
.split('/')
.filter(Boolean);
const marketSlug = extraSegments[0];

if (
resource === 'market' &&
actualResource === 'event' &&
slug !== undefined &&
extraSegments.length <= 1
) {
return marketSlug ?? slug;
}
Comment thread
cesarenaldi marked this conversation as resolved.

if (
actualResource !== resource ||
Expand Down
4 changes: 2 additions & 2 deletions packages/client/tests/integration/markets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('Markets', () => {

it('fetches a market by URL', async ({ publicClient }) => {
const marketByUrl = await publicClient.fetchMarket({
url: `https://polymarket.com/market/${expectPresent(market.slug)}`,
url: `https://polymarket.com/event/${expectPresent(market.slug)}`,
});

expect(marketByUrl.id).toBe(market.id);
Expand All @@ -79,7 +79,7 @@ describe('Markets', () => {

await expect(
publicClient.fetchMarket({
url: 'https://polymarket.com/event/presidential-election-2028',
url: 'https://polymarket.com/tag/politics',
}),
).rejects.toThrow(UserInputError);
});
Expand Down
Loading