Umerpy's picture
init commit
c4c79ba verified
from fastapi import FastAPI, HTTPException
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from typing import Literal
from datetime import datetime
from fastapi.staticfiles import StaticFiles
# Import from the same backend folder
from .signal_logic import generate_trading_signal
app = FastAPI(
title="Uzair Forex Club",
description="Binary Options Trading Signal Generator",
version="1.0.0"
)
app.mount("/static", StaticFiles(directory="backend/static"), name="static")
# Add CORS middleware
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
class SignalRequest(BaseModel):
platform: str
currency_pair: str
timeframe: str
class SignalResponse(BaseModel):
signal: Literal["BUY", "SELL"]
confidence: float
timestamp: str
next_signal_in: int
platform: str
currency_pair: str
timeframe: str
indicators: dict = None
@app.get("/")
def read_root():
"""Root endpoint"""
return {
"message": "Uzair Forex Club",
"version": "1.0.0",
"status": "active",
"endpoints": {
"signal": "/api/signal",
"platforms": "/api/platforms",
"currency_pairs": "/api/currency-pairs",
"timeframes": "/api/timeframes",
"health": "/health"
}
}
@app.post("/api/signal", response_model=SignalResponse)
async def get_signal(request: SignalRequest):
"""
Generate trading signal based on platform, currency pair, and timeframe
Parameters:
- platform: Trading platform name
- currency_pair: Currency pair to trade
- timeframe: Trading timeframe
Returns:
- SignalResponse with BUY/SELL signal and confidence
"""
try:
# Generate signal using imported logic
result = generate_trading_signal(
platform=request.platform,
currency_pair=request.currency_pair,
timeframe=request.timeframe
)
return SignalResponse(
signal=result["signal"],
confidence=result["confidence"],
timestamp=datetime.now().isoformat(),
next_signal_in=result["next_signal_in"],
platform=request.platform,
currency_pair=request.currency_pair,
timeframe=request.timeframe,
indicators=result.get("indicators", {})
)
except Exception as e:
raise HTTPException(status_code=500, detail=f"Error generating signal: {str(e)}")
@app.get("/api/platforms")
def get_platforms():
"""Get list of supported trading platforms"""
return {
"platforms": [
{"name": "QUOTEX", "icon": "πŸ”΄"},
{"name": "POCKET OPTION", "icon": "πŸ”΅"},
{"name": "BINOMO", "icon": "⚑"},
{"name": "OLYMP", "icon": "β­•"},
{"name": "IQ OPTION", "icon": "🟠"},
{"name": "EXPERT OPTION", "icon": "πŸ”·"}
]
}
@app.get("/api/currency-pairs")
def get_currency_pairs():
"""Get list of supported currency pairs"""
return {
"pairs": [
"USD/BRL (OTC)",
"USD/BRL (CTC)",
"USD/ARS (OTC)",
"USD/DZD (OTC)",
"USD/COP (OTC)",
"CAD/CHF (OTC)",
"USD/BDT (OTC)",
"USD/PKR (OTC)",
"EUR/USD (OTC)",
"GBP/USD (OTC)",
"USD/JPY (OTC)",
"AUD/USD (OTC)"
]
}
@app.get("/api/timeframes")
def get_timeframes():
"""Get list of supported timeframes"""
return {
"timeframes": [
{"value": "5s", "label": "5 seconds"},
{"value": "10s", "label": "10 seconds"},
{"value": "15s", "label": "15 seconds"},
{"value": "30s", "label": "30 seconds"},
{"value": "1m", "label": "1 minute"},
{"value": "2m", "label": "2 minutes"},
{"value": "5m", "label": "5 mintes"}
]
}
@app.get("/health")
def health_check():
"""Health check endpoint"""
return {
"status": "healthy",
"timestamp": datetime.now().isoformat(),
"service": "Uzair Fortex Club API"
}
@app.get("/api/stats")
def get_stats():
"""Get API statistics (placeholder)"""
return {
"total_signals": 0,
"accuracy": 0.0,
"uptime": "100%"
}
if __name__ == "__main__":
import uvicorn
print("πŸš€ Starting Uzair Forex Club API Server...")
print("πŸ“‘ API Documentation: http://localhost:8000/docs")
print("πŸ”— API Endpoint: http://localhost:8000")
# st.image("http://127.0.0.1:8000/static/mylogo.png", width=150)
uvicorn.run(app, host="0.0.0.0", port=8000, reload=True)