def load_algo_config(config, algo): load_successful = False for i, algo_config in enumerate(config): if algo == list(algo_config.keys())[0]: try: globalvars.algo_config_list.append(algo_config) calclog.debug("Found " + algo + " in config file") load_successful = True return load_successful except (KeyError, IndexError) as err: calclog.error(algo + " not found in file") return load_successful
def load_se_prices(se_prices): prices_loaded = False # Load the prices of coins on stocks exchange. while not prices_loaded: try: se_prices = requests.get( 'https://stocks.exchange/api2/prices').json() prices_loaded = True except (requests.exceptions.HTTPError, ValueError, ConnectionError) as err: prices_loaded = False calclog.error( "Error loading prices from Stocks.Exchange api, trying again in 30 seconds..." ) time.sleep(30) return se_prices
def load_cb_prices(cb_prices): prices_loaded = False # Load prices from Crypto-bridge. while not prices_loaded: try: cb_prices = requests.get( 'https://api.crypto-bridge.org/api/v1/ticker').json() prices_loaded = True except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError, ValueError, ConnectionError) as err: prices_loaded = False calclog.error( "Error loading prices from Crypto-bridge api, trying again in 30 seconds..." ) time.sleep(30) return cb_prices
def load_ct_prices(ct_prices): prices_loaded = False # Load prices from Cryptopia. while not prices_loaded: try: ct_prices = requests.get( 'https://www.cryptopia.co.nz/api/GetMarkets').json() prices_loaded = True except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError, ValueError, ConnectionError) as err: prices_loaded = False calclog.error( "Error loading prices from Cryptopia api, trying again in 30 seconds..." ) time.sleep(30) return ct_prices
def load_sx_prices(sx_prices): prices_loaded = False # Load prices from Southxchange. while not prices_loaded: try: sx_prices = requests.get( 'https://www.southxchange.com/api/prices').json() prices_loaded = True except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError, ValueError, ConnectionError) as err: prices_loaded = False calclog.error( "Error loading prices from Southxchange api, trying again in 30 seconds..." ) time.sleep(30) return sx_prices
def load_btc_price(btc_price): prices_loaded = False # Load the price of BTC from coinbase. while not prices_loaded: try: btc_price = requests.get( 'https://api.coinbase.com/v2/exchange-rates?currency=BTC' ).json() prices_loaded = True except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError, ValueError, ConnectionError) as err: prices_loaded = False calclog.error( "Error loading prices from Coinbase api, trying again in 30 seconds..." ) time.sleep(30) return btc_price
def load_ts_prices(ts_prices): prices_loaded = False # Load prices from trade satoshi. while not prices_loaded: try: ts_prices = requests.get( 'https://tradesatoshi.com/api/public/getmarketsummaries').json( ) prices_loaded = True except (requests.exceptions.HTTPError, requests.exceptions.ConnectionError, ValueError, ConnectionError) as err: prices_loaded = False calclog.error( "Error loading prices from Trade Satoshi api, trying again in 30 seconds..." ) time.sleep(30) return ts_prices
def load_difficulty(url, name): new_num = '' difficulty_loaded = False if "crypto-coinz" in url: i = 0 while not difficulty_loaded: difficulty_loaded = False try: response = requests.get(url) txt = response.text num = txt.find("Difficulty:") for i in range(15): if txt[num + 19 + i].isdigit() or txt[num + 19 + i] == '.': new_num += txt[num + 19 + i] difficulty = float(new_num) difficulty_loaded = True except (requests.exceptions.HTTPError, ValueError) as err: #calclog.error("Error loading " + name + " difficuly. Retrying...") i += 1 except: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded finally: if i == 3: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded elif "fsight" in url: difficulty_loaded = False i = 0 while not difficulty_loaded: try: temp = requests.get(url).json() difficulty = float(temp["difficulty"]) difficulty_loaded = True except (requests.exceptions.HTTPError, ValueError) as err: #calclog.error("Error loading " + name + " difficuly. Retrying...") i += 1 except: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded finally: if i == 3: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded elif "trezar" in url or "denarius" in url: i = 0 difficulty_loaded = False while not difficulty_loaded: try: temp = requests.get(url).json() difficulty = float(temp["proof-of-work"]) difficulty_loaded = True except (requests.exceptions.HTTPError, ValueError) as err: #calclog.error("Error loading " + name + " difficuly. Retrying...") i += 1 except: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded finally: if i == 3: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded elif "zcha" in url: i = 0 difficulty_loaded = False while not difficulty_loaded: try: temp = requests.get(url).json() difficulty = float(temp["difficulty"]) difficulty_loaded = True except (requests.exceptions.HTTPError, ValueError) as err: #calclog.error("Error loading " + name + " difficuly. Retrying...") i += 1 except: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded finally: if i == 3: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded else: i = 0 difficulty_loaded = False while not difficulty_loaded: try: difficulty = float(requests.get(url).text) difficulty_loaded = True except (requests.exceptions.HTTPError, ValueError) as err: #calclog.error("Error loading " + name + " difficuly. Retrying...") i += 1 except: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded finally: if i == 3: calclog.error("Could not load the difficulty for " + name + ". Skipping coin") difficulty = 0 return difficulty, difficulty_loaded return difficulty, difficulty_loaded
try: globalvars.algo_config_list.append(algo_config) calclog.debug("Found " + algo + " in config file") load_successful = True return load_successful except (KeyError, IndexError) as err: calclog.error(algo + " not found in file") return load_successful if __name__ == "__main__": # Check if the person has a configuration file. If not, start benchmarking. config_load_successful, config = load_config() if not config_load_successful: calclog.error( "Config file not found, try running the benchmark first.") if config_load_successful: coin_info = json.load(open('coininfo.json')) algorithm_list = [] algorithm_list.append(coin_info[0]['algo']) for key in coin_info: if not key['algo'] in algorithm_list: algorithm_list.append(key['algo']) for i, algo in enumerate(algorithm_list): algo_config_load_successful = load_algo_config(config, algo) if not algo_config_load_successful: calclog.error(