The First Forex Broker Built for AI Agents

AI Trading API
& MCP Server

Build trading agents, dashboards and tools on Mega1’s open API, or connect Claude, Cursor and other MCP clients to your XBTFX account. Trade, manage positions and stream market data from your own code or in plain language.

Contract
OpenAPI 3.1
Protocol
REST + WebSocket
API keys
In the Mega1 terminal
Crypto trading
24/7
An agent at work
  1. GET/v1/whoamitrader · 2 accounts
  2. GET/v1/quotes?symbols=EURUSDbid 1.08421 · ask 1.08424
  3. POST/v1/chartEURUSD · H1 · 200 candles
  4. POST/v1/preview/ordermargin 108.42 · commission 0.35
  5. POST/v1/trade-operationskey rebalance-0142 · filled 0.10
  6. WS/v1/streamquotes · positions · account_state

Illustrative example, not real trading data.

Why build on the Mega1 API

For traders who want AI in the loop, with an API that states exactly what it does.

Your own trading agent

Write the prompt, the rules and the limits. Your agent trades through the same API as everything else in Mega1: quotes, orders, positions and the account’s live state.

A contract your AI can read

Mega1 publishes its API as an OpenAPI 3.1 document. Hand it to Claude, Cursor or any coding assistant and it knows every endpoint, field and error before it writes a line.

Orders you can safely retry

Trade operations carry an ID you choose. If the connection drops, your agent checks whether the operation went through instead of sending it twice.

Check before you send

Preview an order’s margin, commission and whether the account can afford it before it goes to the market.

Dashboards and tools built by AI

Ask your AI to build a dashboard, a risk monitor or a specialist interface against your key, in the browser, on the command line or on the desktop.

One live stream

A single WebSocket carries quotes, market depth, orders, positions, deals and account state, so your tools react the moment something changes.

What the API covers

The trader side of Mega1’s API, in six groups. Your key works only on your own accounts.

OpenAPI contract

Market data

Current quotes, historical candles, the symbols on your account and their trading terms.

Orders

Market and pending orders: place, modify, cancel one or all, with a preview of margin and commission first.

Positions

Set stop loss and take profit, close in full or in part, reverse, or close two hedged positions against each other.

Account

Live balance, equity and margin, your accounts, and the leverage that applies to each symbol.

Reporting

Order, deal and position history, account statements, and equity and margin snapshots over time.

Streaming

One JSON WebSocket for quotes, depth, orders, positions, deals and account state.

Connect a supported MCP client

Add the XBTFX MCP server to Claude Desktop, Cursor, Windsurf or another MCP client, and your assistant can trade your account in plain language.

The setup guide covers your key, each client and every tool the server offers.

Read the setup guide
claude_desktop_config.json
{
  "mcpServers": {
    "xbtfx": {
      "command": "npx",
      "args": ["@xbtfx/mcp-trading"],
      "env": { "XBTFX_API_KEY": "your_key_here" }
    }
  }
}

Build on the Mega1 API in three steps

  1. Open your account

    Register at XBTFX and open a Mega1 trading account in the portal.

    Create account
  2. Create an API key

    In the Mega1 terminal, create the key your agent will use. Treat it like a password: keep it out of your code and your chats.

  3. Connect your AI

    Give your coding assistant the OpenAPI contract and describe what to build. Review its work before it trades.

    OpenAPI contract

Frequently asked questions

What is AI trading on XBTFX?
Using AI to build and run your own trading tools: an agent that places and manages trades by your rules, a dashboard or a risk monitor. On XBTFX it runs on Mega1’s open API, with an API key you create in the Mega1 terminal.
Do I need programming experience?
Not necessarily. With an MCP client such as Claude Desktop you can trade in plain language. To build your own agent on Mega1’s API, an AI coding assistant can do much of the work: give it the OpenAPI contract, describe what you want, and review what it builds before you rely on it.
Is AI trading free on XBTFX?
Yes. Mega1’s API is free to use with your account: you pay only the usual trading costs, such as spreads and commissions.
Where do I get an API key?
In the Mega1 terminal. Store it like a password, in an environment variable or a secrets manager, never in your code or a chat.
Which AI assistants work with XBTFX?
MCP clients such as Claude Desktop, Cursor and Windsurf connect through the XBTFX MCP server. To build on Mega1’s API, any assistant or framework that can read an OpenAPI document and make HTTPS and WebSocket requests works: Claude, ChatGPT, Cursor, or your own code in Python, TypeScript or any other language.
What can my agent trade?
The instruments on your Mega1 account: forex, crypto, metals, indices, stocks and energies.
Is it safe to let AI trade my account?
Your key works only on your own accounts, and every action is an API call you can log and review. Start with small sizes, use the order preview, and build your limits into the agent’s rules.
Can my agent retry an order safely?
Yes. Trade operations carry an ID you choose; if a request times out, your agent can ask whether that operation went through instead of placing it again.

Build your agent.
Trade it on XBTFX.

Open an XBTFX account, create your API key in the Mega1 terminal and connect your AI.

Live Support

Chat with our support team, including on weekends.

Support site

Guides and answers for your account, funding and platforms.

Visit support

Blog

Company news, market updates and trading insights.

Read the blog

Risk Warning: Trading CFD products carries a high level of risk and may not be suitable for all investors.