Spaces:
Running
Running
File size: 4,974 Bytes
c4c79ba | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | 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) |