diff --git a/realtime.py b/realtime.py index 8d8aa34..b0d77a2 100644 --- a/realtime.py +++ b/realtime.py @@ -1490,7 +1490,7 @@ class RealTimeChart: # Interval component for updates - set to refresh every 500ms dcc.Interval( id='interval-component', - interval=500, # Refresh every 500ms for better real-time updates + interval=300, # Refresh every 300ms for better real-time updates n_intervals=0 ), @@ -1696,11 +1696,11 @@ class RealTimeChart: # Limit the number of candles to display but show more for context if df_1m is not None and not df_1m.empty: - df_1m = df_1m.tail(200) # Show more 1m candles (3+ hours) + df_1m = df_1m.tail(600) # Show 600 1m candles for better context - 10 hours if df_1h is not None and not df_1h.empty: - df_1h = df_1h.tail(72) # Show 3 days of hourly data + df_1h = df_1h.tail(480) # Show 480 hours of hourly data for better context - 20 days if df_1d is not None and not df_1d.empty: - df_1d = df_1d.tail(60) # Show 2 months of daily data + df_1d = df_1d.tail(365*2) # Show 2 years of daily data for better context except Exception as e: logger.error(f"Error getting additional timeframes: {str(e)}") @@ -1809,7 +1809,8 @@ class RealTimeChart: line=dict(width=1, color='darkgreen') ), text=buy_markers, - hoverinfo='x+y+text' + hoverinfo='x+y+text', + showlegend=True # Ensure Buy appears in legend ), row=1, col=1 ) @@ -1850,7 +1851,8 @@ class RealTimeChart: text=sell_markers, textposition='top center', textfont=dict(size=10), - hoverinfo='x+y+text' + hoverinfo='x+y+text', + showlegend=True # Ensure Sell appears in legend ), row=1, col=1 ) @@ -2746,26 +2748,39 @@ class RealTimeChart: except Exception as e: logger.error(f"Error converting timestamp for trade: {str(e)}") timestamp = datetime.now() - - # Initialize trades list if it doesn't exist - if not hasattr(self, 'trades'): - self.trades = [] - - # Add the trade to our list - self.trades.append({ - 'type': trade_type, + + # Create the trade object + trade = { 'price': price, 'timestamp': timestamp, - 'amount': amount, 'pnl': pnl, - 'added': datetime.now() - }) + 'amount': amount, + 'action': trade_type + } - # Only keep the most recent 50 trades - if len(self.trades) > 50: - self.trades = self.trades[-50:] - - logger.info(f"Added trade: {trade_type} {amount} at price {price} at time {timestamp} with PnL: {pnl}") + # Add to our trades list + if not hasattr(self, 'trades'): + self.trades = [] + self.trades.append(trade) + + # Log the trade for debugging + pnl_str = f" with PnL: {pnl}" if pnl is not None else "" + logger.info(f"Added trade: {trade_type} {amount} at price {price} at time {timestamp}{pnl_str}") + + # Trigger a more frequent update of the chart by scheduling a callback + # This helps ensure the trade appears immediately on the chart + if hasattr(self, 'app') and self.app is not None: + try: + # Only update if we have a dash app running + # This is a workaround to make trades appear immediately + interval_component = self.app.get_asset_url('interval-component') + if interval_component: + self.app.callback_map[interval_component]['callback']() + except: + # If callback triggering fails, it's not critical + pass + + return trade def update_trading_info(self, signal=None, position=None, balance=None, pnl=None): """Update the current trading information to be displayed on the chart