Skip to content

Trading Skill

The xbtfx-trading skill provides AI agents with the ability to execute trades and manage positions on the XBTFX platform.

  • Skill name: xbtfx-trading
  • Required env var: XBTFX_API_KEY
  • Base URL: https://interface.xbtfx.com
  • Execute market trades (buy/sell)
  • Close open positions
  • Modify stop-loss and take-profit levels
  • Reverse an existing position
  • Close a position by its opposite (hedging accounts)
  • Close all positions or all positions for a symbol
  • Market commentary or analysis — this skill only executes actions
  • Read-only account checks (balance, equity, margin) — use the Account Skill
  • Symbol specifications, contract sizes, volume constraints — use the Market Data Skill
EndpointMethodWeightDescription
/v1/tradePOST1Open a market position
/v1/closePOST1Close a specific position
/v1/modifyPOST1Modify SL/TP on a position
/v1/close-byPOST1Close position by opposite (hedging)
/v1/reversePOST2Reverse a position atomically
/v1/close-allPOST10Close all open positions
/v1/close-symbolPOST10Close all positions for a symbol

Open a new market position.

Parameters:

ParameterTypeRequiredDescription
symbolstringYesTrading symbol (e.g., BTCUSD)
sidestringYesbuy or sell
volumenumberYesTrade volume in lots
slnumberNoStop-loss price
tpnumberNoTake-profit price
pricenumberNoAdvisory price. Bridge uses MT5 server price for market orders.
commentstringNoTrade comment (max 27 characters)

Supports idempotency via the Idempotency-Key header.

Example:

POST /v1/trade
{
"symbol": "BTCUSD",
"side": "buy",
"volume": 0.01,
"sl": 60000,
"tp": 70000,
"comment": "ai-trade"
}

Response:

{
"status": "placed",
"retcode": 10008,
"volume": 0.10,
"comment": ""
}

Close a specific open position by ticket number.

Parameters:

ParameterTypeRequiredDescription
ticketnumberYesPosition ticket to close
volumenumberNoPartial close volume (omit for full close)
commentstringNoClose comment (max 27 characters)
pricenumberNoAdvisory price. Bridge uses MT5 server price.

Supports idempotency via the Idempotency-Key header.

Example:

POST /v1/close
{
"ticket": 12345678
}

Response:

{
"status": "placed",
"retcode": 10008
}

Modify stop-loss and/or take-profit on an open position or pending order.

Parameters:

ParameterTypeRequiredDescription
ticketnumberYesPosition or order ticket
slnumberNoNew stop-loss price (0 to remove)
tpnumberNoNew take-profit price (0 to remove)

Supports idempotency via the Idempotency-Key header.

Example:

POST /v1/modify
{
"ticket": 12345678,
"sl": 61000,
"tp": 72000
}

Close a position using an opposite position on the same symbol. Only available on hedging accounts.

Parameters:

ParameterTypeRequiredDescription
positionnumberYesPosition ticket to close
position_bynumberYesOpposite position ticket
commentstringNoClose comment (max 27 characters)

Supports idempotency via the Idempotency-Key header.

Example:

POST /v1/close-by
{
"position": 12345678,
"position_by": 12345679
}

Reverse a position atomically. This closes the current position and opens a new one in the opposite direction. Consumes 2 weight units.

Parameters:

ParameterTypeRequiredDescription
ticketnumberYesPosition ticket to reverse
commentstringNoTrade comment (max 27 characters)

Supports idempotency via the Idempotency-Key header.

Example:

POST /v1/reverse
{
"ticket": 12345678
}

Close all open positions on the account. Consumes 10 weight units.

Parameters:

ParameterTypeRequiredDescription
commentstringNoClose comment (max 27 characters)

Supports idempotency via the Idempotency-Key header.

Example:

POST /v1/close-all
{}

Response:

{
"closed": 3,
"failed": 0,
"total_profit": 125.50,
"details": []
}

Close all open positions for a specific symbol. Consumes 10 weight units.

Parameters:

ParameterTypeRequiredDescription
symbolstringYesSymbol to close all positions for
commentstringNoClose comment (max 27 characters)

Supports idempotency via the Idempotency-Key header.

Example:

POST /v1/close-symbol
{
"symbol": "BTCUSD"
}

Response:

{
"closed": 2,
"failed": 0,
"total_profit": 75.00,
"details": []
}
ValueDescription
buyLong position
sellShort position
ValueDescription
placedTrade request accepted by the server (may fill immediately)
filledTrade executed and fully filled
okModification or close succeeded
rejectedOperation was rejected by the server

All POST endpoints support idempotency via the Idempotency-Key HTTP header. If a request with the same key has already been processed, the server returns the original response instead of executing the operation again.

Use idempotency keys for all trade operations to prevent duplicate executions from retries or network issues. Keys should be unique per intended operation (e.g., UUID v4).

Example header:

Idempotency-Key: trade-abc-123

See Idempotency for full details.

CodeMeaning
400Invalid parameters
400 market_closedMarket is closed. Response includes next_open.
401Authentication failed
403Insufficient permissions
404Position or order not found
207Partial success (bulk operations)
429Rate limit exceeded
500Internal server error

See Error Codes for the complete reference.

Agents using this skill must follow these behavioral rules:

  1. Always confirm before executing trades. Never open, close, or modify positions without explicit user confirmation.
  2. Check symbol specifications first. Use the Market Data Skill to verify volume constraints, contract size, and trading hours before placing trades.
  3. Check the account margin mode. Determine whether the account uses hedging or netting before using close-by or reverse operations.
  4. Use idempotency keys on every trade request. Send a unique Idempotency-Key header (UUID v4) for each intended operation to prevent duplicate executions.
  5. Handle HTTP 207 responses. Bulk operations (close-all, close-symbol) may partially succeed. Inspect each result in the response array.
  6. Never mask or hide ticket numbers. Always display position tickets to the user so they can verify operations.
  7. Always mask API keys in output. Never display the full API key to the user.
  8. Respect rate limits. Trading endpoints consume weight as listed in the quick reference table. Monitor usage to avoid 429 responses.
  9. Volume is always in lots. Do not confuse lots with units or contract size. Check the symbol specification for lot constraints.
  10. Comments are optional and limited to 27 characters. Use them for tagging trades, not for long descriptions.
  11. Maximum 200 open positions per account. Check current position count before opening new trades.