القائمة

    تحذير المخاطر: يحمل تداول منتجات العقود مقابل الفروقات (CFD) مستوى عالياً من المخاطر وقد لا يكون مناسباً لجميع المستثمرين.

    XBTFX Trading API · v1

    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.

    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 }
    REST
    Protocol
    WebSocket
    Streaming
    600
    Weight / Min
    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 — opening positions, modifying stops, querying balances, and streaming live quotes — all 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

    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.

    # 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); };
    AI-Ready

    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.

    Example commands →
    💬
    "Buy 0.10 lots of EURUSD with a stop loss 30 pips below entry"Trade Execution
    💬
    "Close all my losing positions on EUR pairs and show me the total realized loss"Position Management
    💬
    "What's my current margin usage? Am I at risk of a margin call?"Risk Monitoring
    💬
    "Move my stop loss to breakeven on all positions at least 20 pips in profit"Smart Management
    💬
    "Show me my P&L for the last week broken down by symbol"Analytics
    1
    Install the Skill
    Install a skill from the Skills Hub, or connect the MCP server to Claude Code, Cursor, Windsurf, or other compatible clients.
    2
    Add Your API Key
    Your AI agent will guide you to configure your XBTFX API key. Keys are stored locally — never uploaded to third-party servers.
    3
    Start Trading
    Issue natural language commands. Your AI sends trades, retrieves data, and manages positions — all through the XBTFX Trading API.
    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.

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

    Account base currency

    One API. USD or Crypto-Denominated Accounts.

    Every account base currency we support is a first-class citizen in the API. Whether your account settles in USD, USDT, BTC, ETH, or XRP, the same endpoints return balances, equity, margin, and PnL in the account's native currency — no conversion logic to wire up on your side.
    You're still trading the same instruments — forex, indices, metals, energies, crypto CFDs, and more. The base currency only affects how your account denominates value, not what you can buy or sell. Run a BTC-funded strategy and PnL accrues in BTC; fund in USDT for stable accounting; or stick with USD.
    USD
    USDT (Tether)
    BTC (Bitcoin)
    ETH (Ethereum)
    XRP (Ripple)

    How to Get Your API Key & Start Trading

    Three steps to send your first trade via the XBTFX Trading API.

    1
    Create Your Account
    Register at my.xbtfx.com and open a trading account. Choose your preferred base currency — USD, USDT, BTC, ETH, or XRP.
    Create Account
    2
    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
    3
    Verify Access
    Send GET /v1/auth/status to confirm your key works, validate permissions, and check your margin mode before sending trades.
    Read Docs

    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.