diff --git a/crypto/brian/index-deep-new.py b/crypto/brian/index-deep-new.py index 2d18ffd..cf23b20 100644 --- a/crypto/brian/index-deep-new.py +++ b/crypto/brian/index-deep-new.py @@ -22,6 +22,18 @@ import matplotlib.dates as mdates from dotenv import load_dotenv load_dotenv() +# --- Helper Function for Timestamp Conversion --- +def convert_timestamp(ts): + """ + Safely converts a timestamp to a datetime object. + If the timestamp is abnormally high (i.e. in milliseconds), + it is divided by 1000. + """ + ts = float(ts) + if ts > 1e10: # Likely in milliseconds + ts = ts / 1000.0 + return datetime.fromtimestamp(ts) + # --- Directories --- LAST_DIR = os.path.join("models", "last") BEST_DIR = os.path.join("models", "best") @@ -219,11 +231,10 @@ def load_best_checkpoint(model, best_dir=BEST_DIR): old_embed = old_state["timeframe_embed.weight"] new_embed = new_state["timeframe_embed.weight"] if old_embed.shape[0] < new_embed.shape[0]: - # Copy the available rows and keep the remaining as initialized. new_embed[:old_embed.shape[0]] = old_embed old_state["timeframe_embed.weight"] = new_embed - # For channel_branches, if there are missing keys, load_state_dict with strict=False. + # For channel_branches, missing keys are handled by strict=False. model.load_state_dict(old_state, strict=False) return checkpoint @@ -232,7 +243,7 @@ def update_live_html(candles, trade_history, epoch): """ Generate a chart image that uses actual timestamps on the x-axis and shows a cumulative epoch PnL. The chart (with buy/sell markers and dotted lines) - is embedded in an HTML page that auto-refreshes every 10 seconds. + is embedded in an HTML page that auto-refreshes every 1 seconds. """ from io import BytesIO import base64 @@ -252,7 +263,7 @@ def update_live_html(candles, trade_history, epoch): - + Live Trading Chart - Epoch {epoch}