Repository navigation
Expand file tree
/
Copy pathchat.html
More file actions
310 lines (272 loc) Β· 12.3 KB
/
Copy pathchat.html
File metadata and controls
310 lines (272 loc) Β· 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AI Market Analyst Copilot | Virtual Stock</title>
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.5.1/css/all.min.css" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<style>
.chat-layout {
max-width: 1100px;
margin: 80px auto 20px;
padding: 0 1rem;
height: calc(100vh - 100px);
display: flex;
flex-direction: column;
gap: 1rem;
}
.chat-card {
background: var(--bg-card);
border: 1px solid var(--border-glass);
border-radius: var(--radius-lg);
flex: 1;
display: flex;
flex-direction: column;
overflow: hidden;
box-shadow: var(--shadow-lg);
backdrop-filter: var(--blur-glass);
}
.chat-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 1.2rem 1.8rem;
background: rgba(15, 23, 42, 0.6);
border-bottom: 1px solid var(--border-glass);
}
.chat-messages {
flex: 1;
padding: 1.5rem;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 1.2rem;
}
.message {
display: flex;
gap: 0.9rem;
max-width: 80%;
animation: fadeIn 0.3s ease;
}
@keyframes fadeIn {
from { opacity: 0; transform: translateY(10px); }
to { opacity: 1; transform: translateY(0); }
}
.message.user-message {
align-self: flex-end;
flex-direction: row-reverse;
}
.message-avatar {
width: 38px;
height: 38px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
font-size: 0.85rem;
flex-shrink: 0;
}
.bot-message .message-avatar {
background: var(--gradient-brand);
color: white;
box-shadow: var(--shadow-glow);
}
.user-message .message-avatar {
background: var(--accent-secondary);
color: #0b0f19;
}
.message-content {
background: rgba(255, 255, 255, 0.05);
border: 1px solid var(--border-glass);
padding: 1rem 1.2rem;
border-radius: var(--radius-md);
font-size: 0.95rem;
line-height: 1.5;
color: var(--text-primary);
}
.user-message .message-content {
background: var(--accent-primary);
color: white;
border-color: transparent;
}
.suggestion-chips {
display: flex;
gap: 0.6rem;
padding: 0.8rem 1.5rem;
overflow-x: auto;
border-top: 1px solid var(--border-glass);
background: rgba(15, 23, 42, 0.4);
}
.chip {
background: rgba(255, 255, 255, 0.06);
border: 1px solid var(--border-glass);
padding: 0.45rem 0.9rem;
border-radius: var(--radius-full);
font-size: 0.82rem;
color: var(--text-secondary);
white-space: nowrap;
cursor: pointer;
transition: var(--transition-smooth);
}
.chip:hover {
background: var(--accent-primary);
color: white;
border-color: var(--accent-primary);
}
.chat-input-area {
display: flex;
padding: 1rem 1.5rem;
gap: 0.8rem;
background: rgba(15, 23, 42, 0.6);
border-top: 1px solid var(--border-glass);
align-items: center;
}
.chat-input {
flex: 1;
background: rgba(255, 255, 255, 0.05);
border: 1px solid var(--border-glass);
padding: 0.8rem 1.2rem;
border-radius: var(--radius-full);
color: var(--text-primary);
font-size: 0.95rem;
outline: none;
}
.chat-input:focus {
border-color: var(--accent-primary);
box-shadow: var(--shadow-glow);
}
.typing-indicator {
display: none;
padding: 0.5rem 1.5rem;
font-size: 0.85rem;
color: var(--text-muted);
font-style: italic;
}
</style>
</head>
<body>
<!-- Top Navigation Header -->
<header>
<div class="logo" onclick="window.location.href='index.html'">
<i class="fa-solid fa-chart-line"></i>
<span>VirtualStock</span>
</div>
<nav class="nav-links">
<a href="index.html" class="nav-link"><i class="fa-solid fa-house"></i> Markets</a>
<a href="profit_loss.html" class="nav-link"><i class="fa-solid fa-wallet"></i> Portfolio & P/L</a>
<a href="chat.html" class="nav-link active"><i class="fa-solid fa-robot"></i> AI Analyst</a>
</nav>
<div class="header-actions">
<a href="index.html" class="btn-primary">
<i class="fa-solid fa-bolt"></i> Trade Stocks
</a>
</div>
</header>
<div class="chat-layout">
<div class="chat-card">
<div class="chat-header">
<div style="display:flex; align-items:center; gap:0.8rem;">
<div class="bot-status">
<div class="status-indicator"></div>
<span style="font-weight:700; color:var(--text-primary);">StockBot Pro Copilot</span>
</div>
</div>
<button class="btn-secondary" style="padding:0.35rem 0.8rem; font-size:0.8rem;" onclick="clearChat()">
<i class="fa-solid fa-broom"></i> Clear
</button>
</div>
<div class="chat-messages" id="chatContainer">
<div class="message bot-message">
<div class="message-avatar">AI</div>
<div class="message-content">
π Welcome to <strong>VirtualStock AI Assistant</strong>! I can help you analyze chart patterns, calculate risk/reward ratios, explain complex market concepts, or give insights on stocks like RELIANCE, TCS, AAPL, and NVDA. How can I help you trade smarter today?
</div>
</div>
</div>
<div class="typing-indicator" id="typingIndicator">
<i class="fa-solid fa-circle-notch fa-spin"></i> StockBot is analyzing market data...
</div>
<div class="suggestion-chips">
<div class="chip" onclick="sendQuickPrompt('What is a Stop-Loss and how should I set it?')">π‘οΈ What is Stop-Loss?</div>
<div class="chip" onclick="sendQuickPrompt('Analyze RELIANCE stock trends')">π Analyze RELIANCE</div>
<div class="chip" onclick="sendQuickPrompt('Explain Bull vs Bear Market')">π Bull vs Bear Market</div>
<div class="chip" onclick="sendQuickPrompt('How is P&L calculated in stock trading?')">π° How is P&L calculated?</div>
<div class="chip" onclick="sendQuickPrompt('Best risk management rules for beginners')">π― Risk Management Tips</div>
</div>
<div class="chat-input-area">
<input type="text" class="chat-input" id="messageInput" placeholder="Ask about stocks, indicators, or trading strategies..." onkeypress="handleKeyPress(event)">
<button class="btn-primary" onclick="handleSend()" style="padding:0.75rem 1.4rem;">
<i class="fa-solid fa-paper-plane"></i>
</button>
</div>
</div>
</div>
<script>
const chatContainer = document.getElementById('chatContainer');
const messageInput = document.getElementById('messageInput');
const typingIndicator = document.getElementById('typingIndicator');
const KNOWLEDGE_BASE = {
'stop-loss': "A **Stop-Loss order** limits potential loss by automatically selling a stock once it reaches a predefined trigger price. For example, if you buy RELIANCE at βΉ2,980, setting a stop-loss at βΉ2,900 prevents losses greater than ~2.7%. Standard recommendation is risking no more than 1-2% of total portfolio on any single trade.",
'reliance': "π **RELIANCE (Reliance Industries Ltd.) Analysis**:\n- Current Price: ~βΉ2,980.50\n- Trend: Bullish above 50-day moving average.\n- Key Support: βΉ2,920 | Resistance: βΉ3,050\n- Strategy: Buy on dips near support with a trailing stop-loss.",
'tcs': "π **TCS (Tata Consultancy Services) Analysis**:\n- Current Price: ~βΉ4,250.40\n- Trend: Steady consolidation near all-time highs.\n- Key Support: βΉ4,180 | Resistance: βΉ4,350\n- Strategy: Long-term value accumulator.",
'bull': "π **Bull vs Bear Market**:\n- **Bull Market**: Optimistic market condition characterized by sustained upward price trends, strong investor confidence, and economic growth.\n- **Bear Market**: Downtrend where prices drop 20% or more from recent peaks, driven by negative sentiment and selling pressure.",
'p&l': "π° **P&L (Profit & Loss) Calculation**:\n- **Unrealized P&L**: (Current Market Price - Avg Purchase Price) Γ Quantity Held.\n- **Realized P&L**: (Selling Execution Price - Avg Purchase Price) Γ Quantity Sold.\n- **ROI %**: (Total P&L / Total Invested Capital) Γ 100.",
'risk': "π― **Top Risk Management Rules for Beginners**:\n1. Never risk more than 1-2% of your capital on a single trade.\n2. Always define your stop-loss *before* entering an order.\n3. Maintain a Risk-to-Reward ratio of at least 1:2.\n4. Avoid emotional revenge-trading after a loss.\n5. Diversify across sectors (Tech, Banking, Energy, Pharma)."
};
function addMessage(content, isUser = false) {
const msgDiv = document.createElement('div');
msgDiv.className = `message ${isUser ? 'user-message' : 'bot-message'}`;
msgDiv.innerHTML = `
<div class="message-avatar">${isUser ? 'YOU' : 'AI'}</div>
<div class="message-content">${formatMarkdown(content)}</div>
`;
chatContainer.appendChild(msgDiv);
chatContainer.scrollTop = chatContainer.scrollHeight;
}
function formatMarkdown(text) {
return text
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
.replace(/\n/g, '<br>');
}
function handleSend() {
const query = messageInput.value.trim();
if (!query) return;
addMessage(query, true);
messageInput.value = '';
processBotResponse(query);
}
function handleKeyPress(e) {
if (e.key === 'Enter') handleSend();
}
function sendQuickPrompt(promptText) {
messageInput.value = promptText;
handleSend();
}
function processBotResponse(query) {
typingIndicator.style.display = 'block';
chatContainer.scrollTop = chatContainer.scrollHeight;
setTimeout(() => {
typingIndicator.style.display = 'none';
const lower = query.toLowerCase();
let answer = null;
for (const key in KNOWLEDGE_BASE) {
if (lower.includes(key)) {
answer = KNOWLEDGE_BASE[key];
break;
}
}
if (!answer) {
answer = `Based on current market parameters for "${query}", volatility is moderate. Always verify support/resistance levels and maintain a strict stop-loss before executing orders on the VirtualStock platform.`;
}
addMessage(answer, false);
}, 800);
}
function clearChat() {
chatContainer.innerHTML = '';
addMessage("π Chat history cleared. Ask me any question about stocks, trades, or portfolio strategy!", false);
}
</script>
</body>
</html>