Spaces:
Running
Running
Update data_manager.py
Browse files- data_manager.py +28 -13
data_manager.py
CHANGED
|
@@ -651,14 +651,14 @@ class DataManager:
|
|
| 651 |
try:
|
| 652 |
ohlcv_data = {}
|
| 653 |
|
| 654 |
-
#
|
| 655 |
timeframes = [
|
| 656 |
-
('5m',
|
| 657 |
-
('15m',
|
| 658 |
-
('1h',
|
| 659 |
-
('4h',
|
| 660 |
-
('1d',
|
| 661 |
-
('1w',
|
| 662 |
]
|
| 663 |
|
| 664 |
# إنشاء مهام لجميع الإطارات الزمنية بشكل متوازي
|
|
@@ -676,12 +676,16 @@ class DataManager:
|
|
| 676 |
for i, (timeframe, limit) in enumerate(timeframes):
|
| 677 |
result = timeframe_results[i]
|
| 678 |
if isinstance(result, Exception) or result is None:
|
|
|
|
| 679 |
has_sufficient_data = False
|
| 680 |
break
|
| 681 |
|
| 682 |
-
|
|
|
|
| 683 |
ohlcv_data[timeframe] = result
|
|
|
|
| 684 |
else:
|
|
|
|
| 685 |
has_sufficient_data = False
|
| 686 |
break
|
| 687 |
|
|
@@ -690,25 +694,36 @@ class DataManager:
|
|
| 690 |
ticker = self.exchange.fetch_ticker(symbol)
|
| 691 |
current_price = ticker.get('last', 0) if ticker else 0
|
| 692 |
|
| 693 |
-
|
| 694 |
'symbol': symbol,
|
| 695 |
'ohlcv': ohlcv_data,
|
| 696 |
'current_price': current_price,
|
| 697 |
-
'timestamp': datetime.now().isoformat()
|
|
|
|
| 698 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 699 |
except Exception as price_error:
|
|
|
|
| 700 |
return None
|
| 701 |
else:
|
|
|
|
| 702 |
return None
|
| 703 |
|
| 704 |
except Exception as e:
|
|
|
|
| 705 |
return None
|
| 706 |
|
| 707 |
async def _fetch_single_timeframe(self, symbol: str, timeframe: str, limit: int):
|
| 708 |
"""جلب بيانات إطار زمني واحد"""
|
| 709 |
try:
|
| 710 |
-
|
| 711 |
-
|
|
|
|
|
|
|
|
|
|
| 712 |
return None
|
| 713 |
|
| 714 |
async def get_latest_price_async(self, symbol):
|
|
@@ -800,4 +815,4 @@ class DataManager:
|
|
| 800 |
'source': 'whale_analysis'
|
| 801 |
}
|
| 802 |
|
| 803 |
-
print("✅ DataManager loaded - Parallel OHLCV Fetching System with Whale Data Support")
|
|
|
|
| 651 |
try:
|
| 652 |
ohlcv_data = {}
|
| 653 |
|
| 654 |
+
# ✅ تصحيح: جلب 200 شمعة لكل إطار زمني بدلاً من 100
|
| 655 |
timeframes = [
|
| 656 |
+
('5m', 200), # كان 100
|
| 657 |
+
('15m', 200), # كان 100
|
| 658 |
+
('1h', 200), # كان 100
|
| 659 |
+
('4h', 200), # كان 100
|
| 660 |
+
('1d', 200), # كان 100
|
| 661 |
+
('1w', 200), # كان 50 - الآن 200
|
| 662 |
]
|
| 663 |
|
| 664 |
# إنشاء مهام لجميع الإطارات الزمنية بشكل متوازي
|
|
|
|
| 676 |
for i, (timeframe, limit) in enumerate(timeframes):
|
| 677 |
result = timeframe_results[i]
|
| 678 |
if isinstance(result, Exception) or result is None:
|
| 679 |
+
print(f" ⚠️ فشل جلب بيانات {timeframe} لـ {symbol}")
|
| 680 |
has_sufficient_data = False
|
| 681 |
break
|
| 682 |
|
| 683 |
+
# ✅ تخفيف الشرط من 20 إلى 50 شمعة كحد أدنى
|
| 684 |
+
if result and len(result) >= 50:
|
| 685 |
ohlcv_data[timeframe] = result
|
| 686 |
+
print(f" ✅ {symbol} - {timeframe}: {len(result)} شمعة")
|
| 687 |
else:
|
| 688 |
+
print(f" ⚠️ {symbol} - {timeframe}: بيانات غير كافية ({len(result) if result else 0} شمعة)")
|
| 689 |
has_sufficient_data = False
|
| 690 |
break
|
| 691 |
|
|
|
|
| 694 |
ticker = self.exchange.fetch_ticker(symbol)
|
| 695 |
current_price = ticker.get('last', 0) if ticker else 0
|
| 696 |
|
| 697 |
+
result_data = {
|
| 698 |
'symbol': symbol,
|
| 699 |
'ohlcv': ohlcv_data,
|
| 700 |
'current_price': current_price,
|
| 701 |
+
'timestamp': datetime.now().isoformat(),
|
| 702 |
+
'candles_count': {tf: len(data) for tf, data in ohlcv_data.items()}
|
| 703 |
}
|
| 704 |
+
|
| 705 |
+
print(f" ✅ اكتمل جلب بيانات {symbol}: {result_data['candles_count']}")
|
| 706 |
+
return result_data
|
| 707 |
+
|
| 708 |
except Exception as price_error:
|
| 709 |
+
print(f" ❌ خطأ في جلب سعر {symbol}: {price_error}")
|
| 710 |
return None
|
| 711 |
else:
|
| 712 |
+
print(f" ❌ بيانات غير كافية لـ {symbol}")
|
| 713 |
return None
|
| 714 |
|
| 715 |
except Exception as e:
|
| 716 |
+
print(f" ❌ خطأ عام في جلب بيانات {symbol}: {e}")
|
| 717 |
return None
|
| 718 |
|
| 719 |
async def _fetch_single_timeframe(self, symbol: str, timeframe: str, limit: int):
|
| 720 |
"""جلب بيانات إطار زمني واحد"""
|
| 721 |
try:
|
| 722 |
+
ohlcv_data = self.exchange.fetch_ohlcv(symbol, timeframe, limit=limit)
|
| 723 |
+
print(f" 📊 {symbol} - {timeframe}: {len(ohlcv_data)} شمعة")
|
| 724 |
+
return ohlcv_data
|
| 725 |
+
except Exception as e:
|
| 726 |
+
print(f" ❌ فشل جلب {timeframe} لـ {symbol}: {e}")
|
| 727 |
return None
|
| 728 |
|
| 729 |
async def get_latest_price_async(self, symbol):
|
|
|
|
| 815 |
'source': 'whale_analysis'
|
| 816 |
}
|
| 817 |
|
| 818 |
+
print("✅ DataManager loaded - Parallel OHLCV Fetching System with Whale Data Support & 200 Candles")
|