private OrderResetResult CreateResetResult(Order order, Dictionary <Guid, TradeDayCommonResult> commonDict, Dictionary <Guid, OpenOrderPLOfCurrentDay> openOrderPLOfCurrentDayDict, Dictionary <Guid, InterestStorage> notValuedPLDict, Dictionary <Guid, InterestStorage> valuedPLDict) { OrderResetResult resetResult = new OrderResetResult(); TradeDayCommonResult commonResult = null; if (commonDict != null) { commonDict.TryGetValue(order.Id, out commonResult); } OpenOrderPLOfCurrentDay openOrderPLOfCurrentDay = null; if (openOrderPLOfCurrentDayDict != null) { openOrderPLOfCurrentDayDict.TryGetValue(order.Id, out openOrderPLOfCurrentDay); } InterestStorage interestStoragePLNotValued = InterestStorage.Empty; if (notValuedPLDict != null) { notValuedPLDict.TryGetValue(order.Id, out interestStoragePLNotValued); } InterestStorage interestStoragePLValued = InterestStorage.Empty; if (valuedPLDict != null) { valuedPLDict.TryGetValue(order.Id, out interestStoragePLValued); } resetResult.TradeDay = _info.TradeDay; resetResult.OrderId = order.Id; resetResult.LotBalance = order.LotBalance; resetResult.CurrencyId = _info.RateSetting.CurrencyId; Price livePrice = order.IsBuy ? _info.Settings.SellPrice : _info.Settings.BuyPrice; resetResult.Margin = Calculator.MarginCalculator.CalculateMargin((int)_info.Instrument.MarginFormula, order.LotBalance, order.Owner.ContractSize(_info.TradeDay), order.ExecutePrice, livePrice, _info.RateSetting.RateIn, _info.RateSetting.RateOut, _info.RateSetting.RoundDecimals.Common, _info.RateSetting.RoundDecimals.Instrument); resetResult.PerLot = commonResult == null ? InterestStorage.Empty : new InterestStorage(commonResult.InterestPerLot, commonResult.StoragePerLot); resetResult.FloatPL = commonResult == null ? InterestStorage.Empty : new InterestStorage(_exchanger.ExchangeByCommonWithInstrumentSourceDecimals(order.LotBalance * commonResult.InterestPerLot), _exchanger.ExchangeByCommonWithInstrumentSourceDecimals(order.LotBalance * commonResult.StoragePerLot)); resetResult.DayNotValuedPL = openOrderPLOfCurrentDay == null ? InterestStorage.Empty : new InterestStorage(openOrderPLOfCurrentDay.DayNotValued); resetResult.NotValuedPL = interestStoragePLNotValued + (openOrderPLOfCurrentDay == null ? InterestStorage.Empty : openOrderPLOfCurrentDay.NotValued); resetResult.ValuedPL = interestStoragePLValued + (openOrderPLOfCurrentDay == null ? InterestStorage.Empty : openOrderPLOfCurrentDay.Valued); if (_info.Instrument.Category == InstrumentCategory.Physical) { Physical.PhysicalOrder physicalOrder = (Physical.PhysicalOrder)order; resetResult.PhysicalPaidAmount = physicalOrder.PaidAmount; resetResult.PaidPledgeBalance = physicalOrder.PaidPledgeBalance; resetResult.PhysicalOriginValueBalance = physicalOrder.PhysicalOriginValueBalance; resetResult.InstalmentInterest = commonResult == null ? 0m : commonResult.InstalmentInterest; } return(resetResult); }
internal static Dictionary <Guid, OpenOrderPLOfCurrentDay> Calculate(TradeDayInfo tradeDayInfo, Dictionary <Guid, TradeDayCommonResult> resetCommonResultDict, Exchanger exchanger) { if (tradeDayInfo.Settings.ValueDate == null && !tradeDayInfo.Settings.UseCompatibleMode) { return(null); } Dictionary <Guid, OpenOrderPLOfCurrentDay> result = new Dictionary <Guid, OpenOrderPLOfCurrentDay>(); foreach (var eachPair in resetCommonResultDict) { var orderId = eachPair.Key; var commonResetResult = eachPair.Value; if (!orderId.ShouldCalculate(tradeDayInfo.AffectedOrders)) { continue; } var eachOrder = tradeDayInfo.GetOrder(orderId); if (!IsOpenOrderOfCurrentDay(eachOrder, tradeDayInfo)) { continue; } OpenOrderPLOfCurrentDay openOrderPLOfCurrentDay = new OpenOrderPLOfCurrentDay(); int decimals = tradeDayInfo.Settings.IsInterestUseAccountCurrency ? tradeDayInfo.RateSetting.RoundDecimals.Max : tradeDayInfo.RateSetting.RoundDecimals.Instrument; var storage = Math.Round(eachOrder.LotBalance * commonResetResult.StoragePerLot, decimals, MidpointRounding.AwayFromZero); var interest = Math.Round(eachOrder.LotBalance * commonResetResult.InterestPerLot, decimals, MidpointRounding.AwayFromZero); openOrderPLOfCurrentDay.DayNotValued += tradeDayInfo.Settings.ShouldValueCurrentDayPL ? InterestStorage.Empty : new InterestStorage(interest, storage); var exchangeStorage = exchanger.ExchangeByCommonDecimals(storage); var exchangeInterest = exchanger.ExchangeByCommonDecimals(interest); openOrderPLOfCurrentDay.NotValued += tradeDayInfo.Settings.ShouldValueCurrentDayPL ? InterestStorage.Empty : new InterestStorage(exchangeInterest, exchangeStorage); bool isInterestValued = (eachOrder.InterestValueDate ?? tradeDayInfo.TradeDay) <= tradeDayInfo.TradeDay; decimal interestPLValued = tradeDayInfo.Settings.ShouldValueCurrentDayPL && isInterestValued ? exchangeInterest : 0; decimal storagePLValued = tradeDayInfo.Settings.ShouldValueCurrentDayPL ? exchangeStorage : 0; openOrderPLOfCurrentDay.Valued += new InterestStorage(interestPLValued, storagePLValued); openOrderPLOfCurrentDay.IsInterestValued = isInterestValued; openOrderPLOfCurrentDay.IsStorageValued = true; result.Add(orderId, openOrderPLOfCurrentDay); } return(result); }