def __init__(self, exchange='coinbasepro', filename='config.json'): args = parse_arguments() self.api_key = '' self.api_secret = '' self.api_passphrase = '' self.api_url = '' if args['config'] is not None: filename = args['config'] if args['exchange'] is not None: if args['exchange'] not in ['coinbasepro', 'binance', 'dummy']: raise TypeError('Invalid exchange: coinbasepro, binance') else: self.exchange = args['exchange'] else: self.exchange = exchange self.market = 'BTC-GBP' self.base_currency = 'BTC' self.quote_currency = 'GBP' self.granularity = 3600 self.is_live = 0 self.is_verbose = 0 self.save_graphs = 0 self.is_sim = 0 self.simstartdate = None self.simenddate = None self.sim_speed = 'fast' self.sell_upper_pcnt = None self.sell_lower_pcnt = None self.trailing_stop_loss = None self.sell_at_loss = 1 self.smart_switch = 1 self.telegram = False self.buypercent = 100 self.sellpercent = 100 self.last_action = None self._chat_client = None self.buymaxsize = None self.configbuilder = False self.sellatresistance = False self.autorestart = False self.disablebullonly = False self.disablebuynearhigh = False self.disablebuymacd = False self.disablebuyobv = False self.disablebuyelderray = False self.disablefailsafefibonaccilow = False self.disablefailsafelowerpcnt = False self.disableprofitbankupperpcnt = False self.disableprofitbankreversal = False self.disabletelegram = False self.disablelog = False self.disabletracker = False self.filelog = True self.logfile = args['logfile'] if args['logfile'] else 'pycryptobot.log' self.fileloglevel = 'DEBUG' self.consolelog = True self.consoleloglevel = 'INFO' self.ema1226_1h_cache = None self.ema1226_6h_cache = None self.sma50200_1h_cache = None if args['init']: # config builder cb = ConfigBuilder() cb.init() sys.exit() try: with open(filename) as config_file: config = json.load(config_file) if exchange not in config and 'binance' in config: self.exchange = 'binance' if self.exchange == 'coinbasepro' and 'coinbasepro' in config: coinbaseProConfigParser(self, config['coinbasepro'], args) elif self.exchange == 'binance' and 'binance' in config: binanceConfigParser(self, config['binance'], args) elif self.exchange == 'dummy' and 'dummy' in config: dummyConfigParser(self, config['dummy'], args) if not self.disabletelegram and 'telegram' in config and 'token' in config[ 'telegram'] and 'client_id' in config['telegram']: telegram = config['telegram'] self._chat_client = Telegram(telegram['token'], telegram['client_id']) self.telegram = True if 'logger' in config: loggerConfigParser(self, config['logger']) if self.disablelog: self.filelog = 0 self.fileloglevel = 'NOTSET' self.logfile == "pycryptobot.log" Logger.configure(filelog=self.filelog, logfile=self.logfile, fileloglevel=self.fileloglevel, consolelog=self.consolelog, consoleloglevel=self.consoleloglevel) except json.decoder.JSONDecodeError as err: sys.tracebacklimit = 0 raise ValueError('Invalid config.json: ' + str(err)) except IOError as err: sys.tracebacklimit = 0 raise ValueError('Invalid config.json: ' + str(err)) except ValueError as err: sys.tracebacklimit = 0 raise ValueError('Invalid config.json: ' + str(err))
def __init__(self, exchange='coinbasepro', filename='config.json'): self.api_key = '' self.api_secret = '' self.api_passphrase = '' self.api_url = '' if args['config'] is not None: filename = args['config'] if args['exchange'] is not None: if args['exchange'] not in ['coinbasepro', 'binance', 'dummy']: raise TypeError('Invalid exchange: coinbasepro, binance') else: self.exchange = args['exchange'] else: self.exchange = exchange self.market = 'BTC-GBP' self.base_currency = 'BTC' self.quote_currency = 'GBP' self.granularity = None self.is_live = 0 self.is_verbose = 0 self.save_graphs = 0 self.is_sim = 0 self.simstartdate = None self.sim_speed = 'fast' self.sell_upper_pcnt = None self.sell_lower_pcnt = None self.trailing_stop_loss = None self.sell_at_loss = 1 self.smart_switch = 1 self.telegram = False self.buypercent = 100 self.sellpercent = 100 self.last_action = None self._chat_client = None self.sellatresistance = False self.autorestart = False self.disablebullonly = False self.disablebuynearhigh = False self.disablebuymacd = False self.disablebuyobv = False self.disablebuyelderray = False self.disablefailsafefibonaccilow = False self.disablefailsafelowerpcnt = False self.disableprofitbankupperpcnt = False self.disableprofitbankreversal = False self.disabletelegram = False self.disablelog = False self.disabletracker = False self.logfile = args['logfile'] if args['logfile'] else "pycryptobot.log" try: with open(filename) as config_file: config = json.load(config_file) if exchange not in config and 'binance' in config: self.exchange = 'binance' if self.exchange == 'coinbasepro' and 'coinbasepro' in config: coinbaseProConfigParser(self, config['coinbasepro'], args) elif self.exchange == 'binance' and 'binance' in config: binanceConfigParser(self, config['binance'], args) if not self.disabletelegram and 'telegram' in config and 'token' in config[ 'telegram'] and 'client_id' in config['telegram']: telegram = config['telegram'] self._chat_client = Telegram(telegram['token'], telegram['client_id']) self.telegram = True except json.decoder.JSONDecodeError as err: sys.tracebacklimit = 0 print('Invalid config.json: ' + str(err) + "\n") sys.exit() except IOError as err: sys.tracebacklimit = 0 print('Invalid config.json: ' + str(err) + "\n") sys.exit() except ValueError as err: sys.tracebacklimit = 0 print('Invalid config.json: ' + str(err) + "\n") sys.exit()
def read_config(self, exchange): if os.path.isfile(self.config_file): self.config_provided = True try: with open(self.config_file, "r", encoding="utf8") as stream: try: self.config = yaml.safe_load(stream) except: try: stream.seek(0) self.config = json.load(stream) except json.decoder.JSONDecodeError as err: sys.tracebacklimit = 0 raise ValueError( f"Invalid config.json: {str(err)}") except (ScannerError, ConstructorError) as err: sys.tracebacklimit = 0 raise ValueError( f"Invalid config: cannot parse config file: {str(err)}") except (IOError, FileNotFoundError) as err: sys.tracebacklimit = 0 raise ValueError( f"Invalid config: cannot open config file: {str(err)}") except ValueError as err: sys.tracebacklimit = 0 raise ValueError(f"Invalid config: {str(err)}") except: raise # set exchange platform self.exchange = self._set_exchange(exchange) # set defaults ( self.api_url, self.api_key, self.api_secret, self.api_passphrase, self.market, ) = self._set_default_api_info(self.exchange) if self.config_provided: if self.exchange == Exchange.COINBASEPRO and self.exchange.value in self.config: coinbaseProConfigParser(self, self.config[self.exchange.value], self.cli_args) elif self.exchange == Exchange.BINANCE and self.exchange.value in self.config: binanceConfigParser(self, self.config[self.exchange.value], self.cli_args) elif self.exchange == Exchange.KUCOIN and self.exchange.value in self.config: kucoinConfigParser(self, self.config[self.exchange.value], self.cli_args) elif self.exchange == Exchange.DUMMY and self.exchange.value in self.config: dummyConfigParser(self, self.config[self.exchange.value], self.cli_args) if (not self.disabletelegram and "telegram" in self.config and "token" in self.config["telegram"] and "client_id" in self.config["telegram"]): telegram = self.config["telegram"] self._chat_client = Telegram(telegram["token"], telegram["client_id"]) if "datafolder" in telegram: self.telegramdatafolder = telegram["datafolder"] self.telegram = True if "scanner" in self.config: self.enableexitaftersell = self.config["scanner"][ "enableexitaftersell"] if "enableexitaftersell" in self.config[ "scanner"] else False self.enable_buy_next = True if "enable_buy_now" not in self.config[ "scanner"] else self.config["scanner"]["enable_buy_now"] self.enable_atr72_pcnt = True if "enable_atr72_pcnt" not in self.config[ "scanner"] else self.config["scanner"]["enable_atr72_pcnt"] self.enable_volume = False if "enable_volume" not in self.config[ "scanner"] else self.config["scanner"]["enable_volume"] if "logger" in self.config: loggerConfigParser(self, self.config["logger"]) if self.disablelog: self.filelog = 0 self.fileloglevel = "NOTSET" self.logfile == "/dev/null" else: if self.exchange == Exchange.BINANCE: binanceConfigParser(self, None, self.cli_args) elif self.exchange == Exchange.KUCOIN: kucoinConfigParser(self, None, self.cli_args) else: coinbaseProConfigParser(self, None, self.cli_args) self.filelog = 0 self.fileloglevel = "NOTSET" self.logfile == "/dev/null"