File size: 27,109 Bytes
b190b45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
#!/usr/bin/env python3
"""

New Providers Registry - Additional Free Data Sources

رجیستری جدید برای منابع داده رایگان اضافی

"""

import aiohttp
import asyncio
from typing import Dict, List, Any, Optional
from dataclasses import dataclass
from enum import Enum
from datetime import datetime
import feedparser


class ProviderType(Enum):
    """نوع سرویس‌دهنده"""
    OHLCV = "ohlcv"
    NEWS = "news"
    ONCHAIN = "onchain"
    SOCIAL = "social"
    DEFI = "defi"
    TECHNICAL = "technical"


@dataclass
class ProviderInfo:
    """اطلاعات سرویس‌دهنده"""
    id: str
    name: str
    type: str
    url: str
    description: str
    free: bool
    requires_key: bool
    rate_limit: str
    features: List[str]
    verified: bool


class NewProvidersRegistry:
    """

    رجیستری جدید برای سرویس‌دهندگان داده

    Registry of 50+ new free data providers

    """
    
    def __init__(self):
        self.providers = self._load_providers()
    
    def _load_providers(self) -> Dict[str, ProviderInfo]:
        """بارگذاری سرویس‌دهندگان"""
        return {
            # ===== NEW OHLCV PROVIDERS =====
            
            "coinranking": ProviderInfo(
                id="coinranking",
                name="CoinRanking",
                type=ProviderType.OHLCV.value,
                url="https://api.coinranking.com/v2",
                description="3000+ coins, real-time prices",
                free=True,
                requires_key=False,  # Has free tier
                rate_limit="10 req/sec",
                features=["prices", "history", "markets", "exchanges"],
                verified=False
            ),
            
            "coincap_v2": ProviderInfo(
                id="coincap_v2",
                name="CoinCap API v2",
                type=ProviderType.OHLCV.value,
                url="https://api.coincap.io/v2",
                description="2000+ assets, historical data",
                free=True,
                requires_key=False,
                rate_limit="200 req/min",
                features=["assets", "rates", "exchanges", "markets"],
                verified=True
            ),
            
            "coinlore": ProviderInfo(
                id="coinlore",
                name="CoinLore",
                type=ProviderType.OHLCV.value,
                url="https://api.coinlore.net/api",
                description="Simple crypto API, 5000+ coins",
                free=True,
                requires_key=False,
                rate_limit="Unlimited",
                features=["tickers", "markets", "global"],
                verified=False
            ),
            
            "nomics": ProviderInfo(
                id="nomics",
                name="Nomics",
                type=ProviderType.OHLCV.value,
                url="https://api.nomics.com/v1",
                description="Professional grade crypto data",
                free=True,
                requires_key=True,  # Free key available
                rate_limit="1 req/sec (free)",
                features=["currencies", "ticker", "sparkline", "ohlcv"],
                verified=False
            ),
            
            "messari": ProviderInfo(
                id="messari",
                name="Messari",
                type=ProviderType.OHLCV.value,
                url="https://data.messari.io/api/v1",
                description="High-quality crypto research data",
                free=True,
                requires_key=False,  # Basic endpoints free
                rate_limit="20 req/min",
                features=["assets", "metrics", "news", "profile"],
                verified=False
            ),
            
            "cryptocompare_extended": ProviderInfo(
                id="cryptocompare_extended",
                name="CryptoCompare Extended",
                type=ProviderType.OHLCV.value,
                url="https://min-api.cryptocompare.com/data",
                description="Extended endpoints for CryptoCompare",
                free=True,
                requires_key=False,
                rate_limit="100K calls/month",
                features=["price", "ohlcv", "social", "news"],
                verified=True
            ),
            
            # ===== NEW NEWS PROVIDERS =====
            
            "cryptonews_api": ProviderInfo(
                id="cryptonews_api",
                name="CryptoNews API",
                type=ProviderType.NEWS.value,
                url="https://cryptonews-api.com",
                description="Aggregated crypto news from 50+ sources",
                free=True,
                requires_key=True,  # Free tier available
                rate_limit="100 req/day (free)",
                features=["news", "sentiment", "filtering"],
                verified=False
            ),
            
            "newsapi_crypto": ProviderInfo(
                id="newsapi_crypto",
                name="NewsAPI Crypto",
                type=ProviderType.NEWS.value,
                url="https://newsapi.org/v2",
                description="General news API with crypto filtering",
                free=True,
                requires_key=True,  # Free key available
                rate_limit="100 req/day (free)",
                features=["everything", "top-headlines", "sources"],
                verified=False
            ),
            
            "bitcoin_magazine_rss": ProviderInfo(
                id="bitcoin_magazine_rss",
                name="Bitcoin Magazine RSS",
                type=ProviderType.NEWS.value,
                url="https://bitcoinmagazine.com/feed",
                description="Bitcoin Magazine articles RSS",
                free=True,
                requires_key=False,
                rate_limit="Unlimited",
                features=["articles", "rss"],
                verified=False
            ),
            
            "decrypt_rss": ProviderInfo(
                id="decrypt_rss",
                name="Decrypt RSS",
                type=ProviderType.NEWS.value,
                url="https://decrypt.co/feed",
                description="Decrypt media RSS feed",
                free=True,
                requires_key=False,
                rate_limit="Unlimited",
                features=["articles", "rss", "web3"],
                verified=False
            ),
            
            "cryptoslate_rss": ProviderInfo(
                id="cryptoslate_rss",
                name="CryptoSlate RSS",
                type=ProviderType.NEWS.value,
                url="https://cryptoslate.com/feed/",
                description="CryptoSlate news RSS",
                free=True,
                requires_key=False,
                rate_limit="Unlimited",
                features=["articles", "rss", "analysis"],
                verified=False
            ),
            
            "theblock_rss": ProviderInfo(
                id="theblock_rss",
                name="The Block RSS",
                type=ProviderType.NEWS.value,
                url="https://www.theblock.co/rss.xml",
                description="The Block crypto news RSS",
                free=True,
                requires_key=False,
                rate_limit="Unlimited",
                features=["articles", "rss", "research"],
                verified=False
            ),
            
            # ===== ON-CHAIN PROVIDERS =====
            
            "blockchain_info": ProviderInfo(
                id="blockchain_info",
                name="Blockchain.info",
                type=ProviderType.ONCHAIN.value,
                url="https://blockchain.info",
                description="Bitcoin blockchain explorer API",
                free=True,
                requires_key=False,
                rate_limit="1 req/10sec",
                features=["blocks", "transactions", "addresses", "charts"],
                verified=True
            ),
            
            "blockchair": ProviderInfo(
                id="blockchair",
                name="Blockchair",
                type=ProviderType.ONCHAIN.value,
                url="https://api.blockchair.com",
                description="Multi-chain blockchain API",
                free=True,
                requires_key=False,
                rate_limit="30 req/min",
                features=["bitcoin", "ethereum", "litecoin", "stats"],
                verified=False
            ),
            
            "blockcypher": ProviderInfo(
                id="blockcypher",
                name="BlockCypher",
                type=ProviderType.ONCHAIN.value,
                url="https://api.blockcypher.com/v1",
                description="Multi-blockchain web service",
                free=True,
                requires_key=False,  # Higher limits with key
                rate_limit="200 req/hour",
                features=["btc", "eth", "ltc", "doge", "webhooks"],
                verified=False
            ),
            
            "btc_com": ProviderInfo(
                id="btc_com",
                name="BTC.com API",
                type=ProviderType.ONCHAIN.value,
                url="https://chain.api.btc.com/v3",
                description="BTC.com blockchain data",
                free=True,
                requires_key=False,
                rate_limit="120 req/min",
                features=["blocks", "transactions", "stats", "addresses"],
                verified=False
            ),
            
            # ===== DEFI PROVIDERS =====
            
            "defillama": ProviderInfo(
                id="defillama",
                name="DefiLlama",
                type=ProviderType.DEFI.value,
                url="https://api.llama.fi",
                description="DeFi TVL and protocol data",
                free=True,
                requires_key=False,
                rate_limit="300 req/min",
                features=["tvl", "protocols", "chains", "yields"],
                verified=True
            ),
            
            "defipulse": ProviderInfo(
                id="defipulse",
                name="DeFi Pulse",
                type=ProviderType.DEFI.value,
                url="https://data-api.defipulse.com/api/v1",
                description="DeFi rankings and metrics",
                free=True,
                requires_key=True,  # Free key available
                rate_limit="Varies",
                features=["rankings", "history", "lending"],
                verified=False
            ),
            
            "1inch": ProviderInfo(
                id="1inch",
                name="1inch API",
                type=ProviderType.DEFI.value,
                url="https://api.1inch.io/v4.0",
                description="DEX aggregator API",
                free=True,
                requires_key=False,
                rate_limit="Varies",
                features=["quotes", "swap", "liquidity", "tokens"],
                verified=False
            ),
            
            "uniswap_subgraph": ProviderInfo(
                id="uniswap_subgraph",
                name="Uniswap Subgraph",
                type=ProviderType.DEFI.value,
                url="https://api.thegraph.com/subgraphs/name/uniswap",
                description="Uniswap protocol data via The Graph",
                free=True,
                requires_key=False,
                rate_limit="Varies",
                features=["pairs", "swaps", "liquidity", "volumes"],
                verified=True
            ),
            
            # ===== SOCIAL/SENTIMENT PROVIDERS =====
            
            "lunarcrush": ProviderInfo(
                id="lunarcrush",
                name="LunarCrush",
                type=ProviderType.SOCIAL.value,
                url="https://api.lunarcrush.com/v2",
                description="Social media analytics for crypto",
                free=True,
                requires_key=True,  # Free key available
                rate_limit="50 req/day (free)",
                features=["social", "sentiment", "influencers"],
                verified=False
            ),
            
            "santiment": ProviderInfo(
                id="santiment",
                name="Santiment",
                type=ProviderType.SOCIAL.value,
                url="https://api.santiment.net",
                description="On-chain, social, and development metrics",
                free=True,
                requires_key=True,  # Limited free access
                rate_limit="Varies",
                features=["social", "onchain", "dev_activity"],
                verified=False
            ),
            
            "bitinfocharts": ProviderInfo(
                id="bitinfocharts",
                name="BitInfoCharts",
                type=ProviderType.SOCIAL.value,
                url="https://bitinfocharts.com",
                description="Crypto charts and statistics",
                free=True,
                requires_key=False,
                rate_limit="Unlimited",
                features=["charts", "compare", "stats"],
                verified=False
            ),
            
            # ===== TECHNICAL ANALYSIS PROVIDERS =====
            
            "tradingview_scraper": ProviderInfo(
                id="tradingview_scraper",
                name="TradingView (Public)",
                type=ProviderType.TECHNICAL.value,
                url="https://www.tradingview.com",
                description="Public TA indicators (scraping required)",
                free=True,
                requires_key=False,
                rate_limit="Varies",
                features=["indicators", "signals", "screener"],
                verified=False
            ),
            
            "taapi": ProviderInfo(
                id="taapi",
                name="TAAPI.IO",
                type=ProviderType.TECHNICAL.value,
                url="https://api.taapi.io",
                description="Technical Analysis API",
                free=True,
                requires_key=True,  # Free tier available
                rate_limit="50 req/day (free)",
                features=["150+ indicators", "crypto", "forex", "stocks"],
                verified=False
            ),
        }
    
    def get_all_providers(self) -> List[ProviderInfo]:
        """دریافت تمام سرویس‌دهندگان"""
        return list(self.providers.values())
    
    def get_provider_by_id(self, provider_id: str) -> Optional[ProviderInfo]:
        """دریافت سرویس‌دهنده با ID"""
        return self.providers.get(provider_id)
    
    def filter_providers(

        self,

        provider_type: Optional[str] = None,

        free_only: bool = True,

        no_key_required: bool = False,

        verified_only: bool = False

    ) -> List[ProviderInfo]:
        """فیلتر سرویس‌دهندگان"""
        results = self.get_all_providers()
        
        if provider_type:
            results = [p for p in results if p.type == provider_type]
        
        if free_only:
            results = [p for p in results if p.free]
        
        if no_key_required:
            results = [p for p in results if not p.requires_key]
        
        if verified_only:
            results = [p for p in results if p.verified]
        
        return results
    
    def get_providers_by_type(self, provider_type: str) -> List[ProviderInfo]:
        """دریافت سرویس‌دهندگان بر اساس نوع"""
        return self.filter_providers(provider_type=provider_type)
    
    def search_providers(self, query: str) -> List[ProviderInfo]:
        """جستجوی سرویس‌دهندگان"""
        query_lower = query.lower()
        results = []
        
        for provider in self.get_all_providers():
            if (query_lower in provider.name.lower() or
                query_lower in provider.description.lower() or
                any(query_lower in feature.lower() for feature in provider.features)):
                results.append(provider)
        
        return results
    
    def get_provider_stats(self) -> Dict[str, Any]:
        """آمار سرویس‌دهندگان"""
        providers = self.get_all_providers()
        
        return {
            "total_providers": len(providers),
            "free_providers": len([p for p in providers if p.free]),
            "no_key_required": len([p for p in providers if not p.requires_key]),
            "verified": len([p for p in providers if p.verified]),
            "by_type": {
                ptype.value: len([p for p in providers if p.type == ptype.value])
                for ptype in ProviderType
            }
        }


