def __init__(self, parsed_config, parsed_creds): # Load creds for correct environment access_key, secret_key = load_correct_creds(parsed_creds) self.client = Client(access_key, secret_key) api_ready, msg = test_api_key(client, BinanceAPIException) if api_ready is not True: raise Exception(msg) # Load system vars self.test_mode = parsed_config['script_options']['TEST_MODE'] self.log_trades = parsed_config['script_options'].get('LOG_TRADES') self.log_file = parsed_config['script_options'].get('LOG_FILE') self.debug = parsed_config['script_options'].get('DEBUG') or False # Load trading vars self.custom_list = parsed_config['trading_options']['CUSTOM_LIST'] self.pair_with = parsed_config['trading_options']['PAIR_WITH'] self.fiats = parsed_config['trading_options']['FIATS'] self.time_difference = parsed_config['trading_options']['TIME_DIFFERENCE'] self.recheck_interval = parsed_config['trading_options']['RECHECK_INTERVAL'] self.change_in_price = parsed_config['trading_options']['CHANGE_IN_PRICE'] self.max_coins = parsed_config['trading_options']['MAX_COINS'] self.quantity = parsed_config['trading_options']['QUANTITY'] self.stop_loss = parsed_config['trading_options']['STOP_LOSS'] self.take_profit = parsed_config['trading_options']['TAKE_PROFIT'] self.user_trailing_stop_loss = parsed_config['trading_options']['USE_TRAILING_STOP_LOSS'] self.trailing_stop_loss = parsed_config['trading_options']['TRAILING_STOP_LOSS'] self.trailing_take_profit = parsed_config['trading_options']['TRAILING_TAKE_PROFIT'] # rolling window of prices; cyclical queue self.historical_prices = [None] * (self.time_difference * self.recheck_interval) self.hsp_head = -1 self.coins_bought = {} # path to the saved coins_bought file self.coins_bought_file_path = 'coins_bought.json' # use separate files for testing and live trading if self.test_mode: self.coins_bought_file_path = 'test_' + self.coins_bought_file_path # if saved coins_bought json file exists and it's not empty then load it if os.path.isfile(self.coins_bought_file_path) and os.stat(self.coins_bought_file_path).st_size != 0: with open(self.coins_bought_file_path) as file: self.coins_bought = json.load(file) # prevent including a coin in volatile_coins if it has already appeared there less than TIME_DIFFERENCE minutes ago self.volatility_cooloff = {} # Use CUSTOM_LIST symbols if CUSTOM_LIST is set to True self.tickers = [line.strip() for line in open('tickers.txt')] if self.custom_list else [] # tracks profit/loss each session self.session_profit = 0
args = parse_args() DEFAULT_CONFIG_FILE = '../config.yml' DEFAULT_CREDS_FILE = '../creds.yml' config_file = args.config if args.config else DEFAULT_CONFIG_FILE creds_file = args.creds if args.creds else DEFAULT_CREDS_FILE parsed_creds = load_config(creds_file) parsed_config = load_config(config_file) LOG_TRADES = parsed_config['script_options'].get('LOG_TRADES') LOG_FILE = parsed_config['script_options'].get('LOG_FILE') LOG_FILE_PATH = '../' + LOG_FILE access_key, secret_key = load_correct_creds(parsed_creds) client = Client(access_key, secret_key) def write_log(logline): timestamp = datetime.now().strftime("%d/%m %H:%M:%S") with open(LOG_FILE_PATH, 'a+') as f: f.write(timestamp + ' ' + logline + '\n') with open('../coins_bought.json', 'r') as f: coins = json.load(f) for coin in list(coins): sell_coin = client.create_order(symbol=coin,