OpenMM Grid Trading
Create automated grid trading strategies that profit from market volatility.
What is Grid Trading?
Grid trading places multiple buy and sell orders at preset price intervals around the current center price. As price oscillates, the bot automatically:
- - Buys low — places buy orders below the center price
- Sells high — places sell orders above the center price
- Profits from volatility — each complete cycle captures the spread
The grid uses levels per side and spacing to distribute orders. With 5 levels and 2% spacing (linear), orders are placed at 2%, 4%, 6%, 8%, 10% from center on both sides (10 total orders).
When to Use
Good for:
- - Sideways/ranging markets
- High volatility pairs
- Passive income generation
- 24/7 automated trading
Avoid when:
- - Strong trending markets (risk of holding losing positions)
- Low liquidity pairs
- High fee environments
Quick Start
1. Dry Run First (Always!)
CODEBLOCK0
2. Start Grid with Defaults
CODEBLOCK1
3. Custom Configuration
CODEBLOCK2
4. Stop the Strategy
Press Ctrl+C to gracefully stop. The system will:
- 1. Cancel all open orders
- Disconnect from exchange
- Display final status
Command Options
Required Parameters
- -
--strategy grid — Specifies grid trading strategy - INLINECODE2 — Exchange to trade on (mexc, bitget, gateio, kraken)
- INLINECODE3 — Trading pair (e.g., INDY/USDT, SNEK/USDT, ADA/EUR)
Grid Parameters
| Parameter | Description | Default |
|---|
| INLINECODE4 | Grid levels each side (max: 10, total = levels x 2) | 5 |
| INLINECODE5 |
Base price spacing between levels (0.02 = 2%) | 0.02 |
|
--size <number> | Base order size in quote currency | 50 |
|
--confidence <decimal> | Minimum price confidence to trade | 0.6 |
|
--deviation <decimal> | Price deviation to trigger grid recreation | 0.015 |
|
--debounce <ms> | Delay between grid adjustments | 2000 |
|
--max-position <decimal> | Max position size as % of balance | 0.8 |
|
--safety-reserve <decimal> | Safety reserve as % of balance | 0.2 |
|
--dry-run | Simulate without placing real orders | — |
Dynamic Grid Parameters
| Parameter | Description | Default |
|---|
| INLINECODE13 | linear, geometric, or custom | linear |
| INLINECODE14 |
Geometric spacing multiplier per level | 1.3 |
|
--size-model <model> | flat, pyramidal, or custom | flat |
|
--grid-profile <path> | Load grid config from a JSON profile file | — |
Volatility Parameters
| Parameter | Description | Default |
|---|
| INLINECODE17 | Enable volatility-based spread adjustment | off |
| INLINECODE18 |
Low volatility threshold | 0.02 |
|
--volatility-high <decimal> | High volatility threshold | 0.05 |
Spacing Models
Linear (default): Equal spacing between all levels.
CODEBLOCK3
Geometric: Tighter spacing near center, wider gaps at outer levels.
openmm trade --strategy grid --exchange kraken --symbol BTC/USD \
--levels 5 --spacing 0.005 --spacing-model geometric --spacing-factor 1.5
CODEBLOCK5
Custom: Define exact spacing offsets per level using a grid profile JSON file.
Size Models
Flat (default): All levels get equal order sizes.
Pyramidal: Larger orders near center price where fills are more likely, tapering at outer levels.
CODEBLOCK6
Grid Profiles
JSON files for complete grid configuration:
CODEBLOCK7
CODEBLOCK8
Volatility-Based Spread Adjustment
When enabled, the grid automatically widens during volatile conditions and tightens when the market calms. Tracks price changes over a 5-minute rolling window.
- - Below low threshold (default 2%): Normal spacing (1.0x)
- Between thresholds: Elevated spacing (1.5x)
- Above high threshold (default 5%): Wide spacing (2.0x)
CODEBLOCK9
Trading Examples
Conservative
CODEBLOCK10
Active
CODEBLOCK11
Dynamic (Geometric + Pyramidal)
CODEBLOCK12
Risk Management
- -
--max-position — Maximum % of balance used for trading (default: 80%) - INLINECODE21 — % of balance kept as reserve (default: 20%)
- INLINECODE22 — Minimum price confidence required (default: 60%)
- Grid is automatically recreated when orders are filled
- Adjusts to significant price movements (configurable via
--deviation)
Exchange-Specific Notes
MEXC/Gate.io: Minimum order value 1 USDT per order
Bitget: Minimum 1 USDT. Requires API key, secret, and passphrase. 6 decimal price precision for SNEK/NIGHT pairs.
Kraken: Minimum 5 EUR/USD per order. Supports major fiat pairs (EUR, USD, GBP).
Tips for Agents
- 1. Always dry-run first — show user the plan before executing
- Check balance — verify sufficient funds with INLINECODE24
- Check current price — use INLINECODE25
- Respect minimum order values — ensure
--size divided by --levels meets exchange minimums - Use Ctrl+C to stop — graceful shutdown cancels all open orders
OpenMM 网格交易
创建自动化网格交易策略,从市场波动中获利。
什么是网格交易?
网格交易在当前中心价格周围预设的价格区间内放置多个买入和卖出订单。当价格波动时,机器人会自动:
- - 低买 — 在中心价格下方放置买入订单
- 高卖 — 在中心价格上方放置卖出订单
- 从波动中获利 — 每个完整周期捕获价差
网格使用每侧层数和间距来分布订单。使用5层和2%间距(线性),订单放置在距中心2%、4%、6%、8%、10%的位置(共10个订单)。
何时使用
适合:
- - 横盘/震荡市场
- 高波动性交易对
- 被动收入生成
- 7x24小时自动化交易
避免:
- - 强趋势市场(存在持有亏损头寸的风险)
- 低流动性交易对
- 高手续费环境
快速开始
1. 先进行模拟运行(务必!)
bash
openmm trade --strategy grid --exchange mexc --symbol INDY/USDT --dry-run
2. 使用默认设置启动网格
bash
openmm trade --strategy grid --exchange mexc --symbol INDY/USDT
3. 自定义配置
bash
openmm trade --strategy grid --exchange mexc --symbol INDY/USDT \
--levels 5 \
--spacing 0.02 \
--size 50 \
--max-position 0.6 \
--safety-reserve 0.3
4. 停止策略
按下 Ctrl+C 优雅停止。系统将:
- 1. 取消所有未成交订单
- 断开与交易所的连接
- 显示最终状态
命令选项
必需参数
- - --strategy grid — 指定网格交易策略
- --exchange <交易所> — 交易的交易所(mexc、bitget、gateio、kraken)
- --symbol <交易对> — 交易对(例如 INDY/USDT、SNEK/USDT、ADA/EUR)
网格参数
| 参数 | 描述 | 默认值 |
|---|
| --levels <数字> | 每侧网格层数(最大:10,总计 = 层数 x 2) | 5 |
| --spacing <小数> |
层间基础价格间距(0.02 = 2%) | 0.02 |
| --size <数字> | 以报价货币计的基础订单大小 | 50 |
| --confidence <小数> | 交易所需的最低价格置信度 | 0.6 |
| --deviation <小数> | 触发网格重建的价格偏差 | 0.015 |
| --debounce <毫秒> | 网格调整之间的延迟 | 2000 |
| --max-position <小数> | 最大持仓大小占余额百分比 | 0.8 |
| --safety-reserve <小数> | 安全储备占余额百分比 | 0.2 |
| --dry-run | 模拟运行,不实际下单 | — |
动态网格参数
| 参数 | 描述 | 默认值 |
|---|
| --spacing-model <模型> | 线性、几何或自定义 | linear |
| --spacing-factor <数字> |
每层几何间距乘数 | 1.3 |
| --size-model <模型> | 扁平、金字塔或自定义 | flat |
| --grid-profile <路径> | 从JSON配置文件加载网格配置 | — |
波动性参数
| 参数 | 描述 | 默认值 |
|---|
| --volatility | 启用基于波动性的价差调整 | off |
| --volatility-low <小数> |
低波动性阈值 | 0.02 |
| --volatility-high <小数> | 高波动性阈值 | 0.05 |
间距模型
线性(默认): 所有层之间等距。
使用 --spacing 0.02 和 5层:
第1层:距中心 2%
第2层:距中心 4%
第3层:距中心 6%
第4层:距中心 8%
第5层:距中心 10%
几何: 靠近中心间距更紧密,外层间距更宽。
bash
openmm trade --strategy grid --exchange kraken --symbol BTC/USD \
--levels 5 --spacing 0.005 --spacing-model geometric --spacing-factor 1.5
第1层:距中心 0.50%
第2层:距中心 1.25%
第3层:距中心 2.38%
第4层:距中心 4.06%
第5层:距中心 6.59%
自定义: 使用网格配置文件JSON定义每层的精确间距偏移量。
大小模型
扁平(默认): 所有层获得相同的订单大小。
金字塔: 靠近中心价格(更易成交)的订单更大,外层逐渐减小。
bash
openmm trade --strategy grid --exchange mexc --symbol INDY/USDT \
--levels 5 --size 50 --size-model pyramidal
网格配置文件
用于完整网格配置的JSON文件:
json
{
name: balanced-geometric,
description: 几何间距配合金字塔大小,
levels: 10,
spacingModel: geometric,
baseSpacing: 0.005,
spacingFactor: 1.3,
sizeModel: pyramidal,
baseSize: 50
}
bash
openmm trade --strategy grid --exchange gateio --symbol SNEK/USDT \
--grid-profile ./profiles/balanced-geometric.json
基于波动性的价差调整
启用后,网格在波动条件下自动扩大价差,在市场平静时收紧价差。追踪5分钟滚动窗口内的价格变化。
- - 低于低阈值(默认2%):正常间距(1.0倍)
- 介于阈值之间:提高间距(1.5倍)
- 高于高阈值(默认5%):宽间距(2.0倍)
bash
openmm trade --strategy grid --exchange mexc --symbol INDY/USDT \
--levels 10 \
--spacing 0.005 \
--spacing-model geometric \
--spacing-factor 1.3 \
--size-model pyramidal \
--size 5 \
--volatility
交易示例
保守型
bash
openmm trade --strategy grid --exchange bitget --symbol SNEK/USDT \
--levels 2 \
--spacing 0.02 \
--size 20
活跃型
bash
openmm trade --strategy grid --exchange mexc --symbol BTC/USDT \
--levels 7 \
--spacing 0.005 \
--size 25
动态型(几何 + 金字塔)
bash
openmm trade --strategy grid --exchange kraken --symbol SNEK/EUR \
--levels 10 \
--spacing 0.005 \
--spacing-model geometric \
--spacing-factor 1.5 \
--size-model pyramidal \
--size 5
风险管理
- - --max-position — 用于交易的最大余额百分比(默认:80%)
- --safety-reserve — 保留为储备的余额百分比(默认:20%)
- --confidence — 所需的最低价格置信度(默认:60%)
- 订单成交时自动重建网格
- 适应显著的价格变动(可通过 --deviation 配置)
交易所特定说明
MEXC/Gate.io: 每笔订单最低价值1 USDT
Bitget: 最低1 USDT。需要API密钥、密钥和密码。SNEK/NIGHT交易对价格精度为6位小数。
Kraken: 每笔订单最低5 EUR/USD。支持主要法币交易对(EUR、USD、GBP)。
给代理的提示
- 1. 始终先模拟运行 — 在执行前向用户展示计划
- 检查余额 — 使用 openmm balance --exchange <交易所> 验证资金充足
- 检查当前价格 — 使用 openmm ticker --exchange <交易所> --symbol <交易对>
- 遵守最低订单价值 — 确保 --size 除以 --levels 满足交易所最低要求
- 使用Ctrl+C停止 — 优雅关闭会取消所有未成交订单