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 = self.arg_parser.parse_known_args()[0] self.blueprint_days = args.days self.ticker_size = int(args.ticker_size) self.blueprint_end_time = int(time.time()) self.start_time = self.blueprint_end_time - int( self.blueprint_days) * 86400 self.ticker_epoch = self.start_time self.exchange = Exchange(None) self.pairs = common.parse_pairs(self.exchange, args.pairs) blueprints_module = common.load_module('ai.blueprints.', args.features) self.blueprint = blueprints_module(self.pairs) self.max_buffer_size = int( int(args.buffer_size) * (1440 / self.ticker_size) * len(self.pairs)) self.df_buffer = pd.DataFrame() self.df_blueprint = pd.DataFrame() self.output_dir = args.output_dir self.export_file_name = self.get_output_file_path( self.output_dir, self.blueprint.name) self.export_file_initialized = False # Crete output dir if not os.path.exists(self.out_dir): os.makedirs(self.out_dir)
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()