Fix: Add yfinance as main route and update docker command
Browse filesFiles changed (2)
- Dockerfile+5-8
- app.py+23-12
1234567891011121314# Gunakan image Python yang ringanFROM python:3.10-slim# Set folder kerja di dalam containerWORKDIR /app# Copy semua file kita ke dalam containerCOPY . .# Install dependenciesRUN pip install --no-cache-dir -r requirements.txt# Jalankan FastAPI menggunakan UvicornCMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]1234567891011FROM python:3.10-slimWORKDIR /codeCOPY ./requirements.txt /code/requirements.txtRUN pip install --no-cache-dir --upgrade -r /code/requirements.txtCOPY . .CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
4 unmodified lines567891011 unmodified lines2223242526272829301 unmodified line3233343536373839401 unmodified line42434445464748495051525354555657585960616233 unmodified lines969798991001011022 unmodified lines1051061071084 unmodified linesfrom tensorflow.keras.models import Sequentialfrom tensorflow.keras.layers import Dense, LSTM, Inputimport requestsimport osapp = FastAPI()11 unmodified linesexcept: passdef get_crypto_data_global():"""Sistem Autopilot Multi-Jalur (Failover) untuk Menjamin Data Pasti Masuk"""# JALUR 1: Binance Vision APItry:url = "https://api.binance.vision/api/v3/klines?symbol=BTCUSDT&interval=1d&limit=60"res = requests.get(url, timeout=5).json()1 unmodified linecloses = [float(item[4]) for item in res]return pd.DataFrame(closes, columns=['close']), Noneexcept Exception as e:print(f"Jalur 1 Gagal: {str(e)}")# JALUR 2: Tokocrypto API (Binance Cloud)try:url = "https://api.tokocrypto.com/open/v1/market/klines?symbol=BTC_USDT&intervals=1d&limit=60"res = requests.get(url, timeout=5).json()1 unmodified linecloses = [float(item[4]) for item in res["data"]]return pd.DataFrame(closes, columns=['close']), Noneexcept Exception as e:print(f"Jalur 2 Gagal: {str(e)}")# JALUR 3: CoinGecko Public API (Benteng Terakhir)try:url = "https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=60&interval=daily"res = requests.get(url, timeout=5).json()if "prices" in res:# Format CoinGecko: [[timestamp, price], ...]closes = [float(item[1]) for item in res["prices"]]# Ambil 60 data teratas/terakhirreturn pd.DataFrame(closes[:60], columns=['close']), Noneexcept Exception as e:print(f"Jalur 3 Gagal: {str(e)}")return None, "Semua jalur API (Binance, Tokocrypto, CoinGecko) sedang down/timeout."def save_to_supabase(payload):if not SUPA_KEY: return33 unmodified linessave_to_supabase(payload)# Kirim Laporan ke Telegrammsg = f"🛡️ CHRONOS AI REPORT\n\nPrice: ${current_price:,.2f}\nPred: ${final_pred:,.2f}\nSignal: {signal}\n\n🤖 Server Status: Ultra Secure (Triple API)"send_telegram(msg)return {**payload, "telegram_status": "Pesan dikirim"}2 unmodified lines@app.get("/")def health():return {"status": "Chronos Online", "engine": "Triple-Route Failover System"}4 unmodified lines56789101111 unmodified lines2324252627282930313233343536373839404142431 unmodified line4546474849505152531 unmodified line5556575859606162636465666768697071727333 unmodified lines1071081091101111121132 unmodified lines1161171181194 unmodified linesfrom tensorflow.keras.models import Sequentialfrom tensorflow.keras.layers import Dense, LSTM, Inputimport requestsimport yfinance as yfimport osapp = FastAPI()11 unmodified linesexcept: passdef get_crypto_data_global():"""Sistem Autopilot Multi-Jalur + Yahoo Finance untuk Kestabilan Cloud"""# JALUR UTAMA UTK CLOUD: Yahoo Finance (Anti-Blokir)try:ticker = yf.Ticker("BTC-USD")# Ambil 60 hari terakhir data hariandf_yf = ticker.history(period="60d", interval="1d")if not df_yf.empty:closes = df_yf['Close'].tolist()print("✅ Jalur Utama (Yahoo Finance) Sukses Beroperasi!")return pd.DataFrame(closes, columns=['close']), Noneexcept Exception as e:print(f"Jalur Utama (Yahoo Finance) Gagal: {str(e)}")# JALUR CADANGAN 1: Binance Vision APItry:url = "https://api.binance.vision/api/v3/klines?symbol=BTCUSDT&interval=1d&limit=60"res = requests.get(url, timeout=5).json()1 unmodified linecloses = [float(item[4]) for item in res]return pd.DataFrame(closes, columns=['close']), Noneexcept Exception as e:print(f"Jalur Cadangan 1 Gagal: {str(e)}")# JALUR CADANGAN 2: Tokocrypto APItry:url = "https://api.tokocrypto.com/open/v1/market/klines?symbol=BTC_USDT&intervals=1d&limit=60"res = requests.get(url, timeout=5).json()1 unmodified linecloses = [float(item[4]) for item in res["data"]]return pd.DataFrame(closes, columns=['close']), Noneexcept Exception as e:print(f"Jalur Cadangan 2 Gagal: {str(e)}")# JALUR CADANGAN 3: CoinGecko Public APItry:url = "https://api.coingecko.com/api/v3/coins/bitcoin/market_chart?vs_currency=usd&days=60&interval=daily"res = requests.get(url, timeout=5).json()if "prices" in res:closes = [float(item[1]) for item in res["prices"]]return pd.DataFrame(closes[:60], columns=['close']), Noneexcept Exception as e:print(f"Jalur Cadangan 3 Gagal: {str(e)}")return None, "Semua jalur API (YahooFinance, Binance, Tokocrypto, CoinGecko) down/timeout."def save_to_supabase(payload):if not SUPA_KEY: return33 unmodified linessave_to_supabase(payload)# Kirim Laporan ke Telegrammsg = f"🛡️ CHRONOS AI REPORT\n\nPrice: ${current_price:,.2f}\nPred: ${final_pred:,.2f}\nSignal: {signal}\n\n🤖 Server Status: Ultra Secure (Quad-Route Failover)"send_telegram(msg)return {**payload, "telegram_status": "Pesan dikirim"}2 unmodified lines@app.get("/")def health():return {"status": "Chronos Online", "engine": "Quad-Route Failover System (yFinance Active)"}
Dockerfile+5-8
app.py+23-12