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

# Drift

> Trade spot and perpetual markets and deposit to Drift Vaults

Commands for interacting with Drift Protocol (spot and perp trading) and Drift Vaults.

> [!NOTE]
>
> The `Drift` integration must be enabled before using these commands:
>
> ```bash theme={null}
> glam-cli integration enable DriftProtocol DriftVaults
> ```

***

## Drift Protocol

### User Management

#### Initialize User

Initialize a Drift user account (sub-account) for the vault.

* `--sub-account-id`, `-s`: Sub-account ID (default: 0)
* `--pool-id`, `-p`: Isolated pool ID (default: 0)

```bash theme={null}
glam-cli drift-protocol init-user [--sub-account-id <id>] [--pool-id <id>] [--yes]
```

#### List Users

List all Drift user sub-accounts for the vault.

```bash theme={null}
glam-cli drift-protocol list-users
```

#### Delete User

Delete a Drift user sub-account.

```bash theme={null}
glam-cli drift-protocol delete-user <sub_account_id> [--yes]
```

#### Update User Pool ID

Update a Drift user's pool ID.

```bash theme={null}
glam-cli drift-protocol update-user-pool-id <sub_account_id> <pool_id> [--yes]
```

### Deposits & Withdrawals

#### Deposit

Deposit to a Drift spot market.

* `market_index`: Spot market index (e.g., 0 for USDC, 1 for SOL)
* `amount`: Amount to deposit
* `--sub-account-id`, `-s`: Sub-account ID (default: 0)

```bash theme={null}
glam-cli drift-protocol deposit <market_index> <amount> [--sub-account-id <id>] [--yes]
```

#### Withdraw

Withdraw from a Drift spot market. If withdrawing more than your balance with sufficient collateral, this becomes a borrow.

```bash theme={null}
glam-cli drift-protocol withdraw <market_index> <amount> [--sub-account-id <id>] [--yes]
```

### Trading

#### Enable/Disable Margin

Enable or disable margin trading for a sub-account.

```bash theme={null}
glam-cli drift-protocol margin <true|false> [--sub-account-id <id>] [--yes]
```

#### Spot Order

Place a limit spot order.

* `direction`: `long` or `short`
* `market_index`: Spot market index
* `amount`: Order size
* `price_limit`: Limit price in USD

```bash theme={null}
glam-cli drift-protocol spot <direction> <market_index> <amount> <price_limit> [--sub-account-id <id>] [--yes]
```

**Example:** Buy 0.5 SOL at \$100:

```bash theme={null}
glam-cli drift-protocol spot long 1 0.5 100
```

#### Perp Order

Place a limit perpetual order.

```bash theme={null}
glam-cli drift-protocol perp <direction> <market_index> <amount> <price_limit> [--sub-account-id <id>] [--yes]
```

#### List Orders

List open orders.

```bash theme={null}
glam-cli drift-protocol list-orders [--sub-account-id <id>]
```

#### Cancel Orders

Cancel one or more orders by ID.

```bash theme={null}
glam-cli drift-protocol cancel <order_ids...> [--sub-account-id <id>] [--yes]
```

### Positions

#### List Positions

List all Drift positions (spot and perp).

```bash theme={null}
glam-cli drift-protocol list-positions [--sub-account-id <id>]
```

#### Settle PnL

Settle PnL for a perp market.

```bash theme={null}
glam-cli drift-protocol settle <market_index> [--sub-account-id <id>]
```

### Policy Management

#### View Policy

```bash theme={null}
glam-cli drift-protocol view-policy
```

#### Allowlist Market

```bash theme={null}
glam-cli drift-protocol allowlist-market <spot|perp> <market_index> [--yes]
```

#### Remove Market

```bash theme={null}
glam-cli drift-protocol remove-market <spot|perp> <market_index> [--yes]
```

#### Allowlist Borrowable Asset

```bash theme={null}
glam-cli drift-protocol allowlist-borrowable-asset <token_mint> [--yes]
```

#### Remove Borrowable Asset

```bash theme={null}
glam-cli drift-protocol remove-borrowable-asset <token_mint> [--yes]
```

***

## Drift Vaults

### List Depositors

List Drift vault depositor accounts owned by the GLAM vault.

```bash theme={null}
glam-cli drift-vaults list-depositors
```

### Deposit

Deposit to a Drift vault.

```bash theme={null}
glam-cli drift-vaults deposit <vault> <amount> [--yes]
```

### Request Withdraw

Request to withdraw from a Drift vault.

* `amount`: Amount in vault shares

```bash theme={null}
glam-cli drift-vaults request-withdraw <vault> <amount> [--yes]
```

### Cancel Withdraw

Cancel a pending withdrawal request.

```bash theme={null}
glam-cli drift-vaults cancel-withdraw <vault> [--yes]
```

### Withdraw

Claim a withdrawal after the request period has passed.

```bash theme={null}
glam-cli drift-vaults withdraw <vault>
```

### Policy Management

#### View Policy

```bash theme={null}
glam-cli drift-vaults view-policy
```

#### Allowlist Vault

```bash theme={null}
glam-cli drift-vaults allowlist-vault <vault> [--yes]
```

#### Remove Vault

```bash theme={null}
glam-cli drift-vaults remove-vault <vault> [--yes]
```


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