Close Positions

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

Close Positions

Endpoint: Close All Margin Positions

export BITGO_EXPRESS_HOST="<YOUR_LOCALHOST>"
export ACCOUNT_ID="<YOUR_ACCOUNT_ID>"
export ACCESS_TOKEN="<YOUR_ACCESS_TOKEN>"
curl -X POST \
  https://$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
      }'
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 \
  https://$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