How to Apply a Fixed Commission per Order

How to Apply a Fixed Commission per Order

#region Namespaces
# ---------- DON'T REMOVE OR EDIT THESE LINES -------------------
# These lines are required for integrating Python with our .NET platform.
import clr
clr.AddReference("Tickblaze.Model")
import ScriptCode
from CommissionAPI import *
from AssemblyCommission_3000_ImportedScripts import *
# ---------------------------------------------------------------

## <summary>
## Commission scripts are used for calculating the commission paid to a broker for each executed order, based on the broker's exact commission schedule.
## </summary>
class MyCommission(ScriptCode.CommissionScriptBase): # NEVER CHANGE THE CLASS NAME
    #region Variables
    # Variables Content
    #endregion

    #region OnInitialize
    ## <summary>
    ## This function is used for accepting the script parameters and for initializing the script prior to all other function calls. 
    ## Once the script is assigned to a desktop, its parameter values can be specified by the user and can be selected for optimization. 
    ## </summary>
    ## --------------------------------------------------------------------------------------------------
    ##                                 INSTRUCTIONS - PLEASE READ CAREFULLY
    ## --------------------------------------------------------------------------------------------------
    ## YOU MUST SET A PARAM TAG FOR EACH PARAMETER ACCEPTED BY THIS FUNCTION.
    ## ALL PARAM TAGS SHOULD BE SET IN THE 'OnInitialize' REGION, RIGHT ABOVE THE 'OnInitialize' FUNCTION.
    ## THE ORDER OF THE TAGS MUST MATCH THE ORDER OF THE ACTUAL PARAMETERS.

    ## REQUIRED ATTRIBUTES:
    ## (1) name: The exact parameter name.
    ## (2) type: The type of data to collect from the user: 
    ## Set to "Integer" when the data type is 'int'
    ## Set to "IntegerArray" when the data type is 'int[]'
    ## Set to "DateTime" when the data type is 'long' (The 'long' data type can only be used for date/time representation)
    ## Set to "DateTimeArray" when the data type is 'long[]' (The 'long' data type can only be used for date/time representation)
    ## Set to "Boolean" when the data type is 'bool'
    ## Set to "BooleanArray" when the data type is 'bool[]'
    ## Set to "Double" when the data type is 'double'
    ## Set to "DoubleArray" when the data type is 'double[]'
    ## Set to "String" when the data type is 'string'
    ## Set to "StringArray" when the data type is 'string[]'

    ## OPTIONAL ATTRIBUTES:
    ## (3) default: The default parameter value is only valid when the type is Integer, Boolean, Double, String or an API Type. 
    ## (4) min: The minimum parameter value is only valid when the type is Integer or Double.
    ## (5) max: The maximum parameter value is only valid when the type is Integer or Double.

    ## EXAMPLE: <param name="" type="" default="" min="" max="">Enter the parameter description here.</param>
    ## --------------------------------------------------------------------------------------------------
    ## <param name="commissionPerOrder" type="Double" default="10">The commission amount paid for each executed order.</param>    
    def OnInitialize(self, commissionPerOrder):
        # Create a variable to store the commission amount provided.
        self._commissionPerOrder = commissionPerOrder;
    #endregion

    #region OnCommission
    ## <summary>
    ## This function is called to calculate the commission paid to a broker for a specified order fill.
    ## Note that the commission is denominated in the currency of the specified desktop strategy.
    ## </summary>
    ## <param name="strategyNumber" type="Integer">The strategy number to which the order belongs</param>
    ## <param name="orderIndex" type="Integer">The order index in the orders table to which the order fill belongs</param>
    ## <param name="orderFillIndex" type="Integer">The order fill index (0 being the first fill for the order, 1 being the next fill, etc.)</param>
    ## <param name="fillQuantity" type="Double">The quantity of the new order fill for the specified order</param>
    ## <param name="fillPrice" type="Double">The price of the new order fill for the specified order</param>
    ## <returns type="Double">The commission paid for the specified order fill, in the desktop strategy currency.</returns>
    def OnCommission(self, strategyNumber, orderIndex, orderFillIndex, fillQuantity, fillPrice):
        # Check whether this is the first order fill. 
        if orderFillIndex == 0:
            # Return the fixed commission per order.
            return self._commissionPerOrder
        return 0
    #endregion

    #region OnShutdown
    ## <summary>
    ## This function is called when the script is shutdown.
    ## </summary>
    def OnShutdown(self):
        # OnShutdown Content
        pass
    #endregion