Spaces:
Running
Running
Download components/volatility-comparison.js from Fraqim/volatilitybot-pro: direct link, hf CLI and curl.
- Browser
- Download file 9.2 kB
-
https://huggingface.co/spaces/Fraqim/volatilitybot-pro/resolve/main/components/volatility-comparison.js
- Command line
-
hf download hf://spaces/Fraqim/volatilitybot-pro/components/volatility-comparison.js
-
curl -L -o volatility-comparison.js https://huggingface.co/spaces/Fraqim/volatilitybot-pro/resolve/main/components/volatility-comparison.js
9.2 kB
| class CustomVolatilityComparison extends HTMLElement { | |
| constructor() { | |
| super(); | |
| this.attachShadow({ mode: 'open' }); | |
| this.indices = [ | |
| { name: 'V10', value: 12.5, change: 2.3, volume: 45200 }, | |
| { name: 'V25', value: 28.3, change: -1.5, volume: 38700 }, | |
| { name: 'V50', value: 52.1, change: 5.7, volume: 52300 }, | |
| { name: 'V75', value: 75.8, change: 8.2, volume: 61200 }, | |
| { name: 'V100', value: 98.4, change: -3.1, volume: 48900 } | |
| ]; | |
| } | |
| connectedCallback() { | |
| this.render(); | |
| this.startSimulation(); | |
| } | |
| render() { | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| :host { | |
| display: block; | |
| } | |
| .panel { | |
| background: rgba(30, 41, 59, 0.6); | |
| backdrop-filter: blur(12px); | |
| border: 1px solid rgba(255, 255, 255, 0.05); | |
| border-radius: 1rem; | |
| padding: 1.25rem; | |
| } | |
| .header { | |
| display: flex; | |
| align-items: center; | |
| justify-content: space-between; | |
| margin-bottom: 1rem; | |
| } | |
| .title { | |
| font-weight: 700; | |
| color: white; | |
| display: flex; | |
| align-items: center; | |
| gap: 0.5rem; | |
| font-size: 0.95rem; | |
| } | |
| .index-list { | |
| display: flex; | |
| flex-direction: column; | |
| gap: 0.5rem; | |
| } | |
| .index-item { | |
| display: grid; | |
| grid-template-columns: 50px 1fr auto auto; | |
| align-items: center; | |
| gap: 1rem; | |
| padding: 0.75rem; | |
| background: rgba(15, 23, 42, 0.5); | |
| border-radius: 0.5rem; | |
| transition: all 0.2s; | |
| cursor: pointer; | |
| } | |
| .index-item:hover { | |
| background: rgba(99, 102, 241, 0.1); | |
| transform: translateX(4px); | |
| } | |
| .index-name { | |
| font-weight: 600; | |
| color: white; | |
| font-size: 0.875rem; | |
| } | |
| .volatility-bar-container { | |
| position: relative; | |
| height: 6px; | |
| background: rgba(255, 255, 255, 0.05); | |
| border-radius: 3px; | |
| overflow: hidden; | |
| } | |
| .volatility-bar { | |
| height: 100%; | |
| border-radius: 3px; | |
| transition: width 0.5s ease; | |
| } | |
| .volatility-bar.v10 { background: linear-gradient(90deg, #10b981, #34d399); } | |
| .volatility-bar.v25 { background: linear-gradient(90deg, #3b82f6, #60a5fa); } | |
| .volatility-bar.v50 { background: linear-gradient(90deg, #f59e0b, #fbbf24); } | |
| .volatility-bar.v75 { background: linear-gradient(90deg, #f43f5e, #fb7185); } | |
| .volatility-bar.v100 { background: linear-gradient(90deg, #8b5cf6, #a78bfa); } | |
| .index-value { | |
| font-weight: 700; | |
| color: white; | |
| font-size: 0.875rem; | |
| font-variant-numeric: tabular-nums; | |
| min-width: 50px; | |
| text-align: right; | |
| } | |
| .index-change { | |
| font-size: 0.75rem; | |
| font-weight: 600; | |
| padding: 0.25rem 0.5rem; | |
| border-radius: 0.25rem; | |
| min-width: 60px; | |
| text-align: center; | |
| } | |
| .change-positive { | |
| background: rgba(16, 185, 129, 0.15); | |
| color: #10b981; | |
| } | |
| .change-negative { | |
| background: rgba(244, 63, 94, 0.15); | |
| color: #f43f5e; | |
| } | |
| .sparkline { | |
| width: 60px; | |
| height: 24px; | |
| } | |
| .volume-indicator { | |
| display: flex; | |
| align-items: center; | |
| gap: 0.25rem; | |
| font-size: 0.65rem; | |
| color: #64748b; | |
| margin-top: 0.25rem; | |
| } | |
| .recommendation { | |
| margin-top: 1rem; | |
| padding: 0.75rem; | |
| background: rgba(16, 185, 129, 0.1); | |
| border: 1px solid rgba(16, 185, 129, 0.2); | |
| border-radius: 0.5rem; | |
| } | |
| .recommendation-title { | |
| font-size: 0.75rem; | |
| font-weight: 600; | |
| color: #10b981; | |
| margin-bottom: 0.25rem; | |
| } | |
| .recommendation-text { | |
| font-size: 0.75rem; | |
| color: #94a3b8; | |
| } | |
| </style> | |
| <div class="panel"> | |
| <div class="header"> | |
| <div class="title"> | |
| <svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" class="text-primary-400"> | |
| <line x1="18" y1="20" x2="18" y2="10"></line> | |
| <line x1="12" y1="20" x2="12" y2="4"></line> | |
| <line x1="6" y1="20" x2="6" y2="14"></line> | |
| </svg> | |
| Index Comparison | |
| </div> | |
| <span style="font-size: 0.75rem; color: #64748b;">Live</span> | |
| </div> | |
| <div class="index-list" id="index-list"> | |
| ${this.indices.map(idx => this.renderIndexItem(idx)).join('')} | |
| </div> | |
| <div class="recommendation"> | |
| <div class="recommendation-title">Trading Recommendation</div> | |
| <div class="recommendation-text" id="recommendation-text"> | |
| V75 shows strong momentum with rising volatility. Consider trend-following strategies. | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| } | |
| renderIndexItem(idx) { | |
| const changeClass = idx.change >= 0 ? 'change-positive' : 'change-negative'; | |
| const changeSign = idx.change >= 0 ? '+' : ''; | |
| const barClass = idx.name.toLowerCase(); | |
| const barWidth = Math.min(100, (idx.value / 120) * 100); | |
| return ` | |
| <div class="index-item" data-index="${idx.name}"> | |
| <span class="index-name">${idx.name}</span> | |
| <div> | |
| <div class="volatility-bar-container"> | |
| <div class="volatility-bar ${barClass}" style="width: ${barWidth}%;"></div> | |
| </div> | |
| <div class="volume-indicator"> | |
| <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"> | |
| <polyline points="22 12 18 12 15 21 9 3 6 12 2 12"></polyline> | |
| </svg> | |
| Vol: ${(idx.volume / 1000).toFixed(1)}K | |
| </div> | |
| </div> | |
| <span class="index-value">${idx.value.toFixed(1)}</span> | |
| <span class="index-change ${changeClass}">${changeSign}${idx.change.toFixed(1)}%</span> | |
| </div> | |
| `; | |
| } | |
| startSimulation() { | |
| setInterval(() => { | |
| this.indices.forEach(idx => { | |
| // Simulate small changes | |
| const change = (Math.random() - 0.5) * 2; | |
| idx.value = Math.max(5, idx.value + change); | |
| idx.change += (Math.random() - 0.5) * 0.5; | |
| idx.volume += Math.floor((Math.random() - 0.5) * 1000); | |
| }); | |
| this.updateDisplay(); | |
| }, 3000); | |
| } | |
| updateDisplay() { | |
| const list = this.shadowRoot.getElementById('index-list'); | |
| if (list) { | |
| list.innerHTML = this.indices.map(idx => this.renderIndexItem(idx)).join(''); | |
| } | |
| // Update recommendation based on highest volatility change | |
| const hottest = this.indices.reduce((a, b) => Math.abs(a.change) > Math.abs(b.change) ? a : b); | |
| const recText = this.shadowRoot.getElementById('recommendation-text'); | |
| if (recText) { | |
| const direction = hottest.change > 0 ? 'rising' : 'falling'; | |
| recText.textContent = `${hottest.name} shows ${direction} volatility momentum. ${hottest.change > 5 ? 'Consider momentum strategies.' : 'Suitable for range trading.'}`; | |
| } | |
| } | |
| } | |
| customElements.define('custom-volatility-comparison', CustomVolatilityComparison); |