Install
openclaw skills install vibetrading-code-genGenerate executable Hyperliquid trading strategy code from natural language prompts. Use when a user wants to create automated trading strategies for Hyperliquid exchange based on their trading ideas, technical indicators, or VibeTrading signals. The skill generates complete Python code with proper error handling, logging, and configuration using actual Hyperliquid API wrappers.
openclaw skills install vibetrading-code-genGenerate executable Hyperliquid trading strategy code from natural language prompts. This skill transforms trading ideas into ready-to-run Python code using actual Hyperliquid API implementations. Generated code includes complete API integration, error handling, logging, and configuration management.
# Generate a simple RSI strategy
python scripts/strategy_generator.py "Generate a BTC RSI strategy, buy below 30, sell above 70"
# Generate a grid trading strategy
python scripts/strategy_generator.py "BTC grid trading 50000-60000 10 grids 0.01 BTC per grid"
# Generate a signal-following strategy
python scripts/strategy_generator.py "ETH trading strategy based on VibeTrading signals, buy on bullish signals, sell on bearish signals"
The generator creates:
All generated code is automatically validated and fixed using the built-in validation system:
# Validate generated code
python scripts/code_validator.py generated_strategy.py
# Validate and fix automatically
python scripts/code_validator.py generated_strategy.py --fix
# Validate entire directory
python scripts/code_validator.py strategy_directory/
The validation system performs these checks:
When validation fails, the system automatically fixes common issues:
# -*- coding: utf-8 -*- if missingThe validation system can be configured via command-line arguments:
# Basic validation
python scripts/code_validator.py strategy.py
# Validate and fix automatically
python scripts/code_validator.py strategy.py --fix
# Use specific Python executable
python scripts/code_validator.py strategy.py --python python3.6
# Validate directory with all files
python scripts/code_validator.py strategies/ --fix
# Maximum 5 fix iterations
python scripts/code_validator.py strategy.py --fix --max-iterations 5
The system enforces these rules for generated code:
Python 3.5+ Compatibility
.format() or % formatting)os.path instead)Code Quality
# -*- coding: utf-8 -*-)Security
Performance
User Prompt → Code Generation → Validation → Fixes → Final Code
↓
If validation fails
↓
Apply automatic fixes
↓
Re-validate until success
↓
Deliver validated code
When validation fails, the system automatically updates the code with these steps:
# Before (error: NameError: name 'List' is not defined)
def calculate_prices(prices: List[float]) -> List[float]:
# After (automatic fix)
from typing import List, Dict, Optional
def calculate_prices(prices):
# Before (error: SyntaxError: Non-ASCII character)
# Strategy description: Grid trading
# After (automatic fix)
# -*- coding: utf-8 -*-
# Strategy description: Grid trading
# Before (error: SyntaxError in Python 3.5)
price = f"Current price: {current_price}"
# After (automatic fix)
price = "Current price: {}".format(current_price)
# Before (error: ImportError: No module named 'hyperliquid_api')
from hyperliquid_api import HyperliquidClient
# After (automatic fix)
import sys
import os
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "api_wrappers"))
from hyperliquid_api import HyperliquidClient
The generator analyzes your natural language prompt to identify:
Based on the analysis, the system selects the most appropriate template from:
templates/grid_trading.py - Grid trading strategy templateThe generator:
The generated code is automatically validated and fixed:
If validation fails after automatic fixes:
You receive validated, runnable code including:
The generated code uses mature Hyperliquid API implementations that support:
Each template includes:
grid_trading.py - Grid trading within price ranges (Python 3.5+ compatible)
Generated strategies include configurable parameters:
STRATEGY_CONFIG = {
"symbol": "BTC",
"timeframe": "1h",
"parameters": {
"rsi_period": 14,
"oversold": 30,
"overbought": 70
},
"risk_management": {
"position_size": 0.01,
"stop_loss": 0.05,
"take_profit": 0.10,
"max_drawdown": 0.20
}
}
# Required environment variables
export HYPERLIQUID_API_KEY="your_api_key_here"
export HYPERLIQUID_ACCOUNT_ADDRESS="your_address_here"
export TELEGRAM_BOT_TOKEN="optional_for_alerts"
All generated strategies include:
Generated strategies can integrate with VibeTrading Global Signals:
from vibetrading import get_latest_signals
# Get AI-generated signals
signals = get_latest_signals("BTC,ETH")
# Use signals in trading logic
if signals["BTC"]["sentiment"] == "BULLISH":
strategy.execute_buy("BTC", amount=0.01)
Prompt: "Generate a BTC RSI strategy, buy 0.01 BTC when RSI below 30, sell when above 70"
Generated Code Features:
Prompt: "ETH grid trading strategy, price range 3000-4000, 20 grids, 0.1 ETH per grid"
Generated Code Features:
Prompt: "SOL trading strategy based on VibeTrading signals, buy on bullish signals, sell on bearish signals, 10 SOL per trade"
Generated Code Features:
# Check API key and account address
echo $HYPERLIQUID_API_KEY
echo $HYPERLIQUID_ACCOUNT_ADDRESS
# Test API connection
python scripts/test_connection.py
# Common validation errors and solutions:
# Error: "SyntaxError: invalid syntax"
# Solution: Check for f-strings or type annotations
python scripts/code_validator.py strategy.py --fix
# Error: "ImportError: No module named 'typing'"
# Solution: Remove typing imports (Python 3.4 compatibility)
sed -i '' 's/from typing import.*//g' strategy.py
# Error: "SyntaxError: Non-ASCII character"
# Solution: Add encoding declaration
echo -e '# -*- coding: utf-8 -*-\n' | cat - strategy.py > temp && mv temp strategy.py
# Error: "NameError: name 'List' is not defined"
# Solution: Remove type annotations or add typing import
sed -i '' 's/: List//g; s/: Dict//g; s/: Optional//g' strategy.py
# Manual validation check
python -m py_compile strategy.py
You can create custom templates in templates/custom/:
{{variable_name}}scripts/template_registry.pyWhile this generator focuses on live trading, you can:
For running multiple strategies:
examples/This skill will be updated with:
After generating a strategy, you can now evaluate its performance using our integrated backtesting system:
# Generate a strategy
python scripts/strategy_generator.py "BTC grid trading 50000-60000 10 grids 0.01 BTC per grid"
# Run backtest on the generated strategy
python scripts/backtest_runner.py generated_strategies/btc_grid_trading_strategy.py
# Run backtest with custom parameters
python scripts/backtest_runner.py generated_strategies/btc_grid_trading_strategy.py \
--start-date 2025-01-01 \
--end-date 2025-03-01 \
--initial-balance 10000 \
--interval 1h
The backtesting system provides:
Historical Data Simulation - Uses historical price data for realistic testing
Performance Metrics - Calculates key metrics:
Risk Analysis - Evaluates strategy risk characteristics
Visual Reports - Generates charts and performance reports
Comparative Analysis - Compares strategy performance against benchmarks
You can configure backtests with these parameters:
BACKTEST_CONFIG = {
"start_date": "2025-01-01",
"end_date": "2025-03-01",
"initial_balance": 10000, # USDC
"interval": "1h", # 1m, 5m, 15m, 30m, 1h, 4h, 1d
"symbols": ["BTC", "ETH"], # Trading symbols
"commission_rate": 0.001, # 0.1% trading commission
"slippage": 0.001, # 0.1% slippage
}
📊 Backtest Results for BTC Grid Trading Strategy
================================================
📅 Period: 2025-01-01 to 2025-03-01 (60 days)
💰 Initial Balance: $10,000.00
💰 Final Balance: $11,234.56
📈 Performance Metrics:
• Total Return: +12.35%
• Max Drawdown: -5.67%
• Sharpe Ratio: 1.45
• Win Rate: 58.3%
• Total Trades: 120
• Avg Trade Duration: 12.5 hours
📋 Trade Analysis:
• Winning Trades: 70
• Losing Trades: 50
• Largest Win: +$245.67
• Largest Loss: -$123.45
• Avg Win: +$89.12
• Avg Loss: -$56.78
⚠️ Risk Assessment:
• Risk-Adjusted Return: Good
• Drawdown Control: Acceptable
• Consistency: Moderate
Generated strategies now include backtest compatibility:
# Generated strategy includes backtest method
strategy = GridTradingStrategy(api_key, account_address, config)
# Run backtest
backtest_results = strategy.run_backtest(
start_date="2025-01-01",
end_date="2025-03-01",
initial_balance=10000
)
# Generate backtest report
strategy.generate_backtest_report(backtest_results)
The backtesting system uses:
Important Notes:
Best Practices:
Validation Limitations: While the code validation system automatically fixes common issues, it cannot guarantee:
Validation Success Criteria: Code is considered "valid" when:
Not Validated:
# Check Python version
python scripts/check_python_version.py
# Minimum: Python 3.6+ (for f-string support)
# Generate strategy
python scripts/strategy_generator.py "BTC grid trading 50000-60000 10 grids"
# Run backtest
python scripts/backtest_runner.py generated_strategies/btc_grid_trading_strategy.py
Important: Trading cryptocurrencies involves significant risk. Generated strategies should be thoroughly tested before use with real funds. Past performance is not indicative of future results. Always use proper risk management and never trade with money you cannot afford to lose.
The code generator provides tools for strategy creation, but ultimate responsibility for trading decisions and risk management lies with the user.
Validation is not a substitute for:
Backtesting Limitations: