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

XBTFX Trading API

Compatible with XBTFX MetaTrader 5® accounts

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.

Edge & ECN 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 { "ticket": 184729, "status": "filled", "price": 1.08650, "retcode": 10009 }
Protocol icon
REST
Protocol
Streaming icon
WebSocket
Streaming
Weight / Min icon
600
Weight / Min
Response Format icon
JSON
Response Format

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 & 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.

POST Send Trades
Send market orders to your account with stop loss and take profit. Supports both hedging and netting margin modes.
/v1/trade
POST Close & 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
GET Positions & 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
GET Account & Balance
Real-time balance, equity, margin, free margin, floating PnL, and leverage. One call for a complete snapshot.
/v1/account
GET Symbols & Specs
Full symbol list with live bid/ask, spread, contract size, volume min/max/step, digits, and margin requirements.
/v1/symbols · /v1/symbols/:symbol
WS WebSocket 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.

XBTFX Trading API · examples
# 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"
import requests API_KEY = "xbtfx_live_your_key_here" BASE = "https://interface.xbtfx.com" HEADERS = {"Authorization": f"Bearer {API_KEY}"} # Send a trade to your account r = requests.post(f"{BASE}/v1/trade", json={ "symbol": "EURUSD", "side": "buy", "volume": 0.10 }, headers=HEADERS) print(r.json()) # {"status": "filled", "retcode": 10009}
const ws = new WebSocket("wss://ws.xbtfx.com/v1/ws"); ws.onopen = () => { ws.send(JSON.stringify({ type: "auth", api_key: "xbtfx_live_..." })); ws.send(JSON.stringify({ type: "subscribe", symbols: ["EURUSD", "BTCUSD"] })); }; ws.onmessage = (e) => { const q = JSON.parse(e.data); console.log(q.symbol, q.bid, q.ask); };
main 0 errors Shell UTF-8 LF interface.xbtfx.com
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 Agent
online · 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 Edge or ECN 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.

FIX 4.4 institutional

FIX 4.4 access via the xPro infrastructure for prime brokers, hedge funds and HFT firms. Contact sales.
Account compatibility

Edge or ECN — same account

Edge & ECN accounts

Tighter spreads with a per-lot commission. The API treats every Edge / ECN account identically — 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 Edge & ECN: USD, EUR, USDT, BTC, ETH, XRP, SOL, LTC, ZEC, XAU. Balances, equity, margin and PnL come back in the account's native currency — 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 console.xbtfx.com with your XBTFX account credentials, select your trading account, and generate a key.
Open Console
2
Install Skill or MCP
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.

  • 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 trading 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, create an XBTFX trading account at my.xbtfx.com if you don't have one. Then log in to the API Console at console.xbtfx.com with your XBTFX credentials, select your trading account, and generate a key. Verify it works by sending GET /v1/auth/status before placing trades.

  • Can I use the API with a demo account?

    Yes. API keys work with both live and demo accounts. This lets you test your integration and validate your code before going live — on the same API with the same endpoints.

  • 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. We recommend starting with a demo account to test your setup before going live.