# APIs & Payloads

This section documents the available API endpoints for executing trades, managing positions, and automating actions with the RenkoGurus VPS Bot. These endpoints are optimized for speed, reliability, and compatibility with TradingView webhooks or manual triggers.

***

### 🚀 API Endpoints Summary

| Endpoint               | Method | Description                                                                            |
| ---------------------- | ------ | -------------------------------------------------------------------------------------- |
| `/place-order`         | POST   | Places a new order with optional bracket, stop loss, take profit, and trailing offset. |
| `/flatten-all`         | POST   | Closes all open positions and cancels all working orders for the given symbol.         |
| `/close-all-positions` | POST   | Closes all open positions for a particular Symbol                                      |
| `/reverse-order`       | POST   | Reverses the current position by placing an opposite market order.                     |

***

### ✅ `/place-order`

**Method:** `POST`\
**Description:** Places a new order for the given account and symbol with full support for bracket orders and custom trade windows.

#### 🔧 Payload Example

```json
{
  "accountName": "PRACTICEAPR812677831",
  "action": "Sell",
  "orderType": "Bracket",
  "symbol": "MNQ",
  "qty": 1,
  "limitPrice": 150.25,
  "stopPrice": 30,
  "takeProfit": 30,
  "trailingOffset": 0.0,
  "closeExistingOrders": "false",
  "tradeTimeRanges": [""],
  "avoidTradeTimeRanges": [""]
}
```

#### 📌 Field Descriptions

| Field                  | Description                                                   | Possible Values                    | Required |
| ---------------------- | ------------------------------------------------------------- | ---------------------------------- | -------- |
| `accountName`          | Tradovate account identifier                                  | Example: "PRACTICEAPR812677831"    | ✅ Yes    |
| `action`               | Direction of the trade                                        | `"Buy"`, `"Sell"`                  | ✅ Yes    |
| `orderType`            | Type of order to be placed                                    | `"Market"`, `"Limit"`, `"Bracket"` | ✅ Yes    |
| `symbol`               | Ticker symbol for the instrument                              | Example: `"MNQ"`, `"ES"`           | ✅ Yes    |
| `qty`                  | Number of contracts                                           | Any positive integer               | ✅ Yes    |
| `limitPrice`           | Price for limit entry (used for limit/bracket orders)         | Numeric                            | ❌ No     |
| `stopPrice`            | Stop loss distance or trigger price                           | Numeric                            | ❌ No     |
| `takeProfit`           | Take profit distance or trigger price                         | Numeric                            | ❌ No     |
| `trailingOffset`       | Trailing stop distance (if using trailing stop)               | Numeric                            | ❌ No     |
| `closeExistingOrders`  | Whether to cancel existing open orders before placing new one | `"true"`, `"false"`                | ❌ No     |
| `tradeTimeRanges`      | Time windows to allow trade execution                         | `["09:30-16:00"]`, etc.            | ❌ No     |
| `avoidTradeTimeRanges` | Time windows to block trade execution                         | `["12:00-13:00"]`, etc.            | ❌ No     |

***

### 🧹 `/flatten-all`

**Method:** `POST`\
**Description:** Closes all open positions _and_ cancels all working orders for the specified symbol and account.

#### 🔧 Payload Example

```json
{
  "accountName": "PRACTICEMAR1711838981",
  "symbol": "MNQ"
}
```

#### 📌 Field Descriptions

| Field         | Description                  | Example                   | Required |
| ------------- | ---------------------------- | ------------------------- | -------- |
| `accountName` | Tradovate account identifier | `"PRACTICEMAR1711838981"` | ✅ Yes    |
| `symbol`      | Ticker symbol to flatten     | `"MNQ"`, `"ES"`           | ✅ Yes    |

***

### ✂️ `/close-all-positions`

**Method:** `POST`\
**Description:** Closes all open positions for the specified symbol&#x20;

#### 🔧 Payload Example

```json
{
  "accountName": "PRACTICEMAR1711838981",
  "symbol": "MNQ"
}
```

#### 📌 Field Descriptions

| Field         | Description                         | Example                   | Required |
| ------------- | ----------------------------------- | ------------------------- | -------- |
| `accountName` | Tradovate account identifier        | `"PRACTICEMAR1711838981"` | ✅ Yes    |
| `symbol`      | Ticker symbol to close positions on | `"MNQ"`, `"ES"`           | ✅ Yes    |

***

### 🔁 `/reverse-order`

**Method:** `POST`\
**Description:** Reverses the current position for the given symbol by immediately closing the position and entering an opposite market order of equal size.

#### 🔧 Payload Example

```json
{
  "accountName": "PRACTICEMAR1711838981",
  "symbol": "MNQ"
}
```

#### 📌 Field Descriptions

| Field         | Description                       | Example                   | Required |
| ------------- | --------------------------------- | ------------------------- | -------- |
| `accountName` | Tradovate account identifier      | `"PRACTICEMAR1711838981"` | ✅ Yes    |
| `symbol`      | Ticker symbol to reverse order on | `"MNQ"`, `"ES"`           | ✅ Yes    |
