mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-31 06:22: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>
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
""" opensea.io Model """
|
|
|
|
import logging
|
|
from datetime import datetime
|
|
|
|
import pandas as pd
|
|
import requests
|
|
|
|
from openbb_terminal.decorators import log_start_end
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
API_URL = "https://api.opensea.io/api/v1"
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_collection_stats(slug: str) -> pd.DataFrame:
|
|
"""Get stats of a nft collection [Source: opensea.io]
|
|
|
|
Parameters
|
|
----------
|
|
slug : str
|
|
Opensea collection slug. If the name of the collection is Mutant Ape Yacht Club the slug is mutant-ape-yacht-club
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
collection stats
|
|
"""
|
|
res = requests.get(f"{API_URL}/collection/{slug}")
|
|
if res.status_code == 200:
|
|
data = res.json()
|
|
collection = data["collection"]
|
|
stats = collection["stats"]
|
|
metrics = [
|
|
"Name",
|
|
"Floor Price (ETH)",
|
|
"Number of Owners",
|
|
"Market Cap (ETH)",
|
|
"Average Price ETH",
|
|
"One day volume (ETH)",
|
|
"One day change (%)",
|
|
"One day sales (ETH)",
|
|
"One day average price (ETH)",
|
|
"Thirty day volume (ETH)",
|
|
"Thirty day change (%)",
|
|
"Thirty day sales (ETH)",
|
|
"Thirty day average price (ETH)",
|
|
"Total Supply (ETH)",
|
|
"Total Sales (ETH)",
|
|
"Total Volume (ETH)",
|
|
"Creation Date",
|
|
"URL",
|
|
]
|
|
# T his variable is here because sometimes the created dates also have
|
|
# milliseconds in the string and we dont it, so this just gets the m,d,y,h,m,s
|
|
created_date = collection["created_date"][0:19]
|
|
values = [
|
|
collection["name"],
|
|
"-" if not stats["floor_price"] else float(stats["floor_price"]),
|
|
round(float(stats["num_owners"]), 2),
|
|
round(float(stats["market_cap"]), 2),
|
|
round(float(stats["average_price"]), 2),
|
|
round(float(stats["one_day_volume"]), 2),
|
|
round(float(stats["one_day_change"]) * 100, 2),
|
|
round(float(stats["one_day_sales"]), 2),
|
|
round(float(stats["one_day_average_price"]), 2),
|
|
round(float(stats["thirty_day_volume"]), 2),
|
|
round(float(stats["thirty_day_change"]) * 100, 2),
|
|
round(float(stats["thirty_day_sales"]), 2),
|
|
round(float(stats["thirty_day_average_price"]), 2),
|
|
round(float(stats["total_supply"]), 2),
|
|
round(float(stats["total_sales"]), 2),
|
|
round(float(stats["total_volume"]), 2),
|
|
datetime.strptime(created_date, "%Y-%m-%dT%H:%M:%S").strftime("%b %d, %Y"),
|
|
"-" if not collection["external_url"] else collection["external_url"],
|
|
]
|
|
df = pd.DataFrame({"Metric": metrics, "Value": values})
|
|
return df
|
|
return pd.DataFrame()
|