public async Task <PhysicalTrade> MapTrade(TradeDataObject tradeDataObject, TradeSummaryResponse tradeSummaryResponse, IEnumerable <CashflowResponse> cashflowResponses,
                                                   IEnumerable <ProfileResponse> profileResponses, MappingHelper mappingHelper, string apiJwtToken)
        {
            if (tradeDataObject is null)
            {
                throw new DataException("Trade is null");
            }

            if (tradeDataObject.Product?.Commodity?.Timezone is null)
            {
                throw new DataException("Trade's timezone is null");
            }

            if (cashflowResponses is null)
            {
                throw new DataException("No cashflow data");
            }

            if (profileResponses is null)
            {
                throw new DataException("No profile data");
            }

            var timezone  = DateTimeHelper.GetTimeZone(tradeDataObject.Product?.Commodity?.Timezone);
            var cashflows = cashflowResponses.ToList();
            var commodity = MapCommodityToCommodity(tradeDataObject.Product?.Commodity?.Commodity, mappingHelper);

            var buyerEic = await MapEic(tradeDataObject.Buyer, "Buyer party", apiJwtToken);

            var sellerEic = await MapEic(tradeDataObject.Seller, "Seller party", apiJwtToken);

            var beneficiaryId = await MapEic(tradeDataObject.Beneficiary, "Beneficiary party", apiJwtToken, buyerEic);

            return(new PhysicalTrade
            {
                ActionType = tradeDataObject.EboActionType(),
                TradeId = TestMapTradeReferenceToTradeId(tradeDataObject.TradeReference, tradeDataObject.TradeLeg),
                Uti = tradeDataObject.Uti,
                ProcessInformation = new ProcessInformation
                {
                    ReportingOnBehalfOf = false,
                    EmirReportMode = CmsReportType,
                    RemitReportMode = CmsReportType
                },
                Market = MapCommodityToMarket(tradeDataObject.Product?.Commodity),
                Commodity = commodity,
                TransactionType = MapContractTypeToTransactionType(tradeDataObject.Product?.ContractType, mappingHelper),
                DeliveryPointArea = tradeDataObject.Product?.Commodity?.DeliveryArea?.Eic,
                BuyerParty = buyerEic,
                SellerParty = sellerEic,
                BeneficiaryId = beneficiaryId,
                Intragroup = MapInternalToIntragroup(tradeDataObject.Buyer?.Internal, tradeDataObject.Seller?.Internal),
                LoadType = MapShapeDescriptionToLoadType(tradeDataObject.Product?.ShapeDescription, "Custom", mappingHelper),
                Agreement = MapContractAgreementToAgreement(tradeDataObject.Contract?.AgreementType?.AgreementType, tradeDataObject.Product?.Commodity?.Commodity, mappingHelper),
                TotalVolume = AbsoluteValue(tradeSummaryResponse?.TotalVolume),
                TotalVolumeUnit = MapEnergyUnitToVolumeUnit(tradeDataObject.Quantity?.QuantityUnit?.EnergyUnit?.EnergyUnit, mappingHelper),
                TradeExecutionTimestamp = EquiasDateTimeHelper.FormatDateTimeWithOffset(tradeDataObject.TradeDateTime, timezone),
                CapacityUnit = MapQuantityUnitToCapacityUnit(tradeDataObject.Quantity?.QuantityUnit?.QuantityUnit, mappingHelper),
                PriceUnit = MapPriceUnit(tradeDataObject.Price?.PriceUnit, mappingHelper),
                TotalContractValue = AbsoluteValue(tradeSummaryResponse?.TotalValue),
                SettlementCurrency = tradeSummaryResponse?.TotalValueCurrency,
                SettlementDates = cashflows.Any()
                    ? cashflows.SelectMany(d => d.Cashflows.Select(c => c.SettlementDate.ToIso8601DateTime()))
                    : null,
                TimeIntervalQuantities = MapProfileResponsesToDeliveryStartTimes(tradeDataObject.Quantity?.Quantity, profileResponses, timezone, tradeDataObject.Price?.PriceUnit?.CurrencyExponent),
                TraderName = tradeDataObject.InternalTrader?.ContactLongName,
                HubCodificationInformation = commodity == EquiasConstants.CommodityGas
                    ? await MapHubCodificationInformation(tradeDataObject.Buyer, tradeDataObject.Seller, apiJwtToken)
                    : null,
                Agents = commodity == EquiasConstants.CommodityPower
                    ? new List <Agent>
                {
                    new()
                    {
                        AgentName = tradeDataObject.Extension?.BuyerEnergyAccount,
                        AgentType = EquiasConstants.AgentTypeEcvna,
                        Ecvna = new Ecvna
                        {
                            BscPartyId = await MapBscParty(tradeDataObject.Extension?.EcvnAgentParty?.Extension?.BscParty, apiJwtToken),
                            BuyerEnergyAccount = tradeDataObject.Extension?.BuyerEnergyAccount,
                            SellerEnergyAccount = tradeDataObject.Extension?.SellerEnergyAccount,
                            BuyerId = await MapBuyerSellerId(tradeDataObject.Buyer, apiJwtToken),
                            SellerId = await MapBuyerSellerId(tradeDataObject.Seller, apiJwtToken),
                            NotificationAgent = await MapNotificationAgent(tradeDataObject.Extension?.EcvnAgentParty, apiJwtToken),
                            TransmissionChargeIdentification = MapSchedule5(tradeDataObject.Extension?.Schedule5, mappingHelper)
                        }
                    }
                }
Beispiel #2
0
        public async Task <TradeConfirmation> MapConfirmation(TradeDataObject tradeDataObject, TradeSummaryResponse tradeSummaryResponse,
                                                              IEnumerable <ProfileResponse> profileResponses, string apiJwtToken, IFidectusConfiguration fidectusConfiguration)
        {
            if (tradeDataObject is null)
            {
                throw new DataException("Trade is null");
            }

            if (tradeDataObject.Product?.Commodity?.Timezone is null)
            {
                throw new DataException("Trade's timezone is null");
            }

            if (profileResponses is null)
            {
                throw new DataException("No profile data");
            }


            var timezone = DateTimeHelper.GetTimeZone(tradeDataObject.Product?.Commodity?.Timezone);

            var senderId = await MapSenderId(tradeDataObject, apiJwtToken);

            var receiverId = await MapReceiverId(tradeDataObject, apiJwtToken);

            var buyerEic = await MapEic(tradeDataObject.Buyer, "Buyer party", apiJwtToken);

            var sellerEic = await MapEic(tradeDataObject.Seller, "Seller party", apiJwtToken);

            var commodity = MapCommodityToCommodity(tradeDataObject.Product?.Commodity?.Commodity, fidectusConfiguration);

            return(new TradeConfirmation
            {
                DocumentId = MapDocumentId(tradeDataObject, senderId),
                DocumentUsage = fidectusConfiguration.GetSetting("FidectusConfirmationUsage", "Live"),
                SenderId = senderId,
                ReceiverId = receiverId,
                ReceiverRole = "Trader",
                DocumentVersion = 1,
                Market = tradeDataObject.Product?.Commodity?.Country,
                Commodity = commodity,
                TransactionType = MapContractTypeToTransactionType(tradeDataObject.Product?.ContractType, fidectusConfiguration),
                DeliveryPointArea = tradeDataObject.Product?.Commodity?.DeliveryArea?.Eic,
                BuyerParty = buyerEic,
                SellerParty = sellerEic,
                LoadType = MapShapeDescriptionToLoadType(tradeDataObject.Product?.ShapeDescription, "Custom", fidectusConfiguration),
                Agreement = MapContractAgreementToAgreement(tradeDataObject.Contract?.AgreementType?.AgreementType, tradeDataObject.Product?.Commodity?.Commodity, fidectusConfiguration),
                Currency = MapPriceUnitToCurrency(tradeDataObject.Price?.PriceUnit),
                TotalVolume = AbsoluteValue(tradeSummaryResponse?.TotalVolume),
                TotalVolumeUnit = MapEnergyUnitToVolumeUnit(tradeDataObject.Quantity?.QuantityUnit?.EnergyUnit?.EnergyUnit, fidectusConfiguration),
                TradeDate = tradeDataObject.TradeDateTime.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture),
                CapacityUnit = MapQuantityUnitToCapacityUnit(tradeDataObject.Quantity?.QuantityUnit?.QuantityUnit, fidectusConfiguration),
                PriceUnit = MapPriceUnitToPriceUnit(tradeDataObject.Price?.PriceUnit, fidectusConfiguration),
                TotalContractValue = AbsoluteValue(tradeSummaryResponse?.TotalValue),
                TimeIntervalQuantities = MapProfileResponsesToDeliveryStartTimes(tradeDataObject.Quantity?.Quantity, profileResponses, timezone, tradeDataObject.Price?.PriceUnit?.CurrencyExponent),
                TraderName = tradeDataObject.InternalTrader?.ContactLongName,
                HubCodificationInformation = commodity == FidectusConstants.CommodityGas
                    ? await MapHubCodificationInformation(tradeDataObject.Buyer, tradeDataObject.Seller, apiJwtToken)
                    : null,
                AccountAndChargeInformation = commodity == FidectusConstants.CommodityPower
                    ? MapAccountAndChargeInformation(tradeDataObject)
                    : null,
                Agents = commodity == FidectusConstants.CommodityPower
                    ? new List <Agent>
                {
                    new()
                    {
                        AgentName = tradeDataObject.Extension?.EcvnAgentParty?.Extension?.BscParty?.BscPartyLongName,
                        AgentType = FidectusConstants.AgentTypeEcvna,
                        Ecvna = new Ecvna
                        {
                            BscPartyId = await MapBscParty(tradeDataObject.Extension?.EcvnAgentParty?.Extension?.BscParty, apiJwtToken),
                            BuyerEnergyAccount = tradeDataObject.Extension?.BuyerEnergyAccount,
                            SellerEnergyAccount = tradeDataObject.Extension?.SellerEnergyAccount,
                            BuyerId = await MapBuyerSellerId(tradeDataObject.Buyer, apiJwtToken),
                            SellerId = await MapBuyerSellerId(tradeDataObject.Seller, apiJwtToken),
                        }
                    }
                }