mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-09 10:51:57 +00:00
Fixed bugs and set load default source as cp (#1482)
This commit is contained in:
@@ -241,7 +241,7 @@ def _create_closest_match_df(
|
||||
# TODO: verify vs, interval, days, depending on source
|
||||
def load(
|
||||
coin: str,
|
||||
source: str = "cg",
|
||||
source: str = "cp",
|
||||
days: int = 60,
|
||||
vs: str = "usd",
|
||||
interval: str = "1day",
|
||||
@@ -285,6 +285,10 @@ def load(
|
||||
|
||||
if source == "cg":
|
||||
coingecko = pycoingecko_model.Coin(coin.lower(), True)
|
||||
|
||||
if not coingecko.symbol:
|
||||
return None, None, None, None, None, None
|
||||
|
||||
coin_map_df = coins_map_df.loc[coingecko.symbol]
|
||||
coin_map_df = (
|
||||
coin_map_df.iloc[0]
|
||||
@@ -321,6 +325,10 @@ def load(
|
||||
paprika_coins = get_list_of_coins()
|
||||
paprika_coins_dict = dict(zip(paprika_coins.id, paprika_coins.symbol))
|
||||
current_coin, symbol = coinpaprika_model.validate_coin(coin, paprika_coins_dict)
|
||||
|
||||
if not symbol:
|
||||
return None, None, None, None, None, None
|
||||
|
||||
coin_map_df = coins_map_df.loc[symbol.lower() if symbol is not None else symbol]
|
||||
coin_map_df = (
|
||||
coin_map_df.iloc[0]
|
||||
|
||||
@@ -330,7 +330,7 @@ def get_tickers_info_for_coin(
|
||||
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def validate_coin(coin: str, coins_dct: dict) -> Tuple[str, Optional[Any]]:
|
||||
def validate_coin(coin: str, coins_dct: dict) -> Tuple[Optional[Any], Optional[Any]]:
|
||||
"""Helper method that validates if proper coin id or symbol was provided [Source: CoinPaprika]
|
||||
|
||||
Parameters
|
||||
@@ -357,8 +357,8 @@ def validate_coin(coin: str, coins_dct: dict) -> Tuple[str, Optional[Any]]:
|
||||
symbol = value
|
||||
|
||||
if not coin_found:
|
||||
raise ValueError(f"Could not find coin with given id: {coin}\n")
|
||||
# console.print(f"Coin found : {coin_found} with symbol {symbol}\n")
|
||||
console.print(f"[red]Could not find coin with given id: {coin}\n[/red]")
|
||||
return None, None
|
||||
return coin_found, symbol
|
||||
|
||||
|
||||
|
||||
@@ -243,10 +243,15 @@ class Coin:
|
||||
self._coin_list = self.client.get_coins_list()
|
||||
else:
|
||||
self._coin_list = read_file_data("coingecko_coins.json")
|
||||
|
||||
self.coin_symbol, self.symbol = self._validate_coin(symbol)
|
||||
|
||||
if self.coin_symbol:
|
||||
self.coin: Dict[Any, Any] = self._get_coin_info()
|
||||
else:
|
||||
console.print(
|
||||
f"[red]Could not find coin with the given id: {symbol}\n[/red]"
|
||||
)
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def __str__(self):
|
||||
@@ -279,7 +284,7 @@ class Coin:
|
||||
coin = dct.get("id")
|
||||
symbol = dct.get("symbol")
|
||||
return coin, symbol
|
||||
raise ValueError(f"Could not find coin with the given id: {search_coin}\n")
|
||||
return None, None
|
||||
|
||||
@log_start_end(log=logger)
|
||||
def coin_list(self) -> list:
|
||||
|
||||
@@ -509,7 +509,7 @@ class CryptoBaseController(BaseController, metaclass=ABCMeta):
|
||||
help="Source of data",
|
||||
dest="source",
|
||||
choices=("cp", "cg", "bin", "cb"),
|
||||
default="cg",
|
||||
default="cp",
|
||||
required=False,
|
||||
)
|
||||
parser.add_argument(
|
||||
|
||||
Reference in New Issue
Block a user