Compatible with XBTFX MetaTrader 5® accounts

XBTFX Trading API

Programmatically trade, manage positions, monitor account state, and stream real-time market data on compatible XBTFX MetaTrader 5® accounts through REST and WebSocket. Build automated strategies, connect AI agents, and integrate your account into custom workflows. Start with docs, working examples, AI skills, or the XBTFX MCP server. Designed for developers and users with experience in programming or AI coding assistants.

  • Pro accounts
  • Full programmatic access
  • Hedging & netting modes
  • AI-agent ready (MCP)
terminal
# Send a trade to your XBTFX account
curl -X POST https://interface.xbtfx.com/v1/trade \
  -H "Authorization: Bearer xbtfx_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "symbol": "EURUSD",
    "side":   "buy",
    "volume": 0.10,
    "sl":     1.08200,
    "tp":     1.09000
  }'

# Response
{
  "status":  "filled",
  "retcode": 10009,
  "deal":    184729,
  "price":   1.08650,
  "volume":  0.10
}
Protocol
REST
Streaming
WebSocket
Weight per minute
600
Response format
JSON

Automate your trading with the XBTFX API

The XBTFX Trading API lets you send instructions to your compatible XBTFX MetaTrader 5® account. Open positions, modify stops, query balances, and stream live quotes through standard REST and WebSocket calls.

Automated strategies

Build trading bots and algorithmic strategies that send trades to your account automatically. Run signal-driven execution, portfolio rebalancing, or custom risk management logic.

AI agent integration

Connect AI assistants to your account via the XBTFX Skills Hub or MCP server. Issue trading commands in natural language through Claude Code, Cursor, Windsurf, or other compatible clients.

Custom integrations

Build dashboards, connect to external data sources, pipe trade signals from other platforms, or integrate account data into your own reporting and analytics systems.

API endpoints for trading, positions and market data

Open and close positions, set stop loss and take profit, query account balances, retrieve trade history, and stream live forex and crypto quotes via WebSocket.

API docs

POSTSend trades

Send market orders to your account with stop loss and take profit. Supports both hedging and netting margin modes.

/v1/trade

POSTClose & modify

Close positions fully or partially. Update SL/TP on open positions. Close all, close by symbol, or net opposing positions.

/v1/close · /v1/modify · /v1/close-all

GETPositions & orders

Retrieve all open positions and pending orders in real time. Filter by symbol. Responses served from cache with live push updates.

/v1/positions · /v1/orders

GETAccount & balance

Real-time balance, equity, margin, free margin, floating PnL, and leverage. One call for a complete snapshot.

/v1/account

GETSymbols & specs

Full symbol list with live bid/ask, spread, contract size, volume min/max/step, digits, and margin requirements.

/v1/symbols · /v1/symbols/:symbol

WSWebSocket streaming

Real-time streaming quotes with 5-level market depth. Subscribe to any symbols available on your account.

wss://ws.xbtfx.com/v1/ws

Send your first API trade in minutes

A few lines of code in your language of choice. Standard HTTP — any language that can make a POST request works.

# Send a buy order to your XBTFX account
curl -X POST https://interface.xbtfx.com/v1/trade \
  -H "Authorization: Bearer $XBTFX_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"symbol":"EURUSD","side":"buy","volume":0.10,"sl":1.082,"tp":1.09}'

# Retrieve open positions
curl https://interface.xbtfx.com/v1/positions \
  -H "Authorization: Bearer $XBTFX_API_KEY"

interface.xbtfx.comShell

AI-ready

Execute trades with natural language

The XBTFX Trading API is built to be consumed by AI agents and large language models — clean JSON, human-readable errors, predictable endpoints. Connect via the XBTFX Skills Hub or the MCP server and your AI client can send trades through conversational commands.

  • Conversational orders — buy, sell, close, condition on data.
  • Tool-grounded reasoning — every action returns a structured response.
  • Portable across clients — Claude, Cursor, Windsurf, Codex.

Less technical? See our AI Agent Trading overview.

Example conversation

XBTFX Trading Agentonline · executing trades

Today · 13:25 GMT

If today's NFP prints above 200k, close all my open EURUSD and GBPUSD trades.

13:25 ✓✓

Got it. Watching the BLS release at 13:30 GMT. I'll close 4 positions if NFP > 200k.

13:25

tool · xbtfx_get_positions4 open · EURUSD ×2, GBPUSD ×2 · floating +$184.20

13:26

13:30 · NFP released: 247k (forecast 195k)

tool · xbtfx_close_all (filter: EURUSD, GBPUSD)Closed 4 positions in 38 ms · realized +$212.80

13:30

Illustrative example. Conditional flows depend on the configured agent and market-data feeds.

Use cases

What AI agents do with the API

Four common patterns we see across automated and AI-driven workflows on XBTFX accounts.

Event-driven trading

AI monitors news and economic data in real time, sending trades to your account when market-moving events are detected.

Smart risk management

AI tracks your margin, floating PnL, and exposure, adjusting stops, reducing sizes, or closing trades to protect capital.

Portfolio rebalancing

Define target allocations and let AI maintain them, sending adjustment trades when drift exceeds your threshold.

Autonomous analysis

Ask your AI to analyze trade history, calculate win rates by symbol, and identify your best-performing setups.

Built for your existing XBTFX account

Use your current Pro MetaTrader 5 account, your existing base currency, and your existing margin mode. The API plugs into the same account you already trade on.

Technical specs

Production-grade endpoints

