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

# Quickstart

> Get NanoARB up and running in minutes with this step-by-step guide

## Quick start

This guide will help you get NanoARB running locally with synthetic market data in just a few minutes.

## Prerequisites

Before you begin, make sure you have:

* **Rust 1.75+** — [Install Rust](https://rustup.rs/)
* **Node.js 18+** and **pnpm** — For the dashboard UI
* **Git** — To clone the repository

<Note>
  Optional: Docker Desktop for Prometheus/Grafana monitoring
</Note>

## One-command setup

The fastest way to get started is using the provided startup script:

<Steps>
  <Step title="Clone the repository">
    ```bash theme={null}
    git clone https://github.com/dhir1007/nanoARB.git
    cd nanoARB
    ```
  </Step>

  <Step title="Start everything">
    ```bash theme={null}
    ./start.sh
    ```

    This single command will:

    * Build the Rust trading engine in release mode
    * Install UI dependencies (if needed)
    * Start the trading engine on port 9090
    * Launch the dashboard UI on port 3000

    Expected output:

    ```bash theme={null}
    ============================================
      NanoARB - Starting Full Stack
    ============================================

    [1/3] Building Rust trading engine (release)...
    [2/3] Installing UI dependencies...
    [3/3] Starting services...

      Rust Engine   : http://localhost:9090  (PID 12345)
      Metrics       : http://localhost:9090/metrics
      Health        : http://localhost:9090/health
      API State     : http://localhost:9090/api/state
      SSE Stream    : http://localhost:9090/api/stream
      Dashboard UI  : http://localhost:3000   (PID 12346)

    ============================================
      All services running. Press Ctrl+C to stop.
    ============================================
    ```
  </Step>

  <Step title="Access the dashboard">
    Open your browser to [http://localhost:3000](http://localhost:3000) to see the real-time trading dashboard.

    The dashboard shows:

    * Live order book with 15 levels
    * Real-time price chart with ML predictions
    * Trade history and P\&L curve
    * Latency metrics and performance statistics
    * Risk monitoring and position tracking
  </Step>

  <Step title="Stop the services">
    Press `Ctrl+C` in the terminal, or run:

    ```bash theme={null}
    ./stop.sh
    ```
  </Step>
</Steps>

## Manual setup

If you prefer more control, you can start services manually:

<Steps>
  <Step title="Build the Rust engine">
    ```bash theme={null}
    cargo build --release
    ```

    This compiles the trading engine with maximum optimizations (LTO, single codegen unit).
  </Step>

  <Step title="Start the trading engine">
    ```bash theme={null}
    ./target/release/nanoarb
    ```

    Or run in the background:

    ```bash theme={null}
    ./target/release/nanoarb &
    ```

    The engine will start in simulation mode by default, generating synthetic market data.
  </Step>

  <Step title="Start the dashboard UI (optional)">
    In a new terminal:

    ```bash theme={null}
    cd nano-arb-ui-development
    pnpm install
    pnpm dev
    ```

    The UI will be available at [http://localhost:3000](http://localhost:3000).
  </Step>
</Steps>

## Running your first backtest

NanoARB includes a powerful backtesting engine that simulates realistic market conditions.

### CLI backtest

Run a backtest using synthetic data:

```bash theme={null}
cargo run --release --bin nanoarb -- --backtest
```

Expected output:

```
INFO Starting NanoARB Trading Engine v0.1.0
INFO Running in backtest mode
INFO Using synthetic data for backtest
INFO Generated 100000 synthetic events
INFO Backtest completed in 2.3s
INFO Events processed: 100000
INFO Total P&L: $892.45
INFO Max Drawdown: 3.2%
INFO Sharpe Ratio: 4.8
INFO Win Rate: 54.3%
INFO Profit Factor: 2.3
```

### API backtest

While the engine is running, you can trigger backtests via the REST API:

```bash theme={null}
curl -X POST http://localhost:9090/api/backtest \
  -H "Content-Type: application/json" \
  -d '{
    "symbol": "ES",
    "startDate": "2024-01-01",
    "endDate": "2024-12-31",
    "initialCapital": 1000000,
    "spreadMultiplier": 1.0,
    "inventoryLimit": 50,
    "skewFactor": 0.5,
    "useML": true,
    "maxDrawdown": 5.0,
    "positionLimit": 50
  }'
```

### Custom configuration

Create a `config.toml` file to customize backtest parameters:

```toml config.toml theme={null}
[trading]
live_enabled = false
symbols = ["ESH24"]
initial_capital = 1000000.0
max_position = 50
max_order_size = 10

[latency]
order_latency_ns = 100000
market_data_latency_ns = 50000
jitter_ns = 10000

[risk]
max_position = 50
max_drawdown_pct = 0.06
max_daily_loss = 100000.0
enable_kill_switch = true

[fees]
maker_fee = 0.25
taker_fee = 0.85
exchange_fee = 1.18
```

Then run:

```bash theme={null}
cargo run --release --bin nanoarb -- --config config.toml --backtest
```

## Available endpoints

Once the engine is running, the following HTTP endpoints are available:

| Endpoint        | Method | Description                         |
| --------------- | ------ | ----------------------------------- |
| `/health`       | GET    | Health check                        |
| `/metrics`      | GET    | Prometheus metrics                  |
| `/api/state`    | GET    | Full engine state (JSON)            |
| `/api/stream`   | GET    | Server-Sent Events stream           |
| `/api/backtest` | POST   | Run backtest with custom parameters |

### Example: Get current state

```bash theme={null}
curl http://localhost:9090/api/state | jq
```

Response includes:

* Order book snapshot (15 levels)
* Current position and P\&L
* Recent trades
* Latency metrics
* Risk alerts

## Monitoring with Grafana

For advanced monitoring, you can launch Prometheus and Grafana:

```bash theme={null}
cd docker
docker compose -f docker-compose-monitoring.yml up -d
```

Access Grafana at [http://localhost:3000](http://localhost:3000) (login: `admin` / `nanoarb`).

The pre-configured dashboard shows:

* Real-time P\&L and Sharpe ratio
* Latency histograms (p50, p95, p99)
* Order flow and fill rates
* Position and inventory tracking

To stop monitoring:

```bash theme={null}
docker compose -f docker-compose-monitoring.yml down
```

## Running tests

Verify your installation by running the test suite:

```bash theme={null}
# Run all tests
cargo test --workspace

# Run specific crate tests
cargo test -p nano-lob

# Run benchmarks
cargo bench --workspace
```

## Next steps

<CardGroup cols={2}>
  <Card title="Installation" icon="download" href="/installation">
    Detailed installation guide and troubleshooting
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference">
    Explore the full API documentation
  </Card>
</CardGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Port already in use">
    If port 9090 or 3000 is already in use:

    ```bash theme={null}
    # Kill processes on ports
    lsof -ti:9090 | xargs kill -9
    lsof -ti:3000 | xargs kill -9
    ```

    Or specify a custom port:

    ```bash theme={null}
    PORT=8080 ./target/release/nanoarb
    ```
  </Accordion>

  <Accordion title="Rust version too old">
    NanoARB requires Rust 1.75+. Update Rust:

    ```bash theme={null}
    rustup update stable
    rustc --version
    ```
  </Accordion>

  <Accordion title="pnpm not found">
    Install pnpm:

    ```bash theme={null}
    npm install -g pnpm
    ```
  </Accordion>

  <Accordion title="Build fails with linker errors">
    On Linux, you may need to install additional dependencies:

    ```bash theme={null}
    # Ubuntu/Debian
    sudo apt-get install build-essential pkg-config libssl-dev

    # Fedora/RHEL
    sudo dnf install gcc gcc-c++ make openssl-devel
    ```
  </Accordion>
</AccordionGroup>
