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
commentstringNoTrade comment (max 27 characters)
idempotency_keystringNoUnique key to prevent duplicates

Example:

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

Response:

{
"status": "filled",
"ticket": 12345678,
"symbol": "BTCUSD",
"side": "buy",
"volume": 0.01,
"price": 65000.00
}

Close a specific open position by ticket number.

Parameters:

ParameterTypeRequiredDescription
ticketnumberYesPosition ticket to close
volumenumberNoPartial close volume (omit for full close)
idempotency_keystringNoUnique key to prevent duplicates

Example:

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

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)
idempotency_keystringNoUnique key to prevent duplicates

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
ticketnumberYesPosition ticket to close
ticket_bynumberYesOpposite position ticket
idempotency_keystringNoUnique key to prevent duplicates

Example:

POST /v1/close-by
{
"ticket": 12345678,
"ticket_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
volumenumberNoVolume for the new position (defaults to original)
slnumberNoStop-loss for the new position
tpnumberNoTake-profit for the new position
idempotency_keystringNoUnique key to prevent duplicates

Example:

POST /v1/reverse
{
"ticket": 12345678,
"sl": 64000,
"tp": 58000
}

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

Parameters:

ParameterTypeRequiredDescription
idempotency_keystringNoUnique key to prevent duplicates

Example:

POST /v1/close-all
{}

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

Parameters:

ParameterTypeRequiredDescription
symbolstringYesSymbol to close all positions for
idempotency_keystringNoUnique key to prevent duplicates

Example:

POST /v1/close-symbol
{
"symbol": "BTCUSD"
}
ValueDescription
buyLong position
sellShort position
ValueDescription
filledTrade executed successfully
placedPending order placed
okModification or close succeeded
rejectedOperation was rejected by the server

All POST endpoints accept an idempotency_key parameter. 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).

See Idempotency for full details.

CodeMeaning
400Invalid parameters
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. Generate a unique key (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.