add decision fusion. training but not enabled.
reports cleanup
This commit is contained in:
@ -818,6 +818,9 @@ class CleanTradingDashboard:
|
||||
entry_price = self.current_position.get('price', 0)
|
||||
|
||||
if entry_price and size > 0:
|
||||
# Calculate position size in USD
|
||||
position_size_usd = size * entry_price
|
||||
|
||||
# Calculate unrealized P&L with current leverage
|
||||
if side.upper() == 'LONG' or side.upper() == 'BUY':
|
||||
raw_pnl_per_unit = current_price - entry_price
|
||||
@ -832,7 +835,13 @@ class CleanTradingDashboard:
|
||||
else:
|
||||
# Apply leverage locally
|
||||
leveraged_unrealized_pnl = raw_pnl_per_unit * size * self.current_leverage
|
||||
total_session_pnl += leveraged_unrealized_pnl
|
||||
|
||||
# Calculate trading fees (opening + closing)
|
||||
trading_fees = self._calculate_trading_fees(position_size_usd, current_price, size)
|
||||
|
||||
# Subtract fees from unrealized P&L
|
||||
net_unrealized_pnl = leveraged_unrealized_pnl - trading_fees
|
||||
total_session_pnl += net_unrealized_pnl
|
||||
|
||||
session_pnl_str = f"${total_session_pnl:.2f}"
|
||||
session_pnl_class = "text-success" if total_session_pnl >= 0 else "text-danger"
|
||||
@ -850,6 +859,9 @@ class CleanTradingDashboard:
|
||||
pnl_class = ""
|
||||
|
||||
if current_price and entry_price and size > 0:
|
||||
# Calculate position size in USD
|
||||
position_size_usd = size * entry_price
|
||||
|
||||
# Calculate raw P&L per unit
|
||||
if side.upper() == 'LONG' or side.upper() == 'BUY':
|
||||
raw_pnl_per_unit = current_price - entry_price
|
||||
@ -860,11 +872,17 @@ class CleanTradingDashboard:
|
||||
leverage_applied_by_exchange = self._get_leverage_applied_by_exchange()
|
||||
if leverage_applied_by_exchange:
|
||||
# Broker already applies leverage, so use base P&L
|
||||
unrealized_pnl = raw_pnl_per_unit * size
|
||||
leveraged_pnl = raw_pnl_per_unit * size
|
||||
else:
|
||||
# Apply leverage locally
|
||||
leveraged_pnl_per_unit = raw_pnl_per_unit * self.current_leverage
|
||||
unrealized_pnl = leveraged_pnl_per_unit * size
|
||||
leveraged_pnl = leveraged_pnl_per_unit * size
|
||||
|
||||
# Calculate trading fees (opening + closing)
|
||||
trading_fees = self._calculate_trading_fees(position_size_usd, current_price, size)
|
||||
|
||||
# Subtract fees from unrealized P&L
|
||||
unrealized_pnl = leveraged_pnl - trading_fees
|
||||
|
||||
# Format P&L string with color
|
||||
if unrealized_pnl >= 0:
|
||||
@ -1326,6 +1344,42 @@ class CleanTradingDashboard:
|
||||
logger.debug(f"Error checking leverage_applied_by_exchange: {e}")
|
||||
return False
|
||||
|
||||
def _calculate_trading_fees(self, position_size_usd: float, current_price: float, quantity: float) -> float:
|
||||
"""Calculate opening and closing fees for a position
|
||||
|
||||
Args:
|
||||
position_size_usd: Position size in USD
|
||||
current_price: Current market price
|
||||
quantity: Position quantity
|
||||
|
||||
Returns:
|
||||
float: Total fees (opening + closing)
|
||||
"""
|
||||
try:
|
||||
# Get fee rates from trading executor if available
|
||||
maker_fee = 0.0001 # Default 0.01%
|
||||
taker_fee = 0.0006 # Default 0.06%
|
||||
|
||||
if self.trading_executor and hasattr(self.trading_executor, 'primary_config'):
|
||||
trading_fees = self.trading_executor.primary_config.get('trading_fees', {})
|
||||
maker_fee = trading_fees.get('maker_fee', 0.0001)
|
||||
taker_fee = trading_fees.get('taker_fee', 0.0006)
|
||||
|
||||
# Calculate fees (opening + closing)
|
||||
# Opening fee on entry price
|
||||
opening_fee = position_size_usd * taker_fee # Use taker fee for market orders
|
||||
|
||||
# Closing fee on current price
|
||||
closing_fee = (current_price * quantity) * taker_fee
|
||||
|
||||
total_fees = opening_fee + closing_fee
|
||||
return total_fees
|
||||
|
||||
except Exception as e:
|
||||
logger.debug(f"Error calculating trading fees: {e}")
|
||||
# Fallback to simple calculation
|
||||
return position_size_usd * 0.0012 # 0.12% total (0.06% * 2)
|
||||
|
||||
def _get_current_price(self, symbol: str) -> Optional[float]:
|
||||
"""Get current price for symbol - ONLY using our data providers"""
|
||||
try:
|
||||
@ -4087,6 +4141,9 @@ class CleanTradingDashboard:
|
||||
entry_price = self.current_position.get('price', 0)
|
||||
|
||||
if entry_price and size > 0:
|
||||
# Calculate position size in USD
|
||||
position_size_usd = size * entry_price
|
||||
|
||||
# Calculate unrealized P&L with current leverage
|
||||
if side.upper() == 'LONG':
|
||||
raw_pnl_per_unit = current_price - entry_price
|
||||
@ -4102,20 +4159,26 @@ class CleanTradingDashboard:
|
||||
# Apply leverage locally
|
||||
leveraged_unrealized_pnl = raw_pnl_per_unit * size * self.current_leverage
|
||||
|
||||
# Calculate trading fees (opening + closing)
|
||||
trading_fees = self._calculate_trading_fees(position_size_usd, current_price, size)
|
||||
|
||||
# Subtract fees from unrealized P&L for profit incentive calculation
|
||||
net_unrealized_pnl = leveraged_unrealized_pnl - trading_fees
|
||||
|
||||
# Calculate profit incentive - bigger profits create stronger incentive to close
|
||||
if leveraged_unrealized_pnl > 0:
|
||||
# Profit incentive scales with profit amount
|
||||
if net_unrealized_pnl > 0:
|
||||
# Profit incentive scales with profit amount (after fees)
|
||||
# $1+ profit = 0.1 bonus, $5+ = 0.2 bonus, $10+ = 0.3 bonus
|
||||
if leveraged_unrealized_pnl >= 10.0:
|
||||
if net_unrealized_pnl >= 10.0:
|
||||
profit_incentive = 0.35 # Strong incentive for big profits
|
||||
elif leveraged_unrealized_pnl >= 5.0:
|
||||
elif net_unrealized_pnl >= 5.0:
|
||||
profit_incentive = 0.25 # Good incentive
|
||||
elif leveraged_unrealized_pnl >= 2.0:
|
||||
elif net_unrealized_pnl >= 2.0:
|
||||
profit_incentive = 0.15 # Moderate incentive
|
||||
elif leveraged_unrealized_pnl >= 1.0:
|
||||
elif net_unrealized_pnl >= 1.0:
|
||||
profit_incentive = 0.10 # Small incentive
|
||||
else:
|
||||
profit_incentive = leveraged_unrealized_pnl * 0.05 # Tiny profits get small bonus
|
||||
profit_incentive = net_unrealized_pnl * 0.05 # Tiny profits get small bonus
|
||||
|
||||
# Determine if we should execute based on current position and action
|
||||
if action == 'BUY':
|
||||
@ -5971,10 +6034,10 @@ class CleanTradingDashboard:
|
||||
logger.warning(f"Failed to store COB RL model: {e}")
|
||||
|
||||
# 5. Store Decision Fusion model
|
||||
if hasattr(self.orchestrator, 'decision_model') and self.orchestrator.decision_model:
|
||||
if hasattr(self.orchestrator, 'decision_fusion_network') and self.orchestrator.decision_fusion_network:
|
||||
try:
|
||||
if hasattr(self.orchestrator.decision_model, 'save'):
|
||||
save_path = self.orchestrator.decision_model.save('models/saved/decision_fusion_session')
|
||||
if hasattr(self.orchestrator.decision_fusion_network, 'save'):
|
||||
save_path = self.orchestrator.decision_fusion_network.save('models/saved/decision_fusion_session')
|
||||
stored_models.append(('Decision Fusion', save_path))
|
||||
logger.info(f"Stored Decision Fusion model: {save_path}")
|
||||
except Exception as e:
|
||||
@ -7883,7 +7946,28 @@ class CleanTradingDashboard:
|
||||
logger.info(f"[ORCHESTRATOR SIGNAL] Received: {action} for {symbol} (confidence: {confidence:.3f})")
|
||||
|
||||
# EXECUTE THE DECISION THROUGH TRADING EXECUTOR
|
||||
if self.trading_executor and confidence > 0.5: # Only execute confirmed signals
|
||||
# check if we are entering or exiting a position with this signal
|
||||
direction = 'ENTER'
|
||||
if action == 'BUY' or action == 'SELL':
|
||||
current_position = self.trading_executor.get_position(symbol)
|
||||
# check if we are already in a position for this symbol
|
||||
if current_position:
|
||||
if current_position['side'] == 'BUY' and action == 'SELL':
|
||||
direction = 'EXIT'
|
||||
elif current_position['side'] == 'SELL' and action == 'BUY':
|
||||
direction = 'EXIT'
|
||||
elif current_position['side'] == 'BUY' and action == 'BUY':
|
||||
direction = 'HOLD'
|
||||
elif current_position['side'] == 'SELL' and action == 'SELL':
|
||||
direction = 'HOLD'
|
||||
else:
|
||||
direction = 'ENTER'
|
||||
else:
|
||||
direction = 'HOLD'
|
||||
|
||||
agressiveness_threshold = self.agressiveness_enter if direction == 'ENTER' else self.agressiveness_exit
|
||||
# compare confidence with current aggressiveness
|
||||
if self.trading_executor and confidence > agressiveness_threshold:
|
||||
try:
|
||||
logger.info(f"[ORCHESTRATOR EXECUTION] Attempting to execute {action} for {symbol} via trading executor...")
|
||||
success = self.trading_executor.execute_signal(
|
||||
|
@ -304,7 +304,7 @@ class DashboardLayoutManager:
|
||||
html.H6([
|
||||
html.I(className="fas fa-chart-candlestick me-2"),
|
||||
"Live Price (WebSocket): ",
|
||||
html.Span(id="current-price", className="ms-2 text-primary", style={"fontWeight": "bold", "fontSize": "1.2em"})
|
||||
html.Span(id="chart-current-price", className="ms-2 text-primary", style={"fontWeight": "bold", "fontSize": "1.2em"})
|
||||
], className="card-title mb-0"),
|
||||
html.Div([
|
||||
html.Button([
|
||||
|
Reference in New Issue
Block a user