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

# Close Position

> Manually close an existing position

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "https://api.strike.markets/close" \
    -H "X-API-Key: stk_your_api_key_here" \
    -H "Content-Type: application/json" \
    -d '{
      "positionId": 12345
    }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch('https://api.strike.markets/close', {
    method: 'POST',
    headers: {
      'X-API-Key': 'stk_your_api_key_here',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      positionId: 12345
    })
  });

  const data = await response.json();
  console.log('Position closed:', data);
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://api.strike.markets/close',
      headers={
          'X-API-Key': 'stk_your_api_key_here',
          'Content-Type': 'application/json'
      },
      json={
          'positionId': 12345
      }
  )

  data = response.json()
  print('Position closed:', data)
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "success": true,
    "message": "Position closed successfully",
    "txHash": "0x1234567890abcdef1234567890abcdef12345680",
    "gasUsed": 165000,
    "positionId": 12345,
    "symbol": "BTC-USD",
    "szi": "0.002217",
    "margin": "100.0",
    "entryPrice": "45123.50",
    "exitPrice": "46123.50",
    "realizedPnl": "114.50",
    "pnlFee": "8.75",
    "status": "closed",
    "createdAt": "2024-01-15T14:30:00Z",
    "closedAt": "2024-01-15T15:45:00Z",
    "settledAt": null,
    "spread": "5.25"
  }
  ```
</ResponseExample>

## Overview

Manually close an existing position at the current market price. This endpoint allows you to realize profits or cut losses by closing your position immediately.

<Warning>
  This endpoint requires authentication with a valid API key. You can only close positions that belong to your wallet.
</Warning>

## Authentication

Include your API key in the X-API-Key header:

```
X-API-Key: stk_your_api_key_here
```

## Request Body

<ParamField body="positionId" type="integer" required>
  The unique identifier of the position to close.

  **How to get**: Use [Get Positions](/api-reference/positions/get-positions) to find your position IDs\
  **Example**: 12345
</ParamField>

## Response Fields

<ResponseField name="success" type="boolean">
  Indicates if the position was closed successfully
</ResponseField>

<ResponseField name="message" type="string">
  Success message describing the operation
</ResponseField>

<ResponseField name="txHash" type="string">
  Blockchain transaction hash for the position closure
</ResponseField>

<ResponseField name="positionId" type="integer">
  ID of the closed position
</ResponseField>

<ResponseField name="exitPrice" type="string">
  Price at which the position was closed
</ResponseField>

<ResponseField name="pricePnl" type="string">
  PnL from price movement only (excludes funding)
</ResponseField>

<ResponseField name="accumulatedFunding" type="string">
  Total funding payments received/paid during position lifetime
</ResponseField>

<ResponseField name="grossPnl" type="string">
  Total PnL including funding (pricePnl + accumulatedFunding)
</ResponseField>

<ResponseField name="pnl" type="string">
  Net PnL after fees (grossPnl - fee)
</ResponseField>

<ResponseField name="fee" type="string">
  Total fees charged for closing the position
</ResponseField>

<ResponseField name="gasUsed" type="integer">
  Gas consumed for the transaction
</ResponseField>

<ResponseField name="position" type="object">
  Updated position object with closure details
</ResponseField>

## Error Responses

<ResponseField name="400 Bad Request" type="object">
  Invalid position ID or position cannot be closed

  ```json theme={null}
  {
    "error": 400,
    "message": "Position not found or already closed"
  }
  ```
</ResponseField>

<ResponseField name="401 Unauthorized" type="object">
  Missing or invalid authentication token

  ```json theme={null}
  {
    "error": 401,
    "message": "Authorization header missing"
  }
  ```
</ResponseField>

<ResponseField name="403 Forbidden" type="object">
  Attempting to close position that doesn't belong to your wallet

  ```json theme={null}
  {
    "error": 403,
    "message": "Position does not belong to authenticated wallet"
  }
  ```
</ResponseField>

<ResponseField name="429 Too Many Requests" type="object">
  Rate limit exceeded (10 requests per minute for trading endpoints)

  ```json theme={null}
  {
    "error": "RATE_LIMIT_EXCEEDED",
    "message": "Rate limit exceeded. Please wait 45 seconds.",
    "retry_after": 45
  }
  ```
</ResponseField>

## Next Steps

After closing a position:

1. **Check Balance** - View updated balance in [Account](/api-reference/account/account-info)
2. **Review Performance** - Analyze trade in [Dashboard](/api-reference/account/dashboard)
3. **Monitor Queue** - If queued, check status with [Queue Positions](/api-reference/positions/queue-positions)
4. **Plan Next Trade** - Use [Market Data](/api-reference/market-data/markets) for analysis

<Tip>
  Consider market conditions and your overall strategy before closing positions. Sometimes holding through temporary volatility can be more profitable than frequent trading.
</Tip>

<Warning>
  Position closure is irreversible. Make sure you want to close the position before submitting the request.
</Warning>


## OpenAPI

````yaml POST /close
openapi: 3.1.0
info:
  title: Strike Protocol API
  description: >-
    Strike Protocol is a perpetual futures trading platform that allows users to
    trade with leverage (1-1000x) on various crypto assets. This API provides
    access to trading operations, account management, market data, analytics,
    and user systems.
  version: 1.0.0
  contact:
    name: Strike Protocol
    url: https://strike.markets
  license:
    name: MIT
servers:
  - url: https://api.strike.markets
    description: Production server
security:
  - apiKeyAuth: []
paths:
  /close:
    post:
      summary: Close Position
      description: Manually close an existing position
      operationId: closePosition
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ClosePositionRequest'
      responses:
        '200':
          description: Position closed successfully
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ClosePositionResponse'
        '400':
          description: Invalid request parameters
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '401':
          description: Unauthorized - Invalid or missing authentication token
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
components:
  schemas:
    ClosePositionRequest:
      type: object
      required:
        - positionId
      properties:
        positionId:
          type: integer
          description: Position ID to close
    ClosePositionResponse:
      type: object
      properties:
        success:
          type: boolean
        txHash:
          type: string
        pnl:
          type: string
        fees:
          type: string
        netPayout:
          type: string
    Error:
      type: object
      required:
        - error
        - message
      properties:
        error:
          type: integer
          format: int32
        message:
          type: string
  securitySchemes:
    apiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: Strike Protocol API key authentication

````