Grid Strategy
This guide explains how to run the Grid Trading Strategy using OpenMM's unified CLI interface.
Prerequisites
Environment Setup
# Set your exchange API credentials # For MEXC export MEXC_API_KEY="your_api_key" export MEXC_SECRET_KEY="your_secret_key" # For Bitget export BITGET_API_KEY="your_api_key" export BITGET_SECRET="your_secret_key" export BITGET_PASSPHRASE="your_passphrase" # For Gate.io export GATEIO_API_KEY="your_api_key" export GATEIO_SECRET="your_secret_key" # For Kraken export KRAKEN_API_KEY="your_api_key" export KRAKEN_SECRET="your_secret_key"Install Dependencies
npm install npm run build
Quick Start
Basic Grid Strategy
MEXC Example:
Bitget Example:
Gate.io Example:
Kraken Example:
Custom Configuration
MEXC Advanced Grid:
Bitget Advanced Grid:
Kraken Advanced Grid:
Command Options
Required Parameters
--strategy grid- Specifies grid trading strategy--exchange <exchange>- Exchange to trade on (supports:mexc,bitget,gateio,kraken)--symbol <symbol>- Trading pair (e.g., INDY/USDT, SNEK/USDT, ADA/EUR, BTC/USD)
Grid Parameters
--levels <number>- Grid levels each side (default: 5, max: 10, total orders = levels x 2)--spacing <decimal>- Base price spacing between levels (default: 0.02 = 2%)--size <number>- Base order size in quote currency (default: 50)--confidence <decimal>- Minimum price confidence to trade (default: 0.6 = 60%)--deviation <decimal>- Price deviation % to trigger grid recreation (default: 0.015 = 1.5%)--debounce <ms>- Delay between grid adjustments (default: 2000ms)--max-position <decimal>- Maximum position size as % of balance (default: 0.8 = 80%)--safety-reserve <decimal>- Safety reserve as % of balance (default: 0.2 = 20%)--dry-run- Simulate trading without placing real orders
Dynamic Grid Parameters
These parameters control how order levels and sizes are distributed across the grid:
--spacing-model <model>- How spacing between levels is calculated (default:linear)linear- Equal spacing between all levelsgeometric- Spacing increases by a factor per level (wider gaps at outer levels)custom- User-defined spacing offsets via grid profile file
--spacing-factor <number>- Geometric spacing multiplier per level (default: 1.3)--size-model <model>- How order sizes are distributed across levels (default:flat)flat- Equal size for all levelspyramidal- Larger sizes near center price, smaller at outer levelscustom- User-defined weight multipliers via grid profile file
--grid-profile <path>- Load complete grid configuration from a JSON profile file
Volatility Parameters
These parameters control automatic spread adjustment based on market volatility:
--volatility- Enable volatility-based dynamic spread adjustment (off by default)--volatility-low <decimal>- Low volatility threshold (default: 0.02 = 2%). Below this, grid spacing stays normal.--volatility-high <decimal>- High volatility threshold (default: 0.05 = 5%). Above this, grid spacing is widened maximally.
Dynamic Grid Configuration
Spacing Models
Linear (default): Equal spacing between all levels. With --spacing 0.02 and 5 levels, each level is 2% apart:
Geometric: Each level's gap is multiplied by the spacing factor. This creates tighter spacing near the center price and wider gaps at the outer levels, which is more realistic for market making:
With --spacing 0.005 and --spacing-factor 1.5:
Custom: Define exact spacing offsets per level using a grid profile file (see Grid Profiles section below).
Size Models
Flat (default): All levels get equal order sizes.
Pyramidal: Larger orders near the center price where fills are more likely, tapering at outer levels:
Custom: Define exact size weight multipliers per level using a grid profile file.
Grid Profiles
Grid profiles are JSON files that define a complete grid configuration. This is useful for:
Full per-level control over spacing and sizing
Sharing and version-controlling configurations
Quickly switching between strategies
Basic profile (geometric spacing, pyramidal sizing):
Custom profile (full per-level control):
Using a profile:
Profile values override corresponding CLI parameters.
Trading Examples
Conservative Trading Strategies
MEXC - Conservative INDY Trading:
Bitget - Conservative SNEK Trading:
Kraken - Conservative ADA Trading:
Active Trading Strategies
MEXC - Active BTC Trading:
Bitget - Active NIGHT Trading:
Kraken - Active ETH Trading:
Dynamic Grid Strategies
1. Linear Spacing + Flat Sizing (default behavior):
2. Geometric Spacing + Flat Sizing:
3. Geometric Spacing + Pyramidal Sizing:
4. Linear Spacing + Pyramidal Sizing:
5. Geometric with Aggressive Factor (wider outer levels):
6. Profile-Based Grid (custom JSON config):
7. Multi-Exchange Dynamic Grid:
Volatility-Based Spread Adjustment
When enabled with --volatility, the grid automatically widens during volatile market conditions and tightens when the market calms down. The system tracks price changes over a rolling 5-minute window (10 samples at 30-second intervals) and calculates volatility as the price range divided by the average price.
How it works:
Volatility below low threshold (default 2%): Normal grid spacing (multiplier 1.0x)
Volatility between thresholds: Elevated spacing (multiplier 1.5x)
Volatility above high threshold (default 5%): Wide spacing (multiplier 2.0x)
8. Volatility with default thresholds (2% low, 5% high):
9. Volatility with custom thresholds (tighter sensitivity):
10. Volatility combined with geometric spacing:
Test Mode (No Real Orders)
MEXC Test:
Bitget Test:
Gate.io Test:
Kraken Test:
Dynamic Grid Test:
Volatility Test:
Risk Management
The Grid Strategy includes built-in risk management:
Configurable Risk Limits
Users can customize risk management through CLI parameters:
--max-position 0.6- Use max 60% of balance for trading (default: 80%)--safety-reserve 0.3- Keep 30% as safety reserve (default: 20%)--confidence 0.8- Require 80% price confidence (default: 60%)
Automatic Position Sizing
When using flat sizing, the system distributes the base order size equally across all levels. With pyramidal sizing, larger allocations are placed near the center price where fills are more likely, with smaller orders at the edges.
Total allocation is automatically capped at 80% of available balance regardless of the size model used.
Price Confidence Filtering
Only executes trades when price confidence >= minimum threshold
Sources price data from Cardano DEX via Iris API
Prevents trading on unreliable price data
Dynamic Grid Management
Recreates grid when orders are filled
Adjusts to significant price movements (configurable via
--deviation)Cancels and replaces orders as needed
Debounce mechanism prevents rapid-fire grid recreation
Monitoring Your Strategy
Real-time Updates
The strategy provides live feedback:
Graceful Shutdown
The system will:
Cancel all open orders
Disconnect from exchange
Display final status
Troubleshooting
Common Issues
Invalid credentials (MEXC):
Solution: Verify MEXC_API_KEY and MEXC_SECRET_KEY environment variables
Invalid credentials (Bitget):
Solution: Verify BITGET_API_KEY, BITGET_SECRET, and BITGET_PASSPHRASE environment variables
Invalid credentials (Gate.io):
Solution: Verify GATEIO_API_KEY and GATEIO_SECRET environment variables
Invalid credentials (Kraken):
Solution: Verify KRAKEN_API_KEY and KRAKEN_SECRET environment variables
Minimum order value (Bitget/MEXC):
Solution: Increase --size parameter or reduce number of --levels to ensure each order meets 1 USDT minimum
Minimum order value (Kraken):
Solution: Increase --size parameter or reduce number of --levels to ensure each order meets 5 EUR/USD minimum
Low price confidence:
Solution: Lower --confidence threshold or wait for better price data
Price precision error (Bitget):
Solution: This is automatically handled by the system's precision formatting. If you see this error, please report it as it indicates a system issue.
Insufficient balance:
Solution: Ensure sufficient USDT balance in your exchange account
Invalid grid profile:
Solution: Verify the profile file path exists and contains valid JSON
Invalid spacing/size model:
Solution: Use one of the supported models: linear, geometric, or custom for spacing; flat, pyramidal, or custom for sizing
Exchange-Specific Notes
Bitget Requirements:
Minimum order value: 1 USDT per order
Price precision: 6 decimal places for SNEK/NIGHT pairs
Quantity precision: 2 decimal places for SNEK/INDY/NIGHT pairs
Requires API key, secret, and passphrase for authentication
MEXC Requirements:
Minimum order value: 1 USDT per order
Flexible precision handling
Requires API key and secret for authentication
Gate.io Requirements:
Minimum order value: 1 USDT per order
Requires API key and secret for authentication
Kraken Requirements:
Minimum order value: 5 EUR/USD/GBP per order
Price precision: Maximum 6 decimal places
Quantity precision: 2 decimal places for ADA, 6-8 for BTC/ETH
Requires API key and secret for authentication
Supports major fiat pairs (EUR, USD, GBP) and crypto pairs
Last updated