14
14
# You should have received a copy of the GNU Lesser General Public
15
15
# License along with this library.
16
16
import contextlib
17
+ import copy
17
18
18
19
import octobot_commons .logging as logging
19
20
import octobot_commons .constants as commons_constants
@@ -44,6 +45,7 @@ def __init__(self, config, trader, exchange_manager):
44
45
self .historical_portfolio_value_manager = None
45
46
self .reference_market = None
46
47
self ._is_initialized_event_set = False
48
+ self ._simulated_portfolio_initial_config = None
47
49
48
50
async def initialize_impl (self ):
49
51
"""
@@ -53,6 +55,9 @@ async def initialize_impl(self):
53
55
if self .exchange_manager .is_storage_enabled () and self .historical_portfolio_value_manager is None :
54
56
self .historical_portfolio_value_manager = personal_data .HistoricalPortfolioValueManager (self )
55
57
await self .historical_portfolio_value_manager .initialize ()
58
+ self .set_simulated_portfolio_initial_config (
59
+ self .config [commons_constants .CONFIG_SIMULATOR ][commons_constants .CONFIG_STARTING_PORTFOLIO ]
60
+ )
56
61
self ._reset_portfolio ()
57
62
58
63
def handle_balance_update (self , balance , is_diff_update = False ):
@@ -263,7 +268,7 @@ def _load_portfolio(self, reset_from_config):
263
268
if reset_from_config \
264
269
or self .historical_portfolio_value_manager is None \
265
270
or not self .historical_portfolio_value_manager .has_previous_session_portfolio ():
266
- self ._set_starting_simulated_portfolio ()
271
+ self ._apply_starting_simulated_portfolio ()
267
272
else :
268
273
self ._load_simulated_portfolio_from_history ()
269
274
self .logger .info (f"{ constants .CURRENT_PORTFOLIO_STRING } { self .portfolio .portfolio } " )
@@ -278,13 +283,14 @@ def _load_simulated_portfolio_from_history(self):
278
283
)
279
284
self .handle_balance_update (self .portfolio .get_portfolio_from_amount_dict (portfolio_amount_dict ))
280
285
281
- def _set_starting_simulated_portfolio (self ):
286
+ def set_simulated_portfolio_initial_config (self , portfolio_config ):
287
+ self ._simulated_portfolio_initial_config = copy .deepcopy (portfolio_config )
288
+
289
+ def _apply_starting_simulated_portfolio (self ):
282
290
"""
283
291
Load new portfolio from config settings
284
292
"""
285
- portfolio_amount_dict = personal_data .parse_decimal_config_portfolio (
286
- self .config [commons_constants .CONFIG_SIMULATOR ][commons_constants .CONFIG_STARTING_PORTFOLIO ]
287
- )
293
+ portfolio_amount_dict = personal_data .parse_decimal_config_portfolio (self ._simulated_portfolio_initial_config )
288
294
self .handle_balance_update (self .portfolio .get_portfolio_from_amount_dict (portfolio_amount_dict ))
289
295
290
296
def _set_initialized_event (self ):
0 commit comments