Skip to main content
POST
/
api
/
trade
/
position
/
close
Close Position
curl --request POST \
  --url https://api.dexaggregatorbeta.xyz/api/trade/position/close \
  --header 'Content-Type: application/json' \
  --header 'X-API-KEY: <api-key>' \
  --data '
{
  "symbol": "<string>",
  "direction": "LONG",
  "size": "<string>",
  "credentials": {
    "lighter": {
      "apiKeyPrivateKey": "<string>",
      "accountIndex": 123
    },
    "aster": {
      "apiKey": "<string>",
      "apiSecret": "<string>",
      "walletAddress": "<string>"
    },
    "hyperliquid": {
      "privateKey": "<string>"
    },
    "avantis": {
      "apiKey": "<string>",
      "apiSecret": "<string>",
      "walletAddress": "<string>"
    }
  },
  "orderType": "LIMIT",
  "limitPrice": "<string>",
  "preferredExchange": "hyperliquid"
}
'
{
  "success": true,
  "data": {
    "executedOn": "hyperliquid",
    "order": {
      "orderId": "<string>",
      "symbol": "<string>",
      "side": "BUY",
      "type": "LIMIT",
      "status": "OPEN",
      "price": "<string>",
      "quantity": "<string>",
      "filledQuantity": "<string>",
      "averagePrice": "<string>",
      "timestamp": 123,
      "exchange": "hyperliquid",
      "clientOrderId": "<string>",
      "reduceOnly": true,
      "triggerPrice": "<string>"
    },
    "routing": {},
    "execution": {}
  }
}
Close an existing position using a reduce-only order. The router mirrors the behaviour of the open endpoint—scanning all supported venues for the best exit price unless you force a specific exchange.

Features

  • Reduce-only safety: Guarantees the API only decreases exposure
  • Smart venue selection: Routes exits to the venue with the best available price
  • Partial or full closes: Specify any size up to the total position
  • Consistent payloads: Response structure matches the open position endpoint for easy reconciliation

Use Cases

  • Automate take-profit or stop-loss workflows across multiple exchanges
  • Build UI flows for one-click position unwinds
  • Implement partial de-risking strategies using precise quantities
  • Maintain audit trails with routing and execution metadata in a single response

Request

  • Method: POST
  • Endpoint: /api/trade/position/close
  • Authentication: Required

Request Fields

FieldTypeRequiredDescription
symbolstringAsset symbol being closed
directionstringDirection of the position you are closing (LONG or SHORT)
sizestringQuantity to close (must not exceed open position size)
orderTypestringMARKET by default; LIMIT supported when limitPrice is supplied
limitPricestringRequired when orderType is LIMIT
preferredExchangestringForce close on a specific venue
credentialsobjectExchange credentials required for execution
The response mirrors the Open Position endpoint, returning execution, routing, and position data so you can reconcile final fills.

Usage Tips

  • Reduce-only semantics ensure the API never increases exposure while closing.
  • Provide credentials only for venues you wish to use; missing credentials remove that venue from routing consideration.
  • For partial closes, set size to the exact quantity you want to reduce.
Combine /api/trade/position/open and /api/trade/position/close in your workflow to ladder into and out of positions while keeping routing logic centralized.

Hyperliquid - Close Single Position

Close a specific open position for a given symbol on Hyperliquid.

Endpoint

POST /api/hyperliquid/:walletId/positions/close/:symbol

Path Parameters

ParameterTypeRequiredDescription
walletIdstringYesWallet ID (UUID)
symbolstringYesAsset symbol (e.g., “BTC”)

Headers

HeaderValueRequired
x-wallet-idWallet ID (UUID)Yes
Content-Typeapplication/jsonYes

Request Body

{
  "userId": "ee337309-3e77-4278-b21a-4681468168ba",
  "symbol": "BTC-PERP",
  "side": "BUY",
  "type": "MARKET",
  "quantity": "0.1",
  "price": "1",
  "reduceOnly": true
}

Request Parameters

FieldTypeRequiredDescription
userIdstringYesUser’s wallet ID
symbolstringYesTrading pair (e.g., “BTC-PERP”)
sidestringYes”BUY” or “SELL” (opposite of position)
typestringYes”MARKET” or “LIMIT”
quantitystringYesQuantity to close
pricestringYesPrice for the order
reduceOnlybooleanYesMust be true for closing positions

Example Request

