Skip to content

Rename readme.md to ading_Pro_Demo.html - #184

Open
debojitbehera966-beep wants to merge 1 commit into
htmlpreview:masterfrom
debojitbehera966-beep:patch-1
Open

debojitbehera966-beep wants to merge 1 commit into
htmlpreview:masterfrom
debojitbehera966-beep:patch-1

Conversation

@debojitbehera966-beep

Copy link
Copy Markdown

ading_Pro_Demo.htmlimport os
from datetime import datetime, timezone
from typing import Any
import requests
import pandas as pd
from fastapi import FastAPI, HTTPException
from fastapi.responses import HTMLResponse
from dotenv import load_dotenv

load_dotenv()
API_KEY = os.getenv("TWELVE_DATA_API_KEY", "").strip()
SYMBOL = os.getenv("SYMBOL", "XAU/USD")
INTERVAL = os.getenv("INTERVAL", "5min")
app = FastAPI(title="AI TRADING PRO — Gold Demo")

def fetch_candles(symbol=SYMBOL, interval=INTERVAL, outputsize=150):
if not API_KEY:
raise RuntimeError("TWELVE_DATA_API_KEY missing. Add it to .env")
url = "https://api.twelvedata.com/time_series"
response = requests.get(url, params={
"symbol": symbol, "interval": interval,
"outputsize": outputsize, "apikey": API_KEY,
"format": "JSON"
}, timeout=20)
response.raise_for_status()
payload = response.json()
if payload.get("status") == "error" or "values" not in payload:
raise RuntimeError(payload.get("message", str(payload)))
df = pd.DataFrame(payload["values"])
for col in ["open", "high", "low", "close"]:
df[col] = pd.to_numeric(df[col], errors="coerce")
df["datetime"] = pd.to_datetime(df["datetime"], errors="coerce", utc=True)
df = df.dropna(subset=["datetime", "open", "high", "low", "close"])
df = df.sort_values("datetime").drop_duplicates("datetime").reset_index(drop=True)
if len(df) < 60:
raise RuntimeError(f"Not enough candles: received {len(df)}; need at least 60.")
return df, payload.get("meta", {})

def rsi(series, period=14):
delta = series.diff()
gain = delta.clip(lower=0).ewm(alpha=1/period, adjust=False).mean()
loss = (-delta.clip(upper=0)).ewm(alpha=1/period, adjust=False).mean()
rs = gain / loss.replace(0, pd.NA)
out = 100 - (100 / (1 + rs))
return out.fillna(100)

def analyze(df):
x = df.copy()
close = x.close
x["ema9"] = close.ewm(span=9, adjust=False).mean()
x["ema21"] = close.ewm(span=21, adjust=False).mean()
x["ema50"] = close.ewm(span=50, adjust=False).mean()
x["rsi14"] = rsi(close, 14)
ema12 = close.ewm(span=12, adjust=False).mean()
ema26 = close.ewm(span=26, adjust=False).mean()
x["macd"] = ema12 - ema26
x["macd_signal"] = x.macd.ewm(span=9, adjust=False).mean()
prev_close = close.shift(1)
tr = pd.concat([(x.high-x.low), (x.high-prev_close).abs(),
(x.low-prev_close).abs()], axis=1).max(axis=1)
x["atr14"] = tr.rolling(14).mean()
last = x.iloc[-1]
# Use the latest returned candle as supplied by provider. It may still be forming.
# Signals are deliberately conservative and for paper/demo review only.
score = 0
score += 1 if last.ema9 > last.ema21 else -1
score += 1 if last.ema21 > last.ema50 else -1
score += 1 if last.macd > last.macd_signal else -1
score += 1 if last.rsi14 > 52 else (-1 if last.rsi14 < 48 else 0)
if score >= 3 and 50 <= last.rsi14 <= 68:
signal = "BUY BIAS"
elif score <= -3 and 32 <= last.rsi14 <= 50:
signal = "SELL BIAS"
else:
signal = "NO TRADE"
recent = x.tail(20)
support = float(recent.low.min())
resistance = float(recent.high.max())
return {
"signal": signal, "score": int(score),
"price": round(float(last.close), 3),
"candle_time_utc": last.datetime.isoformat(),
"ema9": round(float(last.ema9), 3),
"ema21": round(float(last.ema21), 3),
"ema50": round(float(last.ema50), 3),
"rsi14": round(float(last.rsi14), 2),
"macd": round(float(last.macd), 5),
"macd_signal": round(float(last.macd_signal), 5),
"atr14": round(float(last.atr14), 3) if pd.notna(last.atr14) else None,
"support_20_candles": round(support, 3),
"resistance_20_candles": round(resistance, 3),
"data_note": "Spot XAU/USD feed; not Quotex OTC. Latest candle may be incomplete.",
"mode": "DEMO / ANALYSIS ONLY"
}

@app.get("/api/analysis")
def api_analysis():
try:
df, meta = fetch_candles()
return {"symbol": SYMBOL, "interval": INTERVAL, "provider": "Twelve Data",
"provider_meta": meta, "updated_at_utc": datetime.now(timezone.utc).isoformat(),
"analysis": analyze(df)}
except Exception as e:
raise HTTPException(status_code=502, detail=str(e))

@app.get("/", response_class=HTMLResponse)
def dashboard():
return HTMLResponse("""<!doctype html>
<title>AI TRADING PRO</title>

<style> body{margin:0;background:#0b1220;color:#e8eefc;font:16px system-ui;padding:20px} main{max-width:760px;margin:auto}.card{background:#151f33;border:1px solid #293650;border-radius:16px;padding:18px;margin:12px 0} h1{margin-bottom:4px}.muted{color:#a9b7d0}.signal{font-size:28px;font-weight:800} .grid{display:grid;grid-template-columns:1fr 1fr;gap:10px}.value{font-size:20px;font-weight:700} button{background:#4b83ff;color:white;border:0;border-radius:10px;padding:12px 16px;font-weight:700} </style>

AI TRADING PRO

Gold XAU/USD · 5 मिनट · हिंदी · DEMO / Analysis Only
अभी Analysis करें

डेटा लोड करने के लिए बटन दबाएँ।

—
महत्वपूर्ण

यह तकनीकी विश्लेषण का डेमो है, वित्तीय सलाह या ट्रेड निर्देश नहीं। डेटा XAU/USD spot feed है; Quotex OTC भाव अलग हो सकते हैं।

<script> async function loadData(){let s=document.getElementById('status');s.textContent='लाइव डेटा प्राप्त हो रहा है…'; try{let r=await fetch('/api/analysis');let j=await r.json();if(!r.ok)throw Error(j.detail||'डेटा त्रुटि'); let a=j.analysis;document.getElementById('signal').textContent=a.signal; document.getElementById('note').textContent=a.data_note; document.getElementById('metrics').innerHTML=[ ['अंतिम भाव',a.price],['Score',a.score+'/4'],['RSI (14)',a.rsi14],['EMA 9',a.ema9], ['EMA 21',a.ema21],['EMA 50',a.ema50],['MACD',a.macd],['ATR (14)',a.atr14], ['Support',a.support_20_candles],['Resistance',a.resistance_20_candles] ].map(x=>`
${x[0]}
${x[1]??'—'}
`).join(''); s.textContent='अपडेट: '+j.updated_at_utc+' | '+j.symbol+' '+j.interval; }catch(e){s.textContent='त्रुटि: '+e.message+' — .env में API key और symbol access जाँचें।'}} </script>""")

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant