mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-01 15:01:18 +00:00
* Fixes * Update stocks_helper.py * update git-actions set-output to new format * Update stocks_helper.py * Update terminal_helper.py * removed LineAnnotateDrawer from qa_view * lint * few changes * updates * sdk auto gen modules done * Update stocks_helper.py * updates to changed imports, and remove first sdk_modules * Update generate_sdk.py * Update generate_sdk.py * pylint * revert stocks_helper * Update generate_sdk.py * Update sdk.py * Update generate_sdk.py * full auto generation, added sdk.py/controllers creation * missed enable forecasting * added running black in subprocess after sdk files generation completes * removed deleted sdk_arg_logger * comment out tests * property doc fix * clean up * Update generate_sdk.py * make trailmap classes useable for doc generation * Update generate_sdk.py * added lineon to trailmap class for linking to func in markdown * changed lineon to dict * added full_path to trailmap for linking in docs * updated portfolio * feat: initial files * feat: added meta head * feat: added funcdef * added func_def to trailmap attributes for markdown in docs, added missing type hints to covid functions * feat: added view and merged with jaun * Update generate_sdk.py * Update generate_sdk.py * Update generate_sdk.py * Update generate_sdk.py * init * fix returns * fix: random stuff * fix: random * fixed encoding issue on windows * fix: generate tabs * update * Update generate_sdk_markdown.py * Create .pydocstyle.ini * added type hint classes for views * fixes * alt, ba * alt-economy * Update finviz_compare_model.py * fixs * Update substack_model.py * Update generate_sdk.py * last of my section * porfolio * po * Update optimizer_model.py * fixing more things * few more * keys done * update * fixes * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * mypy forecast fix * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * fixes * forecast fixes * one more fix * Update coinbase_model.py * Update generate_sdk_markdown.py Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> Co-authored-by: jose-donato <zmcdonato@gmail.com> Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
250 lines
6.9 KiB
Python
250 lines
6.9 KiB
Python
"""DappRadar model"""
|
|
__docformat__ = "numpy"
|
|
|
|
# pylint: disable=C0301,E1137
|
|
from typing import Optional
|
|
import logging
|
|
|
|
import pandas as pd
|
|
import requests
|
|
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.helper_funcs import get_user_agent
|
|
from openbb_terminal.rich_config import console
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
NFT_COLUMNS = [
|
|
"Name",
|
|
"Protocols",
|
|
"Floor Price [$]",
|
|
"Avg Price [$]",
|
|
"Market Cap [$]",
|
|
"Volume [$]",
|
|
]
|
|
|
|
DAPPS_COLUMNS = [
|
|
"Name",
|
|
"Category",
|
|
"Protocols",
|
|
"Daily Users",
|
|
"Daily Volume [$]",
|
|
]
|
|
|
|
DEX_COLUMNS = [
|
|
"Name",
|
|
"Category",
|
|
"Daily Users",
|
|
"Daily Volume [$]",
|
|
]
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def _make_request(url: str, verbose: bool = True) -> Optional[dict]:
|
|
"""Helper method handles dappradar api requests. [Source: https://dappradar.com/]
|
|
|
|
Parameters
|
|
----------
|
|
url: str
|
|
endpoint url
|
|
verbose: bool
|
|
whether to print the text from the response
|
|
|
|
Returns
|
|
-------
|
|
Optional[dict]:
|
|
dictionary with response data
|
|
"""
|
|
|
|
headers = {
|
|
"Accept": "application/json",
|
|
"User-Agent": get_user_agent(),
|
|
"referer": "https://dappradar.com/",
|
|
}
|
|
response = requests.get(url, headers=headers)
|
|
if not 200 <= response.status_code < 300:
|
|
if verbose:
|
|
console.print(f"[red]dappradar api exception: {response.text}[/red]")
|
|
return None
|
|
try:
|
|
return response.json()
|
|
except Exception as e: # noqa: F841
|
|
logger.exception("Invalid Response: %s", str(e))
|
|
if verbose:
|
|
console.print(f"[red]Invalid Response:: {response.text}[/red]")
|
|
return None
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_top_nfts(sortby: str = "", limit: int = 10) -> pd.DataFrame:
|
|
"""Get top nft collections [Source: https://dappradar.com/]
|
|
|
|
Parameters
|
|
----------
|
|
sortby: str
|
|
Key by which to sort data
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
NFTs Columns: Name, Protocols, Floor Price [$], Avg Price [$], Market Cap [$], Volume [$]
|
|
"""
|
|
|
|
response = _make_request(
|
|
"https://nft-sales-service.dappradar.com/v2/collection/day?limit=20&p"
|
|
"age=1¤cy=USD&sort=marketCapInFiat&order=desc"
|
|
)
|
|
if response:
|
|
data = response.get("results")
|
|
df = pd.DataFrame(
|
|
data,
|
|
columns=[
|
|
"name",
|
|
"activeProtocols",
|
|
"floorPriceInFiat",
|
|
"avgPriceInFiat",
|
|
"marketCapInFiat",
|
|
"volumeInFiat",
|
|
],
|
|
)
|
|
|
|
df = df.set_axis(
|
|
NFT_COLUMNS,
|
|
axis=1,
|
|
copy=False,
|
|
)
|
|
df["Protocols"] = df["Protocols"].apply(lambda x: ",".join(x))
|
|
if sortby in NFT_COLUMNS:
|
|
df = df.sort_values(by=sortby, ascending=False)
|
|
return df.head(limit)
|
|
return pd.DataFrame()
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_top_dexes(sortby: str = "", limit: int = 10) -> pd.DataFrame:
|
|
"""Get top dexes by daily volume and users [Source: https://dappradar.com/]
|
|
|
|
Parameters
|
|
----------
|
|
sortby: str
|
|
Key by which to sort data
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
Top decentralized exchanges. Columns: Name, Daily Users, Daily Volume [$]
|
|
"""
|
|
data = _make_request(
|
|
"https://dappradar.com/v2/api/dapps?params=WkdGd2NISmhaR0Z5Y0dGblpUMHhKbk5uY205MWNEMXR"
|
|
"ZWGdtWTNWeWNtVnVZM2s5VlZORUptWmxZWFIxY21Wa1BURW1jbUZ1WjJVOVpHRjVKbU5oZEdWbmIzSjVQV1Y0WTJ"
|
|
"oaGJtZGxjeVp6YjNKMFBYUnZkR0ZzVm05c2RXMWxTVzVHYVdGMEptOXlaR1Z5UFdSbGMyTW1iR2x0YVhROU1qWT0="
|
|
)
|
|
if data:
|
|
arr = [
|
|
[
|
|
dex["name"],
|
|
dex["category"],
|
|
dex["statistic"]["userActivity"],
|
|
dex["statistic"]["totalVolumeInFiat"],
|
|
]
|
|
for dex in data["dapps"]
|
|
]
|
|
|
|
df = pd.DataFrame(arr, columns=DEX_COLUMNS)
|
|
if sortby in DEX_COLUMNS:
|
|
df = df.sort_values(by=sortby, ascending=False)
|
|
df = df[df["Category"] == "exchanges"]
|
|
if df.empty:
|
|
return pd.DataFrame()
|
|
df.drop("Category", axis=1, inplace=True)
|
|
return df.head(limit)
|
|
return pd.DataFrame()
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_top_games(sortby: str = "", limit: int = 10) -> pd.DataFrame:
|
|
"""Get top blockchain games by daily volume and users [Source: https://dappradar.com/]
|
|
|
|
Parameters
|
|
----------
|
|
limit: int
|
|
Number of records to display
|
|
sortby: str
|
|
Key by which to sort data
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
Top blockchain games. Columns: Name, Daily Users, Daily Volume [$]
|
|
"""
|
|
data = _make_request(
|
|
"https://dappradar.com/v2/api/dapps?params=WkdGd2NISmhaR0Z5Y0dGblpUMHhKbk5uY205MWNEMX"
|
|
"RZWGdtWTNWeWNtVnVZM2s5VlZORUptWmxZWFIxY21Wa1BURW1jbUZ1WjJVOVpHRjVKbU5oZEdWbmIzSjVQV2R"
|
|
"oYldWekpuTnZjblE5ZFhObGNpWnZjbVJsY2oxa1pYTmpKbXhwYldsMFBUSTI="
|
|
)
|
|
if data:
|
|
arr = [
|
|
[
|
|
dex["name"],
|
|
dex["category"],
|
|
dex["statistic"]["userActivity"],
|
|
dex["statistic"]["totalVolumeInFiat"],
|
|
]
|
|
for dex in data["dapps"]
|
|
]
|
|
|
|
df = pd.DataFrame(
|
|
arr,
|
|
columns=DEX_COLUMNS,
|
|
).sort_values("Daily Users", ascending=False)
|
|
if sortby in df.columns:
|
|
df = df.sort_values(by=sortby, ascending=False)
|
|
df = df[df["Category"] == "games"]
|
|
df.drop("Category", axis=1, inplace=True)
|
|
return df.head(limit)
|
|
return pd.DataFrame()
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_top_dapps(sortby: str = "", limit: int = 10) -> pd.DataFrame:
|
|
"""Get top decentralized applications by daily volume and users [Source: https://dappradar.com/]
|
|
|
|
Parameters
|
|
----------
|
|
sortby: str
|
|
Key by which to sort data
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
Top decentralized exchanges.
|
|
Columns: Name, Category, Protocols, Daily Users, Daily Volume [$]
|
|
"""
|
|
data = _make_request(
|
|
"https://dappradar.com/v2/api/dapps?params=WkdGd2NISmhaR0Z5Y0dGblpUMHhKbk5uY205MWNEMX"
|
|
"RZWGdtWTNWeWNtVnVZM2s5VlZORUptWmxZWFIxY21Wa1BURW1jbUZ1WjJVOVpHRjVKbk52Y25ROWRYTmxjaVp"
|
|
"2Y21SbGNqMWtaWE5qSm14cGJXbDBQVEky",
|
|
False,
|
|
)
|
|
if data:
|
|
arr = [
|
|
[
|
|
dex["name"],
|
|
dex["category"],
|
|
dex["activeProtocols"],
|
|
dex["statistic"]["userActivity"],
|
|
dex["statistic"]["totalVolumeInFiat"],
|
|
]
|
|
for dex in data["dapps"]
|
|
]
|
|
|
|
df = pd.DataFrame(
|
|
arr,
|
|
columns=DAPPS_COLUMNS,
|
|
).sort_values("Daily Users", ascending=False)
|
|
df["Protocols"] = df["Protocols"].apply(lambda x: ",".join(x))
|
|
if sortby in DAPPS_COLUMNS:
|
|
df = df.sort_values(by=sortby, ascending=False)
|
|
return df.head(limit)
|
|
return pd.DataFrame()
|