- Create a virtual environment:
python -m venv opensea-venv
source opensea-venv/bin/activate # On Windows: opensea-venv\Scripts\activate
- Install the package:
pip install opensea-transaction-retriever
- Get an API key from OpenSea
- Set it as an environment variable:
export API_KEY=your_api_key
Or use it directly in code:
client = OpenSeaClient(api_key="your_api_key")
from opensea_transaction_retriever import OpenSeaClient
from datetime import datetime, timedelta
# Initialize client
client = OpenSeaClient()
# Set time range
end_time = datetime.now()
start_time = end_time - timedelta(days=7)
# Format times
t_before = end_time.strftime('%Y-%m-%d %H:%M:%S')
t_after = start_time.strftime('%Y-%m-%d %H:%M:%S')
# Fetch transactions
transactions = client.get_collection_transactions(
collection_slug="boredapeyachtclub",
t_before=t_before,
t_after=t_after
)
# Get collection traits
collection = client.get_collection("boredapeyachtclub")
# Calculate rarity scores
trait_rarity = client.calculate_collection_rarity("boredapeyachtclub")
# Visualize trait distribution
from opensea_transaction_retriever.visualization import plot_trait_distribution
plot_trait_distribution(trait_rarity, "Background")
from opensea_transaction_retriever.visualization import (
plot_price_history,
plot_volume_over_time,
plot_price_distribution
)
# Plot price history
plot_price_history(transactions, title="BAYC Price History")
# Plot trading volume
plot_volume_over_time(transactions, interval='D')
# Plot price distribution
plot_price_distribution(transactions, bins=50)
from opensea_transaction_retriever.visualization import (
plot_trait_distribution,
plot_rarity_scores,
plot_trait_correlation
)
# Plot trait distributions
plot_trait_distribution(trait_rarity, "Background")
# Plot rarity scores
plot_rarity_scores(trait_rarity, "Background")
# Plot trait-price correlation
plot_trait_correlation(transactions, "Background")
-
Rate Limiting: The client handles rate limiting automatically, but be mindful of API limits
-
Data Storage: Save raw data for later analysis:
transactions = client.get_collection_transactions(
collection_slug="boredapeyachtclub",
t_before=t_before,
t_after=t_after,
save_to_file="transactions.json"
)
-
Error Handling: The client includes retry logic for failed requests
-
Resource Management: Use context managers:
with OpenSeaClient() as client:
transactions = client.get_collection_transactions(...)
- API Key Issues
# Check if API key is set
import os
print("API key is set:", bool(os.getenv("API_KEY")))
-
Rate Limiting The client automatically handles rate limiting with exponential backoff
-
Data Processing Use pandas for advanced analysis:
import pandas as pd
df = pd.DataFrame([t.__dict__ for t in transactions])