Spaces:
Paused
Paused
Update whale_monitor/core.py
Browse files- whale_monitor/core.py +14 -9
whale_monitor/core.py
CHANGED
|
@@ -295,19 +295,15 @@ class EnhancedWhaleMonitor:
|
|
| 295 |
payload_block = {"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": int(time.time())}
|
| 296 |
json_response_block = await self.rpc_manager.post(network, payload_block, timeout=15.0)
|
| 297 |
|
| 298 |
-
# 🔴 --- START OF CHANGE --- 🔴
|
| 299 |
# (إصلاح خطأ 'NoneType' - يجب التحقق من None أولاً)
|
| 300 |
if json_response_block is None:
|
| 301 |
-
# (هذا يحدث إذا فشل rpc_manager في الاتصال بـ *جميع* النقاط)
|
| 302 |
print(f" ❌ [RPC Manager] فشلت جميع محاولات جلب رقم الكتلة لشبكة {network}.")
|
| 303 |
return []
|
| 304 |
|
| 305 |
if not json_response_block.get('result'):
|
| 306 |
-
# (هذا يحدث إذا أعادت النقطة استجابة صالحة ولكنها تحتوي على خطأ)
|
| 307 |
error_msg = json_response_block.get('error', {}).get('message', 'No block number result')
|
| 308 |
print(f" ❌ [RPC Manager] لم يتم الحصول على رقم أحدث كتلة من {network}: {error_msg}")
|
| 309 |
return []
|
| 310 |
-
# 🔴 --- END OF CHANGE --- 🔴
|
| 311 |
|
| 312 |
latest_block = int(json_response_block['result'], 16)
|
| 313 |
|
|
@@ -805,20 +801,29 @@ class EnhancedWhaleMonitor:
|
|
| 805 |
except Exception as e: print(f"❌ خطأ في _get_accurate_token_value_optimized لـ {symbol}: {e}"); return 0
|
| 806 |
|
| 807 |
async def _get_token_price(self, symbol):
|
| 808 |
-
"""
|
|
|
|
|
|
|
| 809 |
try:
|
| 810 |
base_symbol = symbol.split('/')[0].upper()
|
| 811 |
cache_entry = self.token_price_cache.get(base_symbol)
|
| 812 |
-
if cache_entry and time.time() - cache_entry.get('timestamp', 0) < 300:
|
|
|
|
| 813 |
|
| 814 |
-
|
| 815 |
-
|
| 816 |
-
self.token_price_cache[base_symbol] = {'price': price, 'timestamp': time.time()}; return price
|
| 817 |
|
|
|
|
| 818 |
price = await self._get_token_price_from_kucoin(symbol)
|
| 819 |
if price is not None and price > 0:
|
| 820 |
self.token_price_cache[base_symbol] = {'price': price, 'timestamp': time.time()}; return price
|
| 821 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 822 |
print(f"❌ فشل جميع محاولات جلب سعر العملة {symbol}"); self.token_price_cache[base_symbol] = {'price': 0, 'timestamp': time.time()}; return 0
|
| 823 |
except Exception as e: print(f"❌ فشل عام في جلب سعر العملة {symbol}: {e}"); return 0
|
| 824 |
|
|
|
|
| 295 |
payload_block = {"jsonrpc": "2.0", "method": "eth_blockNumber", "params": [], "id": int(time.time())}
|
| 296 |
json_response_block = await self.rpc_manager.post(network, payload_block, timeout=15.0)
|
| 297 |
|
|
|
|
| 298 |
# (إصلاح خطأ 'NoneType' - يجب التحقق من None أولاً)
|
| 299 |
if json_response_block is None:
|
|
|
|
| 300 |
print(f" ❌ [RPC Manager] فشلت جميع محاولات جلب رقم الكتلة لشبكة {network}.")
|
| 301 |
return []
|
| 302 |
|
| 303 |
if not json_response_block.get('result'):
|
|
|
|
| 304 |
error_msg = json_response_block.get('error', {}).get('message', 'No block number result')
|
| 305 |
print(f" ❌ [RPC Manager] لم يتم الحصول على رقم أحدث كتلة من {network}: {error_msg}")
|
| 306 |
return []
|
|
|
|
| 307 |
|
| 308 |
latest_block = int(json_response_block['result'], 16)
|
| 309 |
|
|
|
|
| 801 |
except Exception as e: print(f"❌ خطأ في _get_accurate_token_value_optimized لـ {symbol}: {e}"); return 0
|
| 802 |
|
| 803 |
async def _get_token_price(self, symbol):
|
| 804 |
+
"""
|
| 805 |
+
(محدث) جلب سعر العملة (KuCoin أولاً، ثم CoinGecko كاحتياطي).
|
| 806 |
+
"""
|
| 807 |
try:
|
| 808 |
base_symbol = symbol.split('/')[0].upper()
|
| 809 |
cache_entry = self.token_price_cache.get(base_symbol)
|
| 810 |
+
if cache_entry and time.time() - cache_entry.get('timestamp', 0) < 300:
|
| 811 |
+
return cache_entry['price']
|
| 812 |
|
| 813 |
+
# 🔴 --- START OF CHANGE --- 🔴
|
| 814 |
+
# (تغيير الأولوية حسب طلبك)
|
|
|
|
| 815 |
|
| 816 |
+
# 1. جرب KuCoin أولاً (سريع وله حدود أعلى)
|
| 817 |
price = await self._get_token_price_from_kucoin(symbol)
|
| 818 |
if price is not None and price > 0:
|
| 819 |
self.token_price_cache[base_symbol] = {'price': price, 'timestamp': time.time()}; return price
|
| 820 |
|
| 821 |
+
# 2. جرب CoinGecko كاحتياطي (أبطأ وله حدود صارمة)
|
| 822 |
+
price = await self._get_token_price_from_coingecko(symbol)
|
| 823 |
+
if price is not None and price > 0:
|
| 824 |
+
self.token_price_cache[base_symbol] = {'price': price, 'timestamp': time.time()}; return price
|
| 825 |
+
# 🔴 --- END OF CHANGE --- 🔴
|
| 826 |
+
|
| 827 |
print(f"❌ فشل جميع محاولات جلب سعر العملة {symbol}"); self.token_price_cache[base_symbol] = {'price': 0, 'timestamp': time.time()}; return 0
|
| 828 |
except Exception as e: print(f"❌ فشل عام في جلب سعر العملة {symbol}: {e}"); return 0
|
| 829 |
|