def index_remove_coin(self, coin): if (coin.upper() == "BTC"): logger.warn("You cannot remove BTC from your index.") return indexedCoin = DatabaseManager.get_index_coin_model(coin.upper()) btcCoin = DatabaseManager.get_index_coin_model('BTC') percentageToAdd = indexedCoin.DesiredPercentage if self.coin_supported_check(coin.upper()): if DatabaseManager.delete_index_coin_model(coin.upper()): # Add percentage back to BTC model DatabaseManager.update_index_coin_model( btcCoin.Ticker, btcCoin.DesiredPercentage + percentageToAdd, btcCoin.DistanceFromTarget, btcCoin.Locked) logger.info("Coin " + coin.upper() + " removed from index") else: # Already Exist logger.warn("Coin not in index") else: logger.warn("Coin not supported")
def import_index(self): """Destructively create the index from a JSON file.""" coins = DatabaseManager.get_all_index_coin_models() for coin in coins: DatabaseManager.delete_index_coin_model(coin.Ticker) indexed_coins = "" with open("index.json", "r") as file_obj: indexed_coins = jsonpickle.decode(file_obj.read()) for coin in indexed_coins: coin.DesiredPercentage = coin.DesiredPercentage if coin.DesiredPercentage is not None else 1 coin.Locked = coin.Locked if coin.Locked is not None else False # logger.debug('adding %s with percentage %s', coin.Ticker, coin.DesiredPercentage) DatabaseManager.create_index_coin_model(coin.Ticker, coin.DesiredPercentage, 0, coin.Locked) logger.info("Index imported from index.json")
def index_remove_coin(self, coin): if self.coin_supported_check(coin.upper()): if DatabaseManager.delete_index_coin_model(coin.upper()): DatabaseManager.delete_realized_gain_model(coin.upper()) logger.info("Coin " + coin.upper() + " removed from index") else: # Already Exist logger.warn("Coin not in index") else: logger.warn("Coin not supported")