APIs, Bots & Automation

How to Add Maximum-Notional and Allowed-Symbol Controls to a Trading Bot

Put one risk-checking layer in front of every order. Allow only approved symbols, cap each order and each day’s USD notional, keep leverage off unless explicitly allowed, and add a kill switch.

45 minutesAdvancedBot developers and risk engineers

What you will accomplish

  • Route every order through the same risk checks
  • Check the current market list
  • Enforce per-order, daily, and leverage limits
  • Add and test a kill switch

Before you begin

  • A defined order format
  • One central limits configuration
  • Current account and position data
  • One server-side execution service that holds the API secret
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.

EnforcementOne risk-checking service
Limit stateStored and restored after restart
Kill switchBlocks new orders but keeps account and position checks available
Step-by-step

Send every order through one risk-checking service

Do not let each strategy call the trading API directly. Send every order through one service that validates the account, symbol, side, amount, price, payment currency, leverage, and current limits before signing it.

Expected result

All live orders pass through the same risk checks.

Check the symbol before sending the order

Compare the bot’s allowed-symbol list with current exchange information. Reject a symbol that is halted, unknown, or entered with invalid precision.

Expected result

A stale symbol configuration cannot enable trading by itself.

Apply per-order and daily USD limits

Calculate the USD order value with decimal arithmetic. Include open orders and the day’s executed orders, and restore the total after a restart instead of resetting it to zero.

python
if order.notional > policy.maxOrderNotional:
    raise PolicyReject("ORDER_NOTIONAL_EXCEEDED")
if ledger.dailyNotional + order.notional > policy.maxDailyNotional:
    raise PolicyReject("DAILY_NOTIONAL_EXCEEDED")
Expected result

Orders above either cap are rejected before signing.

Default leverage off and limit order types

Default to disableLeverage=1 unless leverage is separately approved and supported by the live account and order configuration. Allow only the order types and verified order modes the strategy actually needs.

Expected result

Invalid strategy output cannot turn into an unsupported or leveraged order.

Add a kill switch and recovery plan

Add a control that immediately blocks all new orders while keeping market data, account reads, position monitoring, and order-status checks available. Test it before enabling live trading.

Expected result

The kill switch blocks new orders while read-only monitoring remains available.

Troubleshooting

Common problems and fixes

A strategy bypasses the risk checks

Remove its API access so only the risk-checking service can call private trading endpoints.

Daily volume resets after a restart

Persist the risk ledger and reload exchange state on startup.

The kill switch also blocks order and position checks

Keep read-only market, account, order, and position access available. The kill switch should block new orders, not the checks needed to understand current exposure.

Primary sources

Ready for the next step?

Review Quote.Trade trading fields

Review Quote.Trade trading fields