I needed to emulate IB 's tiered structure of fees in python, where most examples I found were for C#. Anyways, this works and may help someone else:
for security in self.stocks:
self.Securities[security].SetSlippageModel(CustomSlippageModel())
self.Securities[security].SetDataNormalizationMode(DataNormalizationMode.Raw)
self.Securities[security].SetFeeModel(CustomFeeModel(self)) #ConstantFeeModel(10.00))
class CustomFeeModel(FeeModel):
def __init__(self, algorithm):
self.algorithm = algorithm
def GetOrderFee(self, parameters):
# custom fee math
# less than 300000 shares
#USD 0.0035 USD 0.35 1.0% of trade value
minfee = max(0.35, parameters.Security.Price * parameters.Order.AbsoluteQuantity * 0.0035 )
maxfee = parameters.Order.AbsoluteQuantity * 0.01
fee = min(minfee,maxfee)
self.algorithm.Log("CustomFeeModel: " + str(fee))
return OrderFee(CashAmount(fee, "USD"))
# Custom slippage implementation
class CustomSlippageModel:
def GetSlippageApproximation(self, asset, order):
try:
return decimal.Decimal(0.0002)
except:
self.Log('An unknown error occurred trying CustomSlippageModel.' + str(sys.exc_info()[0]) )
return 0.0002
Hope this helps someone else.