> ## Documentation Index
> Fetch the complete documentation index at: https://docs.tide.ag/llms.txt
> Use this file to discover all available pages before exploring further.

# Withdraw Funds

# Withdraw Funds from Exchanges

Withdraw funds from exchange accounts back to your server wallet. The server handles transaction signing and withdrawal request processing.

## Supported Exchanges

| Exchange    | Endpoint                                 | Description                              |
| ----------- | ---------------------------------------- | ---------------------------------------- |
| Aster       | `POST /api/trading/aster/withdraw`       | Withdraw from Aster to server wallet     |
| Hyperliquid | `POST /api/trading/hyperliquid/withdraw` | Withdraw from Hyperliquid to destination |

***

## Aster Withdrawal

Withdraw funds from your Aster exchange account to your server wallet.

### Endpoint

`POST /api/trading/aster/withdraw`

### Request Body

```json theme={null}
{
  "walletAddress": "0x07943f0f79097572451601e768c329a2765f2ea2",
  "chainId": 56,
  "asset": "USDT",
  "amount": "50",
  "broker": 1000,
  "receiver": "0x07943f0f79097572451601e768c329a2765f2ea2",
  "accountType": "perp"
}
```

### Request Parameters

| Field           | Type   | Required | Description                        |
| --------------- | ------ | -------- | ---------------------------------- |
| `walletAddress` | string | Yes      | User wallet performing withdrawal  |
| `chainId`       | number | Yes      | Target blockchain (e.g., 56 = BSC) |
| `asset`         | string | Yes      | Token symbol (e.g., "USDT")        |
| `amount`        | string | Yes      | Withdrawal amount in raw units     |
| `broker`        | number | No       | Broker ID (default: 1000)          |
| `receiver`      | string | Yes      | Destination wallet address         |
| `accountType`   | string | Yes      | Account type: "spot" or "perp"     |

<Warning>
  **Important**: The `receiver` address should match the `walletAddress` for signature verification. The exchange verifies that the receiver address matches the signer address.
</Warning>

### What Happens

1. **Create Withdrawal Message** - Server creates withdrawal request with transaction details
2. **Sign Request** - Server signs using the wallet's MPC key shares
3. **Verify Signature** - Exchange verifies the signature matches the wallet
4. **Process Withdrawal** - Exchange validates and processes the withdrawal
5. **Broadcast Transaction** - Funds are sent to the blockchain
6. **Receive Funds** - Funds arrive in the server wallet after confirmation

### Example Request

```bash theme={null}
curl -X POST https://api.tide.ag/api/trading/aster/withdraw \
  -H "Content-Type: application/json" \
  -d '{
    "walletAddress": "0x07943f0f79097572451601e768c329a2765f2ea2",
    "chainId": 56,
    "asset": "USDT",
    "amount": "50",
    "receiver": "0x07943f0f79097572451601e768c329a2765f2ea2",
    "accountType": "perp"
  }'
```

```javascript theme={null}
await axios.post('https://api.tide.ag/api/trading/aster/withdraw', {
  walletAddress: '0x07943f0f79097572451601e768c329a2765f2ea2',
  chainId: 56,
  asset: 'USDT',
  amount: '50',
  receiver: '0x07943f0f79097572451601e768c329a2765f2ea2',
  accountType: 'perp'
});
```

### Success Response

```json theme={null}
{
  "success": true,
  "withdrawalId": "4c93dfe1-8c62-40ae-93d7-f02a999ab2f7",
  "status": "submitted",
  "timestamp": 1698840000000
}
```

### Response Fields

| Field          | Type    | Description                                             |
| -------------- | ------- | ------------------------------------------------------- |
| `success`      | boolean | Operation status                                        |
| `withdrawalId` | string  | Unique withdrawal identifier                            |
| `status`       | string  | Withdrawal status ("submitted", "pending", "completed") |
| `timestamp`    | number  | Unix timestamp in milliseconds                          |

***

## Hyperliquid Withdrawal

Withdraw funds from your Hyperliquid account to a destination address.

### Endpoint

`POST /api/trading/hyperliquid/withdraw`

### Headers

| Header         | Value            | Required |
| -------------- | ---------------- | -------- |
| `x-wallet-id`  | Wallet ID (UUID) | Yes      |
| `Content-Type` | application/json | Yes      |

### Request Body

