# Dev Mode - Solana

**Dev Mode** lets you spin up a local Socket.IO server for manual trading while still reusing the full Leap trader engine — including pricing, position tracking, and analytics logic.

***

### ⚙️ Overview

When you enable **Dev Mode**, it runs a local Socket.IO server that listens on port `8080`.\
This server exposes only the `/socket.io/` namespace — all other HTTP requests are rejected.

```js
// Example connection:
const socket = io("http://localhost:8080", { path: "/socket.io/" });
```

This setup ensures your manual trades go through the same internal logic (pricing, validation, and analytics) as live trades — just locally.

***

### 📡 Connecting with Socket.IO

* **Port:** `8080`
* **Namespace:** `/socket.io/`
* **Protocol:** WebSocket (via Socket.IO client)

All communications must target the `/socket.io/` namespace.\
If you send HTTP requests elsewhere, the server rejects them automatically.

***

### 🧾 Request Payload Schema

All trade actions share the same `OrderRequest` schema.\
Below is the complete list of available fields.

| Field                               | Type     | Required              | Description                                                                                 |
| ----------------------------------- | -------- | --------------------- | ------------------------------------------------------------------------------------------- |
| `id`                                | `string` | optional              | Used to correlate requests and responses.                                                   |
| `token`                             | `string` | ✅ required            | Base58 token address.                                                                       |
| `amount`                            | `float`  | optional              | Custom SOL amount for `"buy"`.                                                              |
| `sellPercentage`                    | `int`    | required for `"sell"` | Percentage (1–100) to sell.                                                                 |
| `buyMc`                             | `float`  | required for `"add"`  | Market cap (USD) when seeding a manual position.                                            |
| `holdings`                          | `float`  | required for `"add"`  | Number of tokens held for the added position.                                               |
| `buyPriorityFee`, `sellPriorityFee` | `float`  | optional              | Override default priority fees.                                                             |
| `buySlippage`, `sellSlippage`       | `float`  | optional              | Override slippage settings.                                                                 |
| `processor`                         | `string` | optional              | Choose routing processor: `"jito"`, `"blox"`, `"temporal"`, `"zeroslot"`, or `"astralane"`. |
| `processorFee`                      | `float`  | optional              | Custom fee when a processor is set.                                                         |

**Server-side validation** ensures required fields are present.\
If validation fails, the server emits an `"error"` response with a descriptive message.

***

### 🚀 Supported Actions

#### **1. `"buy"`**

Places a **market buy** for the requested token.\
Optional fields let you override:

* Buy amount
* Priority fee
* Slippage
* Processor routing

Once executed, the trader posts a `"confirmed"` response with trade details.

***

#### **2. `"sell"`**

Sells all or part of your current position.

* Requires `sellPercentage` (e.g. `25`, `50`, `100`)
* The system automatically looks up your holdings and executes a proportional sell.
* Emits a `DEV_MODE` signal into the normal exit flow.

***

#### **3. `"add"`**

Seeds Dev Mode with a **manual position** you already hold.\
You must include:

* `token`
* `buyMc` (market cap at entry)
* `holdings`

The server reconstructs the position, calculates spent SOL, and begins PnL tracking.\
You can later sell this token using `"sell"` through Dev Mode.

***

### 🔁 Response Flow

All responses are emitted on the `"response"` event.\
Each includes:

| Field     | Description                                            |
| --------- | ------------------------------------------------------ |
| `type`    | `"buy"`, `"sell"`, `"add"`, or `"error"`               |
| `id`      | The correlated request ID                              |
| `amounts` | Amounts traded                                         |
| `tx`      | Transaction signature (if applicable)                  |
| `status`  | `"received"`, `"queued"`, `"confirmed"`, or `"failed"` |
| `message` | Optional error or info text                            |

#### Example Flow

1. You send a `"buy"` request with `id: "123"`.
2. The server validates it → sends `"received"`.
3. After execution, it emits a `"confirmed"` response (including on-chain signature).
4. Your client matches responses by `id` to update the UI or CLI.

***

### 🧩 Example Usage

```js
socket.emit("buy", {
  id: "trade1",
  token: "So11111111111111111111111111111111111111112",
  amount: 0.5,
  buyPriorityFee: 0.0005,
  processor: "jito",
});

socket.on("response", (res) => {
  console.log("Response:", res);
});
```

***

### ✅ Summary

| Feature            | Description                                                 |
| ------------------ | ----------------------------------------------------------- |
| Local Testing      | Trade manually without touching live funds                  |
| Full Logic Reuse   | Uses same pricing, analytics, and validation as main trader |
| Real-Time Feedback | `"response"` events mirror production flow                  |
| Extensible         | Supports all processors and fee overrides                   |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.leap-blockchain.com/leap-trading-sol-bot/leap-trading-bot-setup/dev-mode-solana.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
