Spaces:
Sleeping
Sleeping
Commit ·
cb756bf
0
Parent(s):
feat: update project
Browse files- .gitignore +8 -0
- README.md +116 -0
- backend/app.py +546 -0
- backend/intraday_model.py +465 -0
- backend/model.py +192 -0
- backend/sentiment.py +124 -0
- backend/step4_install.sh +12 -0
- backend/stock_data.py +313 -0
- backend/test_intraday_signal.py +137 -0
- backend/trader.py +619 -0
- frontend/app.js +1057 -0
- frontend/backend_wallet_api.py +137 -0
- frontend/index.html +414 -0
- frontend/style.css +2019 -0
- frontend/wallet-styles.css +363 -0
- frontend/wallet.html +90 -0
.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__pycache__/
|
| 2 |
+
*.pyc
|
| 3 |
+
venv/
|
| 4 |
+
.env
|
| 5 |
+
trained_models/
|
| 6 |
+
portfolio.json
|
| 7 |
+
node_modules/
|
| 8 |
+
.DS_Store
|
README.md
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 📈 StockSense AI — AI-Powered Stock Market Prediction
|
| 2 |
+
|
| 3 |
+
> **Hackathon Project** | Built in 48 hours
|
| 4 |
+
|
| 5 |
+
##🎤 Elevator Pitch (30 seconds)
|
| 6 |
+
|
| 7 |
+
*"StockSense AI uses deep learning and NLP to predict stock prices 5 days ahead.
|
| 8 |
+
Enter any ticker — our LSTM model analyzes 2 years of market data and technical
|
| 9 |
+
indicators, while FinBERT reads the latest financial news to gauge market
|
| 10 |
+
sentiment. You get an interactive chart with predictions, a confidence score,
|
| 11 |
+
a risk level, and a clear sentiment breakdown — all in seconds."*
|
| 12 |
+
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
## 🚀 Quick Start
|
| 16 |
+
|
| 17 |
+
### Prerequisites
|
| 18 |
+
- Python 3.10+
|
| 19 |
+
- Node.js (optional – only if you want a dev server for frontend)
|
| 20 |
+
- ~2 GB disk for FinBERT model weights (auto-downloaded)
|
| 21 |
+
|
| 22 |
+
### 1. Backend Setup
|
| 23 |
+
|
| 24 |
+
```bash
|
| 25 |
+
cd backend
|
| 26 |
+
python -m venv venv
|
| 27 |
+
source venv/bin/activate # Windows: venv\Scripts\activate
|
| 28 |
+
pip install -r requirements.txt
|
| 29 |
+
uvicorn app:app --reload --port 8000
|
| 30 |
+
```
|
| 31 |
+
|
| 32 |
+
The API will be live at **http://localhost:8000**.
|
| 33 |
+
|
| 34 |
+
### 2. Frontend Setup
|
| 35 |
+
|
| 36 |
+
Simply open `frontend/index.html` in your browser, **or** serve it:
|
| 37 |
+
|
| 38 |
+
```bash
|
| 39 |
+
cd frontend
|
| 40 |
+
python -m http.server 3000
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
Then visit **http://localhost:3000**.
|
| 44 |
+
|
| 45 |
+
---
|
| 46 |
+
|
| 47 |
+
## 🔗 API Endpoints
|
| 48 |
+
|
| 49 |
+
| Method | Endpoint | Description |
|
| 50 |
+
|--------|----------------------------|------------------------------------|
|
| 51 |
+
| GET | `/api/stock/{ticker}` | Historical data + indicators |
|
| 52 |
+
| GET | `/api/predict/{ticker}` | LSTM 5-day price prediction |
|
| 53 |
+
| GET | `/api/sentiment/{ticker}` | FinBERT news sentiment analysis |
|
| 54 |
+
| GET | `/api/summary/{ticker}` | Combined analysis (all of above) |
|
| 55 |
+
|
| 56 |
+
---
|
| 57 |
+
|
| 58 |
+
## 🏗️ Architecture
|
| 59 |
+
|
| 60 |
+
```
|
| 61 |
+
User → React/HTML Frontend → FastAPI Backend
|
| 62 |
+
├── yfinance (stock data)
|
| 63 |
+
├── ta (technical indicators)
|
| 64 |
+
├── PyTorch LSTM (price prediction)
|
| 65 |
+
└── FinBERT (sentiment analysis)
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## 🧠 ML Pipeline
|
| 71 |
+
|
| 72 |
+
1. **Data**: 2 years of daily OHLCV via Yahoo Finance
|
| 73 |
+
2. **Features**: Close price (normalized via MinMaxScaler)
|
| 74 |
+
3. **Model**: 2-layer LSTM (64 hidden units) → FC → 5-day output
|
| 75 |
+
4. **Training**: 30 epochs, Adam optimizer, MSE loss, 85/15 train/test split
|
| 76 |
+
5. **Inference**: Last 60-day window → next 5 closing prices
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## ☁️ Deployment (Optional)
|
| 81 |
+
|
| 82 |
+
### Docker
|
| 83 |
+
|
| 84 |
+
```dockerfile
|
| 85 |
+
FROM python:3.11-slim
|
| 86 |
+
WORKDIR /app
|
| 87 |
+
COPY backend/ .
|
| 88 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 89 |
+
EXPOSE 8000
|
| 90 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]
|
| 91 |
+
```
|
| 92 |
+
|
| 93 |
+
```bash
|
| 94 |
+
docker build -t stocksense-ai .
|
| 95 |
+
docker run -p 8000:8000 stocksense-ai
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
### Cloud (Render / Railway / Fly.io)
|
| 99 |
+
1. Push to GitHub
|
| 100 |
+
2. Connect repo on Render → set build command: `pip install -r requirements.txt`
|
| 101 |
+
3. Set start command: `uvicorn app:app --host 0.0.0.0 --port 8000`
|
| 102 |
+
|
| 103 |
+
---
|
| 104 |
+
|
| 105 |
+
## ⚠️ Disclaimer
|
| 106 |
+
|
| 107 |
+
This project is for **educational and hackathon demonstration purposes only**.
|
| 108 |
+
Stock market predictions generated by this tool are **not financial advice**.
|
| 109 |
+
Past performance does not guarantee future results. Always consult a qualified
|
| 110 |
+
financial advisor before making investment decisions.
|
| 111 |
+
|
| 112 |
+
---
|
| 113 |
+
|
| 114 |
+
## 📜 License
|
| 115 |
+
|
| 116 |
+
MIT — feel free to fork and improve!
|
backend/app.py
ADDED
|
@@ -0,0 +1,546 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
from fastapi import FastAPI, HTTPException, Query
|
| 3 |
+
from pydantic import BaseModel
|
| 4 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 5 |
+
from stock_data import fetch_stock_data, add_technical_indicators, get_stock_info, fetch_live_price, fetch_chart_data
|
| 6 |
+
from sentiment import analyze_sentiment
|
| 7 |
+
from model import train_and_predict
|
| 8 |
+
from intraday_model import generate_intraday_signal
|
| 9 |
+
from trader import (
|
| 10 |
+
get_portfolio, reset_portfolio, toggle_bot,
|
| 11 |
+
evaluate_trade_signal, execute_sell, execute_buy, check_position,
|
| 12 |
+
compute_dynamic_levels, detect_market_regime,
|
| 13 |
+
add_to_balance, withdraw_from_balance, get_wallet_transactions,
|
| 14 |
+
)
|
| 15 |
+
import concurrent.futures
|
| 16 |
+
|
| 17 |
+
app = FastAPI(title="StockSense AI", version="3.0.0")
|
| 18 |
+
|
| 19 |
+
app.add_middleware(
|
| 20 |
+
CORSMiddleware,
|
| 21 |
+
allow_origins=["*"],
|
| 22 |
+
allow_methods=["*"],
|
| 23 |
+
allow_headers=["*"],
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
@app.get("/")
|
| 28 |
+
def root():
|
| 29 |
+
return {"message": "StockSense AI API v3.0 is running 🚀"}
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
@app.get("/api/stock/{ticker}")
|
| 33 |
+
def get_stock(ticker: str):
|
| 34 |
+
try:
|
| 35 |
+
df = fetch_stock_data(ticker)
|
| 36 |
+
df = add_technical_indicators(df)
|
| 37 |
+
records = df.tail(200).to_dict(orient="records")
|
| 38 |
+
for r in records:
|
| 39 |
+
if "Date" in r:
|
| 40 |
+
r["Date"] = str(r["Date"])
|
| 41 |
+
info = get_stock_info(ticker)
|
| 42 |
+
return {"info": info, "data": records}
|
| 43 |
+
except Exception as e:
|
| 44 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
@app.get("/api/live/{ticker}")
|
| 48 |
+
def live_price(ticker: str):
|
| 49 |
+
try:
|
| 50 |
+
return fetch_live_price(ticker)
|
| 51 |
+
except Exception as e:
|
| 52 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@app.get("/api/chart/{ticker}")
|
| 56 |
+
def chart_data(ticker: str, timeframe: str = Query("1mo", regex="^(1d|5d|1wk|1mo|3mo|6mo|1y|2y)$")):
|
| 57 |
+
try:
|
| 58 |
+
data = fetch_chart_data(ticker, timeframe)
|
| 59 |
+
return {"ticker": ticker, "timeframe": timeframe, "data": data}
|
| 60 |
+
except Exception as e:
|
| 61 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
@app.get("/api/market-indices")
|
| 65 |
+
def get_market_indices():
|
| 66 |
+
import yfinance as yf
|
| 67 |
+
indices = {"NIFTY 50": "^NSEI", "SENSEX": "^BSESN"}
|
| 68 |
+
results = []
|
| 69 |
+
for name, symbol in indices.items():
|
| 70 |
+
try:
|
| 71 |
+
stock = yf.Ticker(symbol)
|
| 72 |
+
info = stock.info or {}
|
| 73 |
+
hist = stock.history(period="5d")
|
| 74 |
+
price = 0
|
| 75 |
+
prev = 0
|
| 76 |
+
if len(hist) >= 2:
|
| 77 |
+
price = round(float(hist["Close"].iloc[-1]), 2)
|
| 78 |
+
prev = round(float(hist["Close"].iloc[-2]), 2)
|
| 79 |
+
elif len(hist) == 1:
|
| 80 |
+
price = round(float(hist["Close"].iloc[-1]), 2)
|
| 81 |
+
prev = info.get("previousClose", info.get("regularMarketPreviousClose", price))
|
| 82 |
+
else:
|
| 83 |
+
price = info.get("regularMarketPrice", info.get("previousClose", 0))
|
| 84 |
+
prev = info.get("previousClose", info.get("regularMarketPreviousClose", price))
|
| 85 |
+
if not price and info:
|
| 86 |
+
price = info.get("regularMarketPrice", info.get("previousClose", 0))
|
| 87 |
+
if not prev or prev == price:
|
| 88 |
+
prev = info.get("previousClose", info.get("regularMarketPreviousClose", prev))
|
| 89 |
+
change = round(price - prev, 2)
|
| 90 |
+
change_pct = round((change / prev) * 100, 2) if prev else 0
|
| 91 |
+
results.append({
|
| 92 |
+
"name": name, "symbol": symbol, "price": price,
|
| 93 |
+
"change": change, "change_pct": change_pct,
|
| 94 |
+
"direction": "up" if change >= 0 else "down",
|
| 95 |
+
})
|
| 96 |
+
except Exception:
|
| 97 |
+
results.append({"name": name, "symbol": symbol, "price": 0, "change": 0, "change_pct": 0, "direction": "up"})
|
| 98 |
+
return {"indices": results}
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
@app.get("/api/predict/{ticker}")
|
| 102 |
+
def predict(ticker: str):
|
| 103 |
+
try:
|
| 104 |
+
df = fetch_stock_data(ticker)
|
| 105 |
+
df = add_technical_indicators(df)
|
| 106 |
+
result = train_and_predict(df)
|
| 107 |
+
return {"ticker": ticker, **result}
|
| 108 |
+
except Exception as e:
|
| 109 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
@app.get("/api/sentiment/{ticker}")
|
| 113 |
+
def sentiment(ticker: str):
|
| 114 |
+
try:
|
| 115 |
+
return analyze_sentiment(ticker)
|
| 116 |
+
except Exception as e:
|
| 117 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
@app.get("/api/summary/{ticker}")
|
| 121 |
+
def summary(ticker: str):
|
| 122 |
+
try:
|
| 123 |
+
info = get_stock_info(ticker)
|
| 124 |
+
df = fetch_stock_data(ticker)
|
| 125 |
+
df_ind = add_technical_indicators(df)
|
| 126 |
+
prediction = train_and_predict(df_ind)
|
| 127 |
+
sent = analyze_sentiment(ticker)
|
| 128 |
+
|
| 129 |
+
latest = df_ind.iloc[-1]
|
| 130 |
+
indicators = {
|
| 131 |
+
"RSI": round(float(latest["RSI"]), 2),
|
| 132 |
+
"MACD": round(float(latest["MACD"]), 4),
|
| 133 |
+
"MACD_Signal": round(float(latest["MACD_Signal"]), 4),
|
| 134 |
+
"SMA_20": round(float(latest["SMA_20"]), 2),
|
| 135 |
+
"SMA_50": round(float(latest["SMA_50"]), 2),
|
| 136 |
+
"BB_Upper": round(float(latest["BB_Upper"]), 2),
|
| 137 |
+
"BB_Lower": round(float(latest["BB_Lower"]), 2),
|
| 138 |
+
"BB_Width": round(float(latest["BB_Width"]), 4),
|
| 139 |
+
"ATR": round(float(latest["ATR"]), 2),
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
return {
|
| 143 |
+
"info": info,
|
| 144 |
+
"indicators": indicators,
|
| 145 |
+
"prediction": prediction,
|
| 146 |
+
"sentiment": sent,
|
| 147 |
+
}
|
| 148 |
+
except Exception as e:
|
| 149 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 150 |
+
|
| 151 |
+
|
| 152 |
+
STOCK_DATABASE = [
|
| 153 |
+
{"ticker": "RELIANCE.NS", "name": "Reliance Industries"},
|
| 154 |
+
{"ticker": "TCS.NS", "name": "Tata Consultancy Services"},
|
| 155 |
+
{"ticker": "INFY.NS", "name": "Infosys"},
|
| 156 |
+
{"ticker": "HDFCBANK.NS", "name": "HDFC Bank"},
|
| 157 |
+
{"ticker": "ICICIBANK.NS", "name": "ICICI Bank"},
|
| 158 |
+
{"ticker": "BHARTIARTL.NS", "name": "Bharti Airtel"},
|
| 159 |
+
{"ticker": "SBIN.NS", "name": "State Bank of India"},
|
| 160 |
+
{"ticker": "HINDUNILVR.NS", "name": "Hindustan Unilever"},
|
| 161 |
+
{"ticker": "ITC.NS", "name": "ITC Limited"},
|
| 162 |
+
{"ticker": "LT.NS", "name": "Larsen & Toubro"},
|
| 163 |
+
{"ticker": "KOTAKBANK.NS", "name": "Kotak Mahindra Bank"},
|
| 164 |
+
{"ticker": "TATAMOTORS.NS", "name": "Tata Motors"},
|
| 165 |
+
{"ticker": "WIPRO.NS", "name": "Wipro"},
|
| 166 |
+
{"ticker": "MARUTI.NS", "name": "Maruti Suzuki India"},
|
| 167 |
+
{"ticker": "ADANIENT.NS", "name": "Adani Enterprises"},
|
| 168 |
+
{"ticker": "TATASTEEL.NS", "name": "Tata Steel"},
|
| 169 |
+
{"ticker": "TATASILV.NS", "name": "Tata Silver ETF"},
|
| 170 |
+
{"ticker": "TATAPOWER.NS", "name": "Tata Power Company"},
|
| 171 |
+
{"ticker": "TATACOMM.NS", "name": "Tata Communications"},
|
| 172 |
+
{"ticker": "TATAELXSI.NS", "name": "Tata Elxsi"},
|
| 173 |
+
{"ticker": "TATACHEM.NS", "name": "Tata Chemicals"},
|
| 174 |
+
{"ticker": "TATACONSUM.NS", "name": "Tata Consumer Products"},
|
| 175 |
+
{"ticker": "TITAN.NS", "name": "Titan Company"},
|
| 176 |
+
{"ticker": "SUNPHARMA.NS", "name": "Sun Pharmaceutical"},
|
| 177 |
+
{"ticker": "HCLTECH.NS", "name": "HCL Technologies"},
|
| 178 |
+
{"ticker": "BAJFINANCE.NS", "name": "Bajaj Finance"},
|
| 179 |
+
{"ticker": "BAJAJFINSV.NS", "name": "Bajaj Finserv"},
|
| 180 |
+
{"ticker": "ASIANPAINT.NS", "name": "Asian Paints"},
|
| 181 |
+
{"ticker": "AXISBANK.NS", "name": "Axis Bank"},
|
| 182 |
+
{"ticker": "ULTRACEMCO.NS", "name": "UltraTech Cement"},
|
| 183 |
+
{"ticker": "NESTLEIND.NS", "name": "Nestle India"},
|
| 184 |
+
{"ticker": "NTPC.NS", "name": "NTPC Limited"},
|
| 185 |
+
{"ticker": "POWERGRID.NS", "name": "Power Grid Corporation"},
|
| 186 |
+
{"ticker": "ONGC.NS", "name": "Oil & Natural Gas Corporation"},
|
| 187 |
+
{"ticker": "COALINDIA.NS", "name": "Coal India"},
|
| 188 |
+
{"ticker": "JSWSTEEL.NS", "name": "JSW Steel"},
|
| 189 |
+
{"ticker": "TECHM.NS", "name": "Tech Mahindra"},
|
| 190 |
+
{"ticker": "DRREDDY.NS", "name": "Dr. Reddy's Laboratories"},
|
| 191 |
+
{"ticker": "CIPLA.NS", "name": "Cipla"},
|
| 192 |
+
{"ticker": "DIVISLAB.NS", "name": "Divi's Laboratories"},
|
| 193 |
+
{"ticker": "EICHERMOT.NS", "name": "Eicher Motors"},
|
| 194 |
+
{"ticker": "HEROMOTOCO.NS", "name": "Hero MotoCorp"},
|
| 195 |
+
{"ticker": "BAJAJ-AUTO.NS", "name": "Bajaj Auto"},
|
| 196 |
+
{"ticker": "M&M.NS", "name": "Mahindra & Mahindra"},
|
| 197 |
+
{"ticker": "BRITANNIA.NS", "name": "Britannia Industries"},
|
| 198 |
+
{"ticker": "DABUR.NS", "name": "Dabur India"},
|
| 199 |
+
{"ticker": "GODREJCP.NS", "name": "Godrej Consumer Products"},
|
| 200 |
+
{"ticker": "PIDILITIND.NS", "name": "Pidilite Industries"},
|
| 201 |
+
{"ticker": "BERGEPAINT.NS", "name": "Berger Paints India"},
|
| 202 |
+
{"ticker": "HAVELLS.NS", "name": "Havells India"},
|
| 203 |
+
{"ticker": "SIEMENS.NS", "name": "Siemens India"},
|
| 204 |
+
{"ticker": "ABB.NS", "name": "ABB India"},
|
| 205 |
+
{"ticker": "ADANIPORTS.NS", "name": "Adani Ports"},
|
| 206 |
+
{"ticker": "ADANIGREEN.NS", "name": "Adani Green Energy"},
|
| 207 |
+
{"ticker": "GRASIM.NS", "name": "Grasim Industries"},
|
| 208 |
+
{"ticker": "INDUSINDBK.NS", "name": "IndusInd Bank"},
|
| 209 |
+
{"ticker": "SBILIFE.NS", "name": "SBI Life Insurance"},
|
| 210 |
+
{"ticker": "HDFCLIFE.NS", "name": "HDFC Life Insurance"},
|
| 211 |
+
{"ticker": "APOLLOHOSP.NS", "name": "Apollo Hospitals"},
|
| 212 |
+
{"ticker": "ZOMATO.NS", "name": "Zomato"},
|
| 213 |
+
{"ticker": "PAYTM.NS", "name": "One97 Communications (Paytm)"},
|
| 214 |
+
{"ticker": "NYKAA.NS", "name": "FSN E-Commerce (Nykaa)"},
|
| 215 |
+
{"ticker": "DMART.NS", "name": "Avenue Supermarts (DMart)"},
|
| 216 |
+
{"ticker": "IRCTC.NS", "name": "IRCTC"},
|
| 217 |
+
{"ticker": "HAL.NS", "name": "Hindustan Aeronautics"},
|
| 218 |
+
{"ticker": "BEL.NS", "name": "Bharat Electronics"},
|
| 219 |
+
{"ticker": "BANKBARODA.NS", "name": "Bank of Baroda"},
|
| 220 |
+
{"ticker": "PNB.NS", "name": "Punjab National Bank"},
|
| 221 |
+
{"ticker": "CANBK.NS", "name": "Canara Bank"},
|
| 222 |
+
{"ticker": "IOC.NS", "name": "Indian Oil Corporation"},
|
| 223 |
+
{"ticker": "BPCL.NS", "name": "Bharat Petroleum"},
|
| 224 |
+
{"ticker": "HINDPETRO.NS", "name": "Hindustan Petroleum"},
|
| 225 |
+
{"ticker": "VEDL.NS", "name": "Vedanta Limited"},
|
| 226 |
+
{"ticker": "HINDALCO.NS", "name": "Hindalco Industries"},
|
| 227 |
+
{"ticker": "GOLDIAM.NS", "name": "Goldiam International"},
|
| 228 |
+
{"ticker": "GOLDBEES.NS", "name": "Nippon India Gold ETF"},
|
| 229 |
+
{"ticker": "SILVEREES.NS", "name": "Nippon India Silver ETF"},
|
| 230 |
+
]
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
@app.get("/api/search")
|
| 234 |
+
def search_stocks(q: str = Query("", min_length=1)):
|
| 235 |
+
query = q.strip().upper()
|
| 236 |
+
if not query:
|
| 237 |
+
return {"results": []}
|
| 238 |
+
|
| 239 |
+
matches = []
|
| 240 |
+
for stock in STOCK_DATABASE:
|
| 241 |
+
ticker_upper = stock["ticker"].upper()
|
| 242 |
+
name_upper = stock["name"].upper()
|
| 243 |
+
if query in ticker_upper or query in name_upper:
|
| 244 |
+
matches.append(stock)
|
| 245 |
+
|
| 246 |
+
matches.sort(key=lambda s: (
|
| 247 |
+
0 if s["ticker"].upper().startswith(query) else
|
| 248 |
+
1 if s["name"].upper().startswith(query) else 2
|
| 249 |
+
))
|
| 250 |
+
|
| 251 |
+
return {"results": matches[:10]}
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
SCAN_TICKERS = [
|
| 255 |
+
"RELIANCE.NS", "TCS.NS", "INFY.NS", "HDFCBANK.NS", "ICICIBANK.NS",
|
| 256 |
+
"BHARTIARTL.NS", "SBIN.NS", "HINDUNILVR.NS", "ITC.NS", "LT.NS",
|
| 257 |
+
"KOTAKBANK.NS", "TATAMOTORS.NS", "WIPRO.NS", "MARUTI.NS", "ADANIENT.NS",
|
| 258 |
+
]
|
| 259 |
+
|
| 260 |
+
|
| 261 |
+
def _analyze_one(ticker: str) -> dict | None:
|
| 262 |
+
try:
|
| 263 |
+
info = get_stock_info(ticker)
|
| 264 |
+
df = fetch_stock_data(ticker, period="3mo")
|
| 265 |
+
df = add_technical_indicators(df)
|
| 266 |
+
latest = df.iloc[-1]
|
| 267 |
+
|
| 268 |
+
rsi = float(latest["RSI"])
|
| 269 |
+
macd = float(latest["MACD"])
|
| 270 |
+
macd_signal = float(latest["MACD_Signal"])
|
| 271 |
+
sma_20 = float(latest["SMA_20"])
|
| 272 |
+
price = float(latest["Close"])
|
| 273 |
+
|
| 274 |
+
score = 50
|
| 275 |
+
if rsi < 30: score += 20
|
| 276 |
+
elif rsi < 40: score += 10
|
| 277 |
+
elif rsi > 70: score -= 15
|
| 278 |
+
elif rsi > 60: score -= 5
|
| 279 |
+
|
| 280 |
+
if macd > macd_signal: score += 15
|
| 281 |
+
else: score -= 10
|
| 282 |
+
|
| 283 |
+
if price > sma_20: score += 10
|
| 284 |
+
else: score -= 10
|
| 285 |
+
|
| 286 |
+
vol = float(latest["Volume"])
|
| 287 |
+
vol_avg = float(latest["Volume_SMA_20"])
|
| 288 |
+
if vol_avg > 0 and vol > vol_avg * 1.3: score += 10
|
| 289 |
+
|
| 290 |
+
score = max(0, min(100, score))
|
| 291 |
+
|
| 292 |
+
if score >= 70: signal_text = "🟢 Strong Buy"
|
| 293 |
+
elif score >= 55: signal_text = "🔵 Buy"
|
| 294 |
+
elif score >= 40: signal_text = "🟡 Hold"
|
| 295 |
+
else: signal_text = "🔴 Sell"
|
| 296 |
+
|
| 297 |
+
prev_close = float(df.iloc[-2]["Close"])
|
| 298 |
+
change_pct = round(((price - prev_close) / prev_close) * 100, 2)
|
| 299 |
+
|
| 300 |
+
return {
|
| 301 |
+
"ticker": ticker, "name": info.get("name", ticker),
|
| 302 |
+
"price": round(price, 2), "change_pct": change_pct,
|
| 303 |
+
"rsi": round(rsi, 2), "score": score,
|
| 304 |
+
"signal": signal_text, "currency": info.get("currency", "INR"),
|
| 305 |
+
}
|
| 306 |
+
except Exception:
|
| 307 |
+
return None
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
@app.get("/api/high-potential")
|
| 311 |
+
def high_potential():
|
| 312 |
+
results = []
|
| 313 |
+
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
|
| 314 |
+
futures = {executor.submit(_analyze_one, t): t for t in SCAN_TICKERS}
|
| 315 |
+
for future in concurrent.futures.as_completed(futures):
|
| 316 |
+
result = future.result()
|
| 317 |
+
if result:
|
| 318 |
+
results.append(result)
|
| 319 |
+
results.sort(key=lambda x: x["score"], reverse=True)
|
| 320 |
+
return {"stocks": results, "count": len(results)}
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
@app.get("/api/trade/portfolio")
|
| 324 |
+
def trade_portfolio():
|
| 325 |
+
try:
|
| 326 |
+
portfolio = get_portfolio()
|
| 327 |
+
total_unrealized = 0
|
| 328 |
+
for ticker, pos in portfolio["positions"].items():
|
| 329 |
+
try:
|
| 330 |
+
live = fetch_live_price(ticker)
|
| 331 |
+
current = live["price"]
|
| 332 |
+
pnl = (current - pos["buy_price"]) * pos["shares"]
|
| 333 |
+
pos["current_price"] = current
|
| 334 |
+
pos["unrealized_pnl"] = round(pnl, 2)
|
| 335 |
+
pos["pnl_pct"] = round(((current - pos["buy_price"]) / pos["buy_price"]) * 100, 2)
|
| 336 |
+
total_unrealized += pnl
|
| 337 |
+
except Exception:
|
| 338 |
+
pos["current_price"] = pos["buy_price"]
|
| 339 |
+
pos["unrealized_pnl"] = 0
|
| 340 |
+
pos["pnl_pct"] = 0
|
| 341 |
+
|
| 342 |
+
portfolio["total_unrealized_pnl"] = round(total_unrealized, 2)
|
| 343 |
+
portfolio["total_value"] = round(portfolio["balance"] + total_unrealized + sum(
|
| 344 |
+
p["shares"] * p.get("current_price", p["buy_price"]) for p in portfolio["positions"].values()
|
| 345 |
+
), 2)
|
| 346 |
+
|
| 347 |
+
portfolio["total_realized_pnl"] = round(
|
| 348 |
+
sum(t["profit"] for t in portfolio["trade_history"]), 2
|
| 349 |
+
)
|
| 350 |
+
portfolio["total_trades"] = len(portfolio["trade_history"])
|
| 351 |
+
portfolio["winning_trades"] = sum(1 for t in portfolio["trade_history"] if t["profit"] > 0)
|
| 352 |
+
portfolio["losing_trades"] = sum(1 for t in portfolio["trade_history"] if t["profit"] <= 0)
|
| 353 |
+
|
| 354 |
+
if portfolio["total_trades"] > 0:
|
| 355 |
+
portfolio["win_rate"] = round(
|
| 356 |
+
(portfolio["winning_trades"] / portfolio["total_trades"]) * 100, 1
|
| 357 |
+
)
|
| 358 |
+
else:
|
| 359 |
+
portfolio["win_rate"] = 0
|
| 360 |
+
|
| 361 |
+
return portfolio
|
| 362 |
+
except Exception as e:
|
| 363 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
@app.post("/api/trade/reset")
|
| 367 |
+
def trade_reset():
|
| 368 |
+
return reset_portfolio()
|
| 369 |
+
|
| 370 |
+
|
| 371 |
+
@app.post("/api/trade/toggle")
|
| 372 |
+
def trade_toggle():
|
| 373 |
+
return toggle_bot()
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
@app.post("/api/trade/execute/{ticker}")
|
| 377 |
+
def trade_execute(ticker: str):
|
| 378 |
+
try:
|
| 379 |
+
live = fetch_live_price(ticker)
|
| 380 |
+
current_price = live["price"]
|
| 381 |
+
|
| 382 |
+
df = fetch_stock_data(ticker)
|
| 383 |
+
df = add_technical_indicators(df)
|
| 384 |
+
prediction = train_and_predict(df)
|
| 385 |
+
|
| 386 |
+
latest = df.iloc[-1]
|
| 387 |
+
indicators = {
|
| 388 |
+
"RSI": float(latest["RSI"]),
|
| 389 |
+
"MACD": float(latest["MACD"]),
|
| 390 |
+
"MACD_Signal": float(latest["MACD_Signal"]),
|
| 391 |
+
"SMA_20": float(latest["SMA_20"]),
|
| 392 |
+
"SMA_50": float(latest["SMA_50"]),
|
| 393 |
+
"price": current_price,
|
| 394 |
+
}
|
| 395 |
+
|
| 396 |
+
try:
|
| 397 |
+
sent = analyze_sentiment(ticker)
|
| 398 |
+
sentiment_score = sent.get("overall_score", 0.0)
|
| 399 |
+
except Exception:
|
| 400 |
+
sentiment_score = 0.0
|
| 401 |
+
|
| 402 |
+
signal = evaluate_trade_signal(
|
| 403 |
+
ticker=ticker,
|
| 404 |
+
current_price=current_price,
|
| 405 |
+
predicted_prices=prediction["predicted_prices"],
|
| 406 |
+
confidence=prediction["confidence"],
|
| 407 |
+
indicators=indicators,
|
| 408 |
+
sentiment_score=sentiment_score,
|
| 409 |
+
)
|
| 410 |
+
|
| 411 |
+
signal["live"] = live
|
| 412 |
+
signal["prediction_details"] = prediction
|
| 413 |
+
return signal
|
| 414 |
+
|
| 415 |
+
except Exception as e:
|
| 416 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
@app.post("/api/trade/sell/{ticker}")
|
| 420 |
+
def trade_force_sell(ticker: str):
|
| 421 |
+
try:
|
| 422 |
+
live = fetch_live_price(ticker)
|
| 423 |
+
result = execute_sell(ticker, live["price"], "Manual sell (forced)")
|
| 424 |
+
return result
|
| 425 |
+
except Exception as e:
|
| 426 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 427 |
+
|
| 428 |
+
|
| 429 |
+
@app.get("/api/trade/check/{ticker}")
|
| 430 |
+
def trade_check(ticker: str):
|
| 431 |
+
try:
|
| 432 |
+
live = fetch_live_price(ticker)
|
| 433 |
+
result = check_position(ticker, live["price"])
|
| 434 |
+
result["live"] = live
|
| 435 |
+
return result
|
| 436 |
+
except Exception as e:
|
| 437 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
@app.get("/api/trade/intraday-signal/{ticker}")
|
| 441 |
+
def trade_intraday_signal(ticker: str):
|
| 442 |
+
"""Single-stock intraday signal using XGBoost pipeline."""
|
| 443 |
+
try:
|
| 444 |
+
signal = generate_intraday_signal(ticker)
|
| 445 |
+
return signal
|
| 446 |
+
except Exception as e:
|
| 447 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
@app.post("/api/trade/auto-scan")
|
| 451 |
+
def trade_auto_scan():
|
| 452 |
+
"""Auto-scan using intraday XGBoost pipeline with dynamic SL/TP."""
|
| 453 |
+
try:
|
| 454 |
+
portfolio = get_portfolio()
|
| 455 |
+
if not portfolio["bot_active"]:
|
| 456 |
+
return {"status": "inactive", "message": "Bot is OFF. Toggle it on first."}
|
| 457 |
+
|
| 458 |
+
results = []
|
| 459 |
+
|
| 460 |
+
# 1. Check existing positions for SL/TP/trailing triggers
|
| 461 |
+
for ticker in list(portfolio["positions"].keys()):
|
| 462 |
+
try:
|
| 463 |
+
live = fetch_live_price(ticker)
|
| 464 |
+
check = check_position(ticker, live["price"])
|
| 465 |
+
if check["action"] == "sell":
|
| 466 |
+
sell_result = execute_sell(ticker, live["price"], check["reason"])
|
| 467 |
+
results.append({"ticker": ticker, "action": "SELL", "result": sell_result})
|
| 468 |
+
except Exception:
|
| 469 |
+
continue
|
| 470 |
+
|
| 471 |
+
# 2. Scan for new entries using intraday XGBoost signals
|
| 472 |
+
for scan_ticker in SCAN_TICKERS[:8]:
|
| 473 |
+
if scan_ticker in portfolio["positions"]:
|
| 474 |
+
continue
|
| 475 |
+
try:
|
| 476 |
+
signal = generate_intraday_signal(scan_ticker)
|
| 477 |
+
|
| 478 |
+
if signal.get("action") == "BUY":
|
| 479 |
+
buy_result = execute_buy(
|
| 480 |
+
ticker=scan_ticker,
|
| 481 |
+
current_price=signal["entry_price"],
|
| 482 |
+
predicted_prices=[signal["tp1_price"]],
|
| 483 |
+
confidence=signal["confidence"],
|
| 484 |
+
sl_price=signal["sl_price"],
|
| 485 |
+
tp1_price=signal["tp1_price"],
|
| 486 |
+
tp2_price=signal.get("tp2_price"),
|
| 487 |
+
regime=signal["regime"],
|
| 488 |
+
)
|
| 489 |
+
signal["trade_result"] = buy_result
|
| 490 |
+
|
| 491 |
+
results.append(signal)
|
| 492 |
+
except Exception:
|
| 493 |
+
continue
|
| 494 |
+
|
| 495 |
+
return {
|
| 496 |
+
"status": "completed",
|
| 497 |
+
"scanned": len(results),
|
| 498 |
+
"results": results,
|
| 499 |
+
"portfolio": get_portfolio(),
|
| 500 |
+
}
|
| 501 |
+
except Exception as e:
|
| 502 |
+
raise HTTPException(status_code=400, detail=str(e))
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
# ── Wallet API ────────────────────────────────────────────────────────────────
|
| 506 |
+
|
| 507 |
+
class AddMoneyRequest(BaseModel):
|
| 508 |
+
payment_id: str
|
| 509 |
+
amount: float
|
| 510 |
+
|
| 511 |
+
class WithdrawRequest(BaseModel):
|
| 512 |
+
amount: float
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
@app.get("/api/wallet/balance")
|
| 516 |
+
def wallet_balance():
|
| 517 |
+
"""Return wallet balance (= portfolio cash balance)."""
|
| 518 |
+
portfolio = get_portfolio()
|
| 519 |
+
return {"balance": portfolio["balance"], "status": "success"}
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
@app.post("/api/wallet/add")
|
| 523 |
+
def wallet_add(req: AddMoneyRequest):
|
| 524 |
+
"""Credit wallet after Razorpay payment."""
|
| 525 |
+
if req.amount <= 0:
|
| 526 |
+
raise HTTPException(status_code=400, detail="Invalid amount")
|
| 527 |
+
result = add_to_balance(req.amount, req.payment_id)
|
| 528 |
+
return result
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
@app.post("/api/wallet/withdraw")
|
| 532 |
+
def wallet_withdraw(req: WithdrawRequest):
|
| 533 |
+
"""Withdraw from wallet (portfolio cash)."""
|
| 534 |
+
if req.amount <= 0:
|
| 535 |
+
raise HTTPException(status_code=400, detail="Invalid amount")
|
| 536 |
+
result = withdraw_from_balance(req.amount)
|
| 537 |
+
if result["status"] == "error":
|
| 538 |
+
raise HTTPException(status_code=400, detail=result["message"])
|
| 539 |
+
return result
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
@app.get("/api/wallet/transactions")
|
| 543 |
+
def wallet_transactions():
|
| 544 |
+
"""Return wallet transaction history."""
|
| 545 |
+
txns = get_wallet_transactions()
|
| 546 |
+
return {"transactions": txns, "status": "success"}
|
backend/intraday_model.py
ADDED
|
@@ -0,0 +1,465 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Intraday XGBoost model for short-term price movement forecasting.
|
| 3 |
+
Predicts next 3-5 bar (minute) returns using tabular features.
|
| 4 |
+
Used exclusively by the Auto Trade tab.
|
| 5 |
+
|
| 6 |
+
Includes:
|
| 7 |
+
- In-memory model cache (10-min TTL) to avoid retraining every tick
|
| 8 |
+
- Sector-strength feature
|
| 9 |
+
- generate_intraday_signal() - full pipeline producing structured signals
|
| 10 |
+
"""
|
| 11 |
+
|
| 12 |
+
import time
|
| 13 |
+
import numpy as np
|
| 14 |
+
import pandas as pd
|
| 15 |
+
from xgboost import XGBRegressor
|
| 16 |
+
from sklearn.model_selection import TimeSeriesSplit
|
| 17 |
+
from sklearn.metrics import mean_squared_error
|
| 18 |
+
from stock_data import (
|
| 19 |
+
fetch_intraday_data,
|
| 20 |
+
add_intraday_indicators,
|
| 21 |
+
fetch_india_vix,
|
| 22 |
+
fetch_nifty_trend,
|
| 23 |
+
detect_ipo_stock,
|
| 24 |
+
)
|
| 25 |
+
from trader import (
|
| 26 |
+
compute_dynamic_levels,
|
| 27 |
+
detect_market_regime,
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
# Features the model uses (must match columns from add_intraday_indicators)
|
| 32 |
+
FEATURE_COLS = [
|
| 33 |
+
# Price & returns
|
| 34 |
+
"returns_1bar", "returns_5bar", "returns_15bar",
|
| 35 |
+
# Moving average distances
|
| 36 |
+
"price_vs_ema9", "price_vs_ema21", "price_vs_sma50",
|
| 37 |
+
# Momentum
|
| 38 |
+
"RSI", "MACD", "MACD_Signal", "MACD_Hist",
|
| 39 |
+
# Volatility
|
| 40 |
+
"ATR", "BB_Width", "BB_Position",
|
| 41 |
+
# Volume
|
| 42 |
+
"volume_ratio", "price_vs_vwap",
|
| 43 |
+
# Trend
|
| 44 |
+
"Supertrend_Dir", "supertrend_dist",
|
| 45 |
+
# Time
|
| 46 |
+
"minute_of_day", "is_first_hour", "is_last_hour",
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
# Market context features (appended at prediction time)
|
| 50 |
+
MARKET_FEATURES = ["vix_level", "vix_change_5d", "nifty_trend_dir", "sector_strength"]
|
| 51 |
+
|
| 52 |
+
FORWARD_BARS = 5 # Predict return over next 5 minutes
|
| 53 |
+
MODEL_CACHE_TTL = 600 # 10 minutes in seconds
|
| 54 |
+
|
| 55 |
+
# --- In-memory model cache ---
|
| 56 |
+
_model_cache: dict = {} # ticker -> {model, feature_names, metrics, timestamp}
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _cache_valid(ticker: str) -> bool:
|
| 60 |
+
"""Check if cached model for ticker is still within TTL."""
|
| 61 |
+
if ticker not in _model_cache:
|
| 62 |
+
return False
|
| 63 |
+
return (time.time() - _model_cache[ticker]["timestamp"]) < MODEL_CACHE_TTL
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
# --- Sector strength helper ---
|
| 67 |
+
SECTOR_INDEX_MAP = {
|
| 68 |
+
"Financial Services": "^NSEBANK",
|
| 69 |
+
"Information Technology": "^CNXIT",
|
| 70 |
+
"Pharmaceuticals": "^CNXPHARMA",
|
| 71 |
+
"Energy": "^CNXENERGY",
|
| 72 |
+
"Automobile": "^CNXAUTO",
|
| 73 |
+
"FMCG": "^CNXFMCG",
|
| 74 |
+
"Metals & Mining": "^CNXMETAL",
|
| 75 |
+
"Realty": "^CNXREALTY",
|
| 76 |
+
"Media": "^CNXMEDIA",
|
| 77 |
+
}
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def _fetch_sector_strength(ticker: str) -> float:
|
| 81 |
+
"""
|
| 82 |
+
Compute sector relative strength vs Nifty 50 over last 5 days.
|
| 83 |
+
Returns a float: >0 means sector outperforming, <0 underperforming.
|
| 84 |
+
"""
|
| 85 |
+
import yfinance as yf
|
| 86 |
+
try:
|
| 87 |
+
stock_info = yf.Ticker(ticker).info
|
| 88 |
+
sector = stock_info.get("sector", "")
|
| 89 |
+
idx_symbol = SECTOR_INDEX_MAP.get(sector)
|
| 90 |
+
if not idx_symbol:
|
| 91 |
+
return 0.0
|
| 92 |
+
|
| 93 |
+
idx = yf.Ticker(idx_symbol)
|
| 94 |
+
hist = idx.history(period="5d")
|
| 95 |
+
if len(hist) < 2:
|
| 96 |
+
return 0.0
|
| 97 |
+
|
| 98 |
+
sector_ret = (float(hist["Close"].iloc[-1]) / float(hist["Close"].iloc[0]) - 1) * 100
|
| 99 |
+
|
| 100 |
+
nifty = yf.Ticker("^NSEI")
|
| 101 |
+
nh = nifty.history(period="5d")
|
| 102 |
+
if len(nh) < 2:
|
| 103 |
+
return 0.0
|
| 104 |
+
nifty_ret = (float(nh["Close"].iloc[-1]) / float(nh["Close"].iloc[0]) - 1) * 100
|
| 105 |
+
|
| 106 |
+
return round(sector_ret - nifty_ret, 4)
|
| 107 |
+
except Exception:
|
| 108 |
+
return 0.0
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
# --- Core model functions ---
|
| 112 |
+
|
| 113 |
+
def _build_target(df: pd.DataFrame, forward_bars: int = FORWARD_BARS) -> pd.Series:
|
| 114 |
+
"""Target = percentage return over the next N bars."""
|
| 115 |
+
future_close = df["Close"].shift(-forward_bars)
|
| 116 |
+
target = ((future_close - df["Close"]) / df["Close"]) * 100
|
| 117 |
+
return target
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def _add_market_context(df: pd.DataFrame, vix: dict, nifty: dict,
|
| 121 |
+
sector_strength: float = 0.0) -> pd.DataFrame:
|
| 122 |
+
"""Append market-level context features to every row."""
|
| 123 |
+
df["vix_level"] = vix.get("vix_level", 15.0)
|
| 124 |
+
df["vix_change_5d"] = vix.get("vix_change_5d", 0.0)
|
| 125 |
+
trend_map = {"bullish": 1, "flat": 0, "bearish": -1}
|
| 126 |
+
df["nifty_trend_dir"] = trend_map.get(nifty.get("trend", "flat"), 0)
|
| 127 |
+
df["sector_strength"] = sector_strength
|
| 128 |
+
return df
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _prepare_features(df: pd.DataFrame) -> tuple:
|
| 132 |
+
"""Select feature columns and return X matrix + available column names."""
|
| 133 |
+
all_cols = FEATURE_COLS + MARKET_FEATURES
|
| 134 |
+
available = [c for c in all_cols if c in df.columns]
|
| 135 |
+
X = df[available].values.astype(np.float32)
|
| 136 |
+
return X, available
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def train_intraday_model(df: pd.DataFrame, vix: dict, nifty: dict,
|
| 140 |
+
sector_strength: float = 0.0) -> dict:
|
| 141 |
+
"""
|
| 142 |
+
Train an XGBoost regressor on intraday data.
|
| 143 |
+
Returns dict with model, scaler info, feature names, and metrics.
|
| 144 |
+
"""
|
| 145 |
+
df = _add_market_context(df, vix, nifty, sector_strength)
|
| 146 |
+
|
| 147 |
+
# Build target
|
| 148 |
+
df["target"] = _build_target(df, FORWARD_BARS)
|
| 149 |
+
|
| 150 |
+
# Drop rows where target is NaN (last FORWARD_BARS rows)
|
| 151 |
+
df_clean = df.dropna(subset=["target"]).copy()
|
| 152 |
+
|
| 153 |
+
if len(df_clean) < 100:
|
| 154 |
+
raise ValueError(f"Insufficient data for training: {len(df_clean)} rows (need >=100)")
|
| 155 |
+
|
| 156 |
+
X, feature_names = _prepare_features(df_clean)
|
| 157 |
+
y = df_clean["target"].values.astype(np.float32)
|
| 158 |
+
|
| 159 |
+
# Replace any remaining NaN/inf in features
|
| 160 |
+
X = np.nan_to_num(X, nan=0.0, posinf=0.0, neginf=0.0)
|
| 161 |
+
|
| 162 |
+
# Time-series split: train on first 80%, test on last 20%
|
| 163 |
+
split_idx = int(len(X) * 0.8)
|
| 164 |
+
X_train, X_test = X[:split_idx], X[split_idx:]
|
| 165 |
+
y_train, y_test = y[:split_idx], y[split_idx:]
|
| 166 |
+
|
| 167 |
+
model = XGBRegressor(
|
| 168 |
+
n_estimators=200,
|
| 169 |
+
max_depth=5,
|
| 170 |
+
learning_rate=0.05,
|
| 171 |
+
subsample=0.8,
|
| 172 |
+
colsample_bytree=0.8,
|
| 173 |
+
min_child_weight=5,
|
| 174 |
+
reg_alpha=0.1,
|
| 175 |
+
reg_lambda=1.0,
|
| 176 |
+
random_state=42,
|
| 177 |
+
verbosity=0,
|
| 178 |
+
)
|
| 179 |
+
|
| 180 |
+
model.fit(
|
| 181 |
+
X_train, y_train,
|
| 182 |
+
eval_set=[(X_test, y_test)],
|
| 183 |
+
verbose=False,
|
| 184 |
+
)
|
| 185 |
+
|
| 186 |
+
# Evaluate
|
| 187 |
+
y_pred = model.predict(X_test)
|
| 188 |
+
mse = mean_squared_error(y_test, y_pred)
|
| 189 |
+
rmse = float(np.sqrt(mse))
|
| 190 |
+
|
| 191 |
+
# Directional accuracy (did we predict the right direction?)
|
| 192 |
+
dir_correct = np.sum(np.sign(y_pred) == np.sign(y_test))
|
| 193 |
+
dir_accuracy = float(dir_correct / len(y_test)) * 100 if len(y_test) > 0 else 0
|
| 194 |
+
|
| 195 |
+
return {
|
| 196 |
+
"model": model,
|
| 197 |
+
"feature_names": feature_names,
|
| 198 |
+
"rmse": round(rmse, 4),
|
| 199 |
+
"dir_accuracy": round(dir_accuracy, 1),
|
| 200 |
+
"train_samples": len(X_train),
|
| 201 |
+
"test_samples": len(X_test),
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def compute_confidence(expected_return: float, rmse: float,
|
| 206 |
+
dir_accuracy: float, regime_str: str) -> float:
|
| 207 |
+
"""
|
| 208 |
+
Compute a confidence score (0-100) for the prediction.
|
| 209 |
+
Factors: magnitude of expected return vs model RMSE,
|
| 210 |
+
directional accuracy, and current market regime.
|
| 211 |
+
"""
|
| 212 |
+
# Signal-to-noise ratio: how big is the predicted move vs model error
|
| 213 |
+
snr = abs(expected_return) / rmse if rmse > 0 else 0
|
| 214 |
+
snr_score = min(40, snr * 20) # 0-40 points
|
| 215 |
+
|
| 216 |
+
# Directional accuracy contribution
|
| 217 |
+
dir_score = min(35, max(0, (dir_accuracy - 45) * 0.7)) # 0-35 points
|
| 218 |
+
|
| 219 |
+
# Regime bonus/penalty
|
| 220 |
+
regime_bonus = {
|
| 221 |
+
"BULL_LOW_VOL": 15,
|
| 222 |
+
"BULL_HIGH_VOL": 10,
|
| 223 |
+
"SIDEWAYS": 0,
|
| 224 |
+
"BEAR_HIGH_VOL": -5,
|
| 225 |
+
}.get(regime_str, 5)
|
| 226 |
+
|
| 227 |
+
# Return-direction bonus: predicted returns in the direction we'd trade
|
| 228 |
+
dir_bonus = 10 if expected_return > 0.3 else (5 if expected_return > 0 else 0)
|
| 229 |
+
|
| 230 |
+
confidence = snr_score + dir_score + regime_bonus + dir_bonus
|
| 231 |
+
return round(max(0, min(100, confidence)), 1)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
def intraday_predict(ticker: str) -> dict:
|
| 235 |
+
"""
|
| 236 |
+
Full pipeline: fetch data -> add indicators -> add market context ->
|
| 237 |
+
train XGBoost -> predict next bars -> return raw prediction data.
|
| 238 |
+
Uses cache when available.
|
| 239 |
+
"""
|
| 240 |
+
# 1. Fetch intraday data
|
| 241 |
+
df = fetch_intraday_data(ticker, period="5d", interval="1m")
|
| 242 |
+
df = add_intraday_indicators(df)
|
| 243 |
+
|
| 244 |
+
if len(df) < 120:
|
| 245 |
+
return {
|
| 246 |
+
"ticker": ticker,
|
| 247 |
+
"status": "insufficient_data",
|
| 248 |
+
"message": f"Only {len(df)} bars available (need >=120)",
|
| 249 |
+
}
|
| 250 |
+
|
| 251 |
+
# 2. Fetch market context
|
| 252 |
+
vix = fetch_india_vix()
|
| 253 |
+
nifty = fetch_nifty_trend()
|
| 254 |
+
sector_str = _fetch_sector_strength(ticker)
|
| 255 |
+
|
| 256 |
+
# 3. Train model or use cache
|
| 257 |
+
if _cache_valid(ticker):
|
| 258 |
+
cached = _model_cache[ticker]
|
| 259 |
+
model = cached["model"]
|
| 260 |
+
feature_names = cached["feature_names"]
|
| 261 |
+
result_metrics = {
|
| 262 |
+
"rmse": cached["rmse"],
|
| 263 |
+
"dir_accuracy": cached["dir_accuracy"],
|
| 264 |
+
"train_samples": cached["train_samples"],
|
| 265 |
+
"test_samples": cached["test_samples"],
|
| 266 |
+
}
|
| 267 |
+
else:
|
| 268 |
+
try:
|
| 269 |
+
result = train_intraday_model(df.copy(), vix, nifty, sector_str)
|
| 270 |
+
except ValueError as e:
|
| 271 |
+
return {"ticker": ticker, "status": "train_error", "message": str(e)}
|
| 272 |
+
|
| 273 |
+
model = result["model"]
|
| 274 |
+
feature_names = result["feature_names"]
|
| 275 |
+
result_metrics = {
|
| 276 |
+
"rmse": result["rmse"],
|
| 277 |
+
"dir_accuracy": result["dir_accuracy"],
|
| 278 |
+
"train_samples": result["train_samples"],
|
| 279 |
+
"test_samples": result["test_samples"],
|
| 280 |
+
}
|
| 281 |
+
|
| 282 |
+
# Cache the trained model
|
| 283 |
+
_model_cache[ticker] = {
|
| 284 |
+
"model": model,
|
| 285 |
+
"feature_names": feature_names,
|
| 286 |
+
"timestamp": time.time(),
|
| 287 |
+
**result_metrics,
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
# 4. Predict on latest bar
|
| 291 |
+
df_latest = _add_market_context(df, vix, nifty, sector_str)
|
| 292 |
+
X_latest, _ = _prepare_features(df_latest)
|
| 293 |
+
X_latest = np.nan_to_num(X_latest, nan=0.0, posinf=0.0, neginf=0.0)
|
| 294 |
+
|
| 295 |
+
# Predict for the last bar
|
| 296 |
+
last_features = X_latest[-1:].reshape(1, -1)
|
| 297 |
+
expected_return = float(model.predict(last_features)[0])
|
| 298 |
+
|
| 299 |
+
# 5. Get current indicators for the signal
|
| 300 |
+
last_row = df.iloc[-1]
|
| 301 |
+
current_price = float(last_row["Close"])
|
| 302 |
+
current_atr = float(last_row["ATR"])
|
| 303 |
+
current_rsi = float(last_row["RSI"])
|
| 304 |
+
current_supertrend_dir = int(last_row["Supertrend_Dir"])
|
| 305 |
+
current_vwap = float(last_row["VWAP"])
|
| 306 |
+
current_volume_ratio = float(last_row["volume_ratio"])
|
| 307 |
+
|
| 308 |
+
# 6. Feature importances (top 5)
|
| 309 |
+
importances = model.feature_importances_
|
| 310 |
+
top_indices = np.argsort(importances)[-5:][::-1]
|
| 311 |
+
top_features = [
|
| 312 |
+
{"name": feature_names[i], "importance": round(float(importances[i]), 3)}
|
| 313 |
+
for i in top_indices if i < len(feature_names)
|
| 314 |
+
]
|
| 315 |
+
|
| 316 |
+
return {
|
| 317 |
+
"ticker": ticker,
|
| 318 |
+
"status": "ok",
|
| 319 |
+
"expected_return_pct": round(expected_return, 4),
|
| 320 |
+
"forward_bars": FORWARD_BARS,
|
| 321 |
+
"current_price": round(current_price, 2),
|
| 322 |
+
"current_atr": round(current_atr, 4),
|
| 323 |
+
"current_rsi": round(current_rsi, 2),
|
| 324 |
+
"supertrend_dir": current_supertrend_dir,
|
| 325 |
+
"vwap": round(current_vwap, 2),
|
| 326 |
+
"volume_ratio": round(current_volume_ratio, 2),
|
| 327 |
+
"model_rmse": result_metrics["rmse"],
|
| 328 |
+
"model_dir_accuracy": result_metrics["dir_accuracy"],
|
| 329 |
+
"train_samples": result_metrics["train_samples"],
|
| 330 |
+
"vix": vix,
|
| 331 |
+
"nifty_trend": nifty,
|
| 332 |
+
"sector_strength": sector_str,
|
| 333 |
+
"top_features": top_features,
|
| 334 |
+
}
|
| 335 |
+
|
| 336 |
+
|
| 337 |
+
# --- Full signal generator ---
|
| 338 |
+
|
| 339 |
+
def generate_intraday_signal(ticker: str) -> dict:
|
| 340 |
+
"""
|
| 341 |
+
Full pipeline: predict -> detect regime -> compute dynamic SL/TP ->
|
| 342 |
+
apply entry threshold -> return structured trading signal.
|
| 343 |
+
|
| 344 |
+
Output example:
|
| 345 |
+
{
|
| 346 |
+
"action": "BUY",
|
| 347 |
+
"ticker": "RELIANCE.NS",
|
| 348 |
+
"entry_price": 2987.40,
|
| 349 |
+
"sl_price": 2952.20, "sl_pct": -1.18,
|
| 350 |
+
"tp1_price": 3024.60, "tp1_pct": 1.24,
|
| 351 |
+
"tp2_price": 3057.80, "tp2_pct": 2.35,
|
| 352 |
+
"confidence": 67.3,
|
| 353 |
+
"expected_return_pct": 1.12,
|
| 354 |
+
"regime": "BULL_LOW_VOL",
|
| 355 |
+
...
|
| 356 |
+
}
|
| 357 |
+
"""
|
| 358 |
+
# 1. Get raw prediction
|
| 359 |
+
pred = intraday_predict(ticker)
|
| 360 |
+
|
| 361 |
+
if pred.get("status") != "ok":
|
| 362 |
+
return {
|
| 363 |
+
"action": "SKIP",
|
| 364 |
+
"ticker": ticker,
|
| 365 |
+
"reason": pred.get("message", "Prediction failed"),
|
| 366 |
+
"status": pred.get("status", "error"),
|
| 367 |
+
}
|
| 368 |
+
|
| 369 |
+
expected_return = pred["expected_return_pct"]
|
| 370 |
+
current_price = pred["current_price"]
|
| 371 |
+
current_atr = pred["current_atr"]
|
| 372 |
+
|
| 373 |
+
# 2. Build stock-level indicators for regime detection
|
| 374 |
+
stock_indicators = {
|
| 375 |
+
"RSI": pred["current_rsi"],
|
| 376 |
+
"price": current_price,
|
| 377 |
+
"Supertrend_Dir": pred["supertrend_dir"],
|
| 378 |
+
"MACD": 0,
|
| 379 |
+
"MACD_Signal": 0,
|
| 380 |
+
}
|
| 381 |
+
|
| 382 |
+
# 3. Detect regime (uses VIX + Nifty + stock signals)
|
| 383 |
+
regime_info = detect_market_regime(
|
| 384 |
+
indicators=stock_indicators,
|
| 385 |
+
vix=pred["vix"],
|
| 386 |
+
nifty=pred["nifty_trend"],
|
| 387 |
+
)
|
| 388 |
+
regime = regime_info["regime"]
|
| 389 |
+
entry_threshold = regime_info["entry_threshold"]
|
| 390 |
+
min_confidence = regime_info["min_confidence"]
|
| 391 |
+
|
| 392 |
+
# 4. Check IPO status
|
| 393 |
+
ipo_info = detect_ipo_stock(ticker)
|
| 394 |
+
is_ipo = ipo_info.get("is_ipo", False)
|
| 395 |
+
|
| 396 |
+
# 5. Compute dynamic SL/TP
|
| 397 |
+
levels = compute_dynamic_levels(current_price, current_atr, regime, is_ipo)
|
| 398 |
+
|
| 399 |
+
# 6. Compute confidence
|
| 400 |
+
confidence = compute_confidence(
|
| 401 |
+
expected_return,
|
| 402 |
+
pred["model_rmse"],
|
| 403 |
+
pred["model_dir_accuracy"],
|
| 404 |
+
regime,
|
| 405 |
+
)
|
| 406 |
+
|
| 407 |
+
# 7. Apply entry threshold
|
| 408 |
+
if expected_return >= entry_threshold and confidence >= min_confidence:
|
| 409 |
+
action = "BUY"
|
| 410 |
+
elif expected_return > 0 and confidence >= min_confidence * 1.3:
|
| 411 |
+
# Relaxed entry if confidence is very high
|
| 412 |
+
action = "BUY"
|
| 413 |
+
else:
|
| 414 |
+
action = "WAIT"
|
| 415 |
+
|
| 416 |
+
# Build reason string for WAIT
|
| 417 |
+
reason = None
|
| 418 |
+
if action == "WAIT":
|
| 419 |
+
parts = []
|
| 420 |
+
if expected_return < entry_threshold:
|
| 421 |
+
parts.append(
|
| 422 |
+
f"Expected return {expected_return:.2f}% < threshold {entry_threshold}%"
|
| 423 |
+
)
|
| 424 |
+
if confidence < min_confidence:
|
| 425 |
+
parts.append(
|
| 426 |
+
f"Confidence {confidence} < minimum {min_confidence}"
|
| 427 |
+
)
|
| 428 |
+
reason = "; ".join(parts) if parts else "Conditions not met"
|
| 429 |
+
|
| 430 |
+
signal = {
|
| 431 |
+
"action": action,
|
| 432 |
+
"ticker": ticker,
|
| 433 |
+
"entry_price": current_price,
|
| 434 |
+
"sl_price": levels["sl_price"],
|
| 435 |
+
"sl_pct": levels["sl_pct"],
|
| 436 |
+
"tp1_price": levels["tp1_price"],
|
| 437 |
+
"tp1_pct": levels["tp1_pct"],
|
| 438 |
+
"tp2_price": levels["tp2_price"] if levels["include_tp2"] else None,
|
| 439 |
+
"tp2_pct": levels["tp2_pct"] if levels["include_tp2"] else None,
|
| 440 |
+
"confidence": confidence,
|
| 441 |
+
"expected_return_pct": round(expected_return, 4),
|
| 442 |
+
"regime": regime,
|
| 443 |
+
"regime_details": regime_info,
|
| 444 |
+
"is_ipo": is_ipo,
|
| 445 |
+
"ipo_age_days": ipo_info.get("ipo_age_days"),
|
| 446 |
+
"current_atr": pred["current_atr"],
|
| 447 |
+
"current_rsi": pred["current_rsi"],
|
| 448 |
+
"supertrend_dir": pred["supertrend_dir"],
|
| 449 |
+
"vwap": pred["vwap"],
|
| 450 |
+
"volume_ratio": pred["volume_ratio"],
|
| 451 |
+
"sector_strength": pred.get("sector_strength", 0),
|
| 452 |
+
"model_metrics": {
|
| 453 |
+
"rmse": pred["model_rmse"],
|
| 454 |
+
"dir_accuracy": pred["model_dir_accuracy"],
|
| 455 |
+
"train_samples": pred["train_samples"],
|
| 456 |
+
},
|
| 457 |
+
"top_features": pred["top_features"],
|
| 458 |
+
"vix": pred["vix"],
|
| 459 |
+
"nifty_trend": pred["nifty_trend"],
|
| 460 |
+
}
|
| 461 |
+
|
| 462 |
+
if reason:
|
| 463 |
+
signal["reason"] = reason
|
| 464 |
+
|
| 465 |
+
return signal
|
backend/model.py
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import numpy as np
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import torch
|
| 5 |
+
import torch.nn as nn
|
| 6 |
+
from torch.utils.data import DataLoader, TensorDataset
|
| 7 |
+
from sklearn.preprocessing import MinMaxScaler
|
| 8 |
+
from datetime import datetime, timedelta
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
FEATURE_COLS = ["Close", "SMA_20", "EMA_20", "RSI", "MACD", "Volume",
|
| 12 |
+
"BB_Upper", "BB_Lower", "BB_Width", "ATR"]
|
| 13 |
+
LOOK_BACK = 60
|
| 14 |
+
PREDICT_DAYS = 5
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class StockLSTM(nn.Module):
|
| 18 |
+
def __init__(self, input_size: int = 10, hidden_size: int = 128,
|
| 19 |
+
num_layers: int = 3, output_size: int = 5, dropout: float = 0.3):
|
| 20 |
+
super().__init__()
|
| 21 |
+
self.hidden_size = hidden_size
|
| 22 |
+
self.num_layers = num_layers
|
| 23 |
+
|
| 24 |
+
self.lstm = nn.LSTM(
|
| 25 |
+
input_size, hidden_size, num_layers,
|
| 26 |
+
batch_first=True, dropout=dropout if num_layers > 1 else 0.0,
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
self.head = nn.Sequential(
|
| 30 |
+
nn.Linear(hidden_size, hidden_size // 2),
|
| 31 |
+
nn.ReLU(),
|
| 32 |
+
nn.Dropout(dropout),
|
| 33 |
+
nn.Linear(hidden_size // 2, output_size),
|
| 34 |
+
)
|
| 35 |
+
|
| 36 |
+
def forward(self, x):
|
| 37 |
+
h0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size, device=x.device)
|
| 38 |
+
c0 = torch.zeros(self.num_layers, x.size(0), self.hidden_size, device=x.device)
|
| 39 |
+
out, _ = self.lstm(x, (h0, c0))
|
| 40 |
+
out = self.head(out[:, -1, :])
|
| 41 |
+
return out
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _prepare_features(df: pd.DataFrame):
|
| 45 |
+
available = [c for c in FEATURE_COLS if c in df.columns]
|
| 46 |
+
if len(available) < 2:
|
| 47 |
+
available = ["Close"]
|
| 48 |
+
|
| 49 |
+
features = df[available].values.astype(np.float32)
|
| 50 |
+
close = df["Close"].values.astype(np.float32)
|
| 51 |
+
return features, close, len(available)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _prepare_data(features: np.ndarray, close_col_idx: int = 0):
|
| 55 |
+
n_samples = len(features)
|
| 56 |
+
split = int(n_samples * 0.85)
|
| 57 |
+
|
| 58 |
+
scaler = MinMaxScaler()
|
| 59 |
+
scaler.fit(features[:split])
|
| 60 |
+
|
| 61 |
+
scaled = scaler.transform(features)
|
| 62 |
+
|
| 63 |
+
X, y = [], []
|
| 64 |
+
for i in range(LOOK_BACK, len(scaled) - PREDICT_DAYS):
|
| 65 |
+
X.append(scaled[i - LOOK_BACK:i])
|
| 66 |
+
y.append(scaled[i:i + PREDICT_DAYS, close_col_idx])
|
| 67 |
+
|
| 68 |
+
X = np.array(X, dtype=np.float32)
|
| 69 |
+
y = np.array(y, dtype=np.float32)
|
| 70 |
+
|
| 71 |
+
adj_split = split - LOOK_BACK
|
| 72 |
+
adj_split = max(1, min(adj_split, len(X) - 1))
|
| 73 |
+
|
| 74 |
+
return X, y, scaler, adj_split
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def train_and_predict(
|
| 78 |
+
df: pd.DataFrame,
|
| 79 |
+
epochs: int = 100,
|
| 80 |
+
lr: float = 0.001,
|
| 81 |
+
batch_size: int = 32,
|
| 82 |
+
patience: int = 10,
|
| 83 |
+
):
|
| 84 |
+
features, close, n_features = _prepare_features(df)
|
| 85 |
+
X, y, scaler, split = _prepare_data(features)
|
| 86 |
+
|
| 87 |
+
X_train, y_train = X[:split], y[:split]
|
| 88 |
+
X_test, y_test = X[split:], y[split:]
|
| 89 |
+
|
| 90 |
+
X_train_t = torch.tensor(X_train)
|
| 91 |
+
y_train_t = torch.tensor(y_train)
|
| 92 |
+
X_test_t = torch.tensor(X_test)
|
| 93 |
+
y_test_t = torch.tensor(y_test)
|
| 94 |
+
|
| 95 |
+
train_ds = TensorDataset(X_train_t, y_train_t)
|
| 96 |
+
train_loader = DataLoader(train_ds, batch_size=batch_size, shuffle=True)
|
| 97 |
+
|
| 98 |
+
model = StockLSTM(
|
| 99 |
+
input_size=n_features,
|
| 100 |
+
hidden_size=128,
|
| 101 |
+
num_layers=3,
|
| 102 |
+
output_size=PREDICT_DAYS,
|
| 103 |
+
)
|
| 104 |
+
criterion = nn.MSELoss()
|
| 105 |
+
optimizer = torch.optim.Adam(model.parameters(), lr=lr, weight_decay=1e-5)
|
| 106 |
+
scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(
|
| 107 |
+
optimizer, mode="min", factor=0.5, patience=5, min_lr=1e-6,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
best_val_loss = float("inf")
|
| 111 |
+
epochs_no_improve = 0
|
| 112 |
+
|
| 113 |
+
for epoch in range(epochs):
|
| 114 |
+
model.train()
|
| 115 |
+
for xb, yb in train_loader:
|
| 116 |
+
optimizer.zero_grad()
|
| 117 |
+
preds = model(xb)
|
| 118 |
+
loss = criterion(preds, yb)
|
| 119 |
+
loss.backward()
|
| 120 |
+
torch.nn.utils.clip_grad_norm_(model.parameters(), max_norm=1.0)
|
| 121 |
+
optimizer.step()
|
| 122 |
+
|
| 123 |
+
model.eval()
|
| 124 |
+
with torch.no_grad():
|
| 125 |
+
val_preds = model(X_test_t)
|
| 126 |
+
val_loss = float(criterion(val_preds, y_test_t))
|
| 127 |
+
|
| 128 |
+
scheduler.step(val_loss)
|
| 129 |
+
|
| 130 |
+
if val_loss < best_val_loss:
|
| 131 |
+
best_val_loss = val_loss
|
| 132 |
+
epochs_no_improve = 0
|
| 133 |
+
best_state = {k: v.clone() for k, v in model.state_dict().items()}
|
| 134 |
+
else:
|
| 135 |
+
epochs_no_improve += 1
|
| 136 |
+
if epochs_no_improve >= patience:
|
| 137 |
+
break
|
| 138 |
+
|
| 139 |
+
if best_val_loss < float("inf"):
|
| 140 |
+
model.load_state_dict(best_state)
|
| 141 |
+
|
| 142 |
+
model.eval()
|
| 143 |
+
with torch.no_grad():
|
| 144 |
+
test_preds = model(X_test_t).numpy()
|
| 145 |
+
test_loss = float(criterion(torch.tensor(test_preds), y_test_t))
|
| 146 |
+
|
| 147 |
+
confidence = max(0, min(100, round((1 - test_loss * 10) * 100, 1)))
|
| 148 |
+
if confidence >= 70:
|
| 149 |
+
risk = "Low"
|
| 150 |
+
elif confidence >= 45:
|
| 151 |
+
risk = "Medium"
|
| 152 |
+
else:
|
| 153 |
+
risk = "High"
|
| 154 |
+
|
| 155 |
+
last_window = features[-LOOK_BACK:]
|
| 156 |
+
last_scaled = scaler.transform(last_window).reshape(1, LOOK_BACK, n_features)
|
| 157 |
+
last_seq = torch.tensor(last_scaled, dtype=torch.float32)
|
| 158 |
+
|
| 159 |
+
with torch.no_grad():
|
| 160 |
+
raw_pred = model(last_seq).numpy().flatten()
|
| 161 |
+
|
| 162 |
+
dummy = np.zeros((len(raw_pred), n_features), dtype=np.float32)
|
| 163 |
+
dummy[:, 0] = raw_pred
|
| 164 |
+
predicted_prices = scaler.inverse_transform(dummy)[:, 0].tolist()
|
| 165 |
+
|
| 166 |
+
historical_prices = close[-30:].tolist()
|
| 167 |
+
|
| 168 |
+
if "Date" in df.columns:
|
| 169 |
+
last_dates = df["Date"].iloc[-30:]
|
| 170 |
+
hist_dates = [str(d.date()) if hasattr(d, 'date') else str(d)[:10] for d in last_dates]
|
| 171 |
+
else:
|
| 172 |
+
hist_dates = [(datetime.now() - timedelta(days=30-i)).strftime("%Y-%m-%d") for i in range(30)]
|
| 173 |
+
|
| 174 |
+
last_date = datetime.now()
|
| 175 |
+
pred_dates = []
|
| 176 |
+
bdays = 0
|
| 177 |
+
d = last_date
|
| 178 |
+
while bdays < PREDICT_DAYS:
|
| 179 |
+
d += timedelta(days=1)
|
| 180 |
+
if d.weekday() < 5:
|
| 181 |
+
pred_dates.append(d.strftime("%Y-%m-%d"))
|
| 182 |
+
bdays += 1
|
| 183 |
+
|
| 184 |
+
return {
|
| 185 |
+
"predicted_prices": [round(p, 2) for p in predicted_prices],
|
| 186 |
+
"confidence": confidence,
|
| 187 |
+
"risk": risk,
|
| 188 |
+
"test_mse": round(test_loss, 6),
|
| 189 |
+
"historical_last_30": [round(float(p), 2) for p in historical_prices],
|
| 190 |
+
"historical_dates": hist_dates,
|
| 191 |
+
"prediction_dates": pred_dates,
|
| 192 |
+
}
|
backend/sentiment.py
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import BertTokenizer, BertForSequenceClassification
|
| 4 |
+
import numpy as np
|
| 5 |
+
import yfinance as yf
|
| 6 |
+
import nltk
|
| 7 |
+
from nltk.sentiment.vader import SentimentIntensityAnalyzer
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
nltk.data.find("sentiment/vader_lexicon.zip")
|
| 11 |
+
except LookupError:
|
| 12 |
+
nltk.download("vader_lexicon", quiet=True)
|
| 13 |
+
|
| 14 |
+
_vader = SentimentIntensityAnalyzer()
|
| 15 |
+
|
| 16 |
+
MODEL_NAME = "ProsusAI/finbert"
|
| 17 |
+
_tokenizer = BertTokenizer.from_pretrained(MODEL_NAME)
|
| 18 |
+
_finbert = BertForSequenceClassification.from_pretrained(MODEL_NAME)
|
| 19 |
+
_finbert.eval()
|
| 20 |
+
FINBERT_LABELS = ["negative", "neutral", "positive"]
|
| 21 |
+
|
| 22 |
+
VADER_WEIGHT = 0.4
|
| 23 |
+
FINBERT_WEIGHT = 0.6
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _score_vader(text: str) -> dict:
|
| 27 |
+
scores = _vader.polarity_scores(text)
|
| 28 |
+
compound = scores["compound"]
|
| 29 |
+
|
| 30 |
+
if compound >= 0.05:
|
| 31 |
+
label = "positive"
|
| 32 |
+
elif compound <= -0.05:
|
| 33 |
+
label = "negative"
|
| 34 |
+
else:
|
| 35 |
+
label = "neutral"
|
| 36 |
+
|
| 37 |
+
confidence = round(abs(compound), 4)
|
| 38 |
+
return {"label": label, "score": round(compound, 4), "confidence": confidence}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _score_finbert(text: str) -> dict:
|
| 42 |
+
tokens = _tokenizer(text, return_tensors="pt", padding=True,
|
| 43 |
+
truncation=True, max_length=128)
|
| 44 |
+
with torch.no_grad():
|
| 45 |
+
logits = _finbert(**tokens).logits
|
| 46 |
+
probs = torch.nn.functional.softmax(logits, dim=-1).squeeze().tolist()
|
| 47 |
+
idx = int(np.argmax(probs))
|
| 48 |
+
|
| 49 |
+
signed_score = probs[2] - probs[0]
|
| 50 |
+
return {
|
| 51 |
+
"label": FINBERT_LABELS[idx],
|
| 52 |
+
"score": round(signed_score, 4),
|
| 53 |
+
"confidence": round(probs[idx], 4),
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _score_text(text: str) -> dict:
|
| 58 |
+
vader = _score_vader(text)
|
| 59 |
+
finbert = _score_finbert(text)
|
| 60 |
+
|
| 61 |
+
combined_score = (VADER_WEIGHT * vader["score"]) + (FINBERT_WEIGHT * finbert["score"])
|
| 62 |
+
|
| 63 |
+
if combined_score > 0.1:
|
| 64 |
+
label = "positive"
|
| 65 |
+
elif combined_score < -0.1:
|
| 66 |
+
label = "negative"
|
| 67 |
+
else:
|
| 68 |
+
label = "neutral"
|
| 69 |
+
|
| 70 |
+
combined_confidence = (VADER_WEIGHT * vader["confidence"]) + (FINBERT_WEIGHT * finbert["confidence"])
|
| 71 |
+
|
| 72 |
+
return {
|
| 73 |
+
"text": text,
|
| 74 |
+
"label": label,
|
| 75 |
+
"confidence": round(combined_confidence, 4),
|
| 76 |
+
"combined_score": round(combined_score, 4),
|
| 77 |
+
"vader": vader,
|
| 78 |
+
"finbert": finbert,
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def fetch_news_headlines(ticker: str, max_items: int = 10) -> list[str]:
|
| 83 |
+
stock = yf.Ticker(ticker)
|
| 84 |
+
news = stock.news or []
|
| 85 |
+
headlines = []
|
| 86 |
+
for item in news[:max_items]:
|
| 87 |
+
content = item.get("content", {})
|
| 88 |
+
title = content.get("title", "") or item.get("title", "")
|
| 89 |
+
if title:
|
| 90 |
+
headlines.append(title)
|
| 91 |
+
return headlines
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def analyze_sentiment(ticker: str) -> dict:
|
| 95 |
+
headlines = fetch_news_headlines(ticker)
|
| 96 |
+
if not headlines:
|
| 97 |
+
return {
|
| 98 |
+
"ticker": ticker,
|
| 99 |
+
"articles_analyzed": 0,
|
| 100 |
+
"details": [],
|
| 101 |
+
"overall_sentiment": "neutral",
|
| 102 |
+
"overall_score": 0.0,
|
| 103 |
+
"method": "VADER (40%) + FinBERT (60%) ensemble",
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
details = [_score_text(h) for h in headlines]
|
| 107 |
+
|
| 108 |
+
avg = float(np.mean([d["combined_score"] for d in details]))
|
| 109 |
+
|
| 110 |
+
if avg > 0.15:
|
| 111 |
+
overall = "positive"
|
| 112 |
+
elif avg < -0.15:
|
| 113 |
+
overall = "negative"
|
| 114 |
+
else:
|
| 115 |
+
overall = "neutral"
|
| 116 |
+
|
| 117 |
+
return {
|
| 118 |
+
"ticker": ticker,
|
| 119 |
+
"articles_analyzed": len(details),
|
| 120 |
+
"details": details,
|
| 121 |
+
"overall_sentiment": overall,
|
| 122 |
+
"overall_score": round(avg, 4),
|
| 123 |
+
"method": "VADER (40%) + FinBERT (60%) ensemble",
|
| 124 |
+
}
|
backend/step4_install.sh
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pip install --upgrade pip
|
| 2 |
+
|
| 3 |
+
pip install fastapi==0.115.0
|
| 4 |
+
pip install uvicorn==0.30.0
|
| 5 |
+
pip install yfinance==1.1.0
|
| 6 |
+
pip install pandas==2.2.0
|
| 7 |
+
pip install numpy==1.26.4
|
| 8 |
+
pip install scikit-learn==1.5.0
|
| 9 |
+
pip install transformers==4.44.0
|
| 10 |
+
pip install requests==2.32.0
|
| 11 |
+
pip install python-dateutil==2.9.0
|
| 12 |
+
pip install ta==0.11.0
|
backend/stock_data.py
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import yfinance as yf
|
| 3 |
+
import pandas as pd
|
| 4 |
+
import ta
|
| 5 |
+
from datetime import datetime
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def fetch_stock_data(ticker: str, period: str = "2y", interval: str = "1d") -> pd.DataFrame:
|
| 9 |
+
stock = yf.Ticker(ticker)
|
| 10 |
+
df = stock.history(period=period, interval=interval)
|
| 11 |
+
if df.empty:
|
| 12 |
+
raise ValueError(f"No data found for ticker: {ticker}")
|
| 13 |
+
df.reset_index(inplace=True)
|
| 14 |
+
return df
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def add_technical_indicators(df: pd.DataFrame) -> pd.DataFrame:
|
| 18 |
+
close = df["Close"]
|
| 19 |
+
high = df["High"]
|
| 20 |
+
low = df["Low"]
|
| 21 |
+
volume = df["Volume"]
|
| 22 |
+
|
| 23 |
+
df["SMA_20"] = ta.trend.sma_indicator(close, window=20)
|
| 24 |
+
df["SMA_50"] = ta.trend.sma_indicator(close, window=50)
|
| 25 |
+
df["EMA_20"] = ta.trend.ema_indicator(close, window=20)
|
| 26 |
+
df["RSI"] = ta.momentum.rsi(close, window=14)
|
| 27 |
+
|
| 28 |
+
macd = ta.trend.MACD(close)
|
| 29 |
+
df["MACD"] = macd.macd()
|
| 30 |
+
df["MACD_Signal"] = macd.macd_signal()
|
| 31 |
+
df["MACD_Hist"] = macd.macd_diff()
|
| 32 |
+
|
| 33 |
+
bb = ta.volatility.BollingerBands(close, window=20, window_dev=2)
|
| 34 |
+
df["BB_Upper"] = bb.bollinger_hband()
|
| 35 |
+
df["BB_Lower"] = bb.bollinger_lband()
|
| 36 |
+
df["BB_Width"] = bb.bollinger_wband()
|
| 37 |
+
|
| 38 |
+
df["ATR"] = ta.volatility.average_true_range(high, low, close, window=14)
|
| 39 |
+
|
| 40 |
+
df["Volume_SMA_20"] = ta.trend.sma_indicator(volume, window=20)
|
| 41 |
+
df.dropna(inplace=True)
|
| 42 |
+
return df
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def get_stock_info(ticker: str) -> dict:
|
| 46 |
+
stock = yf.Ticker(ticker)
|
| 47 |
+
info = stock.info
|
| 48 |
+
return {
|
| 49 |
+
"name": info.get("shortName", ticker),
|
| 50 |
+
"sector": info.get("sector", "N/A"),
|
| 51 |
+
"currency": info.get("currency", "INR"),
|
| 52 |
+
"current_price": info.get("currentPrice", info.get("regularMarketPrice", 0)),
|
| 53 |
+
"market_cap": info.get("marketCap", 0),
|
| 54 |
+
"day_high": info.get("dayHigh", 0),
|
| 55 |
+
"day_low": info.get("dayLow", 0),
|
| 56 |
+
"prev_close": info.get("previousClose", 0),
|
| 57 |
+
"open": info.get("open", 0),
|
| 58 |
+
"volume": info.get("volume", 0),
|
| 59 |
+
"fifty_two_week_high": info.get("fiftyTwoWeekHigh", 0),
|
| 60 |
+
"fifty_two_week_low": info.get("fiftyTwoWeekLow", 0),
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def fetch_live_price(ticker: str) -> dict:
|
| 65 |
+
stock = yf.Ticker(ticker)
|
| 66 |
+
info = stock.info
|
| 67 |
+
|
| 68 |
+
current = info.get("currentPrice", info.get("regularMarketPrice", 0))
|
| 69 |
+
prev_close = info.get("previousClose", 0)
|
| 70 |
+
|
| 71 |
+
change = round(current - prev_close, 2) if current and prev_close else 0
|
| 72 |
+
change_pct = round((change / prev_close) * 100, 2) if prev_close else 0
|
| 73 |
+
|
| 74 |
+
return {
|
| 75 |
+
"ticker": ticker,
|
| 76 |
+
"price": current,
|
| 77 |
+
"change": change,
|
| 78 |
+
"change_pct": change_pct,
|
| 79 |
+
"direction": "up" if change >= 0 else "down",
|
| 80 |
+
"day_high": info.get("dayHigh", 0),
|
| 81 |
+
"day_low": info.get("dayLow", 0),
|
| 82 |
+
"volume": info.get("volume", 0),
|
| 83 |
+
"timestamp": datetime.now().isoformat(),
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
TIMEFRAME_MAP = {
|
| 88 |
+
"1d": ("1d", "5m"),
|
| 89 |
+
"5d": ("5d", "15m"),
|
| 90 |
+
"1wk": ("5d", "15m"),
|
| 91 |
+
"1mo": ("1mo", "1h"),
|
| 92 |
+
"3mo": ("3mo", "1d"),
|
| 93 |
+
"6mo": ("6mo", "1d"),
|
| 94 |
+
"1y": ("1y", "1d"),
|
| 95 |
+
"2y": ("2y", "1wk"),
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
|
| 99 |
+
def fetch_chart_data(ticker: str, timeframe: str) -> list[dict]:
|
| 100 |
+
period, interval = TIMEFRAME_MAP.get(timeframe, ("1mo", "1h"))
|
| 101 |
+
stock = yf.Ticker(ticker)
|
| 102 |
+
df = stock.history(period=period, interval=interval)
|
| 103 |
+
if df.empty:
|
| 104 |
+
raise ValueError(f"No chart data for {ticker}")
|
| 105 |
+
df.reset_index(inplace=True)
|
| 106 |
+
|
| 107 |
+
records = []
|
| 108 |
+
date_col = "Datetime" if "Datetime" in df.columns else "Date"
|
| 109 |
+
for _, row in df.iterrows():
|
| 110 |
+
records.append({
|
| 111 |
+
"time": str(row[date_col]),
|
| 112 |
+
"open": round(float(row["Open"]), 2),
|
| 113 |
+
"high": round(float(row["High"]), 2),
|
| 114 |
+
"low": round(float(row["Low"]), 2),
|
| 115 |
+
"close": round(float(row["Close"]), 2),
|
| 116 |
+
"volume": int(row["Volume"]),
|
| 117 |
+
})
|
| 118 |
+
return records
|
| 119 |
+
|
| 120 |
+
|
| 121 |
+
# ─────────────────────────────────────────────────
|
| 122 |
+
# INTRADAY DATA & FEATURES (for Auto Trade only)
|
| 123 |
+
# ─────────────────────────────────────────────────
|
| 124 |
+
|
| 125 |
+
import numpy as np
|
| 126 |
+
|
| 127 |
+
|
| 128 |
+
def fetch_intraday_data(ticker: str, period: str = "5d", interval: str = "1m") -> pd.DataFrame:
|
| 129 |
+
"""Fetch 1-min intraday bars (max 7 days with yfinance)."""
|
| 130 |
+
stock = yf.Ticker(ticker)
|
| 131 |
+
df = stock.history(period=period, interval=interval)
|
| 132 |
+
if df.empty:
|
| 133 |
+
raise ValueError(f"No intraday data for {ticker}")
|
| 134 |
+
df.reset_index(inplace=True)
|
| 135 |
+
col = "Datetime" if "Datetime" in df.columns else "Date"
|
| 136 |
+
df.rename(columns={col: "Datetime"}, inplace=True)
|
| 137 |
+
df["Datetime"] = pd.to_datetime(df["Datetime"])
|
| 138 |
+
return df
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def _supertrend(df: pd.DataFrame, period: int = 10, multiplier: float = 3.0):
|
| 142 |
+
"""Compute Supertrend indicator (period, multiplier)."""
|
| 143 |
+
hl2 = (df["High"] + df["Low"]) / 2
|
| 144 |
+
atr = ta.volatility.average_true_range(df["High"], df["Low"], df["Close"], window=period)
|
| 145 |
+
|
| 146 |
+
upper_band = hl2 + multiplier * atr
|
| 147 |
+
lower_band = hl2 - multiplier * atr
|
| 148 |
+
|
| 149 |
+
supertrend = pd.Series(0.0, index=df.index)
|
| 150 |
+
direction = pd.Series(1, index=df.index) # 1 = bullish, -1 = bearish
|
| 151 |
+
|
| 152 |
+
for i in range(1, len(df)):
|
| 153 |
+
if df["Close"].iloc[i] > upper_band.iloc[i - 1]:
|
| 154 |
+
direction.iloc[i] = 1
|
| 155 |
+
elif df["Close"].iloc[i] < lower_band.iloc[i - 1]:
|
| 156 |
+
direction.iloc[i] = -1
|
| 157 |
+
else:
|
| 158 |
+
direction.iloc[i] = direction.iloc[i - 1]
|
| 159 |
+
if direction.iloc[i] == 1 and lower_band.iloc[i] < lower_band.iloc[i - 1]:
|
| 160 |
+
lower_band.iloc[i] = lower_band.iloc[i - 1]
|
| 161 |
+
if direction.iloc[i] == -1 and upper_band.iloc[i] > upper_band.iloc[i - 1]:
|
| 162 |
+
upper_band.iloc[i] = upper_band.iloc[i - 1]
|
| 163 |
+
|
| 164 |
+
supertrend.iloc[i] = lower_band.iloc[i] if direction.iloc[i] == 1 else upper_band.iloc[i]
|
| 165 |
+
|
| 166 |
+
return supertrend, direction
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def add_intraday_indicators(df: pd.DataFrame) -> pd.DataFrame:
|
| 170 |
+
"""Add all intraday trading indicators to a DataFrame of 1-min bars."""
|
| 171 |
+
close = df["Close"]
|
| 172 |
+
high = df["High"]
|
| 173 |
+
low = df["Low"]
|
| 174 |
+
volume = df["Volume"].astype(float)
|
| 175 |
+
|
| 176 |
+
# Moving averages
|
| 177 |
+
df["EMA_9"] = ta.trend.ema_indicator(close, window=9)
|
| 178 |
+
df["EMA_21"] = ta.trend.ema_indicator(close, window=21)
|
| 179 |
+
df["SMA_50"] = ta.trend.sma_indicator(close, window=50)
|
| 180 |
+
|
| 181 |
+
# Price vs MAs (percentage distance)
|
| 182 |
+
df["price_vs_ema9"] = ((close - df["EMA_9"]) / df["EMA_9"]) * 100
|
| 183 |
+
df["price_vs_ema21"] = ((close - df["EMA_21"]) / df["EMA_21"]) * 100
|
| 184 |
+
df["price_vs_sma50"] = ((close - df["SMA_50"]) / df["SMA_50"]) * 100
|
| 185 |
+
|
| 186 |
+
# Returns
|
| 187 |
+
df["returns_1bar"] = close.pct_change(1) * 100
|
| 188 |
+
df["returns_5bar"] = close.pct_change(5) * 100
|
| 189 |
+
df["returns_15bar"] = close.pct_change(15) * 100
|
| 190 |
+
|
| 191 |
+
# Momentum
|
| 192 |
+
df["RSI"] = ta.momentum.rsi(close, window=14)
|
| 193 |
+
macd_obj = ta.trend.MACD(close, window_fast=12, window_slow=26, window_sign=9)
|
| 194 |
+
df["MACD"] = macd_obj.macd()
|
| 195 |
+
df["MACD_Signal"] = macd_obj.macd_signal()
|
| 196 |
+
df["MACD_Hist"] = macd_obj.macd_diff()
|
| 197 |
+
|
| 198 |
+
# Volatility
|
| 199 |
+
df["ATR"] = ta.volatility.average_true_range(high, low, close, window=14)
|
| 200 |
+
bb = ta.volatility.BollingerBands(close, window=20, window_dev=2)
|
| 201 |
+
df["BB_Upper"] = bb.bollinger_hband()
|
| 202 |
+
df["BB_Lower"] = bb.bollinger_lband()
|
| 203 |
+
df["BB_Width"] = bb.bollinger_wband()
|
| 204 |
+
bb_range = df["BB_Upper"] - df["BB_Lower"]
|
| 205 |
+
df["BB_Position"] = np.where(bb_range > 0, (close - df["BB_Lower"]) / bb_range, 0.5)
|
| 206 |
+
|
| 207 |
+
# VWAP
|
| 208 |
+
cumvol = volume.cumsum()
|
| 209 |
+
cumtp = (((high + low + close) / 3) * volume).cumsum()
|
| 210 |
+
df["VWAP"] = np.where(cumvol > 0, cumtp / cumvol, close)
|
| 211 |
+
df["price_vs_vwap"] = ((close - df["VWAP"]) / df["VWAP"]) * 100
|
| 212 |
+
|
| 213 |
+
# Volume ratio
|
| 214 |
+
vol_sma20 = volume.rolling(window=20).mean()
|
| 215 |
+
df["volume_ratio"] = np.where(vol_sma20 > 0, volume / vol_sma20, 1.0)
|
| 216 |
+
|
| 217 |
+
# Supertrend
|
| 218 |
+
st_val, st_dir = _supertrend(df, period=10, multiplier=3.0)
|
| 219 |
+
df["Supertrend"] = st_val
|
| 220 |
+
df["Supertrend_Dir"] = st_dir # 1=bullish, -1=bearish
|
| 221 |
+
df["supertrend_dist"] = ((close - st_val) / close) * 100
|
| 222 |
+
|
| 223 |
+
# Time features
|
| 224 |
+
if "Datetime" in df.columns:
|
| 225 |
+
dt = pd.to_datetime(df["Datetime"])
|
| 226 |
+
df["minute_of_day"] = dt.dt.hour * 60 + dt.dt.minute
|
| 227 |
+
df["is_first_hour"] = (dt.dt.hour == 9).astype(int)
|
| 228 |
+
df["is_last_hour"] = (dt.dt.hour >= 15).astype(int)
|
| 229 |
+
else:
|
| 230 |
+
df["minute_of_day"] = 0
|
| 231 |
+
df["is_first_hour"] = 0
|
| 232 |
+
df["is_last_hour"] = 0
|
| 233 |
+
|
| 234 |
+
df.dropna(inplace=True)
|
| 235 |
+
return df
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
def fetch_india_vix() -> dict:
|
| 239 |
+
"""Fetch India VIX current level and recent change."""
|
| 240 |
+
try:
|
| 241 |
+
stock = yf.Ticker("^INDIAVIX")
|
| 242 |
+
hist = stock.history(period="7d")
|
| 243 |
+
if hist.empty:
|
| 244 |
+
return {"vix_level": 15.0, "vix_change_5d": 0.0, "available": False}
|
| 245 |
+
current = float(hist["Close"].iloc[-1])
|
| 246 |
+
if len(hist) >= 5:
|
| 247 |
+
prev = float(hist["Close"].iloc[-5])
|
| 248 |
+
else:
|
| 249 |
+
prev = float(hist["Close"].iloc[0])
|
| 250 |
+
change = round(current - prev, 2)
|
| 251 |
+
return {"vix_level": round(current, 2), "vix_change_5d": change, "available": True}
|
| 252 |
+
except Exception:
|
| 253 |
+
return {"vix_level": 15.0, "vix_change_5d": 0.0, "available": False}
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def fetch_nifty_trend() -> dict:
|
| 257 |
+
"""Fetch Nifty 50 trend vs EMA-9 and EMA-21."""
|
| 258 |
+
try:
|
| 259 |
+
stock = yf.Ticker("^NSEI")
|
| 260 |
+
hist = stock.history(period="1mo", interval="1d")
|
| 261 |
+
if len(hist) < 21:
|
| 262 |
+
return {"nifty_price": 0, "trend": "flat", "above_ema9": False,
|
| 263 |
+
"above_ema21": False, "available": False}
|
| 264 |
+
close = hist["Close"]
|
| 265 |
+
ema9 = ta.trend.ema_indicator(close, window=9)
|
| 266 |
+
ema21 = ta.trend.ema_indicator(close, window=21)
|
| 267 |
+
price = float(close.iloc[-1])
|
| 268 |
+
e9 = float(ema9.iloc[-1])
|
| 269 |
+
e21 = float(ema21.iloc[-1])
|
| 270 |
+
|
| 271 |
+
above_ema9 = price > e9
|
| 272 |
+
above_ema21 = price > e21
|
| 273 |
+
|
| 274 |
+
if above_ema9 and above_ema21:
|
| 275 |
+
trend = "bullish"
|
| 276 |
+
elif not above_ema9 and not above_ema21:
|
| 277 |
+
trend = "bearish"
|
| 278 |
+
else:
|
| 279 |
+
trend = "flat"
|
| 280 |
+
|
| 281 |
+
return {
|
| 282 |
+
"nifty_price": round(price, 2),
|
| 283 |
+
"ema9": round(e9, 2),
|
| 284 |
+
"ema21": round(e21, 2),
|
| 285 |
+
"trend": trend,
|
| 286 |
+
"above_ema9": above_ema9,
|
| 287 |
+
"above_ema21": above_ema21,
|
| 288 |
+
"available": True,
|
| 289 |
+
}
|
| 290 |
+
except Exception:
|
| 291 |
+
return {"nifty_price": 0, "trend": "flat", "above_ema9": False,
|
| 292 |
+
"above_ema21": False, "available": False}
|
| 293 |
+
|
| 294 |
+
|
| 295 |
+
def detect_ipo_stock(ticker: str) -> dict:
|
| 296 |
+
"""Check if stock was listed recently (IPO < 180 days)."""
|
| 297 |
+
try:
|
| 298 |
+
stock = yf.Ticker(ticker)
|
| 299 |
+
hist = stock.history(period="max")
|
| 300 |
+
if hist.empty:
|
| 301 |
+
return {"is_ipo": False, "ipo_age_days": 999, "listing_date": None}
|
| 302 |
+
first_date = hist.index[0]
|
| 303 |
+
if hasattr(first_date, "date"):
|
| 304 |
+
first_date = first_date.date()
|
| 305 |
+
age_days = (datetime.now().date() - first_date).days
|
| 306 |
+
return {
|
| 307 |
+
"is_ipo": age_days < 180,
|
| 308 |
+
"ipo_age_days": age_days,
|
| 309 |
+
"listing_date": str(first_date),
|
| 310 |
+
}
|
| 311 |
+
except Exception:
|
| 312 |
+
return {"is_ipo": False, "ipo_age_days": 999, "listing_date": None}
|
| 313 |
+
|
backend/test_intraday_signal.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Tests for the intraday trading model components:
|
| 3 |
+
- compute_dynamic_levels (ATR-based SL/TP with regime + IPO modifiers)
|
| 4 |
+
- detect_market_regime (4-state VIX-aware classification)
|
| 5 |
+
- risk_check_position_size (risk-per-trade capping)
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import sys
|
| 9 |
+
sys.path.insert(0, ".")
|
| 10 |
+
|
| 11 |
+
from trader import compute_dynamic_levels, detect_market_regime, risk_check_position_size
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def test_dynamic_levels_basic():
|
| 15 |
+
"""Base ATR-based SL/TP in SIDEWAYS regime."""
|
| 16 |
+
result = compute_dynamic_levels(
|
| 17 |
+
current_price=1000.0, atr=10.0, regime="SIDEWAYS", is_ipo=False
|
| 18 |
+
)
|
| 19 |
+
assert result["sl_price"] < 1000.0, f"SL should be below entry: {result}"
|
| 20 |
+
assert result["tp1_price"] > 1000.0, f"TP1 should be above entry: {result}"
|
| 21 |
+
assert result["tp1_pct"] >= 0.5, f"TP1 pct should be >= 0.5%: {result}"
|
| 22 |
+
assert result["tp1_pct"] <= 5.0, f"TP1 pct should be <= 5.0%: {result}"
|
| 23 |
+
assert result["include_tp2"] is False, "SIDEWAYS should not include TP2"
|
| 24 |
+
print(f" PASS: basic levels = SL {result['sl_pct']}%, TP1 {result['tp1_pct']}%")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
def test_dynamic_levels_bull_low_vol():
|
| 28 |
+
"""Bullish low-vol regime should have tighter stop, wider target."""
|
| 29 |
+
sideways = compute_dynamic_levels(1000, 10, "SIDEWAYS")
|
| 30 |
+
bull = compute_dynamic_levels(1000, 10, "BULL_LOW_VOL")
|
| 31 |
+
assert bull["sl_price"] > sideways["sl_price"], "Bull SL should be tighter (higher)"
|
| 32 |
+
assert bull["tp1_pct"] >= sideways["tp1_pct"], "Bull TP should be >= Sideways TP"
|
| 33 |
+
assert bull["include_tp2"] is True, "BULL_LOW_VOL should include TP2"
|
| 34 |
+
print(f" PASS: BULL_LOW_VOL SL={bull['sl_pct']}%, TP1={bull['tp1_pct']}%")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def test_dynamic_levels_bear_high_vol():
|
| 38 |
+
"""Bear regime should have wider stop, tighter target."""
|
| 39 |
+
bear = compute_dynamic_levels(1000, 10, "BEAR_HIGH_VOL")
|
| 40 |
+
sideways = compute_dynamic_levels(1000, 10, "SIDEWAYS")
|
| 41 |
+
assert bear["sl_price"] < sideways["sl_price"], "Bear SL should be wider (lower)"
|
| 42 |
+
assert bear["include_tp2"] is False, "BEAR should not include TP2"
|
| 43 |
+
print(f" PASS: BEAR_HIGH_VOL SL={bear['sl_pct']}%, TP1={bear['tp1_pct']}%")
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def test_dynamic_levels_ipo():
|
| 47 |
+
"""IPO stocks should get boosted targets and tighter stop."""
|
| 48 |
+
normal = compute_dynamic_levels(1000, 10, "BULL_LOW_VOL", is_ipo=False)
|
| 49 |
+
ipo = compute_dynamic_levels(1000, 10, "BULL_LOW_VOL", is_ipo=True)
|
| 50 |
+
assert ipo["tp1_pct"] >= normal["tp1_pct"], "IPO TP should be >= normal"
|
| 51 |
+
assert ipo["include_tp2"] is True, "IPO should include TP2"
|
| 52 |
+
print(f" PASS: IPO TP1={ipo['tp1_pct']}% vs normal TP1={normal['tp1_pct']}%")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def test_regime_bullish_low_vol():
|
| 56 |
+
"""VIX < 18 + Nifty bullish + bullish stock signals."""
|
| 57 |
+
regime = detect_market_regime(
|
| 58 |
+
indicators={"RSI": 35, "price": 100, "Supertrend_Dir": 1, "MACD": 1, "MACD_Signal": 0},
|
| 59 |
+
vix={"vix_level": 14.0},
|
| 60 |
+
nifty={"trend": "bullish"},
|
| 61 |
+
)
|
| 62 |
+
assert regime["regime"] == "BULL_LOW_VOL", f"Expected BULL_LOW_VOL, got {regime['regime']}"
|
| 63 |
+
print(f" PASS: regime={regime['regime']}, entry_threshold={regime['entry_threshold']}")
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def test_regime_bear_high_vol():
|
| 67 |
+
"""VIX >= 22 + Nifty bearish + bearish stock signals."""
|
| 68 |
+
regime = detect_market_regime(
|
| 69 |
+
indicators={"RSI": 70, "price": 90, "Supertrend_Dir": -1, "MACD": -1, "MACD_Signal": 0},
|
| 70 |
+
vix={"vix_level": 25.0},
|
| 71 |
+
nifty={"trend": "bearish"},
|
| 72 |
+
)
|
| 73 |
+
assert regime["regime"] == "BEAR_HIGH_VOL", f"Expected BEAR_HIGH_VOL, got {regime['regime']}"
|
| 74 |
+
assert regime["entry_threshold"] >= 1.0, "Bear should need higher expected return"
|
| 75 |
+
print(f" PASS: regime={regime['regime']}, entry_threshold={regime['entry_threshold']}")
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def test_regime_sideways():
|
| 79 |
+
"""Flat Nifty + moderate VIX."""
|
| 80 |
+
regime = detect_market_regime(
|
| 81 |
+
indicators={"RSI": 50, "price": 100},
|
| 82 |
+
vix={"vix_level": 16.0},
|
| 83 |
+
nifty={"trend": "flat"},
|
| 84 |
+
)
|
| 85 |
+
assert regime["regime"] == "SIDEWAYS", f"Expected SIDEWAYS, got {regime['regime']}"
|
| 86 |
+
print(f" PASS: regime={regime['regime']}")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def test_regime_no_data():
|
| 90 |
+
"""No indicators, VIX, or Nifty data — should default to SIDEWAYS."""
|
| 91 |
+
regime = detect_market_regime()
|
| 92 |
+
assert regime["regime"] == "SIDEWAYS", f"Expected SIDEWAYS, got {regime['regime']}"
|
| 93 |
+
print(f" PASS: no-data regime={regime['regime']}")
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def test_risk_position_size():
|
| 97 |
+
"""Position size should cap loss at ~1% of capital."""
|
| 98 |
+
balance = 1_000_000.0
|
| 99 |
+
entry = 1000.0
|
| 100 |
+
sl = 985.0 # 15 rupees risk per share
|
| 101 |
+
shares = risk_check_position_size(balance, entry, sl)
|
| 102 |
+
max_loss = shares * (entry - sl)
|
| 103 |
+
assert max_loss <= balance * 0.015 + 1, f"Max loss {max_loss} exceeds 1.5% of capital"
|
| 104 |
+
assert shares > 0, "Should buy at least 1 share"
|
| 105 |
+
print(f" PASS: shares={shares}, max_loss={max_loss:.0f} ({max_loss/balance*100:.2f}% of capital)")
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
if __name__ == "__main__":
|
| 109 |
+
tests = [
|
| 110 |
+
("Dynamic levels — basic", test_dynamic_levels_basic),
|
| 111 |
+
("Dynamic levels — BULL_LOW_VOL", test_dynamic_levels_bull_low_vol),
|
| 112 |
+
("Dynamic levels — BEAR_HIGH_VOL", test_dynamic_levels_bear_high_vol),
|
| 113 |
+
("Dynamic levels — IPO", test_dynamic_levels_ipo),
|
| 114 |
+
("Regime — BULL_LOW_VOL", test_regime_bullish_low_vol),
|
| 115 |
+
("Regime — BEAR_HIGH_VOL", test_regime_bear_high_vol),
|
| 116 |
+
("Regime — SIDEWAYS", test_regime_sideways),
|
| 117 |
+
("Regime — no data", test_regime_no_data),
|
| 118 |
+
("Risk position sizing", test_risk_position_size),
|
| 119 |
+
]
|
| 120 |
+
|
| 121 |
+
passed = 0
|
| 122 |
+
failed = 0
|
| 123 |
+
for name, test_fn in tests:
|
| 124 |
+
try:
|
| 125 |
+
print(f"[TEST] {name}")
|
| 126 |
+
test_fn()
|
| 127 |
+
passed += 1
|
| 128 |
+
except Exception as e:
|
| 129 |
+
print(f" FAIL: {e}")
|
| 130 |
+
failed += 1
|
| 131 |
+
|
| 132 |
+
print(f"\n{'='*50}")
|
| 133 |
+
print(f"Results: {passed} passed, {failed} failed out of {len(tests)} tests")
|
| 134 |
+
if failed == 0:
|
| 135 |
+
print("All tests passed!")
|
| 136 |
+
else:
|
| 137 |
+
sys.exit(1)
|
backend/trader.py
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from datetime import datetime
|
| 5 |
+
from threading import Lock
|
| 6 |
+
|
| 7 |
+
INITIAL_BALANCE = 1_000_000.00
|
| 8 |
+
MAX_HOLD_BARS = 60 # ~60 min max hold for intraday
|
| 9 |
+
DEFAULT_POSITION_PCT = 10.0 # fallback if dynamic sizing unavailable
|
| 10 |
+
RISK_PER_TRADE_MIN = 0.008 # 0.8% of capital
|
| 11 |
+
RISK_PER_TRADE_MAX = 0.015 # 1.5% of capital
|
| 12 |
+
RISK_PER_TRADE_DEFAULT = 0.01 # 1.0% default
|
| 13 |
+
|
| 14 |
+
DATA_FILE = "portfolio.json"
|
| 15 |
+
_lock = Lock()
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _default_state():
|
| 19 |
+
return {
|
| 20 |
+
"balance": INITIAL_BALANCE,
|
| 21 |
+
"initial_balance": INITIAL_BALANCE,
|
| 22 |
+
"positions": {},
|
| 23 |
+
"trade_history": [],
|
| 24 |
+
"bot_active": True, # Bot starts as ACTIVE by default
|
| 25 |
+
"created_at": datetime.now().isoformat(),
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def _load_state() -> dict:
|
| 30 |
+
if os.path.exists(DATA_FILE):
|
| 31 |
+
with open(DATA_FILE, "r") as f:
|
| 32 |
+
return json.load(f)
|
| 33 |
+
return _default_state()
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def _save_state(state: dict):
|
| 37 |
+
with open(DATA_FILE, "w") as f:
|
| 38 |
+
json.dump(state, f, indent=2, default=str)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def get_portfolio() -> dict:
|
| 42 |
+
with _lock:
|
| 43 |
+
state = _load_state()
|
| 44 |
+
return state
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def reset_portfolio() -> dict:
|
| 48 |
+
with _lock:
|
| 49 |
+
state = _default_state()
|
| 50 |
+
_save_state(state)
|
| 51 |
+
return state
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def toggle_bot() -> dict:
|
| 55 |
+
with _lock:
|
| 56 |
+
state = _load_state()
|
| 57 |
+
state["bot_active"] = not state["bot_active"]
|
| 58 |
+
_save_state(state)
|
| 59 |
+
return {"bot_active": state["bot_active"]}
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def add_to_balance(amount: float, payment_id: str = "") -> dict:
|
| 63 |
+
"""Add funds to the portfolio balance (wallet top-up)."""
|
| 64 |
+
with _lock:
|
| 65 |
+
state = _load_state()
|
| 66 |
+
state["balance"] += amount
|
| 67 |
+
state["balance"] = round(state["balance"], 2)
|
| 68 |
+
# Also bump initial_balance so reset reflects deposits
|
| 69 |
+
state["initial_balance"] = round(state.get("initial_balance", INITIAL_BALANCE) + amount, 2)
|
| 70 |
+
# Record transaction
|
| 71 |
+
txn = {
|
| 72 |
+
"type": "credit",
|
| 73 |
+
"amount": amount,
|
| 74 |
+
"payment_id": payment_id,
|
| 75 |
+
"timestamp": datetime.now().isoformat(),
|
| 76 |
+
"status": "success",
|
| 77 |
+
}
|
| 78 |
+
state.setdefault("wallet_transactions", []).append(txn)
|
| 79 |
+
_save_state(state)
|
| 80 |
+
return {"status": "success", "new_balance": state["balance"], "transaction": txn}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def withdraw_from_balance(amount: float) -> dict:
|
| 84 |
+
"""Withdraw funds from the portfolio balance."""
|
| 85 |
+
with _lock:
|
| 86 |
+
state = _load_state()
|
| 87 |
+
if amount > state["balance"]:
|
| 88 |
+
return {"status": "error", "message": "Insufficient balance"}
|
| 89 |
+
state["balance"] -= amount
|
| 90 |
+
state["balance"] = round(state["balance"], 2)
|
| 91 |
+
state["initial_balance"] = round(state.get("initial_balance", INITIAL_BALANCE) - amount, 2)
|
| 92 |
+
txn = {
|
| 93 |
+
"type": "debit",
|
| 94 |
+
"amount": amount,
|
| 95 |
+
"timestamp": datetime.now().isoformat(),
|
| 96 |
+
"status": "success",
|
| 97 |
+
}
|
| 98 |
+
state.setdefault("wallet_transactions", []).append(txn)
|
| 99 |
+
_save_state(state)
|
| 100 |
+
return {"status": "success", "new_balance": state["balance"], "transaction": txn}
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def get_wallet_transactions() -> list:
|
| 104 |
+
"""Return wallet transaction history."""
|
| 105 |
+
with _lock:
|
| 106 |
+
state = _load_state()
|
| 107 |
+
return state.get("wallet_transactions", [])
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def compute_dynamic_levels(
|
| 111 |
+
current_price: float,
|
| 112 |
+
atr: float,
|
| 113 |
+
regime: str = "SIDEWAYS",
|
| 114 |
+
is_ipo: bool = False,
|
| 115 |
+
) -> dict:
|
| 116 |
+
"""
|
| 117 |
+
Compute ATR-based dynamic SL / TP1 / TP2 levels.
|
| 118 |
+
Regime and IPO flag modulate width.
|
| 119 |
+
"""
|
| 120 |
+
if atr <= 0:
|
| 121 |
+
atr = current_price * 0.005 # fallback: 0.5% of price
|
| 122 |
+
|
| 123 |
+
# Base multipliers (in ATR units)
|
| 124 |
+
sl_mult = 1.5
|
| 125 |
+
tp1_mult = 2.5
|
| 126 |
+
tp2_mult = 3.5
|
| 127 |
+
|
| 128 |
+
# Regime modifiers
|
| 129 |
+
regime_mod = {
|
| 130 |
+
"BULL_LOW_VOL": {"sl": 0.9, "tp": 1.2},
|
| 131 |
+
"BULL_HIGH_VOL": {"sl": 1.1, "tp": 1.0},
|
| 132 |
+
"BEAR_HIGH_VOL": {"sl": 1.3, "tp": 0.7},
|
| 133 |
+
"SIDEWAYS": {"sl": 1.0, "tp": 0.8},
|
| 134 |
+
}.get(regime, {"sl": 1.0, "tp": 1.0})
|
| 135 |
+
|
| 136 |
+
sl_mult *= regime_mod["sl"]
|
| 137 |
+
tp1_mult *= regime_mod["tp"]
|
| 138 |
+
tp2_mult *= regime_mod["tp"]
|
| 139 |
+
|
| 140 |
+
# IPO boost: more upside room, tighter stop
|
| 141 |
+
if is_ipo:
|
| 142 |
+
tp1_mult *= 1.5
|
| 143 |
+
tp2_mult *= 1.8
|
| 144 |
+
sl_mult *= 0.8
|
| 145 |
+
|
| 146 |
+
sl_distance = atr * sl_mult
|
| 147 |
+
tp1_distance = atr * tp1_mult
|
| 148 |
+
tp2_distance = atr * tp2_mult
|
| 149 |
+
|
| 150 |
+
sl_price = round(current_price - sl_distance, 2)
|
| 151 |
+
tp1_price = round(current_price + tp1_distance, 2)
|
| 152 |
+
tp2_price = round(current_price + tp2_distance, 2)
|
| 153 |
+
|
| 154 |
+
sl_pct = round(((sl_price - current_price) / current_price) * 100, 2)
|
| 155 |
+
tp1_pct = round(((tp1_price - current_price) / current_price) * 100, 2)
|
| 156 |
+
tp2_pct = round(((tp2_price - current_price) / current_price) * 100, 2)
|
| 157 |
+
|
| 158 |
+
# Clamp target pct to [0.5%, 5.0%]
|
| 159 |
+
tp1_pct = max(0.5, min(5.0, tp1_pct))
|
| 160 |
+
tp2_pct = max(tp1_pct + 0.3, min(5.0, tp2_pct))
|
| 161 |
+
tp1_price = round(current_price * (1 + tp1_pct / 100), 2)
|
| 162 |
+
tp2_price = round(current_price * (1 + tp2_pct / 100), 2)
|
| 163 |
+
|
| 164 |
+
# Include TP2 only in bullish regimes or IPO stocks
|
| 165 |
+
include_tp2 = is_ipo or regime in ("BULL_LOW_VOL", "BULL_HIGH_VOL")
|
| 166 |
+
|
| 167 |
+
return {
|
| 168 |
+
"sl_price": sl_price, "sl_pct": sl_pct,
|
| 169 |
+
"tp1_price": tp1_price, "tp1_pct": tp1_pct,
|
| 170 |
+
"tp2_price": tp2_price, "tp2_pct": tp2_pct,
|
| 171 |
+
"include_tp2": include_tp2,
|
| 172 |
+
"atr_used": round(atr, 4),
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def risk_check_position_size(
|
| 177 |
+
balance: float,
|
| 178 |
+
current_price: float,
|
| 179 |
+
sl_price: float,
|
| 180 |
+
risk_pct: float = RISK_PER_TRADE_DEFAULT,
|
| 181 |
+
) -> int:
|
| 182 |
+
"""
|
| 183 |
+
Compute position size so that the max loss (entry→SL) ≤ risk_pct of capital.
|
| 184 |
+
Returns number of shares.
|
| 185 |
+
"""
|
| 186 |
+
risk_pct = max(RISK_PER_TRADE_MIN, min(RISK_PER_TRADE_MAX, risk_pct))
|
| 187 |
+
risk_amount = balance * risk_pct
|
| 188 |
+
per_share_risk = abs(current_price - sl_price)
|
| 189 |
+
if per_share_risk <= 0:
|
| 190 |
+
per_share_risk = current_price * 0.01 # fallback 1%
|
| 191 |
+
shares = int(risk_amount // per_share_risk)
|
| 192 |
+
# Also cap at DEFAULT_POSITION_PCT of balance
|
| 193 |
+
max_by_balance = int((balance * DEFAULT_POSITION_PCT / 100) // current_price)
|
| 194 |
+
shares = min(shares, max_by_balance)
|
| 195 |
+
return max(shares, 0)
|
| 196 |
+
|
| 197 |
+
|
| 198 |
+
def execute_buy(
|
| 199 |
+
ticker: str,
|
| 200 |
+
current_price: float,
|
| 201 |
+
predicted_prices: list,
|
| 202 |
+
confidence: float,
|
| 203 |
+
sl_price: float | None = None,
|
| 204 |
+
tp1_price: float | None = None,
|
| 205 |
+
tp2_price: float | None = None,
|
| 206 |
+
regime: str = "SIDEWAYS",
|
| 207 |
+
) -> dict:
|
| 208 |
+
with _lock:
|
| 209 |
+
state = _load_state()
|
| 210 |
+
|
| 211 |
+
if ticker in state["positions"]:
|
| 212 |
+
return {"status": "skipped", "reason": f"Already holding {ticker}"}
|
| 213 |
+
|
| 214 |
+
# Dynamic position sizing based on risk
|
| 215 |
+
if sl_price and sl_price < current_price:
|
| 216 |
+
shares = risk_check_position_size(state["balance"], current_price, sl_price)
|
| 217 |
+
else:
|
| 218 |
+
position_value = state["balance"] * (DEFAULT_POSITION_PCT / 100)
|
| 219 |
+
shares = int(position_value // current_price)
|
| 220 |
+
# Fallback SL/TP if not provided
|
| 221 |
+
if sl_price is None:
|
| 222 |
+
sl_price = round(current_price * 0.985, 2)
|
| 223 |
+
if tp1_price is None:
|
| 224 |
+
tp1_price = round(current_price * 1.02, 2)
|
| 225 |
+
|
| 226 |
+
if shares == 0:
|
| 227 |
+
return {"status": "skipped", "reason": "Position too small after risk check"}
|
| 228 |
+
|
| 229 |
+
cost = shares * current_price
|
| 230 |
+
if cost > state["balance"]:
|
| 231 |
+
shares = int(state["balance"] // current_price)
|
| 232 |
+
if shares == 0:
|
| 233 |
+
return {"status": "skipped", "reason": "Insufficient balance"}
|
| 234 |
+
cost = shares * current_price
|
| 235 |
+
|
| 236 |
+
# Trailing stop starts at the hard SL
|
| 237 |
+
trailing_stop = sl_price
|
| 238 |
+
|
| 239 |
+
position = {
|
| 240 |
+
"ticker": ticker,
|
| 241 |
+
"shares": shares,
|
| 242 |
+
"buy_price": current_price,
|
| 243 |
+
"cost": round(cost, 2),
|
| 244 |
+
"stop_loss": sl_price,
|
| 245 |
+
"tp1": tp1_price,
|
| 246 |
+
"tp2": tp2_price,
|
| 247 |
+
"trailing_stop": trailing_stop,
|
| 248 |
+
"peak_price": current_price,
|
| 249 |
+
"predicted_prices": predicted_prices,
|
| 250 |
+
"confidence": confidence,
|
| 251 |
+
"regime": regime,
|
| 252 |
+
"buy_time": datetime.now().isoformat(),
|
| 253 |
+
"bar_count": 0,
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
state["balance"] -= cost
|
| 257 |
+
state["balance"] = round(state["balance"], 2)
|
| 258 |
+
state["positions"][ticker] = position
|
| 259 |
+
_save_state(state)
|
| 260 |
+
|
| 261 |
+
return {
|
| 262 |
+
"status": "bought",
|
| 263 |
+
"ticker": ticker,
|
| 264 |
+
"shares": shares,
|
| 265 |
+
"price": current_price,
|
| 266 |
+
"cost": round(cost, 2),
|
| 267 |
+
"stop_loss": sl_price,
|
| 268 |
+
"tp1": tp1_price,
|
| 269 |
+
"tp2": tp2_price,
|
| 270 |
+
"regime": regime,
|
| 271 |
+
"balance": state["balance"],
|
| 272 |
+
}
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
def execute_sell(ticker: str, current_price: float, reason: str) -> dict:
|
| 276 |
+
with _lock:
|
| 277 |
+
state = _load_state()
|
| 278 |
+
|
| 279 |
+
if ticker not in state["positions"]:
|
| 280 |
+
return {"status": "skipped", "reason": f"No position in {ticker}"}
|
| 281 |
+
|
| 282 |
+
pos = state["positions"][ticker]
|
| 283 |
+
revenue = pos["shares"] * current_price
|
| 284 |
+
profit = revenue - pos["cost"]
|
| 285 |
+
profit_pct = (profit / pos["cost"]) * 100
|
| 286 |
+
|
| 287 |
+
trade = {
|
| 288 |
+
"ticker": ticker,
|
| 289 |
+
"shares": pos["shares"],
|
| 290 |
+
"buy_price": pos["buy_price"],
|
| 291 |
+
"sell_price": current_price,
|
| 292 |
+
"cost": pos["cost"],
|
| 293 |
+
"revenue": round(revenue, 2),
|
| 294 |
+
"profit": round(profit, 2),
|
| 295 |
+
"profit_pct": round(profit_pct, 2),
|
| 296 |
+
"buy_time": pos["buy_time"],
|
| 297 |
+
"sell_time": datetime.now().isoformat(),
|
| 298 |
+
"reason": reason,
|
| 299 |
+
"confidence": pos["confidence"],
|
| 300 |
+
}
|
| 301 |
+
|
| 302 |
+
state["balance"] += revenue
|
| 303 |
+
state["balance"] = round(state["balance"], 2)
|
| 304 |
+
state["trade_history"].append(trade)
|
| 305 |
+
del state["positions"][ticker]
|
| 306 |
+
_save_state(state)
|
| 307 |
+
|
| 308 |
+
return {
|
| 309 |
+
"status": "sold",
|
| 310 |
+
"ticker": ticker,
|
| 311 |
+
"shares": trade["shares"],
|
| 312 |
+
"price": current_price,
|
| 313 |
+
"profit": trade["profit"],
|
| 314 |
+
"profit_pct": trade["profit_pct"],
|
| 315 |
+
"reason": reason,
|
| 316 |
+
"balance": state["balance"],
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def check_position(ticker: str, current_price: float) -> dict:
|
| 321 |
+
with _lock:
|
| 322 |
+
state = _load_state()
|
| 323 |
+
|
| 324 |
+
if ticker not in state["positions"]:
|
| 325 |
+
return {"action": "none", "reason": "No position"}
|
| 326 |
+
|
| 327 |
+
pos = state["positions"][ticker]
|
| 328 |
+
buy_price = pos["buy_price"]
|
| 329 |
+
change_pct = ((current_price - buy_price) / buy_price) * 100
|
| 330 |
+
|
| 331 |
+
sl = pos["stop_loss"]
|
| 332 |
+
tp1 = pos.get("tp1") or pos.get("take_profit", buy_price * 1.02)
|
| 333 |
+
|
| 334 |
+
# Hard stop-loss
|
| 335 |
+
if current_price <= sl:
|
| 336 |
+
sl_pct = round(((sl - buy_price) / buy_price) * 100, 2)
|
| 337 |
+
return {"action": "sell", "reason": f"Stop-loss triggered ({sl_pct}%)"}
|
| 338 |
+
|
| 339 |
+
# Take-profit 1 hit
|
| 340 |
+
if current_price >= tp1:
|
| 341 |
+
tp_pct = round(((tp1 - buy_price) / buy_price) * 100, 2)
|
| 342 |
+
return {"action": "sell", "reason": f"Target 1 reached (+{tp_pct}%)"}
|
| 343 |
+
|
| 344 |
+
# Trailing stop: move up as price makes new highs
|
| 345 |
+
if current_price > pos["peak_price"]:
|
| 346 |
+
with _lock:
|
| 347 |
+
state = _load_state()
|
| 348 |
+
if ticker in state["positions"]:
|
| 349 |
+
state["positions"][ticker]["peak_price"] = current_price
|
| 350 |
+
# Trailing stop = 50% of the distance from entry to SL
|
| 351 |
+
trail_dist = abs(buy_price - sl) * 0.5
|
| 352 |
+
new_trailing = round(current_price - trail_dist, 2)
|
| 353 |
+
if new_trailing > state["positions"][ticker]["trailing_stop"]:
|
| 354 |
+
state["positions"][ticker]["trailing_stop"] = new_trailing
|
| 355 |
+
_save_state(state)
|
| 356 |
+
elif current_price <= pos["trailing_stop"]:
|
| 357 |
+
trail_pct = round(((pos["trailing_stop"] - buy_price) / buy_price) * 100, 2)
|
| 358 |
+
return {"action": "sell", "reason": f"Trailing stop triggered ({trail_pct}%)"}
|
| 359 |
+
|
| 360 |
+
# Max hold bars (intraday)
|
| 361 |
+
pos["bar_count"] = pos.get("bar_count", pos.get("day_count", 0)) + 1
|
| 362 |
+
if pos["bar_count"] >= MAX_HOLD_BARS:
|
| 363 |
+
return {"action": "sell", "reason": f"Max hold period ({MAX_HOLD_BARS} bars)"}
|
| 364 |
+
|
| 365 |
+
return {
|
| 366 |
+
"action": "hold",
|
| 367 |
+
"reason": "Within thresholds",
|
| 368 |
+
"current_pnl": round(change_pct, 2),
|
| 369 |
+
"current_price": current_price,
|
| 370 |
+
"stop_loss": sl,
|
| 371 |
+
"tp1": tp1,
|
| 372 |
+
"trailing_stop": pos["trailing_stop"],
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
|
| 376 |
+
def compute_technical_score(indicators: dict) -> float:
|
| 377 |
+
score = 50.0
|
| 378 |
+
|
| 379 |
+
rsi = indicators.get("RSI", 50)
|
| 380 |
+
macd = indicators.get("MACD", 0)
|
| 381 |
+
macd_signal = indicators.get("MACD_Signal", 0)
|
| 382 |
+
sma_20 = indicators.get("SMA_20", 0)
|
| 383 |
+
sma_50 = indicators.get("SMA_50", 0)
|
| 384 |
+
price = indicators.get("price", 0)
|
| 385 |
+
|
| 386 |
+
if rsi < 25:
|
| 387 |
+
score += 20
|
| 388 |
+
elif rsi < 35:
|
| 389 |
+
score += 12
|
| 390 |
+
elif rsi < 45:
|
| 391 |
+
score += 5
|
| 392 |
+
elif rsi > 75:
|
| 393 |
+
score -= 20
|
| 394 |
+
elif rsi > 65:
|
| 395 |
+
score -= 12
|
| 396 |
+
elif rsi > 55:
|
| 397 |
+
score -= 5
|
| 398 |
+
|
| 399 |
+
macd_diff = macd - macd_signal
|
| 400 |
+
if macd_diff > 0:
|
| 401 |
+
score += min(15, macd_diff * 100)
|
| 402 |
+
else:
|
| 403 |
+
score += max(-15, macd_diff * 100)
|
| 404 |
+
|
| 405 |
+
if sma_20 > 0 and price > sma_20:
|
| 406 |
+
score += 8
|
| 407 |
+
elif sma_20 > 0:
|
| 408 |
+
score -= 8
|
| 409 |
+
|
| 410 |
+
if sma_50 > 0 and price > sma_50:
|
| 411 |
+
score += 7
|
| 412 |
+
elif sma_50 > 0:
|
| 413 |
+
score -= 7
|
| 414 |
+
|
| 415 |
+
if sma_20 > 0 and sma_50 > 0:
|
| 416 |
+
if sma_20 > sma_50:
|
| 417 |
+
score += 5
|
| 418 |
+
else:
|
| 419 |
+
score -= 5
|
| 420 |
+
|
| 421 |
+
return max(0, min(100, score))
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
def compute_composite_score(
|
| 425 |
+
predicted_prices: list,
|
| 426 |
+
current_price: float,
|
| 427 |
+
confidence: float,
|
| 428 |
+
indicators: dict | None = None,
|
| 429 |
+
sentiment_score: float | None = None,
|
| 430 |
+
xgb_score: float | None = None,
|
| 431 |
+
) -> dict:
|
| 432 |
+
pred_day5 = predicted_prices[-1]
|
| 433 |
+
pred_change_pct = ((pred_day5 - current_price) / current_price) * 100
|
| 434 |
+
days_above = sum(1 for p in predicted_prices if p > current_price)
|
| 435 |
+
|
| 436 |
+
lstm_score = 50.0
|
| 437 |
+
lstm_score += pred_change_pct * 5
|
| 438 |
+
lstm_score += (days_above - 2.5) * 6
|
| 439 |
+
lstm_score += (confidence - 50) * 0.3
|
| 440 |
+
lstm_score = max(0, min(100, lstm_score))
|
| 441 |
+
|
| 442 |
+
# XGBoost score: if not provided, fallback to 50
|
| 443 |
+
if xgb_score is None:
|
| 444 |
+
xgb_score = 50.0
|
| 445 |
+
|
| 446 |
+
if sentiment_score is not None:
|
| 447 |
+
sent_score = 50 + sentiment_score * 50
|
| 448 |
+
sent_score = max(0, min(100, sent_score))
|
| 449 |
+
else:
|
| 450 |
+
sent_score = 50.0
|
| 451 |
+
|
| 452 |
+
# Blend: 45% LSTM, 45% XGBoost, 10% news
|
| 453 |
+
LSTM_W, XGB_W, SENT_W = 0.45, 0.45, 0.10
|
| 454 |
+
composite = (lstm_score * LSTM_W) + (xgb_score * XGB_W) + (sent_score * SENT_W)
|
| 455 |
+
composite = round(max(0, min(100, composite)), 1)
|
| 456 |
+
|
| 457 |
+
return {
|
| 458 |
+
"composite_score": composite,
|
| 459 |
+
"lstm_score": round(lstm_score, 1),
|
| 460 |
+
"xgb_score": round(xgb_score, 1),
|
| 461 |
+
"sent_score": round(sent_score, 1),
|
| 462 |
+
"pred_change_pct": round(pred_change_pct, 2),
|
| 463 |
+
"days_above": days_above,
|
| 464 |
+
}
|
| 465 |
+
|
| 466 |
+
|
| 467 |
+
def detect_market_regime(
|
| 468 |
+
indicators: dict | None = None,
|
| 469 |
+
vix: dict | None = None,
|
| 470 |
+
nifty: dict | None = None,
|
| 471 |
+
) -> dict:
|
| 472 |
+
"""
|
| 473 |
+
4-state regime detection using VIX, Nifty trend, and stock-level signals.
|
| 474 |
+
States: BULL_LOW_VOL, BULL_HIGH_VOL, BEAR_HIGH_VOL, SIDEWAYS
|
| 475 |
+
"""
|
| 476 |
+
vix_level = (vix or {}).get("vix_level", 15.0)
|
| 477 |
+
nifty_trend = (nifty or {}).get("trend", "flat")
|
| 478 |
+
nifty_bullish = nifty_trend == "bullish"
|
| 479 |
+
nifty_bearish = nifty_trend == "bearish"
|
| 480 |
+
|
| 481 |
+
# Stock-level signals
|
| 482 |
+
bull_signals = 0
|
| 483 |
+
bear_signals = 0
|
| 484 |
+
if indicators:
|
| 485 |
+
rsi = indicators.get("RSI", 50)
|
| 486 |
+
price = indicators.get("price", 0)
|
| 487 |
+
ema9 = indicators.get("EMA_9", indicators.get("SMA_20", 0))
|
| 488 |
+
ema21 = indicators.get("EMA_21", indicators.get("SMA_50", 0))
|
| 489 |
+
supertrend_dir = indicators.get("Supertrend_Dir", indicators.get("supertrend_dir", 0))
|
| 490 |
+
|
| 491 |
+
if rsi < 40: bull_signals += 1
|
| 492 |
+
elif rsi > 65: bear_signals += 1
|
| 493 |
+
|
| 494 |
+
if ema9 > 0 and price > ema9: bull_signals += 1
|
| 495 |
+
elif ema9 > 0: bear_signals += 1
|
| 496 |
+
|
| 497 |
+
if ema21 > 0 and price > ema21: bull_signals += 1
|
| 498 |
+
elif ema21 > 0: bear_signals += 1
|
| 499 |
+
|
| 500 |
+
if supertrend_dir == 1: bull_signals += 1
|
| 501 |
+
elif supertrend_dir == -1: bear_signals += 1
|
| 502 |
+
|
| 503 |
+
macd = indicators.get("MACD", 0)
|
| 504 |
+
macd_signal = indicators.get("MACD_Signal", 0)
|
| 505 |
+
if macd > macd_signal: bull_signals += 1
|
| 506 |
+
else: bear_signals += 1
|
| 507 |
+
|
| 508 |
+
# Combine VIX + Nifty + stock signals into 4-state regime
|
| 509 |
+
high_vol = vix_level >= 18
|
| 510 |
+
very_high_vol = vix_level >= 22
|
| 511 |
+
|
| 512 |
+
if nifty_bearish and (very_high_vol or bear_signals >= 3):
|
| 513 |
+
regime = "BEAR_HIGH_VOL"
|
| 514 |
+
entry_threshold = 0.1 # DEMO: much easier entry
|
| 515 |
+
min_confidence = 5
|
| 516 |
+
elif nifty_bullish and not high_vol and bull_signals >= 2:
|
| 517 |
+
regime = "BULL_LOW_VOL"
|
| 518 |
+
entry_threshold = 0.05 # DEMO: very easy entry
|
| 519 |
+
min_confidence = 2
|
| 520 |
+
elif nifty_bullish and high_vol:
|
| 521 |
+
regime = "BULL_HIGH_VOL"
|
| 522 |
+
entry_threshold = 0.1
|
| 523 |
+
min_confidence = 5
|
| 524 |
+
else:
|
| 525 |
+
regime = "SIDEWAYS"
|
| 526 |
+
entry_threshold = 0.15
|
| 527 |
+
min_confidence = 5
|
| 528 |
+
|
| 529 |
+
return {
|
| 530 |
+
"regime": regime,
|
| 531 |
+
"entry_threshold": entry_threshold,
|
| 532 |
+
"min_confidence": min_confidence,
|
| 533 |
+
"vix_level": vix_level,
|
| 534 |
+
"nifty_trend": nifty_trend,
|
| 535 |
+
"bull_signals": bull_signals,
|
| 536 |
+
"bear_signals": bear_signals,
|
| 537 |
+
}
|
| 538 |
+
|
| 539 |
+
|
| 540 |
+
def evaluate_trade_signal(
|
| 541 |
+
ticker: str,
|
| 542 |
+
current_price: float,
|
| 543 |
+
predicted_prices: list,
|
| 544 |
+
confidence: float,
|
| 545 |
+
indicators: dict | None = None,
|
| 546 |
+
sentiment_score: float | None = None,
|
| 547 |
+
) -> dict:
|
| 548 |
+
"""Legacy trade signal evaluation (used by manual /trade/execute endpoint)."""
|
| 549 |
+
state = _load_state()
|
| 550 |
+
|
| 551 |
+
regime = detect_market_regime(indicators=indicators)
|
| 552 |
+
# Backwards-compatible thresholds derived from new regime
|
| 553 |
+
regime_thresholds = {
|
| 554 |
+
"BULL_LOW_VOL": {"buy": 5, "sell": 30}, # DEMO: much lower buy threshold
|
| 555 |
+
"BULL_HIGH_VOL": {"buy": 8, "sell": 35},
|
| 556 |
+
"BEAR_HIGH_VOL": {"buy": 10, "sell": 40},
|
| 557 |
+
"SIDEWAYS": {"buy": 7, "sell": 35},
|
| 558 |
+
}
|
| 559 |
+
thresholds = regime_thresholds.get(regime["regime"], {"buy": 7, "sell": 35})
|
| 560 |
+
buy_threshold = thresholds["buy"]
|
| 561 |
+
sell_threshold = thresholds["sell"]
|
| 562 |
+
|
| 563 |
+
scores = compute_composite_score(
|
| 564 |
+
predicted_prices, current_price, confidence,
|
| 565 |
+
indicators, sentiment_score,
|
| 566 |
+
)
|
| 567 |
+
composite = scores["composite_score"]
|
| 568 |
+
|
| 569 |
+
pred_day1 = predicted_prices[0]
|
| 570 |
+
pred_day5 = predicted_prices[-1]
|
| 571 |
+
pred_direction = "up" if pred_day5 > current_price else "down"
|
| 572 |
+
|
| 573 |
+
signal = {
|
| 574 |
+
"ticker": ticker,
|
| 575 |
+
"current_price": current_price,
|
| 576 |
+
"predicted_day1": round(pred_day1, 2),
|
| 577 |
+
"predicted_day5": round(pred_day5, 2),
|
| 578 |
+
"pred_change_pct": scores["pred_change_pct"],
|
| 579 |
+
"pred_direction": pred_direction,
|
| 580 |
+
"days_above_current": scores["days_above"],
|
| 581 |
+
"confidence": confidence,
|
| 582 |
+
"composite_score": composite,
|
| 583 |
+
"market_regime": regime["regime"],
|
| 584 |
+
"scores": scores,
|
| 585 |
+
}
|
| 586 |
+
|
| 587 |
+
if ticker in state["positions"]:
|
| 588 |
+
check = check_position(ticker, current_price)
|
| 589 |
+
if check["action"] == "sell":
|
| 590 |
+
result = execute_sell(ticker, current_price, check["reason"])
|
| 591 |
+
signal["action"] = "SELL"
|
| 592 |
+
signal["trade_result"] = result
|
| 593 |
+
elif composite <= sell_threshold:
|
| 594 |
+
result = execute_sell(ticker, current_price,
|
| 595 |
+
f"Bearish signal in {regime['regime']} market ({composite}/100)")
|
| 596 |
+
signal["action"] = "SELL"
|
| 597 |
+
signal["trade_result"] = result
|
| 598 |
+
else:
|
| 599 |
+
signal["action"] = "HOLD"
|
| 600 |
+
signal["position"] = check
|
| 601 |
+
else:
|
| 602 |
+
if composite >= buy_threshold and confidence >= regime.get("min_confidence", 20):
|
| 603 |
+
result = execute_buy(ticker, current_price, predicted_prices, confidence)
|
| 604 |
+
signal["action"] = "BUY"
|
| 605 |
+
signal["trade_result"] = result
|
| 606 |
+
elif (scores["pred_change_pct"] > 2.0 and scores["days_above"] >= 3
|
| 607 |
+
and confidence >= 25):
|
| 608 |
+
result = execute_buy(ticker, current_price, predicted_prices, confidence)
|
| 609 |
+
signal["action"] = "BUY"
|
| 610 |
+
signal["trade_result"] = result
|
| 611 |
+
else:
|
| 612 |
+
signal["action"] = "WAIT"
|
| 613 |
+
signal["reason"] = (
|
| 614 |
+
f"Score {composite}/100 ({regime['regime']} mode, "
|
| 615 |
+
f"need >={buy_threshold})"
|
| 616 |
+
)
|
| 617 |
+
|
| 618 |
+
return signal
|
| 619 |
+
|
frontend/app.js
ADDED
|
@@ -0,0 +1,1057 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
// ============================================================================
|
| 2 |
+
// WALLET FUNCTIONS
|
| 3 |
+
// ============================================================================
|
| 4 |
+
|
| 5 |
+
let walletBalance = 1000000.00; // Initial wallet balance (synced with backend)
|
| 6 |
+
|
| 7 |
+
function showWallet() {
|
| 8 |
+
document.getElementById("walletPanel").classList.remove("hidden");
|
| 9 |
+
document.getElementById("walletActionArea").innerHTML = "";
|
| 10 |
+
document.getElementById("walletMessage").classList.add("hidden");
|
| 11 |
+
loadWalletBalance();
|
| 12 |
+
loadWalletTransactions();
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
function closeWallet() {
|
| 16 |
+
document.getElementById("walletPanel").classList.add("hidden");
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
async function loadWalletBalance() {
|
| 20 |
+
try {
|
| 21 |
+
const res = await fetch(`${API}/api/wallet/balance`);
|
| 22 |
+
const data = await res.json();
|
| 23 |
+
if (data.balance !== undefined) {
|
| 24 |
+
walletBalance = data.balance;
|
| 25 |
+
document.getElementById("walletBalance").textContent = "₹" + formatNumber(walletBalance);
|
| 26 |
+
// Sync portfolio cash balance display
|
| 27 |
+
const portBalanceEl = document.getElementById("portBalance");
|
| 28 |
+
if (portBalanceEl) portBalanceEl.textContent = "₹" + formatNumber(walletBalance);
|
| 29 |
+
}
|
| 30 |
+
} catch (e) {
|
| 31 |
+
console.error("Error loading wallet balance:", e);
|
| 32 |
+
document.getElementById("walletBalance").textContent = "₹" + formatNumber(walletBalance);
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
async function loadWalletTransactions() {
|
| 37 |
+
try {
|
| 38 |
+
const res = await fetch(`${API}/api/wallet/transactions`);
|
| 39 |
+
const data = await res.json();
|
| 40 |
+
const list = document.getElementById("walletTxnList");
|
| 41 |
+
if (!data.transactions || data.transactions.length === 0) {
|
| 42 |
+
list.innerHTML = '<div class="wallet-txn-empty">No transactions yet</div>';
|
| 43 |
+
return;
|
| 44 |
+
}
|
| 45 |
+
list.innerHTML = data.transactions.slice(-10).reverse().map(txn => {
|
| 46 |
+
const date = new Date(txn.timestamp);
|
| 47 |
+
const dateStr = date.toLocaleDateString('en-IN', { day: '2-digit', month: 'short', year: '2-digit' }) + ' ' +
|
| 48 |
+
date.toLocaleTimeString('en-IN', { hour: '2-digit', minute: '2-digit' });
|
| 49 |
+
const sign = txn.type === 'credit' ? '+' : '-';
|
| 50 |
+
return `
|
| 51 |
+
<div class="wallet-txn-item">
|
| 52 |
+
<div class="wallet-txn-left">
|
| 53 |
+
<span class="wallet-txn-type ${txn.type}">${txn.type === 'credit' ? '↓ Deposit' : '↑ Withdrawal'}</span>
|
| 54 |
+
<span class="wallet-txn-date">${dateStr}</span>
|
| 55 |
+
</div>
|
| 56 |
+
<span class="wallet-txn-amount" style="color: ${txn.type === 'credit' ? '#22c55e' : '#ef4444'}">${sign}₹${formatNumber(txn.amount)}</span>
|
| 57 |
+
</div>
|
| 58 |
+
`;
|
| 59 |
+
}).join("");
|
| 60 |
+
} catch (e) {
|
| 61 |
+
console.error("Error loading transactions:", e);
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
function showAddMoney() {
|
| 66 |
+
document.getElementById("walletActionArea").innerHTML = `
|
| 67 |
+
<div class='wallet-form'>
|
| 68 |
+
<h3>Add Money</h3>
|
| 69 |
+
<input type='number' id='addAmount' placeholder='Enter amount (₹)' min='1' />
|
| 70 |
+
<button onclick='startRazorpayPayment()'>Pay with Razorpay</button>
|
| 71 |
+
</div>
|
| 72 |
+
`;
|
| 73 |
+
document.getElementById("walletMessage").classList.add("hidden");
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
function showWithdrawMoney() {
|
| 77 |
+
document.getElementById("walletActionArea").innerHTML = `
|
| 78 |
+
<div class='wallet-form'>
|
| 79 |
+
<h3>Withdraw Money</h3>
|
| 80 |
+
<input type='number' id='withdrawAmount' placeholder='Enter amount (₹)' min='1' />
|
| 81 |
+
<button onclick='startWithdraw()'>Withdraw to Bank</button>
|
| 82 |
+
</div>
|
| 83 |
+
`;
|
| 84 |
+
document.getElementById("walletMessage").classList.add("hidden");
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
function showWalletMessage(message, type = 'success') {
|
| 88 |
+
const msgEl = document.getElementById("walletMessage");
|
| 89 |
+
msgEl.textContent = message;
|
| 90 |
+
msgEl.className = `wallet-message ${type}`;
|
| 91 |
+
msgEl.classList.remove("hidden");
|
| 92 |
+
setTimeout(() => { msgEl.classList.add("hidden"); }, 5000);
|
| 93 |
+
}
|
| 94 |
+
|
| 95 |
+
function quickAdd(amount) {
|
| 96 |
+
// Pre-fill the add money form and trigger Razorpay
|
| 97 |
+
showAddMoney();
|
| 98 |
+
setTimeout(() => {
|
| 99 |
+
const input = document.getElementById('addAmount');
|
| 100 |
+
if (input) input.value = amount;
|
| 101 |
+
startRazorpayPayment();
|
| 102 |
+
}, 100);
|
| 103 |
+
}
|
| 104 |
+
|
| 105 |
+
// Razorpay integration
|
| 106 |
+
function startRazorpayPayment() {
|
| 107 |
+
const amt = document.getElementById('addAmount').value;
|
| 108 |
+
if (!amt || amt <= 0) {
|
| 109 |
+
showWalletMessage('Please enter a valid amount', 'error');
|
| 110 |
+
return;
|
| 111 |
+
}
|
| 112 |
+
|
| 113 |
+
const amountInPaise = Math.round(parseFloat(amt) * 100);
|
| 114 |
+
|
| 115 |
+
const options = {
|
| 116 |
+
key: 'rzp_test_SDdi0bRwia1AA4',
|
| 117 |
+
amount: amountInPaise,
|
| 118 |
+
currency: 'INR',
|
| 119 |
+
name: 'StockSense Wallet',
|
| 120 |
+
description: 'Add Money to Wallet',
|
| 121 |
+
handler: function (response) {
|
| 122 |
+
verifyAndCreditWallet(response.razorpay_payment_id, parseFloat(amt));
|
| 123 |
+
},
|
| 124 |
+
prefill: {
|
| 125 |
+
name: 'User',
|
| 126 |
+
email: 'user@example.com'
|
| 127 |
+
},
|
| 128 |
+
theme: {
|
| 129 |
+
color: '#22c55e'
|
| 130 |
+
},
|
| 131 |
+
modal: {
|
| 132 |
+
ondismiss: function () {
|
| 133 |
+
showWalletMessage('Payment cancelled', 'error');
|
| 134 |
+
}
|
| 135 |
+
}
|
| 136 |
+
};
|
| 137 |
+
|
| 138 |
+
try {
|
| 139 |
+
const rzp = new Razorpay(options);
|
| 140 |
+
rzp.open();
|
| 141 |
+
} catch (e) {
|
| 142 |
+
console.error("Razorpay error:", e);
|
| 143 |
+
showWalletMessage('Payment gateway error. Please try again.', 'error');
|
| 144 |
+
}
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
async function verifyAndCreditWallet(paymentId, amount) {
|
| 148 |
+
try {
|
| 149 |
+
const res = await fetch(`${API}/api/wallet/add`, {
|
| 150 |
+
method: 'POST',
|
| 151 |
+
headers: { 'Content-Type': 'application/json' },
|
| 152 |
+
body: JSON.stringify({ payment_id: paymentId, amount: amount })
|
| 153 |
+
});
|
| 154 |
+
|
| 155 |
+
const data = await res.json();
|
| 156 |
+
|
| 157 |
+
if (res.ok && data.status === 'success') {
|
| 158 |
+
walletBalance = data.new_balance;
|
| 159 |
+
document.getElementById("walletBalance").textContent = "₹" + formatNumber(walletBalance);
|
| 160 |
+
// Sync portfolio cash balance
|
| 161 |
+
const portBalanceEl = document.getElementById("portBalance");
|
| 162 |
+
if (portBalanceEl) portBalanceEl.textContent = "₹" + formatNumber(walletBalance);
|
| 163 |
+
showWalletMessage(`✅ ₹${formatNumber(amount)} added successfully!`, 'success');
|
| 164 |
+
document.getElementById("walletActionArea").innerHTML = "";
|
| 165 |
+
loadWalletTransactions();
|
| 166 |
+
} else {
|
| 167 |
+
showWalletMessage(data.detail || 'Payment verification failed. Contact support.', 'error');
|
| 168 |
+
}
|
| 169 |
+
} catch (e) {
|
| 170 |
+
console.error("Wallet credit error:", e);
|
| 171 |
+
showWalletMessage('Network error. Please check your connection and try again.', 'error');
|
| 172 |
+
}
|
| 173 |
+
}
|
| 174 |
+
|
| 175 |
+
async function startWithdraw() {
|
| 176 |
+
const amt = document.getElementById('withdrawAmount').value;
|
| 177 |
+
if (!amt || amt <= 0) {
|
| 178 |
+
showWalletMessage('Please enter a valid amount', 'error');
|
| 179 |
+
return;
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
const withdrawAmount = parseFloat(amt);
|
| 183 |
+
|
| 184 |
+
if (withdrawAmount > walletBalance) {
|
| 185 |
+
showWalletMessage('Insufficient balance', 'error');
|
| 186 |
+
return;
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
if (!confirm(`Withdraw ₹${formatNumber(withdrawAmount)} from your wallet?`)) {
|
| 190 |
+
return;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
try {
|
| 194 |
+
const res = await fetch(`${API}/api/wallet/withdraw`, {
|
| 195 |
+
method: 'POST',
|
| 196 |
+
headers: { 'Content-Type': 'application/json' },
|
| 197 |
+
body: JSON.stringify({ amount: withdrawAmount })
|
| 198 |
+
});
|
| 199 |
+
|
| 200 |
+
const data = await res.json();
|
| 201 |
+
|
| 202 |
+
if (res.ok && data.status === 'success') {
|
| 203 |
+
walletBalance = data.new_balance;
|
| 204 |
+
document.getElementById("walletBalance").textContent = "₹" + formatNumber(walletBalance);
|
| 205 |
+
// Sync portfolio cash balance
|
| 206 |
+
const portBalanceEl = document.getElementById("portBalance");
|
| 207 |
+
if (portBalanceEl) portBalanceEl.textContent = "₹" + formatNumber(walletBalance);
|
| 208 |
+
showWalletMessage(`✅ ₹${formatNumber(withdrawAmount)} withdrawn successfully!`, 'success');
|
| 209 |
+
document.getElementById("walletActionArea").innerHTML = "";
|
| 210 |
+
loadWalletTransactions();
|
| 211 |
+
} else {
|
| 212 |
+
showWalletMessage(data.detail || 'Withdrawal failed', 'error');
|
| 213 |
+
}
|
| 214 |
+
} catch (e) {
|
| 215 |
+
console.error("Withdrawal error:", e);
|
| 216 |
+
showWalletMessage('Network error. Please check your connection and try again.', 'error');
|
| 217 |
+
}
|
| 218 |
+
}
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
// ============================================================================
|
| 222 |
+
// MAIN APP CODE
|
| 223 |
+
// ============================================================================
|
| 224 |
+
|
| 225 |
+
const API = "http://127.0.0.1:8000";
|
| 226 |
+
let currentTicker = "";
|
| 227 |
+
let liveInterval = null;
|
| 228 |
+
let portfolioInterval = null;
|
| 229 |
+
let mainChart = null;
|
| 230 |
+
let volumeChart = null;
|
| 231 |
+
let predChart = null;
|
| 232 |
+
let activeTimeframe = "1d";
|
| 233 |
+
let loadVersion = 0;
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
let searchTimeout = null;
|
| 237 |
+
|
| 238 |
+
document.addEventListener("DOMContentLoaded", () => {
|
| 239 |
+
loadHighPotential();
|
| 240 |
+
loadPortfolio();
|
| 241 |
+
loadMarketIndices();
|
| 242 |
+
loadWalletBalance();
|
| 243 |
+
setupTimeframeButtons();
|
| 244 |
+
portfolioInterval = setInterval(loadPortfolio, 15000);
|
| 245 |
+
setInterval(loadMarketIndices, 30000);
|
| 246 |
+
|
| 247 |
+
const tickerInput = document.getElementById("tickerInput");
|
| 248 |
+
const dropdown = document.getElementById("searchDropdown");
|
| 249 |
+
|
| 250 |
+
tickerInput.addEventListener("keydown", (e) => {
|
| 251 |
+
if (e.key === "Enter") {
|
| 252 |
+
dropdown.classList.add("hidden");
|
| 253 |
+
loadTicker();
|
| 254 |
+
}
|
| 255 |
+
if (e.key === "Escape") dropdown.classList.add("hidden");
|
| 256 |
+
});
|
| 257 |
+
|
| 258 |
+
tickerInput.addEventListener("input", () => {
|
| 259 |
+
clearTimeout(searchTimeout);
|
| 260 |
+
const q = tickerInput.value.trim();
|
| 261 |
+
if (q.length < 1) {
|
| 262 |
+
dropdown.classList.add("hidden");
|
| 263 |
+
return;
|
| 264 |
+
}
|
| 265 |
+
searchTimeout = setTimeout(() => searchStocks(q), 250);
|
| 266 |
+
});
|
| 267 |
+
|
| 268 |
+
document.addEventListener("click", (e) => {
|
| 269 |
+
if (!e.target.closest(".search-wrapper")) {
|
| 270 |
+
dropdown.classList.add("hidden");
|
| 271 |
+
}
|
| 272 |
+
});
|
| 273 |
+
});
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
async function searchStocks(query) {
|
| 277 |
+
const dropdown = document.getElementById("searchDropdown");
|
| 278 |
+
try {
|
| 279 |
+
const res = await fetch(`${API}/api/search?q=${encodeURIComponent(query)}`);
|
| 280 |
+
const data = await res.json();
|
| 281 |
+
|
| 282 |
+
if (!data.results || data.results.length === 0) {
|
| 283 |
+
dropdown.innerHTML = '<div class="search-no-results">No stocks found</div>';
|
| 284 |
+
dropdown.classList.remove("hidden");
|
| 285 |
+
return;
|
| 286 |
+
}
|
| 287 |
+
|
| 288 |
+
dropdown.innerHTML = data.results.map(s => `
|
| 289 |
+
<div class="search-item" data-ticker="${s.ticker}">
|
| 290 |
+
<span class="search-ticker">${s.ticker}</span>
|
| 291 |
+
<span class="search-name">${s.name}</span>
|
| 292 |
+
</div>
|
| 293 |
+
`).join("");
|
| 294 |
+
|
| 295 |
+
dropdown.querySelectorAll(".search-item").forEach(item => {
|
| 296 |
+
item.addEventListener("click", () => {
|
| 297 |
+
const ticker = item.dataset.ticker;
|
| 298 |
+
document.getElementById("tickerInput").value = ticker;
|
| 299 |
+
dropdown.classList.add("hidden");
|
| 300 |
+
loadTicker(ticker);
|
| 301 |
+
});
|
| 302 |
+
});
|
| 303 |
+
|
| 304 |
+
dropdown.classList.remove("hidden");
|
| 305 |
+
} catch (e) {
|
| 306 |
+
console.error("Search error:", e);
|
| 307 |
+
dropdown.classList.add("hidden");
|
| 308 |
+
}
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
|
| 312 |
+
async function loadMarketIndices() {
|
| 313 |
+
try {
|
| 314 |
+
const res = await fetch(`${API}/api/market-indices`);
|
| 315 |
+
const data = await res.json();
|
| 316 |
+
data.indices.forEach((idx) => {
|
| 317 |
+
let priceEl, changeEl;
|
| 318 |
+
if (idx.name === "NIFTY 50") {
|
| 319 |
+
priceEl = document.getElementById("mktNiftyPrice");
|
| 320 |
+
changeEl = document.getElementById("mktNiftyChange");
|
| 321 |
+
} else if (idx.name === "SENSEX") {
|
| 322 |
+
priceEl = document.getElementById("mktSensexPrice");
|
| 323 |
+
changeEl = document.getElementById("mktSensexChange");
|
| 324 |
+
}
|
| 325 |
+
if (priceEl && changeEl) {
|
| 326 |
+
priceEl.textContent = formatPrice(idx.price);
|
| 327 |
+
const sign = idx.change >= 0 ? "+" : "";
|
| 328 |
+
changeEl.textContent = `${sign}${idx.change.toFixed(2)} (${sign}${idx.change_pct}%)`;
|
| 329 |
+
changeEl.className = `mkt-change ${idx.direction}`;
|
| 330 |
+
}
|
| 331 |
+
});
|
| 332 |
+
} catch (e) {
|
| 333 |
+
console.error("Market indices error:", e);
|
| 334 |
+
}
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
function switchTab(tab) {
|
| 339 |
+
document.querySelectorAll(".nav-tab").forEach((t) => t.classList.remove("active"));
|
| 340 |
+
document.querySelectorAll(".tab-content").forEach((t) => t.classList.add("hidden"));
|
| 341 |
+
|
| 342 |
+
if (tab === "charts") {
|
| 343 |
+
document.getElementById("chartsTab").classList.remove("hidden");
|
| 344 |
+
document.querySelectorAll(".nav-tab")[0].classList.add("active");
|
| 345 |
+
} else {
|
| 346 |
+
document.getElementById("tradingTab").classList.remove("hidden");
|
| 347 |
+
document.querySelectorAll(".nav-tab")[1].classList.add("active");
|
| 348 |
+
loadPortfolio();
|
| 349 |
+
}
|
| 350 |
+
}
|
| 351 |
+
|
| 352 |
+
|
| 353 |
+
function setupTimeframeButtons() {
|
| 354 |
+
document.querySelectorAll(".tf-btn").forEach((btn) => {
|
| 355 |
+
btn.addEventListener("click", () => {
|
| 356 |
+
document.querySelectorAll(".tf-btn").forEach((b) => b.classList.remove("active"));
|
| 357 |
+
btn.classList.add("active");
|
| 358 |
+
activeTimeframe = btn.dataset.tf;
|
| 359 |
+
if (currentTicker) loadChartData(currentTicker, activeTimeframe);
|
| 360 |
+
});
|
| 361 |
+
});
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
async function loadTicker(ticker) {
|
| 366 |
+
ticker = ticker || document.getElementById("tickerInput").value.trim().toUpperCase();
|
| 367 |
+
if (!ticker) return;
|
| 368 |
+
|
| 369 |
+
loadVersion++;
|
| 370 |
+
const myVersion = loadVersion;
|
| 371 |
+
currentTicker = ticker;
|
| 372 |
+
document.getElementById("tickerInput").value = ticker;
|
| 373 |
+
|
| 374 |
+
const emptyState = document.getElementById("chartEmptyState");
|
| 375 |
+
if (emptyState) emptyState.style.display = "none";
|
| 376 |
+
|
| 377 |
+
if (liveInterval) clearInterval(liveInterval);
|
| 378 |
+
|
| 379 |
+
await Promise.all([
|
| 380 |
+
loadLivePrice(ticker, myVersion),
|
| 381 |
+
loadChartData(ticker, activeTimeframe, myVersion),
|
| 382 |
+
loadPrediction(ticker, myVersion),
|
| 383 |
+
loadSentimentAndIndicators(ticker, myVersion),
|
| 384 |
+
]);
|
| 385 |
+
|
| 386 |
+
if (myVersion !== loadVersion) return;
|
| 387 |
+
liveInterval = setInterval(() => loadLivePrice(ticker, loadVersion), 10000);
|
| 388 |
+
}
|
| 389 |
+
|
| 390 |
+
|
| 391 |
+
async function loadLivePrice(ticker, version) {
|
| 392 |
+
try {
|
| 393 |
+
const res = await fetch(`${API}/api/live/${ticker}`);
|
| 394 |
+
if (version !== undefined && version !== loadVersion) return;
|
| 395 |
+
const data = await res.json();
|
| 396 |
+
|
| 397 |
+
document.getElementById("priceBanner").classList.remove("hidden");
|
| 398 |
+
document.getElementById("bannerName").textContent = ticker;
|
| 399 |
+
document.getElementById("bannerPrice").textContent = formatPrice(data.price);
|
| 400 |
+
|
| 401 |
+
const changeEl = document.getElementById("bannerChange");
|
| 402 |
+
const sign = data.change >= 0 ? "+" : "";
|
| 403 |
+
changeEl.textContent = `${sign}${data.change} (${sign}${data.change_pct}%)`;
|
| 404 |
+
changeEl.className = `price-change ${data.direction}`;
|
| 405 |
+
|
| 406 |
+
document.getElementById("statHigh").textContent = formatPrice(data.day_high);
|
| 407 |
+
document.getElementById("statLow").textContent = formatPrice(data.day_low);
|
| 408 |
+
document.getElementById("statVol").textContent = formatVolume(data.volume);
|
| 409 |
+
|
| 410 |
+
document.getElementById("mktStockLabel").textContent = ticker;
|
| 411 |
+
document.getElementById("mktStockPrice").textContent = formatPrice(data.price);
|
| 412 |
+
const mktChg = document.getElementById("mktStockChange");
|
| 413 |
+
mktChg.textContent = `${sign}${data.change} (${sign}${data.change_pct}%)`;
|
| 414 |
+
mktChg.className = `mkt-change ${data.direction}`;
|
| 415 |
+
} catch (e) {
|
| 416 |
+
console.error("Live price error:", e);
|
| 417 |
+
}
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
|
| 421 |
+
async function loadChartData(ticker, timeframe, version) {
|
| 422 |
+
try {
|
| 423 |
+
const [chartRes, infoRes] = await Promise.all([
|
| 424 |
+
fetch(`${API}/api/chart/${ticker}?timeframe=${timeframe}`),
|
| 425 |
+
fetch(`${API}/api/stock/${ticker}`),
|
| 426 |
+
]);
|
| 427 |
+
if (version !== undefined && version !== loadVersion) return;
|
| 428 |
+
const chartData = await chartRes.json();
|
| 429 |
+
const stockData = await infoRes.json();
|
| 430 |
+
|
| 431 |
+
if (stockData.info) {
|
| 432 |
+
const info = stockData.info;
|
| 433 |
+
document.getElementById("bannerName").textContent = `${info.name} (${ticker})`;
|
| 434 |
+
document.getElementById("statOpen").textContent = formatPrice(info.open);
|
| 435 |
+
document.getElementById("statHigh").textContent = formatPrice(info.day_high);
|
| 436 |
+
document.getElementById("statLow").textContent = formatPrice(info.day_low);
|
| 437 |
+
document.getElementById("statVol").textContent = formatVolume(info.volume);
|
| 438 |
+
document.getElementById("stat52H").textContent = formatPrice(info.fifty_two_week_high);
|
| 439 |
+
document.getElementById("stat52L").textContent = formatPrice(info.fifty_two_week_low);
|
| 440 |
+
}
|
| 441 |
+
|
| 442 |
+
drawMainChart(chartData.data);
|
| 443 |
+
drawVolumeChart(chartData.data);
|
| 444 |
+
} catch (e) {
|
| 445 |
+
console.error("Chart error:", e);
|
| 446 |
+
}
|
| 447 |
+
}
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
function drawMainChart(data) {
|
| 451 |
+
const labels = data.map((d) => d.time);
|
| 452 |
+
const closes = data.map((d) => d.close);
|
| 453 |
+
const highs = data.map((d) => d.high);
|
| 454 |
+
const lows = data.map((d) => d.low);
|
| 455 |
+
|
| 456 |
+
const isUp = closes[closes.length - 1] >= closes[0];
|
| 457 |
+
const lineColor = isUp ? "#22c55e" : "#ef4444";
|
| 458 |
+
const fillColor = isUp ? "rgba(34,197,94,0.08)" : "rgba(239,68,68,0.08)";
|
| 459 |
+
|
| 460 |
+
if (mainChart) mainChart.destroy();
|
| 461 |
+
|
| 462 |
+
mainChart = new Chart(document.getElementById("mainChart").getContext("2d"), {
|
| 463 |
+
type: "line",
|
| 464 |
+
data: {
|
| 465 |
+
labels,
|
| 466 |
+
datasets: [
|
| 467 |
+
{ label: "Close", data: closes, borderColor: lineColor, backgroundColor: fillColor, fill: true, tension: 0.3, pointRadius: 0, borderWidth: 2 },
|
| 468 |
+
{ label: "High", data: highs, borderColor: "rgba(34,197,94,0.2)", borderDash: [2, 4], pointRadius: 0, borderWidth: 1, fill: false },
|
| 469 |
+
{ label: "Low", data: lows, borderColor: "rgba(239,68,68,0.2)", borderDash: [2, 4], pointRadius: 0, borderWidth: 1, fill: false },
|
| 470 |
+
],
|
| 471 |
+
},
|
| 472 |
+
options: {
|
| 473 |
+
responsive: true,
|
| 474 |
+
maintainAspectRatio: false,
|
| 475 |
+
interaction: { mode: "index", intersect: false },
|
| 476 |
+
plugins: {
|
| 477 |
+
legend: { labels: { color: "#6b7280", font: { size: 11 } } },
|
| 478 |
+
tooltip: { backgroundColor: "#1a1f2e", borderColor: "#242a38", borderWidth: 1, titleColor: "#fff", bodyColor: "#d1d5db" },
|
| 479 |
+
},
|
| 480 |
+
scales: {
|
| 481 |
+
x: { ticks: { color: "#4b5563", maxTicksLimit: 10, maxRotation: 0, font: { size: 10 } }, grid: { color: "#1f2937" } },
|
| 482 |
+
y: { ticks: { color: "#4b5563", font: { size: 10 } }, grid: { color: "#1f2937" } },
|
| 483 |
+
},
|
| 484 |
+
},
|
| 485 |
+
});
|
| 486 |
+
}
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
function drawVolumeChart(data) {
|
| 490 |
+
const labels = data.map((d) => d.time);
|
| 491 |
+
const volumes = data.map((d) => d.volume);
|
| 492 |
+
const colors = data.map((d, i) => {
|
| 493 |
+
if (i === 0) return "rgba(59,130,246,0.5)";
|
| 494 |
+
return d.close >= data[i - 1].close ? "rgba(34,197,94,0.5)" : "rgba(239,68,68,0.5)";
|
| 495 |
+
});
|
| 496 |
+
|
| 497 |
+
if (volumeChart) volumeChart.destroy();
|
| 498 |
+
|
| 499 |
+
volumeChart = new Chart(document.getElementById("volumeChart").getContext("2d"), {
|
| 500 |
+
type: "bar",
|
| 501 |
+
data: {
|
| 502 |
+
labels,
|
| 503 |
+
datasets: [{ label: "Volume", data: volumes, backgroundColor: colors, borderWidth: 0 }],
|
| 504 |
+
},
|
| 505 |
+
options: {
|
| 506 |
+
responsive: true,
|
| 507 |
+
maintainAspectRatio: false,
|
| 508 |
+
plugins: { legend: { display: false } },
|
| 509 |
+
scales: {
|
| 510 |
+
x: { display: false },
|
| 511 |
+
y: { ticks: { color: "#4b5563", font: { size: 9 } }, grid: { color: "#1f2937" } },
|
| 512 |
+
},
|
| 513 |
+
},
|
| 514 |
+
});
|
| 515 |
+
}
|
| 516 |
+
|
| 517 |
+
|
| 518 |
+
const PRED_MESSAGES = [
|
| 519 |
+
"Extracting 10 features (RSI, MACD, Bollinger, ATR…)",
|
| 520 |
+
"Training 3-layer LSTM neural network…",
|
| 521 |
+
"Running 100 epochs with early stopping…",
|
| 522 |
+
"Analyzing 60-day price patterns…",
|
| 523 |
+
"Applying gradient clipping & LR scheduling…",
|
| 524 |
+
"Generating 5-day price forecast…",
|
| 525 |
+
"Cross-validating with test set…",
|
| 526 |
+
];
|
| 527 |
+
let predMsgInterval = null;
|
| 528 |
+
|
| 529 |
+
async function loadPrediction(ticker, version) {
|
| 530 |
+
const section = document.getElementById("predSection");
|
| 531 |
+
const loader = document.getElementById("predLoader");
|
| 532 |
+
const chartWrap = document.getElementById("predChartWrap");
|
| 533 |
+
const msgEl = document.getElementById("predLoaderMsg");
|
| 534 |
+
|
| 535 |
+
|
| 536 |
+
section.classList.remove("hidden");
|
| 537 |
+
loader.classList.remove("hidden");
|
| 538 |
+
chartWrap.style.display = "none";
|
| 539 |
+
|
| 540 |
+
|
| 541 |
+
let msgIdx = 0;
|
| 542 |
+
msgEl.textContent = PRED_MESSAGES[0];
|
| 543 |
+
predMsgInterval = setInterval(() => {
|
| 544 |
+
msgIdx = (msgIdx + 1) % PRED_MESSAGES.length;
|
| 545 |
+
msgEl.textContent = PRED_MESSAGES[msgIdx];
|
| 546 |
+
}, 3000);
|
| 547 |
+
|
| 548 |
+
try {
|
| 549 |
+
const res = await fetch(`${API}/api/predict/${ticker}`);
|
| 550 |
+
if (version !== undefined && version !== loadVersion) {
|
| 551 |
+
clearInterval(predMsgInterval);
|
| 552 |
+
return;
|
| 553 |
+
}
|
| 554 |
+
const data = await res.json();
|
| 555 |
+
|
| 556 |
+
|
| 557 |
+
clearInterval(predMsgInterval);
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
loader.classList.add("hidden");
|
| 561 |
+
chartWrap.style.display = "";
|
| 562 |
+
|
| 563 |
+
document.getElementById("predConf").textContent = data.confidence + "%";
|
| 564 |
+
document.getElementById("predConf").style.color =
|
| 565 |
+
data.confidence >= 70 ? "#22c55e" : data.confidence >= 45 ? "#eab308" : "#ef4444";
|
| 566 |
+
|
| 567 |
+
document.getElementById("predRisk").textContent = data.risk;
|
| 568 |
+
document.getElementById("predRisk").style.color =
|
| 569 |
+
data.risk === "Low" ? "#22c55e" : data.risk === "Medium" ? "#eab308" : "#ef4444";
|
| 570 |
+
|
| 571 |
+
document.getElementById("predDay1").textContent = "₹" + data.predicted_prices[0];
|
| 572 |
+
document.getElementById("predDay5").textContent = "₹" + data.predicted_prices[4];
|
| 573 |
+
|
| 574 |
+
drawPredictionChart(data);
|
| 575 |
+
} catch (e) {
|
| 576 |
+
console.error("Prediction error:", e);
|
| 577 |
+
clearInterval(predMsgInterval);
|
| 578 |
+
msgEl.textContent = "⚠️ Forecast failed — try again";
|
| 579 |
+
}
|
| 580 |
+
}
|
| 581 |
+
|
| 582 |
+
function drawPredictionChart(pred) {
|
| 583 |
+
const hist = pred.historical_last_30;
|
| 584 |
+
const future = pred.predicted_prices;
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
const histDates = pred.historical_dates || [];
|
| 588 |
+
const predDates = pred.prediction_dates || [];
|
| 589 |
+
|
| 590 |
+
const labels = [];
|
| 591 |
+
for (let i = 0; i < hist.length; i++) {
|
| 592 |
+
labels.push(histDates[i] || `D-${hist.length - i}`);
|
| 593 |
+
}
|
| 594 |
+
for (let i = 0; i < future.length; i++) {
|
| 595 |
+
labels.push(predDates[i] || `+${i + 1}d`);
|
| 596 |
+
}
|
| 597 |
+
|
| 598 |
+
const histData = [...hist, ...Array(future.length).fill(null)];
|
| 599 |
+
const predData = [...Array(hist.length - 1).fill(null), hist[hist.length - 1], ...future];
|
| 600 |
+
|
| 601 |
+
if (predChart) predChart.destroy();
|
| 602 |
+
|
| 603 |
+
predChart = new Chart(document.getElementById("predChart").getContext("2d"), {
|
| 604 |
+
type: "line",
|
| 605 |
+
data: {
|
| 606 |
+
labels,
|
| 607 |
+
datasets: [
|
| 608 |
+
{ label: "Historical", data: histData, borderColor: "#3b82f6", backgroundColor: "rgba(59,130,246,0.05)", fill: true, tension: 0.3, pointRadius: 0, borderWidth: 2 },
|
| 609 |
+
{ label: "Forecast", data: predData, borderColor: "#22c55e", borderDash: [6, 3], backgroundColor: "rgba(34,197,94,0.08)", fill: true, tension: 0.3, pointRadius: 4, borderWidth: 2, pointBackgroundColor: "#22c55e" },
|
| 610 |
+
],
|
| 611 |
+
},
|
| 612 |
+
options: {
|
| 613 |
+
responsive: true,
|
| 614 |
+
plugins: { legend: { labels: { color: "#6b7280" } } },
|
| 615 |
+
scales: {
|
| 616 |
+
x: { ticks: { color: "#4b5563", maxTicksLimit: 10, maxRotation: 45, font: { size: 9 } }, grid: { color: "#1f2937" } },
|
| 617 |
+
y: { ticks: { color: "#4b5563", font: { size: 10 } }, grid: { color: "#1f2937" } },
|
| 618 |
+
},
|
| 619 |
+
},
|
| 620 |
+
});
|
| 621 |
+
}
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
async function loadSentimentAndIndicators(ticker, version) {
|
| 625 |
+
|
| 626 |
+
try {
|
| 627 |
+
const sentRes = await fetch(`${API}/api/sentiment/${ticker}`);
|
| 628 |
+
if (version !== undefined && version !== loadVersion) return;
|
| 629 |
+
const sent = await sentRes.json();
|
| 630 |
+
|
| 631 |
+
const sentPanel = document.getElementById("sentPanel");
|
| 632 |
+
sentPanel.classList.remove("hidden");
|
| 633 |
+
|
| 634 |
+
const gauge = document.getElementById("gaugeCircle");
|
| 635 |
+
gauge.className = `gauge-circle ${sent.overall_sentiment}`;
|
| 636 |
+
document.getElementById("gaugeText").textContent =
|
| 637 |
+
typeof sent.overall_score === "number" ? sent.overall_score.toFixed(2) : sent.overall_score;
|
| 638 |
+
document.getElementById("gaugeLabel").textContent = sent.overall_sentiment.toUpperCase();
|
| 639 |
+
document.getElementById("gaugeLabel").style.color =
|
| 640 |
+
sent.overall_sentiment === "positive" ? "#22c55e" :
|
| 641 |
+
sent.overall_sentiment === "negative" ? "#ef4444" : "#eab308";
|
| 642 |
+
|
| 643 |
+
const sentList = document.getElementById("sentList");
|
| 644 |
+
sentList.innerHTML = "";
|
| 645 |
+
(sent.details || []).forEach((d) => {
|
| 646 |
+
const li = document.createElement("li");
|
| 647 |
+
const cls = d.label === "positive" ? "s-pos" : d.label === "negative" ? "s-neg" : "s-neu";
|
| 648 |
+
const score = d.combined_score !== undefined ? ` (${d.combined_score.toFixed(3)})` : "";
|
| 649 |
+
li.innerHTML = `<span class="${cls}">● ${d.label}${score}</span> ${d.text}`;
|
| 650 |
+
sentList.appendChild(li);
|
| 651 |
+
});
|
| 652 |
+
} catch (e) {
|
| 653 |
+
console.error("Sentiment error:", e);
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
try {
|
| 658 |
+
const infoRes = await fetch(`${API}/api/summary/${ticker}`);
|
| 659 |
+
if (version !== undefined && version !== loadVersion) return;
|
| 660 |
+
const data = await infoRes.json();
|
| 661 |
+
|
| 662 |
+
if (data.indicators) {
|
| 663 |
+
const indPanel = document.getElementById("indPanel");
|
| 664 |
+
indPanel.classList.remove("hidden");
|
| 665 |
+
const indBody = document.getElementById("indBody");
|
| 666 |
+
indBody.innerHTML = "";
|
| 667 |
+
Object.entries(data.indicators).forEach(([key, val]) => {
|
| 668 |
+
const tr = document.createElement("tr");
|
| 669 |
+
tr.innerHTML = `<td>${key}</td><td>${val}</td>`;
|
| 670 |
+
indBody.appendChild(tr);
|
| 671 |
+
});
|
| 672 |
+
}
|
| 673 |
+
} catch (e) {
|
| 674 |
+
console.error("Indicators error:", e);
|
| 675 |
+
}
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
|
| 679 |
+
async function loadHighPotential() {
|
| 680 |
+
try {
|
| 681 |
+
const res = await fetch(`${API}/api/high-potential`);
|
| 682 |
+
const data = await res.json();
|
| 683 |
+
|
| 684 |
+
document.getElementById("hpLoader").classList.add("hidden");
|
| 685 |
+
const list = document.getElementById("hpList");
|
| 686 |
+
list.innerHTML = "";
|
| 687 |
+
|
| 688 |
+
data.stocks.forEach((s) => {
|
| 689 |
+
const div = document.createElement("div");
|
| 690 |
+
div.className = "hp-item";
|
| 691 |
+
div.onclick = () => {
|
| 692 |
+
document.getElementById("tickerInput").value = s.ticker;
|
| 693 |
+
loadTicker(s.ticker);
|
| 694 |
+
};
|
| 695 |
+
|
| 696 |
+
const changeClass = s.change_pct >= 0 ? "up" : "down";
|
| 697 |
+
const sign = s.change_pct >= 0 ? "+" : "";
|
| 698 |
+
const scoreClass = s.score >= 70 ? "high" : s.score >= 45 ? "med" : "low";
|
| 699 |
+
|
| 700 |
+
div.innerHTML = `
|
| 701 |
+
<div>
|
| 702 |
+
<div class="hp-ticker">${s.ticker}</div>
|
| 703 |
+
<div class="hp-name">${s.name}</div>
|
| 704 |
+
</div>
|
| 705 |
+
<div>
|
| 706 |
+
<div class="hp-price">₹${s.price}</div>
|
| 707 |
+
<div class="hp-change ${changeClass}">${sign}${s.change_pct}%</div>
|
| 708 |
+
</div>
|
| 709 |
+
<div class="hp-score ${scoreClass}">${s.signal}</div>
|
| 710 |
+
`;
|
| 711 |
+
list.appendChild(div);
|
| 712 |
+
});
|
| 713 |
+
} catch (e) {
|
| 714 |
+
document.getElementById("hpLoader").textContent = "⚠️ Scanner unavailable";
|
| 715 |
+
console.error("High potential error:", e);
|
| 716 |
+
}
|
| 717 |
+
}
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
async function loadPortfolio() {
|
| 721 |
+
try {
|
| 722 |
+
const res = await fetch(`${API}/api/trade/portfolio`);
|
| 723 |
+
const data = await res.json();
|
| 724 |
+
|
| 725 |
+
|
| 726 |
+
document.getElementById("portValue").textContent = "₹" + formatNumber(data.total_value || data.balance);
|
| 727 |
+
document.getElementById("portBalance").textContent = "₹" + formatNumber(data.balance);
|
| 728 |
+
|
| 729 |
+
const unrealized = data.total_unrealized_pnl || 0;
|
| 730 |
+
const unrealizedEl = document.getElementById("portUnrealized");
|
| 731 |
+
unrealizedEl.textContent = (unrealized >= 0 ? "+₹" : "-₹") + formatNumber(Math.abs(unrealized));
|
| 732 |
+
unrealizedEl.style.color = unrealized >= 0 ? "#22c55e" : "#ef4444";
|
| 733 |
+
|
| 734 |
+
const realized = data.total_realized_pnl || 0;
|
| 735 |
+
const realizedEl = document.getElementById("portRealized");
|
| 736 |
+
realizedEl.textContent = (realized >= 0 ? "+₹" : "-₹") + formatNumber(Math.abs(realized));
|
| 737 |
+
realizedEl.style.color = realized >= 0 ? "#22c55e" : "#ef4444";
|
| 738 |
+
|
| 739 |
+
document.getElementById("portWinRate").textContent = (data.win_rate || 0) + "%";
|
| 740 |
+
document.getElementById("portWinRate").style.color = data.win_rate >= 50 ? "#22c55e" : "#ef4444";
|
| 741 |
+
|
| 742 |
+
document.getElementById("portTrades").textContent = data.total_trades || 0;
|
| 743 |
+
|
| 744 |
+
|
| 745 |
+
const botDot = document.getElementById("botDot");
|
| 746 |
+
const botStatus = document.getElementById("botStatus");
|
| 747 |
+
const toggleBtn = document.getElementById("toggleBotBtn");
|
| 748 |
+
|
| 749 |
+
if (data.bot_active) {
|
| 750 |
+
botDot.className = "bot-dot active";
|
| 751 |
+
botStatus.textContent = "Bot: ACTIVE";
|
| 752 |
+
botStatus.style.color = "#22c55e";
|
| 753 |
+
toggleBtn.textContent = "⏹ Deactivate Bot";
|
| 754 |
+
toggleBtn.classList.add("active");
|
| 755 |
+
} else {
|
| 756 |
+
botDot.className = "bot-dot";
|
| 757 |
+
botStatus.textContent = "Bot: OFF";
|
| 758 |
+
botStatus.style.color = "#ef4444";
|
| 759 |
+
toggleBtn.textContent = "⚡ Activate Bot";
|
| 760 |
+
toggleBtn.classList.remove("active");
|
| 761 |
+
}
|
| 762 |
+
|
| 763 |
+
|
| 764 |
+
renderPositions(data.positions || {});
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
renderTradeHistory(data.trade_history || []);
|
| 768 |
+
|
| 769 |
+
} catch (e) {
|
| 770 |
+
console.error("Portfolio error:", e);
|
| 771 |
+
}
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
|
| 775 |
+
function renderPositions(positions) {
|
| 776 |
+
const tbody = document.getElementById("positionsBody");
|
| 777 |
+
|
| 778 |
+
if (Object.keys(positions).length === 0) {
|
| 779 |
+
tbody.innerHTML = '<tr><td colspan="9" class="empty-msg">No open positions — activate the bot or trade manually</td></tr>';
|
| 780 |
+
return;
|
| 781 |
+
}
|
| 782 |
+
|
| 783 |
+
tbody.innerHTML = "";
|
| 784 |
+
Object.entries(positions).forEach(([ticker, pos]) => {
|
| 785 |
+
const pnl = pos.unrealized_pnl || 0;
|
| 786 |
+
const pnlPct = pos.pnl_pct || 0;
|
| 787 |
+
const pnlClass = pnl >= 0 ? "pnl-positive" : "pnl-negative";
|
| 788 |
+
const pnlSign = pnl >= 0 ? "+" : "";
|
| 789 |
+
const sl = pos.stop_loss || 0;
|
| 790 |
+
const tp = pos.tp1 || pos.take_profit || 0;
|
| 791 |
+
|
| 792 |
+
const tr = document.createElement("tr");
|
| 793 |
+
tr.innerHTML = `
|
| 794 |
+
<td class="ticker-col">${ticker}</td>
|
| 795 |
+
<td>${pos.shares}</td>
|
| 796 |
+
<td>₹${pos.buy_price}</td>
|
| 797 |
+
<td>₹${pos.current_price || pos.buy_price}</td>
|
| 798 |
+
<td class="${pnlClass}">${pnlSign}₹${formatNumber(Math.abs(pnl))}</td>
|
| 799 |
+
<td class="${pnlClass}">${pnlSign}${pnlPct}%</td>
|
| 800 |
+
<td style="color:#ef4444">₹${sl}</td>
|
| 801 |
+
<td style="color:#22c55e">₹${tp}</td>
|
| 802 |
+
<td><button class="btn-sell-small" onclick="forceSell('${ticker}')">SELL</button></td>
|
| 803 |
+
`;
|
| 804 |
+
tbody.appendChild(tr);
|
| 805 |
+
});
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
|
| 809 |
+
function renderTradeHistory(trades) {
|
| 810 |
+
const log = document.getElementById("tradeLog");
|
| 811 |
+
|
| 812 |
+
if (trades.length === 0) {
|
| 813 |
+
log.innerHTML = '<div class="empty-msg">No trades yet. Activate the bot or execute a trade.</div>';
|
| 814 |
+
return;
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
log.innerHTML = "";
|
| 818 |
+
|
| 819 |
+
[...trades].reverse().forEach((t) => {
|
| 820 |
+
const profit = (typeof t.profit === "number" && !isNaN(t.profit)) ? t.profit : 0;
|
| 821 |
+
const profit_pct = (typeof t.profit_pct === "number" && !isNaN(t.profit_pct)) ? t.profit_pct : 0;
|
| 822 |
+
const profitClass = profit >= 0 ? "pnl-positive" : "pnl-negative";
|
| 823 |
+
const profitSign = profit >= 0 ? "+" : "";
|
| 824 |
+
const time = new Date(t.sell_time).toLocaleString();
|
| 825 |
+
|
| 826 |
+
const entry = document.createElement("div");
|
| 827 |
+
entry.className = "trade-entry";
|
| 828 |
+
entry.innerHTML = `
|
| 829 |
+
<span class="te-time">${time}</span>
|
| 830 |
+
<span>
|
| 831 |
+
<span class="te-ticker">${t.ticker}</span>
|
| 832 |
+
— ${t.shares} shares @ ₹${t.buy_price} → ₹${t.sell_price}
|
| 833 |
+
<span style="color:#6b7280;font-size:0.7rem;"> (${t.reason})</span>
|
| 834 |
+
</span>
|
| 835 |
+
<span class="${profitClass}">${profitSign}₹${formatNumber(Math.abs(profit))}</span>
|
| 836 |
+
<span class="${profitClass}">${profitSign}${profit_pct}%</span>
|
| 837 |
+
`;
|
| 838 |
+
log.appendChild(entry);
|
| 839 |
+
});
|
| 840 |
+
}
|
| 841 |
+
|
| 842 |
+
|
| 843 |
+
function addToFeed(message, type) {
|
| 844 |
+
const feed = document.getElementById("tradeFeed");
|
| 845 |
+
const time = new Date().toLocaleTimeString();
|
| 846 |
+
|
| 847 |
+
const item = document.createElement("div");
|
| 848 |
+
item.className = `feed-item ${type}`;
|
| 849 |
+
item.innerHTML = `<span style="color:#6b7280;font-size:0.7rem;">[${time}]</span> ${message}`;
|
| 850 |
+
|
| 851 |
+
|
| 852 |
+
feed.insertBefore(item, feed.firstChild);
|
| 853 |
+
|
| 854 |
+
|
| 855 |
+
while (feed.children.length > 50) {
|
| 856 |
+
feed.removeChild(feed.lastChild);
|
| 857 |
+
}
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
|
| 861 |
+
async function toggleBot() {
|
| 862 |
+
try {
|
| 863 |
+
const res = await fetch(`${API}/api/trade/toggle`, { method: "POST" });
|
| 864 |
+
const data = await res.json();
|
| 865 |
+
|
| 866 |
+
if (data.bot_active) {
|
| 867 |
+
addToFeed("🤖 <strong>Auto-trading bot ACTIVATED</strong> — scanning for opportunities...", "buy");
|
| 868 |
+
} else {
|
| 869 |
+
addToFeed("⏹ <strong>Auto-trading bot DEACTIVATED</strong>", "sell");
|
| 870 |
+
}
|
| 871 |
+
|
| 872 |
+
loadPortfolio();
|
| 873 |
+
} catch (e) {
|
| 874 |
+
console.error("Toggle error:", e);
|
| 875 |
+
addToFeed("❌ Failed to toggle bot", "sell");
|
| 876 |
+
}
|
| 877 |
+
}
|
| 878 |
+
|
| 879 |
+
|
| 880 |
+
async function executeManualTrade() {
|
| 881 |
+
const ticker = currentTicker || document.getElementById("tickerInput").value.trim().toUpperCase();
|
| 882 |
+
if (!ticker) {
|
| 883 |
+
alert("Enter a ticker first!");
|
| 884 |
+
return;
|
| 885 |
+
}
|
| 886 |
+
|
| 887 |
+
addToFeed(`🔄 Analyzing <strong>${ticker}</strong> — running LSTM + Technical + Sentiment...`, "hold");
|
| 888 |
+
|
| 889 |
+
try {
|
| 890 |
+
const res = await fetch(`${API}/api/trade/execute/${ticker}`, { method: "POST" });
|
| 891 |
+
const data = await res.json();
|
| 892 |
+
|
| 893 |
+
const action = data.action;
|
| 894 |
+
const price = data.current_price;
|
| 895 |
+
|
| 896 |
+
if (action === "BUY") {
|
| 897 |
+
const tr = data.trade_result;
|
| 898 |
+
const cs = data.composite_score || '?';
|
| 899 |
+
const regime = data.market_regime || 'NEUTRAL';
|
| 900 |
+
const regimeIcon = regime === 'BULL' ? '🐂' : regime === 'BEAR' ? '🐻' : '⚖️';
|
| 901 |
+
addToFeed(
|
| 902 |
+
`🟢 <strong>BOUGHT ${tr.shares} x ${ticker}</strong> @ ₹${price} | ` +
|
| 903 |
+
`${regimeIcon} ${regime} | Score: ${cs}/100 | SL: ₹${tr.stop_loss} | TP: ₹${tr.take_profit}`,
|
| 904 |
+
"buy"
|
| 905 |
+
);
|
| 906 |
+
} else if (action === "SELL") {
|
| 907 |
+
const tr = data.trade_result;
|
| 908 |
+
const profit = (typeof tr.profit === "number" && !isNaN(tr.profit)) ? tr.profit : 0;
|
| 909 |
+
const profit_pct = (typeof tr.profit_pct === "number" && !isNaN(tr.profit_pct)) ? tr.profit_pct : 0;
|
| 910 |
+
const profitSign = profit >= 0 ? "+" : "";
|
| 911 |
+
addToFeed(
|
| 912 |
+
`🔴 <strong>SOLD ${ticker}</strong> @ ₹${price} | ` +
|
| 913 |
+
`P&L: ${profitSign}₹${profit} (${profitSign}${profit_pct}%) | Reason: ${tr.reason}`,
|
| 914 |
+
"sell"
|
| 915 |
+
);
|
| 916 |
+
} else if (action === "HOLD") {
|
| 917 |
+
addToFeed(
|
| 918 |
+
`🟡 <strong>HOLD ${ticker}</strong> @ ₹${price} — position within thresholds ` +
|
| 919 |
+
`(P&L: ${data.position.current_pnl}%)`,
|
| 920 |
+
"hold"
|
| 921 |
+
);
|
| 922 |
+
} else {
|
| 923 |
+
const cs = data.composite_score || '?';
|
| 924 |
+
const regime = data.market_regime || 'NEUTRAL';
|
| 925 |
+
const regimeIcon = regime === 'BULL' ? '🐂' : regime === 'BEAR' ? '🐻' : '⚖️';
|
| 926 |
+
addToFeed(
|
| 927 |
+
`⚪ <strong>WAIT on ${ticker}</strong> @ ₹${price} — ${regimeIcon} ${regime} | Score: ${cs}/100 | ` +
|
| 928 |
+
`${data.reason || "conditions not met"}`,
|
| 929 |
+
"wait"
|
| 930 |
+
);
|
| 931 |
+
}
|
| 932 |
+
|
| 933 |
+
loadPortfolio();
|
| 934 |
+
} catch (e) {
|
| 935 |
+
console.error("Trade error:", e);
|
| 936 |
+
addToFeed(`❌ Trade execution failed for ${ticker}: ${e.message}`, "sell");
|
| 937 |
+
}
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
|
| 941 |
+
async function runAutoScan() {
|
| 942 |
+
addToFeed("🔍 <strong>Auto-scan started</strong> — XGBoost intraday analysis with regime detection...", "hold");
|
| 943 |
+
|
| 944 |
+
try {
|
| 945 |
+
const res = await fetch(`${API}/api/trade/auto-scan`, { method: "POST" });
|
| 946 |
+
const data = await res.json();
|
| 947 |
+
|
| 948 |
+
if (data.status === "inactive") {
|
| 949 |
+
addToFeed("⚠️ Bot is OFF — activate it first before scanning", "wait");
|
| 950 |
+
return;
|
| 951 |
+
}
|
| 952 |
+
|
| 953 |
+
addToFeed(`✅ <strong>Scan complete</strong> — analyzed ${data.scanned} stocks`, "hold");
|
| 954 |
+
|
| 955 |
+
|
| 956 |
+
(data.results || []).forEach((r) => {
|
| 957 |
+
const action = r.action;
|
| 958 |
+
const ticker = r.ticker;
|
| 959 |
+
|
| 960 |
+
if (action === "BUY" && r.trade_result) {
|
| 961 |
+
const tr = r.trade_result;
|
| 962 |
+
if (tr.status === "bought") {
|
| 963 |
+
addToFeed(
|
| 964 |
+
`🟢 <strong>AUTO-BUY ${tr.shares} x ${ticker}</strong> @ ₹${tr.price} | ` +
|
| 965 |
+
`SL: ₹${tr.stop_loss || 0} | TP: ₹${tr.tp1 || 0}`,
|
| 966 |
+
"buy"
|
| 967 |
+
);
|
| 968 |
+
} else {
|
| 969 |
+
addToFeed(`⚪ ${ticker}: ${tr.reason || "skipped"}`, "wait");
|
| 970 |
+
}
|
| 971 |
+
} else if (action === "SELL" && (r.trade_result || r.result)) {
|
| 972 |
+
const tr = r.trade_result || r.result;
|
| 973 |
+
const profit = (typeof tr.profit === "number" && !isNaN(tr.profit)) ? tr.profit : 0;
|
| 974 |
+
const profitSign = profit >= 0 ? "+" : "";
|
| 975 |
+
addToFeed(
|
| 976 |
+
`🔴 <strong>AUTO-SELL ${ticker}</strong> | P&L: ${profitSign}₹${profit} | ${tr.reason || ''}`,
|
| 977 |
+
"sell"
|
| 978 |
+
);
|
| 979 |
+
} else if (action === "WAIT") {
|
| 980 |
+
const regime = r.regime || 'SIDEWAYS';
|
| 981 |
+
const conf = r.confidence || 0;
|
| 982 |
+
const expRet = r.expected_return_pct || 0;
|
| 983 |
+
const regimeIcon = regime.includes('BULL') ? '🐂' : regime.includes('BEAR') ? '🐻' : '⚖️';
|
| 984 |
+
addToFeed(
|
| 985 |
+
`⚪ ${ticker}: WAIT — ${regimeIcon} ${regime} | Confidence: ${conf} | Expected: ${expRet}%`,
|
| 986 |
+
"wait"
|
| 987 |
+
);
|
| 988 |
+
} else if (action === "SKIP") {
|
| 989 |
+
addToFeed(`⚪ ${ticker}: SKIP — ${r.reason || 'insufficient data'}`, "wait");
|
| 990 |
+
}
|
| 991 |
+
});
|
| 992 |
+
|
| 993 |
+
loadPortfolio();
|
| 994 |
+
} catch (e) {
|
| 995 |
+
console.error("Scan error:", e);
|
| 996 |
+
addToFeed(`❌ Auto-scan failed: ${e.message}`, "sell");
|
| 997 |
+
}
|
| 998 |
+
}
|
| 999 |
+
|
| 1000 |
+
|
| 1001 |
+
async function forceSell(ticker) {
|
| 1002 |
+
if (!confirm(`Force sell all ${ticker} shares at market price?`)) return;
|
| 1003 |
+
|
| 1004 |
+
addToFeed(`🔄 Force-selling <strong>${ticker}</strong>...`, "hold");
|
| 1005 |
+
|
| 1006 |
+
try {
|
| 1007 |
+
const res = await fetch(`${API}/api/trade/sell/${ticker}`, { method: "POST" });
|
| 1008 |
+
const data = await res.json();
|
| 1009 |
+
|
| 1010 |
+
if (data.status === "sold") {
|
| 1011 |
+
const profitSign = data.profit >= 0 ? "+" : "";
|
| 1012 |
+
addToFeed(
|
| 1013 |
+
`🔴 <strong>FORCE-SOLD ${ticker}</strong> @ ₹${data.price} | ` +
|
| 1014 |
+
`P&L: ${profitSign}₹${data.profit} (${profitSign}${data.profit_pct}%)`,
|
| 1015 |
+
"sell"
|
| 1016 |
+
);
|
| 1017 |
+
} else {
|
| 1018 |
+
addToFeed(`⚠️ ${ticker}: ${data.reason}`, "wait");
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
loadPortfolio();
|
| 1022 |
+
} catch (e) {
|
| 1023 |
+
console.error("Force sell error:", e);
|
| 1024 |
+
addToFeed(`❌ Force sell failed: ${e.message}`, "sell");
|
| 1025 |
+
}
|
| 1026 |
+
}
|
| 1027 |
+
|
| 1028 |
+
|
| 1029 |
+
async function resetPortfolio() {
|
| 1030 |
+
if (!confirm("Reset portfolio to ₹10,00,000? All positions and history will be lost.")) return;
|
| 1031 |
+
|
| 1032 |
+
try {
|
| 1033 |
+
await fetch(`${API}/api/trade/reset`, { method: "POST" });
|
| 1034 |
+
addToFeed("🔄 <strong>Portfolio reset</strong> to ₹10,00,000.00", "hold");
|
| 1035 |
+
loadPortfolio();
|
| 1036 |
+
} catch (e) {
|
| 1037 |
+
console.error("Reset error:", e);
|
| 1038 |
+
}
|
| 1039 |
+
}
|
| 1040 |
+
|
| 1041 |
+
|
| 1042 |
+
function formatPrice(p) {
|
| 1043 |
+
if (!p) return "—";
|
| 1044 |
+
return parseFloat(p).toLocaleString("en-IN", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
| 1045 |
+
}
|
| 1046 |
+
|
| 1047 |
+
function formatVolume(v) {
|
| 1048 |
+
if (!v) return "—";
|
| 1049 |
+
if (v >= 1e9) return (v / 1e9).toFixed(2) + "B";
|
| 1050 |
+
if (v >= 1e6) return (v / 1e6).toFixed(2) + "M";
|
| 1051 |
+
if (v >= 1e3) return (v / 1e3).toFixed(1) + "K";
|
| 1052 |
+
return v.toString();
|
| 1053 |
+
}
|
| 1054 |
+
|
| 1055 |
+
function formatNumber(n) {
|
| 1056 |
+
return parseFloat(n).toLocaleString("en-IN", { minimumFractionDigits: 2, maximumFractionDigits: 2 });
|
| 1057 |
+
}
|
frontend/backend_wallet_api.py
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Add these endpoints to your FastAPI backend (main.py or similar)
|
| 2 |
+
|
| 3 |
+
from fastapi import FastAPI, HTTPException
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
from typing import Optional
|
| 6 |
+
import time
|
| 7 |
+
|
| 8 |
+
app = FastAPI()
|
| 9 |
+
|
| 10 |
+
# In-memory wallet balance (replace with database in production)
|
| 11 |
+
wallet_data = {
|
| 12 |
+
"balance": 10000.00,
|
| 13 |
+
"transactions": []
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
class AddMoneyRequest(BaseModel):
|
| 17 |
+
payment_id: str
|
| 18 |
+
amount: float
|
| 19 |
+
|
| 20 |
+
class WithdrawRequest(BaseModel):
|
| 21 |
+
amount: float
|
| 22 |
+
|
| 23 |
+
@app.get("/api/wallet/balance")
|
| 24 |
+
async def get_wallet_balance():
|
| 25 |
+
"""Get current wallet balance"""
|
| 26 |
+
return {
|
| 27 |
+
"balance": wallet_data["balance"],
|
| 28 |
+
"status": "success"
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
@app.post("/api/wallet/add")
|
| 32 |
+
async def add_money(request: AddMoneyRequest):
|
| 33 |
+
"""
|
| 34 |
+
Add money to wallet after successful Razorpay payment
|
| 35 |
+
|
| 36 |
+
In production, you should:
|
| 37 |
+
1. Verify the payment with Razorpay API using payment_id
|
| 38 |
+
2. Check payment status and amount
|
| 39 |
+
3. Store transaction in database
|
| 40 |
+
"""
|
| 41 |
+
|
| 42 |
+
# TODO: Verify payment with Razorpay
|
| 43 |
+
# For now, we'll trust the frontend (NOT recommended for production)
|
| 44 |
+
|
| 45 |
+
if request.amount <= 0:
|
| 46 |
+
raise HTTPException(status_code=400, detail="Invalid amount")
|
| 47 |
+
|
| 48 |
+
# Add money to wallet
|
| 49 |
+
wallet_data["balance"] += request.amount
|
| 50 |
+
|
| 51 |
+
# Store transaction
|
| 52 |
+
transaction = {
|
| 53 |
+
"type": "credit",
|
| 54 |
+
"amount": request.amount,
|
| 55 |
+
"payment_id": request.payment_id,
|
| 56 |
+
"timestamp": time.time(),
|
| 57 |
+
"status": "success"
|
| 58 |
+
}
|
| 59 |
+
wallet_data["transactions"].append(transaction)
|
| 60 |
+
|
| 61 |
+
return {
|
| 62 |
+
"status": "success",
|
| 63 |
+
"message": f"₹{request.amount} added successfully",
|
| 64 |
+
"new_balance": wallet_data["balance"],
|
| 65 |
+
"transaction": transaction
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
@app.post("/api/wallet/withdraw")
|
| 69 |
+
async def withdraw_money(request: WithdrawRequest):
|
| 70 |
+
"""
|
| 71 |
+
Withdraw money from wallet
|
| 72 |
+
|
| 73 |
+
In production, you should:
|
| 74 |
+
1. Verify user authentication
|
| 75 |
+
2. Check withdrawal limits
|
| 76 |
+
3. Process actual bank transfer
|
| 77 |
+
4. Store transaction in database
|
| 78 |
+
"""
|
| 79 |
+
|
| 80 |
+
if request.amount <= 0:
|
| 81 |
+
raise HTTPException(status_code=400, detail="Invalid amount")
|
| 82 |
+
|
| 83 |
+
# Check sufficient balance
|
| 84 |
+
if wallet_data["balance"] < request.amount:
|
| 85 |
+
raise HTTPException(status_code=400, detail="Insufficient balance")
|
| 86 |
+
|
| 87 |
+
# Deduct money from wallet
|
| 88 |
+
wallet_data["balance"] -= request.amount
|
| 89 |
+
|
| 90 |
+
# Store transaction
|
| 91 |
+
transaction = {
|
| 92 |
+
"type": "debit",
|
| 93 |
+
"amount": request.amount,
|
| 94 |
+
"timestamp": time.time(),
|
| 95 |
+
"status": "success"
|
| 96 |
+
}
|
| 97 |
+
wallet_data["transactions"].append(transaction)
|
| 98 |
+
|
| 99 |
+
return {
|
| 100 |
+
"status": "success",
|
| 101 |
+
"message": f"₹{request.amount} withdrawn successfully",
|
| 102 |
+
"new_balance": wallet_data["balance"],
|
| 103 |
+
"transaction": transaction
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
@app.get("/api/wallet/transactions")
|
| 107 |
+
async def get_transactions():
|
| 108 |
+
"""Get all wallet transactions"""
|
| 109 |
+
return {
|
| 110 |
+
"transactions": wallet_data["transactions"],
|
| 111 |
+
"status": "success"
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
# Example of how to verify Razorpay payment (add this to your add_money endpoint)
|
| 115 |
+
"""
|
| 116 |
+
import razorpay
|
| 117 |
+
|
| 118 |
+
razorpay_client = razorpay.Client(auth=("YOUR_KEY_ID", "YOUR_KEY_SECRET"))
|
| 119 |
+
|
| 120 |
+
def verify_razorpay_payment(payment_id: str, amount: float):
|
| 121 |
+
try:
|
| 122 |
+
# Fetch payment details
|
| 123 |
+
payment = razorpay_client.payment.fetch(payment_id)
|
| 124 |
+
|
| 125 |
+
# Verify payment status
|
| 126 |
+
if payment['status'] != 'captured':
|
| 127 |
+
return False
|
| 128 |
+
|
| 129 |
+
# Verify amount (Razorpay stores in paise)
|
| 130 |
+
if payment['amount'] != int(amount * 100):
|
| 131 |
+
return False
|
| 132 |
+
|
| 133 |
+
return True
|
| 134 |
+
except Exception as e:
|
| 135 |
+
print(f"Payment verification failed: {e}")
|
| 136 |
+
return False
|
| 137 |
+
"""
|
frontend/index.html
ADDED
|
@@ -0,0 +1,414 @@
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
|
| 4 |
+
<head>
|
| 5 |
+
<meta charset="UTF-8" />
|
| 6 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 7 |
+
<title>StockSense AI — Live Trading Dashboard</title>
|
| 8 |
+
<link rel="stylesheet" href="style.css?v=6" />
|
| 9 |
+
<!-- Razorpay Checkout Script -->
|
| 10 |
+
<script src="https://checkout.razorpay.com/v1/checkout.js"></script>
|
| 11 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.0"></script>
|
| 12 |
+
</head>
|
| 13 |
+
|
| 14 |
+
<body>
|
| 15 |
+
|
| 16 |
+
<!-- Wallet Panel — Premium Slide-in -->
|
| 17 |
+
<div id="walletPanel" class="wallet-panel hidden">
|
| 18 |
+
<div class="wallet-panel-content">
|
| 19 |
+
<span class="wallet-close" onclick="closeWallet()">×</span>
|
| 20 |
+
|
| 21 |
+
<!-- Header -->
|
| 22 |
+
<div class="wallet-header">
|
| 23 |
+
<div class="wallet-header-icon">💰</div>
|
| 24 |
+
<h2>My Wallet</h2>
|
| 25 |
+
<p class="wallet-subtitle">Synced with AutoBot Balance</p>
|
| 26 |
+
</div>
|
| 27 |
+
|
| 28 |
+
<!-- Balance Card -->
|
| 29 |
+
<div class="wallet-balance-card">
|
| 30 |
+
<div class="wallet-balance-label">Available Balance</div>
|
| 31 |
+
<div class="wallet-balance-amount" id="walletBalance">₹10,00,000.00</div>
|
| 32 |
+
<div class="wallet-balance-bar"></div>
|
| 33 |
+
</div>
|
| 34 |
+
|
| 35 |
+
<!-- Quick Add Buttons -->
|
| 36 |
+
<div class="wallet-quick-add">
|
| 37 |
+
<span class="wallet-quick-label">Quick Add</span>
|
| 38 |
+
<div class="wallet-quick-btns">
|
| 39 |
+
<button onclick="quickAdd(500)">₹500</button>
|
| 40 |
+
<button onclick="quickAdd(1000)">₹1,000</button>
|
| 41 |
+
<button onclick="quickAdd(5000)">₹5,000</button>
|
| 42 |
+
<button onclick="quickAdd(10000)">₹10,000</button>
|
| 43 |
+
</div>
|
| 44 |
+
</div>
|
| 45 |
+
|
| 46 |
+
<!-- Action Buttons -->
|
| 47 |
+
<div class="wallet-actions">
|
| 48 |
+
<button class="wallet-action-btn add" onclick="showAddMoney()">
|
| 49 |
+
<span class="action-icon">+</span> Add Money
|
| 50 |
+
</button>
|
| 51 |
+
<button class="wallet-action-btn withdraw" onclick="showWithdrawMoney()">
|
| 52 |
+
<span class="action-icon">↗</span> Withdraw
|
| 53 |
+
</button>
|
| 54 |
+
</div>
|
| 55 |
+
|
| 56 |
+
<!-- Dynamic Form Area -->
|
| 57 |
+
<div id="walletActionArea"></div>
|
| 58 |
+
|
| 59 |
+
<!-- Status Message -->
|
| 60 |
+
<div id="walletMessage" class="wallet-message hidden"></div>
|
| 61 |
+
|
| 62 |
+
<!-- Transaction History -->
|
| 63 |
+
<div class="wallet-txn-section">
|
| 64 |
+
<h4>Recent Transactions</h4>
|
| 65 |
+
<div id="walletTxnList" class="wallet-txn-list">
|
| 66 |
+
<div class="wallet-txn-empty">No transactions yet</div>
|
| 67 |
+
</div>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
</div>
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
<nav class="topbar">
|
| 74 |
+
<div class="brand">📈 <span>StockSense AI</span></div>
|
| 75 |
+
<div class="search-area">
|
| 76 |
+
<div class="search-wrapper">
|
| 77 |
+
<input id="tickerInput" type="text" placeholder="Search stock… (e.g. Tata, Reliance, INFY)" spellcheck="false"
|
| 78 |
+
autocomplete="off" />
|
| 79 |
+
<div class="search-dropdown hidden" id="searchDropdown"></div>
|
| 80 |
+
</div>
|
| 81 |
+
<button id="analyzeBtn" onclick="loadTicker()">Analyze</button>
|
| 82 |
+
</div>
|
| 83 |
+
<div class="nav-tabs">
|
| 84 |
+
<button class="nav-tab active" onclick="switchTab('charts')">📊 Charts</button>
|
| 85 |
+
<button class="nav-tab" onclick="switchTab('trading')">🤖 Auto Trade</button>
|
| 86 |
+
<button class="btn-wallet nav-btn" onclick="showWallet()">💰 Wallet</button>
|
| 87 |
+
<button class="btn-trade nav-btn" onclick="executeManualTrade()">🛒 Trade</button>
|
| 88 |
+
</div>
|
| 89 |
+
<div class="live-badge" id="liveBadge">
|
| 90 |
+
<span class="dot"></span> LIVE
|
| 91 |
+
</div>
|
| 92 |
+
</nav>
|
| 93 |
+
|
| 94 |
+
<div class="market-bar" id="marketBar">
|
| 95 |
+
<div class="market-bar-inner">
|
| 96 |
+
<div class="market-item" id="mktStock">
|
| 97 |
+
<span class="mkt-label" id="mktStockLabel">STOCK</span>
|
| 98 |
+
<span class="mkt-price" id="mktStockPrice">—</span>
|
| 99 |
+
<span class="mkt-change" id="mktStockChange">—</span>
|
| 100 |
+
</div>
|
| 101 |
+
<div class="market-sep">│</div>
|
| 102 |
+
<div class="market-item">
|
| 103 |
+
<span class="mkt-label">NIFTY 50</span>
|
| 104 |
+
<span class="mkt-price" id="mktNiftyPrice">—</span>
|
| 105 |
+
<span class="mkt-change" id="mktNiftyChange">—</span>
|
| 106 |
+
</div>
|
| 107 |
+
<div class="market-sep">│</div>
|
| 108 |
+
<div class="market-item">
|
| 109 |
+
<span class="mkt-label">SENSEX</span>
|
| 110 |
+
<span class="mkt-price" id="mktSensexPrice">—</span>
|
| 111 |
+
<span class="mkt-change" id="mktSensexChange">—</span>
|
| 112 |
+
</div>
|
| 113 |
+
</div>
|
| 114 |
+
</div>
|
| 115 |
+
|
| 116 |
+
|
| 117 |
+
<section class="price-banner hidden" id="priceBanner">
|
| 118 |
+
<div class="price-main">
|
| 119 |
+
<h1 id="bannerName">—</h1>
|
| 120 |
+
<span class="price-value" id="bannerPrice">0.00</span>
|
| 121 |
+
<span class="price-change" id="bannerChange">0.00 (0.00%)</span>
|
| 122 |
+
</div>
|
| 123 |
+
<div class="price-stats">
|
| 124 |
+
<div><label>Open</label><span id="statOpen">—</span></div>
|
| 125 |
+
<div><label>High</label><span id="statHigh">—</span></div>
|
| 126 |
+
<div><label>Low</label><span id="statLow">—</span></div>
|
| 127 |
+
<div><label>Vol</label><span id="statVol">—</span></div>
|
| 128 |
+
<div><label>52W H</label><span id="stat52H">—</span></div>
|
| 129 |
+
<div><label>52W L</label><span id="stat52L">—</span></div>
|
| 130 |
+
</div>
|
| 131 |
+
</section>
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
<div id="chartsTab" class="tab-content">
|
| 135 |
+
<div class="dashboard">
|
| 136 |
+
<div class="chart-area">
|
| 137 |
+
<div class="timeframe-bar">
|
| 138 |
+
<button class="tf-btn active" data-tf="1d">1D</button>
|
| 139 |
+
<button class="tf-btn" data-tf="5d">5D</button>
|
| 140 |
+
<button class="tf-btn" data-tf="1mo">1M</button>
|
| 141 |
+
<button class="tf-btn" data-tf="3mo">3M</button>
|
| 142 |
+
<button class="tf-btn" data-tf="1y">1Y</button>
|
| 143 |
+
<button class="tf-btn" data-tf="2y">2Y</button>
|
| 144 |
+
</div>
|
| 145 |
+
<div class="chart-container" id="mainChartWrap">
|
| 146 |
+
<canvas id="mainChart"></canvas>
|
| 147 |
+
<div class="chart-empty-state" id="chartEmptyState">
|
| 148 |
+
<div class="empty-icon">📈</div>
|
| 149 |
+
<h3>Explore Any Stock</h3>
|
| 150 |
+
<p>Search for a stock above or pick one from <strong>High Potential Stocks</strong> to view charts, analysis
|
| 151 |
+
& AI insights.</p>
|
| 152 |
+
<div class="empty-hint">Try: <span
|
| 153 |
+
onclick="document.getElementById('tickerInput').focus()">RELIANCE.NS</span> · <span
|
| 154 |
+
onclick="document.getElementById('tickerInput').focus()">TCS.NS</span> · <span
|
| 155 |
+
onclick="document.getElementById('tickerInput').focus()">TATAMOTORS.NS</span></div>
|
| 156 |
+
</div>
|
| 157 |
+
</div>
|
| 158 |
+
<div class="chart-container volume-chart"><canvas id="volumeChart"></canvas></div>
|
| 159 |
+
|
| 160 |
+
<div class="prediction-section hidden" id="predSection">
|
| 161 |
+
<h3>🤖 Next 5-Day Price Forecast</h3>
|
| 162 |
+
|
| 163 |
+
<div class="pred-loader" id="predLoader">
|
| 164 |
+
<div class="pred-loader-inner">
|
| 165 |
+
<div class="neural-dots">
|
| 166 |
+
<span></span><span></span><span></span><span></span><span></span>
|
| 167 |
+
</div>
|
| 168 |
+
<div class="loader-brain">🧠</div>
|
| 169 |
+
<p class="loader-title">AI Model Training</p>
|
| 170 |
+
<p class="loader-sub" id="predLoaderMsg">Analyzing patterns with 10-feature LSTM...</p>
|
| 171 |
+
<div class="loader-bar">
|
| 172 |
+
<div class="loader-bar-fill"></div>
|
| 173 |
+
</div>
|
| 174 |
+
</div>
|
| 175 |
+
</div>
|
| 176 |
+
<div class="chart-container" id="predChartWrap"><canvas id="predChart"></canvas></div>
|
| 177 |
+
<div class="pred-metrics">
|
| 178 |
+
<div class="metric-card">
|
| 179 |
+
<span class="m-label">Confidence</span>
|
| 180 |
+
<span class="m-value" id="predConf">—</span>
|
| 181 |
+
</div>
|
| 182 |
+
<div class="metric-card">
|
| 183 |
+
<span class="m-label">Risk Level</span>
|
| 184 |
+
<span class="m-value" id="predRisk">—</span>
|
| 185 |
+
</div>
|
| 186 |
+
<div class="metric-card">
|
| 187 |
+
<span class="m-label">Day 1 Forecast</span>
|
| 188 |
+
<span class="m-value" id="predDay1">—</span>
|
| 189 |
+
</div>
|
| 190 |
+
<div class="metric-card">
|
| 191 |
+
<span class="m-label">Day 5 Forecast</span>
|
| 192 |
+
<span class="m-value" id="predDay5">—</span>
|
| 193 |
+
</div>
|
| 194 |
+
</div>
|
| 195 |
+
</div>
|
| 196 |
+
</div>
|
| 197 |
+
|
| 198 |
+
<aside class="sidebar">
|
| 199 |
+
<div class="panel">
|
| 200 |
+
<h3>🔥 High Potential Stocks</h3>
|
| 201 |
+
<p class="panel-sub">Ranked by momentum + indicators</p>
|
| 202 |
+
<div id="hpLoader" class="mini-loader">Loading scanner...</div>
|
| 203 |
+
<div id="hpList" class="hp-list"></div>
|
| 204 |
+
</div>
|
| 205 |
+
<div class="panel hidden" id="sentPanel">
|
| 206 |
+
<h3>📰 News Sentiment</h3>
|
| 207 |
+
<div class="sent-gauge">
|
| 208 |
+
<div class="gauge-circle" id="gaugeCircle"><span id="gaugeText">—</span></div>
|
| 209 |
+
<span class="gauge-label" id="gaugeLabel">Neutral</span>
|
| 210 |
+
</div>
|
| 211 |
+
<ul id="sentList" class="sent-list"></ul>
|
| 212 |
+
</div>
|
| 213 |
+
<div class="panel hidden" id="indPanel">
|
| 214 |
+
<h3>📊 Technical Indicators</h3>
|
| 215 |
+
<table class="ind-table">
|
| 216 |
+
<tbody id="indBody"></tbody>
|
| 217 |
+
</table>
|
| 218 |
+
</div>
|
| 219 |
+
</aside>
|
| 220 |
+
</div>
|
| 221 |
+
</div>
|
| 222 |
+
|
| 223 |
+
|
| 224 |
+
<div id="tradingTab" class="tab-content hidden">
|
| 225 |
+
<div class="trading-dashboard">
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
<div class="trade-grid">
|
| 229 |
+
<div class="portfolio-header">
|
| 230 |
+
<div class="port-card balance">
|
| 231 |
+
<span class="pc-label">Portfolio Value</span>
|
| 232 |
+
<span class="pc-value" id="portValue">₹10,00,000.00</span>
|
| 233 |
+
</div>
|
| 234 |
+
<div class="port-card">
|
| 235 |
+
<span class="pc-label">Cash Balance</span>
|
| 236 |
+
<span class="pc-value" id="portBalance">₹10,00,000.00</span>
|
| 237 |
+
</div>
|
| 238 |
+
<div class="port-card">
|
| 239 |
+
<span class="pc-label">Unrealized P&L</span>
|
| 240 |
+
<span class="pc-value" id="portUnrealized">₹0.00</span>
|
| 241 |
+
</div>
|
| 242 |
+
<div class="port-card">
|
| 243 |
+
<span class="pc-label">Realized P&L</span>
|
| 244 |
+
<span class="pc-value" id="portRealized">₹0.00</span>
|
| 245 |
+
</div>
|
| 246 |
+
<div class="port-card">
|
| 247 |
+
<span class="pc-label">Win Rate</span>
|
| 248 |
+
<span class="pc-value" id="portWinRate">0%</span>
|
| 249 |
+
</div>
|
| 250 |
+
<div class="port-card">
|
| 251 |
+
<span class="pc-label">Total Trades</span>
|
| 252 |
+
<span class="pc-value" id="portTrades">0</span>
|
| 253 |
+
</div>
|
| 254 |
+
</div>
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
<div class="bot-controls">
|
| 258 |
+
<div class="bot-status">
|
| 259 |
+
<span class="bot-dot" id="botDot"></span>
|
| 260 |
+
<span id="botStatus">Bot: OFF</span>
|
| 261 |
+
</div>
|
| 262 |
+
<div class="bot-buttons">
|
| 263 |
+
<button class="btn-bot" id="toggleBotBtn" onclick="toggleBot()">⚡ Auto Bot</button>
|
| 264 |
+
<button class="btn-scan" onclick="runAutoScan()">🔍 Auto Scan</button>
|
| 265 |
+
<button class="btn-reset" onclick="resetPortfolio()">🔄 Reset</button>
|
| 266 |
+
</div>
|
| 267 |
+
</div>
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
<div class="trade-panel">
|
| 271 |
+
<h3>📂 Open Positions</h3>
|
| 272 |
+
<div class="positions-table-wrap">
|
| 273 |
+
<table class="positions-table">
|
| 274 |
+
<thead>
|
| 275 |
+
<tr>
|
| 276 |
+
<th>Ticker</th>
|
| 277 |
+
<th>Shares</th>
|
| 278 |
+
<th>Buy Price</th>
|
| 279 |
+
<th>Current</th>
|
| 280 |
+
<th>P&L</th>
|
| 281 |
+
<th>P&L %</th>
|
| 282 |
+
<th>Stop Loss</th>
|
| 283 |
+
<th>Take Profit</th>
|
| 284 |
+
<th>Action</th>
|
| 285 |
+
</tr>
|
| 286 |
+
</thead>
|
| 287 |
+
<tbody id="positionsBody">
|
| 288 |
+
<tr>
|
| 289 |
+
<td colspan="9" class="empty-msg">No open positions</td>
|
| 290 |
+
</tr>
|
| 291 |
+
</tbody>
|
| 292 |
+
</table>
|
| 293 |
+
</div>
|
| 294 |
+
</div>
|
| 295 |
+
|
| 296 |
+
|
| 297 |
+
<div class="trade-panel">
|
| 298 |
+
<h3>📋 Trade History</h3>
|
| 299 |
+
<div class="trade-log" id="tradeLog">
|
| 300 |
+
<div class="empty-msg">No trades yet. Activate the bot or execute a trade.</div>
|
| 301 |
+
</div>
|
| 302 |
+
</div>
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
<div class="trade-panel">
|
| 306 |
+
<h3>⚡ Live Trade Feed</h3>
|
| 307 |
+
<div class="trade-feed" id="tradeFeed"></div>
|
| 308 |
+
</div>
|
| 309 |
+
|
| 310 |
+
</div>
|
| 311 |
+
</div>
|
| 312 |
+
</div>
|
| 313 |
+
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
<section class="insights-section">
|
| 319 |
+
<h2 class="section-title">🌐 AI × Finance — Did You Know?</h2>
|
| 320 |
+
<div class="insights-grid">
|
| 321 |
+
<div class="insight-card">
|
| 322 |
+
<div class="insight-icon">🤖</div>
|
| 323 |
+
<h4>AI Handles 60-70% of Trades</h4>
|
| 324 |
+
<p>Algorithmic and AI-driven systems now execute the majority of trades on major stock exchanges worldwide.</p>
|
| 325 |
+
</div>
|
| 326 |
+
<div class="insight-card">
|
| 327 |
+
<div class="insight-icon">🧠</div>
|
| 328 |
+
<h4>LSTM Remembers Patterns</h4>
|
| 329 |
+
<p>Long Short-Term Memory networks can learn patterns across 60+ trading days, capturing trends that humans
|
| 330 |
+
easily miss.</p>
|
| 331 |
+
</div>
|
| 332 |
+
<div class="insight-card">
|
| 333 |
+
<div class="insight-icon">📰</div>
|
| 334 |
+
<h4>News Moves Markets</h4>
|
| 335 |
+
<p>Studies show that news sentiment can predict short-term stock movements with up to 70% accuracy when combined
|
| 336 |
+
with technical analysis.</p>
|
| 337 |
+
</div>
|
| 338 |
+
<div class="insight-card">
|
| 339 |
+
<div class="insight-icon">📊</div>
|
| 340 |
+
<h4>Bollinger Bands</h4>
|
| 341 |
+
<p>When Bollinger Band width contracts, a big price move is coming. Our model uses this "squeeze" signal in its
|
| 342 |
+
10-feature pipeline.</p>
|
| 343 |
+
</div>
|
| 344 |
+
<div class="insight-card">
|
| 345 |
+
<div class="insight-icon">⚡</div>
|
| 346 |
+
<h4>Sub-Second Decisions</h4>
|
| 347 |
+
<p>Once trained, our LSTM model generates 5-day forecasts in under 50ms — faster than any human analyst could
|
| 348 |
+
process a single chart.</p>
|
| 349 |
+
</div>
|
| 350 |
+
<div class="insight-card">
|
| 351 |
+
<div class="insight-icon">🛡️</div>
|
| 352 |
+
<h4>Risk Management is Key</h4>
|
| 353 |
+
<p>Professional trading firms never risk more than 2% per trade. Our bot uses stop-loss, take-profit, and
|
| 354 |
+
trailing stops for protection.</p>
|
| 355 |
+
</div>
|
| 356 |
+
</div>
|
| 357 |
+
</section>
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
<section class="pipeline-section">
|
| 361 |
+
<h2 class="section-title">⚙️ How StockSense AI Works</h2>
|
| 362 |
+
<div class="pipeline">
|
| 363 |
+
<div class="pipe-step">
|
| 364 |
+
<div class="pipe-num">01</div>
|
| 365 |
+
<div class="pipe-icon">📥</div>
|
| 366 |
+
<h4>Data Ingestion</h4>
|
| 367 |
+
<p>2 years of OHLCV data fetched from Yahoo Finance in real-time for any stock ticker.</p>
|
| 368 |
+
</div>
|
| 369 |
+
<div class="pipe-arrow">→</div>
|
| 370 |
+
<div class="pipe-step">
|
| 371 |
+
<div class="pipe-num">02</div>
|
| 372 |
+
<div class="pipe-icon">📊</div>
|
| 373 |
+
<h4>Feature Engineering</h4>
|
| 374 |
+
<p>10 technical indicators computed: SMA, EMA, RSI, MACD, Bollinger Bands, ATR, and Volume.</p>
|
| 375 |
+
</div>
|
| 376 |
+
<div class="pipe-arrow">→</div>
|
| 377 |
+
<div class="pipe-step">
|
| 378 |
+
<div class="pipe-num">03</div>
|
| 379 |
+
<div class="pipe-icon">🧠</div>
|
| 380 |
+
<h4>AI Prediction</h4>
|
| 381 |
+
<p>3-layer LSTM neural network trained on 60-day windows predicts next 5 business days' prices.</p>
|
| 382 |
+
</div>
|
| 383 |
+
<div class="pipe-arrow">→</div>
|
| 384 |
+
<div class="pipe-step">
|
| 385 |
+
<div class="pipe-num">04</div>
|
| 386 |
+
<div class="pipe-icon">💹</div>
|
| 387 |
+
<h4>Smart Trading</h4>
|
| 388 |
+
<p>Composite score (LSTM + Technical + Sentiment) adapts to market regime for auto BUY/SELL.</p>
|
| 389 |
+
</div>
|
| 390 |
+
</div>
|
| 391 |
+
</section>
|
| 392 |
+
|
| 393 |
+
|
| 394 |
+
<footer class="app-footer">
|
| 395 |
+
<div class="footer-content">
|
| 396 |
+
<div class="footer-brand">
|
| 397 |
+
<span class="footer-logo">📈 StockSense AI</span>
|
| 398 |
+
<span class="footer-tagline">Where Machine Learning Meets Market Intelligence</span>
|
| 399 |
+
</div>
|
| 400 |
+
<div class="footer-tech">
|
| 401 |
+
<span>Built with</span>
|
| 402 |
+
<span class="tech-badge">Python</span>
|
| 403 |
+
<span class="tech-badge">PyTorch</span>
|
| 404 |
+
<span class="tech-badge">FastAPI</span>
|
| 405 |
+
<span class="tech-badge">FinBERT</span>
|
| 406 |
+
<span class="tech-badge">Chart.js</span>
|
| 407 |
+
</div>
|
| 408 |
+
</div>
|
| 409 |
+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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ════════════════════════════════════════════════════════════════════════════
|
| 2 |
+
WALLET PANEL — PREMIUM SLIDE-IN
|
| 3 |
+
════════════════════════════════════════════════════════════════════════════ */
|
| 4 |
+
|
| 5 |
+
.wallet-panel {
|
| 6 |
+
position: fixed;
|
| 7 |
+
top: 0;
|
| 8 |
+
right: 0;
|
| 9 |
+
height: 100vh;
|
| 10 |
+
width: 440px;
|
| 11 |
+
background: linear-gradient(165deg, #0f1219 0%, #161b28 40%, #1a1f2e 100%);
|
| 12 |
+
box-shadow: -12px 0 60px rgba(0, 0, 0, 0.45), -2px 0 20px rgba(59, 130, 246, 0.06);
|
| 13 |
+
z-index: 9999;
|
| 14 |
+
transform: translateX(100%);
|
| 15 |
+
transition: transform 0.38s cubic-bezier(.25, 1, .3, 1);
|
| 16 |
+
border-left: 1px solid rgba(59, 130, 246, 0.12);
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.wallet-panel:not(.hidden) {
|
| 20 |
+
transform: translateX(0);
|
| 21 |
+
}
|
| 22 |
+
|
| 23 |
+
.wallet-panel-content {
|
| 24 |
+
padding: 2rem 2rem 2rem 2rem;
|
| 25 |
+
height: 100vh;
|
| 26 |
+
overflow-y: auto;
|
| 27 |
+
position: relative;
|
| 28 |
+
display: flex;
|
| 29 |
+
flex-direction: column;
|
| 30 |
+
gap: 1.4rem;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
.wallet-close {
|
| 34 |
+
position: absolute;
|
| 35 |
+
right: 1.2rem;
|
| 36 |
+
top: 1.2rem;
|
| 37 |
+
font-size: 1.8rem;
|
| 38 |
+
color: #6b7280;
|
| 39 |
+
cursor: pointer;
|
| 40 |
+
transition: color 0.2s, transform 0.2s;
|
| 41 |
+
z-index: 2;
|
| 42 |
+
line-height: 1;
|
| 43 |
+
width: 36px;
|
| 44 |
+
height: 36px;
|
| 45 |
+
display: flex;
|
| 46 |
+
align-items: center;
|
| 47 |
+
justify-content: center;
|
| 48 |
+
border-radius: 50%;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.wallet-close:hover {
|
| 52 |
+
color: #fff;
|
| 53 |
+
background: rgba(255, 255, 255, 0.06);
|
| 54 |
+
transform: rotate(90deg);
|
| 55 |
+
}
|
| 56 |
+
|
| 57 |
+
/* ── Header ────────────────────────────── */
|
| 58 |
+
.wallet-header {
|
| 59 |
+
text-align: center;
|
| 60 |
+
padding-top: 0.5rem;
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
.wallet-header-icon {
|
| 64 |
+
font-size: 2.5rem;
|
| 65 |
+
margin-bottom: 0.4rem;
|
| 66 |
+
filter: drop-shadow(0 4px 12px rgba(234, 179, 8, 0.3));
|
| 67 |
+
}
|
| 68 |
+
|
| 69 |
+
.wallet-header h2 {
|
| 70 |
+
font-size: 1.5rem;
|
| 71 |
+
font-weight: 800;
|
| 72 |
+
letter-spacing: -0.02em;
|
| 73 |
+
background: linear-gradient(135deg, #fff 0%, #94a3b8 100%);
|
| 74 |
+
-webkit-background-clip: text;
|
| 75 |
+
-webkit-text-fill-color: transparent;
|
| 76 |
+
background-clip: text;
|
| 77 |
+
margin-bottom: 0.2rem;
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
.wallet-subtitle {
|
| 81 |
+
font-size: 0.72rem;
|
| 82 |
+
color: #6b7280;
|
| 83 |
+
text-transform: uppercase;
|
| 84 |
+
letter-spacing: 0.1em;
|
| 85 |
+
font-weight: 600;
|
| 86 |
+
}
|
| 87 |
+
|
| 88 |
+
/* ── Balance Card ──────────────────────── */
|
| 89 |
+
.wallet-balance-card {
|
| 90 |
+
background: linear-gradient(135deg, rgba(34, 197, 94, 0.08) 0%, rgba(59, 130, 246, 0.06) 100%);
|
| 91 |
+
border: 1px solid rgba(34, 197, 94, 0.15);
|
| 92 |
+
border-radius: 14px;
|
| 93 |
+
padding: 1.3rem 1.4rem;
|
| 94 |
+
position: relative;
|
| 95 |
+
overflow: hidden;
|
| 96 |
+
}
|
| 97 |
+
|
| 98 |
+
.wallet-balance-card::before {
|
| 99 |
+
content: '';
|
| 100 |
+
position: absolute;
|
| 101 |
+
top: -50%;
|
| 102 |
+
left: -50%;
|
| 103 |
+
width: 200%;
|
| 104 |
+
height: 200%;
|
| 105 |
+
background: linear-gradient(45deg, transparent 40%, rgba(255, 255, 255, 0.03) 50%, transparent 60%);
|
| 106 |
+
animation: walletShimmer 4s ease-in-out infinite;
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
@keyframes walletShimmer {
|
| 110 |
+
0% {
|
| 111 |
+
transform: translateX(-100%) rotate(45deg);
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
100% {
|
| 115 |
+
transform: translateX(100%) rotate(45deg);
|
| 116 |
+
}
|
| 117 |
+
}
|
| 118 |
+
|
| 119 |
+
.wallet-balance-label {
|
| 120 |
+
font-size: 0.72rem;
|
| 121 |
+
color: #6b7280;
|
| 122 |
+
text-transform: uppercase;
|
| 123 |
+
letter-spacing: 0.08em;
|
| 124 |
+
font-weight: 600;
|
| 125 |
+
margin-bottom: 0.5rem;
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.wallet-balance-amount {
|
| 129 |
+
font-size: 2rem;
|
| 130 |
+
font-weight: 800;
|
| 131 |
+
background: linear-gradient(135deg, #22c55e 0%, #4ade80 40%, #86efac 100%);
|
| 132 |
+
-webkit-background-clip: text;
|
| 133 |
+
-webkit-text-fill-color: transparent;
|
| 134 |
+
background-clip: text;
|
| 135 |
+
letter-spacing: -0.02em;
|
| 136 |
+
line-height: 1.2;
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
.wallet-balance-bar {
|
| 140 |
+
height: 3px;
|
| 141 |
+
margin-top: 0.8rem;
|
| 142 |
+
background: linear-gradient(90deg, #22c55e 0%, #3b82f6 50%, #a855f7 100%);
|
| 143 |
+
border-radius: 4px;
|
| 144 |
+
opacity: 0.5;
|
| 145 |
+
}
|
| 146 |
+
|
| 147 |
+
/* ── Quick Add ─────────────────────────── */
|
| 148 |
+
.wallet-quick-add {
|
| 149 |
+
display: flex;
|
| 150 |
+
flex-direction: column;
|
| 151 |
+
gap: 0.5rem;
|
| 152 |
+
}
|
| 153 |
+
|
| 154 |
+
.wallet-quick-label {
|
| 155 |
+
font-size: 0.7rem;
|
| 156 |
+
color: #6b7280;
|
| 157 |
+
text-transform: uppercase;
|
| 158 |
+
letter-spacing: 0.08em;
|
| 159 |
+
font-weight: 600;
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
.wallet-quick-btns {
|
| 163 |
+
display: grid;
|
| 164 |
+
grid-template-columns: repeat(4, 1fr);
|
| 165 |
+
gap: 0.5rem;
|
| 166 |
+
}
|
| 167 |
+
|
| 168 |
+
.wallet-quick-btns button {
|
| 169 |
+
padding: 0.55rem 0;
|
| 170 |
+
border-radius: 8px;
|
| 171 |
+
border: 1px solid #2a3040;
|
| 172 |
+
background: rgba(255, 255, 255, 0.03);
|
| 173 |
+
color: #d1d5db;
|
| 174 |
+
font-family: inherit;
|
| 175 |
+
font-size: 0.78rem;
|
| 176 |
+
font-weight: 700;
|
| 177 |
+
cursor: pointer;
|
| 178 |
+
transition: all 0.2s ease;
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
.wallet-quick-btns button:hover {
|
| 182 |
+
border-color: #22c55e;
|
| 183 |
+
color: #22c55e;
|
| 184 |
+
background: rgba(34, 197, 94, 0.06);
|
| 185 |
+
transform: translateY(-1px);
|
| 186 |
+
box-shadow: 0 4px 12px rgba(34, 197, 94, 0.1);
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
/* ── Action Buttons ────────────────────── */
|
| 190 |
+
.wallet-actions {
|
| 191 |
+
display: grid;
|
| 192 |
+
grid-template-columns: 1fr 1fr;
|
| 193 |
+
gap: 0.8rem;
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
.wallet-action-btn {
|
| 197 |
+
display: flex;
|
| 198 |
+
align-items: center;
|
| 199 |
+
justify-content: center;
|
| 200 |
+
gap: 0.4rem;
|
| 201 |
+
padding: 0.85rem 0;
|
| 202 |
+
border-radius: 10px;
|
| 203 |
+
border: none;
|
| 204 |
+
font-family: inherit;
|
| 205 |
+
font-size: 0.9rem;
|
| 206 |
+
font-weight: 700;
|
| 207 |
+
cursor: pointer;
|
| 208 |
+
transition: all 0.22s ease;
|
| 209 |
+
position: relative;
|
| 210 |
+
overflow: hidden;
|
| 211 |
+
}
|
| 212 |
+
|
| 213 |
+
.wallet-action-btn .action-icon {
|
| 214 |
+
font-size: 1.1rem;
|
| 215 |
+
font-weight: 800;
|
| 216 |
+
}
|
| 217 |
+
|
| 218 |
+
.wallet-action-btn.add {
|
| 219 |
+
background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
|
| 220 |
+
color: #fff;
|
| 221 |
+
box-shadow: 0 4px 16px rgba(34, 197, 94, 0.2);
|
| 222 |
+
}
|
| 223 |
+
|
| 224 |
+
.wallet-action-btn.add:hover {
|
| 225 |
+
box-shadow: 0 6px 24px rgba(34, 197, 94, 0.35);
|
| 226 |
+
transform: translateY(-1px);
|
| 227 |
+
}
|
| 228 |
+
|
| 229 |
+
.wallet-action-btn.withdraw {
|
| 230 |
+
background: linear-gradient(135deg, #3b82f6 0%, #2563eb 100%);
|
| 231 |
+
color: #fff;
|
| 232 |
+
box-shadow: 0 4px 16px rgba(59, 130, 246, 0.2);
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.wallet-action-btn.withdraw:hover {
|
| 236 |
+
box-shadow: 0 6px 24px rgba(59, 130, 246, 0.35);
|
| 237 |
+
transform: translateY(-1px);
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
/* ── Wallet Form ───────────────────────── */
|
| 241 |
+
.wallet-form {
|
| 242 |
+
display: flex;
|
| 243 |
+
flex-direction: column;
|
| 244 |
+
gap: 0.8rem;
|
| 245 |
+
background: rgba(255, 255, 255, 0.02);
|
| 246 |
+
border: 1px solid #242a38;
|
| 247 |
+
border-radius: 12px;
|
| 248 |
+
padding: 1.2rem;
|
| 249 |
+
animation: walletFormIn 0.25s ease-out;
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
+
@keyframes walletFormIn {
|
| 253 |
+
from {
|
| 254 |
+
opacity: 0;
|
| 255 |
+
transform: translateY(-6px);
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
to {
|
| 259 |
+
opacity: 1;
|
| 260 |
+
transform: translateY(0);
|
| 261 |
+
}
|
| 262 |
+
}
|
| 263 |
+
|
| 264 |
+
.wallet-form h3 {
|
| 265 |
+
color: #06b6d4;
|
| 266 |
+
font-size: 0.95rem;
|
| 267 |
+
font-weight: 700;
|
| 268 |
+
margin-bottom: 0.2rem;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
.wallet-form input {
|
| 272 |
+
padding: 0.85rem 1rem;
|
| 273 |
+
border-radius: 8px;
|
| 274 |
+
border: 1.5px solid #2a3040;
|
| 275 |
+
background: #171c28;
|
| 276 |
+
/* This is the background color */
|
| 277 |
+
color: #fff;
|
| 278 |
+
width: 100%;
|
| 279 |
+
font-size: 1.05rem;
|
| 280 |
+
font-family: inherit;
|
| 281 |
+
font-weight: 600;
|
| 282 |
+
transition: all 0.2s ease;
|
| 283 |
+
appearance: none;
|
| 284 |
+
/* Helps with some browser defaults */
|
| 285 |
+
}
|
| 286 |
+
|
| 287 |
+
/* Fix white background on number spin buttons */
|
| 288 |
+
.wallet-form input::-webkit-outer-spin-button,
|
| 289 |
+
.wallet-form input::-webkit-inner-spin-button {
|
| 290 |
+
-webkit-appearance: none;
|
| 291 |
+
margin: 0;
|
| 292 |
+
background: transparent;
|
| 293 |
+
}
|
| 294 |
+
|
| 295 |
+
.wallet-form input {
|
| 296 |
+
-moz-appearance: textfield;
|
| 297 |
+
/* Firefox */
|
| 298 |
+
}
|
| 299 |
+
|
| 300 |
+
|
| 301 |
+
.wallet-form input:focus {
|
| 302 |
+
outline: none;
|
| 303 |
+
border-color: #3b82f6;
|
| 304 |
+
background: #131720;
|
| 305 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.08);
|
| 306 |
+
}
|
| 307 |
+
|
| 308 |
+
.wallet-form input::placeholder {
|
| 309 |
+
color: #4b5563;
|
| 310 |
+
font-weight: 500;
|
| 311 |
+
}
|
| 312 |
+
|
| 313 |
+
.wallet-form button {
|
| 314 |
+
background: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
|
| 315 |
+
color: #fff;
|
| 316 |
+
border: none;
|
| 317 |
+
border-radius: 8px;
|
| 318 |
+
padding: 0.85rem 0;
|
| 319 |
+
font-size: 0.95rem;
|
| 320 |
+
font-weight: 700;
|
| 321 |
+
cursor: pointer;
|
| 322 |
+
font-family: inherit;
|
| 323 |
+
transition: all 0.2s ease;
|
| 324 |
+
box-shadow: 0 2px 12px rgba(59, 130, 246, 0.15);
|
| 325 |
+
}
|
| 326 |
+
|
| 327 |
+
.wallet-form button:hover {
|
| 328 |
+
transform: translateY(-1px);
|
| 329 |
+
box-shadow: 0 4px 20px rgba(59, 130, 246, 0.3);
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
/* ── Message ───────────────────────────── */
|
| 333 |
+
.wallet-message {
|
| 334 |
+
padding: 0.9rem 1rem;
|
| 335 |
+
border-radius: 10px;
|
| 336 |
+
font-size: 0.85rem;
|
| 337 |
+
font-weight: 600;
|
| 338 |
+
text-align: center;
|
| 339 |
+
animation: walletFormIn 0.3s ease-out;
|
| 340 |
+
position: relative;
|
| 341 |
+
overflow: hidden;
|
| 342 |
+
}
|
| 343 |
+
|
| 344 |
+
.wallet-message::before {
|
| 345 |
+
content: '';
|
| 346 |
+
position: absolute;
|
| 347 |
+
left: 0;
|
| 348 |
+
top: 0;
|
| 349 |
+
bottom: 0;
|
| 350 |
+
width: 3px;
|
| 351 |
+
animation: msgProgress 5s linear forwards;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
@keyframes msgProgress {
|
| 355 |
+
from {
|
| 356 |
+
height: 100%;
|
| 357 |
+
}
|
| 358 |
+
|
| 359 |
+
to {
|
| 360 |
+
height: 0%;
|
| 361 |
+
}
|
| 362 |
+
}
|
| 363 |
+
|
| 364 |
+
.wallet-message.success {
|
| 365 |
+
background: rgba(34, 197, 94, 0.1);
|
| 366 |
+
color: #22c55e;
|
| 367 |
+
border: 1px solid rgba(34, 197, 94, 0.25);
|
| 368 |
+
}
|
| 369 |
+
|
| 370 |
+
.wallet-message.success::before {
|
| 371 |
+
background: #22c55e;
|
| 372 |
+
}
|
| 373 |
+
|
| 374 |
+
.wallet-message.error {
|
| 375 |
+
background: rgba(239, 68, 68, 0.1);
|
| 376 |
+
color: #ef4444;
|
| 377 |
+
border: 1px solid rgba(239, 68, 68, 0.25);
|
| 378 |
+
}
|
| 379 |
+
|
| 380 |
+
.wallet-message.error::before {
|
| 381 |
+
background: #ef4444;
|
| 382 |
+
}
|
| 383 |
+
|
| 384 |
+
.wallet-message.hidden {
|
| 385 |
+
display: none;
|
| 386 |
+
}
|
| 387 |
+
|
| 388 |
+
/* ── Transaction History ───────────────── */
|
| 389 |
+
.wallet-txn-section {
|
| 390 |
+
border-top: 1px solid #1e2433;
|
| 391 |
+
padding-top: 1rem;
|
| 392 |
+
}
|
| 393 |
+
|
| 394 |
+
.wallet-txn-section h4 {
|
| 395 |
+
font-size: 0.72rem;
|
| 396 |
+
color: #6b7280;
|
| 397 |
+
text-transform: uppercase;
|
| 398 |
+
letter-spacing: 0.08em;
|
| 399 |
+
font-weight: 700;
|
| 400 |
+
margin-bottom: 0.7rem;
|
| 401 |
+
}
|
| 402 |
+
|
| 403 |
+
.wallet-txn-list {
|
| 404 |
+
display: flex;
|
| 405 |
+
flex-direction: column;
|
| 406 |
+
gap: 0.4rem;
|
| 407 |
+
max-height: 200px;
|
| 408 |
+
overflow-y: auto;
|
| 409 |
+
}
|
| 410 |
+
|
| 411 |
+
.wallet-txn-item {
|
| 412 |
+
display: flex;
|
| 413 |
+
justify-content: space-between;
|
| 414 |
+
align-items: center;
|
| 415 |
+
padding: 0.6rem 0.8rem;
|
| 416 |
+
background: rgba(255, 255, 255, 0.02);
|
| 417 |
+
border: 1px solid #1e2433;
|
| 418 |
+
border-radius: 8px;
|
| 419 |
+
transition: background 0.15s;
|
| 420 |
+
}
|
| 421 |
+
|
| 422 |
+
.wallet-txn-item:hover {
|
| 423 |
+
background: rgba(255, 255, 255, 0.04);
|
| 424 |
+
}
|
| 425 |
+
|
| 426 |
+
.wallet-txn-left {
|
| 427 |
+
display: flex;
|
| 428 |
+
flex-direction: column;
|
| 429 |
+
gap: 0.15rem;
|
| 430 |
+
}
|
| 431 |
+
|
| 432 |
+
.wallet-txn-type {
|
| 433 |
+
font-size: 0.7rem;
|
| 434 |
+
font-weight: 700;
|
| 435 |
+
text-transform: uppercase;
|
| 436 |
+
letter-spacing: 0.04em;
|
| 437 |
+
}
|
| 438 |
+
|
| 439 |
+
.wallet-txn-type.credit {
|
| 440 |
+
color: #22c55e;
|
| 441 |
+
}
|
| 442 |
+
|
| 443 |
+
.wallet-txn-type.debit {
|
| 444 |
+
color: #ef4444;
|
| 445 |
+
}
|
| 446 |
+
|
| 447 |
+
.wallet-txn-date {
|
| 448 |
+
font-size: 0.65rem;
|
| 449 |
+
color: #4b5563;
|
| 450 |
+
}
|
| 451 |
+
|
| 452 |
+
.wallet-txn-amount {
|
| 453 |
+
font-weight: 700;
|
| 454 |
+
font-size: 0.9rem;
|
| 455 |
+
color: #d1d5db;
|
| 456 |
+
}
|
| 457 |
+
|
| 458 |
+
.wallet-txn-empty {
|
| 459 |
+
text-align: center;
|
| 460 |
+
padding: 1rem;
|
| 461 |
+
color: #4b5563;
|
| 462 |
+
font-size: 0.8rem;
|
| 463 |
+
}
|
| 464 |
+
|
| 465 |
+
/* ── Nav Button ────────────────────────── */
|
| 466 |
+
.nav-btn {
|
| 467 |
+
margin-left: 0.5rem;
|
| 468 |
+
padding: 0.5rem 1.1rem;
|
| 469 |
+
font-size: 0.95rem;
|
| 470 |
+
vertical-align: middle;
|
| 471 |
+
}
|
| 472 |
+
|
| 473 |
+
.btn-wallet {
|
| 474 |
+
background: linear-gradient(135deg, #eab308 0%, #f59e0b 100%);
|
| 475 |
+
color: #000;
|
| 476 |
+
padding: 0.55rem 1rem;
|
| 477 |
+
border: none;
|
| 478 |
+
border-radius: 8px;
|
| 479 |
+
font-family: inherit;
|
| 480 |
+
font-weight: 700;
|
| 481 |
+
font-size: 0.85rem;
|
| 482 |
+
cursor: pointer;
|
| 483 |
+
transition: all 0.2s ease;
|
| 484 |
+
box-shadow: 0 2px 8px rgba(234, 179, 8, 0.15);
|
| 485 |
+
}
|
| 486 |
+
|
| 487 |
+
.btn-wallet:hover {
|
| 488 |
+
background: linear-gradient(135deg, #facc15 0%, #fbbf24 100%);
|
| 489 |
+
box-shadow: 0 4px 16px rgba(234, 179, 8, 0.3);
|
| 490 |
+
transform: translateY(-1px);
|
| 491 |
+
}
|
| 492 |
+
|
| 493 |
+
/* ── Responsive ────────────────────────── */
|
| 494 |
+
@media (max-width: 500px) {
|
| 495 |
+
.wallet-panel {
|
| 496 |
+
width: 100%;
|
| 497 |
+
border-left: none;
|
| 498 |
+
border-radius: 0;
|
| 499 |
+
}
|
| 500 |
+
|
| 501 |
+
.wallet-panel-content {
|
| 502 |
+
padding: 1.5rem;
|
| 503 |
+
}
|
| 504 |
+
|
| 505 |
+
.wallet-quick-btns {
|
| 506 |
+
grid-template-columns: repeat(2, 1fr);
|
| 507 |
+
}
|
| 508 |
+
}
|
| 509 |
+
|
| 510 |
+
*,
|
| 511 |
+
*::before,
|
| 512 |
+
*::after {
|
| 513 |
+
box-sizing: border-box;
|
| 514 |
+
margin: 0;
|
| 515 |
+
padding: 0;
|
| 516 |
+
}
|
| 517 |
+
|
| 518 |
+
|
| 519 |
+
*::-webkit-scrollbar {
|
| 520 |
+
width: 8px;
|
| 521 |
+
height: 8px;
|
| 522 |
+
}
|
| 523 |
+
|
| 524 |
+
*::-webkit-scrollbar-track {
|
| 525 |
+
background: #0b0e14;
|
| 526 |
+
}
|
| 527 |
+
|
| 528 |
+
*::-webkit-scrollbar-thumb {
|
| 529 |
+
background: #2a2f3e;
|
| 530 |
+
border-radius: 4px;
|
| 531 |
+
}
|
| 532 |
+
|
| 533 |
+
*::-webkit-scrollbar-thumb:hover {
|
| 534 |
+
background: #3a4050;
|
| 535 |
+
}
|
| 536 |
+
|
| 537 |
+
*::-webkit-scrollbar-corner {
|
| 538 |
+
background: #0b0e14;
|
| 539 |
+
}
|
| 540 |
+
|
| 541 |
+
|
| 542 |
+
* {
|
| 543 |
+
scrollbar-width: thin;
|
| 544 |
+
scrollbar-color: #2a2f3e #0b0e14;
|
| 545 |
+
}
|
| 546 |
+
|
| 547 |
+
:root {
|
| 548 |
+
--bg: #0b0e14;
|
| 549 |
+
--bg2: #131720;
|
| 550 |
+
--bg3: #1a1f2e;
|
| 551 |
+
--border: #242a38;
|
| 552 |
+
--text: #d1d5db;
|
| 553 |
+
--text-dim: #6b7280;
|
| 554 |
+
--green: #22c55e;
|
| 555 |
+
--red: #ef4444;
|
| 556 |
+
--blue: #3b82f6;
|
| 557 |
+
--cyan: #06b6d4;
|
| 558 |
+
--yellow: #eab308;
|
| 559 |
+
--accent: #22c55e;
|
| 560 |
+
--purple: #a855f7;
|
| 561 |
+
}
|
| 562 |
+
|
| 563 |
+
body {
|
| 564 |
+
font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
|
| 565 |
+
background: var(--bg);
|
| 566 |
+
color: var(--text);
|
| 567 |
+
min-height: 100vh;
|
| 568 |
+
font-size: 14px;
|
| 569 |
+
}
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
.topbar {
|
| 573 |
+
display: flex;
|
| 574 |
+
align-items: center;
|
| 575 |
+
justify-content: space-between;
|
| 576 |
+
padding: 0.6rem 1.5rem;
|
| 577 |
+
background: var(--bg2);
|
| 578 |
+
border-bottom: 1px solid var(--border);
|
| 579 |
+
position: sticky;
|
| 580 |
+
top: 0;
|
| 581 |
+
z-index: 100;
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
.brand {
|
| 585 |
+
font-size: 1.2rem;
|
| 586 |
+
font-weight: 700;
|
| 587 |
+
color: var(--accent);
|
| 588 |
+
}
|
| 589 |
+
|
| 590 |
+
.brand span {
|
| 591 |
+
color: #fff;
|
| 592 |
+
}
|
| 593 |
+
|
| 594 |
+
.search-area {
|
| 595 |
+
display: flex;
|
| 596 |
+
gap: 0.4rem;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
.search-area input {
|
| 600 |
+
width: 260px;
|
| 601 |
+
padding: 0.5rem 0.8rem;
|
| 602 |
+
background: var(--bg3);
|
| 603 |
+
border: 1px solid var(--border);
|
| 604 |
+
border-radius: 6px;
|
| 605 |
+
color: #fff;
|
| 606 |
+
font-family: inherit;
|
| 607 |
+
font-size: 0.9rem;
|
| 608 |
+
}
|
| 609 |
+
|
| 610 |
+
.search-area input:focus {
|
| 611 |
+
outline: none;
|
| 612 |
+
border-color: var(--accent);
|
| 613 |
+
}
|
| 614 |
+
|
| 615 |
+
.search-area button {
|
| 616 |
+
padding: 0.5rem 1.2rem;
|
| 617 |
+
border: none;
|
| 618 |
+
border-radius: 6px;
|
| 619 |
+
background: var(--accent);
|
| 620 |
+
color: #000;
|
| 621 |
+
font-weight: 700;
|
| 622 |
+
cursor: pointer;
|
| 623 |
+
font-family: inherit;
|
| 624 |
+
transition: 0.2s;
|
| 625 |
+
}
|
| 626 |
+
|
| 627 |
+
.search-area button:hover {
|
| 628 |
+
background: #16a34a;
|
| 629 |
+
}
|
| 630 |
+
|
| 631 |
+
.search-wrapper {
|
| 632 |
+
position: relative;
|
| 633 |
+
}
|
| 634 |
+
|
| 635 |
+
.search-dropdown {
|
| 636 |
+
position: absolute;
|
| 637 |
+
top: 100%;
|
| 638 |
+
left: 0;
|
| 639 |
+
right: 0;
|
| 640 |
+
margin-top: 4px;
|
| 641 |
+
background: var(--bg2);
|
| 642 |
+
border: 1px solid var(--border);
|
| 643 |
+
border-radius: 8px;
|
| 644 |
+
max-height: 320px;
|
| 645 |
+
overflow-y: auto;
|
| 646 |
+
z-index: 200;
|
| 647 |
+
box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
|
| 648 |
+
animation: dropdownFade 0.15s ease;
|
| 649 |
+
}
|
| 650 |
+
|
| 651 |
+
.search-dropdown.hidden {
|
| 652 |
+
display: none;
|
| 653 |
+
}
|
| 654 |
+
|
| 655 |
+
@keyframes dropdownFade {
|
| 656 |
+
from {
|
| 657 |
+
opacity: 0;
|
| 658 |
+
transform: translateY(-6px);
|
| 659 |
+
}
|
| 660 |
+
|
| 661 |
+
to {
|
| 662 |
+
opacity: 1;
|
| 663 |
+
transform: translateY(0);
|
| 664 |
+
}
|
| 665 |
+
}
|
| 666 |
+
|
| 667 |
+
.search-item {
|
| 668 |
+
display: flex;
|
| 669 |
+
align-items: center;
|
| 670 |
+
gap: 0.8rem;
|
| 671 |
+
padding: 0.6rem 0.8rem;
|
| 672 |
+
cursor: pointer;
|
| 673 |
+
transition: background 0.15s;
|
| 674 |
+
border-bottom: 1px solid var(--border);
|
| 675 |
+
}
|
| 676 |
+
|
| 677 |
+
.search-item:last-child {
|
| 678 |
+
border-bottom: none;
|
| 679 |
+
}
|
| 680 |
+
|
| 681 |
+
.search-item:hover {
|
| 682 |
+
background: var(--bg3);
|
| 683 |
+
}
|
| 684 |
+
|
| 685 |
+
.search-ticker {
|
| 686 |
+
font-weight: 700;
|
| 687 |
+
color: var(--accent);
|
| 688 |
+
font-size: 0.85rem;
|
| 689 |
+
min-width: 110px;
|
| 690 |
+
}
|
| 691 |
+
|
| 692 |
+
.search-name {
|
| 693 |
+
color: var(--text-dim);
|
| 694 |
+
font-size: 0.8rem;
|
| 695 |
+
white-space: nowrap;
|
| 696 |
+
overflow: hidden;
|
| 697 |
+
text-overflow: ellipsis;
|
| 698 |
+
}
|
| 699 |
+
|
| 700 |
+
.search-no-results {
|
| 701 |
+
padding: 0.8rem;
|
| 702 |
+
text-align: center;
|
| 703 |
+
color: var(--text-dim);
|
| 704 |
+
font-size: 0.8rem;
|
| 705 |
+
}
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
.chart-empty-state {
|
| 709 |
+
position: absolute;
|
| 710 |
+
inset: 0;
|
| 711 |
+
display: flex;
|
| 712 |
+
flex-direction: column;
|
| 713 |
+
align-items: center;
|
| 714 |
+
justify-content: center;
|
| 715 |
+
text-align: center;
|
| 716 |
+
z-index: 5;
|
| 717 |
+
padding: 2rem;
|
| 718 |
+
}
|
| 719 |
+
|
| 720 |
+
#mainChartWrap {
|
| 721 |
+
position: relative;
|
| 722 |
+
}
|
| 723 |
+
|
| 724 |
+
.chart-empty-state .empty-icon {
|
| 725 |
+
font-size: 3.5rem;
|
| 726 |
+
margin-bottom: 1rem;
|
| 727 |
+
animation: floatIcon 3s ease-in-out infinite;
|
| 728 |
+
}
|
| 729 |
+
|
| 730 |
+
@keyframes floatIcon {
|
| 731 |
+
|
| 732 |
+
0%,
|
| 733 |
+
100% {
|
| 734 |
+
transform: translateY(0);
|
| 735 |
+
}
|
| 736 |
+
|
| 737 |
+
50% {
|
| 738 |
+
transform: translateY(-8px);
|
| 739 |
+
}
|
| 740 |
+
}
|
| 741 |
+
|
| 742 |
+
.chart-empty-state h3 {
|
| 743 |
+
font-size: 1.3rem;
|
| 744 |
+
color: #fff;
|
| 745 |
+
margin-bottom: 0.5rem;
|
| 746 |
+
font-weight: 700;
|
| 747 |
+
}
|
| 748 |
+
|
| 749 |
+
.chart-empty-state p {
|
| 750 |
+
color: var(--text-dim);
|
| 751 |
+
font-size: 0.9rem;
|
| 752 |
+
max-width: 400px;
|
| 753 |
+
line-height: 1.5;
|
| 754 |
+
margin-bottom: 1rem;
|
| 755 |
+
}
|
| 756 |
+
|
| 757 |
+
.empty-hint {
|
| 758 |
+
display: flex;
|
| 759 |
+
gap: 0.5rem;
|
| 760 |
+
font-size: 0.8rem;
|
| 761 |
+
color: var(--text-dim);
|
| 762 |
+
}
|
| 763 |
+
|
| 764 |
+
.empty-hint span {
|
| 765 |
+
color: var(--accent);
|
| 766 |
+
background: rgba(34, 197, 94, 0.1);
|
| 767 |
+
padding: 0.2rem 0.6rem;
|
| 768 |
+
border-radius: 4px;
|
| 769 |
+
cursor: pointer;
|
| 770 |
+
transition: 0.2s;
|
| 771 |
+
font-weight: 600;
|
| 772 |
+
}
|
| 773 |
+
|
| 774 |
+
.empty-hint span:hover {
|
| 775 |
+
background: rgba(34, 197, 94, 0.2);
|
| 776 |
+
}
|
| 777 |
+
|
| 778 |
+
|
| 779 |
+
.nav-tabs {
|
| 780 |
+
display: flex;
|
| 781 |
+
gap: 0.3rem;
|
| 782 |
+
}
|
| 783 |
+
|
| 784 |
+
.nav-tab {
|
| 785 |
+
padding: 0.5rem 1rem;
|
| 786 |
+
border: 1px solid var(--border);
|
| 787 |
+
background: transparent;
|
| 788 |
+
color: var(--text-dim);
|
| 789 |
+
border-radius: 6px;
|
| 790 |
+
cursor: pointer;
|
| 791 |
+
font-family: inherit;
|
| 792 |
+
font-size: 0.85rem;
|
| 793 |
+
transition: 0.2s;
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
.nav-tab:hover {
|
| 797 |
+
border-color: var(--text);
|
| 798 |
+
color: var(--text);
|
| 799 |
+
}
|
| 800 |
+
|
| 801 |
+
.nav-tab.active {
|
| 802 |
+
background: var(--accent);
|
| 803 |
+
color: #000;
|
| 804 |
+
border-color: var(--accent);
|
| 805 |
+
font-weight: 700;
|
| 806 |
+
}
|
| 807 |
+
|
| 808 |
+
.live-badge {
|
| 809 |
+
display: flex;
|
| 810 |
+
align-items: center;
|
| 811 |
+
gap: 0.4rem;
|
| 812 |
+
color: var(--green);
|
| 813 |
+
font-weight: 700;
|
| 814 |
+
font-size: 0.8rem;
|
| 815 |
+
}
|
| 816 |
+
|
| 817 |
+
.live-badge .dot {
|
| 818 |
+
width: 8px;
|
| 819 |
+
height: 8px;
|
| 820 |
+
background: var(--green);
|
| 821 |
+
border-radius: 50%;
|
| 822 |
+
animation: pulse 1.5s infinite;
|
| 823 |
+
}
|
| 824 |
+
|
| 825 |
+
@keyframes pulse {
|
| 826 |
+
|
| 827 |
+
0%,
|
| 828 |
+
100% {
|
| 829 |
+
opacity: 1;
|
| 830 |
+
}
|
| 831 |
+
|
| 832 |
+
50% {
|
| 833 |
+
opacity: 0.3;
|
| 834 |
+
}
|
| 835 |
+
}
|
| 836 |
+
|
| 837 |
+
|
| 838 |
+
.market-bar {
|
| 839 |
+
background: linear-gradient(90deg, #0d1117 0%, #131720 50%, #0d1117 100%);
|
| 840 |
+
border-bottom: 1px solid var(--border);
|
| 841 |
+
padding: 0.45rem 1.5rem;
|
| 842 |
+
position: sticky;
|
| 843 |
+
top: 42px;
|
| 844 |
+
z-index: 99;
|
| 845 |
+
}
|
| 846 |
+
|
| 847 |
+
.market-bar-inner {
|
| 848 |
+
display: flex;
|
| 849 |
+
align-items: center;
|
| 850 |
+
justify-content: center;
|
| 851 |
+
gap: 2rem;
|
| 852 |
+
}
|
| 853 |
+
|
| 854 |
+
.market-item {
|
| 855 |
+
display: flex;
|
| 856 |
+
align-items: center;
|
| 857 |
+
gap: 0.6rem;
|
| 858 |
+
}
|
| 859 |
+
|
| 860 |
+
.mkt-label {
|
| 861 |
+
color: var(--text-dim);
|
| 862 |
+
font-size: 0.75rem;
|
| 863 |
+
font-weight: 700;
|
| 864 |
+
text-transform: uppercase;
|
| 865 |
+
letter-spacing: 0.5px;
|
| 866 |
+
}
|
| 867 |
+
|
| 868 |
+
.mkt-price {
|
| 869 |
+
color: #fff;
|
| 870 |
+
font-size: 0.9rem;
|
| 871 |
+
font-weight: 700;
|
| 872 |
+
}
|
| 873 |
+
|
| 874 |
+
.mkt-change {
|
| 875 |
+
font-size: 0.75rem;
|
| 876 |
+
font-weight: 600;
|
| 877 |
+
padding: 0.15rem 0.5rem;
|
| 878 |
+
border-radius: 4px;
|
| 879 |
+
}
|
| 880 |
+
|
| 881 |
+
.mkt-change.up {
|
| 882 |
+
color: var(--green);
|
| 883 |
+
background: rgba(34, 197, 94, 0.1);
|
| 884 |
+
}
|
| 885 |
+
|
| 886 |
+
.mkt-change.down {
|
| 887 |
+
color: var(--red);
|
| 888 |
+
background: rgba(239, 68, 68, 0.1);
|
| 889 |
+
}
|
| 890 |
+
|
| 891 |
+
.market-sep {
|
| 892 |
+
color: var(--border);
|
| 893 |
+
font-size: 0.8rem;
|
| 894 |
+
}
|
| 895 |
+
|
| 896 |
+
|
| 897 |
+
.price-banner {
|
| 898 |
+
display: flex;
|
| 899 |
+
justify-content: space-between;
|
| 900 |
+
align-items: center;
|
| 901 |
+
padding: 1rem 1.5rem;
|
| 902 |
+
background: var(--bg2);
|
| 903 |
+
border-bottom: 1px solid var(--border);
|
| 904 |
+
}
|
| 905 |
+
|
| 906 |
+
.price-main {
|
| 907 |
+
display: flex;
|
| 908 |
+
align-items: baseline;
|
| 909 |
+
gap: 1rem;
|
| 910 |
+
}
|
| 911 |
+
|
| 912 |
+
.price-main h1 {
|
| 913 |
+
font-size: 1.3rem;
|
| 914 |
+
color: #fff;
|
| 915 |
+
}
|
| 916 |
+
|
| 917 |
+
.price-value {
|
| 918 |
+
font-size: 2rem;
|
| 919 |
+
font-weight: 700;
|
| 920 |
+
color: #fff;
|
| 921 |
+
}
|
| 922 |
+
|
| 923 |
+
.price-change {
|
| 924 |
+
font-size: 1rem;
|
| 925 |
+
font-weight: 600;
|
| 926 |
+
padding: 0.2rem 0.6rem;
|
| 927 |
+
border-radius: 4px;
|
| 928 |
+
}
|
| 929 |
+
|
| 930 |
+
.price-change.up {
|
| 931 |
+
color: var(--green);
|
| 932 |
+
background: rgba(34, 197, 94, 0.1);
|
| 933 |
+
}
|
| 934 |
+
|
| 935 |
+
.price-change.down {
|
| 936 |
+
color: var(--red);
|
| 937 |
+
background: rgba(239, 68, 68, 0.1);
|
| 938 |
+
}
|
| 939 |
+
|
| 940 |
+
.price-stats {
|
| 941 |
+
display: flex;
|
| 942 |
+
gap: 1.5rem;
|
| 943 |
+
}
|
| 944 |
+
|
| 945 |
+
.price-stats div {
|
| 946 |
+
text-align: center;
|
| 947 |
+
}
|
| 948 |
+
|
| 949 |
+
.price-stats label {
|
| 950 |
+
display: block;
|
| 951 |
+
font-size: 0.7rem;
|
| 952 |
+
color: var(--text-dim);
|
| 953 |
+
text-transform: uppercase;
|
| 954 |
+
}
|
| 955 |
+
|
| 956 |
+
.price-stats span {
|
| 957 |
+
font-size: 0.95rem;
|
| 958 |
+
color: #fff;
|
| 959 |
+
font-weight: 600;
|
| 960 |
+
}
|
| 961 |
+
|
| 962 |
+
|
| 963 |
+
.tab-content {
|
| 964 |
+
display: block;
|
| 965 |
+
}
|
| 966 |
+
|
| 967 |
+
.tab-content.hidden {
|
| 968 |
+
display: none !important;
|
| 969 |
+
}
|
| 970 |
+
|
| 971 |
+
|
| 972 |
+
.dashboard {
|
| 973 |
+
display: grid;
|
| 974 |
+
grid-template-columns: 1fr 340px;
|
| 975 |
+
gap: 0;
|
| 976 |
+
min-height: calc(100vh - 160px);
|
| 977 |
+
}
|
| 978 |
+
|
| 979 |
+
.chart-area {
|
| 980 |
+
padding: 1rem 1.5rem;
|
| 981 |
+
border-right: 1px solid var(--border);
|
| 982 |
+
}
|
| 983 |
+
|
| 984 |
+
.sidebar {
|
| 985 |
+
padding: 1rem;
|
| 986 |
+
}
|
| 987 |
+
|
| 988 |
+
|
| 989 |
+
.timeframe-bar {
|
| 990 |
+
display: flex;
|
| 991 |
+
gap: 0.3rem;
|
| 992 |
+
margin-bottom: 0.8rem;
|
| 993 |
+
}
|
| 994 |
+
|
| 995 |
+
.tf-btn {
|
| 996 |
+
padding: 0.35rem 0.9rem;
|
| 997 |
+
border: 1px solid var(--border);
|
| 998 |
+
background: transparent;
|
| 999 |
+
color: var(--text-dim);
|
| 1000 |
+
border-radius: 4px;
|
| 1001 |
+
cursor: pointer;
|
| 1002 |
+
font-family: inherit;
|
| 1003 |
+
font-size: 0.8rem;
|
| 1004 |
+
transition: 0.2s;
|
| 1005 |
+
}
|
| 1006 |
+
|
| 1007 |
+
.tf-btn:hover {
|
| 1008 |
+
border-color: var(--text);
|
| 1009 |
+
color: var(--text);
|
| 1010 |
+
}
|
| 1011 |
+
|
| 1012 |
+
.tf-btn.active {
|
| 1013 |
+
background: var(--accent);
|
| 1014 |
+
color: #000;
|
| 1015 |
+
border-color: var(--accent);
|
| 1016 |
+
font-weight: 700;
|
| 1017 |
+
}
|
| 1018 |
+
|
| 1019 |
+
|
| 1020 |
+
.chart-container {
|
| 1021 |
+
background: var(--bg2);
|
| 1022 |
+
border: 1px solid var(--border);
|
| 1023 |
+
border-radius: 8px;
|
| 1024 |
+
padding: 0.8rem;
|
| 1025 |
+
margin-bottom: 0.8rem;
|
| 1026 |
+
height: 450px;
|
| 1027 |
+
}
|
| 1028 |
+
|
| 1029 |
+
.volume-chart {
|
| 1030 |
+
height: 180px;
|
| 1031 |
+
}
|
| 1032 |
+
|
| 1033 |
+
|
| 1034 |
+
.prediction-section {
|
| 1035 |
+
margin-top: 1rem;
|
| 1036 |
+
}
|
| 1037 |
+
|
| 1038 |
+
.prediction-section h3 {
|
| 1039 |
+
color: var(--cyan);
|
| 1040 |
+
margin-bottom: 0.8rem;
|
| 1041 |
+
}
|
| 1042 |
+
|
| 1043 |
+
.pred-metrics {
|
| 1044 |
+
display: grid;
|
| 1045 |
+
grid-template-columns: repeat(4, 1fr);
|
| 1046 |
+
gap: 0.6rem;
|
| 1047 |
+
margin-top: 0.8rem;
|
| 1048 |
+
}
|
| 1049 |
+
|
| 1050 |
+
.metric-card {
|
| 1051 |
+
background: var(--bg3);
|
| 1052 |
+
border: 1px solid var(--border);
|
| 1053 |
+
border-radius: 8px;
|
| 1054 |
+
padding: 0.8rem;
|
| 1055 |
+
text-align: center;
|
| 1056 |
+
}
|
| 1057 |
+
|
| 1058 |
+
.m-label {
|
| 1059 |
+
display: block;
|
| 1060 |
+
font-size: 0.7rem;
|
| 1061 |
+
color: var(--text-dim);
|
| 1062 |
+
text-transform: uppercase;
|
| 1063 |
+
margin-bottom: 0.3rem;
|
| 1064 |
+
}
|
| 1065 |
+
|
| 1066 |
+
.m-value {
|
| 1067 |
+
font-size: 1.3rem;
|
| 1068 |
+
font-weight: 700;
|
| 1069 |
+
color: #fff;
|
| 1070 |
+
}
|
| 1071 |
+
|
| 1072 |
+
|
| 1073 |
+
.panel {
|
| 1074 |
+
background: var(--bg2);
|
| 1075 |
+
border: 1px solid var(--border);
|
| 1076 |
+
border-radius: 8px;
|
| 1077 |
+
padding: 1rem;
|
| 1078 |
+
margin-bottom: 0.8rem;
|
| 1079 |
+
}
|
| 1080 |
+
|
| 1081 |
+
.panel h3 {
|
| 1082 |
+
font-size: 0.95rem;
|
| 1083 |
+
color: var(--cyan);
|
| 1084 |
+
margin-bottom: 0.3rem;
|
| 1085 |
+
}
|
| 1086 |
+
|
| 1087 |
+
.panel-sub {
|
| 1088 |
+
font-size: 0.75rem;
|
| 1089 |
+
color: var(--text-dim);
|
| 1090 |
+
margin-bottom: 0.8rem;
|
| 1091 |
+
}
|
| 1092 |
+
|
| 1093 |
+
.hp-list {
|
| 1094 |
+
display: flex;
|
| 1095 |
+
flex-direction: column;
|
| 1096 |
+
gap: 0.4rem;
|
| 1097 |
+
max-height: 400px;
|
| 1098 |
+
overflow-y: auto;
|
| 1099 |
+
}
|
| 1100 |
+
|
| 1101 |
+
.hp-item {
|
| 1102 |
+
display: grid;
|
| 1103 |
+
grid-template-columns: 1fr auto auto;
|
| 1104 |
+
align-items: center;
|
| 1105 |
+
gap: 0.5rem;
|
| 1106 |
+
padding: 0.5rem 0.6rem;
|
| 1107 |
+
background: var(--bg3);
|
| 1108 |
+
border-radius: 6px;
|
| 1109 |
+
cursor: pointer;
|
| 1110 |
+
transition: 0.2s;
|
| 1111 |
+
}
|
| 1112 |
+
|
| 1113 |
+
.hp-item:hover {
|
| 1114 |
+
background: var(--border);
|
| 1115 |
+
}
|
| 1116 |
+
|
| 1117 |
+
.hp-ticker {
|
| 1118 |
+
font-weight: 700;
|
| 1119 |
+
color: #fff;
|
| 1120 |
+
font-size: 0.9rem;
|
| 1121 |
+
}
|
| 1122 |
+
|
| 1123 |
+
.hp-name {
|
| 1124 |
+
font-size: 0.7rem;
|
| 1125 |
+
color: var(--text-dim);
|
| 1126 |
+
}
|
| 1127 |
+
|
| 1128 |
+
.hp-price {
|
| 1129 |
+
text-align: right;
|
| 1130 |
+
font-weight: 600;
|
| 1131 |
+
color: #fff;
|
| 1132 |
+
}
|
| 1133 |
+
|
| 1134 |
+
.hp-change {
|
| 1135 |
+
font-size: 0.8rem;
|
| 1136 |
+
font-weight: 600;
|
| 1137 |
+
text-align: right;
|
| 1138 |
+
}
|
| 1139 |
+
|
| 1140 |
+
.hp-change.up {
|
| 1141 |
+
color: var(--green);
|
| 1142 |
+
}
|
| 1143 |
+
|
| 1144 |
+
.hp-change.down {
|
| 1145 |
+
color: var(--red);
|
| 1146 |
+
}
|
| 1147 |
+
|
| 1148 |
+
.hp-score {
|
| 1149 |
+
font-size: 0.7rem;
|
| 1150 |
+
padding: 0.15rem 0.5rem;
|
| 1151 |
+
border-radius: 10px;
|
| 1152 |
+
font-weight: 700;
|
| 1153 |
+
text-align: center;
|
| 1154 |
+
}
|
| 1155 |
+
|
| 1156 |
+
.hp-score.high {
|
| 1157 |
+
background: rgba(34, 197, 94, 0.15);
|
| 1158 |
+
color: var(--green);
|
| 1159 |
+
}
|
| 1160 |
+
|
| 1161 |
+
.hp-score.med {
|
| 1162 |
+
background: rgba(234, 179, 8, 0.15);
|
| 1163 |
+
color: var(--yellow);
|
| 1164 |
+
}
|
| 1165 |
+
|
| 1166 |
+
.hp-score.low {
|
| 1167 |
+
background: rgba(239, 68, 68, 0.15);
|
| 1168 |
+
color: var(--red);
|
| 1169 |
+
}
|
| 1170 |
+
|
| 1171 |
+
.sent-gauge {
|
| 1172 |
+
display: flex;
|
| 1173 |
+
align-items: center;
|
| 1174 |
+
gap: 1rem;
|
| 1175 |
+
margin: 0.8rem 0;
|
| 1176 |
+
}
|
| 1177 |
+
|
| 1178 |
+
.gauge-circle {
|
| 1179 |
+
width: 64px;
|
| 1180 |
+
height: 64px;
|
| 1181 |
+
border-radius: 50%;
|
| 1182 |
+
display: flex;
|
| 1183 |
+
align-items: center;
|
| 1184 |
+
justify-content: center;
|
| 1185 |
+
font-weight: 700;
|
| 1186 |
+
font-size: 1rem;
|
| 1187 |
+
color: #fff;
|
| 1188 |
+
border: 3px solid var(--text-dim);
|
| 1189 |
+
}
|
| 1190 |
+
|
| 1191 |
+
.gauge-circle.positive {
|
| 1192 |
+
border-color: var(--green);
|
| 1193 |
+
background: rgba(34, 197, 94, 0.1);
|
| 1194 |
+
}
|
| 1195 |
+
|
| 1196 |
+
.gauge-circle.negative {
|
| 1197 |
+
border-color: var(--red);
|
| 1198 |
+
background: rgba(239, 68, 68, 0.1);
|
| 1199 |
+
}
|
| 1200 |
+
|
| 1201 |
+
.gauge-circle.neutral {
|
| 1202 |
+
border-color: var(--yellow);
|
| 1203 |
+
background: rgba(234, 179, 8, 0.1);
|
| 1204 |
+
}
|
| 1205 |
+
|
| 1206 |
+
.gauge-label {
|
| 1207 |
+
font-size: 1.1rem;
|
| 1208 |
+
font-weight: 700;
|
| 1209 |
+
text-transform: uppercase;
|
| 1210 |
+
}
|
| 1211 |
+
|
| 1212 |
+
.sent-list {
|
| 1213 |
+
list-style: none;
|
| 1214 |
+
max-height: 250px;
|
| 1215 |
+
overflow-y: auto;
|
| 1216 |
+
padding-right: 5px;
|
| 1217 |
+
}
|
| 1218 |
+
|
| 1219 |
+
.sent-list li {
|
| 1220 |
+
padding: 0.4rem 0;
|
| 1221 |
+
border-bottom: 1px solid var(--border);
|
| 1222 |
+
font-size: 0.8rem;
|
| 1223 |
+
}
|
| 1224 |
+
|
| 1225 |
+
.s-pos {
|
| 1226 |
+
color: var(--green);
|
| 1227 |
+
}
|
| 1228 |
+
|
| 1229 |
+
.s-neg {
|
| 1230 |
+
color: var(--red);
|
| 1231 |
+
}
|
| 1232 |
+
|
| 1233 |
+
.s-neu {
|
| 1234 |
+
color: var(--yellow);
|
| 1235 |
+
}
|
| 1236 |
+
|
| 1237 |
+
.ind-table {
|
| 1238 |
+
width: 100%;
|
| 1239 |
+
}
|
| 1240 |
+
|
| 1241 |
+
.ind-table td {
|
| 1242 |
+
padding: 0.4rem 0.5rem;
|
| 1243 |
+
border-bottom: 1px solid var(--border);
|
| 1244 |
+
}
|
| 1245 |
+
|
| 1246 |
+
.ind-table td:first-child {
|
| 1247 |
+
color: var(--text-dim);
|
| 1248 |
+
}
|
| 1249 |
+
|
| 1250 |
+
.ind-table td:last-child {
|
| 1251 |
+
text-align: right;
|
| 1252 |
+
font-weight: 600;
|
| 1253 |
+
color: #fff;
|
| 1254 |
+
}
|
| 1255 |
+
|
| 1256 |
+
.mini-loader {
|
| 1257 |
+
text-align: center;
|
| 1258 |
+
color: var(--text-dim);
|
| 1259 |
+
padding: 1rem;
|
| 1260 |
+
font-size: 0.8rem;
|
| 1261 |
+
}
|
| 1262 |
+
|
| 1263 |
+
|
| 1264 |
+
.trading-dashboard {
|
| 1265 |
+
padding: 1rem 1.5rem;
|
| 1266 |
+
}
|
| 1267 |
+
|
| 1268 |
+
.trade-grid {
|
| 1269 |
+
display: flex;
|
| 1270 |
+
flex-direction: column;
|
| 1271 |
+
gap: 1rem;
|
| 1272 |
+
}
|
| 1273 |
+
|
| 1274 |
+
|
| 1275 |
+
.portfolio-header {
|
| 1276 |
+
display: grid;
|
| 1277 |
+
grid-template-columns: repeat(6, 1fr);
|
| 1278 |
+
gap: 0.6rem;
|
| 1279 |
+
}
|
| 1280 |
+
|
| 1281 |
+
.port-card {
|
| 1282 |
+
background: var(--bg2);
|
| 1283 |
+
border: 1px solid var(--border);
|
| 1284 |
+
border-radius: 8px;
|
| 1285 |
+
padding: 1rem;
|
| 1286 |
+
text-align: center;
|
| 1287 |
+
}
|
| 1288 |
+
|
| 1289 |
+
.port-card.balance {
|
| 1290 |
+
border-color: var(--accent);
|
| 1291 |
+
}
|
| 1292 |
+
|
| 1293 |
+
.pc-label {
|
| 1294 |
+
display: block;
|
| 1295 |
+
font-size: 0.7rem;
|
| 1296 |
+
color: var(--text-dim);
|
| 1297 |
+
text-transform: uppercase;
|
| 1298 |
+
margin-bottom: 0.4rem;
|
| 1299 |
+
}
|
| 1300 |
+
|
| 1301 |
+
.pc-value {
|
| 1302 |
+
font-size: 1.4rem;
|
| 1303 |
+
font-weight: 700;
|
| 1304 |
+
color: #fff;
|
| 1305 |
+
}
|
| 1306 |
+
|
| 1307 |
+
|
| 1308 |
+
.bot-controls {
|
| 1309 |
+
display: flex;
|
| 1310 |
+
align-items: center;
|
| 1311 |
+
justify-content: space-between;
|
| 1312 |
+
background: var(--bg2);
|
| 1313 |
+
border: 1px solid var(--border);
|
| 1314 |
+
border-radius: 8px;
|
| 1315 |
+
padding: 1rem 1.5rem;
|
| 1316 |
+
}
|
| 1317 |
+
|
| 1318 |
+
.bot-status {
|
| 1319 |
+
display: flex;
|
| 1320 |
+
align-items: center;
|
| 1321 |
+
gap: 0.6rem;
|
| 1322 |
+
font-size: 1.1rem;
|
| 1323 |
+
font-weight: 700;
|
| 1324 |
+
}
|
| 1325 |
+
|
| 1326 |
+
.bot-dot {
|
| 1327 |
+
width: 12px;
|
| 1328 |
+
height: 12px;
|
| 1329 |
+
border-radius: 50%;
|
| 1330 |
+
background: var(--red);
|
| 1331 |
+
}
|
| 1332 |
+
|
| 1333 |
+
.bot-dot.active {
|
| 1334 |
+
background: var(--green);
|
| 1335 |
+
animation: pulse 1s infinite;
|
| 1336 |
+
}
|
| 1337 |
+
|
| 1338 |
+
.bot-buttons {
|
| 1339 |
+
display: flex;
|
| 1340 |
+
gap: 0.5rem;
|
| 1341 |
+
}
|
| 1342 |
+
|
| 1343 |
+
.btn-bot,
|
| 1344 |
+
.btn-scan,
|
| 1345 |
+
.btn-trade,
|
| 1346 |
+
.btn-reset {
|
| 1347 |
+
padding: 0.6rem 1rem;
|
| 1348 |
+
border: none;
|
| 1349 |
+
border-radius: 6px;
|
| 1350 |
+
font-family: inherit;
|
| 1351 |
+
font-weight: 700;
|
| 1352 |
+
font-size: 0.85rem;
|
| 1353 |
+
cursor: pointer;
|
| 1354 |
+
transition: 0.2s;
|
| 1355 |
+
}
|
| 1356 |
+
|
| 1357 |
+
.btn-bot {
|
| 1358 |
+
background: var(--purple);
|
| 1359 |
+
color: #fff;
|
| 1360 |
+
}
|
| 1361 |
+
|
| 1362 |
+
.btn-bot:hover {
|
| 1363 |
+
background: #9333ea;
|
| 1364 |
+
}
|
| 1365 |
+
|
| 1366 |
+
.btn-bot.active {
|
| 1367 |
+
background: var(--red);
|
| 1368 |
+
}
|
| 1369 |
+
|
| 1370 |
+
.btn-scan {
|
| 1371 |
+
background: var(--blue);
|
| 1372 |
+
color: #fff;
|
| 1373 |
+
}
|
| 1374 |
+
|
| 1375 |
+
.btn-scan:hover {
|
| 1376 |
+
background: #2563eb;
|
| 1377 |
+
}
|
| 1378 |
+
|
| 1379 |
+
.btn-trade {
|
| 1380 |
+
background: var(--green);
|
| 1381 |
+
color: #000;
|
| 1382 |
+
}
|
| 1383 |
+
|
| 1384 |
+
.btn-trade:hover {
|
| 1385 |
+
background: #16a34a;
|
| 1386 |
+
}
|
| 1387 |
+
|
| 1388 |
+
.btn-reset {
|
| 1389 |
+
background: var(--bg3);
|
| 1390 |
+
color: var(--text-dim);
|
| 1391 |
+
border: 1px solid var(--border);
|
| 1392 |
+
}
|
| 1393 |
+
|
| 1394 |
+
.btn-reset:hover {
|
| 1395 |
+
background: var(--border);
|
| 1396 |
+
color: #fff;
|
| 1397 |
+
}
|
| 1398 |
+
|
| 1399 |
+
|
| 1400 |
+
.trade-panel {
|
| 1401 |
+
background: var(--bg2);
|
| 1402 |
+
border: 1px solid var(--border);
|
| 1403 |
+
border-radius: 8px;
|
| 1404 |
+
padding: 1rem 1.5rem;
|
| 1405 |
+
}
|
| 1406 |
+
|
| 1407 |
+
.trade-panel h3 {
|
| 1408 |
+
color: var(--cyan);
|
| 1409 |
+
margin-bottom: 0.8rem;
|
| 1410 |
+
font-size: 0.95rem;
|
| 1411 |
+
}
|
| 1412 |
+
|
| 1413 |
+
|
| 1414 |
+
.positions-table-wrap {
|
| 1415 |
+
overflow-x: auto;
|
| 1416 |
+
}
|
| 1417 |
+
|
| 1418 |
+
.positions-table {
|
| 1419 |
+
width: 100%;
|
| 1420 |
+
border-collapse: collapse;
|
| 1421 |
+
font-size: 0.85rem;
|
| 1422 |
+
}
|
| 1423 |
+
|
| 1424 |
+
.positions-table th {
|
| 1425 |
+
padding: 0.5rem 0.6rem;
|
| 1426 |
+
text-align: left;
|
| 1427 |
+
color: var(--text-dim);
|
| 1428 |
+
border-bottom: 1px solid var(--border);
|
| 1429 |
+
font-size: 0.75rem;
|
| 1430 |
+
text-transform: uppercase;
|
| 1431 |
+
}
|
| 1432 |
+
|
| 1433 |
+
.positions-table td {
|
| 1434 |
+
padding: 0.6rem;
|
| 1435 |
+
border-bottom: 1px solid var(--border);
|
| 1436 |
+
}
|
| 1437 |
+
|
| 1438 |
+
.positions-table .ticker-col {
|
| 1439 |
+
font-weight: 700;
|
| 1440 |
+
color: #fff;
|
| 1441 |
+
}
|
| 1442 |
+
|
| 1443 |
+
.pnl-positive {
|
| 1444 |
+
color: var(--green);
|
| 1445 |
+
font-weight: 700;
|
| 1446 |
+
}
|
| 1447 |
+
|
| 1448 |
+
.pnl-negative {
|
| 1449 |
+
color: var(--red);
|
| 1450 |
+
font-weight: 700;
|
| 1451 |
+
}
|
| 1452 |
+
|
| 1453 |
+
.btn-sell-small {
|
| 1454 |
+
padding: 0.3rem 0.7rem;
|
| 1455 |
+
border: none;
|
| 1456 |
+
border-radius: 4px;
|
| 1457 |
+
background: var(--red);
|
| 1458 |
+
color: #fff;
|
| 1459 |
+
font-weight: 700;
|
| 1460 |
+
cursor: pointer;
|
| 1461 |
+
font-family: inherit;
|
| 1462 |
+
font-size: 0.75rem;
|
| 1463 |
+
}
|
| 1464 |
+
|
| 1465 |
+
.btn-sell-small:hover {
|
| 1466 |
+
background: #dc2626;
|
| 1467 |
+
}
|
| 1468 |
+
|
| 1469 |
+
.empty-msg {
|
| 1470 |
+
color: var(--text-dim);
|
| 1471 |
+
text-align: center;
|
| 1472 |
+
padding: 1.5rem;
|
| 1473 |
+
font-size: 0.85rem;
|
| 1474 |
+
}
|
| 1475 |
+
|
| 1476 |
+
|
| 1477 |
+
.trade-log {
|
| 1478 |
+
max-height: 300px;
|
| 1479 |
+
overflow-y: auto;
|
| 1480 |
+
}
|
| 1481 |
+
|
| 1482 |
+
.trade-entry {
|
| 1483 |
+
display: grid;
|
| 1484 |
+
grid-template-columns: auto 1fr auto auto;
|
| 1485 |
+
gap: 0.8rem;
|
| 1486 |
+
align-items: center;
|
| 1487 |
+
padding: 0.6rem 0;
|
| 1488 |
+
border-bottom: 1px solid var(--border);
|
| 1489 |
+
font-size: 0.8rem;
|
| 1490 |
+
}
|
| 1491 |
+
|
| 1492 |
+
.te-time {
|
| 1493 |
+
color: var(--text-dim);
|
| 1494 |
+
font-size: 0.75rem;
|
| 1495 |
+
}
|
| 1496 |
+
|
| 1497 |
+
.te-ticker {
|
| 1498 |
+
font-weight: 700;
|
| 1499 |
+
color: #fff;
|
| 1500 |
+
}
|
| 1501 |
+
|
| 1502 |
+
.te-action {
|
| 1503 |
+
padding: 0.15rem 0.5rem;
|
| 1504 |
+
border-radius: 4px;
|
| 1505 |
+
font-weight: 700;
|
| 1506 |
+
font-size: 0.75rem;
|
| 1507 |
+
}
|
| 1508 |
+
|
| 1509 |
+
.te-action.buy {
|
| 1510 |
+
background: rgba(34, 197, 94, 0.15);
|
| 1511 |
+
color: var(--green);
|
| 1512 |
+
}
|
| 1513 |
+
|
| 1514 |
+
.te-action.sell {
|
| 1515 |
+
background: rgba(239, 68, 68, 0.15);
|
| 1516 |
+
color: var(--red);
|
| 1517 |
+
}
|
| 1518 |
+
|
| 1519 |
+
|
| 1520 |
+
.trade-feed {
|
| 1521 |
+
max-height: 250px;
|
| 1522 |
+
overflow-y: auto;
|
| 1523 |
+
font-size: 0.8rem;
|
| 1524 |
+
}
|
| 1525 |
+
|
| 1526 |
+
.feed-item {
|
| 1527 |
+
padding: 0.5rem 0.6rem;
|
| 1528 |
+
margin-bottom: 0.3rem;
|
| 1529 |
+
background: var(--bg3);
|
| 1530 |
+
border-radius: 4px;
|
| 1531 |
+
border-left: 3px solid var(--border);
|
| 1532 |
+
animation: fadeIn 0.3s ease;
|
| 1533 |
+
}
|
| 1534 |
+
|
| 1535 |
+
.feed-item.buy {
|
| 1536 |
+
border-left-color: var(--green);
|
| 1537 |
+
}
|
| 1538 |
+
|
| 1539 |
+
.feed-item.sell {
|
| 1540 |
+
border-left-color: var(--red);
|
| 1541 |
+
}
|
| 1542 |
+
|
| 1543 |
+
.feed-item.hold {
|
| 1544 |
+
border-left-color: var(--yellow);
|
| 1545 |
+
}
|
| 1546 |
+
|
| 1547 |
+
.feed-item.wait {
|
| 1548 |
+
border-left-color: var(--text-dim);
|
| 1549 |
+
}
|
| 1550 |
+
|
| 1551 |
+
@keyframes fadeIn {
|
| 1552 |
+
from {
|
| 1553 |
+
opacity: 0;
|
| 1554 |
+
transform: translateY(-5px);
|
| 1555 |
+
}
|
| 1556 |
+
|
| 1557 |
+
to {
|
| 1558 |
+
opacity: 1;
|
| 1559 |
+
transform: translateY(0);
|
| 1560 |
+
}
|
| 1561 |
+
}
|
| 1562 |
+
|
| 1563 |
+
|
| 1564 |
+
footer {
|
| 1565 |
+
text-align: center;
|
| 1566 |
+
padding: 1.5rem;
|
| 1567 |
+
background: var(--bg2);
|
| 1568 |
+
border-top: 1px solid var(--border);
|
| 1569 |
+
color: var(--text-dim);
|
| 1570 |
+
font-size: 0.8rem;
|
| 1571 |
+
}
|
| 1572 |
+
|
| 1573 |
+
footer p+p {
|
| 1574 |
+
margin-top: 0.3rem;
|
| 1575 |
+
}
|
| 1576 |
+
|
| 1577 |
+
.hidden {
|
| 1578 |
+
display: none !important;
|
| 1579 |
+
}
|
| 1580 |
+
|
| 1581 |
+
|
| 1582 |
+
@media (max-width: 1100px) {
|
| 1583 |
+
.portfolio-header {
|
| 1584 |
+
grid-template-columns: repeat(3, 1fr);
|
| 1585 |
+
}
|
| 1586 |
+
}
|
| 1587 |
+
|
| 1588 |
+
@media (max-width: 900px) {
|
| 1589 |
+
.dashboard {
|
| 1590 |
+
grid-template-columns: 1fr;
|
| 1591 |
+
}
|
| 1592 |
+
|
| 1593 |
+
.sidebar {
|
| 1594 |
+
max-height: none;
|
| 1595 |
+
}
|
| 1596 |
+
|
| 1597 |
+
.price-banner {
|
| 1598 |
+
flex-direction: column;
|
| 1599 |
+
gap: 0.8rem;
|
| 1600 |
+
}
|
| 1601 |
+
|
| 1602 |
+
.price-stats {
|
| 1603 |
+
flex-wrap: wrap;
|
| 1604 |
+
}
|
| 1605 |
+
|
| 1606 |
+
.pred-metrics {
|
| 1607 |
+
grid-template-columns: repeat(2, 1fr);
|
| 1608 |
+
}
|
| 1609 |
+
|
| 1610 |
+
.portfolio-header {
|
| 1611 |
+
grid-template-columns: repeat(2, 1fr);
|
| 1612 |
+
}
|
| 1613 |
+
|
| 1614 |
+
.bot-controls {
|
| 1615 |
+
flex-direction: column;
|
| 1616 |
+
gap: 0.8rem;
|
| 1617 |
+
}
|
| 1618 |
+
|
| 1619 |
+
.bot-buttons {
|
| 1620 |
+
flex-wrap: wrap;
|
| 1621 |
+
}
|
| 1622 |
+
}
|
| 1623 |
+
|
| 1624 |
+
|
| 1625 |
+
.pred-loader {
|
| 1626 |
+
display: flex;
|
| 1627 |
+
align-items: center;
|
| 1628 |
+
justify-content: center;
|
| 1629 |
+
min-height: 280px;
|
| 1630 |
+
position: relative;
|
| 1631 |
+
overflow: hidden;
|
| 1632 |
+
background: radial-gradient(ellipse at center, rgba(59, 130, 246, 0.06) 0%, transparent 70%);
|
| 1633 |
+
border-radius: 12px;
|
| 1634 |
+
border: 1px solid var(--border);
|
| 1635 |
+
}
|
| 1636 |
+
|
| 1637 |
+
.pred-loader.hidden {
|
| 1638 |
+
display: none;
|
| 1639 |
+
}
|
| 1640 |
+
|
| 1641 |
+
.pred-loader-inner {
|
| 1642 |
+
text-align: center;
|
| 1643 |
+
z-index: 2;
|
| 1644 |
+
}
|
| 1645 |
+
|
| 1646 |
+
|
| 1647 |
+
.neural-dots {
|
| 1648 |
+
display: flex;
|
| 1649 |
+
justify-content: center;
|
| 1650 |
+
gap: 8px;
|
| 1651 |
+
margin-bottom: 18px;
|
| 1652 |
+
}
|
| 1653 |
+
|
| 1654 |
+
.neural-dots span {
|
| 1655 |
+
width: 10px;
|
| 1656 |
+
height: 10px;
|
| 1657 |
+
border-radius: 50%;
|
| 1658 |
+
background: #3b82f6;
|
| 1659 |
+
animation: neuralPulse 1.4s ease-in-out infinite;
|
| 1660 |
+
box-shadow: 0 0 12px rgba(59, 130, 246, 0.5);
|
| 1661 |
+
}
|
| 1662 |
+
|
| 1663 |
+
.neural-dots span:nth-child(1) {
|
| 1664 |
+
animation-delay: 0s;
|
| 1665 |
+
}
|
| 1666 |
+
|
| 1667 |
+
.neural-dots span:nth-child(2) {
|
| 1668 |
+
animation-delay: 0.15s;
|
| 1669 |
+
}
|
| 1670 |
+
|
| 1671 |
+
.neural-dots span:nth-child(3) {
|
| 1672 |
+
animation-delay: 0.3s;
|
| 1673 |
+
}
|
| 1674 |
+
|
| 1675 |
+
.neural-dots span:nth-child(4) {
|
| 1676 |
+
animation-delay: 0.45s;
|
| 1677 |
+
}
|
| 1678 |
+
|
| 1679 |
+
.neural-dots span:nth-child(5) {
|
| 1680 |
+
animation-delay: 0.6s;
|
| 1681 |
+
}
|
| 1682 |
+
|
| 1683 |
+
@keyframes neuralPulse {
|
| 1684 |
+
|
| 1685 |
+
0%,
|
| 1686 |
+
100% {
|
| 1687 |
+
transform: scale(0.5);
|
| 1688 |
+
opacity: 0.3;
|
| 1689 |
+
background: #3b82f6;
|
| 1690 |
+
}
|
| 1691 |
+
|
| 1692 |
+
50% {
|
| 1693 |
+
transform: scale(1.3);
|
| 1694 |
+
opacity: 1;
|
| 1695 |
+
background: #22c55e;
|
| 1696 |
+
}
|
| 1697 |
+
}
|
| 1698 |
+
|
| 1699 |
+
|
| 1700 |
+
.loader-brain {
|
| 1701 |
+
font-size: 3rem;
|
| 1702 |
+
animation: brainPulse 2s ease-in-out infinite;
|
| 1703 |
+
margin-bottom: 12px;
|
| 1704 |
+
filter: drop-shadow(0 0 16px rgba(34, 197, 94, 0.4));
|
| 1705 |
+
}
|
| 1706 |
+
|
| 1707 |
+
@keyframes brainPulse {
|
| 1708 |
+
|
| 1709 |
+
0%,
|
| 1710 |
+
100% {
|
| 1711 |
+
transform: scale(1);
|
| 1712 |
+
}
|
| 1713 |
+
|
| 1714 |
+
50% {
|
| 1715 |
+
transform: scale(1.15);
|
| 1716 |
+
}
|
| 1717 |
+
}
|
| 1718 |
+
|
| 1719 |
+
.loader-title {
|
| 1720 |
+
font-size: 1.1rem;
|
| 1721 |
+
font-weight: 700;
|
| 1722 |
+
background: linear-gradient(135deg, #3b82f6, #22c55e);
|
| 1723 |
+
-webkit-background-clip: text;
|
| 1724 |
+
-webkit-text-fill-color: transparent;
|
| 1725 |
+
background-clip: text;
|
| 1726 |
+
margin-bottom: 4px;
|
| 1727 |
+
}
|
| 1728 |
+
|
| 1729 |
+
.loader-sub {
|
| 1730 |
+
color: var(--text-dim);
|
| 1731 |
+
font-size: 0.8rem;
|
| 1732 |
+
margin-bottom: 16px;
|
| 1733 |
+
}
|
| 1734 |
+
|
| 1735 |
+
|
| 1736 |
+
.loader-bar {
|
| 1737 |
+
width: 200px;
|
| 1738 |
+
height: 4px;
|
| 1739 |
+
background: var(--bg3);
|
| 1740 |
+
border-radius: 4px;
|
| 1741 |
+
overflow: hidden;
|
| 1742 |
+
margin: 0 auto;
|
| 1743 |
+
}
|
| 1744 |
+
|
| 1745 |
+
.loader-bar-fill {
|
| 1746 |
+
height: 100%;
|
| 1747 |
+
width: 40%;
|
| 1748 |
+
background: linear-gradient(90deg, #3b82f6, #22c55e);
|
| 1749 |
+
border-radius: 4px;
|
| 1750 |
+
animation: barSlide 1.8s ease-in-out infinite;
|
| 1751 |
+
}
|
| 1752 |
+
|
| 1753 |
+
@keyframes barSlide {
|
| 1754 |
+
0% {
|
| 1755 |
+
transform: translateX(-100%);
|
| 1756 |
+
}
|
| 1757 |
+
|
| 1758 |
+
100% {
|
| 1759 |
+
transform: translateX(350%);
|
| 1760 |
+
}
|
| 1761 |
+
}
|
| 1762 |
+
|
| 1763 |
+
|
| 1764 |
+
.stats-ticker {
|
| 1765 |
+
background: var(--bg2);
|
| 1766 |
+
border-top: 1px solid var(--border);
|
| 1767 |
+
border-bottom: 1px solid var(--border);
|
| 1768 |
+
overflow: hidden;
|
| 1769 |
+
white-space: nowrap;
|
| 1770 |
+
padding: 0.6rem 0;
|
| 1771 |
+
}
|
| 1772 |
+
|
| 1773 |
+
.ticker-track {
|
| 1774 |
+
display: inline-block;
|
| 1775 |
+
animation: tickerScroll 40s linear infinite;
|
| 1776 |
+
}
|
| 1777 |
+
|
| 1778 |
+
.ticker-item {
|
| 1779 |
+
color: var(--text);
|
| 1780 |
+
font-size: 0.82rem;
|
| 1781 |
+
margin: 0 1rem;
|
| 1782 |
+
}
|
| 1783 |
+
|
| 1784 |
+
.ticker-item strong {
|
| 1785 |
+
color: var(--cyan);
|
| 1786 |
+
}
|
| 1787 |
+
|
| 1788 |
+
.ticker-sep {
|
| 1789 |
+
color: var(--border);
|
| 1790 |
+
margin: 0 0.3rem;
|
| 1791 |
+
font-size: 0.7rem;
|
| 1792 |
+
}
|
| 1793 |
+
|
| 1794 |
+
@keyframes tickerScroll {
|
| 1795 |
+
0% {
|
| 1796 |
+
transform: translateX(0);
|
| 1797 |
+
}
|
| 1798 |
+
|
| 1799 |
+
100% {
|
| 1800 |
+
transform: translateX(-50%);
|
| 1801 |
+
}
|
| 1802 |
+
}
|
| 1803 |
+
|
| 1804 |
+
|
| 1805 |
+
.section-title {
|
| 1806 |
+
text-align: center;
|
| 1807 |
+
font-size: 1.4rem;
|
| 1808 |
+
color: #fff;
|
| 1809 |
+
margin-bottom: 1.8rem;
|
| 1810 |
+
font-weight: 700;
|
| 1811 |
+
}
|
| 1812 |
+
|
| 1813 |
+
|
| 1814 |
+
.insights-section {
|
| 1815 |
+
padding: 2.5rem 2rem;
|
| 1816 |
+
background: linear-gradient(180deg, var(--bg1) 0%, var(--bg2) 100%);
|
| 1817 |
+
}
|
| 1818 |
+
|
| 1819 |
+
.insights-grid {
|
| 1820 |
+
display: grid;
|
| 1821 |
+
grid-template-columns: repeat(3, 1fr);
|
| 1822 |
+
gap: 1.2rem;
|
| 1823 |
+
max-width: 1200px;
|
| 1824 |
+
margin: 0 auto;
|
| 1825 |
+
}
|
| 1826 |
+
|
| 1827 |
+
.insight-card {
|
| 1828 |
+
background: var(--bg2);
|
| 1829 |
+
border: 1px solid var(--border);
|
| 1830 |
+
border-radius: 12px;
|
| 1831 |
+
padding: 1.5rem;
|
| 1832 |
+
transition: all 0.3s ease;
|
| 1833 |
+
text-align: center;
|
| 1834 |
+
}
|
| 1835 |
+
|
| 1836 |
+
.insight-card:hover {
|
| 1837 |
+
border-color: var(--accent);
|
| 1838 |
+
transform: translateY(-4px);
|
| 1839 |
+
box-shadow: 0 8px 30px rgba(88, 166, 255, 0.1);
|
| 1840 |
+
}
|
| 1841 |
+
|
| 1842 |
+
.insight-icon {
|
| 1843 |
+
font-size: 2.2rem;
|
| 1844 |
+
margin-bottom: 0.6rem;
|
| 1845 |
+
}
|
| 1846 |
+
|
| 1847 |
+
.insight-card h4 {
|
| 1848 |
+
color: var(--cyan);
|
| 1849 |
+
font-size: 0.95rem;
|
| 1850 |
+
margin-bottom: 0.5rem;
|
| 1851 |
+
}
|
| 1852 |
+
|
| 1853 |
+
.insight-card p {
|
| 1854 |
+
color: var(--text-dim);
|
| 1855 |
+
font-size: 0.8rem;
|
| 1856 |
+
line-height: 1.5;
|
| 1857 |
+
}
|
| 1858 |
+
|
| 1859 |
+
|
| 1860 |
+
.pipeline-section {
|
| 1861 |
+
padding: 2.5rem 2rem;
|
| 1862 |
+
background: var(--bg1);
|
| 1863 |
+
}
|
| 1864 |
+
|
| 1865 |
+
.pipeline {
|
| 1866 |
+
display: flex;
|
| 1867 |
+
align-items: flex-start;
|
| 1868 |
+
justify-content: center;
|
| 1869 |
+
gap: 0;
|
| 1870 |
+
max-width: 1200px;
|
| 1871 |
+
margin: 0 auto;
|
| 1872 |
+
}
|
| 1873 |
+
|
| 1874 |
+
.pipe-step {
|
| 1875 |
+
flex: 1;
|
| 1876 |
+
max-width: 260px;
|
| 1877 |
+
background: var(--bg2);
|
| 1878 |
+
border: 1px solid var(--border);
|
| 1879 |
+
border-radius: 12px;
|
| 1880 |
+
padding: 1.5rem 1.2rem;
|
| 1881 |
+
text-align: center;
|
| 1882 |
+
position: relative;
|
| 1883 |
+
transition: all 0.3s ease;
|
| 1884 |
+
}
|
| 1885 |
+
|
| 1886 |
+
.pipe-step:hover {
|
| 1887 |
+
border-color: var(--green);
|
| 1888 |
+
transform: translateY(-4px);
|
| 1889 |
+
box-shadow: 0 8px 30px rgba(34, 197, 94, 0.1);
|
| 1890 |
+
}
|
| 1891 |
+
|
| 1892 |
+
.pipe-num {
|
| 1893 |
+
position: absolute;
|
| 1894 |
+
top: -12px;
|
| 1895 |
+
left: 50%;
|
| 1896 |
+
transform: translateX(-50%);
|
| 1897 |
+
background: linear-gradient(135deg, var(--accent), var(--green));
|
| 1898 |
+
color: #000;
|
| 1899 |
+
font-size: 0.7rem;
|
| 1900 |
+
font-weight: 800;
|
| 1901 |
+
padding: 0.15rem 0.6rem;
|
| 1902 |
+
border-radius: 10px;
|
| 1903 |
+
}
|
| 1904 |
+
|
| 1905 |
+
.pipe-icon {
|
| 1906 |
+
font-size: 2rem;
|
| 1907 |
+
margin-bottom: 0.5rem;
|
| 1908 |
+
margin-top: 0.3rem;
|
| 1909 |
+
}
|
| 1910 |
+
|
| 1911 |
+
.pipe-step h4 {
|
| 1912 |
+
color: #fff;
|
| 1913 |
+
font-size: 0.95rem;
|
| 1914 |
+
margin-bottom: 0.4rem;
|
| 1915 |
+
}
|
| 1916 |
+
|
| 1917 |
+
.pipe-step p {
|
| 1918 |
+
color: var(--text-dim);
|
| 1919 |
+
font-size: 0.78rem;
|
| 1920 |
+
line-height: 1.5;
|
| 1921 |
+
}
|
| 1922 |
+
|
| 1923 |
+
.pipe-arrow {
|
| 1924 |
+
display: flex;
|
| 1925 |
+
align-items: center;
|
| 1926 |
+
font-size: 1.8rem;
|
| 1927 |
+
color: var(--accent);
|
| 1928 |
+
padding: 0 0.5rem;
|
| 1929 |
+
margin-top: 2rem;
|
| 1930 |
+
animation: arrowPulse 1.5s ease-in-out infinite;
|
| 1931 |
+
}
|
| 1932 |
+
|
| 1933 |
+
@keyframes arrowPulse {
|
| 1934 |
+
|
| 1935 |
+
0%,
|
| 1936 |
+
100% {
|
| 1937 |
+
opacity: 0.3;
|
| 1938 |
+
transform: translateX(0);
|
| 1939 |
+
}
|
| 1940 |
+
|
| 1941 |
+
50% {
|
| 1942 |
+
opacity: 1;
|
| 1943 |
+
transform: translateX(4px);
|
| 1944 |
+
}
|
| 1945 |
+
}
|
| 1946 |
+
|
| 1947 |
+
|
| 1948 |
+
.app-footer {
|
| 1949 |
+
background: var(--bg2);
|
| 1950 |
+
border-top: 1px solid var(--border);
|
| 1951 |
+
padding: 1.5rem 2rem;
|
| 1952 |
+
}
|
| 1953 |
+
|
| 1954 |
+
.footer-content {
|
| 1955 |
+
max-width: 1200px;
|
| 1956 |
+
margin: 0 auto;
|
| 1957 |
+
display: flex;
|
| 1958 |
+
justify-content: space-between;
|
| 1959 |
+
align-items: center;
|
| 1960 |
+
}
|
| 1961 |
+
|
| 1962 |
+
.footer-brand {
|
| 1963 |
+
display: flex;
|
| 1964 |
+
flex-direction: column;
|
| 1965 |
+
gap: 0.3rem;
|
| 1966 |
+
}
|
| 1967 |
+
|
| 1968 |
+
.footer-logo {
|
| 1969 |
+
font-size: 1.1rem;
|
| 1970 |
+
font-weight: 700;
|
| 1971 |
+
color: #fff;
|
| 1972 |
+
}
|
| 1973 |
+
|
| 1974 |
+
.footer-tagline {
|
| 1975 |
+
font-size: 0.75rem;
|
| 1976 |
+
color: var(--text-dim);
|
| 1977 |
+
}
|
| 1978 |
+
|
| 1979 |
+
.footer-tech {
|
| 1980 |
+
display: flex;
|
| 1981 |
+
align-items: center;
|
| 1982 |
+
gap: 0.5rem;
|
| 1983 |
+
color: var(--text-dim);
|
| 1984 |
+
font-size: 0.75rem;
|
| 1985 |
+
}
|
| 1986 |
+
|
| 1987 |
+
.tech-badge {
|
| 1988 |
+
padding: 0.2rem 0.6rem;
|
| 1989 |
+
background: var(--bg3);
|
| 1990 |
+
border: 1px solid var(--border);
|
| 1991 |
+
border-radius: 4px;
|
| 1992 |
+
font-size: 0.7rem;
|
| 1993 |
+
color: var(--cyan);
|
| 1994 |
+
font-weight: 600;
|
| 1995 |
+
}
|
| 1996 |
+
|
| 1997 |
+
|
| 1998 |
+
@media (max-width: 900px) {
|
| 1999 |
+
.insights-grid {
|
| 2000 |
+
grid-template-columns: repeat(2, 1fr);
|
| 2001 |
+
}
|
| 2002 |
+
|
| 2003 |
+
.pipeline {
|
| 2004 |
+
flex-direction: column;
|
| 2005 |
+
align-items: center;
|
| 2006 |
+
gap: 0.5rem;
|
| 2007 |
+
}
|
| 2008 |
+
|
| 2009 |
+
.pipe-arrow {
|
| 2010 |
+
transform: rotate(90deg);
|
| 2011 |
+
margin-top: 0;
|
| 2012 |
+
}
|
| 2013 |
+
|
| 2014 |
+
.footer-content {
|
| 2015 |
+
flex-direction: column;
|
| 2016 |
+
text-align: center;
|
| 2017 |
+
gap: 1rem;
|
| 2018 |
+
}
|
| 2019 |
+
}
|
frontend/wallet-styles.css
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* ============================================================================
|
| 2 |
+
WALLET MESSAGE STYLES
|
| 3 |
+
============================================================================ */
|
| 4 |
+
|
| 5 |
+
.wallet-message {
|
| 6 |
+
margin-top: 1.5rem;
|
| 7 |
+
padding: 1.1rem 1.3rem;
|
| 8 |
+
border-radius: 10px;
|
| 9 |
+
font-size: 0.9rem;
|
| 10 |
+
font-weight: 600;
|
| 11 |
+
text-align: center;
|
| 12 |
+
animation: messageSlideIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
|
| 13 |
+
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
|
| 14 |
+
position: relative;
|
| 15 |
+
overflow: hidden;
|
| 16 |
+
letter-spacing: 0.02em;
|
| 17 |
+
}
|
| 18 |
+
|
| 19 |
+
.wallet-message::before {
|
| 20 |
+
content: '';
|
| 21 |
+
position: absolute;
|
| 22 |
+
left: 0;
|
| 23 |
+
top: 0;
|
| 24 |
+
bottom: 0;
|
| 25 |
+
width: 4px;
|
| 26 |
+
animation: progressBar 5s linear forwards;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
.wallet-message.success {
|
| 30 |
+
background: linear-gradient(135deg, rgba(34, 197, 94, 0.12) 0%, rgba(34, 197, 94, 0.08) 100%);
|
| 31 |
+
color: #22c55e;
|
| 32 |
+
border: 1.5px solid rgba(34, 197, 94, 0.35);
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
.wallet-message.success::before {
|
| 36 |
+
background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
.wallet-message.error {
|
| 40 |
+
background: linear-gradient(135deg, rgba(239, 68, 68, 0.12) 0%, rgba(239, 68, 68, 0.08) 100%);
|
| 41 |
+
color: #ef4444;
|
| 42 |
+
border: 1.5px solid rgba(239, 68, 68, 0.35);
|
| 43 |
+
}
|
| 44 |
+
|
| 45 |
+
.wallet-message.error::before {
|
| 46 |
+
background: linear-gradient(180deg, #ef4444 0%, #dc2626 100%);
|
| 47 |
+
}
|
| 48 |
+
|
| 49 |
+
.wallet-message.hidden {
|
| 50 |
+
display: none;
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
@keyframes messageSlideIn {
|
| 54 |
+
from {
|
| 55 |
+
opacity: 0;
|
| 56 |
+
transform: translateY(-15px) scale(0.95);
|
| 57 |
+
}
|
| 58 |
+
to {
|
| 59 |
+
opacity: 1;
|
| 60 |
+
transform: translateY(0) scale(1);
|
| 61 |
+
}
|
| 62 |
+
}
|
| 63 |
+
|
| 64 |
+
@keyframes progressBar {
|
| 65 |
+
from {
|
| 66 |
+
height: 100%;
|
| 67 |
+
}
|
| 68 |
+
to {
|
| 69 |
+
height: 0%;
|
| 70 |
+
}
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
/* ============================================================================
|
| 75 |
+
WALLET FORM STYLES
|
| 76 |
+
============================================================================ */
|
| 77 |
+
|
| 78 |
+
.wallet-form {
|
| 79 |
+
margin-top: 1.2rem;
|
| 80 |
+
display: flex;
|
| 81 |
+
flex-direction: column;
|
| 82 |
+
gap: 1.1rem;
|
| 83 |
+
background: #202534;
|
| 84 |
+
border-radius: 10px;
|
| 85 |
+
padding: 1.3rem 1.2rem 1.5rem 1.2rem;
|
| 86 |
+
box-shadow: 0 2px 12px rgba(59, 130, 246, 0.04);
|
| 87 |
+
border: 1px solid #242a38;
|
| 88 |
+
animation: formFadeIn 0.3s ease-out;
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
@keyframes formFadeIn {
|
| 92 |
+
from {
|
| 93 |
+
opacity: 0;
|
| 94 |
+
transform: translateY(-8px);
|
| 95 |
+
}
|
| 96 |
+
to {
|
| 97 |
+
opacity: 1;
|
| 98 |
+
transform: translateY(0);
|
| 99 |
+
}
|
| 100 |
+
}
|
| 101 |
+
|
| 102 |
+
.wallet-form h3 {
|
| 103 |
+
margin-bottom: 0.5rem;
|
| 104 |
+
color: #06b6d4;
|
| 105 |
+
font-size: 1.1rem;
|
| 106 |
+
font-weight: 700;
|
| 107 |
+
letter-spacing: 0.02em;
|
| 108 |
+
}
|
| 109 |
+
|
| 110 |
+
.wallet-form input {
|
| 111 |
+
padding: 0.9rem 1.1rem;
|
| 112 |
+
border-radius: 7px;
|
| 113 |
+
border: 1.5px solid #242a38;
|
| 114 |
+
background: #23283a;
|
| 115 |
+
color: #fff;
|
| 116 |
+
margin-bottom: 0.7rem;
|
| 117 |
+
width: 100%;
|
| 118 |
+
font-size: 1.05rem;
|
| 119 |
+
font-family: inherit;
|
| 120 |
+
font-weight: 600;
|
| 121 |
+
letter-spacing: 0.01em;
|
| 122 |
+
transition: all 0.2s ease;
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
.wallet-form input:focus {
|
| 126 |
+
outline: none;
|
| 127 |
+
border-color: #3b82f6;
|
| 128 |
+
background: #1a1f2e;
|
| 129 |
+
box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
.wallet-form input:hover {
|
| 133 |
+
border-color: #2a3040;
|
| 134 |
+
}
|
| 135 |
+
|
| 136 |
+
.wallet-form input::placeholder {
|
| 137 |
+
color: #6b7280;
|
| 138 |
+
font-weight: 500;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.wallet-form button {
|
| 142 |
+
background: linear-gradient(90deg, #3b82f6 80%, #a5b4fc 100%);
|
| 143 |
+
color: #fff;
|
| 144 |
+
border: none;
|
| 145 |
+
border-radius: 7px;
|
| 146 |
+
padding: 1rem 0;
|
| 147 |
+
font-size: 1.08rem;
|
| 148 |
+
font-weight: 700;
|
| 149 |
+
cursor: pointer;
|
| 150 |
+
box-shadow: 0 2px 12px rgba(59, 130, 246, 0.08);
|
| 151 |
+
transition: all 0.2s ease;
|
| 152 |
+
font-family: inherit;
|
| 153 |
+
letter-spacing: 0.02em;
|
| 154 |
+
position: relative;
|
| 155 |
+
overflow: hidden;
|
| 156 |
+
}
|
| 157 |
+
|
| 158 |
+
.wallet-form button::before {
|
| 159 |
+
content: '';
|
| 160 |
+
position: absolute;
|
| 161 |
+
top: 50%;
|
| 162 |
+
left: 50%;
|
| 163 |
+
width: 0;
|
| 164 |
+
height: 0;
|
| 165 |
+
border-radius: 50%;
|
| 166 |
+
background: rgba(255, 255, 255, 0.2);
|
| 167 |
+
transform: translate(-50%, -50%);
|
| 168 |
+
transition: width 0.6s, height 0.6s;
|
| 169 |
+
}
|
| 170 |
+
|
| 171 |
+
.wallet-form button:hover::before {
|
| 172 |
+
width: 300px;
|
| 173 |
+
height: 300px;
|
| 174 |
+
}
|
| 175 |
+
|
| 176 |
+
.wallet-form button:hover {
|
| 177 |
+
background: linear-gradient(90deg, #2563eb 80%, #818cf8 100%);
|
| 178 |
+
box-shadow: 0 4px 18px rgba(59, 130, 246, 0.2);
|
| 179 |
+
transform: translateY(-1px);
|
| 180 |
+
}
|
| 181 |
+
|
| 182 |
+
.wallet-form button:active {
|
| 183 |
+
transform: translateY(0) scale(0.98);
|
| 184 |
+
box-shadow: 0 2px 8px rgba(59, 130, 246, 0.15);
|
| 185 |
+
}
|
| 186 |
+
|
| 187 |
+
.wallet-form button:disabled {
|
| 188 |
+
opacity: 0.5;
|
| 189 |
+
cursor: not-allowed;
|
| 190 |
+
transform: none;
|
| 191 |
+
}
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
/* ============================================================================
|
| 195 |
+
WALLET PANEL ENHANCEMENTS
|
| 196 |
+
============================================================================ */
|
| 197 |
+
|
| 198 |
+
.wallet-panel h2 {
|
| 199 |
+
font-size: 1.6rem;
|
| 200 |
+
color: #fff;
|
| 201 |
+
font-weight: 700;
|
| 202 |
+
margin-bottom: 1.5rem;
|
| 203 |
+
letter-spacing: 0.02em;
|
| 204 |
+
background: linear-gradient(135deg, #fff 0%, #d1d5db 100%);
|
| 205 |
+
-webkit-background-clip: text;
|
| 206 |
+
-webkit-text-fill-color: transparent;
|
| 207 |
+
background-clip: text;
|
| 208 |
+
}
|
| 209 |
+
|
| 210 |
+
.wallet-balance {
|
| 211 |
+
position: relative;
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
.wallet-balance::after {
|
| 215 |
+
content: '';
|
| 216 |
+
position: absolute;
|
| 217 |
+
bottom: -5px;
|
| 218 |
+
left: 0;
|
| 219 |
+
right: 0;
|
| 220 |
+
height: 2px;
|
| 221 |
+
background: linear-gradient(90deg, transparent 0%, #22c55e 50%, transparent 100%);
|
| 222 |
+
opacity: 0.3;
|
| 223 |
+
}
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
/* ============================================================================
|
| 227 |
+
LOADING SPINNER FOR FORM SUBMISSIONS
|
| 228 |
+
============================================================================ */
|
| 229 |
+
|
| 230 |
+
.wallet-form button.loading {
|
| 231 |
+
pointer-events: none;
|
| 232 |
+
opacity: 0.8;
|
| 233 |
+
}
|
| 234 |
+
|
| 235 |
+
.wallet-form button.loading::after {
|
| 236 |
+
content: '';
|
| 237 |
+
position: absolute;
|
| 238 |
+
width: 16px;
|
| 239 |
+
height: 16px;
|
| 240 |
+
top: 50%;
|
| 241 |
+
left: 50%;
|
| 242 |
+
margin-left: -8px;
|
| 243 |
+
margin-top: -8px;
|
| 244 |
+
border: 2px solid #ffffff;
|
| 245 |
+
border-radius: 50%;
|
| 246 |
+
border-top-color: transparent;
|
| 247 |
+
animation: spinner 0.6s linear infinite;
|
| 248 |
+
}
|
| 249 |
+
|
| 250 |
+
@keyframes spinner {
|
| 251 |
+
to {
|
| 252 |
+
transform: rotate(360deg);
|
| 253 |
+
}
|
| 254 |
+
}
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
/* ============================================================================
|
| 258 |
+
RESPONSIVE ADJUSTMENTS
|
| 259 |
+
============================================================================ */
|
| 260 |
+
|
| 261 |
+
@media (max-width: 500px) {
|
| 262 |
+
.wallet-panel {
|
| 263 |
+
width: 100%;
|
| 264 |
+
border-radius: 0;
|
| 265 |
+
}
|
| 266 |
+
|
| 267 |
+
.wallet-panel-content {
|
| 268 |
+
padding: 2rem 1.5rem;
|
| 269 |
+
}
|
| 270 |
+
|
| 271 |
+
.wallet-form {
|
| 272 |
+
padding: 1rem;
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
.wallet-message {
|
| 276 |
+
font-size: 0.85rem;
|
| 277 |
+
padding: 0.9rem 1rem;
|
| 278 |
+
}
|
| 279 |
+
}
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
/* ============================================================================
|
| 283 |
+
TRANSACTION HISTORY (OPTIONAL ENHANCEMENT)
|
| 284 |
+
============================================================================ */
|
| 285 |
+
|
| 286 |
+
.wallet-transactions {
|
| 287 |
+
margin-top: 1.5rem;
|
| 288 |
+
}
|
| 289 |
+
|
| 290 |
+
.wallet-transactions h4 {
|
| 291 |
+
color: #06b6d4;
|
| 292 |
+
font-size: 0.9rem;
|
| 293 |
+
font-weight: 700;
|
| 294 |
+
margin-bottom: 0.8rem;
|
| 295 |
+
text-transform: uppercase;
|
| 296 |
+
letter-spacing: 0.05em;
|
| 297 |
+
}
|
| 298 |
+
|
| 299 |
+
.transaction-item {
|
| 300 |
+
display: flex;
|
| 301 |
+
justify-content: space-between;
|
| 302 |
+
align-items: center;
|
| 303 |
+
padding: 0.8rem 1rem;
|
| 304 |
+
background: #1a1f2e;
|
| 305 |
+
border: 1px solid #242a38;
|
| 306 |
+
border-radius: 6px;
|
| 307 |
+
margin-bottom: 0.5rem;
|
| 308 |
+
transition: all 0.2s ease;
|
| 309 |
+
}
|
| 310 |
+
|
| 311 |
+
.transaction-item:hover {
|
| 312 |
+
background: #202534;
|
| 313 |
+
border-color: #2a3040;
|
| 314 |
+
transform: translateX(4px);
|
| 315 |
+
}
|
| 316 |
+
|
| 317 |
+
.transaction-type {
|
| 318 |
+
font-size: 0.75rem;
|
| 319 |
+
font-weight: 700;
|
| 320 |
+
text-transform: uppercase;
|
| 321 |
+
letter-spacing: 0.05em;
|
| 322 |
+
}
|
| 323 |
+
|
| 324 |
+
.transaction-type.credit {
|
| 325 |
+
color: #22c55e;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
.transaction-type.debit {
|
| 329 |
+
color: #ef4444;
|
| 330 |
+
}
|
| 331 |
+
|
| 332 |
+
.transaction-amount {
|
| 333 |
+
font-weight: 700;
|
| 334 |
+
font-size: 0.95rem;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
.transaction-date {
|
| 338 |
+
font-size: 0.7rem;
|
| 339 |
+
color: #6b7280;
|
| 340 |
+
margin-top: 0.2rem;
|
| 341 |
+
}
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
/* ============================================================================
|
| 345 |
+
EMPTY STATE
|
| 346 |
+
============================================================================ */
|
| 347 |
+
|
| 348 |
+
.wallet-empty {
|
| 349 |
+
text-align: center;
|
| 350 |
+
padding: 2rem 1rem;
|
| 351 |
+
color: #6b7280;
|
| 352 |
+
}
|
| 353 |
+
|
| 354 |
+
.wallet-empty-icon {
|
| 355 |
+
font-size: 3rem;
|
| 356 |
+
margin-bottom: 1rem;
|
| 357 |
+
opacity: 0.4;
|
| 358 |
+
}
|
| 359 |
+
|
| 360 |
+
.wallet-empty p {
|
| 361 |
+
font-size: 0.85rem;
|
| 362 |
+
line-height: 1.5;
|
| 363 |
+
}
|
frontend/wallet.html
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!-- wallet.html: Simple wallet modal for add/withdraw money -->
|
| 2 |
+
<div id="walletModal" class="wallet-modal hidden">
|
| 3 |
+
<div class="wallet-modal-content">
|
| 4 |
+
<span class="wallet-close" onclick="closeWallet()">×</span>
|
| 5 |
+
<h2>Wallet</h2>
|
| 6 |
+
<div class="wallet-balance">
|
| 7 |
+
<span>Balance:</span>
|
| 8 |
+
<span id="walletBalance">₹0.00</span>
|
| 9 |
+
</div>
|
| 10 |
+
<div class="wallet-actions">
|
| 11 |
+
<button onclick="showAddMoney()">Add Money</button>
|
| 12 |
+
<button onclick="showWithdrawMoney()">Withdraw</button>
|
| 13 |
+
</div>
|
| 14 |
+
<div id="walletActionArea"></div>
|
| 15 |
+
</div>
|
| 16 |
+
</div>
|
| 17 |
+
|
| 18 |
+
<!-- Add Money Form (hidden by default) -->
|
| 19 |
+
<div id="addMoneyForm" class="wallet-form hidden">
|
| 20 |
+
<h3>Add Money</h3>
|
| 21 |
+
<input type="number" id="addAmount" placeholder="Enter amount" min="1" />
|
| 22 |
+
<button onclick="startRazorpayPayment()">Add via Razorpay</button>
|
| 23 |
+
</div>
|
| 24 |
+
|
| 25 |
+
<!-- Withdraw Money Form (hidden by default) -->
|
| 26 |
+
<div id="withdrawMoneyForm" class="wallet-form hidden">
|
| 27 |
+
<h3>Withdraw Money</h3>
|
| 28 |
+
<input type="number" id="withdrawAmount" placeholder="Enter amount" min="1" />
|
| 29 |
+
<button onclick="startWithdraw()">Withdraw</button>
|
| 30 |
+
</div>
|
| 31 |
+
|
| 32 |
+
<style>
|
| 33 |
+
.wallet-modal {
|
| 34 |
+
position: fixed;
|
| 35 |
+
top: 0; left: 0; right: 0; bottom: 0;
|
| 36 |
+
background: rgba(0,0,0,0.5);
|
| 37 |
+
display: flex;
|
| 38 |
+
align-items: center;
|
| 39 |
+
justify-content: center;
|
| 40 |
+
z-index: 9999;
|
| 41 |
+
}
|
| 42 |
+
.wallet-modal-content {
|
| 43 |
+
background: #181c24;
|
| 44 |
+
padding: 2rem 2.5rem;
|
| 45 |
+
border-radius: 12px;
|
| 46 |
+
min-width: 340px;
|
| 47 |
+
box-shadow: 0 8px 32px rgba(0,0,0,0.25);
|
| 48 |
+
position: relative;
|
| 49 |
+
}
|
| 50 |
+
.wallet-close {
|
| 51 |
+
position: absolute;
|
| 52 |
+
right: 1rem;
|
| 53 |
+
top: 1rem;
|
| 54 |
+
font-size: 1.5rem;
|
| 55 |
+
color: #aaa;
|
| 56 |
+
cursor: pointer;
|
| 57 |
+
}
|
| 58 |
+
.wallet-balance {
|
| 59 |
+
font-size: 1.2rem;
|
| 60 |
+
margin-bottom: 1.2rem;
|
| 61 |
+
display: flex;
|
| 62 |
+
justify-content: space-between;
|
| 63 |
+
}
|
| 64 |
+
.wallet-actions {
|
| 65 |
+
display: flex;
|
| 66 |
+
gap: 1rem;
|
| 67 |
+
margin-bottom: 1.2rem;
|
| 68 |
+
}
|
| 69 |
+
.wallet-form {
|
| 70 |
+
margin-top: 1rem;
|
| 71 |
+
}
|
| 72 |
+
.wallet-form input {
|
| 73 |
+
padding: 0.5rem 1rem;
|
| 74 |
+
border-radius: 6px;
|
| 75 |
+
border: 1px solid #242a38;
|
| 76 |
+
background: #23283a;
|
| 77 |
+
color: #fff;
|
| 78 |
+
margin-bottom: 0.7rem;
|
| 79 |
+
width: 100%;
|
| 80 |
+
}
|
| 81 |
+
.wallet-form button {
|
| 82 |
+
background: var(--green);
|
| 83 |
+
color: #000;
|
| 84 |
+
border: none;
|
| 85 |
+
border-radius: 6px;
|
| 86 |
+
padding: 0.5rem 1.2rem;
|
| 87 |
+
font-weight: 700;
|
| 88 |
+
cursor: pointer;
|
| 89 |
+
}
|
| 90 |
+
</style>
|