### Local Development Setup - Bash Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Commands to set up and run subgraphs locally using Docker Compose. ```bash # Start the Docker environment docker compose up # Prepare subgraph configuration for Polygon network yarn templatify:matic # Generate types for a specific subgraph yarn pnl:codegen yarn activity:codegen yarn orderbook:codegen yarn fpmm:codegen yarn oi:codegen yarn oracle:codegen yarn wallet:codegen yarn feemodule:codegen # Build a subgraph yarn pnl:build # Create and deploy locally yarn pnl:create-local yarn pnl:deploy-local # Access GraphQL playground at: # http://localhost:8000/subgraphs/name/pnl-subgraph/graphql ``` -------------------------------- ### GraphQL Example Query Source: https://github.com/polymarket/polymarket-subgraph/blob/main/README.md An example GraphQL query to retrieve tokenIdConditions, including their id, condition, and complement. ```graphql query tokenIdConditions { tokenIdConditions { id condition complement } } ``` -------------------------------- ### Query Global Open Interest Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Get the total open interest across all markets. This query uses a fixed ID. ```graphql query GlobalOI { globalOpenInterest(id: "") { id amount } } ``` -------------------------------- ### Query Global Exchange Statistics Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Get aggregated exchange volume across all orderbooks. This query does not require any specific IDs. ```graphql query GlobalStats { ordersMatchedGlobal(id: "") { id tradesQuantity buysQuantity sellsQuantity collateralVolume scaledCollateralVolume collateralBuyVolume scaledCollateralBuyVolume collateralSellVolume scaledCollateralSellVolume } } ``` -------------------------------- ### Goldsky Deployment - Bash Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Commands to build and deploy a subgraph to Goldsky's hosted service. ```bash # Build the subgraph yarn pnl:build # Deploy to Goldsky goldsky subgraph deploy pnl-subgraph/v1.0.0 --path ./build/ ``` -------------------------------- ### Build Local Graph-Node Docker Image for M1 Chip Source: https://github.com/polymarket/polymarket-subgraph/blob/main/README.md Steps to build a local Docker image for graph-node on an M1 chip. This involves cloning the graph-node repository and rebuilding the image. ```bash # Remove the original image docker rmi graphprotocol/graph-node:latest # Build the image ./docker/build.sh # Tag the newly created image docker tag graph-node graphprotocol/graph-node:latest ``` -------------------------------- ### Create and Deploy Subgraph Locally Source: https://github.com/polymarket/polymarket-subgraph/blob/main/README.md Use these yarn scripts to create and deploy your subgraph to a local Docker environment. Access the GraphQL editor at http://localhost:8000/subgraphs/name/polymarket-subgraph/graphql. ```bash yarn :create-local yarn :deploy-local ``` -------------------------------- ### Deploy Subgraph to Goldsky Source: https://github.com/polymarket/polymarket-subgraph/blob/main/README.md Build the subgraph using `yarn :build` and then deploy it to Goldsky using the provided command. ```bash goldsky subgraph deploy / --path ./build/ ``` -------------------------------- ### Query All Markets with Open Interest Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Fetch a list of all markets with open interest, ordered by the amount of open interest in descending order. Limited to the first 100 results. ```graphql query AllMarketsOI { marketOpenInterests(orderBy: amount, orderDirection: desc, first: 100) { id amount } } ``` -------------------------------- ### Query Market Maker Details Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Retrieve detailed data for a Fixed Product Market Maker, including liquidity, volume, and pricing. Requires the market maker's address. ```graphql query MarketMaker($address: ID!) { fixedProductMarketMaker(id: $address) { id creator creationTimestamp collateralToken { id name symbol decimals } conditions fee tradesQuantity buysQuantity sellsQuantity liquidityAddQuantity liquidityRemoveQuantity collateralVolume scaledCollateralVolume feeVolume liquidityParameter outcomeTokenAmounts outcomeTokenPrices outcomeSlotCount totalSupply } } # Variables: { "address": "0x1234567890abcdef1234567890abcdef12345678" } ``` -------------------------------- ### Configure MATIC_RPC_URL Environment Variable Source: https://github.com/polymarket/polymarket-subgraph/blob/main/README.md Set the MATIC_RPC_URL in a .env file for the Polygon network RPC URL. Common providers include Alchemy and Infura. ```bash MATIC_RPC_URL= ``` -------------------------------- ### Restart Graph Node and Clear Volumes Source: https://github.com/polymarket/polymarket-subgraph/blob/main/README.md Commands to stop the Docker environment and remove the subgraph's Docker containers. Container names may vary. ```bash docker compose down ``` ```bash sudo docker rm polymarket-subgraph-graph-node-1 && sudo docker rm polymarket-subgraph-ipfs-1 && sudo docker rm polymarket-subgraph-postgres-1 && sudo docker rm polymarket-subgraph-ganache-1 ``` -------------------------------- ### Query Games from Sports Oracle Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Fetch game data indexed by the UMA Sports Oracle subgraph. Limited to the first 50 games. ```graphql # Query games query Games { games(first: 50) { id ancillaryData ordering state homeScore awayScore } } # Response example: # { # "games": [ # { # "id": "0xabc123...", # "ancillaryData": "q:\"NFL Game: Team A vs Team B\"", # "ordering": "1", # "state": "Resolved", # "homeScore": "24", # "awayScore": "17" # } # ] # } ``` -------------------------------- ### Query Wallet by Address - GraphQL Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Use this GraphQL query to retrieve details for a specific wallet address. ```graphql query Wallet($address: ID!) { wallet(id: $address) { id signer type balance lastTransfer createdAt } } ``` -------------------------------- ### Query Funding Additions to a Market Maker Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Track funding additions to a specific market maker. Requires the market maker's address and orders results by timestamp. ```graphql query FundingAdditions($fpmm: String!) { fpmmFundingAdditions(where: { fpmm: $fpmm }, orderBy: timestamp, orderDirection: desc) { id timestamp fpmm { id } funder amountsAdded amountsRefunded sharesMinted } } ``` -------------------------------- ### Query Wallets by Signer - GraphQL Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Use this GraphQL query to find all wallets associated with a given signer address. ```graphql query WalletsBySigner($signer: String!) { wallets(where: { signer: $signer }) { id signer type balance lastTransfer createdAt } } ``` -------------------------------- ### PnL Subgraph - User Position Tracking Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt The PnL subgraph tracks user positions including average buy price, realized profit/loss, and current holdings. ```APIDOC ## PnL Subgraph - User Position Tracking ### Description The PnL subgraph tracks user positions including average buy price, realized profit/loss, and current holdings. ### Method POST ### Endpoint /polymarket/polymarket-subgraph/graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Required - Variables for the GraphQL query, including the user's address. ### Request Example ```json { "query": "query UserPositions($user: String!) { userPositions(where: { user: $user }) { id user tokenId amount avgPrice realizedPnl totalBought } }", "variables": { "user": "0x1234567890abcdef1234567890abcdef12345678" } } ``` ### Response #### Success Response (200) - **userPositions** (Array) - An array of user position objects, each containing id, user, tokenId, amount, avgPrice, realizedPnl, and totalBought. #### Response Example ```json { "data": { "userPositions": [ { "id": "0x1234...0x5678...", "user": "0x1234567890abcdef...", "tokenId": "12345678901234567890", "amount": "500000000000000000", "avgPrice": "550000", "realizedPnl": "100000000", "totalBought": "1000000000000000000" } ] } } ``` ``` -------------------------------- ### Query Global USDC Balance - GraphQL Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query the total USDC balance across all tracked wallets in the subgraph. ```graphql query GlobalBalance { globalUSDCBalance(id: "") { id balance } } ``` -------------------------------- ### FPMM Subgraph - Liquidity Events Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Track funding additions and removals on market makers. ```APIDOC ## POST /graphql ### Description Query funding additions to a specific market maker. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Body ```json { "query": "query FundingAdditions($fpmm: String!) { fpmmFundingAdditions(where: { fpmm: $fpmm }, orderBy: timestamp, orderDirection: desc) { id timestamp fpmm { id } funder amountsAdded amountsRefunded sharesMinted } }", "variables": { "fpmm": "0x1234567890abcdef1234567890abcdef12345678" } } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **fpmmFundingAdditions** (Array) - A list of funding additions. - **id** (String) - Funding addition ID. - **timestamp** (String) - Unix timestamp of the event. - **fpmm** (Object) - The market maker associated with the event. - **id** (String) - FPMM address. - **funder** (String) - The address of the funder. - **amountsAdded** (String) - Amounts of collateral added. - **amountsRefunded** (String) - Amounts of collateral refunded. - **sharesMinted** (String) - Shares minted to the funder. #### Response Example ```json { "data": { "fpmmFundingAdditions": [ { "id": "funding1", "timestamp": "1678886400", "fpmm": { "id": "0x1234567890abcdef1234567890abcdef12345678" }, "funder": "0xfunder123...", "amountsAdded": "50000000000000000000", "amountsRefunded": "0", "sharesMinted": "50000000000000000000" } ] } } ``` ``` ```APIDOC ## POST /graphql ### Description Query funding removals from a specific market maker. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Body ```json { "query": "query FundingRemovals($fpmm: String!) { fpmmFundingRemovals(where: { fpmm: $fpmm }, orderBy: timestamp, orderDirection: desc) { id timestamp fpmm { id } funder amountsRemoved collateralRemoved sharesBurnt } }", "variables": { "fpmm": "0x1234567890abcdef1234567890abcdef12345678" } } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **fpmmFundingRemovals** (Array) - A list of funding removals. - **id** (String) - Funding removal ID. - **timestamp** (String) - Unix timestamp of the event. - **fpmm** (Object) - The market maker associated with the event. - **id** (String) - FPMM address. - **funder** (String) - The address of the funder. - **amountsRemoved** (String) - Amounts of collateral removed. - **collateralRemoved** (String) - Total collateral removed. - **sharesBurnt** (String) - Shares burnt by the funder. #### Response Example ```json { "data": { "fpmmFundingRemovals": [ { "id": "funding2", "timestamp": "1678886400", "fpmm": { "id": "0x1234567890abcdef1234567890abcdef12345678" }, "funder": "0xfunder123...", "amountsRemoved": "10000000000000000000", "collateralRemoved": "10000000000000000000", "sharesBurnt": "10000000000000000000" } ] } } ``` ``` -------------------------------- ### FPMM Subgraph - Trading Transactions Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query buy and sell transactions on Fixed Product Market Makers. ```APIDOC ## POST /graphql ### Description Query recent buy and sell transactions for a specific market on an FPMM. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Body ```json { "query": "query MarketTrades($market: String!) { fpmmTransactions(where: { market: $market }, orderBy: timestamp, orderDirection: desc, first: 100) { id type timestamp market user tradeAmount feeAmount outcomeIndex outcomeTokensAmount } }", "variables": { "market": "0x1234567890abcdef1234567890abcdef12345678" } } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **fpmmTransactions** (Array) - A list of recent transactions. - **id** (String) - Transaction ID. - **type** (String) - Type of transaction (e.g., 'buy', 'sell'). - **timestamp** (String) - Unix timestamp of the transaction. - **market** (String) - The market address. - **user** (String) - The user's address. - **tradeAmount** (String) - The amount traded. - **feeAmount** (String) - The fee paid for the transaction. - **outcomeIndex** (String) - The index of the outcome. - **outcomeTokensAmount** (String) - The amount of outcome tokens. #### Response Example ```json { "data": { "fpmmTransactions": [ { "id": "tx1", "type": "buy", "timestamp": "1678886400", "market": "0x1234567890abcdef1234567890abcdef12345678", "user": "0xuser123...", "tradeAmount": "1000000000000000000", "feeAmount": "10000000000000000", "outcomeIndex": "0", "outcomeTokensAmount": "0.99" } ] } } ``` ``` -------------------------------- ### Query Recent Trades on a Market Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Fetch recent buy and sell transactions on a Fixed Product Market Maker. Filters by market address and orders by timestamp. ```graphql query MarketTrades($market: String!) { fpmmTransactions( where: { market: $market } orderBy: timestamp orderDirection: desc first: 100 ) { id type timestamp market user tradeAmount feeAmount outcomeIndex outcomeTokensAmount } } # Variables: { "market": "0x1234567890abcdef1234567890abcdef12345678" } ``` -------------------------------- ### Query Funding Removals from a Market Maker Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Track funding removals from a specific market maker. Requires the market maker's address and orders results by timestamp. ```graphql query FundingRemovals($fpmm: String!) { fpmmFundingRemovals(where: { fpmm: $fpmm }, orderBy: timestamp, orderDirection: desc) { id timestamp fpmm { id } funder amountsRemoved collateralRemoved sharesBurnt } } ``` -------------------------------- ### Activity Subgraph - NegRisk Conversions Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Track conversions within NegRisk (multi-outcome) markets where positions are converted between outcome tokens using the activity subgraph. ```APIDOC ## Activity Subgraph - NegRisk Conversions ### Description Track conversions within NegRisk (multi-outcome) markets where positions are converted between outcome tokens using the activity subgraph. ### Method POST ### Endpoint /polymarket/polymarket-subgraph/graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Example ```json { "query": "query NegRiskConversions { negRiskConversions(first: 10) { id timestamp stakeholder negRiskMarketId amount indexSet questionCount } }" } ``` ### Response #### Success Response (200) - **negRiskConversions** (Array) - An array of NegRisk conversion objects, each containing id, timestamp, stakeholder, negRiskMarketId, amount, indexSet, and questionCount. #### Response Example ```json { "data": { "negRiskConversions": [ { "id": "0xabc123...", "timestamp": "1699000000", "stakeholder": "0x1234567890abcdef...", "negRiskMarketId": "0xdef456...", "amount": "1000000000000000000", "indexSet": "0", "questionCount": "1" } ] } } ``` ``` -------------------------------- ### Query Market Open Interest Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Retrieve the open interest for a specific market condition. Requires the condition ID. ```graphql query MarketOpenInterest($conditionId: ID!) { marketOpenInterest(id: $conditionId) { id amount } } ``` -------------------------------- ### Query Pool Members for a Market Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Retrieve liquidity provider positions in a specific market maker pool. Filters for members with a positive amount. ```graphql query PoolMembers($pool: String!) { fpmmPoolMemberships(where: { pool: $pool, amount_gt: "0" }) { id pool { id } funder amount } } ``` -------------------------------- ### Query Sports Markets for a Game Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Retrieve sports market data, including spreads and totals, for a specific game. Requires the game ID. ```graphql # Query markets for a game query GameMarkets($gameId: String!) { markets(where: { gameId: $gameId }) { id gameId state marketType underdog line payouts } } ``` -------------------------------- ### FPMM Subgraph - Market Maker Data Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt The FPMM subgraph tracks Fixed Product Market Makers including liquidity, volume, and pricing data. ```APIDOC ## POST /graphql ### Description Query detailed data for a specific Fixed Product Market Maker (FPMM) by its address. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Body ```json { "query": "query MarketMaker($address: ID!) { fixedProductMarketMaker(id: $address) { id creator creationTimestamp collateralToken { id name symbol decimals } conditions fee tradesQuantity buysQuantity sellsQuantity liquidityAddQuantity liquidityRemoveQuantity collateralVolume scaledCollateralVolume feeVolume liquidityParameter outcomeTokenAmounts outcomeTokenPrices outcomeSlotCount totalSupply } }", "variables": { "address": "0x1234567890abcdef1234567890abcdef12345678" } } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **fixedProductMarketMaker** (Object) - Details of the specified FPMM. - **id** (String) - The address of the FPMM. - **creator** (String) - The address of the FPMM creator. - **creationTimestamp** (String) - Timestamp of FPMM creation. - **collateralToken** (Object) - Information about the collateral token. - **id** (String) - Token address. - **name** (String) - Token name. - **symbol** (String) - Token symbol. - **decimals** (Int) - Token decimals. - **conditions** (String) - Conditions associated with the market maker. - **fee** (String) - The fee percentage. - **tradesQuantity** (String) - Total number of trades. - **buysQuantity** (String) - Total quantity of buy orders. - **sellsQuantity** (String) - Total quantity of sell orders. - **liquidityAddQuantity** (String) - Total liquidity added. - **liquidityRemoveQuantity** (String) - Total liquidity removed. - **collateralVolume** (String) - Total collateral volume. - **scaledCollateralVolume** (String) - Scaled total collateral volume. - **feeVolume** (String) - Total fee volume. - **liquidityParameter** (String) - Liquidity parameter. - **outcomeTokenAmounts** (String) - Amounts of outcome tokens. - **outcomeTokenPrices** (String) - Prices of outcome tokens. - **outcomeSlotCount** (String) - Number of outcome slots. - **totalSupply** (String) - Total supply of the market maker's tokens. #### Response Example ```json { "data": { "fixedProductMarketMaker": { "id": "0x1234567890abcdef1234567890abcdef12345678", "creator": "0xabc123...", "creationTimestamp": "1678886400", "collateralToken": { "id": "0x0000000000000000000000000000000000000001", "name": "USDC", "symbol": "USDC", "decimals": 6 }, "conditions": "...", "fee": "0.01", "tradesQuantity": "500", "buysQuantity": "200", "sellsQuantity": "300", "liquidityAddQuantity": "100000000000000000000", "liquidityRemoveQuantity": "20000000000000000000", "collateralVolume": "800000000000000000000", "scaledCollateralVolume": "800", "feeVolume": "8000000000000000000", "liquidityParameter": "...", "outcomeTokenAmounts": "[100, 200]", "outcomeTokenPrices": "[0.5, 0.5]", "outcomeSlotCount": "2", "totalSupply": "100000000000000000000" } } } ``` ``` -------------------------------- ### Query NegRisk Conversions - GraphQL Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query NegRisk conversions from the activity subgraph. Use 'first' to limit the number of results. ```graphql query NegRiskConversions { negRiskConversions(first: 10) { id timestamp stakeholder negRiskMarketId amount indexSet questionCount } } ``` -------------------------------- ### Query NegRisk Events Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Retrieve metadata for NegRisk market events, including fee basis points and question count. This query fetches all such events. ```graphql query NegRiskEvents { negRiskEvents { id feeBps questionCount } } ``` -------------------------------- ### Query Orderbook Statistics for a Token Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Retrieve aggregated orderbook volume and trade statistics for a specific token. Requires a token ID as input. ```graphql query OrderbookStats($tokenId: ID!) { orderbook(id: $tokenId) { id tradesQuantity buysQuantity sellsQuantity collateralVolume scaledCollateralVolume collateralBuyVolume scaledCollateralBuyVolume collateralSellVolume scaledCollateralSellVolume } } # Variables: { "tokenId": "123456789012345678901234567890" } ``` -------------------------------- ### Query Redemptions - GraphQL Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query redemptions with payout information from the activity subgraph. Use 'first' to limit results and 'orderBy'/'orderDirection' to sort. ```graphql query Redemptions { redemptions(first: 20, orderBy: payout, orderDirection: desc) { id timestamp redeemer condition indexSets payout } } ``` -------------------------------- ### Open Interest Subgraph - NegRisk Events Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query NegRisk market metadata including fee basis points. ```APIDOC ## POST /graphql ### Description Query NegRisk market events, including fee basis points and question count. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. ### Request Body ```json { "query": "query NegRiskEvents { negRiskEvents { id feeBps questionCount } }" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **negRiskEvents** (Array) - A list of NegRisk events. - **id** (String) - Event ID. - **feeBps** (String) - Fee in basis points. - **questionCount** (String) - Number of questions associated with the event. #### Response Example ```json { "data": { "negRiskEvents": [ { "id": "negRisk1", "feeBps": "100", "questionCount": "5" } ] } } ``` ``` -------------------------------- ### Open Interest Subgraph - Global Open Interest Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query the total open interest across all markets. ```APIDOC ## POST /graphql ### Description Query the total global open interest across all markets. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. ### Request Body ```json { "query": "query GlobalOI { globalOpenInterest(id: \"\") { id amount } }" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **globalOpenInterest** (Object) - Global open interest details. - **id** (String) - Identifier for global stats (usually empty). - **amount** (String) - The total amount of open interest. #### Response Example ```json { "data": { "globalOpenInterest": { "id": "", "amount": "150000" } } } ``` ``` -------------------------------- ### Sports Oracle Subgraph - Game Data Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt The sports oracle subgraph indexes game data from UMA Sports Oracle. ```APIDOC ## POST /graphql ### Description Query a list of games indexed by the Sports Oracle subgraph. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. ### Request Body ```json { "query": "query Games { games(first: 50) { id ancillaryData ordering state homeScore awayScore } }" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **games** (Array) - A list of game objects. - **id** (String) - The unique identifier for the game. - **ancillaryData** (String) - Additional data related to the game. - **ordering** (String) - Ordering information for the game. - **state** (String) - The current state of the game (e.g., 'Resolved'). - **homeScore** (String) - The score of the home team. - **awayScore** (String) - The score of the away team. #### Response Example ```json { "data": { "games": [ { "id": "0xabc123...", "ancillaryData": "q:\"NFL Game: Team A vs Team B\"", "ordering": "1", "state": "Resolved", "homeScore": "24", "awayScore": "17" } ] } } ``` ``` -------------------------------- ### Query User Positions with P&L - GraphQL Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query user positions with P&L data from the PnL subgraph. Requires a 'user' variable for filtering. ```graphql query UserPositions($user: String!) { userPositions(where: { user: $user }) { id user tokenId amount avgPrice realizedPnl totalBought } } ``` -------------------------------- ### Activity Subgraph - Track Redemptions Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query redemptions with payout information from the activity subgraph. This tracks when users redeem winning outcome tokens for collateral after market resolution. ```APIDOC ## Activity Subgraph - Track Redemptions ### Description Query redemptions with payout information from the activity subgraph. This tracks when users redeem winning outcome tokens for collateral after market resolution. ### Method POST ### Endpoint /polymarket/polymarket-subgraph/graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Example ```json { "query": "query Redemptions { redemptions(first: 20, orderBy: payout, orderDirection: desc) { id timestamp redeemer condition indexSets payout } }" } ``` ### Response #### Success Response (200) - **redemptions** (Array) - An array of redemption objects, each containing id, timestamp, redeemer, condition, indexSets, and payout. #### Response Example ```json { "data": { "redemptions": [ { "id": "0xabc123...", "timestamp": "1699000000", "redeemer": "0x1234567890abcdef...", "condition": "0xdef456...", "indexSets": "0", "payout": "1000000000000000000" } ] } } ``` ``` -------------------------------- ### Activity Subgraph - Track Position Splits Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query recent position splits from the activity subgraph. This tracks when users split collateral into outcome tokens on conditional token markets. ```APIDOC ## Activity Subgraph - Track Position Splits ### Description Query recent position splits from the activity subgraph. This tracks when users split collateral into outcome tokens on conditional token markets. ### Method POST ### Endpoint /polymarket/polymarket-subgraph/graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Example ```json { "query": "query RecentSplits { splits(first: 10, orderBy: timestamp, orderDirection: desc) { id timestamp stakeholder condition amount } }" } ``` ### Response #### Success Response (200) - **splits** (Array) - An array of split objects, each containing id, timestamp, stakeholder, condition, and amount. #### Response Example ```json { "data": { "splits": [ { "id": "0xabc123...", "timestamp": "1699000000", "stakeholder": "0x1234567890abcdef...", "condition": "0xdef456...", "amount": "1000000000000000000" } ] } } ``` ``` -------------------------------- ### Orderbook Subgraph - Global Volume Statistics Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query global exchange volume across all orderbooks. ```APIDOC ## POST /graphql ### Description Query global exchange volume and trade statistics across all orderbooks. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. ### Request Body ```json { "query": "query GlobalStats { ordersMatchedGlobal(id: \"\") { id tradesQuantity buysQuantity sellsQuantity collateralVolume scaledCollateralVolume collateralBuyVolume scaledCollateralBuyVolume collateralSellVolume scaledCollateralSellVolume } }" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **ordersMatchedGlobal** (Object) - Global statistics for matched orders. - **id** (String) - Identifier for global stats (usually empty). - **tradesQuantity** (String) - Total number of trades globally. - **buysQuantity** (String) - Total quantity of buy orders globally. - **sellsQuantity** (String) - Total quantity of sell orders globally. - **collateralVolume** (String) - Total collateral volume globally. - **scaledCollateralVolume** (String) - Scaled total collateral volume globally. - **collateralBuyVolume** (String) - Collateral volume for buy orders globally. - **scaledCollateralBuyVolume** (String) - Scaled collateral volume for buy orders globally. - **collateralSellVolume** (String) - Collateral volume for sell orders globally. - **scaledCollateralSellVolume** (String) - Scaled collateral volume for sell orders globally. #### Response Example ```json { "data": { "ordersMatchedGlobal": { "id": "", "tradesQuantity": "10000", "buysQuantity": "5000", "sellsQuantity": "5000", "collateralVolume": "5000000000000000000000", "scaledCollateralVolume": "5000", "collateralBuyVolume": "2500000000000000000000", "scaledCollateralBuyVolume": "2500", "collateralSellVolume": "2500000000000000000000", "scaledCollateralSellVolume": "2500" } } } ``` ``` -------------------------------- ### FPMM Subgraph - Pool Membership Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query liquidity provider positions in market makers. ```APIDOC ## POST /graphql ### Description Query liquidity provider positions (pool memberships) for a specific market maker pool. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Body ```json { "query": "query PoolMembers($pool: String!) { fpmmPoolMemberships(where: { pool: $pool, amount_gt: \"0\" }) { id pool { id } funder amount } }", "variables": { "pool": "0x1234567890abcdef1234567890abcdef12345678" } } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **fpmmPoolMemberships** (Array) - A list of pool memberships. - **id** (String) - Membership ID. - **pool** (Object) - The market maker pool. - **id** (String) - Pool address. - **funder** (String) - The address of the liquidity provider. - **amount** (String) - The amount of liquidity provided. #### Response Example ```json { "data": { "fpmmPoolMemberships": [ { "id": "membership1", "pool": { "id": "0x1234567890abcdef1234567890abcdef12345678" }, "funder": "0xfunder123...", "amount": "50000000000000000000" } ] } } ``` ``` -------------------------------- ### PnL Subgraph - Condition Resolution Data Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query condition resolution information including payout numerators and denominators from the PnL subgraph. ```APIDOC ## PnL Subgraph - Condition Resolution Data ### Description Query condition resolution information including payout numerators and denominators from the PnL subgraph. ### Method POST ### Endpoint /polymarket/polymarket-subgraph/graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Example ```json { "query": "query ResolvedConditions { conditions(where: { payoutDenominator_gt: \"0\" }) { id positionIds payoutNumerators payoutDenominator } }" } ``` ### Response #### Success Response (200) - **conditions** (Array) - An array of condition objects, each containing id, positionIds, payoutNumerators, and payoutDenominator. #### Response Example ```json { "data": { "conditions": [ { "id": "0xabc123...", "positionIds": ["1", "2"], "payoutNumerators": ["1000000000000000000", "0"], "payoutDenominator": "1000000000000000000" } ] } } ``` ``` -------------------------------- ### Orderbook Subgraph - Market Volume Statistics Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query aggregated orderbook volume and trade statistics per token. ```APIDOC ## POST /graphql ### Description Query orderbook statistics for a specific token. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Body ```json { "query": "query OrderbookStats($tokenId: ID!) { orderbook(id: $tokenId) { id tradesQuantity buysQuantity sellsQuantity collateralVolume scaledCollateralVolume collateralBuyVolume scaledCollateralBuyVolume collateralSellVolume scaledCollateralSellVolume } }", "variables": { "tokenId": "123456789012345678901234567890" } } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **orderbook** (Object) - Statistics for the specified orderbook. - **id** (String) - The unique identifier for the orderbook. - **tradesQuantity** (String) - Total number of trades. - **buysQuantity** (String) - Total quantity of buy orders. - **sellsQuantity** (String) - Total quantity of sell orders. - **collateralVolume** (String) - Total collateral volume. - **scaledCollateralVolume** (String) - Scaled total collateral volume. - **collateralBuyVolume** (String) - Collateral volume for buy orders. - **scaledCollateralBuyVolume** (String) - Scaled collateral volume for buy orders. - **collateralSellVolume** (String) - Collateral volume for sell orders. - **scaledCollateralSellVolume** (String) - Scaled collateral volume for sell orders. #### Response Example ```json { "data": { "orderbook": { "id": "123456789012345678901234567890", "tradesQuantity": "150", "buysQuantity": "70", "sellsQuantity": "80", "collateralVolume": "100000000000000000000", "scaledCollateralVolume": "100", "collateralBuyVolume": "50000000000000000000", "scaledCollateralBuyVolume": "50", "collateralSellVolume": "50000000000000000000", "scaledCollateralSellVolume": "50" } } } ``` ``` -------------------------------- ### Open Interest Subgraph - Market Open Interest Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt The OI subgraph tracks open interest per market condition. ```APIDOC ## POST /graphql ### Description Query the open interest for a specific market condition. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Optional - Variables for the GraphQL query. ### Request Body ```json { "query": "query MarketOpenInterest($conditionId: ID!) { marketOpenInterest(id: $conditionId) { id amount } }", "variables": { "conditionId": "condition123" } } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **marketOpenInterest** (Object) - Open interest details for the condition. - **id** (String) - The condition ID. - **amount** (String) - The amount of open interest. #### Response Example ```json { "data": { "marketOpenInterest": { "id": "condition123", "amount": "1000" } } } ``` ``` ```APIDOC ## POST /graphql ### Description Query the top 100 markets by open interest. ### Method POST ### Endpoint /graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. ### Request Body ```json { "query": "query AllMarketsOI { marketOpenInterests(orderBy: amount, orderDirection: desc, first: 100) { id amount } }" } ``` ### Response #### Success Response (200) - **data** (Object) - Contains the query results. - **marketOpenInterests** (Array) - A list of markets with their open interest. - **id** (String) - The condition ID. - **amount** (String) - The amount of open interest. #### Response Example ```json { "data": { "marketOpenInterests": [ { "id": "condition123", "amount": "1000" }, { "id": "condition456", "amount": "950" } ] } } ``` ``` -------------------------------- ### Polygon Mainnet Contract Addresses - YAML Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Reference contract addresses for Polygon (Matic) network integration. ```yaml # Polygon (Matic) Contract Addresses ConditionalTokens: '0x4D97DCd97eC945f40cF65F87097ACe5EA0476045' FixedProductMarketMakerFactory: '0x8B9805A2f595B6705e74F7310829f2d299D21522' Exchange: '0x4bFb41d5B3570DeFd03C39a9A4D8dE6Bd8B8982E' NegRiskExchange: '0xC5d563A36AE78145C45a50134d48A1215220f80a' NegRiskAdapter: '0xd91E80cF2E7be2e162c6513ceD06f1dD0dA35296' USDC: '0x2791Bca1f2de4661ED88A30C99A7a9449Aa84174' UmaSportsOracle: '0xb21182d0494521Cf45DbbeEbb5A3ACAAb6d22093' FeeModule: '0xE3f18aCc55091e2c48d883fc8C8413319d4Ab7b0' NegRiskFeeModule: '0xB768891e3130F6dF18214Ac804d4DB76c2C37730' ``` -------------------------------- ### Activity Subgraph - Track Position Merges Source: https://context7.com/polymarket/polymarket-subgraph/llms.txt Query merges for a specific stakeholder from the activity subgraph. This tracks when users merge outcome tokens back into collateral. ```APIDOC ## Activity Subgraph - Track Position Merges ### Description Query merges for a specific stakeholder from the activity subgraph. This tracks when users merge outcome tokens back into collateral. ### Method POST ### Endpoint /polymarket/polymarket-subgraph/graphql ### Parameters #### Query Parameters - **query** (String) - Required - The GraphQL query string. - **variables** (JSON) - Required - Variables for the GraphQL query, including the user's address. ### Request Example ```json { "query": "query UserMerges($user: String!) { merges(where: { stakeholder: $user }, orderBy: timestamp, orderDirection: desc) { id timestamp stakeholder condition amount } }", "variables": { "user": "0x1234567890abcdef1234567890abcdef12345678" } } ``` ### Response #### Success Response (200) - **merges** (Array) - An array of merge objects, each containing id, timestamp, stakeholder, condition, and amount. #### Response Example ```json { "data": { "merges": [ { "id": "0xabc123...", "timestamp": "1699000000", "stakeholder": "0x1234567890abcdef...", "condition": "0xdef456...", "amount": "1000000000000000000" } ] } } ``` ```