Skip to main content

Installation

curl -fsSL https://mcp.nilemarkets.com/install.sh | bash
The installer downloads the latest release binary for your platform and adds it to your PATH.
Verify the installation:
nile --version

Configuration

The CLI reads configuration from environment variables, CLI flags, and a config file (~/.config/nile/config.toml). Precedence: CLI flag > environment variable > config file > built-in default.

Set Defaults

# Required: RPC endpoint for onchain reads and writes
nile config set-rpc https://eth-sepolia.g.alchemy.com/v2/YOUR_KEY

# Required for subgraph queries (position lists, history, stats)
nile config set-subgraph https://api.studio.thegraph.com/query/YOUR_SUBGRAPH_ID

# Required for write operations (signing transactions)
nile config set-wallet my-wallet

Verify Configuration

nile config show

Environment Variables

Every flag has a corresponding environment variable with the NILE_ prefix:
FlagEnvironment VariablePurpose
--rpc-urlNILE_RPC_URLEthereum RPC endpoint
--subgraph-urlNILE_SUBGRAPH_URLSubgraph GraphQL endpoint
--networkNILE_NETWORKTarget network (default: sepolia)
--formatNILE_FORMATOutput format: json or table
--signerNILE_SIGNERSigner binary name or path (default: ows)
--walletNILE_WALLETWallet name for the signer
--fromNILE_FROMSender address override (simulate only)

Command Groups

GroupDescriptionKey Commands
poolPool and vault operationsstate, deposit, withdraw, transactions
vaultAlias for poolSame commands as pool
positionPosition lifecyclelist, get, search, open, close
accountMargin account managementbalance, deposit, withdraw
oraclePrice and oracle dataprice, state
protocolProtocol mode and statusmode
simulateDry-run operationsopen
statsAnalyticsdaily
feesFee historyFee event queries
tokenERC-20 operationsbalance, allowance, approve, mint
configCLI configurationshow, set-rpc, set-subgraph, set-signer, set-wallet
Run nile <group> --help for full details on any command group.

Read Operations

Pool State

nile pool state
{
  "totalAssets": "50000000000",
  "totalSupply": "48500000000",
  "sharePrice": "1.030928",
  "utilization": "3200",
  "grossNotional": "16000000000",
  "netExposure": "4000000000"
}

Oracle Prices

nile oracle price
Returns current spot and forward prices for all enabled tenors.

Position Details

Fetch a single position with real-time PnL (combined subgraph + RPC data):
nile position get --id 1

List Account Positions

nile position list --account 0xYOUR_ADDRESS
Filter by status:
nile position list --account 0xYOUR_ADDRESS --status OPEN

Search Positions

Search across all accounts with filters:
# All open LONG positions
nile position search --side 0 --status OPEN

# 1-week positions above 5,000 USDC notional
nile position search --tenor 1 --min-notional 5000000000

# Paginate
nile position search --first 10 --skip 20

Account Balance

nile account balance --account 0xYOUR_ADDRESS

Token Balance and Allowance

nile token balance --account 0xYOUR_ADDRESS
nile token allowance --owner 0xYOUR_ADDRESS --spender positionManager

Daily Statistics

nile stats daily

Write Operations

Write operations require a configured wallet for transaction signing. The CLI delegates signing to an OWS-compatible signer — your private keys never touch the CLI process.

Approve Tokens

# Approve PositionManager to spend USDC (for opening positions)
nile token approve --spender positionManager --amount 1000.0

# Approve MarginAccounts (for margin deposits)
nile token approve --spender marginAccounts --amount 1000.0

# Approve PoolVault (for LP deposits)
nile token approve --spender poolVault --amount 1000.0
The --spender flag accepts contract names (positionManager, marginAccounts, poolVault) or raw addresses.

Deposit and Withdraw Margin

# Deposit 500 USDC into your margin account
nile account deposit --amount 500.0

# Withdraw 200 USDC from your margin account
nile account withdraw --amount 200.0

Open a Position

nile position open \
  --side long \
  --tenor 1w \
  --notional 10000.0 \
  --margin 500.0
FlagValuesDescription
--sidelong, shortPosition direction
--tenor1d, 1w, 1m, testTime to maturity
--notionalDecimal USDCPosition size (e.g., 10000.0)
--marginDecimal USDCCollateral to lock (e.g., 500.0)
--dry-runFlagSimulate only, no transaction

Simulate Before Opening

Add --dry-run to preview without spending gas:
nile position open \
  --side long \
  --tenor 1w \
  --notional 10000.0 \
  --margin 500.0 \
  --dry-run
Or use the dedicated simulate command:
nile simulate open \
  --side long \
  --tenor 1w \
  --notional 10000.0 \
  --margin 500.0

Close a Position

nile position close --id 1

LP Deposit and Withdraw

# Deposit 1,000 USDC into the liquidity pool
nile pool deposit --amount 1000.0

# Withdraw 500 USDC from the liquidity pool
nile pool withdraw --amount 500.0

Mint Test Tokens

On Sepolia, mint MockUSDC for testing:
nile token mint --amount 10000.0

Output Formats

JSON (default)

All commands output JSON by default, designed for piping to jq or consuming in scripts:
nile pool state | jq '.totalAssets'

Table

Use --format table for human-readable terminal output:
nile pool state --format table
┌─────────────────┬──────────────────┐
│ Field           │ Value            │
├─────────────────┼──────────────────┤
│ Total Assets    │ 50,000.00 USDC   │
│ Total Supply    │ 48,500.00 shares │
│ Share Price     │ 1.030928         │
│ Utilization     │ 32.00%           │
│ Gross Notional  │ 16,000.00 USDC   │
│ Net Exposure    │ 4,000.00 USDC    │
└─────────────────┴──────────────────┘
Set the default format via environment variable:
export NILE_FORMAT=table

OWS Wallet Signing

The CLI uses Open Wallet Standard (OWS) for transaction signing. OWS is a local-first, multi-chain wallet tool that manages keys on your machine — no keys are sent to any remote server or exposed to the CLI process.

Setup

  1. Install OWS (see the OWS documentation for platform-specific instructions)
  2. Create or import a wallet:
    ows wallet create my-wallet
    
  3. Configure the CLI to use it:
    nile config set-wallet my-wallet
    

How It Works

When you run a write command, the CLI:
  1. Builds the unsigned transaction
  2. Passes it to the OWS signer binary
  3. OWS prompts you to approve and signs locally
  4. The CLI broadcasts the signed transaction
You can use any OWS-compatible signer by setting --signer:
nile position open --side long --tenor 1w --notional 10000 --margin 500 --signer my-custom-signer

Quick Start

Get from zero to querying the protocol in 15 minutes.

Open a Position

Step-by-step tutorial for opening your first trade.

TypeScript SDK

TypeScript alternative for programmatic integration.

Contract Addresses

All deployed contract addresses on Sepolia.