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

# Subaccounts REST API

> REST endpoints for subaccount management.

QFEX provides three REST endpoints for subaccount workflows:

* `GET /user/subaccounts`
* `POST /user/subaccounts`
* `POST /user/transfer`

These endpoints require authentication.

## Authentication

The CLI authenticates these requests with either:

* `Authorization: Bearer <access_token>` after `qfex login`, or
* QFEX HMAC headers when API keys are configured

For HMAC auth, sign `${nonce}:${unix_ts}` with HMAC-SHA256 using your secret key, then hex-encode the result.

Send:

* `x-qfex-public-key`
* `x-qfex-hmac-signature`
* `x-qfex-nonce`
* `x-qfex-timestamp`

## List Subaccounts

Returns the authenticated user’s subaccount IDs excluding the master account ID.

```http theme={null}
GET /user/subaccounts
```

CLI command:

```sh theme={null}
qfex account subaccounts list
```

Example:

```sh theme={null}
curl https://api.qfex.com/user/subaccounts \
  -H "accept: application/json" \
  -H "x-qfex-public-key: $QFEX_PUBLIC_KEY" \
  -H "x-qfex-hmac-signature: $SIG" \
  -H "x-qfex-nonce: $NONCE" \
  -H "x-qfex-timestamp: $TS"
```

Response shape:

```json theme={null}
{
  "account_ids": [
    "11111111-1111-1111-1111-111111111111",
    "22222222-2222-2222-2222-222222222222"
  ]
}
```

## Create Subaccount

Allocates a new subaccount for the authenticated user.

```http theme={null}
POST /user/subaccounts
Content-Type: application/json
```

CLI command:

```sh theme={null}
qfex account subaccounts create
```

The CLI sends an empty JSON body.

Example:

```sh theme={null}
curl https://api.qfex.com/user/subaccounts \
  -X POST \
  -H "content-type: application/json" \
  -H "accept: application/json" \
  -H "x-qfex-public-key: $QFEX_PUBLIC_KEY" \
  -H "x-qfex-hmac-signature: $SIG" \
  -H "x-qfex-nonce: $NONCE" \
  -H "x-qfex-timestamp: $TS" \
  -d '{}'
```

## Transfer Between Primary Account And Subaccounts

Transfers balance between two accounts owned by the authenticated user.

```http theme={null}
POST /user/transfer?src_account_id=<account-id>&dst_account_id=<account-id>
Content-Type: application/json
```

CLI command:

```sh theme={null}
qfex account subaccounts transfer --from <account-id|primary> --to <account-id|primary> --amount <usd>
```

The CLI resolves `primary` to the authenticated user’s primary account ID, then sends:

* `src_account_id` as a query parameter
* `dst_account_id` as a query parameter
* `{"amount": <number>}` as the JSON body

Example:

```sh theme={null}
curl "https://api.qfex.com/user/transfer?src_account_id=$PRIMARY_ACCOUNT_ID&dst_account_id=$SUBACCOUNT_ID" \
  -X POST \
  -H "content-type: application/json" \
  -H "accept: application/json" \
  -H "x-qfex-public-key: $QFEX_PUBLIC_KEY" \
  -H "x-qfex-hmac-signature: $SIG" \
  -H "x-qfex-nonce: $NONCE" \
  -H "x-qfex-timestamp: $TS" \
  -d '{"amount":100}'
```
