Skip to main content
POST
/
api
/
trade
/
position
/
close
Close Position
curl --request POST \
  --url https://api.tide.ag/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>"
    },
    "pacifica": {
      "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.tide.ag/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.tide.ag/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.tide.ag/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
  }
}

Avantis - Close Position (Client-Side Execution)

Avantis positions are closed client-side via on-chain transactions on the Base network. Like opening, closing is not routed through the Tide backend.
Avantis close execution uses client-side wallet signing via the useAvantisTrade React hook. Supports both full and partial closes.

Close by Pair and Trade Index

useAvantisTrade().closePosition({
  pairIndex: 0,              // From PAIR_INDEX_MAP (e.g., 0 = ETH)
  tradeIndex: 0,             // On-chain trade index
  closeAmountUsdc: "50.00"   // Partial close amount (optional)
})
// Returns: txHash

Close by Symbol and Direction

// Convenience method — finds and closes the matching open trade
useAvantisTrade().closeBySymbol("ETH", "LONG")
// Returns: txHash

Request Parameters

FieldTypeRequiredDescription
pairIndexnumberYesPair index from PAIR_INDEX_MAP
tradeIndexnumberYesOn-chain trade index
closeAmountUsdcstringNoPartial close amount in USDC. Omit for full close

Close by Symbol Parameters

FieldTypeRequiredDescription
symbolstringYesAsset symbol (e.g., “ETH”)
directionstringYes"LONG" or "SHORT"
The close operation uses initialPosToken (not positionSizeUSDC) for the collateral amount, read from TradingStorage.openTrades() on-chain.

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,
pacifica

Response

200 - application/json

Position closed successfully

success
boolean
data
object