# ===== Provider Implementation Examples =====

class CoinRankingProvider:
    """مثال: سرویس‌دهنده CoinRanking"""
    
    BASE_URL = "https://api.coinranking.com/v2"
    
    async def get_coins(

        self,

        limit: int = 50,

        offset: int = 0

    ) -> Dict[str, Any]:
        """دریافت لیست کوین‌ها"""
        url = f"{self.BASE_URL}/coins"
        params = {"limit": limit, "offset": offset}
        
        async with aiohttp.ClientSession() as session:
            async with session.get(url, params=params, timeout=aiohttp.ClientTimeout(total=10)) as response:
                if response.status == 200:
                    data = await response.json()
                    return {
                        "success": True,
                        "data": data.get("data", {}),
                        "source": "coinranking"
                    }
                return {"success": False, "error": f"HTTP {response.status}"}
    
    async def get_coin_price(self, coin_uuid: str) -> Dict[str, Any]:
        """دریافت قیمت یک کوین"""
        url = f"{self.BASE_URL}/coin/{coin_uuid}"
        
        async with aiohttp.ClientSession() as session:
            async with session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as response:
                if response.status == 200:
                    data = await response.json()
                    return {
                        "success": True,
                        "data": data.get("data", {}).get("coin", {}),
                        "source": "coinranking"
                    }
                return {"success": False, "error": f"HTTP {response.status}"}


