mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-13 21:02:13 +00:00
* added statistics for opensea collection feature * trying to fix json error * trying to fix json error * fixing vcr tests * print to include 2 decimal cases * fixing tests * added to script, date format and require * fix: linting
73 lines
2.5 KiB
Python
73 lines
2.5 KiB
Python
""" opensea.io Model """
|
|
|
|
from datetime import datetime
|
|
import requests
|
|
import pandas as pd
|
|
|
|
API_URL = "https://api.opensea.io/api/v1"
|
|
|
|
|
|
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",
|
|
]
|
|
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(
|
|
collection["created_date"], "%Y-%m-%dT%H:%M:%S.%f"
|
|
).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()
|