@@ -1326,23 +1326,28 @@ public void SetMaximumOrders(int max)
13261326 /// <param name="liquidateExistingHoldings">True will liquidate existing holdings</param>
13271327 /// <param name="tag">Tag the order with a short string.</param>
13281328 /// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1329+ /// <returns>A list of order tickets.</returns>
13291330 /// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
13301331 [ DocumentationAttribute ( TradingAndOrders ) ]
1331- public void SetHoldings ( List < PortfolioTarget > targets , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
1332+ public List < OrderTicket > SetHoldings ( List < PortfolioTarget > targets , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
13321333 {
1334+ List < OrderTicket > orderTickets = null ;
13331335 //If they triggered a liquidate
13341336 if ( liquidateExistingHoldings )
13351337 {
1336- Liquidate ( GetSymbolsToLiquidate ( targets . Select ( t => t . Symbol ) ) , tag : tag , orderProperties : orderProperties ) ;
1338+ orderTickets = Liquidate ( GetSymbolsToLiquidate ( targets . Select ( t => t . Symbol ) ) , tag : tag , orderProperties : orderProperties ) ;
13371339 }
1340+ orderTickets ??= new List < OrderTicket > ( ) ;
13381341
13391342 foreach ( var portfolioTarget in targets
13401343 // we need to create targets with quantities for OrderTargetsByMarginImpact
13411344 . Select ( target => new PortfolioTarget ( target . Symbol , CalculateOrderQuantity ( target . Symbol , target . Quantity ) ) )
13421345 . OrderTargetsByMarginImpact ( this , targetIsDelta : true ) )
13431346 {
1344- SetHoldingsImpl ( portfolioTarget . Symbol , portfolioTarget . Quantity , false , tag , orderProperties ) ;
1347+ var tickets = SetHoldingsImpl ( portfolioTarget . Symbol , portfolioTarget . Quantity , false , tag , orderProperties ) ;
1348+ orderTickets . AddRange ( tickets ) ;
13451349 }
1350+ return orderTickets ;
13461351 }
13471352
13481353 /// <summary>
@@ -1353,11 +1358,12 @@ public void SetHoldings(List<PortfolioTarget> targets, bool liquidateExistingHol
13531358 /// <param name="liquidateExistingHoldings">liquidate existing holdings if necessary to hold this stock</param>
13541359 /// <param name="tag">Tag the order with a short string.</param>
13551360 /// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1361+ /// <returns>A list of order tickets.</returns>
13561362 /// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
13571363 [ DocumentationAttribute ( TradingAndOrders ) ]
1358- public void SetHoldings ( Symbol symbol , double percentage , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
1364+ public List < OrderTicket > SetHoldings ( Symbol symbol , double percentage , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
13591365 {
1360- SetHoldings ( symbol , percentage . SafeDecimalCast ( ) , liquidateExistingHoldings , tag , orderProperties ) ;
1366+ return SetHoldings ( symbol , percentage . SafeDecimalCast ( ) , liquidateExistingHoldings , tag , orderProperties ) ;
13611367 }
13621368
13631369 /// <summary>
@@ -1368,11 +1374,12 @@ public void SetHoldings(Symbol symbol, double percentage, bool liquidateExisting
13681374 /// <param name="liquidateExistingHoldings">bool liquidate existing holdings if necessary to hold this stock</param>
13691375 /// <param name="tag">Tag the order with a short string.</param>
13701376 /// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1377+ /// <returns>A list of order tickets.</returns>
13711378 /// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
13721379 [ DocumentationAttribute ( TradingAndOrders ) ]
1373- public void SetHoldings ( Symbol symbol , float percentage , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
1380+ public List < OrderTicket > SetHoldings ( Symbol symbol , float percentage , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
13741381 {
1375- SetHoldings ( symbol , ( decimal ) percentage , liquidateExistingHoldings , tag , orderProperties ) ;
1382+ return SetHoldings ( symbol , ( decimal ) percentage , liquidateExistingHoldings , tag , orderProperties ) ;
13761383 }
13771384
13781385 /// <summary>
@@ -1383,11 +1390,12 @@ public void SetHoldings(Symbol symbol, float percentage, bool liquidateExistingH
13831390 /// <param name="liquidateExistingHoldings">bool liquidate existing holdings if necessary to hold this stock</param>
13841391 /// <param name="tag">Tag the order with a short string.</param>
13851392 /// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1393+ /// <returns>A list of order tickets.</returns>
13861394 /// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
13871395 [ DocumentationAttribute ( TradingAndOrders ) ]
1388- public void SetHoldings ( Symbol symbol , int percentage , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
1396+ public List < OrderTicket > SetHoldings ( Symbol symbol , int percentage , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
13891397 {
1390- SetHoldings ( symbol , ( decimal ) percentage , liquidateExistingHoldings , tag , orderProperties ) ;
1398+ return SetHoldings ( symbol , ( decimal ) percentage , liquidateExistingHoldings , tag , orderProperties ) ;
13911399 }
13921400
13931401 /// <summary>
@@ -1401,24 +1409,27 @@ public void SetHoldings(Symbol symbol, int percentage, bool liquidateExistingHol
14011409 /// <param name="liquidateExistingHoldings">bool flag to clean all existing holdings before setting new faction.</param>
14021410 /// <param name="tag">Tag the order with a short string.</param>
14031411 /// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1412+ /// <returns>A list of order tickets.</returns>
14041413 /// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
14051414 [ DocumentationAttribute ( TradingAndOrders ) ]
1406- public void SetHoldings ( Symbol symbol , decimal percentage , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
1415+ public List < OrderTicket > SetHoldings ( Symbol symbol , decimal percentage , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
14071416 {
1408- SetHoldingsImpl ( symbol , CalculateOrderQuantity ( symbol , percentage ) , liquidateExistingHoldings , tag , orderProperties ) ;
1417+ return SetHoldingsImpl ( symbol , CalculateOrderQuantity ( symbol , percentage ) , liquidateExistingHoldings , tag , orderProperties ) ;
14091418 }
14101419
14111420 /// <summary>
14121421 /// Set holdings implementation, which uses order quantities (delta) not percentage nor target final quantity
14131422 /// </summary>
1414- private void SetHoldingsImpl ( Symbol symbol , decimal orderQuantity , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
1423+ private List < OrderTicket > SetHoldingsImpl ( Symbol symbol , decimal orderQuantity , bool liquidateExistingHoldings = false , string tag = null , IOrderProperties orderProperties = null )
14151424 {
1425+ List < OrderTicket > orderTickets = null ;
14161426 //If they triggered a liquidate
14171427 if ( liquidateExistingHoldings )
14181428 {
1419- Liquidate ( GetSymbolsToLiquidate ( [ symbol ] ) , tag : tag , orderProperties : orderProperties ) ;
1429+ orderTickets = Liquidate ( GetSymbolsToLiquidate ( [ symbol ] ) , tag : tag , orderProperties : orderProperties ) ;
14201430 }
14211431
1432+ orderTickets ??= new List < OrderTicket > ( ) ;
14221433 tag ??= "" ;
14231434 //Calculate total unfilled quantity for open market orders
14241435 var marketOrdersQuantity = Transactions . GetOpenOrderTickets (
@@ -1435,19 +1446,22 @@ private void SetHoldingsImpl(Symbol symbol, decimal orderQuantity, bool liquidat
14351446 if ( ! Securities . TryGetValue ( symbol , out security ) )
14361447 {
14371448 Error ( $ "{ symbol } not found in portfolio. Request this data when initializing the algorithm.") ;
1438- return ;
1449+ return orderTickets ;
14391450 }
14401451
14411452 //Check whether the exchange is open to send a market order. If not, send a market on open order instead
1453+ OrderTicket ticket ;
14421454 if ( security . Exchange . ExchangeOpen )
14431455 {
1444- MarketOrder ( symbol , quantity , false , tag , orderProperties ) ;
1456+ ticket = MarketOrder ( symbol , quantity , false , tag , orderProperties ) ;
14451457 }
14461458 else
14471459 {
1448- MarketOnOpenOrder ( symbol , quantity , tag , orderProperties ) ;
1460+ ticket = MarketOnOpenOrder ( symbol , quantity , tag , orderProperties ) ;
14491461 }
1462+ orderTickets . Add ( ticket ) ;
14501463 }
1464+ return orderTickets ;
14511465 }
14521466
14531467 /// <summary>
0 commit comments