Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -830,8 +830,31 @@ async def run_bot_cycle_async():
|
|
| 830 |
|
| 831 |
if should_look_for_new_trade:
|
| 832 |
portfolio_state = await r2_service_global.get_portfolio_state_async()
|
| 833 |
-
|
| 834 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 835 |
new_opportunity = await find_new_opportunities_async()
|
| 836 |
if new_opportunity:
|
| 837 |
print(f"✅ Opportunity for {new_opportunity['symbol']} confirmed! Saving trade. Strategy: {new_opportunity.get('strategy')}")
|
|
@@ -854,7 +877,7 @@ async def run_bot_cycle_async():
|
|
| 854 |
else:
|
| 855 |
print("✅ Scan complete. No actionable opportunities identified.")
|
| 856 |
else:
|
| 857 |
-
print("😴 No available capital. Waiting for current trade to close.")
|
| 858 |
|
| 859 |
finally:
|
| 860 |
print("✅ Cycle finished. Releasing lock.")
|
|
|
|
| 830 |
|
| 831 |
if should_look_for_new_trade:
|
| 832 |
portfolio_state = await r2_service_global.get_portfolio_state_async()
|
| 833 |
+
current_capital = portfolio_state.get("current_capital_usd", 0)
|
| 834 |
+
|
| 835 |
+
# ✅ الإصلاح الحاسم: التحقق من رأس المال المتاح بشكل صحيح
|
| 836 |
+
print(f"💰 Current available capital: ${current_capital:.2f}")
|
| 837 |
+
|
| 838 |
+
# إذا كان رأس المال 0، نتحقق مما إذا كان هناك خطأ في الحساب
|
| 839 |
+
if current_capital <= 0:
|
| 840 |
+
print("⚠️ Current capital is 0. Checking for potential calculation errors...")
|
| 841 |
+
|
| 842 |
+
# التحقق من وجود صفقات مفتوحة
|
| 843 |
+
if len(open_trades) == 0:
|
| 844 |
+
print("🔄 No open trades but capital is 0. This might be an error.")
|
| 845 |
+
print("💡 Attempting to recover capital state...")
|
| 846 |
+
|
| 847 |
+
# محاولة استعادة رأس المال من الحالة الأولية
|
| 848 |
+
initial_capital = portfolio_state.get("initial_capital_usd", 10.0)
|
| 849 |
+
if initial_capital > 0:
|
| 850 |
+
portfolio_state["current_capital_usd"] = initial_capital
|
| 851 |
+
portfolio_state["invested_capital_usd"] = 0.0
|
| 852 |
+
await r2_service_global.save_portfolio_state_async(portfolio_state)
|
| 853 |
+
print(f"✅ Reset capital to initial amount: ${initial_capital:.2f}")
|
| 854 |
+
current_capital = initial_capital
|
| 855 |
+
|
| 856 |
+
if current_capital > 1:
|
| 857 |
+
print(f"✅ Capital available (${current_capital:.2f}). Scanning for new opportunities...")
|
| 858 |
new_opportunity = await find_new_opportunities_async()
|
| 859 |
if new_opportunity:
|
| 860 |
print(f"✅ Opportunity for {new_opportunity['symbol']} confirmed! Saving trade. Strategy: {new_opportunity.get('strategy')}")
|
|
|
|
| 877 |
else:
|
| 878 |
print("✅ Scan complete. No actionable opportunities identified.")
|
| 879 |
else:
|
| 880 |
+
print(f"😴 No available capital (${current_capital:.2f}). Waiting for current trade to close.")
|
| 881 |
|
| 882 |
finally:
|
| 883 |
print("✅ Cycle finished. Releasing lock.")
|