Update main.py
Browse files16 unmodified lines1718192021222324252627282930313233343536373839404142434445464748495015 unmodified lines6667686970717273747576777879808 unmodified lines8990919216 unmodified linesasync def send_msg(text: str):url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage"async with httpx.AsyncClient() as client:try:await client.post(url, json={"chat_id": TELEGRAM_CHAT_ID, "text": text, "parse_mode": "Markdown"})except:passdef fetch_safe_data(ticker):try:# CRITICAL FIX: period="7d" is the absolute limit for 1m datadf = yf.download(ticker, period="7d", interval="1m", progress=False, auto_adjust=True)if df.empty:return None# Flatten Multi-Indexif isinstance(df.columns, pd.MultiIndex):df.columns = df.columns.get_level_values(0)return df[['Close', 'Open', 'High', 'Low']].ffill().bfill()except Exception as e:print(f"Data Fetch Error for {ticker}: {e}")return Nonedef get_boss_verdict(ticker, name):df = fetch_safe_data(ticker)if df is None: return Nonetry:cp = float(df['Close'].iloc[-1])# Kinetic Analyticsdelta = df['Close'].diff()gain = (delta.where(delta > 0, 0)).rolling(14).mean()loss = (-delta.where(delta < 0, 0)).rolling(14).mean()15 unmodified lineselif score >= (threshold - 1): res = "🛰️ STIMULUS"return {"v": res, "p": round(cp, 4), "score": f"{score}/4"}except:return None@app.get("/")async def root():return {"status": "V8.2 Online", "info": "Data limits optimized"}async def main_loop():await send_msg("🏛️ *OMNI-BOSS MASTER V8.2*\nGranularity limits applied. BTC stream stabilized.")while True:reports = []for name, ticker in ASSETS.items():8 unmodified lines@app.on_event("startup")async def startup():asyncio.create_task(main_loop())16 unmodified lines17181920212223242526272829303132333435363738394015 unmodified lines56575859606162636465666768697071727374758 unmodified lines84858687888916 unmodified linesasync def send_msg(text: str):url = f"https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage"async with httpx.AsyncClient() as client:try: await client.post(url, json={"chat_id": TELEGRAM_CHAT_ID, "text": text, "parse_mode": "Markdown"})except: passdef fetch_safe_data(ticker):try:# Hard limit to 7d to prevent the "delisted" error you sawdf = yf.download(ticker, period="7d", interval="1m", progress=False, auto_adjust=True)if df is None or df.empty: return Noneif isinstance(df.columns, pd.MultiIndex):df.columns = df.columns.get_level_values(0)return df[['Close', 'Open', 'High', 'Low']].ffill().bfill()except: return Nonedef get_boss_verdict(ticker, name):df = fetch_safe_data(ticker)if df is None: return Nonetry:cp = float(df['Close'].iloc[-1])delta = df['Close'].diff()gain = (delta.where(delta > 0, 0)).rolling(14).mean()loss = (-delta.where(delta < 0, 0)).rolling(14).mean()15 unmodified lineselif score >= (threshold - 1): res = "🛰️ STIMULUS"return {"v": res, "p": round(cp, 4), "score": f"{score}/4"}except: return None@app.get("/")async def root():return {"status": "V8.3 Active", "timestamp": datetime.now().isoformat()}async def main_loop():# 1. IMMEDIATE LOG FEEDBACKprint("ENGINE: Initializing Command Circuit...")await asyncio.sleep(5) # 5-second grace period for network bootawait send_msg("🏛️ *OMNI-BOSS MASTER V8.3*\nEngine Warm-up complete. Starting Live Feed.")print("ENGINE: Live Feed Started.")while True:reports = []for name, ticker in ASSETS.items():8 unmodified lines@app.on_event("startup")async def startup():# Create task without blocking the FastAPI startup sequenceloop = asyncio.get_event_loop()loop.create_task(main_loop())
main.py+17-20