From af58e97c63ea54e62b8a4f383413ac99b44140bd Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 1 May 2021 19:20:46 -0400 Subject: [PATCH] add balance command --- .../cryptocurrency/binance_model.py | 38 +++++++++++-------- .../cryptocurrency/binance_view.py | 10 ++--- .../cryptocurrency/crypto_controller.py | 4 +- gamestonk_terminal/main_helper.py | 2 +- 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/gamestonk_terminal/cryptocurrency/binance_model.py b/gamestonk_terminal/cryptocurrency/binance_model.py index 8346035e643..8346ca43ab5 100644 --- a/gamestonk_terminal/cryptocurrency/binance_model.py +++ b/gamestonk_terminal/cryptocurrency/binance_model.py @@ -84,23 +84,25 @@ def order_book(coin: str, other_args: List[str]): """ limit_list = [5, 10, 20, 50, 100, 500, 1000, 5000] - parser = argparse.ArgumentParser(prog = "book", - add_help = False, - description="Get the order book for selected coin") - parser.add_argument("-l", - "--limit", - dest="limit", - help="Limit parameter. Adjusts the weight", - default = 100, - type = int, - choices=limit_list) + parser = argparse.ArgumentParser( + prog="book", add_help=False, description="Get the order book for selected coin" + ) + parser.add_argument( + "-l", + "--limit", + dest="limit", + help="Limit parameter. Adjusts the weight", + default=100, + type=int, + choices=limit_list, + ) try: ns_parser = parse_known_args_and_warn(parser, other_args) if not ns_parser: return client = Client(BINANCE_API_KEY, BINANCE_SECRET_KEY) - order_book = client.get_order_book(symbol=coin, limit = ns_parser.limit) + order_book = client.get_order_book(symbol=coin, limit=ns_parser.limit) bids = np.asarray(order_book["bids"], dtype=float) asks = np.asarray(order_book["asks"], dtype=float) bids = np.insert(bids, 2, bids[:, 1].cumsum(), axis=1) @@ -215,15 +217,13 @@ def candles(coin: str, other_args: List[str]): print("") -def balance(coin: str, other_args: List[str]): +def balance(coin: str): """ Get account holdings for asset Parameters ---------- coin: str Coin to get holdings of - other_args : List[str] - Argparse arguments Returns ------- @@ -231,7 +231,15 @@ def balance(coin: str, other_args: List[str]): """ client = Client(BINANCE_API_KEY, BINANCE_SECRET_KEY) try: - client.get_asset_balance(asset=coin) + balance = client.get_asset_balance(asset=coin) + if balance is None: + print("Check loaded coin") + return + print("") + print(f"You currently have {balance['free']} free and {balance['locked']} locked") + print("") + return except Exception as e: print(e) print("") + return diff --git a/gamestonk_terminal/cryptocurrency/binance_view.py b/gamestonk_terminal/cryptocurrency/binance_view.py index 1a988c94ad9..8ddbebee199 100644 --- a/gamestonk_terminal/cryptocurrency/binance_view.py +++ b/gamestonk_terminal/cryptocurrency/binance_view.py @@ -44,15 +44,15 @@ def plot_order_book(bids: np.array, asks: np.array, coin: str): print("") -def plot_candles(candles_df: pd.DataFrame, coin: str): +def plot_candles(candles_df: pd.DataFrame, title: str): """ Plot candle chart from dataframe Parameters ---------- candles_df: pd.DataFrame Dataframe containing time and OHLVC - coin: str - Coin plotting for + title: str + title of graph Returns ------- @@ -62,8 +62,8 @@ def plot_candles(candles_df: pd.DataFrame, coin: str): candles_df, type="candle", volume=True, - title=f"{coin}", - xrotation=10, + title=f"{title}", + xrotation=20, style="binance", figratio=(10, 7), figscale=1.10, diff --git a/gamestonk_terminal/cryptocurrency/crypto_controller.py b/gamestonk_terminal/cryptocurrency/crypto_controller.py index a3f07271ed8..8f6704e816e 100644 --- a/gamestonk_terminal/cryptocurrency/crypto_controller.py +++ b/gamestonk_terminal/cryptocurrency/crypto_controller.py @@ -122,9 +122,9 @@ class CryptoController: """Candle command - show candle chart from binance""" binance_model.candles(self.current_coin + self.current_currency, other_args) - def call_balance(self, other_args): + def call_balance(self, _): """Balance command - check current holdings of coin in binance""" - binance_model.balance(self.current_coin, other_args) + binance_model.balance(self.current_coin) def call_add(self, other_args): """Add command - set current coin for binance operations""" diff --git a/gamestonk_terminal/main_helper.py b/gamestonk_terminal/main_helper.py index 2c813d24a46..eef982c7349 100644 --- a/gamestonk_terminal/main_helper.py +++ b/gamestonk_terminal/main_helper.py @@ -57,7 +57,7 @@ def print_help(s_ticker, s_start, s_interval, b_is_market_open): print(" mill papermill menu, \t\t\t menu to generate notebook reports") print(" econ economic data, \t\t\t from: FRED, VIX") print(" pa portfolio analysis, \t\t supports: robinhood, alpaca, ally ") - print(" crypto cryptocurrencies, \t\t uses coingecko api") + print(" crypto cryptocurrencies, \t\t coingecko, coinmarketcap and binance") print( " po portfolio optimization, \t\t optimal portfolio weights from pyportfolioopt" )