async def show_balances(self): self._notify("Updating balances, please wait...") df = await self.balances_df() lines = [ " " + line for line in df.to_string(index=False).split("\n") ] self._notify("\n".join(lines)) eth_address = global_config_map["ethereum_wallet"].value if eth_address is not None: bal = UserBalances.ethereum_balance() bal = round(bal, 4) self._notify( f"Ethereum balance in ...{eth_address[-4:]} wallet: {bal} ETH") self._notify( f"Note: You may have other ERC 20 tokens in this same address (not shown here)." ) celo_address = global_config_map["celo_address"].value if celo_address is not None: try: if not CeloCLI.unlocked: await self.validate_n_connect_celo() bals = CeloCLI.balances() self._notify("Celo balances:") for token, bal in bals.items(): self._notify( f" {token} - total: {bal.total} locked: {bal.locked}") except Exception as e: self._notify(f"Celo CLI Error: {str(e)}")
def test_balances(self): result = CeloCLI.unlock_account(celo_address, celo_password) self.assertEqual(result, None) results = CeloCLI.balances() self.assertTrue(results[CELO_BASE].total > 0) self.assertTrue(results[CELO_BASE].available() > 0) self.assertTrue(results[CELO_QUOTE].total > 0) self.assertTrue(results[CELO_QUOTE].available() > 0)
async def celo_balances_df(self, # type: HummingbotApplication ): rows = [] bals = CeloCLI.balances() for token, bal in bals.items(): rows.append({"Asset": token.upper(), "Amount": round(bal.total, 4)}) df = pd.DataFrame(data=rows, columns=["Asset", "Amount"]) df.sort_values(by=["Asset"], inplace=True) return df