How to use two CommissionInfo inside a strategy?
-
Some exchanges have different maker fee and taker fee, for example, BitMEX BTC taker fee is 0.075% and maker fee is -0.025%, I can add
two CommissionInfo
with the following code:cerebro.broker.addcommissioninfo(CommissionInfoFractional(commission=0.0075), name='taker') cerebro.broker.addcommissioninfo(CommissionInfoFractional(commission=-0.0025), name='maker')
And in my strategy class I can retrieve them back:
taker_comm = self.broker.comminfo['taker'] maker_comm = self.broker.comminfo['maker'] print(taker_comm.params.commission) print(maker_comm.params.commission)
How can I use the two ComissionInfo instances in
self.buy()
andself.sell()
? Thanks! -
I believe using name in this way means the name of the dataline. You should look at creating a custom commission scheme.
-
@run-out You're right, the strategy retrieves the CommissionInfo instance at this line https://github.com/mementum/backtrader/blob/master/backtrader/strategy.py#L1315 :
comminfo = self.broker.getcommissioninfo(data)
So it uses the data name.
Since data has only one name, so it's not possible to apply multiple commission fees?
-
@soulmachine said in How to use two CommissionInfo inside a strategy?:
Since data has only one name, so it's not possible to apply multiple commission fees?
You're probably right. AFAIK a single commission could be specified per data name or default. As @run-out correctly mentioned - you may develop your custom commission scheme.