favor i need a favor pleaseeeeee can u pleaseeee just fix the spacing and write back every word of the code for me please # hft_dashboard.py
from PyQt6.QtWidgets import (QMainWindow, QWidget, QVBoxLayout, QHBoxLayout, 
                            QLabel, QPushButton, QTabWidget, QDoubleSpinBox,
                            QTextEdit, QProgressBar, QGridLayout, QFrame)
from PyQt6.QtCore import Qt, pyqtSignal, QTimer
import pyqtgraph as pg
import numpy as np
from dataclasses import dataclass
from typing import Dict
import time

@dataclass
class TradingParams:
    take_profit: float = 1.2
    stop_loss: float = 0.6
    position_size: float = 0.01
    neural_threshold: float = 0.85
    priority_fee: int = 25000
    slippage: float = 0.4

class QuantumDashboard(QMainWindow):
    # Signals
    trade_signal = pyqtSignal(str, str, float)  # token, side, size
    param_updated = pyqtSignal(str, float)
    
    def __init__(self):
        super().__init__()
        self.params = TradingParams()
        self.price_history = {}
        self.volume_history = {}
        
        self.setup_ui()
        self.setup_timers()

    def setup_ui(self):
        self.setWindowTitle("🧠 Quantum Trading Matrix")
        self.setStyleSheet("""
            QMainWindow, QWidget {
                background-color: #0a0a12;
                color: #00ff41;
            }
            QTabWidget::pane {
                border: 1px solid #2a2a3a;
                background-color: #0a0a12;
            }
            QTabBar::tab {
                background-color: #1a1a2a;
                color: #00ff41;
                padding: 8px 20px;
                border-top-left-radius: 4px;
                border-top-right-radius: 4px;
            }
            QTabBar::tab:selected {
                background-color: #2a2a3a;
            }
            QLabel {
                color: #00ff41;
                font-size: 14px;
            }
            QPushButton {
                background-color: #1a1a2a;
                color: #00ff41;
                border: 1px solid #00ff41;
                border-radius: 4px;
                padding: 8px 16px;
                font-weight: bold;
            }
            QPushButton:hover {
                background-color: #00ff41;
                color: #0a0a12;
            }
            QProgressBar {
                border: 2px solid #00ff41;
                border-radius: 5px;
                text-align: center;
            }
            QProgressBar::chunk {
                background-color: #00ff41;
            }
        """)
        
        # Create central widget
        central_widget = QWidget()
        self.setCentralWidget(central_widget)
        main_layout = QVBoxLayout(central_widget)
        
        # Create tabs
        tabs = QTabWidget()
        main_layout.addWidget(tabs)
        
        # Trading tab
        trading_tab = QWidget()
        trading_layout = QVBoxLayout(trading_tab)
        
        # Status panel
        status_panel = self.create_status_panel()
        trading_layout.addWidget(status_panel)
        
        # Charts
        charts_panel = self.create_charts_panel()
        trading_layout.addWidget(charts_panel)
        
        # Controls
        controls_panel = self.create_controls_panel()
        trading_layout.addWidget(controls_panel)
        
        tabs.addTab(trading_tab, "🚀 Trading")
        
        # Parameters tab
        params_tab = self.create_parameters_tab()
        tabs.addTab(params_tab, "⚙️ Parameters")
        
        # Neural tab
        neural_tab = self.create_neural_tab()
        tabs.addTab(neural_tab, "🧠 Neural")
        
        # Status bar for notifications
        self.statusBar().setStyleSheet("color: #00ff41;")

    def create_status_panel(self) -> QFrame:
        panel = QFrame()
        panel.setFrameStyle(QFrame.Shape.Box)
        layout = QGridLayout(panel)
        
        # GPU Status
        self.gpu_status = QProgressBar()
        layout.addWidget(QLabel("GPU Usage"), 0, 0)
        layout.addWidget(self.gpu_status, 0, 1)
        
        # Neural Confidence
        self.confidence_bar = QProgressBar()
        layout.addWidget(QLabel("Neural Confidence"), 1, 0)
        layout.addWidget(self.confidence_bar, 1, 1)
        
        # Current Price
        self.price_label = QLabel("Price: $0.00")
        layout.addWidget(self.price_label, 2, 0, 1, 2)
        
        return panel

    def create_charts_panel(self) -> QFrame:
        panel = QFrame()
        panel.setFrameStyle(QFrame.Shape.Box)
        layout = QGridLayout(panel)
        
        # Price chart
        self.price_plot = pg.PlotWidget(title="Price")
        self.price_plot.setBackground('#1a1a2a')
        self.price_curve = self.price_plot.plot(pen=pg.mkPen('#00ff41', width=2))
        layout.addWidget(self.price_plot, 0, 0)
        
        # Volume chart
        self.volume_plot = pg.PlotWidget(title="Volume")
        self.volume_plot.setBackground('#1a1a2a')
        self.volume_curve = self.volume_plot.plot(pen=pg.mkPen('#4169e1', width=2))
        layout.addWidget(self.volume_plot, 0, 1)
        
        return panel

    def create_controls_panel(self) -> QFrame:
        panel = QFrame()
        panel.setFrameStyle(QFrame.Shape.Box)
        layout = QHBoxLayout(panel)
        
        self.neural_btn = QPushButton("🧠 Neural Trading")
        self.neural_btn.setCheckable(True)
        self.neural_btn.toggled.connect(self.toggle_neural_trading)
        layout.addWidget(self.neural_btn)
        
        buy_btn = QPushButton("🚀 BUY")
        buy_btn.clicked.connect(lambda: self.trade_signal.emit("", "buy", self.params.position_size))
        layout.addWidget(buy_btn)
        
        sell_btn = QPushButton("💰 SELL")
        sell_btn.clicked.connect(lambda: self.trade_signal.emit("", "sell", self.params.position_size))
        layout.addWidget(sell_btn)
        
        return panel

    def create_parameters_tab(self) -> QWidget:
        tab = QWidget()
        layout = QGridLayout(tab)
        
        params = [
            ("Take Profit %", "take_profit", 0, 10),
            ("Stop Loss %", "stop_loss", 0, 5),
            ("Position Size", "position_size", 0.001, 1.0),
            ("Neural Threshold", "neural_threshold", 0.5, 1.0),
            ("Priority Fee", "priority_fee", 1000, 50000),
            ("Slippage %", "slippage", 0.1, 2.0)
        ]
        
        for i, (label, attr, min_val, max_val) in enumerate(params):
            layout.addWidget(QLabel(label), i, 0)
            spinner = QDoubleSpinBox()
            spinner.setRange(min_val, max_val)
            spinner.setValue(getattr(self.params, attr))
            spinner.valueChanged.connect(lambda v, a=attr: self.param_updated.emit(a, v))
            layout.addWidget(spinner, i, 1)
        
        return tab

    def create_neural_tab(self) -> QWidget:
        tab = QWidget()
        layout = QVBoxLayout(tab)
        
        # Neural stats
        stats_frame = QFrame()
        stats_layout = QGridLayout(stats_frame)
        
        self.neural_stats = {
            "Prediction Time": QLabel("0 ms"),
            "Model Accuracy": QLabel("0%"),
            "GPU Memory": QLabel("0 MB"),
            "Learning Rate": QLabel("0.001")
        }
        
        for i, (label, widget) in enumerate(self.neural_stats.items()):
            stats_layout.addWidget(QLabel(label), i, 0)
            stats_layout.addWidget(widget, i, 1)
        
        layout.addWidget(stats_frame)
        
        # Neural insights
        self.neural_text = QTextEdit()
        self.neural_text.setReadOnly(True)
        layout.addWidget(self.neural_text)
        
        return tab

    def setup_timers(self):
        self.update_timer = QTimer()
        self.update_timer.timeout.connect(self.update_display)
        self.update_timer.start(1000)

    def update_display(self):
        """Update real-time displays"""
        # Update charts if we have data
        if self.price_history:
            for token in self.price_history:
                if self.price_history[token]:
                    self.price_curve.setData(y=np.array(self.price_history[token]))
                    if token in self.volume_history and self.volume_history[token]:
                        self.volume_curve.setData(y=np.array(self.volume_history[token]))
    
    def update_market_data(self, data: 'MarketData'):
        """Update market data displays"""
        try:
        # Access the price attribute directly from MarketData object
        price = data.current_price  # or data.price depending on your MarketData class structure
        token = "SOL"  # Default token
        
        # Initialize price history if needed
        if token not in self.price_history:
            self.price_history[token] = []
        
        # Update price history with the float price
        self.price_history[token].append(float(price))
    
        # Keep history at reasonable size
        max_history = 100
        if len(self.price_history[token]) > max_history:
            self.price_history[token] = self.price_history[token][-max_history:]
    
        # Update price label
        formatted_price = f"{price:.6f}" if price < 1 else f"{price:.2f}"
        self.price_label.setText(f"Price: ${formatted_price}")
    
        # Update charts
        if self.price_history[token]:
            self.price_curve.setData(y=np.array(self.price_history[token]))
            
    except Exception as e:
        self.show_notification(f"Update error: {str(e)}", "error")
        import traceback
        print("Market data update error:", traceback.format_exc())

    def update_neural_status(self, confidence: float, insights: str):
        """Update neural network status"""
        self.confidence_bar.setValue(int(confidence * 100))
        self.neural_text.setText(insights)

    def update_gpu_metrics(self, utilization: float, memory_used: float):
        """Update GPU metrics"""
        self.gpu_status.setValue(int(utilization))
        self.neural_stats["GPU Memory"].setText(f"{memory_used:.2f} GB")

    def toggle_neural_trading(self, enabled: bool):
        """Toggle neural trading mode"""
        self.neural_btn.setStyleSheet(
            "background-color: #00ff41; color: #0a0a12;" if enabled 
            else "background-color: #1a1a2a; color: #00ff41;"
        )
        self.show_notification(
            f"Neural Trading {'Activated' if enabled else 'Deactivated'}", 
            "info"
        )

    def show_notification(self, message: str, level: str = "info"):
        """Show notification in status bar"""
        colors = {
            "info": "#00ff41",
            "warning": "#ffff00",
            "error": "#ff0000",
            "success": "#00ff41"
        }
        self.statusBar().setStyleSheet(f"color: {colors.get(level, '#00ff41')};")
        self.statusBar().showMessage(message)

if __name__ == "__main__":
    import sys
    from PyQt6.QtWidgets import QApplication
    
    app = QApplication(sys.argv)
    window = QuantumDashboard()
    window.resize(1200, 800)
    window.show()
    sys.exit(app.exec())