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