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
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.
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.
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.
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.
if order.notional > policy.maxOrderNotional:
raise PolicyReject("ORDER_NOTIONAL_EXCEEDED")
if ledger.dailyNotional + order.notional > policy.maxDailyNotional:
raise PolicyReject("DAILY_NOTIONAL_EXCEEDED")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.
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.
The kill switch blocks new orders while read-only monitoring remains available.
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.