3
3
[ ![ PyPI version] ( https://badge.fury.io/py/divine-thegraph-token-api.svg )] ( https://badge.fury.io/py/divine-thegraph-token-api )
4
4
[ ![ Python versions] ( https://img.shields.io/pypi/pyversions/divine-thegraph-token-api.svg )] ( https://pypi.org/project/divine-thegraph-token-api/ )
5
5
[ ![ License: MIT] ( https://img.shields.io/badge/License-MIT-yellow.svg )] ( https://opensource.org/licenses/MIT )
6
- [ ![ Test Coverage] ( https://img.shields.io/badge/coverage-90 %25+ -brightgreen.svg )] ( https://github.com/divinescreener/thegraph-token-api )
6
+ [ ![ Test Coverage] ( https://img.shields.io/badge/coverage-100 %25-brightgreen.svg )] ( https://github.com/divinescreener/thegraph-token-api )
7
7
[ ![ Code style: ruff] ( https://img.shields.io/badge/code%20style-ruff-000000.svg )] ( https://github.com/astral-sh/ruff )
8
8
9
9
A powerful Python client for The Graph Token API that brings blockchain data to your fingertips. Access token balances, NFT ownership, DeFi swaps, and price histories across Ethereum, Solana, and 8+ other chains with an elegant, type-safe interface.
@@ -45,8 +45,11 @@ balances = await api.evm.balances(wallet_address)
45
45
# That's it! Fully typed, validated, and ready to use
46
46
47
47
# NEW: Unified Price API (convenience feature - not an API endpoint)
48
- eth_price = await api.price.get(Currency.ETH ) # Uses DEX swap data internally
49
- sol_price = await api.price.get(Currency.SOL ) # Calculates from API data
48
+ eth_price = await api.price.get(Currency.ETH ) # $3,873+ from Ethereum DEX swaps
49
+ sol_price = await api.price.get(Currency.SOL ) # $192+ from Solana DEX swaps
50
+ pol_price = await api.price.get(Currency.POL ) # $0.22 from Polygon network
51
+ bnb_price = await api.price.get(Currency.BNB ) # $845+ from BSC network
52
+ avax_price = await api.price.get(Currency.AVAX ) # $26+ from Avalanche network
50
53
```
51
54
52
55
## ✨ Features
@@ -58,7 +61,7 @@ sol_price = await api.price.get(Currency.SOL) # Calculates from API data
58
61
- 🛡️ ** Type Safety** : Full type hints with runtime validation
59
62
- 🔄 ** Smart Defaults** : Auto-loads API keys, sensible limits, mainnet defaults
60
63
- 📈 ** Time-Series Data** : Historical prices and time-filtered swap data
61
- - 💰 ** Unified Price API** : Convenience feature for current crypto prices (uses API data internally )
64
+ - 💰 ** Unified Price API** : Real-time prices for 5 major cryptocurrencies (ETH, SOL, POL, BNB, AVAX )
62
65
- 🎯 ** Developer Friendly** : Clean API, great docs, extensive examples
63
66
64
67
## 📦 Installation
@@ -111,13 +114,19 @@ async def main():
111
114
if token[" balance" ] > 0 :
112
115
print (f " { token[' symbol' ]} : { token[' balance' ]} ($ { token[' value_usd' ]:,.2f } ) " )
113
116
114
- # Get current cryptocurrency prices (convenience feature)
115
- eth_price = await api.price.get(Currency.ETH )
116
- sol_price = await api.price.get(Currency.SOL )
117
+ # Get current cryptocurrency prices (5 major currencies supported)
118
+ eth_price = await api.price.get(Currency.ETH ) # ~$3,873
119
+ sol_price = await api.price.get(Currency.SOL ) # ~$192
120
+ pol_price = await api.price.get(Currency.POL ) # ~$0.22
121
+ bnb_price = await api.price.get(Currency.BNB ) # ~$845
122
+ avax_price = await api.price.get(Currency.AVAX ) # ~$26
117
123
118
124
print (f " \n Current Prices: " )
119
125
print (f " ETH: $ { eth_price:.2f } " ) if eth_price else print (" ETH: unavailable" )
120
126
print (f " SOL: $ { sol_price:.2f } " ) if sol_price else print (" SOL: unavailable" )
127
+ print (f " POL: $ { pol_price:.2f } " ) if pol_price else print (" POL: unavailable" )
128
+ print (f " BNB: $ { bnb_price:.2f } " ) if bnb_price else print (" BNB: unavailable" )
129
+ print (f " AVAX: $ { avax_price:.2f } " ) if avax_price else print (" AVAX: unavailable" )
121
130
122
131
# Get detailed price statistics
123
132
eth_stats = await api.price.get(Currency.ETH , include_stats = True )
@@ -145,8 +154,11 @@ await api.svm.transfers(mint=...) # Get token transfers
145
154
await api.svm.swaps(program_id = ... ) # Get DEX swaps
146
155
147
156
# Unified Price API (convenience feature - uses API data internally)
148
- await api.price.get(Currency.ETH ) # Get current ETH price from DEX swaps
149
- await api.price.get(Currency.SOL ) # Get current SOL price from DEX swaps
157
+ await api.price.get(Currency.ETH ) # Get current ETH price from Ethereum DEX swaps
158
+ await api.price.get(Currency.SOL ) # Get current SOL price from Solana DEX swaps
159
+ await api.price.get(Currency.POL ) # Get current POL price from Polygon network
160
+ await api.price.get(Currency.BNB ) # Get current BNB price from BSC network
161
+ await api.price.get(Currency.AVAX ) # Get current AVAX price from Avalanche network
150
162
```
151
163
152
164
### Smart Organization
@@ -163,10 +175,13 @@ api.evm.nfts.activities(contract) # Recent NFT activities
163
175
api.evm.pools(token = address) # Find liquidity pools
164
176
api.evm.pool_history(pool, " 1h" ) # Get pool metrics over time
165
177
166
- # Price operations (convenience feature)
167
- api.price.get(Currency.ETH ) # Current ETH price from DEX data
168
- api.price.get(Currency.SOL ) # Current SOL price from DEX data
169
- api.price.get_supported_currencies() # List available currencies
178
+ # Price operations (5 major cryptocurrencies)
179
+ api.price.get(Currency.ETH ) # Current ETH price (~$3,873)
180
+ api.price.get(Currency.SOL ) # Current SOL price (~$192)
181
+ api.price.get(Currency.POL ) # Current POL price (~$0.22)
182
+ api.price.get(Currency.BNB ) # Current BNB price (~$845)
183
+ api.price.get(Currency.AVAX ) # Current AVAX price (~$26)
184
+ api.price.get_supported_currencies() # List all 5 supported currencies
170
185
```
171
186
172
187
## 🔥 Usage Examples
@@ -262,20 +277,25 @@ async def monitor_solana_swaps():
262
277
from thegraph_token_api import TokenAPI, Currency
263
278
264
279
# The Unified Price API is a convenience feature that uses DEX swap data
265
- # internally to calculate current cryptocurrency prices
280
+ # internally to calculate current cryptocurrency prices for 5 major currencies
266
281
async def get_current_prices ():
267
282
api = TokenAPI()
268
283
269
- # Simple price queries using Currency enum (type-safe)
270
- eth_price = await api.price.get(Currency.ETH )
271
- sol_price = await api.price.get(Currency.SOL )
284
+ # Simple price queries using Currency enum (type-safe, enum-only interface)
285
+ eth_price = await api.price.get(Currency.ETH ) # ~$3,873
286
+ sol_price = await api.price.get(Currency.SOL ) # ~$192
287
+ pol_price = await api.price.get(Currency.POL ) # ~$0.22
288
+ bnb_price = await api.price.get(Currency.BNB ) # ~$845
289
+ avax_price = await api.price.get(Currency.AVAX ) # ~$26
272
290
273
291
print (f " ETH: $ { eth_price:.2f } " if eth_price else " ETH: unavailable" )
274
292
print (f " SOL: $ { sol_price:.2f } " if sol_price else " SOL: unavailable" )
293
+ print (f " POL: $ { pol_price:.2f } " if pol_price else " POL: unavailable" )
294
+ print (f " BNB: $ { bnb_price:.2f } " if bnb_price else " BNB: unavailable" )
295
+ print (f " AVAX: $ { avax_price:.2f } " if avax_price else " AVAX: unavailable" )
275
296
276
- # Also works with strings (case-insensitive)
277
- eth_price_str = await api.price.get(" eth" )
278
- sol_price_str = await api.price.get(" SOL" )
297
+ # NOTE : String support has been removed - only Currency enum is supported
298
+ # This ensures type safety and eliminates runtime errors
279
299
280
300
# Get detailed statistics with confidence metrics
281
301
eth_stats = await api.price.get(Currency.ETH , include_stats = True )
@@ -429,10 +449,12 @@ Access via `api.price` - provides unified cryptocurrency prices.
429
449
** Note:** This is a convenience feature that uses the API ' s DEX swap data internally to calculate prices. It is not a separate API endpoint.
430
450
431
451
```python
432
- # Simple price queries
433
- await api.price.get(Currency.ETH ) # Current ETH price
434
- await api.price.get(Currency.SOL ) # Current SOL price
435
- await api.price.get(" ETH" ) # Also works with strings
452
+ # Simple price queries (enum-only interface)
453
+ await api.price.get(Currency.ETH ) # Current ETH price (~$3,873)
454
+ await api.price.get(Currency.SOL ) # Current SOL price (~$192)
455
+ await api.price.get(Currency.POL ) # Current POL price (~$0.22)
456
+ await api.price.get(Currency.BNB ) # Current BNB price (~$845)
457
+ await api.price.get(Currency.AVAX ) # Current AVAX price (~$26)
436
458
437
459
# Detailed statistics
438
460
autostats = await api.price.get(Currency.ETH , include_stats = True )
@@ -490,10 +512,12 @@ SwapPrograms.ORCA
490
512
SwapPrograms.JUPITER
491
513
SwapPrograms.PUMP_FUN
492
514
493
- # Supported currencies for Unified Price API
494
- Currency.ETH # Ethereum
495
- Currency.SOL # Solana
496
- # More currencies coming soon...
515
+ # Supported currencies for Unified Price API (5 major cryptocurrencies)
516
+ Currency.ETH # Ethereum (~$3,873)
517
+ Currency.SOL # Solana (~$192)
518
+ Currency.POL # Polygon (~$0.22)
519
+ Currency.BNB # BNB Chain (~$845)
520
+ Currency.AVAX # Avalanche (~$26)
497
521
```
498
522
499
523
### Error Handling
@@ -624,8 +648,8 @@ thegraph-token-api/
624
648
We welcome contributions! Please see our [ Contributing Guidelines] ( CONTRIBUTING.md ) .
625
649
626
650
Key requirements:
627
- - Maintain >90 % test coverage
628
- - Follow the existing code style
651
+ - Maintain 100 % test coverage (382 tests currently passing)
652
+ - Follow the existing code style (ruff + mypy strict mode)
629
653
- Add tests for new features
630
654
- Update documentation
631
655
@@ -639,6 +663,8 @@ The client is optimized for production use:
639
663
- ** Batch Support** : Efficient multi-request handling
640
664
- ** Statistical Analysis** : Median pricing with IQR outlier filtering
641
665
- ** Progressive Retry** : Adaptive sampling for reliable price data
666
+ - ** 100% Test Coverage** : 382 tests ensuring production reliability
667
+ - ** Multi-Chain Architecture** : Unified EVM approach for scalability
642
668
643
669
### Unified Price API Performance
644
670
0 commit comments