{"format":"opendoc-document","version":1,"url":"https://docs.upscale.trade/developers/operations/closeallpositionsandorders","title":"Close all positions and orders","description":"POST /accounts/{accountId}/close-all: Cancels every active order on the account and then closes every open position at market.","kind":"api-operation","locale":"en","inLanguage":"en","lastModified":"2026-09-28T19:22:49.100Z","revision":"25c86f549328fcff320805d5945f4c9804e3927950d831e601d6e3b18c170f66","section":{"title":"Developers","url":"https://docs.upscale.trade/developers"},"representations":{"html":"https://docs.upscale.trade/developers/operations/closeallpositionsandorders","markdown":"https://docs.upscale.trade/developers/operations/closeallpositionsandorders.md","json":"https://docs.upscale.trade/developers/operations/closeallpositionsandorders.json"},"translations":{"en":"https://docs.upscale.trade/developers/operations/closeallpositionsandorders","ru":"https://docs.upscale.trade/ru/developers/operations/closeallpositionsandorders","es":"https://docs.upscale.trade/es/developers/operations/closeallpositionsandorders"},"operation":{"id":"closeAllPositionsAndOrders","method":"POST","path":"/accounts/{accountId}/close-all","summary":"Close all positions and orders","description":"Cancels every active order on the account and then closes every open position at market.\n\n- Responds `204` with no body; the resulting fills appear in the position history and in the account events.\n- Send an `x-idempotency-key` header to make the call replay-safe: inside the replay window stated on that header, the same key on the same route replays the stored response (marked with `X-Idempotency-Cached: true` and `X-Idempotency-Timestamp`) instead of acting again, and a second call arriving while the first one is still running gets `409` (`idempotency_key_in_flight`).","tags":["Accounts"],"deprecated":false,"parameters":[{"name":"accountId","location":"path","schema":{"type":"string · uuid","types":["string"],"nullable":false,"readOnly":false,"writeOnly":false,"constraints":{"format":"uuid"},"properties":[],"variants":[]},"type":"string · uuid","required":true,"description":"Trader account identifier. Must belong to the caller.","example":"00000000-0000-4000-8000-000000000000"},{"name":"x-idempotency-key","location":"header","schema":{"type":"string","types":["string"],"example":"9f1c2b7e-5a3d-4f61-9b0e-2c7d4a8e1f35","nullable":false,"readOnly":false,"writeOnly":false,"constraints":{},"properties":[],"variants":[]},"type":"string","required":false,"description":"Idempotency key — any opaque string, a uuid v4 works well. Repeating the call with the same key on this route within 1 minute replays the stored response instead of acting again; a replay carries `X-Idempotency-Cached: true` and `X-Idempotency-Timestamp`. Omit the header to opt out.","example":"9f1c2b7e-5a3d-4f61-9b0e-2c7d4a8e1f35"}],"bodies":[],"responses":[{"status":"401","description":"Unauthorized","properties":[],"headers":[]},{"status":"403","description":"The account belongs to another user (`account_access_denied`), or the request is authenticated with an API key while `api_trading` is disabled on the account (`api_trading_not_enabled`).","properties":[],"headers":[]},{"status":"404","description":"No account with this identifier.","properties":[],"headers":[]},{"status":"409","description":"Another call with the same `x-idempotency-key` is still running (`idempotency_key_in_flight`). Retry once it finishes.","properties":[],"headers":[]},{"status":"429","description":"Rate limit of the API key exceeded (`api_key_rate_limit_exceeded`). `Retry-After` says when to come back; the body carries the bucket (`read` / `write`), the window that tripped, its limit and `retryAt`.","properties":[],"headers":[]}],"security":[{"name":"bearer","type":"http · bearer","description":"Personal API key, prefixed with `usk_`.","required":true,"scopes":[]}],"codeSamples":[{"label":"cURL","language":"bash","source":"curl --request POST 'https://api.upscale.trade/accounts/{accountId}/close-all' \\\n  --header 'Accept: application/json' \\\n  --header 'Authorization: Bearer YOUR_API_KEY'"},{"label":"JavaScript","language":"javascript","source":"const response = await fetch(\"https://api.upscale.trade/accounts/{accountId}/close-all\", {\n  method: \"POST\",\n  headers: {\n    \"Accept\": \"application/json\",\n    \"Authorization\": \"Bearer YOUR_API_KEY\"\n  },\n});\nconsole.log(response.status, await response.text());"},{"label":"Python","language":"python","source":"import requests\n\nresponse = requests.request(\n    \"POST\",\n    \"https://api.upscale.trade/accounts/{accountId}/close-all\",\n    headers={\"Accept\":\"application/json\",\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nprint(response.status_code, response.text)"}]},"breadcrumbs":[{"title":"What is Prop Trading","url":"https://docs.upscale.trade"},{"title":"Developers","url":"https://docs.upscale.trade/developers"},{"title":"Close all positions and orders","url":"https://docs.upscale.trade/developers/operations/closeallpositionsandorders"}],"headings":[{"depth":2,"id":"authorization","title":"Authorization"},{"depth":2,"id":"parameters","title":"Parameters"},{"depth":2,"id":"examples","title":"Examples"},{"depth":2,"id":"responses","title":"Responses"}],"markdown":"# Close all positions and orders\n\n`POST /accounts/{accountId}/close-all`\n\nCancels every active order on the account and then closes every open position at market.\n\n- Responds `204` with no body; the resulting fills appear in the position history and in the account events.\n- Send an `x-idempotency-key` header to make the call replay-safe: inside the replay window stated on that header, the same key on the same route replays the stored response (marked with `X-Idempotency-Cached: true` and `X-Idempotency-Timestamp`) instead of acting again, and a second call arriving while the first one is still running gets `409` (`idempotency_key_in_flight`).\n\n## Authorization\n\nbearer: http · bearer (required). Personal API key, prefixed with `usk_`.\n\n## Parameters\n\n- path: accountId (string · uuid; required). Trader account identifier. Must belong to the caller.\n\nType: string · uuid\n\nformat: uuid\n\n- header: x-idempotency-key (string; optional). Idempotency key — any opaque string, a uuid v4 works well. Repeating the call with the same key on this route within 1 minute replays the stored response instead of acting again; a replay carries `X-Idempotency-Cached: true` and `X-Idempotency-Timestamp`. Omit the header to opt out.\n\nType: string\n\nExample: \"9f1c2b7e-5a3d-4f61-9b0e-2c7d4a8e1f35\"\n\n## Example · cURL\n\n```bash\ncurl --request POST 'https://api.upscale.trade/accounts/{accountId}/close-all' \\\n  --header 'Accept: application/json' \\\n  --header 'Authorization: Bearer YOUR_API_KEY'\n```\n\n## Example · JavaScript\n\n```javascript\nconst response = await fetch(\"https://api.upscale.trade/accounts/{accountId}/close-all\", {\n  method: \"POST\",\n  headers: {\n    \"Accept\": \"application/json\",\n    \"Authorization\": \"Bearer YOUR_API_KEY\"\n  },\n});\nconsole.log(response.status, await response.text());\n```\n\n## Example · Python\n\n```python\nimport requests\n\nresponse = requests.request(\n    \"POST\",\n    \"https://api.upscale.trade/accounts/{accountId}/close-all\",\n    headers={\"Accept\":\"application/json\",\"Authorization\":\"Bearer YOUR_API_KEY\"},\n    timeout=30,\n)\nprint(response.status_code, response.text)\n```\n\n## Response 401\n\n**401**  — Unauthorized\n\n## Response 403\n\n**403**  — The account belongs to another user (`account_access_denied`), or the request is authenticated with an API key while `api_trading` is disabled on the account (`api_trading_not_enabled`).\n\n## Response 404\n\n**404**  — No account with this identifier.\n\n## Response 409\n\n**409**  — Another call with the same `x-idempotency-key` is still running (`idempotency_key_in_flight`). Retry once it finishes.\n\n## Response 429\n\n**429**  — Rate limit of the API key exceeded (`api_key_rate_limit_exceeded`). `Retry-After` says when to come back; the body carries the bucket (`read` / `write`), the window that tripped, its limit and `retryAt`.","text":"Close all positions and orders Cancels every active order on the account and then closes every open position at market. - Responds `204` with no body; the resulting fills appear in the position history and in the account events. - Send an `x-idempotency-key` header to make the call replay-safe: inside the replay window stated on that header, the same key on the same route replays the stored response (marked with `X-Idempotency-Cached: true` and `X-Idempotency-Timestamp`) instead of acting again, and a second call arriving while the first one is still running gets `409` (`idempotency_key_in_flight`). POST /accounts/{accountId}/close-all Accounts accountId Trader account identifier. Must belong to the caller. string · uuid x-idempotency-key Idempotency key — any opaque string, a uuid v4 works well. Repeating the call with the same key on this route within 1 minute replays the stored response instead of acting again; a replay carries `X-Idempotency-Cached: true` and `X-Idempotency-Timestamp`. Omit the header to opt out. string 401 Unauthorized 403 The account belongs to another user (`account_access_denied`), or the request is authenticated with an API key while `api_trading` is disabled on the account (`api_trading_not_enabled`). 404 No account with this identifier. 409 Another call with the same `x-idempotency-key` is still running (`idempotency_key_in_flight`). Retry once it finishes. 429 Rate limit of the API key exceeded (`api_key_rate_limit_exceeded`). `Retry-After` says when to come back; the body carries the bucket (`read` / `write`), the window that tripped, its limit and `retryAt`.","api":{"title":"Upscale Public API","version":"d796ac9","documentation":"https://docs.upscale.trade/developers","playgroundServer":"https://api.upscale.trade"}}