Update app.py
Browse files
app.py
CHANGED
|
@@ -290,7 +290,83 @@ async def dashboard(request: Request):
|
|
| 290 |
error_msg = f"Failed to connect to cTrader: {e}"
|
| 291 |
logger.error(error_msg)
|
| 292 |
|
| 293 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 294 |
html_content = f"""
|
| 295 |
<!DOCTYPE html>
|
| 296 |
<html>
|
|
@@ -397,55 +473,18 @@ async def dashboard(request: Request):
|
|
| 397 |
<p style="margin: 5px 0 0 0; color: #64748b;">Hugging Face Cloud Server ({CTRADER_ENV} environment)</p>
|
| 398 |
</div>
|
| 399 |
<div>
|
| 400 |
-
{
|
| 401 |
</div>
|
| 402 |
</div>
|
| 403 |
|
| 404 |
-
{
|
| 405 |
|
| 406 |
-
{
|
| 407 |
-
<div class="card" style="text-align: center; padding: 40px;">
|
| 408 |
-
<h2>Authentication Required</h2>
|
| 409 |
-
<p style="color: #94a3b8; margin-bottom: 24px;">Please connect your cTrader account to authorize the bot to execute trades on your behalf.</p>
|
| 410 |
-
<a href="/login" class="btn">Authorize Bot with cTrader</a>
|
| 411 |
-
</div>
|
| 412 |
-
''' or f'''
|
| 413 |
-
<div class="grid">
|
| 414 |
-
<div class="card">
|
| 415 |
-
<h3>Account ID</h3>
|
| 416 |
-
<div class="value">{account_id}</div>
|
| 417 |
-
</div>
|
| 418 |
-
<div class="card">
|
| 419 |
-
<h3>Current Balance</h3>
|
| 420 |
-
<div class="value">{balance}</div>
|
| 421 |
-
</div>
|
| 422 |
-
</div>
|
| 423 |
-
|
| 424 |
-
<div class="card" style="margin-bottom: 30px;">
|
| 425 |
-
<h3>Active Open Positions</h3>
|
| 426 |
-
{positions and f"""
|
| 427 |
-
<table>
|
| 428 |
-
<thead>
|
| 429 |
-
<tr>
|
| 430 |
-
<th>Position ID</th>
|
| 431 |
-
<th>Symbol ID</th>
|
| 432 |
-
<th>Side</th>
|
| 433 |
-
<th>Volume</th>
|
| 434 |
-
<th>Entry Price</th>
|
| 435 |
-
</tr>
|
| 436 |
-
</thead>
|
| 437 |
-
<tbody>
|
| 438 |
-
{"".join(f"<tr><td>{p['id']}</td><td>{p['symbol_id']}</td><td style='color: {'#34d399' if p['side']=='BUY' else '#f87171'}'>{p['side']}</td><td>{p['volume']}</td><td>{p['entry_price']}</td></tr>" for p in positions)}
|
| 439 |
-
</tbody>
|
| 440 |
-
</table>
|
| 441 |
-
""" or '<p style="color: #64748b; margin: 10px 0 0 0;">No active positions found.</p>'}
|
| 442 |
-
</div>
|
| 443 |
-
'''}
|
| 444 |
|
| 445 |
<div class="card">
|
| 446 |
<h3>Webhook Signal History</h3>
|
| 447 |
<div class="log-feed">
|
| 448 |
-
{
|
| 449 |
</div>
|
| 450 |
</div>
|
| 451 |
</div>
|
|
|
|
| 290 |
error_msg = f"Failed to connect to cTrader: {e}"
|
| 291 |
logger.error(error_msg)
|
| 292 |
|
| 293 |
+
# 1. Construct positions table HTML (avoiding nested f-strings)
|
| 294 |
+
positions_html = ""
|
| 295 |
+
if positions:
|
| 296 |
+
rows = "".join(
|
| 297 |
+
f"<tr><td>{p['id']}</td><td>{p['symbol_id']}</td>"
|
| 298 |
+
f"<td style='color: {'#34d399' if p['side']=='BUY' else '#f87171'}'>{p['side']}</td>"
|
| 299 |
+
f"<td>{p['volume']}</td><td>{p['entry_price']}</td></tr>"
|
| 300 |
+
for p in positions
|
| 301 |
+
)
|
| 302 |
+
positions_html = f"""
|
| 303 |
+
<table>
|
| 304 |
+
<thead>
|
| 305 |
+
<tr>
|
| 306 |
+
<th>Position ID</th>
|
| 307 |
+
<th>Symbol ID</th>
|
| 308 |
+
<th>Side</th>
|
| 309 |
+
<th>Volume</th>
|
| 310 |
+
<th>Entry Price</th>
|
| 311 |
+
</tr>
|
| 312 |
+
</thead>
|
| 313 |
+
<tbody>
|
| 314 |
+
{rows}
|
| 315 |
+
</tbody>
|
| 316 |
+
</table>
|
| 317 |
+
"""
|
| 318 |
+
else:
|
| 319 |
+
positions_html = '<p style="color: #64748b; margin: 10px 0 0 0;">No active positions found.</p>'
|
| 320 |
+
|
| 321 |
+
# 2. Construct OAuth status card HTML
|
| 322 |
+
auth_card_html = ""
|
| 323 |
+
if not is_authenticated:
|
| 324 |
+
auth_card_html = f"""
|
| 325 |
+
<div class="card" style="text-align: center; padding: 40px;">
|
| 326 |
+
<h2>Authentication Required</h2>
|
| 327 |
+
<p style="color: #94a3b8; margin-bottom: 24px;">Please connect your cTrader account to authorize the bot to execute trades on your behalf.</p>
|
| 328 |
+
<a href="/login" class="btn">Authorize Bot with cTrader</a>
|
| 329 |
+
</div>
|
| 330 |
+
"""
|
| 331 |
+
else:
|
| 332 |
+
auth_card_html = f"""
|
| 333 |
+
<div class="grid">
|
| 334 |
+
<div class="card">
|
| 335 |
+
<h3>Account ID</h3>
|
| 336 |
+
<div class="value">{account_id}</div>
|
| 337 |
+
</div>
|
| 338 |
+
<div class="card">
|
| 339 |
+
<h3>Current Balance</h3>
|
| 340 |
+
<div class="value">{balance}</div>
|
| 341 |
+
</div>
|
| 342 |
+
</div>
|
| 343 |
+
|
| 344 |
+
<div class="card" style="margin-bottom: 30px;">
|
| 345 |
+
<h3>Active Open Positions</h3>
|
| 346 |
+
{positions_html}
|
| 347 |
+
</div>
|
| 348 |
+
"""
|
| 349 |
+
|
| 350 |
+
# 3. Construct signal logs history HTML
|
| 351 |
+
logs_html = ""
|
| 352 |
+
if WEBHOOK_LOGS:
|
| 353 |
+
logs_html = "".join(
|
| 354 |
+
f'<div class="log-item"><span class="log-time">[{l["time"]}]</span> '
|
| 355 |
+
f'<span class="log-action" style="color: {l["color"]}">{l["action"]}</span> {l["msg"]}</div>'
|
| 356 |
+
for l in reversed(WEBHOOK_LOGS)
|
| 357 |
+
)
|
| 358 |
+
else:
|
| 359 |
+
logs_html = '<div style="color: #64748b;">Waiting for signals from TradingView...</div>'
|
| 360 |
+
|
| 361 |
+
status_badge_html = (
|
| 362 |
+
'<span class="status-badge status-connected">✓ Connected</span>'
|
| 363 |
+
if is_authenticated
|
| 364 |
+
else '<span class="status-badge status-disconnected">✗ Disconnected</span>'
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
error_banner_html = f'<div class="alert-danger">{error_msg}</div>' if error_msg else ''
|
| 368 |
+
|
| 369 |
+
# Main HTML Dashboard String
|
| 370 |
html_content = f"""
|
| 371 |
<!DOCTYPE html>
|
| 372 |
<html>
|
|
|
|
| 473 |
<p style="margin: 5px 0 0 0; color: #64748b;">Hugging Face Cloud Server ({CTRADER_ENV} environment)</p>
|
| 474 |
</div>
|
| 475 |
<div>
|
| 476 |
+
{status_badge_html}
|
| 477 |
</div>
|
| 478 |
</div>
|
| 479 |
|
| 480 |
+
{error_banner_html}
|
| 481 |
|
| 482 |
+
{auth_card_html}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 483 |
|
| 484 |
<div class="card">
|
| 485 |
<h3>Webhook Signal History</h3>
|
| 486 |
<div class="log-feed">
|
| 487 |
+
{logs_html}
|
| 488 |
</div>
|
| 489 |
</div>
|
| 490 |
</div>
|