> ## 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.

# CLI

> JSON-native command-line access to QFEX market data, trading, and account state.

The [QFEX CLI](https://github.com/QFEX-org/cli) provides JSON-only command-line access to QFEX for both human operators and AI agents.

A background daemon manages the underlying WebSocket connections to QFEX, while CLI commands remain stateless from the caller's perspective.

For a higher-level guide to using the CLI with AI agents, see [Agentic Trading](https://docs.qfex.com/qfex/agentic-trading.md).

## Installation

```sh theme={null}
brew install QFEX-org/tap/qfex
```

## Quick Start

```sh theme={null}
# Start the background daemon
qfex daemon start

# Query market data (no credentials required)
qfex market bbo AAPL-USD

# Log in to trade or access account data
qfex login
qfex daemon restart

# Place an order
qfex order place --symbol AAPL-USD --side BUY --type LIMIT --tif GTC --qty 1 --price 200

# Stop the daemon when finished
qfex daemon stop
```

## Why Use The CLI

* All command output is JSON, which makes it easy to pipe into `jq` or parse in code.
* The daemon keeps persistent connections to market data and trade WebSockets, so scripts do not need to manage subscriptions, authentication, or socket lifecycle directly.
* Market data commands work without credentials.
* Trading commands use the API keys described in [API Keys](https://docs.qfex.com/api-reference/api-keys.md).

## Common Commands

```sh theme={null}
# Market data
qfex market bbo AAPL-USD
qfex market orderbook AAPL-USD --depth 5
qfex market trades AAPL-USD --limit 50

# Orders
qfex order place --symbol AAPL-USD --side BUY --type MARKET --tif IOC --qty 1
qfex order list
qfex order cancel --symbol AAPL-USD --order-id <order-id>

# Positions and account state
qfex position list
qfex account balance
qfex account leverage get

# Live streams
qfex watch bbo AAPL-USD
qfex watch orders
qfex watch fills
```

## Environments

The CLI supports both QFEX production and UAT environments:

* `prod`: Connects to `qfex.com` with real funds.
* `uat`: Connects to `qfex.io` for testing strategies and integrations without real funds.

You can select the environment during `qfex login` or by editing `~/.config/qfex/config.yaml`, then restarting the daemon.

## Subaccounts

If your account has subaccounts, `qfex login` will prompt you to choose which account should be active by default. The selected value is stored in `~/.config/qfex/config.yaml` as `selected_subaccount`.

Use these commands to inspect or change it later:

```sh theme={null}
qfex account subaccounts current
qfex account subaccounts select <account-id>
qfex account subaccounts list
```

Selecting a different subaccount updates the config and restarts the daemon so authenticated trading and account requests use the **new account** context.

You can also transfer money between subaccounts using:

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

This command accepts `--from`, `--to`, and `--amount` (in USD). You can set either `--from` or `--to` to `"primary"` to refer to your main account. The other account should be a UUID returned by `qfex account subaccounts list`.

## Links

* [Agentic Trading](https://docs.qfex.com/qfex/agentic-trading.md)
* [QFEX CLI repository](https://github.com/QFEX-org/cli)
* [API key setup instructions](https://docs.qfex.com/api-reference/api-keys.md)
* [WebSocket overview](https://docs.qfex.com/websocket/main.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.