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

# Redemption

> How to collect payout from settled winning positions on Polymarket

When a Polymarket position settles in your favor, redeem your winning side to collect payout.
This page follows the same operational structure as the Simmer guide, adapted to the currently documented Aionmarket capabilities.

Base URL used in examples:

`https://www.aionmarket.com/bvapi`

## Position lifecycle

<Steps>
  <Step title="Active">
    Market is still trading. You can hold, reduce, or close the position.
  </Step>

  <Step title="Awaiting settlement">
    The market window has ended, but venue settlement is not final yet. Nothing to redeem at this stage.
  </Step>

  <Step title="Ready to redeem">
    Settlement is finalized and your winning side is redeemable.
  </Step>

  <Step title="Redeemed">
    Redemption is complete and the payout is returned to your wallet.
  </Step>
</Steps>

If your side lost, there is no redeemable payout for that position.

## Automated redemption loop

The current SDK exposes `redeem()` but does not expose a one-call `auto_redeem()` helper.
Recommended pattern: in your agent loop, detect redeemable candidates from briefing/positions and call `redeem()` per item.

<Tabs>
  <Tab title="Python">
    ```python theme={null}
    from aion_sdk import AionMarketClient
    import requests
    import time

    client = AionMarketClient(api_key="YOUR_API_KEY", base_url="https://www.aionmarket.com/bvapi")

    while True:
        briefing = client.get_briefing(user="0xYOUR_WALLET", include_markets=False, venue="polymarket")
        positions = requests.get(
            "https://www.aionmarket.com/bvapi/markets/current-positions",
            headers={"Authorization": "Bearer YOUR_API_KEY"},
            params={"user": "0xYOUR_WALLET", "venue": "polymarket"},
            timeout=30,
        ).json()

        # Replace this filter with your real redeemable signal from position fields.
        redeemable = [p for p in positions if p.get("marketStatus") == "resolved" and p.get("pnl", 0) > 0]

        for p in redeemable:
            tx_payload = client.redeem(
                market_id=p["marketId"],
                side=p["side"],
                venue="polymarket",
                wallet_address="0xYOUR_WALLET",
            )
            print("Unsigned redeem tx:", tx_payload)

        time.sleep(60)
    ```
  </Tab>
</Tabs>

## Manual redeem

Use this when you need to redeem a specific market immediately.

<Tabs>
  <Tab title="curl">
    ```bash theme={null}
    curl -X POST https://www.aionmarket.com/bvapi/markets/redeem \
      -H "Authorization: Bearer YOUR_API_KEY" \
      -H "Content-Type: application/json" \
      -d '{
        "marketId":"MARKET_ID",
        "side":"YES",
        "venue":"polymarket",
        "walletAddress":"0xYOUR_WALLET"
      }'
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from aion_sdk import AionMarketClient

    client = AionMarketClient(api_key="YOUR_API_KEY", base_url="https://www.aionmarket.com/bvapi")

    redeem_tx = client.redeem(
        market_id="MARKET_ID",
        side="YES",
        venue="polymarket",
        wallet_address="0xYOUR_WALLET",
    )

    print(redeem_tx)
    ```
  </Tab>
</Tabs>

## Build your own signing flow

If you are not using a higher-level wallet helper, handle redemption in three steps:

<Steps>
  <Step title="1. Request unsigned redemption transaction">
    Call `POST /markets/redeem` and store the unsigned tx payload.
  </Step>

  <Step title="2. Sign and broadcast locally">
    Sign the payload with your wallet key in your own execution environment, then broadcast through your on-chain integration.
  </Step>

  <Step title="3. Verify state is cleared">
    Re-check positions and briefing until that market no longer appears as redeemable/pending redemption.
  </Step>
</Steps>

## Gas requirements (Polymarket)

* Redemption is on-chain and requires Polygon gas.
* Keep enough gas token in the wallet used for redemption signing.
* If gas is insufficient, redemption will fail until the wallet is topped up.

## Troubleshooting: why a position is still active

If the market end time passed but your position is still active, settlement may still be pending at venue level.

### Check settlement status first

Use briefing and positions together:

<Tabs>
  <Tab title="curl">
    ```bash theme={null}
    curl -H "Authorization: Bearer YOUR_API_KEY" \
      "https://www.aionmarket.com/bvapi/markets/briefing?venue=polymarket&user=0xYOUR_WALLET&includeMarkets=false"

    curl -H "Authorization: Bearer YOUR_API_KEY" \
      "https://www.aionmarket.com/bvapi/markets/current-positions?venue=polymarket&user=0xYOUR_WALLET"
    ```
  </Tab>

  <Tab title="Python">
    ```python theme={null}
    from aion_sdk import AionMarketClient
    import requests

    client = AionMarketClient(api_key="YOUR_API_KEY", base_url="https://www.aionmarket.com/bvapi")

    briefing = client.get_briefing(user="0xYOUR_WALLET", include_markets=False, venue="polymarket")
    positions = requests.get(
        "https://www.aionmarket.com/bvapi/markets/current-positions",
        headers={"Authorization": "Bearer YOUR_API_KEY"},
        params={"user": "0xYOUR_WALLET", "venue": "polymarket"},
        timeout=30,
    ).json()

    print(briefing)
    print(positions)
    ```
  </Tab>
</Tabs>

### Common errors

* Market not settled yet: wait and retry later.
* Wrong side: only the winning side has redeemable value.
* Already redeemed: treat as idempotent completion in your loop.
* Insufficient gas for on-chain redemption: top up and retry.

### If settlement is taking too long

1. Keep polling `GET /markets/briefing` and `GET /markets/current-positions`.
2. Confirm the market is finalized on the venue side.
3. If venue is settled but status still does not update, escalate with API logs and request IDs.

## Next steps

<CardGroup cols={2}>
  <Card title="Trading guide" icon="chart-line" href="/essentials/trading-guide">
    Follow the full execution loop from discovery to exits.
  </Card>

  <Card title="Heartbeat pattern" icon="compass" href="/essentials/heartbeat">
    Run periodic monitoring and action loops safely.
  </Card>

  <Card title="Place trade API" icon="code" href="/api-reference/endpoint/place-trade">
    Review trade request structure and fill handling.
  </Card>

  <Card title="Wallet setup" icon="wallet" href="/essentials/wallet-setup">
    Verify wallet credentials and live trading prerequisites.
  </Card>
</CardGroup>
