ig_create_working_order
Place a working order on IG Trading by specifying epic, direction, size, currency, expiry, type, level, and time in force. Manage stop loss, take profit, and use guaranteed stops for forex, indices, and commodities trading.
Instructions
Create a working order
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| currencyCode | Yes | Currency code | |
| direction | Yes | Trade direction | |
| epic | Yes | Market epic code | |
| expiry | Yes | Contract expiry | |
| forceOpen | No | Force open a new position | |
| goodTillDate | No | Expiry date for GOOD_TILL_DATE orders | |
| guaranteedStop | No | Use guaranteed stop | |
| level | Yes | Entry level | |
| limitLevel | No | Take profit level | |
| size | Yes | Order size | |
| stopLevel | No | Stop loss level | |
| timeInForce | Yes | Time in force | |
| type | Yes | Order type |
Input Schema (JSON Schema)
{
"properties": {
"currencyCode": {
"description": "Currency code",
"type": "string"
},
"direction": {
"description": "Trade direction",
"enum": [
"BUY",
"SELL"
],
"type": "string"
},
"epic": {
"description": "Market epic code",
"type": "string"
},
"expiry": {
"description": "Contract expiry",
"type": "string"
},
"forceOpen": {
"default": true,
"description": "Force open a new position",
"type": "boolean"
},
"goodTillDate": {
"description": "Expiry date for GOOD_TILL_DATE orders",
"type": "string"
},
"guaranteedStop": {
"default": false,
"description": "Use guaranteed stop",
"type": "boolean"
},
"level": {
"description": "Entry level",
"type": "number"
},
"limitLevel": {
"description": "Take profit level",
"type": "number"
},
"size": {
"description": "Order size",
"type": "number"
},
"stopLevel": {
"description": "Stop loss level",
"type": "number"
},
"timeInForce": {
"description": "Time in force",
"enum": [
"GOOD_TILL_CANCELLED",
"GOOD_TILL_DATE"
],
"type": "string"
},
"type": {
"description": "Order type",
"enum": [
"LIMIT",
"STOP"
],
"type": "string"
}
},
"required": [
"epic",
"direction",
"size",
"currencyCode",
"expiry",
"type",
"level",
"timeInForce"
],
"type": "object"
}
Implementation Reference
- src/services/ig-service.js:273-292 (handler)Core handler that validates input, posts working order to IG API endpoint /workingorders/otc, and retrieves confirmation if available.async createWorkingOrder(ticket) { this.validateWorkingOrderTicket(ticket); try { const response = await this.apiClient.post('/workingorders/otc', ticket, 2); if (response.data.dealReference) { const confirmation = await this.getConfirmation(response.data.dealReference); return { order: response.data, confirmation }; } return response.data; } catch (error) { logger.error('Failed to create working order:', error.message); throw error; } }
- src/services/mcp-service.js:276-342 (schema)Input schema and tool metadata definition used for tool listing and validation.{ name: 'ig_create_working_order', description: 'Create a working order', inputSchema: { type: 'object', properties: { epic: { type: 'string', description: 'Market epic code', }, direction: { type: 'string', enum: ['BUY', 'SELL'], description: 'Trade direction', }, size: { type: 'number', description: 'Order size', }, currencyCode: { type: 'string', description: 'Currency code', }, expiry: { type: 'string', description: 'Contract expiry', }, type: { type: 'string', enum: ['LIMIT', 'STOP'], description: 'Order type', }, level: { type: 'number', description: 'Entry level', }, stopLevel: { type: 'number', description: 'Stop loss level', }, limitLevel: { type: 'number', description: 'Take profit level', }, guaranteedStop: { type: 'boolean', description: 'Use guaranteed stop', default: false, }, forceOpen: { type: 'boolean', description: 'Force open a new position', default: true, }, timeInForce: { type: 'string', enum: ['GOOD_TILL_CANCELLED', 'GOOD_TILL_DATE'], description: 'Time in force', }, goodTillDate: { type: 'string', description: 'Expiry date for GOOD_TILL_DATE orders', }, }, required: ['epic', 'direction', 'size', 'currencyCode', 'expiry', 'type', 'level', 'timeInForce'], }, },
- src/services/mcp-service.js:657-666 (registration)MCP server tool dispatch case that calls the IGService handler and formats the response.case 'ig_create_working_order': const orderResult = await igService.createWorkingOrder(args); return { content: [ { type: 'text', text: JSON.stringify(orderResult, null, 2), }, ], };
- src/services/ig-service.js:526-541 (helper)Helper function that validates the working order ticket parameters before API submission.validateWorkingOrderTicket(ticket) { const required = ['currencyCode', 'direction', 'epic', 'expiry', 'size', 'forceOpen', 'type', 'guaranteedStop', 'timeInForce', 'level']; const missing = required.filter(field => ticket[field] === undefined); if (missing.length > 0) { throw new Error(`Missing required fields: ${missing.join(', ')}`); } if (!['LIMIT', 'STOP'].includes(ticket.type)) { throw new Error('Order type must be LIMIT or STOP'); } if (!['GOOD_TILL_CANCELLED', 'GOOD_TILL_DATE'].includes(ticket.timeInForce)) { throw new Error('TimeInForce must be GOOD_TILL_CANCELLED or GOOD_TILL_DATE'); } }