Skip to content

Commit

Permalink
Minor test brokerages fixes (#7552)
Browse files Browse the repository at this point in the history
* AlgorithmStub Lazy Pandas Converter Set

* Fix brokerages tests adding orders twice
  • Loading branch information
Martin-Molinero authored Nov 1, 2023
1 parent d2f8c73 commit 2f75c68
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Algorithm/QCAlgorithm.Python.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public partial class QCAlgorithm
/// <summary>
/// PandasConverter for this Algorithm
/// </summary>
public PandasConverter PandasConverter { get; private set; }
public virtual PandasConverter PandasConverter { get; private set; }

/// <summary>
/// Sets pandas converter
Expand Down
1 change: 0 additions & 1 deletion Tests/Brokerages/BrokerageTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ protected void LiquidateHoldings()
if (holding.Quantity == 0) continue;
Log.Trace("Liquidating: " + holding);
var order = new MarketOrder(holding.Symbol, -holding.Quantity, DateTime.UtcNow);
_orderProvider.Add(order);
PlaceOrderWaitForStatus(order, OrderStatus.Filled);
}
}
Expand Down
19 changes: 16 additions & 3 deletions Tests/Engine/DataFeeds/AlgorithmStub.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,22 @@ public class AlgorithmStub : QCAlgorithm
public List<SecurityChanges> SecurityChangesRecord = new List<SecurityChanges>();
public DataManager DataManager;
public IDataFeed DataFeed;

/// <summary>
/// Lanzy PandasConverter only if used
/// </summary>
public override PandasConverter PandasConverter
{
get
{
if(base.PandasConverter == null)
{
SetPandasConverter();
}
return base.PandasConverter;
}
}

public AlgorithmStub(bool createDataManager = true)
{
if (createDataManager)
Expand All @@ -44,8 +60,6 @@ public AlgorithmStub(bool createDataManager = true)
var orderProcessor = new FakeOrderProcessor();
orderProcessor.TransactionManager = Transactions;
Transactions.SetOrderProcessor(orderProcessor);
PythonInitializer.Initialize();
SetPandasConverter();
}

public AlgorithmStub(IDataFeed dataFeed)
Expand All @@ -54,7 +68,6 @@ public AlgorithmStub(IDataFeed dataFeed)
DataManager = new DataManagerStub(dataFeed, this);
SubscriptionManager.SetDataManager(DataManager);
Transactions.SetOrderProcessor(new FakeOrderProcessor());
SetPandasConverter();
}

public void AddSecurities(Resolution resolution = Resolution.Second, List<string> equities = null, List<string> forex = null, List<string> crypto = null)
Expand Down

0 comments on commit 2f75c68

Please sign in to comment.