IG Trading MCP
Enables AI assistants to interact with IG Trading API for forex, indices, and commodities trading. Provides 21 tools for account management, position trading, order placement, market data analysis, and watchlist management.
README
ig-trading-mcp
A modern Node.js client for IG Trading API with built-in MCP (Model Context Protocol) server for AI integration. Trade forex, indices, commodities and more through IG's REST API, now with AI assistant support.
✨ Features
- 🤖 MCP Server - 21 tools for AI assistants (Claude, Cursor, etc.)
- 📊 Complete IG REST API - Trading, positions, orders, market data
- 🔐 Enterprise Security - RSA encryption, rate limiting, audit logging
- 🚀 Modern JavaScript - ES modules, async/await, full TypeScript support
- 🛡️ Battle-tested - Production-ready with comprehensive error handling
🚀 Quick Start
Install & Run with npx (no installation needed)
# Run directly with npx
npx ig-trading-mcp serve --api-key YOUR_KEY --identifier YOUR_ID --password YOUR_PWD
# Or install globally
npm install -g ig-trading-mcp
ig-trading-mcp serve
Basic Setup
- Initialize configuration:
npx ig-trading-mcp init
- Edit
.envwith your IG credentials:
IG_API_KEY=your_api_key_here
IG_IDENTIFIER=your_username_here
IG_PASSWORD=your_password_here
IG_DEMO=true
- Test connection:
npx ig-trading-mcp test
- Start MCP server for AI tools:
npx ig-trading-mcp serve
🎯 Usage Examples
Command Line Interface
# Start MCP server with credentials
npx ig-trading-mcp serve \
--api-key YOUR_API_KEY \
--identifier YOUR_USERNAME \
--password YOUR_PASSWORD \
--demo true
# Test account connection
npx ig-trading-mcp test
# List available tools
npx ig-trading-mcp tools
# Initialize config files
npx ig-trading-mcp init
As a Node.js Library
import { IGService } from 'ig-trading-mcp';
const ig = new IGService({
apiKey: 'YOUR_API_KEY',
identifier: 'YOUR_USERNAME',
password: 'YOUR_PASSWORD',
isDemo: true
});
// Login
await ig.login();
// Get accounts
const accounts = await ig.getAccounts();
console.log('Balance:', accounts.accounts[0].balance);
// Search markets
const markets = await ig.searchMarkets('EUR/USD');
// Create position
const position = await ig.createPosition({
epic: 'CS.D.EURUSD.CFD.IP',
direction: 'BUY',
size: 1,
orderType: 'MARKET',
guaranteedStop: false,
forceOpen: true
});
// Get positions
const positions = await ig.getPositions();
// Close position
await ig.closePosition(position.dealId);
// Logout
await ig.logout();
🤖 AI Integration (MCP)
Configure with Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"ig-trading": {
"command": "npx",
"args": ["ig-trading-mcp", "serve"],
"env": {
"IG_API_KEY": "your_api_key",
"IG_IDENTIFIER": "your_username",
"IG_PASSWORD": "your_password",
"IG_DEMO": "true"
}
}
}
}
Configure with Cursor
Add to .cursor/mcp.json in your project:
{
"mcpServers": {
"ig-trading": {
"command": "npx",
"args": ["ig-trading-mcp", "serve"],
"env": {
"IG_API_KEY": "${IG_API_KEY}",
"IG_IDENTIFIER": "${IG_IDENTIFIER}",
"IG_PASSWORD": "${IG_PASSWORD}",
"IG_DEMO": "true"
}
}
}
}
Available MCP Tools (21)
Account Management (5)
ig_login- Authenticate with IGig_logout- End sessionig_get_accounts- List all accountsig_switch_account- Change active accountig_get_account_activity- View account history
Position Management (5)
ig_get_positions- View open positionsig_create_position- Open new positionig_update_position- Modify positionig_close_position- Close specific positionig_close_all_positions- Close all positions
Order Management (3)
ig_get_working_orders- View pending ordersig_create_working_order- Place new orderig_delete_working_order- Cancel order
Market Data (4)
ig_search_markets- Search tradeable marketsig_get_market_details- Get market infoig_get_historical_prices- Historical dataig_get_client_sentiment- Market sentiment
Watchlists (4)
ig_get_watchlists- View all watchlistsig_get_watchlist- Get specific watchlistig_create_watchlist- Create watchlistig_add_to_watchlist- Add market to list
🔒 Security Features
- RSA Encryption - Password encryption using pidCrypt (IG-compatible)
- Secure Storage - Credentials encrypted with AES-256-GCM
- Rate Limiting - Automatic throttling (60 req/min)
- Audit Logging - Track all operations
- Session Management - JWT tokens with auto-refresh
- Input Validation - Joi schemas for all inputs
📁 Project Structure
ig-trading-mcp/
├── bin/
│ └── cli.js # CLI entry point
├── src/
│ ├── core/ # Core modules
│ │ ├── api-client.js # HTTP client
│ │ ├── config.js # Configuration
│ │ └── encryption.cjs # RSA encryption
│ ├── services/ # Business logic
│ │ ├── ig-service.js # Main IG API
│ │ └── mcp-service.js # MCP server
│ ├── security/ # Security layer
│ └── indicators/ # Trading indicators
├── examples/ # Usage examples
├── scripts/ # Utility scripts
└── package.json
🛠️ API Reference
Account Methods
await ig.login(useEncryption = true)
await ig.logout()
await ig.getAccounts()
await ig.switchAccount(accountId)
await ig.getAccountActivity(options)
Trading Methods
await ig.getPositions()
await ig.createPosition(ticket)
await ig.updatePosition(dealId, updates)
await ig.closePosition(dealId)
await ig.closeAllPositions()
Order Methods
await ig.getWorkingOrders()
await ig.createWorkingOrder(ticket)
await ig.deleteWorkingOrder(dealId)
Market Data Methods
await ig.searchMarkets(searchTerm)
await ig.getMarketDetails(epics)
await ig.getHistoricalPrices(epic, resolution, options)
await ig.getClientSentiment(marketIds)
📋 Requirements
- Node.js 18.0.0 or higher
- IG Trading Account (demo or live)
- API Key from IG (get from My IG > Settings > API keys)
🧪 Testing
# Test connection
npm test
# Test with credentials
npm run test:account
🤝 Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
🏗️ Built On
This project is built on top of gfiocco/node-ig-api, enhancing it with:
- Modern ES modules and async/await patterns
- MCP (Model Context Protocol) server for AI integration
- Enhanced security with RSA encryption
- CLI interface for easy usage with npx
- Comprehensive error handling and rate limiting
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
⚠️ Disclaimer
This software is for educational purposes only. Trading CFDs carries risk and you could lose more than your initial deposit. Use at your own risk. The authors are not responsible for any financial losses incurred through use of this software.
🔗 Resources
📞 Support
- Issues: GitHub Issues
- Discussions: GitHub Discussions
Made with ❤️ for the trading community
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。