Documentation Index
Fetch the complete documentation index at: https://docs.struct.to/llms.txt
Use this file to discover all available pages before exploring further.
client.trader.getTraderOutcomePnl returns one row per outcome a wallet has ever traded, with current_shares_balance, realized_pnl_usd, and supporting fields. That single response covers both halves of a portfolio view: open positions (still held) and closed positions (fully exited). The same row shape is pushed live by polymarket_trader_positions, so a portfolio UI seeded from REST can stay in sync with one merge key.
When to use this
- Wallet portfolio pages with separate “Open” and “Closed” sections.
- Leaderboard drilldowns where clicking a trader expands to their bets.
- “My open bets” UI for an authenticated user, with realized PnL surfaced for closed exits.
Open vs closed model
A position is open whencurrent_shares_balance > 0: the wallet still holds outcome tokens, so the row has both unrealised exposure and realized PnL from any partial sells. A position is closed when current_shares_balance === 0: the wallet has fully exited (sold or redeemed), and only realized_pnl_usd remains relevant.
The same row carries both halves of the lifecycle, which means you do not need two endpoints. Filter once in client code.
Step 1: fetch the position book
Usemin_shares: 0 to include closed rows; bump it to drop dust positions.
Step 2: split and sort
Open positions usually rank by current mark-to-market value. Closed positions rank by realized PnL.Step 3: scope to a timeframe
Passtimeframe to limit realized_pnl_usd (and any windowed counters) to a window: 1d, 7d, 30d, or lifetime. Use this to drive period switchers on the portfolio header.
event_slug or condition_id, useful for “this trader’s bets on the election” drilldowns.
Step 4: keep it live
Subscribe topolymarket_trader_positions with the same address. Every trader_position_update carries (trader, position_id) plus current_shares_balance and realized_pnl_usd, so merging into the REST-seeded map is one-to-one.
current_shares_balance flips to 0, move that row from the Open list to the Closed list in your UI. When it ticks up from 0, the trader has re-entered an old position; move the row back.
Common combinations
| Goal | Parameters |
|---|---|
| Lifetime portfolio (open + closed) | address=0x...&min_shares=0&timeframe=lifetime |
| Weekly performance | address=0x...&timeframe=7d |
| Drop dust | address=0x...&min_shares=10 |
| Bets on one event | address=0x...&event_slug=us-election-2028 |
| Sort by realized PnL | address=0x...&sort_by=realized_pnl_usd |
Pagination
For traders with long histories, the SDK’spaginate helper walks every page without manual cursor handling.
offset and pagination_key interact.