@@ -38,11 +38,15 @@ if response.status_code == 200:
38
38
# Parse nested structures, handle errors...
39
39
40
40
# With this client - Clean and simple ✨
41
- from thegraph_token_api import TokenAPI
41
+ from thegraph_token_api import TokenAPI, Currency
42
42
43
43
api = TokenAPI()
44
44
balances = await api.evm.balances(wallet_address)
45
45
# That's it! Fully typed, validated, and ready to use
46
+
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
46
50
```
47
51
48
52
## ✨ Features
@@ -54,6 +58,7 @@ balances = await api.evm.balances(wallet_address)
54
58
- 🛡️ ** Type Safety** : Full type hints with runtime validation
55
59
- 🔄 ** Smart Defaults** : Auto-loads API keys, sensible limits, mainnet defaults
56
60
- 📈 ** Time-Series Data** : Historical prices and time-filtered swap data
61
+ - 💰 ** Unified Price API** : Convenience feature for current crypto prices (uses API data internally)
57
62
- 🎯 ** Developer Friendly** : Clean API, great docs, extensive examples
58
63
59
64
## 📦 Installation
@@ -106,12 +111,18 @@ async def main():
106
111
if token[" balance" ] > 0 :
107
112
print (f " { token[' symbol' ]} : { token[' balance' ]} ($ { token[' value_usd' ]:,.2f } ) " )
108
113
109
- # Get Solana NFTs
110
- sol_nfts = await api.svm.balances(
111
- mint = " So11111111111111111111111111111111111111112"
112
- )
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
+
118
+ print (f " \n Current Prices: " )
119
+ print (f " ETH: $ { eth_price:.2f } " ) if eth_price else print (" ETH: unavailable" )
120
+ print (f " SOL: $ { sol_price:.2f } " ) if sol_price else print (" SOL: unavailable" )
113
121
114
- print (f " \n Found { len (sol_nfts)} Solana NFT holders " )
122
+ # Get detailed price statistics
123
+ eth_stats = await api.price.get(Currency.ETH , include_stats = True )
124
+ if eth_stats:
125
+ print (f " ETH confidence: { eth_stats[' confidence' ]:.0% } (from { eth_stats[' trades_analyzed' ]} trades) " )
115
126
116
127
anyio.run(main)
117
128
```
@@ -132,6 +143,10 @@ await api.evm.swaps(protocol=...) # Get DEX swaps
132
143
await api.svm.balances(mint = ... ) # Get SPL token holders
133
144
await api.svm.transfers(mint = ... ) # Get token transfers
134
145
await api.svm.swaps(program_id = ... ) # Get DEX swaps
146
+
147
+ # 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
135
150
```
136
151
137
152
### Smart Organization
@@ -147,6 +162,11 @@ api.evm.nfts.activities(contract) # Recent NFT activities
147
162
# Pool operations grouped together
148
163
api.evm.pools(token = address) # Find liquidity pools
149
164
api.evm.pool_history(pool, " 1h" ) # Get pool metrics over time
165
+
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
150
170
```
151
171
152
172
## 🔥 Usage Examples
@@ -236,6 +256,46 @@ async def monitor_solana_swaps():
236
256
f " { datetime.fromtimestamp(swap[' timestamp' ])} " )
237
257
```
238
258
259
+ ### Unified Price API (Convenience Feature)
260
+
261
+ ``` python
262
+ from thegraph_token_api import TokenAPI, Currency
263
+
264
+ # The Unified Price API is a convenience feature that uses DEX swap data
265
+ # internally to calculate current cryptocurrency prices
266
+ async def get_current_prices ():
267
+ api = TokenAPI()
268
+
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 )
272
+
273
+ print (f " ETH: $ { eth_price:.2f } " if eth_price else " ETH: unavailable" )
274
+ print (f " SOL: $ { sol_price:.2f } " if sol_price else " SOL: unavailable" )
275
+
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" )
279
+
280
+ # Get detailed statistics with confidence metrics
281
+ eth_stats = await api.price.get(Currency.ETH , include_stats = True )
282
+ if eth_stats:
283
+ print (f " \n ETH Detailed Analysis: " )
284
+ print (f " Price: $ { eth_stats[' price' ]:.2f } " )
285
+ print (f " Confidence: { eth_stats[' confidence' ]:.0% } " )
286
+ print (f " Trades analyzed: { eth_stats[' trades_analyzed' ]} " )
287
+ print (f " Volatility: $ { eth_stats[' std_deviation' ]:.2f } " )
288
+ print (f " Range: $ { eth_stats[' min_price' ]:.2f } - $ { eth_stats[' max_price' ]:.2f } " )
289
+
290
+ # Check supported currencies
291
+ supported = await api.price.get_supported_currencies()
292
+ print (f " \n Supported currencies: { [c.value for c in supported]} " )
293
+
294
+ # Cache management
295
+ await api.price.clear_cache(Currency.ETH ) # Clear specific currency
296
+ await api.price.clear_cache() # Clear all cache
297
+ ```
298
+
239
299
### Price History Analysis
240
300
241
301
``` python
@@ -329,6 +389,11 @@ The main entry point for all API operations.
329
389
``` python
330
390
api = TokenAPI(api_key: Optional[str ] = None )
331
391
# If api_key is None, loads from THEGRAPH_API_KEY env var
392
+
393
+ # Access different interfaces
394
+ api.evm # EVM chain operations
395
+ api.svm # Solana operations
396
+ api.price # Unified Price API (convenience feature)
332
397
```
333
398
334
399
#### ` EVMInterface `
@@ -356,6 +421,32 @@ await api.evm.pool_history(pool: str, interval: str)
356
421
357
422
# Transfers
358
423
await api.evm.transfers(from_address: str = None , to_address: str = None )
424
+
425
+ # ### `UnifiedPriceAPI` (Convenience Feature)
426
+
427
+ Access via `api.price` - provides unified cryptocurrency prices.
428
+
429
+ ** 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
+
431
+ ```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
436
+
437
+ # Detailed statistics
438
+ autostats = await api.price.get(Currency.ETH , include_stats = True )
439
+ # Returns: {"price": 3500.0, "confidence": 0.9, "trades_analyzed": 15, ...}
440
+
441
+ # Utility methods
442
+ await api.price.get_supported_currencies() # List[Currency]
443
+ await api.price.is_supported(Currency.ETH ) # bool
444
+ await api.price.clear_cache(Currency.ETH ) # Clear specific cache
445
+ await api.price.clear_cache() # Clear all cache
446
+
447
+ # Force refresh (bypass cache)
448
+ await api.price.get(Currency.ETH , force_refresh = True )
449
+ ```
359
450
```
360
451
361
452
#### `SVMInterface`
@@ -379,7 +470,7 @@ await api.svm.swaps(
379
470
### Enums
380
471
381
472
``` python
382
- from thegraph_token_api import Chain, Protocol, SwapPrograms
473
+ from thegraph_token_api import Chain, Protocol, SwapPrograms, Currency
383
474
384
475
# EVM chains
385
476
Chain.ETHEREUM
@@ -398,6 +489,11 @@ SwapPrograms.RAYDIUM
398
489
SwapPrograms.ORCA
399
490
SwapPrograms.JUPITER
400
491
SwapPrograms.PUMP_FUN
492
+
493
+ # Supported currencies for Unified Price API
494
+ Currency.ETH # Ethereum
495
+ Currency.SOL # Solana
496
+ # More currencies coming soon...
401
497
```
402
498
403
499
### Error Handling
@@ -539,8 +635,20 @@ The client is optimized for production use:
539
635
540
636
- ** Connection Pooling** : Reuses HTTP connections
541
637
- ** Async Operations** : Non-blocking I/O for high throughput
542
- - ** Smart Caching** : SOL price caching reduces API calls
638
+ - ** Smart Caching** : Unified Price API with volatility-based TTL
543
639
- ** Batch Support** : Efficient multi-request handling
640
+ - ** Statistical Analysis** : Median pricing with IQR outlier filtering
641
+ - ** Progressive Retry** : Adaptive sampling for reliable price data
642
+
643
+ ### Unified Price API Performance
644
+
645
+ The Unified Price API uses advanced techniques for reliable pricing:
646
+
647
+ - ** Volatility-Based Caching** : Shorter cache (60s) during high volatility, longer (300s) during stable periods
648
+ - ** Multi-Source Aggregation** : Uses recent DEX swap data from multiple sources
649
+ - ** Statistical Robustness** : Median prices with outlier filtering prevent manipulation
650
+ - ** Confidence Scoring** : Returns confidence metrics based on sample size and data quality
651
+ - ** Smart Retries** : Progressive retry with increasing sample sizes for reliable data
544
652
545
653
## 🔒 Security
546
654
0 commit comments