Skip to content

Commit

Permalink
Adds crypto features missing in SDK (#2989)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
Co-authored-by: Colin Delahunty <[email protected]>
Co-authored-by: minhhoang1023 <[email protected]>
  • Loading branch information
4 people authored Nov 1, 2022
1 parent 520a5fe commit 9b05c15
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 30 deletions.
12 changes: 6 additions & 6 deletions openbb_terminal/cryptocurrency/due_diligence/ccxt_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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)
Expand Down
27 changes: 19 additions & 8 deletions openbb_terminal/cryptocurrency/due_diligence/ccxt_view.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
"""Ccxt view"""
__docformat__ = "numpy"

import logging
import os
from typing import List, Optional

from matplotlib import pyplot as plt
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,
):
Expand All @@ -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(
Expand All @@ -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]
Expand All @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions openbb_terminal/cryptocurrency/due_diligence/dd_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)

Expand Down Expand Up @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion openbb_terminal/cryptocurrency/nft/nft_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
8 changes: 4 additions & 4 deletions openbb_terminal/cryptocurrency/nft/nftpricefloor_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

@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/]
Parameters
----------
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
Expand All @@ -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 = (
Expand All @@ -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",
Expand Down
23 changes: 14 additions & 9 deletions openbb_terminal/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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"
},
Expand Down

0 comments on commit 9b05c15

Please sign in to comment.