From 0e154f4ced4c4e48091b73b68cfdae69d4b56143 Mon Sep 17 00:00:00 2001 From: Jeffrey Ward Date: Wed, 11 Feb 2026 20:29:40 -0500 Subject: [PATCH] Load from saved state after crash. --- traderex/lib/core/bots/dca_bot.ex | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/traderex/lib/core/bots/dca_bot.ex b/traderex/lib/core/bots/dca_bot.ex index 84472b4..58d0458 100644 --- a/traderex/lib/core/bots/dca_bot.ex +++ b/traderex/lib/core/bots/dca_bot.ex @@ -156,6 +156,10 @@ defmodule Core.Bots.DCABot do def init(%{symbol: symbol, restore_state: restore_state}) do account_id = Core.Client.account_id() + # If no restore_state was explicitly provided, check if there's saved state for this symbol + restore_state = + restore_state || find_saved_state_for_symbol(symbol) + state = if restore_state do # Restoring from saved state @@ -632,4 +636,12 @@ defmodule Core.Bots.DCABot do false end end + + defp find_saved_state_for_symbol(symbol) do + state_data = Core.Bots.BotPersistence.load_state() + + Enum.find(state_data, fn bot_state -> + bot_state["symbol"] == symbol + end) + end end