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

# Polymarket Close Position

Close (sell) a Polymarket position by selling shares. Sells all shares by default, or a specified number. Uses market pricing for immediate fills. Ideal for: exiting positions, taking profits, stop-loss automation, portfolio rebalancing.

![Polymarket Close Position logo](https://cdn.b3.fun/b3os-icons/polymarket-icon.png)
Catalog action EVM Onchain wallet swap

Close (sell) a Polymarket position by selling shares. Sells all shares by default, or a specified number. Uses market pricing for immediate fills. Ideal for: exiting positions, taking profits, stop-loss automation, portfolio rebalancing.

**Review wallet and value movement**

This action can require a wallet connector, gas, token movement, or an external side effect. Test with simulation or a controlled amount before using it in a live workflow.

## At a Glance

| Field | Value |
| --- | --- |
| Action ID | `polymarket-close-position` |
| Category | EVM Onchain |
| Connector | `wallet` |
| Requires gas | No |
| Funds movement | `swap` |
| Tags | `polymarket`, `trading`, `sell`, `position`, `write` |

## Payload Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `tokenId` | `string` | Yes | The token ID \(condition ID / asset ID\) of the position to close. This identifies which outcome shares to sell. |
| `shares` | `number` | No | Number of shares to sell. If omitted, sells the entire position. |
| `orderType` | `string` | No | Order type for the sell order. FAK \(Fill And Kill\) allows partial fills \(default\). FOK \(Fill Or Kill\) requires the entire order to fill or nothing. |

## Result Schema

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `status` | `string` | Yes | Status of the close position operation. |
| `tokenId` | `string` | No | The token ID that was sold. |
| `sharesSold` | `number` | No | Number of shares that were sold. |
| `pricePerShare` | `number` | No | Price per share received. |
| `totalProceeds` | `number` | No | Total USDC proceeds from the sale \(sharesSold * pricePerShare\). |
| `orderId` | `string` | No | The unique identifier for the sell order. |
| `transactionHash` | `string` | No | On-chain transaction hash if the order settled immediately. |
| `message` | `string` | No | Additional context about the result. |

## Examples

**Workflow node**

```json
{
  "type": "polymarket-close-position",
  "payload": {
    "tokenId": "1"
  },
  "children": [],
  "connector": {
    "type": "wallet",
    "id": "conn_wallet"
  }
}
```
  **Test with API**

```bash
curl -X POST "https://api.b3os.org/v1/actions/polymarket-close-position/test" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "inputs": {
    "tokenId": "1"
  }
}'
```

**Use expressions for dynamic values**

Payload fields can use workflow expressions such as `{{$trigger.body.amount}}`, `{{$nodes.fetch.result.price}}`, and `{{$props.asset}}` when the value should come from a trigger, prior node, or reusable workflow prop.