@@ -65,12 +65,6 @@ def __init__(self, config,
6565 self .optimizer_id = None
6666 self .backtesting_id = None
6767 self ._init_default_config_values ()
68- try :
69- self .backtesting_config [common_constants .CONFIG_EXCHANGE_TYPE ] \
70- = config [common_constants .CONFIG_EXCHANGE_TYPE ]
71- except KeyError :
72- self .backtesting_config [common_constants .CONFIG_EXCHANGE_TYPE ] \
73- = common_constants .CONFIG_EXCHANGE_CURRENT_PROFILE
7468 self .stopped = False
7569 self .stopped_event = None
7670 self .post_backtesting_task = None
@@ -327,7 +321,7 @@ def _adapt_config(self):
327321 exchange_details .pop (common_constants .CONFIG_EXCHANGE_SANDBOXED , None )
328322 self .backtesting_config [common_constants .CONFIG_TRADING ][common_constants .CONFIG_TRADER_RISK ] = self .risk
329323 self .backtesting_config [common_constants .CONFIG_TRADING ][
330- common_constants .CONFIG_TRADER_REFERENCE_MARKET ] = self ._find_reference_market ()
324+ common_constants .CONFIG_TRADER_REFERENCE_MARKET ] = self ._find_reference_market_and_update_contract_type ()
331325 self .backtesting_config [common_constants .CONFIG_SIMULATOR ][
332326 common_constants .CONFIG_STARTING_PORTFOLIO ] = self .starting_portfolio
333327 self .backtesting_config [common_constants .CONFIG_SIMULATOR ][
@@ -339,12 +333,17 @@ def _adapt_config(self):
339333 self ._add_config_default_backtesting_values ()
340334
341335 def _init_exchange_type (self ):
336+ forced_exchange_type = self .octobot_origin_config .get (common_constants .CONFIG_EXCHANGE_TYPE ,
337+ common_constants .USE_CURRENT_PROFILE )
342338 try :
343339 for exchange_name in self .symbols_to_create_exchange_classes :
344- # use current profile config to create a spot/future/margin backtesting exchange
345- self .octobot_backtesting .exchange_type_by_exchange [exchange_name ] = \
346- self .octobot_origin_config [common_constants .CONFIG_EXCHANGES ].get (exchange_name , {}).\
347- get (common_constants .CONFIG_EXCHANGE_TYPE , common_constants .DEFAULT_EXCHANGE_TYPE )
340+ if forced_exchange_type == common_constants .USE_CURRENT_PROFILE :
341+ # use current profile config to create a spot/future/margin backtesting exchange
342+ self .octobot_backtesting .exchange_type_by_exchange [exchange_name ] = \
343+ self .octobot_origin_config [common_constants .CONFIG_EXCHANGES ].get (exchange_name , {}).\
344+ get (common_constants .CONFIG_EXCHANGE_TYPE , common_constants .DEFAULT_EXCHANGE_TYPE )
345+ else :
346+ self .octobot_backtesting .exchange_type_by_exchange [exchange_name ] = forced_exchange_type
348347 except StopIteration :
349348 # use default exchange type
350349 pass
@@ -360,25 +359,36 @@ async def _generate_backtesting_id_if_missing(self):
360359 await run_dbs_identifier .initialize ()
361360 self .backtesting_config [common_constants .CONFIG_BACKTESTING_ID ] = run_dbs_identifier .backtesting_id
362361
363- def _find_reference_market (self ):
362+ def _find_reference_market_and_update_contract_type (self ):
364363 ref_market_candidate = None
365364 ref_market_candidates = {}
365+ forced_contract_type = self .octobot_origin_config .get (common_constants .CONFIG_CONTRACT_TYPE ,
366+ common_constants .USE_CURRENT_PROFILE )
366367 for symbols in self .symbols_to_create_exchange_classes .values ():
367368 symbol = symbols [0 ]
368369 if next (iter (self .octobot_backtesting .exchange_type_by_exchange .values ())) \
369370 == common_constants .CONFIG_EXCHANGE_FUTURE :
370- if symbol .is_inverse ():
371- if not all ([symbol .is_inverse () for symbol in symbols ]):
372- self .logger .error (f"Mixed inverse and linear contracts backtesting are not supported yet" )
373- self .octobot_backtesting .futures_contract_type = trading_enums .FutureContractType .INVERSE_PERPETUAL
371+ if forced_contract_type == common_constants .USE_CURRENT_PROFILE :
372+ if symbol .is_inverse ():
373+ if not all ([symbol .is_inverse () for symbol in symbols ]):
374+ self .logger .error (f"Mixed inverse and linear contracts backtesting are not supported yet" )
375+ self .octobot_backtesting .futures_contract_type = \
376+ trading_enums .FutureContractType .INVERSE_PERPETUAL
377+ else :
378+ if not all ([symbol .is_linear () for symbol in symbols ]):
379+ self .logger .error (f"Mixed inverse and linear contracts backtesting are not supported yet" )
380+ self .octobot_backtesting .futures_contract_type = \
381+ trading_enums .FutureContractType .LINEAR_PERPETUAL
382+ # in inverse contracts, use BTC for BTC/USD trading as reference market
383+ if symbol .settlement_asset :
384+ # only use settlement asset if available
385+ return symbol .settlement_asset
374386 else :
375- if not all ([symbol .is_linear () for symbol in symbols ]):
376- self .logger .error (f"Mixed inverse and linear contracts backtesting are not supported yet" )
377- self .octobot_backtesting .futures_contract_type = trading_enums .FutureContractType .LINEAR_PERPETUAL
378- # in inverse contracts, use BTC for BTC/USD trading as reference market
379- if symbol .settlement_asset :
380- # only use settlement asset if available
381- return symbol .settlement_asset
387+ self .octobot_backtesting .futures_contract_type = forced_contract_type
388+ return symbol .base \
389+ if forced_contract_type is trading_enums .FutureContractType .INVERSE_PERPETUAL \
390+ else symbol .quote
391+
382392 for symbol in symbols :
383393 quote = symbol .quote
384394 if ref_market_candidate is None :
0 commit comments