fix model mappings,dash updates, trading
This commit is contained in:
49
fix_dashboard_metrics.py
Normal file
49
fix_dashboard_metrics.py
Normal file
@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
Fix Dashboard Metrics Script
|
||||
|
||||
This script fixes the incomplete code in the update_metrics function
|
||||
of the web/clean_dashboard.py file.
|
||||
"""
|
||||
|
||||
import re
|
||||
import os
|
||||
|
||||
def fix_dashboard_metrics():
|
||||
"""Fix the incomplete code in the update_metrics function"""
|
||||
file_path = 'web/clean_dashboard.py'
|
||||
|
||||
# Read the file content
|
||||
with open(file_path, 'r', encoding='utf-8') as file:
|
||||
content = file.read()
|
||||
|
||||
# Find and replace the incomplete code
|
||||
pattern = r"# Add unrealized P&L from current position \(adjustable leverage\)\s+if self\.curr"
|
||||
replacement = """# Add unrealized P&L from current position (adjustable leverage)
|
||||
if self.current_position and current_price:
|
||||
side = self.current_position.get('side', 'UNKNOWN')
|
||||
size = self.current_position.get('size', 0)
|
||||
entry_price = self.current_position.get('price', 0)
|
||||
|
||||
if entry_price and size > 0:
|
||||
# Calculate unrealized P&L with current leverage
|
||||
if side.upper() == 'LONG' or side.upper() == 'BUY':
|
||||
raw_pnl_per_unit = current_price - entry_price
|
||||
else: # SHORT or SELL
|
||||
raw_pnl_per_unit = entry_price - current_price
|
||||
|
||||
# Apply current leverage to unrealized P&L
|
||||
leveraged_unrealized_pnl = raw_pnl_per_unit * size * self.current_leverage
|
||||
total_session_pnl += leveraged_unrealized_pnl"""
|
||||
|
||||
# Replace the pattern
|
||||
fixed_content = re.sub(pattern, replacement, content)
|
||||
|
||||
# Write the fixed content back to the file
|
||||
with open(file_path, 'w', encoding='utf-8') as file:
|
||||
file.write(fixed_content)
|
||||
|
||||
print(f"Fixed dashboard metrics in {file_path}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
fix_dashboard_metrics()
|
Reference in New Issue
Block a user