Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,41 @@
from typing import Optional

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
import requests

app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

@app.get("/")
async def root():
return {"message": "Hello World"}
def get_live_gold_price():
try:
url = "https://query1.finance.yahoo.com/v8/finance/chart/GC=F?interval=1m&range=1d"
headers = {'User-Agent': 'Mozilla/5.0'}
response = requests.get(url, headers=headers)
data = response.json()
price = data['chart']['result'][0]['meta']['regularMarketPrice']
return float(price)
except Exception as e:
return 2415.50

@app.get("/items/{item_id}")
def read_item(item_id: int, q: Optional[str] = None):
return {"item_id": item_id, "q": q}
@app.get("/")
def get_gold_signal():
live_price = get_live_gold_price()
tp = round(live_price + 10.0, 2)
sl = round(live_price - 5.0, 2)

return {
"status": "success",
"symbol": "XAUUSD",
"price": live_price,
"signal": "BUY",
"entry": live_price,
"tp": tp,
"sl": sl,
"timeframe": "M1"
}