forked from LengKundee/MQL5-Google-Onedrive
283 lines
5.8 KiB
Markdown
283 lines
5.8 KiB
Markdown
# 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 `6a2f2d3a91380985c9ada6d39219fb353b4291b2` with headless mode fixes
|
|
|
|
### Key Improvements
|
|
1. **Better Headless Mode Detection**: Fixed detection for non-interactive environments
|
|
2. **CI Environment Support**: Automatic detection of CI/GitHub Actions environments
|
|
3. **Query Option Support**: Added support for `query` parameter
|
|
4. **Command-line Flag Detection**: Fallback checking for `-p`, `--prompt`, `-y`, and `--yolo` flags
|
|
|
|
## Installation
|
|
|
|
### First Time Setup
|
|
|
|
```bash
|
|
# 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
|
|
|
|
```bash
|
|
# Check version
|
|
npx gemini --version
|
|
|
|
# Should output: 0.30.0-nightly.20260212.207ac6f2d
|
|
|
|
# View help
|
|
npx gemini --help
|
|
```
|
|
|
|
## Usage
|
|
|
|
### Interactive Mode (Terminal Chat)
|
|
|
|
```bash
|
|
npx gemini
|
|
```
|
|
|
|
This starts an interactive chat session with Gemini.
|
|
|
|
### Non-Interactive Mode (Headless)
|
|
|
|
```bash
|
|
# 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:
|
|
|
|
1. **Trade Confirmation** (via EA):
|
|
- Set `UseGeminiFilter = true`
|
|
- Set `AiProvider = PROVIDER_GEMINI`
|
|
- Add your API key to `GeminiApiKey`
|
|
|
|
2. **Market Research** (automated scripts):
|
|
```bash
|
|
python scripts/market_research.py
|
|
```
|
|
|
|
3. **Code Upgrades** (automated suggestions):
|
|
```bash
|
|
python scripts/upgrade_repo.py
|
|
```
|
|
|
|
## Configuration
|
|
|
|
### API Key Setup
|
|
|
|
You need a Google AI API key from [Google AI Studio](https://aistudio.google.com/).
|
|
|
|
#### Option 1: Environment Variable (Recommended)
|
|
|
|
Add to your shell profile or `.env` file:
|
|
|
|
```bash
|
|
export GEMINI_API_KEY="your_api_key_here"
|
|
```
|
|
|
|
#### Option 2: Settings File
|
|
|
|
Create `~/.gemini/settings.json`:
|
|
|
|
```json
|
|
{
|
|
"auth": {
|
|
"apiKey": "your_api_key_here"
|
|
}
|
|
}
|
|
```
|
|
|
|
### MT5 WebRequest Setup
|
|
|
|
For EA integration, enable WebRequests in MT5:
|
|
|
|
1. Open MT5 → **Tools → Options → Expert Advisors**
|
|
2. Check **"Allow WebRequest for listed URL"**
|
|
3. Add: `https://generativelanguage.googleapis.com`
|
|
|
|
## Testing the Integration
|
|
|
|
### Basic Test
|
|
|
|
```bash
|
|
# Test version
|
|
npx gemini --version
|
|
|
|
# Test non-interactive mode
|
|
npx gemini --prompt "Hello, Gemini!"
|
|
```
|
|
|
|
### Full Setup Test
|
|
|
|
```bash
|
|
# 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`:
|
|
|
|
```bash
|
|
npx gemini --version
|
|
```
|
|
|
|
Or install globally:
|
|
|
|
```bash
|
|
npm install -g @google/gemini-cli
|
|
```
|
|
|
|
### API Key Issues
|
|
|
|
If you get authentication errors:
|
|
|
|
1. Verify your API key at [Google AI Studio](https://aistudio.google.com/)
|
|
2. Check the key is set in environment or settings file
|
|
3. Test with: `npx gemini --prompt "test"`
|
|
|
|
### WebRequest Errors in MT5
|
|
|
|
If the EA can't connect to Gemini:
|
|
|
|
1. Check MT5 allowed URLs (Tools → Options → Expert Advisors)
|
|
2. Add `https://generativelanguage.googleapis.com`
|
|
3. Restart MT5 terminal
|
|
|
|
## Features Enabled by Gemini CLI
|
|
|
|
### 1. AI Trade Confirmation
|
|
|
|
The EA can ask Gemini to confirm trades before execution:
|
|
|
|
```mql5
|
|
// 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:
|
|
|
|
```bash
|
|
./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:
|
|
|
|
```bash
|
|
python scripts/upgrade_repo.py
|
|
```
|
|
|
|
Generates: `docs/upgrade_suggestions.md`
|
|
|
|
### 4. Scheduled Research
|
|
|
|
Automatic research every 4 hours:
|
|
|
|
```bash
|
|
python scripts/schedule_research.py
|
|
```
|
|
|
|
## Advanced Usage
|
|
|
|
### Custom Models
|
|
|
|
```bash
|
|
# 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
|
|
|
|
```bash
|
|
# 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
|
|
|
|
```bash
|
|
# List sessions
|
|
npx gemini --list-sessions
|
|
|
|
# Resume session
|
|
npx gemini --resume latest
|
|
|
|
# Delete session
|
|
npx gemini --delete-session 5
|
|
```
|
|
|
|
## Security Notes
|
|
|
|
1. **Never commit API keys** to the repository
|
|
2. Use `.env` file for local development (already in `.gitignore`)
|
|
3. Use GitHub Secrets for CI/CD workflows
|
|
4. Rotate API keys regularly
|
|
5. Monitor API usage at Google AI Studio
|
|
|
|
## Resources
|
|
|
|
- [Gemini CLI Documentation](https://github.com/google-gemini/gemini-cli)
|
|
- [Google AI Studio](https://aistudio.google.com/)
|
|
- [Gemini API Documentation](https://ai.google.dev/docs)
|
|
- [Local Setup Guide](./Gemini_CLI_setup.md)
|
|
|
|
## 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](../mt5/MQL5/Experts/README.md)
|