XBTFX Trading API
Compatible with XBTFX MetaTrader 5® accountsProgrammatically 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.
Automate Your Trading with the XBTFX API
The XBTFX Trading API lets you send instructions to your compatible XBTFX MetaTrader 5® account — opening positions, modifying stops, querying balances, and streaming live quotes — all through standard REST and WebSocket calls.
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.
Code Examples — 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.
AI Trading — Execute Trades with Natural Language
The XBTFX Trading API is designed to be consumed by AI agents and large language models. Clean JSON responses, human-readable errors, and predictable endpoints mean compatible AI assistants can send trades to your XBTFX account through conversational commands.
Two paths to get started: install a skill file from the XBTFX Skills Hub into your agent framework, or connect the XBTFX MCP server to Claude Code, Claude Desktop, OpenAI Codex, Cursor, Windsurf, or any MCP-compatible client.
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.
docs.xbtfx.comAPI Examples
Sample code in Python, JavaScript, curl, and more. Ready to copy and run.
Public RepositoryAI Skills Hub
Skill files for trading, account, market data, and WebSocket workflows for compatible agent frameworks.
AI SkillsMCP Server
For Claude Code, Claude Desktop, OpenAI Codex, Cursor, Windsurf, and other MCP-compatible clients.
MCP ToolsTechnical Specifications
Hedging & Netting
Supports both margin modes. Hedging allows multiple positions per symbol with close-by. Netting aggregates into one position. Mode is bound to your API key.
Idempotency
All trade endpoints support idempotency keys via header. Send the same key within 120 seconds to get the cached response — preventing duplicate orders on retries.
Weight-Based Limits
600 weight per minute shared budget. Reads and trades cost 1 weight each. Bulk operations cost 10. Rate limit headers on every response.
One API. USD or Crypto-Denominated Accounts.
How to Get Your API Key & Start Trading
Three steps to send your first trade via the XBTFX Trading API.
Frequently
Asked Questions
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.
Risk Warning
Trading leveraged CFD products carries a high level of risk and may not be suitable for all investors. Automated trading via API does not eliminate risk — algorithmic strategies can amplify losses as well as gains. You may lose some or all of your invested capital. The XBTFX Trading API is intended for users with programming knowledge or experience using AI coding assistants. Ensure you fully understand the risks before trading. XBTFX does not provide trading advice or guarantee the performance of any automated strategy.
MetaTrader 5® is a registered trademark of MetaQuotes Ltd.