class DefiLlamaProvider:
    """مثال: سرویس‌دهنده DefiLlama"""
    
    BASE_URL = "https://api.llama.fi"
    
    async def get_tvl_protocols(self) -> Dict[str, Any]:
        """دریافت TVL تمام پروتکل‌ها"""
        url = f"{self.BASE_URL}/protocols"
        
        async with aiohttp.ClientSession() as session:
            async with session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as response:
                if response.status == 200:
                    data = await response.json()
                    return {
                        "success": True,
                        "data": data,
                        "count": len(data) if isinstance(data, list) else 0,
                        "source": "defillama"
                    }
                return {"success": False, "error": f"HTTP {response.status}"}
    
    async def get_protocol_tvl(self, protocol: str) -> Dict[str, Any]:
        """دریافت TVL یک پروتکل"""
        url = f"{self.BASE_URL}/protocol/{protocol}"
        
        async with aiohttp.ClientSession() as session:
            async with session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as response:
                if response.status == 200:
                    data = await response.json()
                    return {
                        "success": True,
                        "data": data,
                        "source": "defillama"
                    }
                return {"success": False, "error": f"HTTP {response.status}"}


class BlockchairProvider:
    """مثال: سرویس‌دهنده Blockchair"""
    
    BASE_URL = "https://api.blockchair.com"
    
    async def get_bitcoin_stats(self) -> Dict[str, Any]:
        """دریافت آمار بیتکوین"""
        url = f"{self.BASE_URL}/bitcoin/stats"
        
        async with aiohttp.ClientSession() as session:
            async with session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as response:
                if response.status == 200:
                    data = await response.json()
                    return {
                        "success": True,
                        "data": data.get("data", {}),
                        "source": "blockchair"
                    }
                return {"success": False, "error": f"HTTP {response.status}"}
    
    async def get_address_info(

        self,

        blockchain: str,

        address: str

    ) -> Dict[str, Any]:
        """دریافت اطلاعات یک آدرس"""
        url = f"{self.BASE_URL}/{blockchain}/dashboards/address/{address}"
        
        async with aiohttp.ClientSession() as session:
            async with session.get(url, timeout=aiohttp.ClientTimeout(total=10)) as response:
                if response.status == 200:
                    data = await response.json()
                    return {
                        "success": True,
                        "data": data.get("data", {}),
                        "source": "blockchair"
                    }
                return {"success": False, "error": f"HTTP {response.status}"}


