From 5ee71c08f2cf96f966711f9cc88583e3a9efa67f Mon Sep 17 00:00:00 2001 From: Jamie Date: Sat, 1 May 2021 20:05:05 -0400 Subject: [PATCH] crypto readme --- gamestonk_terminal/cryptocurrency/README.md | 56 ++++++++++++++++++- .../cryptocurrency/binance_model.py | 19 ++++--- .../cryptocurrency/crypto_controller.py | 5 +- 3 files changed, 69 insertions(+), 11 deletions(-) diff --git a/gamestonk_terminal/cryptocurrency/README.md b/gamestonk_terminal/cryptocurrency/README.md index 4a1b7b48fea..882e2756a51 100644 --- a/gamestonk_terminal/cryptocurrency/README.md +++ b/gamestonk_terminal/cryptocurrency/README.md @@ -6,9 +6,21 @@ This menu aims to explore crypto world, and the usage of the following commands * load a given coin vs a given currency [CoinGecko] * [view](#view) * plot the loaded crypto data +* [trend](#trend) + * show the top 7 coins from coingecko * [top](#top) * view top coins from coinmarketcap [coinmarketcap.com] - +* [add](#add) + * add a coin/currency pair for Binance + +* [book](#book) + * get and show market (order) book + +* [candle](#candle) + * show candle plot of selected coin/currency + +* [balance](#balance) + * show current holdings in your account for given coin ## load @@ -35,6 +47,12 @@ Plot the loaded crypto data. ![crypto_view](https://user-images.githubusercontent.com/25267873/115787452-20889a80-a3ba-11eb-9216-f7fd1ffc98cf.png) +## trend +Print the top 7 trending coins from coingecko +```` +usage: trend +```` + ## top @@ -50,3 +68,39 @@ This command displays the top n cryptocurrencies from coinmarketcap.com. crypto +## add +Add a coin/currency to the current object. Note that in binance, the exchange "ticker" is usually COINCURR, such as BTCEUR +for BTC to EURO. There is no USD, but it uses a coin tethered to the USD (USDT), which is the default. Some symbols +are a combination of coins, as `ETHBTC` is a valid symbol +```` +usage: add [-c --coin] [-q --quote] +```` +* -c/--coin Coin to load. If not specified, BTC will be loaded to prevent errors later. +* -q/--quote Quote currency. Defaults to `USDT` (which is 1-to-1 with USD) + +Note that the usage `load btc` will also work, as it will add `-c` if not detected. + +## book +Gets and shows the order book for the given coin/currency. Shows the cumulative amount of orders. +```` +usage: book -l/--limit +```` +* -l/--limit Number of orders to get on each side. One of [5,10,20,50,100,500,1000,5000]. Defaults to 100. + +## candle +Show candle chart for loaded coin/currency. (Terminal will quit if coin is not defined). +```` +usage: candle [-i --interval] [-l --limit] +```` +* -i/--interval. Interval for candles. One of [1day,3day,1hour,2hour,4hour,6hour,8hour,12hour,1week,1min,3min,5min,15min,30min,1month]. + Defaults to 1day. +* -l/--limit. Number of candles to get. Defaults to 100. +Example output (using 3day interval and 50 candles) + +![im](https://user-images.githubusercontent.com/18151143/116797645-f455d380-aab5-11eb-8dbb-df257425302d.png) + +## balance +Shows the current holding balance in your account. +```` +usage: balance +```` diff --git a/gamestonk_terminal/cryptocurrency/binance_model.py b/gamestonk_terminal/cryptocurrency/binance_model.py index 8346ca43ab5..d9e1e0a56dc 100644 --- a/gamestonk_terminal/cryptocurrency/binance_model.py +++ b/gamestonk_terminal/cryptocurrency/binance_model.py @@ -102,18 +102,19 @@ def order_book(coin: str, other_args: List[str]): 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) - bids = np.asarray(order_book["bids"], dtype=float) - asks = np.asarray(order_book["asks"], dtype=float) + market_book = client.get_order_book(symbol=coin, limit=ns_parser.limit) + bids = np.asarray(market_book["bids"], dtype=float) + asks = np.asarray(market_book["asks"], dtype=float) bids = np.insert(bids, 2, bids[:, 1].cumsum(), axis=1) asks = np.insert(asks, 2, np.flipud(asks[:, 1]).cumsum(), axis=1) plot_order_book(bids, asks, coin) + except Exception as e: print(e) print("") -def candles(coin: str, other_args: List[str]): +def show_candles(coin: str, other_args: List[str]): """ Get klines/candles for coin Parameters @@ -164,7 +165,7 @@ def candles(coin: str, other_args: List[str]): ) parser.add_argument( - "-l", "--limit", dest="limit", default=200, help="Number to get", type=int + "-l", "--limit", dest="limit", default=100, help="Number to get", type=int ) try: @@ -231,12 +232,14 @@ def balance(coin: str): """ client = Client(BINANCE_API_KEY, BINANCE_SECRET_KEY) try: - balance = client.get_asset_balance(asset=coin) - if balance is None: + current_balance = client.get_asset_balance(asset=coin) + if current_balance is None: print("Check loaded coin") return print("") - print(f"You currently have {balance['free']} free and {balance['locked']} locked") + print( + f"You currently have {current_balance['free']} free and {current_balance['locked']} locked" + ) print("") return except Exception as e: diff --git a/gamestonk_terminal/cryptocurrency/crypto_controller.py b/gamestonk_terminal/cryptocurrency/crypto_controller.py index 8f6704e816e..a40596315be 100644 --- a/gamestonk_terminal/cryptocurrency/crypto_controller.py +++ b/gamestonk_terminal/cryptocurrency/crypto_controller.py @@ -120,7 +120,9 @@ class CryptoController: def call_candle(self, other_args): """Candle command - show candle chart from binance""" - binance_model.candles(self.current_coin + self.current_currency, other_args) + binance_model.show_candles( + self.current_coin + self.current_currency, other_args + ) def call_balance(self, _): """Balance command - check current holdings of coin in binance""" @@ -134,7 +136,6 @@ class CryptoController: print(f"{self.current_coin} loaded vs {self.current_currency}") print("") - def menu(): crypto_controller = CryptoController() crypto_controller.print_help(crypto_controller)