Simple Python SDK for Hedera DeFi analytics via Hgraph
Project description
Hedera DeFi SDK
Simple Python SDK for accessing Hedera DeFi data via Hgraph GraphQL 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.1.0.tar.gz
(12.2 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.1.0.tar.gz.
File metadata
- Download URL: hedera-defi-0.1.0.tar.gz
- Upload date:
- Size: 12.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.7.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ca2d548b88450d6fe587af3cb77dac49d68cdf4fcaa6bbbc189eaa7ce0d6e21d
|
|
| MD5 |
a02cc59c00ad5d0c30b1b6a0011d3fd5
|
|
| BLAKE2b-256 |
bbc5fc070fb5deb0614938a5521ed6794ecb58a62cc9ba603581032fc0f535f5
|
File details
Details for the file hedera_defi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: hedera_defi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.1 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 |
40fe342b9d3029116cc7de357ac7de2148be50194443c7c4e6c50406243fec58
|
|
| MD5 |
4ddb41360f57b780c9afa1427ee71627
|
|
| BLAKE2b-256 |
2af8847f119d40685c68c47927df635b2b293bdfc90ba15f8e5ad6b585f11811
|