Skip to content

Commit 0986655

Browse files
committed
Improve changes
1 parent 41ba19b commit 0986655

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

Engine/Setup/BrokerageSetupHandler.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ private bool LoadExistingHoldingsAndOrders(IBrokerage brokerage, IAlgorithm algo
419419
// verify existing holding security type
420420
if (!algorithm.Securities.TryGetValue(holding.Symbol, out var security))
421421
{
422-
if (AddUnrequestedSecurity(algorithm, holding.Symbol, holding.Type) == null)
422+
if (!AddUnrequestedSecurity(algorithm, holding.Symbol, holding.Type))
423423
{
424424
continue;
425425
}
@@ -461,7 +461,7 @@ private bool LoadExistingHoldingsAndOrders(IBrokerage brokerage, IAlgorithm algo
461461
return true;
462462
}
463463

464-
private Security AddUnrequestedSecurity(IAlgorithm algorithm, Symbol symbol, SecurityType securityType)
464+
private bool AddUnrequestedSecurity(IAlgorithm algorithm, Symbol symbol, SecurityType securityType)
465465
{
466466
if (!algorithm.Securities.TryGetValue(symbol, out Security security))
467467
{
@@ -470,7 +470,7 @@ private Security AddUnrequestedSecurity(IAlgorithm algorithm, Symbol symbol, Sec
470470
Log.Error("BrokerageSetupHandler.Setup(): Unsupported security type: " + securityType + "-" + symbol.Value);
471471
AddInitializationError("Found unsupported security type in existing brokerage holdings: " + securityType + ". " +
472472
"QuantConnect currently supports the following security types: " + string.Join(",", _supportedSecurityTypes));
473-
return null;
473+
return false;
474474
}
475475

476476
var resolution = algorithm.UniverseSettings.Resolution;
@@ -504,7 +504,7 @@ private Security AddUnrequestedSecurity(IAlgorithm algorithm, Symbol symbol, Sec
504504
security = algorithm.AddSecurity(symbol.SecurityType, symbol.Value, resolution, symbol.ID.Market, fillForward, leverage, extendedHours);
505505
}
506506
}
507-
return security;
507+
return true;
508508
}
509509

510510
/// <summary>
@@ -525,18 +525,15 @@ protected void GetOpenOrders(IAlgorithm algorithm, IResultHandler resultHandler,
525525
foreach (var order in openOrders.OrderByDescending(x => x.SecurityType))
526526
{
527527
// verify existing holding security type
528-
if (!supportedSecurityTypes.Contains(order.SecurityType))
528+
if (!algorithm.Securities.TryGetValue(order.Symbol, out var security))
529529
{
530-
Log.Error("BrokerageSetupHandler.Setup(): Unsupported security type: " + order.SecurityType + "-" + order.Symbol.Value);
531-
AddInitializationError("Found unsupported security type in existing brokerage open orders: " + order.SecurityType + ". " +
532-
"QuantConnect currently supports the following security types: " + string.Join(",", supportedSecurityTypes));
533-
534-
// keep aggregating these errors
535-
continue;
530+
if (!AddUnrequestedSecurity(algorithm, order.Symbol, order.SecurityType))
531+
{
532+
// keep aggregating these errors
533+
continue;
534+
}
536535
}
537536

538-
// Add the security before adding the order to ensure the subscription exists
539-
var security = AddUnrequestedSecurity(algorithm, order.Symbol, order.SecurityType);
540537
transactionHandler.AddOpenOrder(order, algorithm);
541538
order.PriceCurrency = security?.SymbolProperties.QuoteCurrency;
542539

0 commit comments

Comments
 (0)