# Closing accounts and account groups

## Prerequisites

- **Authentication scopes** — `accounts:admin`
For more information, refer to [Authentication scopes](/products/tol/concepts/api_concepts/authentication/authentication_oauth#list-of-authentication-scopes).
- **Webhook handler ready** — Set up a webhook endpoint to listen for account closure events.
  - Subscribe to [`ACCOUNT.CLOSING_INITIATED`](/products/tol/guides/accounts/accounts_webhooks) and [`ACCOUNT.CLOSED`](/products/tol/guides/accounts/accounts_webhooks) events.
  - Subscribe to [`ACCOUNT_GROUP.CLOSING_INITIATED`](/products/tol/guides/accounts/accounts_webhooks) and [`ACCOUNT_GROUP.CLOSED`](/products/tol/guides/accounts/accounts_webhooks) events.
For more information, refer to [Implementing webhooks](/products/tol/getting_started/implementing_webhooks).


## Overview

Closing either an account or an account group is a two step process:

1. You indicate your intention to close the account group or account via the Investment API.
2. Upvest will check that the preconditions for closing an account group or account have been met.


After calling the Investment API to close an account group or an account, the status of the corresponding resource will be `CLOSING`. As soon as all requirements are met, the account or account group is finally closed in the `CLOSED` state.

**Recommended: Use webhooks to track closure progress**

To check if an account closure has completed, set up a webhook listener for `ACCOUNT.CLOSING_INITIATED` and `ACCOUNT.CLOSED` (or `ACCOUNT_GROUP.CLOSING_INITIATED` and `ACCOUNT_GROUP.CLOSED` for account groups). Webhooks notify you automatically when closure progresses through its stages.

For more information, refer to [Account and account group webhooks](/products/tol/guides/accounts/accounts_webhooks)

Upvest is obliged to retain historical information for a certain period of time even after the user has been offboarded. Within this time, you can always retrieve historical information about accounts that have already been closed.

Please note that depending on the domicile of the user, the timing of account closure may vary, for example in the UK accounts will only be closed at the end of a tax year.

## Prerequisites

- **Authentication scopes** — `accounts:admin`
For more information, refer to [Authentication scopes](/products/tol/concepts/api_concepts/authentication/authentication_oauth#list-of-authentication-scopes).
- **Webhook handler ready** — Set up a webhook endpoint to listen for account closure events.
  - Subscribe to [`ACCOUNT.CLOSING_INITIATED`](/products/tol/guides/accounts/accounts_webhooks) and [`ACCOUNT.CLOSED`](/products/tol/guides/accounts/accounts_webhooks) events.
  - Subscribe to [`ACCOUNT_GROUP.CLOSING_INITIATED`](/products/tol/guides/accounts/accounts_webhooks) and [`ACCOUNT_GROUP.CLOSED`](/products/tol/guides/accounts/accounts_webhooks) events.
For more information, refer to [Implementing webhooks](/products/tol/getting_started/implementing_webhooks).
- You can only close an account or an account group that has been already created in the Investment API.
- The account/account group to be closed must not contain any outstanding withdrawals.


## Closing an account

To close an account send

**DELETE** [`/accounts/{account_id}`](/api/accounts/account_closure)

The account, specified by its ID, will be set to a `CLOSING` status and remains in this status as long as there are open positions or expected corporate actions outstanding.

Accounts can only move to the `CLOSED` status once all positions are sold off completely. To facilitate this, `CLOSING` accounts can only execute sell orders. You can also submit a liquidation request using the [`/accounts/{account_id}/liquidations`](/api/liquidations/create_account_liquidation) endpoint to sell all remaining open positions.

After all these preconditions for closure are met, the account status will be updated to `CLOSED`. At this point you will receive a webhook with the respective [account closed event](/api/accounts/account_event).

**Recommended: Use webhooks to track closure completion**

To check if the account has reached `CLOSED` status, set up a webhook listener for `ACCOUNT.CLOSED`. You'll receive automatic notification when the account closure completes and all liquidation/settlement requirements are met.

For more information, refer to [Account and account group webhooks](/products/tol/guides/accounts/accounts_webhooks)

Webhooks notify you of events in business processes, not the success or failure of the initialisation of those processes.

Please be sure to check the [HTTP status](/api_errors) of the response to your requests and handle failure cases appropriately.

## Closing an account group

To close an account group send

**DELETE** [`/account_groups/{account_group_id}`](/api/account-groups/account_group_closure)

The account group specified by its ID is set to a `CLOSING` status. The account group remains in `CLOSING` status until all of the following conditions are met:

- All associated accounts must be in `CLOSED` status
- There are no outstanding fee balances
- The account group has no remaining cash balance.


After all the prerequisites are completed, the account group status will reflect `CLOSED`.

Account Groups can only be CLOSED if all Accounts linked to the Account Group are closed and there is no cash left on the linked cash account.

To inform you about the final closure of the account group, you will receive a webhook with the respective [account group closed event](/api/account-groups/account_group_event). Furthermore you will receive an additional webhook that informs you about the [creation of a PDF report](/api/reports/report_event) of the type `ACCOUNT_CLOSING`.

The tax processes and especially the annual tax statement for German tax residents is processed around March of the following year. For example, if you close an account group on the January 1st of a year, the annual tax statement will be communicated in March the year after.

Webhooks notify you of events in business processes, not the success or failure of the initialisation of those processes.

Please be sure to check the [HTTP status](/api_errors) of the response to your requests and handle failure cases appropriately.

## Next Steps

Closing accounts and account groups is a prerequisite of [User offboarding](/products/tol/guides/users/users_offboarding).