Simple Python SDK for Hedera DeFi analytics via Hgraph
Project description
Hedera DeFi SDK
Simple Python SDK for accessing Hedera DeFi data via Hedera Mirror Node REST API.
Installation
pip install hedera-defi
Quick Start
from hedera_defi import HederaDeFi
# Initialize client
client = HederaDeFi(api_key="your_hgraph_api_key")
# Get all protocols with >$10k TVL
protocols = client.get_protocols(min_tvl=10000)
for protocol in protocols:
print(f"{protocol.name}: ${protocol.tvl:,.0f}")
# Get whale transactions
whales = client.get_whale_transactions(threshold=100000)
for whale in whales:
print(f"${whale.value_usd:,.0f} {whale.token} moved")
# Get best yield opportunities
yields = client.get_best_yields(min_apy=10.0)
print(yields)
# Get complete DeFi overview
overview = client.get_defi_overview()
print(f"Total TVL: ${overview['total_tvl']:,.0f}")
Features
- 🔍 Protocol Discovery: Automatically find all DeFi protocols on Hedera
- 🐋 Whale Tracking: Monitor large transactions in real-time
- 💰 Yield Analytics: Find the best farming opportunities
- 📊 Risk Metrics: Assess protocol and pool risks
- 📈 TVL History: Track historical TVL data
- 🏊 Pool Analytics: Analyze liquidity pools across all protocols
Main Methods
Protocol Operations
get_protocols(min_tvl, protocol_type, limit)- Get all protocolssearch_protocols(query, search_type)- Search for specific protocolsget_risk_metrics(protocol_id)- Get risk assessment
Token Operations
get_top_tokens(limit, sort_by)- Get top tokens by various metricsget_pools(protocol_id, min_tvl, pool_type)- Get liquidity pools
Whale Tracking
get_whale_transactions(threshold, window_minutes)- Track whale movements
Analytics
get_tvl_history(protocol_id, days, interval)- Historical TVL dataget_best_yields(min_apy, max_risk)- Find yield opportunitiesget_defi_overview()- Complete ecosystem overview
Data Models
All methods return typed dataclass objects:
@dataclass
class Protocol:
contract_id: str
name: str
type: str # 'dex', 'lending', 'staking'
tvl: float
volume_24h: float
users_24h: int
pools: List[str]
tokens: List[str]
created_at: datetime
@dataclass
class WhaleAlert:
timestamp: datetime
type: str
token: str
amount: int
value_usd: float
from_address: str
to_address: str
transaction_hash: str
Advanced Usage
Custom Queries
# Execute custom GraphQL queries
query = """
query MyQuery($limit: Int!) {
token(limit: $limit) {
token_id
name
symbol
}
}
"""
result = client.query(query, {"limit": 10})
Pandas Integration
import pandas as pd
# Get TVL history as DataFrame
tvl_df = client.get_tvl_history(days=30, interval="daily")
# Get yields as DataFrame
yields_df = client.get_best_yields(min_apy=5.0)
# Export to CSV
yields_df.to_csv("hedera_yields.csv", index=False)
Risk Analysis
# Get comprehensive risk metrics
protocols = client.get_protocols(min_tvl=100000)
for protocol in protocols:
risk = client.get_risk_metrics(protocol.contract_id)
if risk.overall_risk == "high":
print(f"⚠️ {protocol.name} has high risk!")
print(f" Concentration: {risk.concentration_risk:.1%}")
print(f" Liquidity: {risk.liquidity_risk:.1%}")
Requirements
- Python 3.8+
- requests
- pandas
- numpy
License
MIT
Support
For issues and questions, please visit: https://github.com/yourusername/hedera-defi-sdk
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
hedera-defi-0.2.0.tar.gz
(14.3 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hedera-defi-0.2.0.tar.gz.
File metadata
- Download URL: hedera-defi-0.2.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dec9d9e45155fcbf772dc4f3652ed2068dec7ec0fcaefeb71ada3933bb1bd871
|
|
| MD5 |
4d2c2e7565ab15ae6d794897abdddf3d
|
|
| BLAKE2b-256 |
13801cde5e189a7b787ac97622631a778cc0822aa8e4d4b5774f47d23ab46e18
|
File details
Details for the file hedera_defi-0.2.0-py3-none-any.whl.
File metadata
- Download URL: hedera_defi-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e714dcb1b2152d61e56f9237decd27e9be0f13034574794f9bb61a404eda289f
|
|
| MD5 |
bff3b8c282e985d0228eff614f0bd8d6
|
|
| BLAKE2b-256 |
9c9abcc2dd19625f08d10f1317d483a6e8bb229d155397cc784c98f54c6c35c4
|