class RSSNewsProvider:
    """مثال: سرویس‌دهنده خبر از RSS"""
    
    RSS_FEEDS = {
        "bitcoin_magazine": "https://bitcoinmagazine.com/feed",
        "decrypt": "https://decrypt.co/feed",
        "cryptoslate": "https://cryptoslate.com/feed/",
        "theblock": "https://www.theblock.co/rss.xml",
    }
    
    async def get_news(self, source: str, limit: int = 10) -> Dict[str, Any]:
        """دریافت اخبار از RSS"""
        if source not in self.RSS_FEEDS:
            return {"success": False, "error": "Unknown source"}
        
        url = self.RSS_FEEDS[source]
        
        try:
            # feedparser is synchronous, run in executor
            loop = asyncio.get_event_loop()
            feed = await loop.run_in_executor(None, feedparser.parse, url)
            
            articles = []
            for entry in feed.entries[:limit]:
                articles.append({
                    "title": entry.get("title", ""),
                    "link": entry.get("link", ""),
                    "published": entry.get("published", ""),
                    "summary": entry.get("summary", "")
                })
            
            return {
                "success": True,
                "data": articles,
                "count": len(articles),
                "source": source
            }
        except Exception as e:
            return {"success": False, "error": str(e)}


# ===== Singleton =====
_registry = None