Hedging & netting modes
Both MT5 margin modes are supported. The mode is bound to your API key.
Idempotency keys
Send the same key within 120 seconds and we return the cached response. Safe retries, no duplicate fills.
Weight-based rate limits
600 weight / min per key. Reads and trades cost 1, bulk operations 10. Headers expose your remaining budget on every response.
Streaming limits
Up to 1,000 symbol subscriptions per WebSocket connection and up to 10 connections per API key. Quotes stream as prices change.

Account compatibility

Works with your Pro account

Pro accounts
Raw spreads plus a commission. The API treats every Pro account the same way: same endpoints, same JSON, same auth flow.
PAMM, MAM & Copy Master accounts
Manager accounts can be driven programmatically through the API for allocations, rebalancing and execution. Reach out to onboarding for credential provisioning.
Multi-currency settlement
Every base currency XBTFX MT5 supports for Pro accounts: USD, EUR, USDT, BTC, ETH, XRP, SOL, LTC, ZEC, XAU. Balances, equity, margin and PnL come back in the account's own currency, so there is no conversion logic on your side.
Hedging or netting
Whichever margin mode you set on the MT5 account is what the API uses. No reconfiguration needed.

Developer resources

Example code, AI skill files, and full API documentation — everything you need to get building.

API documentation

Full endpoint reference with request/response examples, authentication guide, and WebSocket integration.

API examples

Sample code in Python, JavaScript, curl, and more. Copy and run.

AI Skills Hub

Skill files for trading, account, market data, and WebSocket workflows for compatible agent frameworks.

MCP server

For Claude Code, Claude Desktop, OpenAI Codex, Cursor, Windsurf, and other MCP-compatible clients.

Get started in three steps

Same shell, two starting points — pick the one that matches your account state.

  1. Generate an API key

    Log in to portal.xbtfx.com with your XBTFX account credentials, select your trading account, and generate a key.

    Open console
  2. Install a skill or the MCP server

    Install a skill from the Skills Hub, or connect the MCP server to Claude Code, Cursor, Windsurf, or other compatible clients. Keys stay local.

    MCP docs
  3. Start trading

    Verify with GET /v1/auth/status, then issue natural-language commands or call the REST/WebSocket endpoints directly.

    Read docs

Frequently asked questions

What is the XBTFX Trading API?
The XBTFX Trading API provides REST and WebSocket access for programmatic trading, account monitoring, market-data retrieval, and streaming on compatible XBTFX MetaTrader 5® accounts. It's built by XBTFX — you interact with clean HTTP endpoints and JSON responses to send trades and retrieve account data.
Can I use the API with a Standard account?
No. The XBTFX Trading API works with Pro accounts on MetaTrader 5 only. With a Standard account, use Mega1's open API: it works with Standard accounts on Mega1, with keys made in the Mega1 terminal.
What programming languages can I use?
Any language that can make HTTP requests. Python, JavaScript, Go, Rust, C#, Java, Ruby, PHP — if it can send a POST request with a JSON body, it can send trades to your XBTFX account via the API.
Can I build automated trading strategies?
Yes. The XBTFX Trading API is designed for algorithmic and automated trading. You can build signal-driven bots, portfolio rebalancers, risk management systems, or any custom logic that sends trades to your account.
Is there a WebSocket feed for real-time prices?
Yes. The XBTFX Trading API provides a WebSocket endpoint for streaming real-time quotes from symbols available on your account. Quotes include 5-level market depth when available. Up to 1,000 symbol subscriptions per connection with up to 10 concurrent connections.
What's the difference between hedging and netting mode?
These are margin modes that determine how positions behave. Hedging allows multiple independent positions per symbol, including opposing buy and sell. Netting aggregates everything into one position per symbol. Your API key inherits the mode from your account.
What are the rate limits?
600 weight per minute per API key. Most requests cost 1 weight — up to 600 calls per minute. Bulk operations like close-all cost 10 weight. Every response includes headers showing your remaining budget.
Can I trade crypto CFDs through the API?
Yes. Every symbol available on your XBTFX account is accessible through the API — including cryptocurrency CFDs. You can also use the API with accounts denominated in BTC, ETH, USDT, or XRP.
Is the API free to use?
Yes. The XBTFX Trading API is included with every Pro account at no additional cost. No API fees, subscription charges, or per-call costs beyond your normal trading commissions and spreads.
How do I get an API key?
First, open an XBTFX Pro account at portal.xbtfx.com if you don't have one. Then log in to the API Console at portal.xbtfx.com with your XBTFX credentials, select your Pro account, and generate a key. Verify it works by sending GET /v1/auth/status before placing trades.
What should I do before placing trades?
Verify your API key and account status first by sending GET /v1/auth/status. This confirms your key is valid, shows your permissions and margin mode, and ensures your account is ready before you send any trade requests.
Do I need programming experience?
Using the REST API directly requires basic programming knowledge. However, with the AI integration paths, you don't need to write code yourself — connect the XBTFX MCP server to Claude Code or Cursor, or install a skill file from the Skills Hub, and issue trading commands through natural language. Familiarity with AI coding assistants is recommended.
Can I use AI to trade my account?
Yes. Use the XBTFX Skills Hub for agent frameworks that support skill files, or connect the XBTFX MCP server to MCP-compatible clients like Claude Code, Claude Desktop, OpenAI Codex, Cursor, or Windsurf. Both paths let you issue trading commands in natural language through the XBTFX Trading API.
Is it safe to give an AI agent access to my account?
API keys are typically stored locally by the agent on your machine and are not uploaded to third-party servers. The agent sends API calls directly to XBTFX's servers using your key. You can revoke the key instantly from the Console at any time.

Start building today.
The API is free to use.

Open your XBTFX account, generate an API key in the portal and send your first trade.

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.