@@ -389,7 +389,7 @@ private bool LoadCashBalance(IBrokerage brokerage, IAlgorithm algorithm)
389389 return true ;
390390 }
391391
392- private bool LoadExistingHoldingsAndOrders ( IBrokerage brokerage , IAlgorithm algorithm , SetupHandlerParameters parameters )
392+ protected bool LoadExistingHoldingsAndOrders ( IBrokerage brokerage , IAlgorithm algorithm , SetupHandlerParameters parameters )
393393 {
394394 Log . Trace ( "BrokerageSetupHandler.Setup(): Fetching open orders from brokerage..." ) ;
395395 try
@@ -417,9 +417,10 @@ private bool LoadExistingHoldingsAndOrders(IBrokerage brokerage, IAlgorithm algo
417417 Log . Trace ( "BrokerageSetupHandler.Setup(): Has existing holding: " + holding ) ;
418418
419419 // verify existing holding security type
420- if ( ! algorithm . Securities . TryGetValue ( holding . Symbol , out var security ) )
420+ Security security ;
421+ if ( ! algorithm . Securities . TryGetValue ( holding . Symbol , out security ) )
421422 {
422- if ( ! AddUnrequestedSecurity ( algorithm , holding . Symbol , holding . Type ) )
423+ if ( ! AddUnrequestedSecurity ( algorithm , holding . Symbol , holding . Type , out security ) )
423424 {
424425 continue ;
425426 }
@@ -461,15 +462,16 @@ private bool LoadExistingHoldingsAndOrders(IBrokerage brokerage, IAlgorithm algo
461462 return true ;
462463 }
463464
464- private bool AddUnrequestedSecurity ( IAlgorithm algorithm , Symbol symbol , SecurityType securityType )
465+ private bool AddUnrequestedSecurity ( IAlgorithm algorithm , Symbol symbol , SecurityType securityType , out Security security )
465466 {
466- if ( ! algorithm . Securities . TryGetValue ( symbol , out Security security ) )
467+ if ( ! algorithm . Securities . TryGetValue ( symbol , out security ) )
467468 {
468469 if ( ! _supportedSecurityTypes . Contains ( ( SecurityType ) securityType ) )
469470 {
470471 Log . Error ( "BrokerageSetupHandler.Setup(): Unsupported security type: " + securityType + "-" + symbol . Value ) ;
471472 AddInitializationError ( "Found unsupported security type in existing brokerage holdings: " + securityType + ". " +
472473 "QuantConnect currently supports the following security types: " + string . Join ( "," , _supportedSecurityTypes ) ) ;
474+ security = null ;
473475 return false ;
474476 }
475477
@@ -525,9 +527,10 @@ protected void GetOpenOrders(IAlgorithm algorithm, IResultHandler resultHandler,
525527 foreach ( var order in openOrders . OrderByDescending ( x => x . SecurityType ) )
526528 {
527529 // verify existing holding security type
528- if ( ! algorithm . Securities . TryGetValue ( order . Symbol , out var security ) )
530+ Security security ;
531+ if ( ! algorithm . Securities . TryGetValue ( order . Symbol , out security ) )
529532 {
530- if ( ! AddUnrequestedSecurity ( algorithm , order . Symbol , order . SecurityType ) )
533+ if ( ! AddUnrequestedSecurity ( algorithm , order . Symbol , order . SecurityType , out security ) )
531534 {
532535 // keep aggregating these errors
533536 continue ;
0 commit comments