# Flash Trade CLI

The CLI signs all transactions locally. Your private keys never leave your machine.

Source: [GitHub](https://github.com/flash-trade/flash-trade-MCP)

***

#### Install Rust (macOS)

The CLI is built with Rust. If you don't have Rust installed yet:

1. Open **Terminal** (press Cmd+Space, type "Terminal", hit Enter)
2. Paste this command and hit Enter:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

3. When prompted, type `1` and hit Enter to proceed with the default installation
4. When it finishes, close Terminal and reopen it (this loads the new Rust tools into your shell)
5. Verify it worked:

```bash
rustc --version
```

You should see something like `rustc 1.XX.X`. If you see "command not found", close and reopen Terminal again.

***

#### Install Rust (Windows)

1. Go to [https://rustup.rs](https://rustup.rs/)
2. Click the download link — this downloads `rustup-init.exe`
3. Run `rustup-init.exe`
4. When prompted, type `1` and hit Enter for the default installation
5. It may ask you to install **Visual Studio C++ Build Tools** — follow the link it gives you, download and install them (this is required for Rust on Windows)
6. When it finishes, close and reopen your terminal (Command Prompt or PowerShell)
7. Verify it worked:

```bash
rustc --version
```

***

#### Install Rust (Linux)

1. Open your terminal
2. Paste this command and hit Enter:

```bash
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

3. Type `1` and hit Enter for the default installation
4. Close and reopen your terminal
5. Verify it worked:

```bash
rustc --version
```

***

#### Install Git

You need Git to download the Flash Trade CLI code. You may already have it.

1. Check if Git is installed:

```bash
git --version
```

If you see a version number, skip ahead to **Download and Build the CLI**.

2. If you see "command not found":
   * **macOS**: A popup may ask to install Xcode Command Line Tools. Click **Install** and wait for it to finish. Then try `git --version` again
   * **Windows**: Download from [https://git-scm.com](https://git-scm.com/), run the installer, accept all defaults. Close and reopen your terminal
   * **Linux**: Run `sudo apt install git` (Ubuntu/Debian) or `sudo dnf install git` (Fedora)

***

#### Download and Build the CLI

{% hint style="info" %} The Flash Trade SDK is in a private GitHub repository. You need to be granted access to [flash-trade/flash-contracts-closed](https://github.com/flash-trade/flash-contracts-closed) before the build will work. Contact the Flash Trade team if you get a permission error during the build step. {% endhint %}

1. Open your terminal
2. Choose where you want to put the code. Your home folder works fine:

```bash
cd ~
```

3. Download the code:

```bash
git clone https://github.com/flash-trade/flash-trade-MCP.git
```

4. Go into the CLI folder:

```bash
cd flash-trade-MCP/cli
```

5. Build the CLI (this takes a few minutes the first time — it's downloading and compiling dependencies):

```bash
cargo build --release
```

6. When it finishes, the CLI is ready at `target/release/flash`. Test it:

```bash
./target/release/flash --help
```

You should see a list of commands. If you do, the build worked.

***

#### Make the CLI Easy to Run

Right now you have to type the full path every time. You can make `flash` available from anywhere:

**macOS / Linux:**

```bash
sudo cp target/release/flash /usr/local/bin/flash
```

Now you can type `flash` from any folder.

**Windows:**

Copy `target\release\flash.exe` to a folder that's in your system PATH, or add the `target\release` folder to your PATH through System Settings → Environment Variables.

***

#### Set Up Your Wallet

The CLI needs a Solana wallet to sign transactions. You have two options:

**Option A — Import an Existing Solana Wallet**

If you already use the Solana CLI and have a keypair file:

```bash
flash keys add main --file ~/.config/solana/id.json
```

**Option B — Generate a New Wallet**

If you don't have a Solana wallet yet:

```bash
flash keys generate trading
```

This creates a new random wallet and saves it. The CLI will print the public key (your wallet address). **Fund this wallet with SOL and USDC before trading.**

***

#### Set Your Active Wallet

Tell the CLI which wallet to use:

```bash
flash keys use main
```

(Replace `main` with whatever name you used in the previous step — `trading` if you went with Option B.)

***

#### Set Up Your RPC (Optional but Recommended)

An RPC is how the CLI talks to the Solana network. The default public RPC works but is slow and rate-limited. For a better experience, use a dedicated provider like [Helius](https://helius.dev/), [Triton](https://triton.one/), or [QuickNode](https://quicknode.com/). Most have free tiers.

Once you have an RPC URL:

```bash
flash config set rpc_url https://your-rpc-url-here.com
```

The CLI has **RPC failover** enabled by default — if your primary RPC goes down, it automatically falls back to the Solana Labs public RPC and warns you once. To add additional fallback endpoints:

```bash
flash config set rpc_fallbacks https://backup-rpc-1.com,https://backup-rpc-2.com
```

To disable failover (strict single-endpoint mode):

```bash
flash config set rpc_failover off
```

{% hint style="info" %} `flash config set rpc_url https://...` saves the URL (including any API key) into `settings.json` with `0o600` permissions. The URL also lands in your shell history. After setting an RPC URL that contains a secret, consider clearing the history entry:

* **bash**: `history -d $(history 1)`
* **zsh**: run `fc -p` to push a clean history stack for the current session {% endhint %}

***

#### Verify Everything Works

Run these commands in order to confirm your setup:

```bash
flash --version
```

Confirms the binary is installed.

```bash
flash keys show main
```

This should print your wallet's public key (a long string of letters and numbers).

```bash
flash price SOL
```

This should show the current SOL price.

```bash
flash perps markets
```

This should list all available trading markets.

```bash
flash perps positions
```

This should show your open positions (or "No open positions"). **This is the first command that actually hits your RPC** — if it errors but `flash price SOL` worked, your RPC is the issue. See [Troubleshooting](https://claude.ai/chat/4bc367e3-38be-41c6-8208-597423cd4d1b#troubleshooting--rpc-errors) below.

***

#### Troubleshooting — RPC Errors

The CLI talks to Solana through your configured RPC endpoint. If that endpoint is misconfigured, dead, or rate-limited, commands that read/write on-chain data will fail — even though `flash price SOL` (which pulls from Pyth's Hermes service, not your RPC) keeps working.

| Error                                                | What It Means                                                                                 | Fix                                                                                    |
| ---------------------------------------------------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| `401 Unauthorized`                                   | RPC API key is invalid, expired, or revoked                                                   | Rotate the key at your provider's dashboard, then `flash config set rpc_url <new-url>` |
| `403 Forbidden`                                      | RPC key is valid but not allowed to call `getProgramAccounts` (some free tiers restrict this) | Upgrade the plan or switch providers                                                   |
| `429 Too Many Requests`                              | Public RPC rate limit hit                                                                     | Set a dedicated RPC URL                                                                |
| `Failed to fetch program accounts` with no HTTP code | Network outage or DNS failure                                                                 | Check your internet connection and provider status page                                |
| `Keypair 'X' not found in keystore`                  | `active_key` refers to a key you haven't imported                                             | Run `flash keys list` to see what's there, then `flash keys use <name>`                |

***

{% hint style="info" %}

#### Important Things to Know

* **Minimum collateral >$10.** Limit orders, take-profit, and stop-loss all require more than $10 in collateral after fees. If you open a $10 position and try to attach a TP/SL later, it will fail because fees have already eaten the collateral below $10. Use at least $11-12.
* **Mainnet only for prices.** The price feeds come from Pyth and only work on mainnet. Devnet will show stale or zero prices.
* **SOL positions use JitoSOL** as the underlying collateral on-chain. This is automatic — you don't need to do anything different.
* **Every trade asks for confirmation.** The CLI always shows you a preview and asks you to type `y` before submitting. You can always cancel.
* **Your keys stay local.** Private keys are stored in your platform's config directory and never leave your machine. All signing happens locally.
* **RPC failover is on by default.** If your primary RPC fails, the CLI automatically tries fallback endpoints. You'll see a one-time warning on the first failover. {% endhint %}

***

#### Check a Price

```bash
flash price SOL
flash price BTC
flash price ETH
```

Watch a price live (updates every 5 seconds, press Ctrl+C to stop):

```bash
flash price SOL --watch
```

***

#### Open a Position

```bash
# Go 5x long on SOL with $20 of USDC as collateral
flash perps open SOL long 20 --leverage 5
```

```bash
# Go 3x short on BTC with $50 of USDC
flash perps open BTC short 50 --leverage 3
```

The CLI will show you a preview of the trade (entry price, fees, leverage, liquidation price) and ask you to confirm before sending anything.

***

#### View Your Positions

```bash
flash perps positions
```

This shows all your open positions with live PnL, leverage, entry price, and liquidation price.

To see details on one specific position:

```bash
flash perps position <PUBKEY>
```

(Replace `<PUBKEY>` with the position's public key from the positions list.)

For an aggregated summary across all your open positions (total notional, total collateral, PnL):

```bash
flash perps portfolio
```

***

#### Close a Position

Close the full position:

```bash
flash perps close <PUBKEY>
```

To close part of a position, use `perps decrease` with a USD size to remove:

```bash
flash perps decrease <PUBKEY> 10    # removes $10 of size from the position
```

***

#### Set Take-Profit and Stop-Loss

Place a take-profit:

```bash
flash orders trigger <POSITION_PUBKEY> --type tp --price 200
```

Place a stop-loss:

```bash
flash orders trigger <POSITION_PUBKEY> --type sl --price 80
```

View all your orders:

```bash
flash orders list
```

Cancel an order (specify `--type tp` or `--type sl`):

```bash
flash orders cancel <ORDER_PUBKEY> --type tp
flash orders cancel <ORDER_PUBKEY> --type sl
```

Cancel all trigger orders for a market:

```bash
flash orders cancel-all SOL
```

***

#### Place a Limit Order

```bash
flash orders limit SOL long 50 --price 120 --leverage 3
```

This places an order to go 3x long SOL with $50 when the price hits $120.

***

#### Adjust Your Position

Add more size:

```bash
flash perps increase <PUBKEY> 10
```

Remove size:

```bash
flash perps decrease <PUBKEY> 10
```

Add collateral (makes your position safer — moves liquidation price further away):

```bash
flash perps add-collateral <PUBKEY> 5
```

Remove collateral (increases your leverage — moves liquidation price closer):

```bash
flash perps remove-collateral <PUBKEY> 5
```

{% hint style="info" %} **Amount is in the position's collateral token, not USD.** For a short or a `*/USDC` position, the token is USDC, so `5` means 5 USDC. For a `SOL/SOL` long the token is SOL, so `5` means 5 SOL. Check `flash perps position <PUBKEY>` to see what currency the position is margined in. The CLI's preview screen will show the token symbol on the "Amount" line so you can confirm before submitting. {% endhint %}

***

#### Provide Liquidity

See available pools:

```bash
flash earn pools
```

Deposit USDC into a pool:

```bash
flash earn add-liquidity Crypto.1 USDC 100
```

Withdraw from a pool:

```bash
flash earn remove-liquidity Crypto.1 USDC 50
```

***

#### Stake FLP

Stake your FLP tokens to earn rewards:

```bash
flash earn stake Crypto.1 100
```

Unstake (instant, pays a fee):

```bash
flash earn unstake Crypto.1 100 --instant
```

Collect staking rewards:

```bash
flash earn claim Crypto.1
```

***

#### View All Markets

```bash
flash perps markets
```

See details on a specific market:

```bash
flash perps market SOL
```

***

#### Change Settings

View your current settings:

```bash
flash config list
```

Change a setting:

```bash
flash config set rpc_url https://your-rpc.com
flash config set default_slippage_bps 50
flash config set priority_fee 200000
```

Reset everything to defaults:

```bash
flash config reset
```

| Setting                | Default        | What It Does                                    |
| ---------------------- | -------------- | ----------------------------------------------- |
| `cluster`              | `mainnet-beta` | Which Solana network to use                     |
| `rpc_url`              | (auto)         | Your RPC endpoint                               |
| `default_slippage_bps` | `100`          | Slippage tolerance (100 = 1%)                   |
| `priority_fee`         | `100000`       | Transaction priority fee in microlamports       |
| `output_format`        | `table`        | `table` for readable output, `json` for scripts |
| `rpc_failover`         | `on`           | Auto-fallback to backup RPCs when primary fails |
| `rpc_fallbacks`        | (none)         | Comma-separated list of backup RPC URLs         |

***

#### Manage Wallets

List all saved wallets:

```bash
flash keys list
```

Show a wallet's public key:

```bash
flash keys show main
```

Delete a wallet:

```bash
flash keys delete old-wallet
```

Switch to a different wallet:

```bash
flash keys use other-wallet
```

***

{% hint style="danger" %}

#### Wallet Security

Your wallets are stored as unencrypted JSON files in a platform-specific config directory, protected by file permissions. This is the same approach the official Solana CLI uses.

| Platform | Config directory                                         |
| -------- | -------------------------------------------------------- |
| macOS    | `~/Library/Application Support/flash/`                   |
| Linux    | `~/.config/flash/` (or `$XDG_CONFIG_HOME/flash/` if set) |
| Windows  | `%APPDATA%\flash\`                                       |

`settings.json` is in that directory; keypairs are under `keys/<name>.json` with `0o600` permissions (and the `keys/` directory with `0o700`).

**Recommendations:**

* Use a dedicated wallet with limited funds for trading — don't import your main wallet
* For large amounts, use a hardware wallet with the Flash Trade web UI instead
* Verify permissions on the keys directory:
  * **macOS**: `ls -la "$HOME/Library/Application Support/flash/keys/"` — should show `-rw-------`
  * **Linux**: `ls -la ~/.config/flash/keys/` — should show `-rw-------` {% endhint %}
