# Close Positions

Source: https://developers.bitgo.com/docs/trade-margin-close

## Overview

You can close open positions by asset or close all positions. When you close all open margin positions, BitGo will start an asynchronous process that buys and sells assets in an attempt to net them to zero.

## Prerequisites

* [Get Started](/docs/get-started-intro)
  * Access token must have the `trade_trade` scope.
* [Create Wallets](/docs/wallets-create-wallets)
* [Deposit Assets](/docs/deposit-assets)
* [Place Margin Order](/docs/trade-margin-margin-order)
* Enterprise user with the Trade role.

## Cookbook

Need just the steps? Expand the cookbook below to get started:

<Cookbook slug="close-margin-positions" title="Close Margin Positions" />

## Close Positions

>Endpoint: [Close All Margin Positions](/reference/trademarginpositionsclose)

```shell cURL (Close All Positions)
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export ACCOUNT_ID="<YOUR_ACCOUNT_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
curl -X POST \
  http://$BITGO_EXPRESS/api/prime/trading/v1/accounts/$ACCOUNT_ID/margin/positions/close \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
        "all": true
      }'
```
```shell cURL (Close Position by Asset)
export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export ACCOUNT_ID="<YOUR_ACCOUNT_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
export CURRENCIES="<ASSET_ID>"
curl -X POST \
  http://$BITGO_EXPRESS/api/prime/trading/v1/accounts/{accountID}/margin/close \
  -H 'Content-Type: application/json' \
  -H "Authorization: Bearer $ACCESS_TOKEN" \
  -d '{
      "currencies": ["'"$CURRENCIES"'"]
    }'

```

## See Also

* [API Reference: Get Net Open Margin Position](/reference/trademarginnetopenpositionsget)
* [API Reference: Cover All Short Positions](/reference/trademarginpositionscover)
* [Go Network Overview](/docs/go-network-overview)
