Skip to content

Commit e6335b1

Browse files
committed
Reset Index.ManualSetIsTradable when security is removed
1 parent 6813afb commit e6335b1

4 files changed

Lines changed: 20 additions & 6 deletions

File tree

Algorithm/QCAlgorithm.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,7 +1977,7 @@ public Security AddSecurity(Symbol symbol, Resolution? resolution = null, bool f
19771977

19781978
if (isCanonical)
19791979
{
1980-
security.IsTradable = false;
1980+
security.MakeNonTradable();
19811981
Securities.Add(security);
19821982

19831983
// add this security to the user defined universe
@@ -2503,7 +2503,7 @@ public bool RemoveSecurity(Symbol symbol)
25032503
}
25042504

25052505
// Mark security as not tradable
2506-
security.IsTradable = false;
2506+
security.MakeNonTradable();
25072507
if (symbol.IsCanonical())
25082508
{
25092509
// remove underlying equity data if it's marked as internal
@@ -3560,8 +3560,8 @@ private RestResponse SendBroadcast(string typeName, Dictionary<string, object> p
35603560
{
35613561
payload["$type"] = typeName;
35623562
}
3563-
return _api.BroadcastLiveCommand(Globals.OrganizationID,
3564-
AlgorithmMode == AlgorithmMode.Live ? ProjectId : null,
3563+
return _api.BroadcastLiveCommand(Globals.OrganizationID,
3564+
AlgorithmMode == AlgorithmMode.Live ? ProjectId : null,
35653565
payload);
35663566
}
35673567

Common/Extensions.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3920,6 +3920,20 @@ public static void MakeTradable(this Security security)
39203920
}
39213921
}
39223922

3923+
/// <summary>
3924+
/// Helper method to set the <see cref="Security.IsTradable"/> property to <code>false</code>
3925+
/// when a security is being removed from the algorithm or delisted
3926+
/// </summary>
3927+
/// <param name="security"></param>
3928+
public static void MakeNonTradable(this Security security)
3929+
{
3930+
if (security is Securities.Index.Index index)
3931+
{
3932+
index.ManualSetIsTradable = false;
3933+
}
3934+
security.IsTradable = false;
3935+
}
3936+
39233937
/// <summary>
39243938
/// Helper method to set an algorithm runtime exception in a normalized fashion
39253939
/// </summary>

Common/Securities/Index/Index.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public override bool IsTradable {
3535
get => _isTradable;
3636
set
3737
{
38-
ManualSetIsTradable = value;
38+
if (value) ManualSetIsTradable = true;
3939
_isTradable = value;
4040
}
4141
}

Engine/DataFeeds/UniverseSelection.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ public SecurityChanges HandleDelisting(BaseData data, bool isInternalFeed)
430430
{
431431
// don't allow users to open a new position once delisted
432432
security.IsDelisted = true;
433-
security.IsTradable = false;
433+
security.MakeNonTradable();
434434

435435
// Add the security removal to the security changes but only if not pending for removal.
436436
// If pending, the removed change event was already emitted for this security

0 commit comments

Comments
 (0)