AI Agents & MCP

How to Restrict an AI Agent by Symbol, Notional, and Leverage

Keep a server-side allowlist for symbols, cap USD notional, keep leverage within limits, and validate the payment currency separately. The model must not be able to change these rules.

40 minutesAdvancedAgent developers and risk engineers

What you will accomplish

  • Define server-side trading limits
  • Calculate USD order value with decimal arithmetic
  • Disable leverage by default
  • Reject orders when account state or quote freshness is uncertain

Before you begin

  • A server-side limits configuration outside the model
  • Production exchange information and price data
  • A secure execution service
  • Monitoring and revocation access
USD price, collateral currency, and network

Prices and order values are shown in USD. The collateral currency, such as USDC or USDT, and its blockchain network are separate settings. Check the live account and market settings for allowed currencies, minimum size, and leverage.

Notional unitUSD quote terms
Payment currencySeparate allowlist
Policy versionUse a simple version label and change it when the limits change
Control layersApplication, MCP server, account, and Quote.Trade
Step-by-step

Start with nothing allowed

Start with every account, symbol, side, order type, payment currency, and leverage setting blocked. Then allow only what the agent actually needs, with a maximum USD value per order and per day.

json
{
  "policyVersion": "qt-agent-policy-v1",
  "allowedSymbols": ["BTC", "ETH"],
  "maxNotionalUsd": "1000.00",
  "allowedPaymentCurrencies": ["USDC"],
  "allowLeverage": false
}

Validate live symbol state and quantity precision

Use exchange information or instruments only for fields they actually return, such as status and quantityScale. Do not infer minimum size or leverage availability from exchangeInfo.

Calculate USD order value with decimal arithmetic

Multiply the amount by the USD price using Decimal. Reject a missing, negative, invalid, or over-limit value.

python
from decimal import Decimal, InvalidOperation

def notional_usd(price: str, quantity: str) -> Decimal:
    try:
        p = Decimal(price)
        q = Decimal(quantity)
        value = p * q
    except InvalidOperation as exc:
        raise ValueError('invalid decimal input') from exc
    if not p.is_finite() or not q.is_finite() or not value.is_finite():
        raise ValueError('price and quantity must be finite')
    if value <= 0:
        raise ValueError('notional must be positive')
    return value

Validate payment currency separately

Confirm that paymentCurrency is allowed for the account and current funding configuration. quoteAsset=USD is a price unit, not permission to send any stablecoin.

Apply MCP server limits

The MCP server should enforce the allowed symbols, maximum USD order value, leverage, credentials, and approval requirements. Client-side limits may be stricter but must never be looser.

Apply account and venue limits

Before a live order, confirm that trading is enabled and that the current balance, margin, risk status, and Quote.Trade account limits allow it. After submission, use Quote.Trade order and account data to confirm the result.

Troubleshooting

Common problems and fixes

A permitted symbol was delisted or halted

Live market status overrides the static allowlist. Reject until production metadata shows the market active.

Different services show different daily order totals

Use one shared order-total ledger and ignore duplicate events. Do not resume trading until every service shows the same total.

The model asks to change the limits

Require an authenticated operator to change the server-side limits. Do not allow a conversational tool call to change them.

Primary sources

Ready for the next step?

Review production market metadata

Review production market metadata