def __init__(self): self.args = self.arg_parser.parse_known_args()[0] self.parse_config() strategy_class = common.load_module('strategies.', self.args.strategy) self.wallet = Wallet() self.history = pd.DataFrame() trade_columns = ['date', 'pair', 'close_price', 'action'] self.trades = pd.DataFrame(columns=trade_columns, index=None) if self.args.backtest: self.bot = Backtest(self.wallet.initial_balance.copy()) self.trade_mode = TradeMode.backtest elif self.args.paper: self.bot = Paper(self.wallet.initial_balance.copy()) self.trade_mode = TradeMode.paper self.wallet.initial_balance = self.bot.get_balance() self.wallet.current_balance = self.bot.get_balance() elif self.args.live: self.bot = Live() self.trade_mode = TradeMode.live self.wallet.initial_balance = self.bot.get_balance() self.wallet.current_balance = self.bot.get_balance() self.strategy = strategy_class() self.pairs = self.bot.get_pairs() self.look_back = pd.DataFrame() self.max_lookback_size = int(self.buffer_size*(1440/self.interval)*len(self.pairs)) self.initialize()
def __init__(self, args, config_file): # Arguments should override config.ini file, so lets initialize # them only after config file parsing self.parse_config(config_file) self.args = args self.config = config_file strategy_class = self.load_strategy(args.strategy, self.config_strategy_name) self.strategy = strategy_class(args, self.verbosity) self.wallet = Wallet(config_file) self.history = pd.DataFrame() trade_columns = ['date', 'pair', 'close_price', 'action'] self.trades = pd.DataFrame(columns=trade_columns, index=None) if args.backtest: self.bot = Backtest(args, config_file) self.trade_mode = TradeMode.backtest elif args.paper: self.bot = Paper(args, config_file) self.trade_mode = TradeMode.paper self.wallet.initial_balance = self.bot.get_balance() self.wallet.current_balance = self.bot.get_balance() elif args.live: self.bot = Live(args, config_file) self.trade_mode = TradeMode.live self.wallet.initial_balance = self.bot.get_balance() self.wallet.current_balance = self.bot.get_balance() self.pairs = self.bot.get_pairs() self.look_back = pd.DataFrame() self.max_lookback_size = int(self.buffer_size * (60 / self.interval) * len(self.pairs)) self.initialize()
def __init__(self, trade_mode_input=None, plot_input=None, strategy='ema'): self.args = self.arg_parser.parse_known_args()[0] self.args.strategy = strategy # handle debugging initialization if trade_mode_input: if trade_mode_input == 'backtest': self.args.backtest = True elif trade_mode_input == 'paper': self.args.backtest = True elif trade_mode_input == 'live': self.args.live = True else: self.args.backtest = True if plot_input: self.args.plot = plot_input self.parse_config() strategy_class = common.load_module('strategies.', self.args.strategy) self.wallet = Wallet() self.history = pd.DataFrame() trade_columns = ['date', 'pair', 'close_price', 'action'] self.trades = pd.DataFrame(columns=trade_columns, index=None) if self.args.backtest: self.bot = Backtest(self.wallet.initial_balance.copy()) self.trade_mode = TradeMode.backtest elif self.args.paper: self.bot = Paper(self.wallet.initial_balance.copy()) self.trade_mode = TradeMode.paper self.wallet.initial_balance = self.bot.get_balance() self.wallet.current_balance = self.bot.get_balance() elif self.args.live: self.bot = Live() self.trade_mode = TradeMode.live self.wallet.initial_balance = self.bot.get_balance() self.wallet.current_balance = self.bot.get_balance() self.strategy = strategy_class( ) #chiama il costruttore della strategie avendone preso il nome!molto oscuro! self.pairs = self.bot.get_pairs() self.look_back = pd.DataFrame() self.max_lookback_size = int(self.buffer_size * (1440 / self.interval) * len(self.pairs)) self.initialize()