Building Trading Strategies Risk Rules

Risk Rules

Overview

Risk controls are essential for managing risks associated with real-time trading. The Botmain Execution Server (ES) provides a robust risk control mechanism in the form of a declarative configuration that sits at the gateway, before orders are sent out to exchanges. The Risk Rules allows fund managers to limit market exposure and other key objectives, applied across multiple strategies running simultaneously that may not be aware of each other. Risk rules never place trades and can only reject trades that breach predefined thresholds.

The Risk Rules Monitor is a specifically defined interface to monitor risk rules in real-time and allow fund managers to see the bigger risk picture by displaying the risk exposures as a portion of their limits:

Key Terms

  • Attribute: A property of an order (e.g., "Symbol", "Quantity", "Exchange").
  • Projection: A set of attributes used to group orders into positions. (e.g., "Account/Exchange/Currency").
  • Risk Limit: A user-defined safety limit for a specific attribute.

Quickstart

  1. Create a Risk Rules:
  • Create a risk-rules.json file at your strategy root.
{
    "rejectUnmatchedOrders": true,
    "riskRules": {    
        "Account/Exchange/Currency": [ "MaxPositionLong", "MaxPositionShort" ],
        "Account/Exchange/Symbol": [ "MaxOrderSize", "MaxPositionLong", "MaxPositionShort" ],
        "Account/Exchange": [ "MaxRejectFrequency", "MaxDailyOrderCount" ]
    }
}
  1. Create a Risk Limits:
  • Risk limits can be set through the Risk Rules Monitor graphical interface, where they can be imported/exported as well as input manually.
  • Alternatively, you can create a risk-limits.json file at your strategy root.
[
    { 
        //Set risk limits for all accounts for Binance-ETHUSDT
        "projection": "Account/Exchange/Symbol",
        "projectionKey": "*/Binance/ETHUSDT",
        "limits": {
            "MaxOrderSize": 5,
            "MaxPositionLong": 20,
            "MaxPositionShort": 20,
        }
    },
    { 
        //Increase risk limit of previous rule for a specific account, and set MaxRejectFrequency for this projection
        "projection": "Account/Exchange/Symbol",
        "projectionKey": "Acc123/Binance/ETHUSDT",
        "limits": {
            "MaxOrderSize": 10,
            "MaxRejectFrequency": 3
        }
    }
]
  1. Send Orders: The ES will reject orders exceeding their defined limits.

Settings

rejectUnmatchedOrders - When set to "false", prevents the rejection of the order that order does not match any of defined the risk table cases, see the Case Tables chapter at the beginning of this document for more information. This mode is unsafe and should not be used in production without good reason. Default value of this setting is "true" (if an order is not covered by explicit risk case it will be rejected).

Projections

  • Order of attributes matters: Consider the example Trader/Exchange/Symbol. The ES will look for an exact match on 'Trader' first, then 'Exchange', and finally 'Symbol'.

Predefined Risk Limits

Botmain provides these pre-defined risk rules out-of-the-box:

  • MaxNetPosition: Limits the size of per-Symbol or per-Currency NET positions (Restricted to projections for Symbol, Currency, and RootSymbol)
  • MaxOrderSize: Limits order quantity.
  • MaxOrderValue: Limits order value (quantity * price).
  • MaxOpenOrders: Number of open orders
  • MaxDailyOrderCount: Limits the number of orders that can be placed daily.
  • MaxPositionLong/MaxPositionShort: Limits long and short positions by symbol.
  • MaxDailyTradeVolume: Limits daily gross trading volume.
  • MaxRejectFrequency: Halts trading when the order rejection rate exceeds the limit.