# ig-trading-mcp
## 基本信息
- Slug: `kea0811-ig-trading-mcp`
- Source: modelscope
- Publisher: @kea0811/ig-trading-mcp
- Categories: 金融 / autonomous-agents / rag-systems
- Hosted: No
- License: Other
- Source URL: https://www.modelscope.cn/mcp/servers/@kea0811/ig-trading-mcp
## 简介
暂无描述。
## 安装提示

```bash
# 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
```

## MCP Server 详情

# ig-trading-mcp

[![npm version](https://img.shields.io/npm/v/ig-trading-mcp.svg)](https://www.npmjs.com/package/ig-trading-mcp)
[![Downloads](https://img.shields.io/npm/dm/ig-trading-mcp.svg)](https://www.npmjs.com/package/ig-trading-mcp)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org)
[![GitHub](https://img.shields.io/badge/GitHub-kea0811%2Fig--trading--mcp-blue)](https://github.com/kea0811/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)

```bash
# 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

1. **Initialize configuration:**
```bash
npx ig-trading-mcp init
```

2. **Edit `.env` with your IG credentials:**
```env
IG_API_KEY=your_api_key_here
IG_IDENTIFIER=your_username_here
IG_PASSWORD=your_password_here
IG_DEMO=true
```

3. **Test connection:**
```bash
npx ig-trading-mcp test
```

4. **Start MCP server for AI tools:**
```bash
npx ig-trading-mcp serve
```

##  Usage Examples

### Command Line Interface

```bash
# 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

```javascript
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`:

```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:

```json
{
  "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 IG
- `ig_logout` - End session
- `ig_get_accounts` - List all accounts
- `ig_switch_account` - Change active account
- `ig_get_account_activity` - View account history

**Position Management (5)**
- `ig_get_positions` - View open positions
- `ig_create_position` - Open new position
- `ig_update_position` - Modify position
- `ig_close_position` - Close specific position
- `ig_close_all_positions` - Close all positions

**Order Management (3)**
- `ig_get_working_orders` - View pending orders
- `ig_create_working_order` - Place new order
- `ig_delete_working_order` - Cancel order

**Market Data (4)**
- `ig_search_markets` - Search tradeable markets
- `ig_get_market_details` - Get market info
- `ig_get_historical_prices` - Historical data
- `ig_get_client_sentiment` - Market sentiment

**Watchlists (4)**
- `ig_get_watchlists` - View all watchlists
- `ig_get_watchlist` - Get specific watchlist
- `ig_create_watchlist` - Create watchlist
- `ig_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
```javascript
await ig.login(useEncryption = true)
await ig.logout()
await ig.getAccounts()
await ig.switchAccount(accountId)
await ig.getAccountActivity(options)
```

##…