```json theme={null}
{
  "walletIdOrAddress": "0x90EA34C09B612AC68E696BdC7be0ED037a086E72",
  "destination": "0x90EA34C09B612AC68E696BdC7be0ED037a086E72",
  "amount": "0.2",
  "feeBuffer": "0",
  "chainId": 42161
}
```

### Request Parameters

| Field               | Type   | Required | Description                                  |
| ------------------- | ------ | -------- | -------------------------------------------- |
| `walletIdOrAddress` | string | Yes      | User's wallet (userId, walletId, or address) |
| `destination`       | string | Yes      | Recipient wallet address                     |
| `amount`            | string | Yes      | Withdrawal amount                            |
| `feeBuffer`         | string | No       | Fee overhead multiplier (default: "0")       |
| `chainId`           | number | Yes      | Destination network (e.g., 42161 = Arbitrum) |

### Example Request

```bash theme={null}
curl -X POST https://api.tide.ag/api/trading/hyperliquid/withdraw \
  -H "x-wallet-id: a1e82339-29f8-41a6-a468-ce8d268a3261" \
  -H "Content-Type: application/json" \
  -d '{
    "walletIdOrAddress": "0x90EA34C09B612AC68E696BdC7be0ED037a086E72",
    "destination": "0x90EA34C09B612AC68E696BdC7be0ED037a086E72",
    "amount": "0.2",
    "feeBuffer": "0",
    "chainId": 42161
  }'
```

```javascript theme={null}
await axios.post('https://api.tide.ag/api/trading/hyperliquid/withdraw', {
  walletIdOrAddress: '0x90EA34C09B612AC68E696BdC7be0ED037a086E72',
  destination: '0x90EA34C09B612AC68E696BdC7be0ED037a086E72',
  amount: '0.2',
  feeBuffer: '0',
  chainId: 42161
}, {
  headers: { 'x-wallet-id': 'a1e82339-29f8-41a6-a468-ce8d268a3261' }
});
```

### Success Response

```json theme={null}
{
  "success": true,
  "data": {
    "withdrawalId": "4828392",
    "status": "accepted",
    "timestamp": 1698840000000
  }
}
```

### Response Fields

| Field               | Type    | Description                                            |
| ------------------- | ------- | ------------------------------------------------------ |
| `success`           | boolean | Operation status                                       |
| `data.withdrawalId` | string  | Unique withdrawal identifier                           |
| `data.status`       | string  | Withdrawal status ("accepted", "pending", "completed") |
| `data.timestamp`    | number  | Unix timestamp in milliseconds                         |

***

## Error Responses

### 400 Bad Request - Missing Parameters

```json theme={null}
{
  "success": false,
  "error": "Missing required parameters",
  "timestamp": 1698840000000
}
```

### 400 Bad Request - Insufficient Balance

```json theme={null}
{
  "success": false,
  "error": "Insufficient balance for withdrawal",
  "timestamp": 1698840000000
}
```

### 404 Not Found - Wallet Not Found

```json theme={null}
{
  "success": false,
  "error": "Wallet not found",
  "timestamp": 1698840000000
}
```

### 500 Internal Server Error

```json theme={null}
{
  "success": false,
  "error": "Failed to process withdrawal",
  "timestamp": 1698840000000
}
```

***

## Supported Networks

| Exchange    | Network         | Chain ID | Token |
| ----------- | --------------- | -------- | ----- |
| Aster       | BSC (BNB Chain) | 56       | USDT  |
| Hyperliquid | Arbitrum        | 42161    | USDC  |

***

## Important Notes

<Warning>
  **Signature Verification**: For Aster, the receiver address must match the wallet address that signs the withdrawal request. This is a security measure to prevent unauthorized withdrawals.
</Warning>

<Note>
  **Fee Buffer**: For Hyperliquid, the `feeBuffer` parameter adds a percentage overhead to cover gas fees. A value of "1.1" means 10% extra for fees.
</Note>

<Tip>
  **Withdrawal Status**: Use the returned `withdrawalId` to track the withdrawal status. Withdrawals typically take a few minutes to complete depending on network congestion.
</Tip>

<Info>
  **Account Types**: For Aster, specify whether you're withdrawing from "spot" or "perp" account. Make sure you have sufficient balance in the specified account type.
</Info>

## Use Cases

* Withdraw profits from trading back to your server wallet
* Move funds between exchanges by withdrawing to wallet then depositing elsewhere
* Cash out positions after closing trades
* Rebalance funds across different platforms
