feat: Add Polymarket connector with Gamma API integration#109
feat: Add Polymarket connector with Gamma API integration#109vale9888 wants to merge 1 commit intoStackOneHQ:mainfrom
Conversation
- Add Polymarket connector with 7 tools for prediction markets - Implement Gamma API client with proper error handling - Add comprehensive test suite following project standards - Update TypeScript config to include DOM lib for fetch support - Add detailed integration plan documentation - Support both public data (no API key) and private data (with API key) - Tools include: get markets, search markets, trending markets, user profile, positions, trade history
| { | ||
| "compilerOptions": { | ||
| "lib": ["ESNext"], | ||
| "lib": ["ESNext", "DOM"], |
There was a problem hiding this comment.
Including DOM in lib for a Node package is unnecessary with @types/node v22 and can pollute globals or cause subtle type conflicts; rely on Node’s fetch types instead.
(Based on your PR description about enabling fetch support by adding the DOM lib.)
Prompt for AI agents
Address the following comment on packages/mcp-connectors/tsconfig.json at line 3:
<comment>Including DOM in lib for a Node package is unnecessary with @types/node v22 and can pollute globals or cause subtle type conflicts; rely on Node’s fetch types instead.
(Based on your PR description about enabling fetch support by adding the DOM lib.)</comment>
<file context>
@@ -1,6 +1,6 @@
{
"compilerOptions": {
- "lib": ["ESNext"],
+ "lib": ["ESNext", "DOM"],
"target": "ESNext",
"module": "ESNext",
</file context>
| it('returns formatted markets list', async () => { | ||
| const tool = PolymarketConnectorConfig.tools.GET_MARKETS as MCPToolDefinition; | ||
| const mockContext = createMockConnectorContext({ | ||
| apiKey: 'test-api-key', |
There was a problem hiding this comment.
Hardcoded API key ('test-api-key') found in test file; secrets should not be committed to source control.
Prompt for AI agents
Address the following comment on packages/mcp-connectors/src/connectors/polymarket.spec.ts at line 126:
<comment>Hardcoded API key ('test-api-key') found in test file; secrets should not be committed to source control.</comment>
<file context>
@@ -0,0 +1,406 @@
+ it('returns formatted markets list', async () => {
+ const tool = PolymarketConnectorConfig.tools.GET_MARKETS as MCPToolDefinition;
+ const mockContext = createMockConnectorContext({
+ apiKey: 'test-api-key',
+ });
+
</file context>
| Outcome ID: ${pos.outcomeId} | ||
| Amount: ${pos.amount} | ||
| Average Price: $${pos.averagePrice} | ||
| ${pos.unrealizedPnL ? `Unrealized P&L: $${pos.unrealizedPnL.toLocaleString()}` : ''}` |
There was a problem hiding this comment.
Zero value hidden by truthiness check; check for undefined/null instead so 0 is shown.
Prompt for AI agents
Address the following comment on packages/mcp-connectors/src/connectors/polymarket.ts at line 382:
<comment>Zero value hidden by truthiness check; check for undefined/null instead so 0 is shown.</comment>
<file context>
@@ -0,0 +1,431 @@
+ Outcome ID: ${pos.outcomeId}
+ Amount: ${pos.amount}
+ Average Price: $${pos.averagePrice}
+ ${pos.unrealizedPnL ? `Unrealized P&L: $${pos.unrealizedPnL.toLocaleString()}` : ''}`
+ ).join('\n\n');
+
</file context>
| return `User Profile: | ||
| Username: ${user.username || 'N/A'} | ||
| Balance: $${user.balance.toLocaleString()} | ||
| ${user.totalPnL ? `Total P&L: $${user.totalPnL.toLocaleString()}` : ''} |
There was a problem hiding this comment.
Zero value hidden by truthiness check; use an undefined/null check so 0 is displayed correctly.
Prompt for AI agents
Address the following comment on packages/mcp-connectors/src/connectors/polymarket.ts at line 352:
<comment>Zero value hidden by truthiness check; use an undefined/null check so 0 is displayed correctly.</comment>
<file context>
@@ -0,0 +1,431 @@
+ return `User Profile:
+Username: ${user.username || 'N/A'}
+Balance: $${user.balance.toLocaleString()}
+${user.totalPnL ? `Total P&L: $${user.totalPnL.toLocaleString()}` : ''}
+Active Positions: ${user.positions.length}`;
+ } catch (error) {
</file context>
| } | ||
|
|
||
| const formatted = markets.map((market, index) => { | ||
| const topOutcome = market.outcomes.reduce((prev, current) => |
There was a problem hiding this comment.
Possible crash: reduce on potentially empty outcomes array; guard for empty outcomes before reducing or provide a safe fallback.
Prompt for AI agents
Address the following comment on packages/mcp-connectors/src/connectors/polymarket.ts at line 216:
<comment>Possible crash: reduce on potentially empty outcomes array; guard for empty outcomes before reducing or provide a safe fallback.</comment>
<file context>
@@ -0,0 +1,431 @@
+ }
+
+ const formatted = markets.map((market, index) => {
+ const topOutcome = market.outcomes.reduce((prev, current) =>
+ current.probability > prev.probability ? current : prev
+ );
</file context>
Team 18!
Summary by cubic
Add a Polymarket connector powered by the Gamma API, exposing 7 tools for prediction markets with solid error handling and full tests. Public data works without a key; user tools require an API key.
New Features
Migration