17 using System.Collections.Generic;
19 using System.Threading;
32 private class TransactionRecordEntry
34 public decimal ProfitLoss;
38 private readonly Dictionary<DateTime, TransactionRecordEntry> _transactionRecord;
41 private int _groupOrderManagerId;
43 private TimeSpan _marketOrderFillTimeout = TimeSpan.MinValue;
52 get {
return _securities.UtcTime; }
60 _algorithm = algorithm;
63 _securities = security;
66 _transactionRecord =
new Dictionary<DateTime, TransactionRecordEntry>();
78 lock (_transactionRecord)
80 return _transactionRecord.ToDictionary(x => x.Key, x => x.Value.ProfitLoss);
92 lock (_transactionRecord)
94 return _transactionRecord.Values.Count(x => x.IsWin);
106 lock (_transactionRecord)
108 return _transactionRecord.Values.Count(x => !x.IsWin);
120 lock (_transactionRecord)
122 return _transactionRecord.Where(x => x.Value.IsWin).ToDictionary(x => x.Key, x => x.Value.ProfitLoss);
134 lock (_transactionRecord)
136 return _transactionRecord.Where(x => !x.Value.IsWin).ToDictionary(x => x.Key, x => x.Value.ProfitLoss);
145 [Obsolete(
"MinimumOrderSize is obsolete and will not be used, please use Settings.MinimumOrderMarginPortfolioPercentage instead")]
152 [Obsolete(
"MinimumOrderQuantity is obsolete and will not be used, please use Settings.MinimumOrderMarginPortfolioPercentage instead")]
174 return _marketOrderFillTimeout;
178 _marketOrderFillTimeout = value;
189 if (_algorithm !=
null && _algorithm.IsWarmingUp)
199 return _orderProcessor.
Process(request);
252 if (_algorithm !=
null && _algorithm.IsWarmingUp)
257 var cancelledOrders =
new List<OrderTicket>();
261 cancelledOrders.Add(ticket);
263 return cancelledOrders;
274 if (_algorithm !=
null && _algorithm.IsWarmingUp)
279 var cancelledOrders =
new List<OrderTicket>();
283 cancelledOrders.Add(ticket);
285 return cancelledOrders;
303 public IEnumerable<OrderTicket>
GetOrderTickets(Func<OrderTicket, bool> filter =
null)
315 return _orderProcessor.
GetOrderTickets(filter.ConvertToDelegate<Func<OrderTicket, bool>>());
349 if (filter.TryConvert(out pythonSymbol))
353 return _orderProcessor.
GetOpenOrderTickets(filter.ConvertToDelegate<Func<OrderTicket, bool>>());
364 .Aggregate(0m, (d, t) => d + t.Quantity - t.QuantityFilled);
378 if (filter.TryConvert(out pythonSymbol))
384 .Aggregate(0m, (d, t) => d + t.Quantity - t.QuantityFilled);
417 if (orderTicket ==
null)
419 Log.
Error($
@"SecurityTransactionManager.WaitForOrder(): {
420 Messages.SecurityTransactionManager.UnableToLocateOrderTicket(orderId)}");
425 if (!orderTicket.OrderClosed.WaitOne(_marketOrderFillTimeout))
427 if(_marketOrderFillTimeout > TimeSpan.Zero)
429 Log.
Error($
@"SecurityTransactionManager.WaitForOrder(): {Messages.SecurityTransactionManager.OrderNotFilledWithinExpectedTime(_marketOrderFillTimeout)}");
456 filter = filter ?? (x =>
true);
471 if (filter.TryConvert(out pythonSymbol))
475 Func<Order, bool> csharpFilter = filter.ConvertToDelegate<Func<Order, bool>>();
513 public IEnumerable<Order>
GetOrders(Func<Order, bool> filter =
null)
515 return _orderProcessor.
GetOrders(filter ?? (x =>
true));
525 return _orderProcessor.
GetOrders(filter.ConvertToDelegate<Func<Order, bool>>());
534 return Interlocked.Increment(ref _orderId);
543 return Interlocked.Increment(ref _groupOrderManagerId);
552 _orderProcessor = orderProvider;
570 lock (_transactionRecord)
573 while (_transactionRecord.ContainsKey(clone))
575 clone = clone.AddMilliseconds(1);
577 _transactionRecord.Add(clone,
new TransactionRecordEntry { ProfitLoss = transactionProfitLoss, IsWin = isWin });