cerebro.addbroker()?
-
Hi all,
I have created a custom broker by modifying a couple of functions from
/backtrader/brokers/bbroker.py
(calling the new filemybbroker.py
and putting it in my own code directory, -- not in the same folder as the original bbroker.py).Now my question is: how can I call this one to be used instead?
I tried to add a line
import mybroker
on top of the code, and though the import happens, it's still the original broker that gets used when I do:
import backtrader import mybroker cerebro = backtrader.Cerebro(maxcpus = 1) cerebro.addobserver(backtrader.observers.Broker) cerebro.addstrategy(StrategyBaseTradingplusplus) data = PandasDataStrat1(dataname = dataframe, datetime = -1, open = -1, high = -1, low = -1, close = -1, volume = -1, openinterest = None) cerebro.adddata(data) cerebro.broker.setcash(100000.0) cerebro.broker.setcommission(commission = 0.2, margin = 1000.0, mult = 100.0) cerebro.broker.set_filler(backtrader.broker.filler.FixedBarPerc(perc = 100.0)) cerebro.run()
So my question is: How to use my custom broker?
-
cerebro.setbroker(<instance of your broker class>)
-
Why don't you use what's already documented?
Example: Docs - Live Trading - Oanda v1.0
The
Cerebro
reference says whatsetbroker
does (can also be reached via thebroker
property): Docs - Cerebro -
Thanks, worked like a charm. As usual, thank you for the prompt answer and the references;)