?> QuantXpress – Deliver high performance automated trading and connectivity solutions



Strategy Custom Command and its Execution

Strategy sometimes needs to publish some custom commands to be reflected to the trading terminal for general control of strategy based on its operational requirement. The framework provides a method to publish all available command and optional parameter list for given command. The command is identified by a unique GUID identifier, the display name and optional input variable definitions. All these command is visible as a context menu on a strategy instance row of a trading terminal. The strategy implementation class must implement following method and return the list of supported command. This command is visible to the trading terminal and triggered based on user action or automated call from custom user interface strategy plug-in.

 
protected override ActionCommandInfo[] GetActionCommands()
{
    List actionCommandList = new List();
    actionCommandList.Add(GetSendModifyOrderActionCommand ());
    return actionCommandList;
}
.......
.......
// Generate a new GUID to be used for a every custom command
private static Guid ModifyCommandStaticID = new Guid("{9A1B9203-F8A1-4CCD-B84F-10731D877AB7}");
private ActionCommandInfo GetSendModifyOrderActionCommand()
{
    List actionCommandParameterInfoList = new List();
    actionCommandParameterInfoList.Add(new ActionCommandFieldInfo("OrderSide",, FieldDataType.Int, (int)OrderSide.None));
    actionCommandParameterInfoList.Add(new ActionCommandFieldInfo("OldPrice",, FieldDataType.Double, 0));
    actionCommandParameterInfoList.Add(new ActionCommandFieldInfo("NewPrice", FieldDataType.Double, 0));
    
    return CreateActionCommand(ModifyCommandStaticID, 
                              "Modify Order Price",
                              true,
                              actionCommandParameterInfoList.ToArray());
 }
//When user trigger the command from trading terminal, the control immediately pass to following 
//strategy implementation class method 

protected override void ExecuteActionCommand(Guid commandStaticID, ActionCommandFieldInfo[] inputFields)
                  
 {
    ActionCommandFieldInfo newOrderSideCommand = null;
    ActionCommandFieldInfo newOrderOldPriceCommand = null;
    ActionCommandFieldInfo newOrderNewPriceCommand = null;

    // Retrieve new parameter
    foreach (ActionCommandFieldInfo actionCommandFieldInfo in inputFields)
    {
        if (actionCommandFieldInfo.Name.Equals("OrderSide",  
                            StringComparison.InvariantCultureIgnoreCase))
        {
            newOrderSideCommand = actionCommandFieldInfo;
        }
        else if (actionCommandFieldInfo.Name.Equals("OldPrice",  
                            StringComparison.InvariantCultureIgnoreCase))
        {
            newOrderOldPriceCommand = actionCommandFieldInfo;
        }
        else if (actionCommandFieldInfo.Name.Equals("NewPrice",  
                            StringComparison.InvariantCultureIgnoreCase))
        {
            newOrderNewPriceCommand = actionCommandFieldInfo;
        }
     }

     if (newOrderSideCommand == null ||
                newOrderOldPriceCommand == null ||
                newOrderNewPriceCommand == null)
     {
          // Parameter validation failed
          return;
     }
                  
      OrderSide orderSide = (OrderSide)(int)newOrderSideCommand.Value;
      double orderOldPrice = (double)newOrderOldPriceCommand.Value;
      double orderNewPrice = (double)newOrderNewPriceCommand.Value;

      // Do some custom processing in strategy implementation class
      // based on new parameters
      ........
      ........
    }
}