> ## Documentation Index
> Fetch the complete documentation index at: https://docs.codex.io/llms.txt
> Use this file to discover all available pages before exploring further.

# detailedPredictionTraderStats

> Returns windowed and all-time stats for a prediction trader.

<Info>
  **Prediction Market data is currently in beta**. It is actively being worked on and improved, but may be unreliable. Polymarket and Kalshi data are live.

  At least for the time being, this endpoint requires a Growth or Enterprise plan. [Learn more](https://dashboard.codex.io/dashboard/billing?utm_source=codex\&utm_medium=docs\&utm_campaign=billing).
</Info>

<Info>
  **Kalshi does not provide trader data**. These endpoints only work with Polymarket data. Kalshi's API does not expose individual trader information due to privacy considerations on their regulated exchange.
</Info>

<div data-generated>
  ## GraphQL

  ```
  type Query {
    # Requires a Growth or Enterprise plan.
    detailedPredictionTraderStats(
      input: DetailedPredictionTraderStatsInput!
    ): DetailedPredictionTraderStats
  }

  enum PredictionProtocol {
    POLYMARKET
    KALSHI
  }

  type PredictionTrader {
    id: String!
    protocol: PredictionProtocol!
    venueTraderId: String!
    alias: String
    primaryAddress: String
    linkedAddresses: [String!]
    profileImageUrl: String
    profileUrl: String
    totalTradesCount: Int!
    totalVolumeUsd: String!
    totalVolumeCT: String!
    firstTradeTimestamp: Int!
    lastTradeTimestamp: Int!
    biggestWinUsd: String!
    biggestWinCT: String!
    biggestLossUsd: String!
    biggestLossCT: String!
    allTimeProfitUsd: String!
    allTimeProfitCT: String!
    activeMarketsCount: Int!
    labels: [String!]
    createdAt: Int!
    updatedAt: Int!
  }

  type WindowedPredictionTraderCurrencyStats {
    volumeUsd: String!
    buyVolumeUsd: String!
    sellVolumeUsd: String!
    volumeCT: String!
    buyVolumeCT: String!
    sellVolumeCT: String!
    realizedPnlUsd: String!
    realizedPnlCT: String!
    realizedProfitPercentage: Float!
    averageProfitUsdPerTrade: String!
    averageProfitCTPerTrade: String!
    averageSwapAmountUsd: String!
    averageSwapAmountCT: String!
    heldTokenAcquisitionCostUsd: String!
    heldTokenAcquisitionCostCT: String!
    soldTokenAcquisitionCostUsd: String!
    soldTokenAcquisitionCostCT: String!
  }

  type WindowedPredictionTraderNonCurrencyStats {
    trades: Int!
    buys: Int!
    sells: Int!
    uniqueMarkets: Int!
    wins: Int!
    losses: Int!
  }

  type WindowedPredictionTraderChangeStats {
    volumeChange: Float!
    buyVolumeChange: Float!
    sellVolumeChange: Float!
    realizedPnlChange: Float!
    tradesChange: Float!
    uniqueMarketsChange: Float!
    winsChange: Float!
    lossesChange: Float!
  }

  type EnhancedWindowedPredictionTraderStats {
    start: Int!
    end: Int!
    lastTransactionAt: Int!
    statsCurrency: WindowedPredictionTraderCurrencyStats!
    statsNonCurrency: WindowedPredictionTraderNonCurrencyStats!
    statsChange: WindowedPredictionTraderChangeStats!
  }

  type WindowedPredictionTraderAllTimeStats {
    totalVolumeUsd: String!
    totalVolumeCT: String!
    totalProfitUsd: String!
    totalProfitCT: String!
  }

  type DetailedPredictionTraderStats {
    traderId: String!
    trader: PredictionTrader!
    lastTransactionAt: Int!
    statsHour1: EnhancedWindowedPredictionTraderStats
    statsHour4: EnhancedWindowedPredictionTraderStats
    statsHour12: EnhancedWindowedPredictionTraderStats
    statsDay1: EnhancedWindowedPredictionTraderStats
    statsWeek1: EnhancedWindowedPredictionTraderStats
    statsDay30: EnhancedWindowedPredictionTraderStats
    allTimeStats: WindowedPredictionTraderAllTimeStats!
  }

  enum PredictionTraderStatsDuration {
    day30
    week1
    day1
    hour12
    hour4
    hour1
  }

  input DetailedPredictionTraderStatsInput {
    traderId: String!
    timestamp: Int
    durations: [PredictionTraderStatsDuration!]
  }
  ```
</div>

## Example: Get detailed stats for a specific trader

<a href="/explore" target="_blank" rel="noopener noreferrer">Test this query in the Explorer →</a>

```graphql theme={null}
{
  detailedPredictionTraderStats(
    input: {
      traderId: "0x6904db029589e17f69209646381b6d663d695b63:Polymarket"
    }
  ) {
    trader {
      protocol
      alias
      primaryAddress
      totalVolumeUsd
      allTimeProfitUsd
      totalTradesCount
      activeMarketsCount
      firstTradeTimestamp
      lastTradeTimestamp
    }
    lastTransactionAt
    statsHour1 {
      start
      end
      statsCurrency {
        volumeUsd
        buyVolumeUsd
        sellVolumeUsd
        realizedPnlUsd
        realizedProfitPercentage
      }
      statsNonCurrency {
        trades
        buys
        sells
        uniqueMarkets
        wins
        losses
      }
    }
    statsDay1 {
      statsCurrency {
        volumeUsd
        realizedPnlUsd
        realizedProfitPercentage
        averageProfitUsdPerTrade
      }
      statsNonCurrency {
        trades
        uniqueMarkets
        wins
        losses
      }
    }
    statsWeek1 {
      statsCurrency {
        volumeUsd
        realizedPnlUsd
      }
      statsNonCurrency {
        trades
        uniqueMarkets
      }
    }
    allTimeStats {
      totalVolumeUsd
      totalProfitUsd
    }
  }
}
```

```json Example Response theme={null}
{
  "data": {
    "detailedPredictionTraderStats": {
      "trader": {
        "protocol": "POLYMARKET",
        "alias": "Humayun331",
        "primaryAddress": null,
        "totalVolumeUsd": "986.210827",
        "allTimeProfitUsd": "-47.22606",
        "totalTradesCount": 47,
        "activeMarketsCount": 0,
        "firstTradeTimestamp": 1770930921,
        "lastTradeTimestamp": 1773267363
      },
      "lastTransactionAt": 1773267363,
      "statsHour1": {
        "start": 1773331200,
        "end": 1773338400,
        "statsCurrency": {
          "volumeUsd": "0",
          "buyVolumeUsd": "0",
          "sellVolumeUsd": "0",
          "realizedPnlUsd": "0",
          "realizedProfitPercentage": 0
        },
        "statsNonCurrency": {
          "trades": 0,
          "buys": 0,
          "sells": 0,
          "uniqueMarkets": 0,
          "wins": 0,
          "losses": 0
        }
      },
      "statsDay1": {
        "statsCurrency": {
          "volumeUsd": "5.988248",
          "realizedPnlUsd": "-0.005655",
          "realizedProfitPercentage": -0.0009434587112937931,
          "averageProfitUsdPerTrade": "-0.005655"
        },
        "statsNonCurrency": {
          "trades": 1,
          "uniqueMarkets": 1,
          "wins": 0,
          "losses": 1
        }
      },
      "statsWeek1": {
        "statsCurrency": {
          "volumeUsd": "41.960793",
          "realizedPnlUsd": "-35.922884"
        },
        "statsNonCurrency": {
          "trades": 12,
          "uniqueMarkets": 7
        }
      },
      "allTimeStats": {
        "totalVolumeUsd": "986.210827",
        "totalProfitUsd": "-47.22606"
      }
    }
  }
}
```

## Example: Query trader stats across multiple time windows

```graphql theme={null}
{
  detailedPredictionTraderStats(
    input: {
      traderId: "0x6904db029589e17f69209646381b6d663d695b63:Polymarket"
      durations: [hour1, hour4, day1, week1]
    }
  ) {
    traderId
    trader {
      alias
      totalVolumeUsd
    }
    statsHour1 {
      statsCurrency {
        volumeUsd
        realizedPnlUsd
      }
      statsChange {
        volumeChange
        realizedPnlChange
      }
    }
    statsHour4 {
      statsCurrency {
        volumeUsd
        realizedPnlUsd
      }
      statsChange {
        volumeChange
      }
    }
    statsDay1 {
      statsCurrency {
        volumeUsd
        realizedPnlUsd
      }
    }
    statsWeek1 {
      statsCurrency {
        volumeUsd
        realizedPnlUsd
      }
    }
  }
}
```

```json Example Response theme={null}
{
  "data": {
    "detailedPredictionTraderStats": {
      "traderId": "0x6904db029589e17f69209646381b6d663d695b63:Polymarket",
      "trader": {
        "alias": "Humayun331",
        "totalVolumeUsd": "986.210827"
      },
      "statsHour1": {
        "statsCurrency": {
          "volumeUsd": "0",
          "realizedPnlUsd": "0"
        },
        "statsChange": {
          "volumeChange": 0,
          "realizedPnlChange": 0
        }
      },
      "statsHour4": {
        "statsCurrency": {
          "volumeUsd": "0",
          "realizedPnlUsd": "0"
        },
        "statsChange": {
          "volumeChange": 0
        }
      },
      "statsDay1": {
        "statsCurrency": {
          "volumeUsd": "5.988248",
          "realizedPnlUsd": "-0.005655"
        }
      },
      "statsWeek1": {
        "statsCurrency": {
          "volumeUsd": "41.960793",
          "realizedPnlUsd": "-35.922884"
        }
      }
    }
  }
}
```

### Usage Guidelines

* Use this query to get comprehensive statistics for a single prediction trader
* Trader stats aggregate data from all markets and trades for that trader
* Windowed statistics are available for multiple time periods: 1h, 4h, 12h, 1d, 1w, 30d
* The `traderId` format is `<address>:<protocol>` (e.g., `0x6904db029589e17f69209646381b6d663d695b63:Polymarket`)
* Find trader IDs using [`filterPredictionTraders`](/api-reference/queries/filterpredictiontraders) or from the `trader { id }` field on prediction trades
* Returns `null` if the trader doesn't exist or has no available data
* Use the `durations` parameter to request only specific time windows and optimize query performance

### Troubleshooting Tips

<AccordionGroup>
  <Accordion title="How is realized PnL calculated?">
    Realized PnL (profit and loss) represents actual profits or losses from closed positions within the time window. It's calculated by comparing the sale price of outcome tokens to their acquisition cost. A positive `realizedPnlUsd` means the trader made a profit on closed positions, while negative values indicate losses. This excludes unrealized PnL from open positions. The `realizedProfitPercentage` shows this as a percentage return on invested capital.
  </Accordion>

  <Accordion title="What's the difference between wins/losses and positive/negative PnL?">
    `wins` and `losses` count the number of individual trades that were profitable vs. unprofitable. A trader could have more wins than losses but still have negative overall PnL if their losses were larger than their wins. The `realizedPnlUsd` metric shows the actual dollar amount of profit/loss, which is more important for evaluating trader performance than win/loss ratio alone.
  </Accordion>

  <Accordion title="What's the difference between trader stats and event stats?">
    Trader stats track the performance and activity of a specific wallet address across all prediction markets. Event stats aggregate all trading activity across all traders for a specific prediction event. Use [`detailedPredictionTraderStats`](/api-reference/queries/detailedpredictiontraderstats) to analyze individual trader behavior, profitability, and trading patterns. Use [`detailedPredictionEventStats`](/api-reference/queries/detailedpredictioneventstats) to understand market-level activity.
  </Accordion>
</AccordionGroup>

### Related Recipes

* [Prediction Traders](/recipes/predictions/traders): Build trader profile pages with windowed stats and performance charts
