Apama Capital Markets Foundation 10.15 | Capital Markets Foundation | Order Management | Risk firewall | Setting up risk firewall evaluation rules | Sample code for registering rule class and adding rule class instances
 
Sample code for registering rule class and adding rule class instances
The following sample code registers the default OrderPriceLimitRiskFirewallRule class and does not specify a callback. This code then shows how to add rule class instances for the registered rule class.
using com.apama.firewall.RiskFirewallFactory;
using com.apama.firewall.RiskFirewall;
using com.apama.firewall.rules.OrderPriceLimitRiskFirewallRule;
using com.apama.firewall.rules.OrderPriceLimitRiskFirewallRuleConsts;
using com.apama.utils.Params;
using com.apama.oms.NewOrder;
 
monitor RiskFirewallExample10 {
 
context mainContext := context.current();
 
action onload() {
// Create a risk firewall in the main context.
RiskFirewall rfw := (new RiskFirewallFactory).
create( mainContext, "MyFirewall" );
 
// Register one of the default rule classes.
rfw.registerRuleClass( (new OrderPriceLimitRiskFirewallRule).create() );
 
// Add a rule class instance.
OrderPriceLimitRiskFirewallRuleConsts priceLimitConsts :=
new OrderPriceLimitRiskFirewallRuleConsts;
 
// Set configuration parameters to issue a
// warning when an order price is more than 15.0 and to
// reject an order with a price more than 20.0.
Params ruleParams := new Params;
ruleParams.addFloatParam( priceLimitConsts.PRICE_LIMIT_PARAMETER, 20.0 );
ruleParams.addFloatParam( priceLimitConsts.PRICE_WARNING_PARAMETER, 15.0 );
 
// Add the rule class instance to MyFirewall.
integer instanceId := rfw.addRuleInstance(
priceLimitConsts.RULE_CLASS_NAME, ruleParams );
 
// Unlock the risk firewall and send orders in.
...
 
// This order will be approved:
rfw.getOrderSender().sendOrder( NewOrder( "orderId_1","APMA",
10.0, "BUY", "LIMIT", 10,
"TargetService","","",
"TargetMarket","", "TraderA",
new dictionary<string,string> ) );
 
// This order will issue a warning as it breaches the price
// warning level that has been set, but is under the price limit
// level.
rfw.getOrderSender().sendOrder( NewOrder( "orderId_2","APMA",
"TargetService","","",
"TargetMarket","", "TraderA",
new dictionary<string,string> ) );
 
// This order will be rejected as it breaches the price limit
// that has been set.
rfw.getOrderSender().sendOrder( NewOrder( "orderId_3","APMA",
21.0, "BUY", "LIMIT", 10,
"TargetService","","",
"TargetMarket","", "TraderA",
new dictionary<string,string> ) );
}
 
...
}
}