@@ -1326,23 +1326,28 @@ public void SetMaximumOrders(int max)
1326
1326
/// <param name="liquidateExistingHoldings">True will liquidate existing holdings</param>
1327
1327
/// <param name="tag">Tag the order with a short string.</param>
1328
1328
/// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1329
+ /// <returns>A list of order tickets.</returns>
1329
1330
/// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
1330
1331
[ 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 )
1332
1333
{
1334
+ List < OrderTicket > orderTickets = null ;
1333
1335
//If they triggered a liquidate
1334
1336
if ( liquidateExistingHoldings )
1335
1337
{
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 ) ;
1337
1339
}
1340
+ orderTickets ??= new List < OrderTicket > ( ) ;
1338
1341
1339
1342
foreach ( var portfolioTarget in targets
1340
1343
// we need to create targets with quantities for OrderTargetsByMarginImpact
1341
1344
. Select ( target => new PortfolioTarget ( target . Symbol , CalculateOrderQuantity ( target . Symbol , target . Quantity ) ) )
1342
1345
. OrderTargetsByMarginImpact ( this , targetIsDelta : true ) )
1343
1346
{
1344
- SetHoldingsImpl ( portfolioTarget . Symbol , portfolioTarget . Quantity , false , tag , orderProperties ) ;
1347
+ var tickets = SetHoldingsImpl ( portfolioTarget . Symbol , portfolioTarget . Quantity , false , tag , orderProperties ) ;
1348
+ orderTickets . AddRange ( tickets ) ;
1345
1349
}
1350
+ return orderTickets ;
1346
1351
}
1347
1352
1348
1353
/// <summary>
@@ -1353,11 +1358,12 @@ public void SetHoldings(List<PortfolioTarget> targets, bool liquidateExistingHol
1353
1358
/// <param name="liquidateExistingHoldings">liquidate existing holdings if necessary to hold this stock</param>
1354
1359
/// <param name="tag">Tag the order with a short string.</param>
1355
1360
/// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1361
+ /// <returns>A list of order tickets.</returns>
1356
1362
/// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
1357
1363
[ 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 )
1359
1365
{
1360
- SetHoldings ( symbol , percentage . SafeDecimalCast ( ) , liquidateExistingHoldings , tag , orderProperties ) ;
1366
+ return SetHoldings ( symbol , percentage . SafeDecimalCast ( ) , liquidateExistingHoldings , tag , orderProperties ) ;
1361
1367
}
1362
1368
1363
1369
/// <summary>
@@ -1368,11 +1374,12 @@ public void SetHoldings(Symbol symbol, double percentage, bool liquidateExisting
1368
1374
/// <param name="liquidateExistingHoldings">bool liquidate existing holdings if necessary to hold this stock</param>
1369
1375
/// <param name="tag">Tag the order with a short string.</param>
1370
1376
/// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1377
+ /// <returns>A list of order tickets.</returns>
1371
1378
/// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
1372
1379
[ 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 )
1374
1381
{
1375
- SetHoldings ( symbol , ( decimal ) percentage , liquidateExistingHoldings , tag , orderProperties ) ;
1382
+ return SetHoldings ( symbol , ( decimal ) percentage , liquidateExistingHoldings , tag , orderProperties ) ;
1376
1383
}
1377
1384
1378
1385
/// <summary>
@@ -1383,11 +1390,12 @@ public void SetHoldings(Symbol symbol, float percentage, bool liquidateExistingH
1383
1390
/// <param name="liquidateExistingHoldings">bool liquidate existing holdings if necessary to hold this stock</param>
1384
1391
/// <param name="tag">Tag the order with a short string.</param>
1385
1392
/// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1393
+ /// <returns>A list of order tickets.</returns>
1386
1394
/// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
1387
1395
[ 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 )
1389
1397
{
1390
- SetHoldings ( symbol , ( decimal ) percentage , liquidateExistingHoldings , tag , orderProperties ) ;
1398
+ return SetHoldings ( symbol , ( decimal ) percentage , liquidateExistingHoldings , tag , orderProperties ) ;
1391
1399
}
1392
1400
1393
1401
/// <summary>
@@ -1401,24 +1409,27 @@ public void SetHoldings(Symbol symbol, int percentage, bool liquidateExistingHol
1401
1409
/// <param name="liquidateExistingHoldings">bool flag to clean all existing holdings before setting new faction.</param>
1402
1410
/// <param name="tag">Tag the order with a short string.</param>
1403
1411
/// <param name="orderProperties">The order properties to use. Defaults to <see cref="DefaultOrderProperties"/></param>
1412
+ /// <returns>A list of order tickets.</returns>
1404
1413
/// <seealso cref="MarketOrder(QuantConnect.Symbol, decimal, bool, string, IOrderProperties)"/>
1405
1414
[ 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 )
1407
1416
{
1408
- SetHoldingsImpl ( symbol , CalculateOrderQuantity ( symbol , percentage ) , liquidateExistingHoldings , tag , orderProperties ) ;
1417
+ return SetHoldingsImpl ( symbol , CalculateOrderQuantity ( symbol , percentage ) , liquidateExistingHoldings , tag , orderProperties ) ;
1409
1418
}
1410
1419
1411
1420
/// <summary>
1412
1421
/// Set holdings implementation, which uses order quantities (delta) not percentage nor target final quantity
1413
1422
/// </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 )
1415
1424
{
1425
+ List < OrderTicket > orderTickets = null ;
1416
1426
//If they triggered a liquidate
1417
1427
if ( liquidateExistingHoldings )
1418
1428
{
1419
- Liquidate ( GetSymbolsToLiquidate ( [ symbol ] ) , tag : tag , orderProperties : orderProperties ) ;
1429
+ orderTickets = Liquidate ( GetSymbolsToLiquidate ( [ symbol ] ) , tag : tag , orderProperties : orderProperties ) ;
1420
1430
}
1421
1431
1432
+ orderTickets ??= new List < OrderTicket > ( ) ;
1422
1433
tag ??= "" ;
1423
1434
//Calculate total unfilled quantity for open market orders
1424
1435
var marketOrdersQuantity = Transactions . GetOpenOrderTickets (
@@ -1435,19 +1446,22 @@ private void SetHoldingsImpl(Symbol symbol, decimal orderQuantity, bool liquidat
1435
1446
if ( ! Securities . TryGetValue ( symbol , out security ) )
1436
1447
{
1437
1448
Error ( $ "{ symbol } not found in portfolio. Request this data when initializing the algorithm.") ;
1438
- return ;
1449
+ return orderTickets ;
1439
1450
}
1440
1451
1441
1452
//Check whether the exchange is open to send a market order. If not, send a market on open order instead
1453
+ OrderTicket ticket ;
1442
1454
if ( security . Exchange . ExchangeOpen )
1443
1455
{
1444
- MarketOrder ( symbol , quantity , false , tag , orderProperties ) ;
1456
+ ticket = MarketOrder ( symbol , quantity , false , tag , orderProperties ) ;
1445
1457
}
1446
1458
else
1447
1459
{
1448
- MarketOnOpenOrder ( symbol , quantity , tag , orderProperties ) ;
1460
+ ticket = MarketOnOpenOrder ( symbol , quantity , tag , orderProperties ) ;
1449
1461
}
1462
+ orderTickets . Add ( ticket ) ;
1450
1463
}
1464
+ return orderTickets ;
1451
1465
}
1452
1466
1453
1467
/// <summary>
0 commit comments