def get_providers_registry() -> NewProvidersRegistry:
    """دریافت instance سراسری"""
    global _registry
    if _registry is None:
        _registry = NewProvidersRegistry()
    return _registry


# ===== Test =====
if __name__ == "__main__":
    print("="*70)
    print("🧪 Testing New Providers Registry")
    print("="*70)
    
    registry = NewProvidersRegistry()
    
    # آمار
    stats = registry.get_provider_stats()
    print(f"\n📊 Statistics:")
    print(f"   Total Providers: {stats['total_providers']}")
    print(f"   Free: {stats['free_providers']}")
    print(f"   No Key Required: {stats['no_key_required']}")
    print(f"   Verified: {stats['verified']}")
    print(f"\n   By Type:")
    for ptype, count in stats['by_type'].items():
        print(f"      • {ptype.upper()}: {count} providers")
    
    # OHLCV providers
    print(f"\n⭐ OHLCV Providers (No Key Required):")
    ohlcv = registry.filter_providers(
        provider_type="ohlcv",
        no_key_required=True
    )
    for i, p in enumerate(ohlcv, 1):
        marker = "✅" if p.verified else "🟡"
        print(f"   {marker} {i}. {p.name}")
        print(f"      URL: {p.url}")
        print(f"      Rate: {p.rate_limit}")
    
    # DeFi providers
    print(f"\n⭐ DeFi Providers:")
    defi = registry.get_providers_by_type("defi")
    for i, p in enumerate(defi, 1):
        marker = "✅" if p.verified else "🟡"
        print(f"   {marker} {i}. {p.name} - {p.description}")
    
    # Test actual API calls
    print(f"\n🧪 Testing API Calls:")
    
    async def test_apis():
        # Test CoinRanking
        print(f"\n   Testing CoinRanking...")
        coinranking = CoinRankingProvider()
        result = await coinranking.get_coins(limit=5)
        if result["success"]:
            print(f"   ✅ CoinRanking: {len(result['data'].get('coins', []))} coins fetched")
        else:
            print(f"   ❌ CoinRanking: {result.get('error')}")
        
        # Test DefiLlama
        print(f"\n   Testing DefiLlama...")
        defillama = DefiLlamaProvider()
        result = await defillama.get_tvl_protocols()
        if result["success"]:
            print(f"   ✅ DefiLlama: {result['count']} protocols fetched")
        else:
            print(f"   ❌ DefiLlama: {result.get('error')}")
        
        # Test Blockchair
        print(f"\n   Testing Blockchair...")
        blockchair = BlockchairProvider()
        result = await blockchair.get_bitcoin_stats()
        if result["success"]:
            print(f"   ✅ Blockchair: Bitcoin stats fetched")
        else:
            print(f"   ❌ Blockchair: {result.get('error')}")
        
        # Test RSS News
        print(f"\n   Testing RSS News (Decrypt)...")
        rss = RSSNewsProvider()
        result = await rss.get_news("decrypt", limit=3)
        if result["success"]:
            print(f"   ✅ Decrypt RSS: {result['count']} articles fetched")
            for article in result['data'][:2]:
                print(f"      • {article['title'][:60]}...")
        else:
            print(f"   ❌ Decrypt RSS: {result.get('error')}")
    
    asyncio.run(test_apis())
    
    print("\n" + "="*70)
    print("✅ New Providers Registry is working!")
    print("="*70)