---
title: "Close an account position or cancel a pending order"
method: DELETE
path: "/rest/api/v1/accounts/{accountId}/positions/{positionId}"
tags: ["Trading API"]
---

# Close an account position or cancel a pending order

`DELETE /rest/api/v1/accounts/{accountId}/positions/{positionId}`

## Request

- Base URL: `https://api.metacopier.io`
- URL: `https://api.metacopier.io/rest/api/v1/accounts/{accountId}/positions/{positionId}`
- Auth: API key in header `X-API-KEY`
- TypeScript: <https://skmtc.dev/metacopier/apis/metacopier-api/docs/rest/api/v1/accounts/:accountId/positions/:positionId/delete.ts> (a function with typed inputs; its response is checked against the schema)

By default closes the position (works for both live positions and pending orders). Set `pendingOnly=true` to cancel the order ONLY if it is still a pending (unfilled) order; if it has already filled into a live position it is left untouched (safe no-op). Use this to safely cancel pending orders on expiry without risking closing a filled position.

## Path parameters

- `accountId` string, uuid, required
- `positionId` string, required

## Query parameters

- `pendingOnly` boolean

## Response `204`

No Content

## Changes

- **2026-08-10** `5c1371d2c0b2`: 1 info
  - added the new optional `query` request parameter `pendingOnly`
- **2025-02-07** `f3a76dd2ff82`: 1 breaking, 1 info
  - removed the success response with the status `200`
  - added the success response with the status `204`

[Operation history](https://skmtc.dev/metacopier/apis/metacopier-api/changes/rest/api/v1/accounts/:accountId/positions/:positionId/delete.md)

---

[API](https://skmtc.dev/metacopier/apis/metacopier-api.md) - [All operations](https://skmtc.dev/metacopier/apis/metacopier-api/llms.txt) - [OpenAPI document](https://skmtc.dev/metacopier/apis/metacopier-api/revisions/cbf3e7810fc2?raw)
