Load from saved state after crash.
This commit is contained in:
@@ -156,6 +156,10 @@ defmodule Core.Bots.DCABot do
|
|||||||
def init(%{symbol: symbol, restore_state: restore_state}) do
|
def init(%{symbol: symbol, restore_state: restore_state}) do
|
||||||
account_id = Core.Client.account_id()
|
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 =
|
state =
|
||||||
if restore_state do
|
if restore_state do
|
||||||
# Restoring from saved state
|
# Restoring from saved state
|
||||||
@@ -632,4 +636,12 @@ defmodule Core.Bots.DCABot do
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user