5.8 KiB
Gemini CLI Integration Guide
Overview
This project now includes Google Gemini CLI as a local npm dependency, providing AI capabilities for market analysis, trade confirmation, and code upgrades.
What's New
Version Integrated
- Package:
@google/gemini-cli - Version:
0.30.0-nightly.20260212.207ac6f2d - Includes: Commit
6a2f2d3a91380985c9ada6d39219fb353b4291b2with headless mode fixes
Key Improvements
- Better Headless Mode Detection: Fixed detection for non-interactive environments
- CI Environment Support: Automatic detection of CI/GitHub Actions environments
- Query Option Support: Added support for
queryparameter - Command-line Flag Detection: Fallback checking for
-p,--prompt,-y, and--yoloflags
Installation
First Time Setup
# Clone the repository
git clone https://github.com/A6-9V/MQL5-Google-Onedrive.git
cd MQL5-Google-Onedrive
# Install all dependencies including Gemini CLI
npm install
# Or use the setup script
bash setup.sh
# Then select option 2: Install npm dependencies
Verify Installation
# Check version
npx gemini --version
# Should output: 0.30.0-nightly.20260212.207ac6f2d
# View help
npx gemini --help
Usage
Interactive Mode (Terminal Chat)
npx gemini
This starts an interactive chat session with Gemini.
Non-Interactive Mode (Headless)
# Single prompt
npx gemini --prompt "Analyze the EURUSD market trend"
# With specific model
npx gemini --model gemini-2.0-flash --prompt "Review this trading strategy"
# YOLO mode (auto-approve all actions)
npx gemini --yolo --prompt "Generate a market report"
Integration with Trading System
The Gemini CLI is used in several places:
-
Trade Confirmation (via EA):
- Set
UseGeminiFilter = true - Set
AiProvider = PROVIDER_GEMINI - Add your API key to
GeminiApiKey
- Set
-
Market Research (automated scripts):
python scripts/market_research.py -
Code Upgrades (automated suggestions):
python scripts/upgrade_repo.py
Configuration
API Key Setup
You need a Google AI API key from Google AI Studio.
Option 1: Environment Variable (Recommended)
Add to your shell profile or .env file:
export GEMINI_API_KEY="your_api_key_here"
Option 2: Settings File
Create ~/.gemini/settings.json:
{
"auth": {
"apiKey": "your_api_key_here"
}
}
MT5 WebRequest Setup
For EA integration, enable WebRequests in MT5:
- Open MT5 → Tools → Options → Expert Advisors
- Check "Allow WebRequest for listed URL"
- Add:
https://generativelanguage.googleapis.com
Testing the Integration
Basic Test
# Test version
npx gemini --version
# Test non-interactive mode
npx gemini --prompt "Hello, Gemini!"
Full Setup Test
# Run full validation
bash setup.sh --ci
# Or interactive menu
bash setup.sh
# Select option 1: Run full validation
Troubleshooting
"gemini: command not found"
If you see this error, use npx:
npx gemini --version
Or install globally:
npm install -g @google/gemini-cli
API Key Issues
If you get authentication errors:
- Verify your API key at Google AI Studio
- Check the key is set in environment or settings file
- Test with:
npx gemini --prompt "test"
WebRequest Errors in MT5
If the EA can't connect to Gemini:
- Check MT5 allowed URLs (Tools → Options → Expert Advisors)
- Add
https://generativelanguage.googleapis.com - Restart MT5 terminal
Features Enabled by Gemini CLI
1. AI Trade Confirmation
The EA can ask Gemini to confirm trades before execution:
// In EA settings
input bool UseGeminiFilter = true;
input ENUM_AI_PROVIDER AiProvider = PROVIDER_GEMINI;
input string GeminiApiKey = "your_key_here";
2. Market Research Automation
Automated market analysis reports:
./scripts/setup_research.sh # First-time setup
python scripts/market_research.py # Run analysis
Generates: docs/market_research_report.md
3. Code Upgrade Suggestions
AI-powered code improvement suggestions:
python scripts/upgrade_repo.py
Generates: docs/upgrade_suggestions.md
4. Scheduled Research
Automatic research every 4 hours:
python scripts/schedule_research.py
Advanced Usage
Custom Models
# Use specific model
npx gemini --model gemini-2.0-flash-exp --prompt "Analyze..."
# Use preview model
npx gemini --model gemini-1.5-pro-preview --prompt "Analyze..."
Approval Modes
# Default mode (prompt for approval)
npx gemini --prompt "Analyze..."
# Auto-edit mode (auto-approve edit tools)
npx gemini --approval-mode auto_edit --prompt "Fix..."
# YOLO mode (auto-approve all)
npx gemini --approval-mode yolo --prompt "Do everything..."
# Plan mode (read-only)
npx gemini --approval-mode plan --prompt "Plan..."
Session Management
# List sessions
npx gemini --list-sessions
# Resume session
npx gemini --resume latest
# Delete session
npx gemini --delete-session 5
Security Notes
- Never commit API keys to the repository
- Use
.envfile for local development (already in.gitignore) - Use GitHub Secrets for CI/CD workflows
- Rotate API keys regularly
- Monitor API usage at Google AI Studio
Resources
Support
For issues with:
- Gemini CLI itself: https://github.com/google-gemini/gemini-cli/issues
- This integration: Open an issue in this repository
- MT5 EA integration: See EA documentation