def get_index_info_model(): try: return IndexInfoModel.get(id=1) except Exception as e: # Model dosen't exist #logger.exception(e) return None
def update_index_info_model(active, totalBtcVal, totalUsdVal, totalRealizedGain, totalUnrealizedGain, balanceThreshold, orderTimeout, orderRetryAmount, rebalanceTickSetting): try: indexInfo = IndexInfoModel.get(id=1) indexInfo.Active = active indexInfo.TotalBTCVal = round(totalBtcVal, 8) indexInfo.TotalUSDVal = round(totalUsdVal, 8) indexInfo.TotalRealizedGain = round(totalRealizedGain, 8) indexInfo.TotalUnrealizedGain = round(totalUnrealizedGain, 8) indexInfo.BalanceThreshold = balanceThreshold indexInfo.OrderTimeout = orderTimeout indexInfo.OrderRetryAmount = orderRetryAmount indexInfo.RebalanceTickSetting = rebalanceTickSetting indexInfo.save() return True except IntegrityError: return False except Exception as e: logger.exception(e)
def get_index_info_model(): with internal_database.execution_context(): try: return IndexInfoModel.get(id=1) except Exception as e: # Model dosen't exist #logger.exception(e) return None
def show_stats(self): indexInfo = IndexInfoModel.get(id=1) # Create the Index Table cointTableData = [[ 'Coin', 'Amount', 'BTC Val', 'USD Val', 'Desired %', 'Locked', 'Active %', 'U Gain %', 'R Gain %' ]] for coin in IndexedCoinModel.select(): coinBalance = CoinBalanceModel.get( CoinBalanceModel.Coin == coin.Ticker) realizedGainModel = DatabaseManager.get_realized_gain_model( coin.Ticker) newArray = [ coin.Ticker, coinBalance.TotalCoins, coinBalance.BTCBalance, round(coinBalance.USDBalance, 2), coin.DesiredPercentage, coin.Locked, coin.CurrentPercentage, coin.UnrealizedGain, realizedGainModel.RealizedGain, ] cointTableData.append(newArray) # Create the summary table summary_table_data = [[ 'Active', 'Index Count', 'BTC Val', 'USD Val', 'Unrealized Gain %', 'Realized Gain %' ]] summary_table_data.append([ True, len(IndexedCoinModel.select()), indexInfo.TotalBTCVal, indexInfo.TotalUSDVal, round(indexInfo.TotalUnrealizedGain, 2), round(indexInfo.TotalRealizedGain, 2) ]) coin_table = AsciiTable(cointTableData) summary_table = AsciiTable(summary_table_data) sys.stdout.write("\nCurrent Index Summary\n") sys.stdout.write(summary_table.table) sys.stdout.write("\nCurrent Index Table\n") sys.stdout.write(coin_table.table) sys.stdout.write('\n')
def show_stats(self): indexInfo = IndexInfoModel.get(id=1) # Create the Index Table cointTableData = [[ 'Coin', 'Amount', 'BTC Val', 'USD Val', 'Locked', 'Desired %', 'Current %', 'Off Target %' ]] for coin in IndexedCoinModel.select(): coinBalance = CoinBalanceModel.get( CoinBalanceModel.Coin == coin.Ticker) newArray = [ coin.Ticker, coinBalance.TotalCoins, coinBalance.BTCBalance, round(coinBalance.USDBalance, 2), coin.Locked, coin.DesiredPercentage, coinBalance.get_current_percentage(indexInfo.TotalBTCVal), coin.get_percent_from_coin_target(coinBalance, indexInfo.TotalBTCVal) ] cointTableData.append(newArray) # Create the summary table summary_table_data = [[ 'Active', 'Index Count', 'BTC Val', 'USD Val', ]] summary_table_data.append([ True, len(IndexedCoinModel.select()), indexInfo.TotalBTCVal, indexInfo.TotalUSDVal ]) coin_table = AsciiTable(cointTableData) summary_table = AsciiTable(summary_table_data) sys.stdout.write("\nCurrent Index Summary\n") sys.stdout.write(summary_table.table) sys.stdout.write("\nCurrent Index Table\n") sys.stdout.write(coin_table.table) sys.stdout.write('\n')