Repository navigation
Rename readme.md to ading_Pro_Demo.html - #184
Open
debojitbehera966-beep wants to merge 1 commit into
Open
debojitbehera966-beep wants to merge 1 commit into
debojitbehera966-beep wants to merge 1 commit into
Conversation
ading_Pro_Demo.html
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)
<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>def dashboard():
return HTMLResponse("""<!doctype html>
<title>AI TRADING PRO</title>
AI TRADING PRO
डेटा लोड करने के लिए बटन दबाएँ।
यह तकनीकी विश्लेषण का डेमो है, वित्तीय सलाह या ट्रेड निर्देश नहीं। डेटा XAU/USD spot feed है; Quotex OTC भाव अलग हो सकते हैं।