def setup(self) -> None: commoncfg = self._instance.config.get('common', {}) storescfg = self._instance.config.get('stores', {}) all_classes = get_classes(self._instance.PATH_STORE) for i, v in storescfg.items(): classname = v.get('classname') params = v.get('params', {}) if not classname: return if classname not in all_classes: raise Exception(f'Store {classname} not found') self.log( 'Creating Store {} ({})\n{}'.format( classname, i, tabulate(params.items(), tablefmt='plain')), logging.DEBUG) store = all_classes[classname](**params) self._instance.stores[i] = store self.log(f'Store {i} created', logging.INFO) # set broker broker = commoncfg.get('broker', None) if broker is not None: store = self._instance.stores[broker] self._instance.cerebro.setbroker(store.getbroker()) self.log(f'Broker from store {broker} set', logging.INFO) # set starting cash if commoncfg.get('cash', None) is not None: if hasattr(self._instance.cerebro.broker, 'setcash'): cash = commoncfg.get('cash') self._instance.cerebro.broker.setcash(cash) self.log(f'Starting cash was set to {cash}', logging.INFO) if len(storescfg): self.log('Stores created\n', logging.INFO) else: self.log('Broker configured\n', logging.INFO)
def setup(self): commoncfg = self._instance.config.get('common', {}) stratname = commoncfg.get('strategy', None) stratcfg = self._instance.config.get('strategy', {}) all_classes = get_classes(self._instance.PATH_STRATEGY) if stratname not in all_classes: raise Exception(f'Strategy {stratname} not found') strat = all_classes[stratname] args = {} for x in [ProtoStrategy, ForexProtoStrategy, strat]: if issubclass(strat, x): args.update(stratcfg.get(x.__name__, {})) runtype = ('strategy' if self._instance.mode != btconfig.MODE_OPTIMIZE else 'optstrategy') params = '' if not len(args) else '\n{}'.format( tabulate(args.items(), tablefmt='plain')) txt = f'Creating {runtype} {stratname}{params}' self.log(txt, logging.DEBUG) if self._instance.mode != btconfig.MODE_OPTIMIZE: self._instance.cerebro.addstrategy(strat, **args) else: for x in args: args[x] = (args[x], ) args.update( create_opt_params(self._instance.config.get('optimize', {}))) self._instance.cerebro.optstrategy(strat, **args) self.log(f'Strategy {stratname} created\n', logging.INFO)
def setup(self): sizercfg = self._instance.config.get('sizer', {}) classname = sizercfg.get('classname') params = sizercfg.get('params', {}) if not classname: return all_classes = get_classes(self._instance.PATH_SIZER) if classname not in all_classes: raise Exception(f'Sizer {classname} not found') self.log( 'Creating Sizer {}\n{}'.format( classname, tabulate(params.items(), tablefmt='plain')), logging.DEBUG) self._instance.cerebro.addsizer(all_classes[classname], **params) self.log(f'Sizer {classname} created\n', logging.INFO)
def setup(self) -> None: comminfocfg = self._instance.config.get('comminfo', {}) classname = comminfocfg.get('classname') params = comminfocfg.get('params', {}) if not classname: return all_classes = get_classes(self._instance.PATH_COMMINFO) if classname not in all_classes: raise Exception(f'CommInfo {classname} not found') self.log( 'Creating Comminfo {}\n{}'.format( classname, tabulate(params.items(), tablefmt='plain')), logging.DEBUG) comminfo = all_classes[classname](**params) self._instance.cerebro.broker.addcommissioninfo(comminfo) self.log(f'Comminfo {classname} created\n', logging.INFO)
def __init__(self, instance: btconfig.BTConfig) -> None: ''' Initialization ''' super(PartDatas, self).__init__(instance) self.all_classes = get_classes(self._instance.PATH_FEED)