curl -X POST https://api.dexaggregatorbeta.xyz/api/hyperliquid/a1e82339-29f8-41a6-a468-ce8d268a3261/positions/close/BTC \
  -H "x-wallet-id: a1e82339-29f8-41a6-a468-ce8d268a3261" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "ee337309-3e77-4278-b21a-4681468168ba",
    "symbol": "BTC-PERP",
    "side": "BUY",
    "type": "MARKET",
    "quantity": "0.1",
    "price": "1",
    "reduceOnly": true
  }'

Success Response

{
  "success": true,
  "data": {
    "closeId": "c2394ab3",
    "status": "submitted",
    "timestamp": 1698840000000
  }
}

Hyperliquid - Close All Positions

Close all open positions for the wallet on Hyperliquid.

Endpoint

POST /api/hyperliquid/:walletId/positions/close-all

Path Parameters

ParameterTypeRequiredDescription
walletIdstringYesWallet ID (UUID)

Headers

HeaderValueRequired
x-wallet-idWallet ID (UUID)Yes
Content-Typeapplication/jsonYes

Request Body

Same schema as close-single-symbol.

Example Request

curl -X POST https://api.dexaggregatorbeta.xyz/api/hyperliquid/a1e82339-29f8-41a6-a468-ce8d268a3261/positions/close-all \
  -H "x-wallet-id: a1e82339-29f8-41a6-a468-ce8d268a3261" \
  -H "Content-Type: application/json" \
  -d '{
    "userId": "a1e82339-29f8-41a6-a468-ce8d268a3261",
    "symbol": "BTC-PERP",
    "side": "BUY",
    "type": "MARKET",
    "quantity": "0.1",
    "price": "1",
    "reduceOnly": true
  }'

Success Response

{
  "success": true,
  "data": {
    "success": true,
    "closedCount": 1,
    "totalPositions": 1,
    "results": [
      {
        "symbol": "BTC",
        "status": "CLOSED",
        "orderId": "255732635491"
      }
    ],
    "message": "Successfully closed 1/1 positions"
  }
}

Aster - Close Position

Close positions on Aster exchange with a single API call.

Endpoint

POST /api/aster/perp/:walletId/close-position

Path Parameters

ParameterTypeRequiredDescription
walletIdstringYesWallet ID (UUID)

Request Body

{
  "symbol": "BTCUSDT"
}
Optional - Close specific side:
{
  "symbol": "BTCUSDT",
  "positionSide": "LONG"
}

Request Parameters

FieldTypeRequiredDescription
symbolstringYesTrading pair (e.g., “BTCUSDT”)
positionSidestringNo”LONG” or “SHORT” (for hedge mode). Omit to close all positions for the symbol

Example Request

curl -X POST https://api.dexaggregatorbeta.xyz/api/aster/perp/ee337309-3e77-4278-b21a-4681468168ba/close-position \
  -H "Content-Type: application/json" \
  -d '{
    "symbol": "BTCUSDT"
  }'

Success Response

{
  "success": true,
  "data": {
    "orderId": 9884649221,
    "symbol": "BTCUSDT",
    "status": "NEW",
    "clientOrderId": "6D52PQwRlg0PcdHz5ttkgN",
    "price": "0",
    "avgPrice": "0.0000",
    "origQty": "0.001",
    "executedQty": "0",
    "cumQty": "0",
    "cumQuote": "0",
    "timeInForce": "GTC",
    "type": "MARKET",
    "reduceOnly": true,
    "closePosition": false,
    "side": "SELL",
    "positionSide": "BOTH",
    "stopPrice": "0",
    "workingType": "CONTRACT_PRICE",
    "priceProtect": false,
    "origType": "MARKET",
    "updateTime": 1764640797006
  }
}

Authorizations

X-API-KEY
string
header
required

API key for authentication. Also requires X-API-SECRET, X-API-TIMESTAMP, and X-API-SIGNATURE headers for private endpoints.

Body

application/json
symbol
string
required

Asset symbol being closed

direction
enum<string>
required
Available options:
LONG,
SHORT
size
string
required

Quantity to close

credentials
object
required
orderType
enum<string>
Available options:
LIMIT,
MARKET,
STOP_MARKET,
STOP_LIMIT
limitPrice
string

Required when orderType is LIMIT

preferredExchange
enum<string>
Available options:
hyperliquid,
aster,
lighter,
avantis

Response

200 - application/json

Position closed successfully

success
boolean
data
object