Grid Trading Executor for Automated Entry and Exit Management
Summary
The document explains a grid trading executor that places buy and sell orders at evenly spaced prices between configured bounds. Each level has an order amount and take-profit target; the executor can handle spot or perpetual futures. It tracks level states from inactive through entry and exit fills, and can cancel orders outside configured activation bounds. Batch processing is described as a way to limit the volume of exchange requests.
Risk and monitoring features include stop loss, take profit, time limits, trailing stops, position and open-order limits, and tracking of realized and unrealized profit and loss, fees, and failed orders. The example configuration illustrates how a price range, capital amount, minimum order spacing, and activation bounds are specified. The document provides no backtest, live-trading evidence, or detail on how grid spacing and position sizing should adapt to volatility. Grid strategies can be exposed to persistent price moves beyond their operating range.
Key ideas
- A grid divides a configured price range into levels for repeated entries and exits as prices fluctuate.
- Each level has an order amount and take-profit target, and the executor manages order states through completion.
- Activation bounds and cancellation rules restrict which levels have active orders near the market.
- Risk controls include barriers, trailing stops, position limits, and caps on open orders.
- The document describes execution features but provides no performance evidence or adaptive sizing method.
Tags
Full text
# Key Concepts:
The **GridExecutor:** is a sophisticated trading executor that implements a grid trading strategy.
## Key Concepts:
1. **Grid Trading**: A strategy that places multiple buy and sell orders at regular price intervals (forming a grid), attempting to profit from price oscillations within a range.
2. **Grid Levels**: The executor creates multiple price levels between a start and end price, where each level represents a potential trading opportunity.
## Main Features:
### 1. **Grid Generation**:
- Creates evenly spaced price levels between start_price and end_price
- Each level has an associated order amount and take-profit target
- Supports both spot and perpetual futures trading
### 2. **Order Management**:
- Places and monitors orders at different grid levels
- Manages both open (entry) and close (exit) orders
- Automatically cancels orders that move outside activation bounds
- Implements batch order processing to avoid overwhelming the exchange
### 3. **Risk Management**:
- Triple Barrier System:
- Stop Loss
- Take Profit
- Time Limit
- Trailing Stop functionality
- Position size limits
- Maximum open orders control
### 4. **State Management**:
Grid levels can be in different states:
- **NOT_ACTIVE**: No orders placed
- **OPEN_ORDER_PLACED**: Entry order active
- **OPEN_ORDER_FILLED**: Entry order completed
- **CLOSE_ORDER_PLACED**: Exit order active
- **COMPLETE**: Both entry and exit orders filled
### 5. **Performance Tracking**:
- Tracks realized and unrealized PnL
- Monitors fees and execution costs
- Calculates position metrics
- Records filled and failed orders
Example Usage:
```python
config = GridExecutorConfig(
connector_name="binance",
trading_pair="BTC-USDT",
start_price=30000,
end_price=40000,
total_amount_quote=1000, # Total USDT to deploy
min_spread_between_orders=0.01, # 1% minimum spread
activation_bounds=0.02, # 2% activation bounds
)
executor = GridExecutor(strategy=my_strategy, config=config)
```
The executor will:
1. Create grid levels between $30,000 and $40,000
2. Deploy $1000 USDT across these levels
3. Maintain minimum 1% spread between orders
4. Only keep active orders within 2% of current price
5. Automatically manage entry and exit orders
This is particularly useful for:
- Range-bound markets
- Market making strategies
- Automated rebalancing
- Risk-managed trading executionShown in full with attribution under the source's licence. Licence: Apache-2.0
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.