From 7c68217eb48805c757bf55e47f6bbcf799db0c1c Mon Sep 17 00:00:00 2001 From: 0xDareDevil <114890815+0xDareDevil@users.noreply.github.com> Date: Mon, 17 Oct 2022 22:29:37 +0530 Subject: [PATCH] Fixed bug in calling function get_balance and added enhancements to use to_symbol argument (#2877) Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek --- .../cryptocurrency/due_diligence/binance_model.py | 13 ++++++++++--- .../cryptocurrency/due_diligence/dd_controller.py | 2 +- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/openbb_terminal/cryptocurrency/due_diligence/binance_model.py b/openbb_terminal/cryptocurrency/due_diligence/binance_model.py index 871c7f7ac0a..98e2884cf3c 100644 --- a/openbb_terminal/cryptocurrency/due_diligence/binance_model.py +++ b/openbb_terminal/cryptocurrency/due_diligence/binance_model.py @@ -194,15 +194,22 @@ def get_balance( client = Client(cfg.API_BINANCE_KEY, cfg.API_BINANCE_SECRET) pair = from_symbol + to_symbol - current_balance = client.get_asset_balance(asset=pair) + current_balance = client.get_asset_balance(asset=from_symbol) if current_balance is None: console.print("Check loaded coin\n") return pd.DataFrame() + last_price = client.get_ticker(symbol=pair).get("lastPrice") amounts = [float(current_balance["free"]), float(current_balance["locked"])] - df = pd.DataFrame(amounts).apply(lambda x: str(float(x))) + + df = pd.DataFrame(amounts) df.columns = ["Amount"] df.index = ["Free", "Locked"] - df["Percent"] = df.div(df.sum(axis=0), axis=1).round(3) + + if last_price: + last_price = float(last_price) + df[f"Amount [{to_symbol}]"] = df["Amount"].mul(last_price) + + df["Percent"] = df["Amount"].mul(100).div(df["Amount"].sum(axis=0)).round(3) return df diff --git a/openbb_terminal/cryptocurrency/due_diligence/dd_controller.py b/openbb_terminal/cryptocurrency/due_diligence/dd_controller.py index f6fb3fb0f62..aec50843b81 100644 --- a/openbb_terminal/cryptocurrency/due_diligence/dd_controller.py +++ b/openbb_terminal/cryptocurrency/due_diligence/dd_controller.py @@ -953,7 +953,7 @@ class DueDiligenceController(CryptoBaseController): if ns_parser: binance_view.display_balance( - to_symbol=coin, from_symbol=ns_parser.vs, export=ns_parser.export + from_symbol=coin, to_symbol=ns_parser.vs, export=ns_parser.export ) @log_start_end(log=logger)