From 9b05c15e863fad350909568000b1b336c9d1fa4f Mon Sep 17 00:00:00 2001 From: jose-donato <43375532+jose-donato@users.noreply.github.com> Date: Tue, 1 Nov 2022 22:37:13 +0000 Subject: [PATCH] Adds crypto features missing in SDK (#2989) * fix(docs): added margin between sections * fix: added/changed missing crypto commands in sdk * fix: added logging to ccxt and sdk fix * fix: vs_currency -> to_symbol; num -> limit Co-authored-by: James Maslek Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: minhhoang1023 <40023817+minhhoang1023@users.noreply.github.com> --- .../due_diligence/ccxt_model.py | 12 ++++----- .../cryptocurrency/due_diligence/ccxt_view.py | 27 +++++++++++++------ .../due_diligence/dd_controller.py | 4 +-- .../cryptocurrency/nft/nft_controller.py | 2 +- .../cryptocurrency/nft/nftpricefloor_view.py | 8 +++--- openbb_terminal/sdk.py | 23 +++++++++------- 6 files changed, 46 insertions(+), 30 deletions(-) diff --git a/openbb_terminal/cryptocurrency/due_diligence/ccxt_model.py b/openbb_terminal/cryptocurrency/due_diligence/ccxt_model.py index e6dfacc0a54..017a45eacf5 100644 --- a/openbb_terminal/cryptocurrency/due_diligence/ccxt_model.py +++ b/openbb_terminal/cryptocurrency/due_diligence/ccxt_model.py @@ -22,7 +22,7 @@ def get_exchanges(): return ccxt.exchanges -def get_orderbook(exchange_id: str, symbol: str, vs: str) -> Dict: +def get_orderbook(exchange_id: str, symbol: str, to_symbol: str) -> Dict: """Returns orderbook for a coin in a given exchange [Source: https://docs.ccxt.com/en/latest/manual.html] @@ -32,7 +32,7 @@ def get_orderbook(exchange_id: str, symbol: str, vs: str) -> Dict: exchange id symbol : str coin symbol - vs : str + to_symbol : str currency to compare coin against Returns @@ -41,11 +41,11 @@ def get_orderbook(exchange_id: str, symbol: str, vs: str) -> Dict: """ exchange_class = getattr(ccxt, exchange_id) exchange = exchange_class() - ob = exchange.fetch_order_book(f"{symbol.upper()}/{vs.upper()}") + ob = exchange.fetch_order_book(f"{symbol.upper()}/{to_symbol.upper()}") return ob -def get_trades(exchange_id: str, symbol: str, vs: str) -> pd.DataFrame: +def get_trades(exchange_id: str, symbol: str, to_symbol: str) -> pd.DataFrame: """Returns trades for a coin in a given exchange [Source: https://docs.ccxt.com/en/latest/manual.html] @@ -55,7 +55,7 @@ def get_trades(exchange_id: str, symbol: str, vs: str) -> pd.DataFrame: exchange id symbol : str coin symbol - vs : str + to_symbol : str currency to compare coin against Returns @@ -65,7 +65,7 @@ def get_trades(exchange_id: str, symbol: str, vs: str) -> pd.DataFrame: """ exchange_class = getattr(ccxt, exchange_id) exchange = exchange_class() - trades = exchange.fetch_trades(f"{symbol.upper()}/{vs.upper()}") + trades = exchange.fetch_trades(f"{symbol.upper()}/{to_symbol.upper()}") df = pd.DataFrame(trades, columns=["datetime", "price", "amount", "cost", "side"]) df["datetime"] = pd.to_datetime(df["datetime"]) df.rename(columns={"datetime": "date"}, inplace=True) diff --git a/openbb_terminal/cryptocurrency/due_diligence/ccxt_view.py b/openbb_terminal/cryptocurrency/due_diligence/ccxt_view.py index 15f45f4d07c..2bfa0208735 100644 --- a/openbb_terminal/cryptocurrency/due_diligence/ccxt_view.py +++ b/openbb_terminal/cryptocurrency/due_diligence/ccxt_view.py @@ -1,6 +1,7 @@ """Ccxt view""" __docformat__ = "numpy" +import logging import os from typing import List, Optional @@ -8,13 +9,17 @@ import numpy as np from openbb_terminal.cryptocurrency.cryptocurrency_helpers import plot_order_book from openbb_terminal.cryptocurrency.due_diligence import ccxt_model +from openbb_terminal.decorators import log_start_end from openbb_terminal.helper_funcs import export_data, print_rich_table +logger = logging.getLogger(__name__) + +@log_start_end(log=logger) def display_order_book( exchange: str, symbol: str, - vs: str, + to_symbol: str, export: str = "", external_axes: Optional[List[plt.Axes]] = None, ): @@ -27,18 +32,23 @@ def display_order_book( exchange id symbol : str coin symbol - vs : str + to_symbol : str currency to compare coin against export : str Export dataframe data to csv,json,xlsx file """ - market_book = ccxt_model.get_orderbook(exchange_id=exchange, symbol=symbol, vs=vs) + market_book = ccxt_model.get_orderbook( + exchange_id=exchange, symbol=symbol, to_symbol=to_symbol + ) 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, f"{exchange.upper()}:{symbol.upper()}/{vs.upper()}", external_axes + bids, + asks, + f"{exchange.upper()}:{symbol.upper()}/{to_symbol.upper()}", + external_axes, ) export_data( @@ -49,8 +59,9 @@ def display_order_book( ) +@log_start_end(log=logger) def display_trades( - exchange: str, symbol: str, vs: str, limit: int = 10, export: str = "" + exchange: str, symbol: str, to_symbol: str, limit: int = 10, export: str = "" ): """Displays trades for a coin in a given exchange [Source: https://docs.ccxt.com/en/latest/manual.html] @@ -61,19 +72,19 @@ def display_trades( exchange id symbol : str coin symbol - vs : str + to_symbol : str currency to compare coin against limit : int number of trades to display export : str Export dataframe data to csv,json,xlsx file """ - df = ccxt_model.get_trades(exchange_id=exchange, symbol=symbol, vs=vs) + df = ccxt_model.get_trades(exchange_id=exchange, symbol=symbol, to_symbol=to_symbol) print_rich_table( df.head(limit), headers=list(df.columns), show_index=False, - title=f"Trades for {exchange.upper()}:{symbol.upper()}/{vs.upper()}", + title=f"Trades for {exchange.upper()}:{symbol.upper()}/{to_symbol.upper()}", ) export_data( diff --git a/openbb_terminal/cryptocurrency/due_diligence/dd_controller.py b/openbb_terminal/cryptocurrency/due_diligence/dd_controller.py index 411f8360493..a8a8fd9a036 100644 --- a/openbb_terminal/cryptocurrency/due_diligence/dd_controller.py +++ b/openbb_terminal/cryptocurrency/due_diligence/dd_controller.py @@ -896,7 +896,7 @@ def call_ob(self, other_args): ccxt_view.display_order_book( ns_parser.exchange, symbol=self.symbol, - vs=ns_parser.vs, + to_symbol=ns_parser.vs, export=ns_parser.export, ) @@ -939,7 +939,7 @@ def call_trades(self, other_args): ccxt_view.display_trades( ns_parser.exchange, symbol=self.symbol, - vs=ns_parser.vs, + to_symbol=ns_parser.vs, export=ns_parser.export, limit=ns_parser.limit, ) diff --git a/openbb_terminal/cryptocurrency/nft/nft_controller.py b/openbb_terminal/cryptocurrency/nft/nft_controller.py index bea640f6444..0e061a2032e 100644 --- a/openbb_terminal/cryptocurrency/nft/nft_controller.py +++ b/openbb_terminal/cryptocurrency/nft/nft_controller.py @@ -169,6 +169,6 @@ def call_collections(self, other_args: List[str]): nftpricefloor_view.display_collections( show_sales=ns_parser.sales, show_fp=ns_parser.fp, - num=ns_parser.limit, + limit=ns_parser.limit, export=ns_parser.export, ) diff --git a/openbb_terminal/cryptocurrency/nft/nftpricefloor_view.py b/openbb_terminal/cryptocurrency/nft/nftpricefloor_view.py index 011e7232643..a96dc3f379a 100644 --- a/openbb_terminal/cryptocurrency/nft/nftpricefloor_view.py +++ b/openbb_terminal/cryptocurrency/nft/nftpricefloor_view.py @@ -25,7 +25,7 @@ @log_start_end(log=logger) def display_collections( - show_fp: bool = False, show_sales: bool = False, num: int = 5, export: str = "" + show_fp: bool = False, show_sales: bool = False, limit: int = 5, export: str = "" ): """Display NFT collections. [Source: https://nftpricefloor.com/] @@ -33,7 +33,7 @@ def display_collections( ---------- show_fp : bool Show NFT Price Floor for top collections - num: int + limit: int Number of NFT collections to display export : str Export dataframe data to csv,json,xlsx file @@ -54,7 +54,7 @@ def display_collections( ] if show_fp or show_sales: _, ax = plt.subplots(figsize=plot_autoscale(), dpi=PLOT_DPI) - for collection in df["slug"].head(num).values: + for collection in df["slug"].head(limit).values: df_collection = nftpricefloor_model.get_floor_price(collection) if not df_collection.empty: values = ( @@ -70,7 +70,7 @@ def display_collections( cfg.theme.visualize_output() print_rich_table( - df.head(num), + df.head(limit), headers=list(df.columns), show_index=False, title="NFT Collections", diff --git a/openbb_terminal/sdk.py b/openbb_terminal/sdk.py index 59d64b80735..d67667941c2 100644 --- a/openbb_terminal/sdk.py +++ b/openbb_terminal/sdk.py @@ -488,9 +488,9 @@ "model": "openbb_terminal.cryptocurrency.due_diligence.binance_view.get_balance", "view": "openbb_terminal.cryptocurrency.due_diligence.binance_view.display_balance", }, - "crypto.dd.book": { - "model": "openbb_terminal.cryptocurrency.due_diligence.binance_view.get_order_book", - "view": "openbb_terminal.cryptocurrency.due_diligence.binance_view.display_order_book", + "crypto.dd.ob": { + "model": "openbb_terminal.cryptocurrency.due_diligence.ccxt_model.get_orderbook", + "view": "openbb_terminal.cryptocurrency.due_diligence.ccxt_view.display_order_book", }, "crypto.dd.show_available_pairs_for_given_symbol": { "model": "openbb_terminal.cryptocurrency.due_diligence.coinbase_model.show_available_pairs_for_given_symbol" @@ -502,17 +502,13 @@ "model": "openbb_terminal.cryptocurrency.due_diligence.coinbase_model.get_candles", "view": "openbb_terminal.cryptocurrency.due_diligence.coinbase_view.display_candles", }, - "crypto.dd.cbbook": { - "model": "openbb_terminal.cryptocurrency.due_diligence.coinbase_model.get_order_book", - "view": "openbb_terminal.cryptocurrency.due_diligence.coinbase_view.display_order_book", - }, "crypto.dd.stats": { "model": "openbb_terminal.cryptocurrency.due_diligence.coinbase_model.get_product_stats", "view": "openbb_terminal.cryptocurrency.due_diligence.coinbase_view.display_stats", }, "crypto.dd.trades": { - "model": "openbb_terminal.cryptocurrency.due_diligence.coinbase_model.get_trades", - "view": "openbb_terminal.cryptocurrency.due_diligence.coinbase_view.display_trades", + "model": "openbb_terminal.cryptocurrency.due_diligence.ccxt_model.get_trades", + "view": "openbb_terminal.cryptocurrency.due_diligence.ccxt_view.display_trades", }, "crypto.dd.trading_pair_info": { "model": "openbb_terminal.cryptocurrency.due_diligence.coinbase_model.get_trading_pair_info" @@ -648,6 +644,14 @@ "model": "openbb_terminal.cryptocurrency.nft.opensea_model.get_collection_stats", "view": "openbb_terminal.cryptocurrency.nft.opensea_view.display_collection_stats", }, + "crypto.nft.fp": { + "model": "openbb_terminal.cryptocurrency.nft.nftpricefloor_model.get_floor_price", + "view": "openbb_terminal.cryptocurrency.nft.nftpricefloor_view.display_floor_price", + }, + "crypto.nft.collections": { + "model": "openbb_terminal.cryptocurrency.nft.nftpricefloor_model.get_collections", + "view": "openbb_terminal.cryptocurrency.nft.nftpricefloor_view.display_collections", + }, "crypto.onchain.dvcp": { "model": "openbb_terminal.cryptocurrency.onchain.bitquery_model.get_daily_dex_volume_for_given_pair", "view": "openbb_terminal.cryptocurrency.onchain.bitquery_view.display_daily_volume_for_given_pair", @@ -1914,6 +1918,7 @@ "crypto.load": { "model": "openbb_terminal.cryptocurrency.cryptocurrency_helpers.load" }, + "crypto.price": {"model": "openbb_terminal.cryptocurrency.pyth_model.get_price"}, "crypto.find": { "model": "openbb_terminal.cryptocurrency.cryptocurrency_helpers.find" },